Ryujinx/Ryujinx.Graphics/Gal/OpenGL/OGLHelper.cs

193 lines
6.1 KiB
C#
Raw Normal View History

2018-08-27 00:10:01 +00:00
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.Texture1D:
GL.TexImage1D(
Target,
Level,
InternalFormat,
Width,
Border,
PixelFormat,
PixelType,
Data);
break;
2018-08-27 00:10:01 +00:00
case TextureTarget.Texture2D:
GL.TexImage2D(
Target,
Level,
InternalFormat,
Width,
Height,
Border,
PixelFormat,
PixelType,
Data);
break;
case TextureTarget.Texture2DArray:
case TextureTarget.Texture3D:
//FIXME: Unstub depth when swizzle is fixed
Depth = 1;
2018-08-27 00:10:01 +00:00
GL.TexImage3D(
Target,
Level,
InternalFormat,
Width,
Height,
Depth,
Border,
PixelFormat,
PixelType,
Data);
break;
case TextureTarget.TextureCubeMap:
2018-08-27 06:03:31 +00:00
{
long FaceSize = Data.LongLength / 6;
2018-08-27 00:10:01 +00:00
2018-08-27 06:03:31 +00:00
for (int Face = 0; Face < 6; Face++)
{
fixed (byte* DataPtr = Data)
2018-08-27 00:10:01 +00:00
{
2018-08-27 06:03:31 +00:00
IntPtr Addr;
2018-08-27 00:10:01 +00:00
2018-08-27 06:03:31 +00:00
if (Data != null)
{
Addr = new IntPtr(DataPtr + FaceSize * Face);
2018-08-27 00:10:01 +00:00
}
2018-08-27 06:03:31 +00:00
else
{
Addr = new IntPtr(0);
}
GL.TexImage2D(
TextureTarget.TextureCubeMapPositiveX + Face,
Level,
InternalFormat,
Width,
Height,
Border,
PixelFormat,
PixelType,
Addr);
2018-08-27 00:10:01 +00:00
}
}
2018-08-27 06:03:31 +00:00
break;
}
2018-08-27 00:10:01 +00:00
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)
{
2018-08-27 06:03:31 +00:00
case TextureTarget.Texture1D:
GL.CompressedTexImage1D(
Target,
Level,
InternalFormat,
Width,
Border,
Data.Length,
Data);
break;
2018-08-27 00:10:01 +00:00
case TextureTarget.Texture2D:
GL.CompressedTexImage2D(
Target,
Level,
InternalFormat,
Width,
Height,
Border,
Data.Length,
Data);
break;
case TextureTarget.Texture2DArray:
case TextureTarget.Texture3D:
//FIXME: Unstub depth when swizzle is fixed
Depth = 1;
2018-08-27 00:10:01 +00:00
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());
}
}
}
}