Abstract into OGLHelper

This commit is contained in:
ReinUsesLisp 2018-08-26 21:10:01 -03:00
parent 30d7d3ae0a
commit 9d82220b37
3 changed files with 186 additions and 115 deletions

View file

@ -0,0 +1,164 @@
using OpenTK.Graphics.OpenGL;
using System;
namespace Ryujinx.Graphics.Gal.OpenGL
{
public static class OGLHelper
{
public static unsafe void TexImage(
TextureTarget Target,
int Level,
PixelInternalFormat InternalFormat,
int Width,
int Height,
int Depth,
int Border,
PixelFormat PixelFormat,
PixelType PixelType,
byte[] Data)
{
switch (Target)
{
case TextureTarget.Texture2D:
GL.TexImage2D(
Target,
Level,
InternalFormat,
Width,
Height,
Border,
PixelFormat,
PixelType,
Data);
break;
case TextureTarget.Texture2DArray:
GL.TexImage3D(
Target,
Level,
InternalFormat,
Width,
Height,
Depth,
Border,
PixelFormat,
PixelType,
Data);
break;
case TextureTarget.TextureCubeMap:
{
long FaceSize = Data.LongLength / 6;
for (int Face = 0; Face < 6; Face++)
{
fixed (byte* DataPtr = Data)
{
IntPtr Addr;
if (Data != null)
{
Addr = new IntPtr(DataPtr + FaceSize * Face);
}
else
{
Addr = new IntPtr(0);
}
GL.TexImage2D(
TextureTarget.TextureCubeMapPositiveX + Face,
Level,
InternalFormat,
Width,
Height,
Border,
PixelFormat,
PixelType,
Addr);
}
}
break;
}
default:
throw new NotImplementedException(Target.ToString());
}
}
public static unsafe void CompressedTexImage(
TextureTarget Target,
int Level,
InternalFormat InternalFormat,
int Width,
int Height,
int Depth,
int Border,
byte[] Data)
{
switch (Target)
{
case TextureTarget.Texture2D:
GL.CompressedTexImage2D(
Target,
Level,
InternalFormat,
Width,
Height,
Border,
Data.Length,
Data);
break;
case TextureTarget.Texture2DArray:
GL.CompressedTexImage3D(
Target,
Level,
InternalFormat,
Width,
Height,
Depth,
Border,
Data.Length,
Data);
break;
case TextureTarget.TextureCubeMap:
{
//FIXME: This implies that all 6 faces are equal
int FaceSize = Data.Length / 6;
for (int Face = 0; Face < 6; Face++)
{
fixed (byte* DataPtr = Data)
{
IntPtr Addr;
if (Data != null)
{
Addr = new IntPtr(DataPtr + FaceSize * Face);
}
else
{
Addr = new IntPtr(0);
}
GL.CompressedTexImage2D(
TextureTarget.TextureCubeMapPositiveX + Face,
Level,
InternalFormat,
Width,
Height,
Border,
FaceSize,
Addr);
}
}
break;
}
default:
throw new NotImplementedException(Target.ToString());
}
}
}
}

View file

@ -45,22 +45,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL
{ {
InternalFormat InternalFmt = OGLEnumConverter.GetCompressedImageFormat(Image.Format); InternalFormat InternalFmt = OGLEnumConverter.GetCompressedImageFormat(Image.Format);
switch (Target) OGLHelper.CompressedTexImage(
{
case TextureTarget.Texture2D:
GL.CompressedTexImage2D(
Target,
Level,
InternalFmt,
Image.Width,
Image.Height,
Border,
Data.Length,
Data);
break;
case TextureTarget.Texture2DArray:
GL.CompressedTexImage3D(
Target, Target,
Level, Level,
InternalFmt, InternalFmt,
@ -68,38 +53,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL
Image.Height, Image.Height,
Image.Depth, Image.Depth,
Border, Border,
Data.Length,
Data); Data);
break;
case TextureTarget.TextureCubeMap:
{
int FaceSize = Data.Length / 6;
for (int i = 0; i < 6; i++)
{
unsafe
{
fixed (byte* DataPtr = Data)
{
GL.CompressedTexImage2D(
TextureTarget.TextureCubeMapPositiveX + i,
Level,
InternalFmt,
Image.Width,
Image.Height,
Border,
FaceSize,
(IntPtr)(DataPtr + FaceSize * i));
}
}
}
break;
}
default:
throw new NotImplementedException(Target.ToString());
}
} }
else else
{ {
@ -120,49 +74,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL
(PixelInternalFormat InternalFormat, PixelFormat Format, PixelType Type) = OGLEnumConverter.GetImageFormat(Image.Format); (PixelInternalFormat InternalFormat, PixelFormat Format, PixelType Type) = OGLEnumConverter.GetImageFormat(Image.Format);
switch (Target) OGLHelper.TexImage(
{
case TextureTarget.Texture2D:
GL.TexImage2D(
Target,
Level,
InternalFormat,
Image.Width,
Image.Height,
Border,
Format,
Type,
Data);
break;
case TextureTarget.TextureCubeMap:
{
long FaceSize = Data.LongLength / 6;
for (int i = 0; i < 6; i++)
{
unsafe
{
fixed (byte* DataPtr = Data)
{
GL.TexImage2D(
TextureTarget.TextureCubeMapPositiveX + i,
Level,
InternalFormat,
Image.Width,
Image.Height,
Border,
Format,
Type,
(IntPtr)(DataPtr + FaceSize * i));
}
}
}
break;
}
case TextureTarget.Texture2DArray:
GL.TexImage3D(
Target, Target,
Level, Level,
InternalFormat, InternalFormat,
@ -173,11 +85,6 @@ namespace Ryujinx.Graphics.Gal.OpenGL
Format, Format,
Type, Type,
Data); Data);
break;
default:
throw new NotImplementedException(Target.ToString());
}
} }
int SwizzleR = (int)OGLEnumConverter.GetTextureSwizzle(Image.XSource); int SwizzleR = (int)OGLEnumConverter.GetTextureSwizzle(Image.XSource);