aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics/Gal/OpenGL/ImageHandler.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Ryujinx.Graphics/Gal/OpenGL/ImageHandler.cs')
-rw-r--r--Ryujinx.Graphics/Gal/OpenGL/ImageHandler.cs143
1 files changed, 89 insertions, 54 deletions
diff --git a/Ryujinx.Graphics/Gal/OpenGL/ImageHandler.cs b/Ryujinx.Graphics/Gal/OpenGL/ImageHandler.cs
index 74f18dcd..dda82538 100644
--- a/Ryujinx.Graphics/Gal/OpenGL/ImageHandler.cs
+++ b/Ryujinx.Graphics/Gal/OpenGL/ImageHandler.cs
@@ -1,13 +1,11 @@
using OpenTK.Graphics.OpenGL;
+using Ryujinx.Graphics.Texture;
using System;
namespace Ryujinx.Graphics.Gal.OpenGL
{
class ImageHandler
{
- //TODO: Use a variable value here
- public const int MaxBpp = 16;
-
private static int CopyBuffer = 0;
private static int CopyBufferSize = 0;
@@ -38,87 +36,124 @@ namespace Ryujinx.Graphics.Gal.OpenGL
this.Image = Image;
}
- public void EnsureSetup(GalImage Image)
+ public void EnsureSetup(GalImage NewImage)
{
- if (Width != Image.Width ||
- Height != Image.Height ||
- Format != Image.Format ||
- !Initialized)
+ if (Width == NewImage.Width &&
+ Height == NewImage.Height &&
+ Format == NewImage.Format &&
+ Initialized)
{
- (PixelInternalFormat InternalFormat, PixelFormat PixelFormat, PixelType PixelType) =
- OGLEnumConverter.GetImageFormat(Image.Format);
+ return;
+ }
- GL.BindTexture(TextureTarget.Texture2D, Handle);
+ PixelInternalFormat InternalFmt;
+ PixelFormat PixelFormat;
+ PixelType PixelType;
- if (Initialized)
- {
- if (CopyBuffer == 0)
- {
- CopyBuffer = GL.GenBuffer();
- }
+ if (ImageUtils.IsCompressed(NewImage.Format))
+ {
+ InternalFmt = (PixelInternalFormat)OGLEnumConverter.GetCompressedImageFormat(NewImage.Format);
+
+ PixelFormat = default(PixelFormat);
+ PixelType = default(PixelType);
+ }
+ else
+ {
+ (InternalFmt, PixelFormat, PixelType) = OGLEnumConverter.GetImageFormat(NewImage.Format);
+ }
- int MaxWidth = Math.Max(Image.Width, Width);
- int MaxHeight = Math.Max(Image.Height, Height);
+ GL.BindTexture(TextureTarget.Texture2D, Handle);
- int CurrentSize = MaxWidth * MaxHeight * MaxBpp;
+ if (Initialized)
+ {
+ if (CopyBuffer == 0)
+ {
+ CopyBuffer = GL.GenBuffer();
+ }
- GL.BindBuffer(BufferTarget.PixelPackBuffer, CopyBuffer);
- GL.BindBuffer(BufferTarget.PixelUnpackBuffer, CopyBuffer);
+ int CurrentSize = Math.Max(ImageUtils.GetSize(NewImage),
+ ImageUtils.GetSize(Image));
- if (CopyBufferSize < CurrentSize)
- {
- CopyBufferSize = CurrentSize;
+ GL.BindBuffer(BufferTarget.PixelPackBuffer, CopyBuffer);
+ GL.BindBuffer(BufferTarget.PixelUnpackBuffer, CopyBuffer);
- GL.BufferData(BufferTarget.PixelPackBuffer, CurrentSize, IntPtr.Zero, BufferUsageHint.StreamCopy);
- }
+ if (CopyBufferSize < CurrentSize)
+ {
+ CopyBufferSize = CurrentSize;
+ GL.BufferData(BufferTarget.PixelPackBuffer, CurrentSize, IntPtr.Zero, BufferUsageHint.StreamCopy);
+ }
+
+ if (ImageUtils.IsCompressed(Image.Format))
+ {
+ GL.GetCompressedTexImage(TextureTarget.Texture2D, 0, IntPtr.Zero);
+ }
+ else
+ {
GL.GetTexImage(TextureTarget.Texture2D, 0, this.PixelFormat, this.PixelType, IntPtr.Zero);
+ }
- GL.DeleteTexture(Handle);
+ GL.DeleteTexture(Handle);
- Handle = GL.GenTexture();
+ Handle = GL.GenTexture();
- GL.BindTexture(TextureTarget.Texture2D, Handle);
- }
+ GL.BindTexture(TextureTarget.Texture2D, Handle);
+ }
- const int MinFilter = (int)TextureMinFilter.Linear;
- const int MagFilter = (int)TextureMagFilter.Linear;
+ const int MinFilter = (int)TextureMinFilter.Linear;
+ const int MagFilter = (int)TextureMagFilter.Linear;
- GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, MinFilter);
- GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, MagFilter);
+ GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, MinFilter);
+ GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, MagFilter);
- const int Level = 0;
- const int Border = 0;
+ const int Level = 0;
+ const int Border = 0;
+ if (ImageUtils.IsCompressed(NewImage.Format))
+ {
+ Console.WriteLine("Hit");
+
+ GL.CompressedTexImage2D(
+ TextureTarget.Texture2D,
+ Level,
+ (InternalFormat)InternalFmt,
+ NewImage.Width,
+ NewImage.Height,
+ Border,
+ ImageUtils.GetSize(NewImage),
+ IntPtr.Zero);
+ }
+ else
+ {
GL.TexImage2D(
TextureTarget.Texture2D,
Level,
- InternalFormat,
- Image.Width,
- Image.Height,
+ InternalFmt,
+ NewImage.Width,
+ NewImage.Height,
Border,
PixelFormat,
PixelType,
IntPtr.Zero);
+ }
- if (Initialized)
- {
- GL.BindBuffer(BufferTarget.PixelPackBuffer, 0);
- GL.BindBuffer(BufferTarget.PixelUnpackBuffer, 0);
- }
+ if (Initialized)
+ {
+ GL.BindBuffer(BufferTarget.PixelPackBuffer, 0);
+ GL.BindBuffer(BufferTarget.PixelUnpackBuffer, 0);
+ }
- this.Image = Image;
+ Image = NewImage;
- this.InternalFormat = InternalFormat;
- this.PixelFormat = PixelFormat;
- this.PixelType = PixelType;
+ this.InternalFormat = InternalFmt;
+ this.PixelFormat = PixelFormat;
+ this.PixelType = PixelType;
- Initialized = true;
- }
+ Initialized = true;
}
- public bool HasColor { get => ImageFormatConverter.HasColor(Format); }
- public bool HasDepth { get => ImageFormatConverter.HasDepth(Format); }
- public bool HasStencil { get => ImageFormatConverter.HasStencil(Format); }
+ public bool HasColor => ImageUtils.HasColor(Image.Format);
+ public bool HasDepth => ImageUtils.HasDepth(Image.Format);
+ public bool HasStencil => ImageUtils.HasStencil(Image.Format);
}
}