2018-04-08 21:17:35 +02:00
|
|
|
using OpenTK.Graphics.OpenGL;
|
|
|
|
using System;
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Gal.OpenGL
|
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
static class OglEnumConverter
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
public static FrontFaceDirection GetFrontFace(GalFrontFace frontFace)
|
2018-07-05 20:47:29 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
switch (frontFace)
|
2018-07-05 20:47:29 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
case GalFrontFace.Cw: return FrontFaceDirection.Cw;
|
|
|
|
case GalFrontFace.Ccw: return FrontFaceDirection.Ccw;
|
2018-07-05 20:47:29 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
throw new ArgumentException(nameof(frontFace) + " \"" + frontFace + "\" is not valid!");
|
2018-07-05 20:47:29 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static CullFaceMode GetCullFace(GalCullFace cullFace)
|
2018-07-05 20:47:29 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
switch (cullFace)
|
2018-07-05 20:47:29 +02:00
|
|
|
{
|
|
|
|
case GalCullFace.Front: return CullFaceMode.Front;
|
|
|
|
case GalCullFace.Back: return CullFaceMode.Back;
|
|
|
|
case GalCullFace.FrontAndBack: return CullFaceMode.FrontAndBack;
|
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
throw new ArgumentException(nameof(cullFace) + " \"" + cullFace + "\" is not valid!");
|
2018-07-05 20:47:29 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static StencilOp GetStencilOp(GalStencilOp op)
|
2018-07-05 20:47:29 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
switch (op)
|
2018-07-05 20:47:29 +02:00
|
|
|
{
|
|
|
|
case GalStencilOp.Keep: return StencilOp.Keep;
|
|
|
|
case GalStencilOp.Zero: return StencilOp.Zero;
|
|
|
|
case GalStencilOp.Replace: return StencilOp.Replace;
|
|
|
|
case GalStencilOp.Incr: return StencilOp.Incr;
|
|
|
|
case GalStencilOp.Decr: return StencilOp.Decr;
|
|
|
|
case GalStencilOp.Invert: return StencilOp.Invert;
|
|
|
|
case GalStencilOp.IncrWrap: return StencilOp.IncrWrap;
|
|
|
|
case GalStencilOp.DecrWrap: return StencilOp.DecrWrap;
|
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
throw new ArgumentException(nameof(op) + " \"" + op + "\" is not valid!");
|
2018-07-05 20:47:29 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static DepthFunction GetDepthFunc(GalComparisonOp func)
|
2018-06-27 06:32:28 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
return (DepthFunction)GetFunc(func);
|
2018-11-01 05:22:24 +01:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static StencilFunction GetStencilFunc(GalComparisonOp func)
|
2018-11-01 05:22:24 +01:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
return (StencilFunction)GetFunc(func);
|
2018-11-01 05:22:24 +01:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
private static All GetFunc(GalComparisonOp func)
|
2018-11-01 05:22:24 +01:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
if ((int)func >= (int)All.Never &&
|
|
|
|
(int)func <= (int)All.Always)
|
2018-06-27 06:32:28 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
return (All)func;
|
2018-06-27 06:32:28 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
switch (func)
|
2018-07-05 20:47:29 +02:00
|
|
|
{
|
2018-11-01 05:22:24 +01:00
|
|
|
case GalComparisonOp.Never: return All.Never;
|
|
|
|
case GalComparisonOp.Less: return All.Less;
|
|
|
|
case GalComparisonOp.Equal: return All.Equal;
|
|
|
|
case GalComparisonOp.Lequal: return All.Lequal;
|
|
|
|
case GalComparisonOp.Greater: return All.Greater;
|
|
|
|
case GalComparisonOp.NotEqual: return All.Notequal;
|
|
|
|
case GalComparisonOp.Gequal: return All.Gequal;
|
|
|
|
case GalComparisonOp.Always: return All.Always;
|
2018-07-05 20:47:29 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
throw new ArgumentException(nameof(func) + " \"" + func + "\" is not valid!");
|
2018-06-27 06:32:28 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static DrawElementsType GetDrawElementsType(GalIndexFormat format)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
switch (format)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
|
|
|
case GalIndexFormat.Byte: return DrawElementsType.UnsignedByte;
|
|
|
|
case GalIndexFormat.Int16: return DrawElementsType.UnsignedShort;
|
|
|
|
case GalIndexFormat.Int32: return DrawElementsType.UnsignedInt;
|
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
throw new ArgumentException(nameof(format) + " \"" + format + "\" is not valid!");
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static PrimitiveType GetPrimitiveType(GalPrimitiveType type)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
switch (type)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
|
|
|
case GalPrimitiveType.Points: return PrimitiveType.Points;
|
|
|
|
case GalPrimitiveType.Lines: return PrimitiveType.Lines;
|
|
|
|
case GalPrimitiveType.LineLoop: return PrimitiveType.LineLoop;
|
|
|
|
case GalPrimitiveType.LineStrip: return PrimitiveType.LineStrip;
|
|
|
|
case GalPrimitiveType.Triangles: return PrimitiveType.Triangles;
|
|
|
|
case GalPrimitiveType.TriangleStrip: return PrimitiveType.TriangleStrip;
|
|
|
|
case GalPrimitiveType.TriangleFan: return PrimitiveType.TriangleFan;
|
|
|
|
case GalPrimitiveType.Polygon: return PrimitiveType.Polygon;
|
|
|
|
case GalPrimitiveType.LinesAdjacency: return PrimitiveType.LinesAdjacency;
|
|
|
|
case GalPrimitiveType.LineStripAdjacency: return PrimitiveType.LineStripAdjacency;
|
|
|
|
case GalPrimitiveType.TrianglesAdjacency: return PrimitiveType.TrianglesAdjacency;
|
|
|
|
case GalPrimitiveType.TriangleStripAdjacency: return PrimitiveType.TriangleStripAdjacency;
|
|
|
|
case GalPrimitiveType.Patches: return PrimitiveType.Patches;
|
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
throw new ArgumentException(nameof(type) + " \"" + type + "\" is not valid!");
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static ShaderType GetShaderType(GalShaderType type)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
switch (type)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
|
|
|
case GalShaderType.Vertex: return ShaderType.VertexShader;
|
|
|
|
case GalShaderType.TessControl: return ShaderType.TessControlShader;
|
|
|
|
case GalShaderType.TessEvaluation: return ShaderType.TessEvaluationShader;
|
|
|
|
case GalShaderType.Geometry: return ShaderType.GeometryShader;
|
|
|
|
case GalShaderType.Fragment: return ShaderType.FragmentShader;
|
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
throw new ArgumentException(nameof(type) + " \"" + type + "\" is not valid!");
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static (PixelInternalFormat, PixelFormat, PixelType) GetImageFormat(GalImageFormat format)
|
2018-04-10 21:50:32 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
switch (format)
|
2018-04-10 21:50:32 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
case GalImageFormat.Rgba32 | GalImageFormat.Float: return (PixelInternalFormat.Rgba32f, PixelFormat.Rgba, PixelType.Float);
|
|
|
|
case GalImageFormat.Rgba32 | GalImageFormat.Sint: return (PixelInternalFormat.Rgba32i, PixelFormat.RgbaInteger, PixelType.Int);
|
|
|
|
case GalImageFormat.Rgba32 | GalImageFormat.Uint: return (PixelInternalFormat.Rgba32ui, PixelFormat.RgbaInteger, PixelType.UnsignedInt);
|
|
|
|
case GalImageFormat.Rgba16 | GalImageFormat.Float: return (PixelInternalFormat.Rgba16f, PixelFormat.Rgba, PixelType.HalfFloat);
|
|
|
|
case GalImageFormat.Rgba16 | GalImageFormat.Sint: return (PixelInternalFormat.Rgba16i, PixelFormat.RgbaInteger, PixelType.Short);
|
|
|
|
case GalImageFormat.Rgba16 | GalImageFormat.Uint: return (PixelInternalFormat.Rgba16ui, PixelFormat.RgbaInteger, PixelType.UnsignedShort);
|
|
|
|
case GalImageFormat.Rgba16 | GalImageFormat.Unorm: return (PixelInternalFormat.Rgba16, PixelFormat.Rgba, PixelType.UnsignedShort);
|
|
|
|
case GalImageFormat.Rg32 | GalImageFormat.Float: return (PixelInternalFormat.Rg32f, PixelFormat.Rg, PixelType.Float);
|
|
|
|
case GalImageFormat.Rg32 | GalImageFormat.Sint: return (PixelInternalFormat.Rg32i, PixelFormat.RgInteger, PixelType.Int);
|
|
|
|
case GalImageFormat.Rg32 | GalImageFormat.Uint: return (PixelInternalFormat.Rg32ui, PixelFormat.RgInteger, PixelType.UnsignedInt);
|
|
|
|
case GalImageFormat.Rgbx8 | GalImageFormat.Unorm: return (PixelInternalFormat.Rgb8, PixelFormat.Rgba, PixelType.UnsignedByte);
|
|
|
|
case GalImageFormat.Rgba8 | GalImageFormat.Snorm: return (PixelInternalFormat.Rgba8Snorm, PixelFormat.Rgba, PixelType.Byte);
|
|
|
|
case GalImageFormat.Rgba8 | GalImageFormat.Unorm: return (PixelInternalFormat.Rgba8, PixelFormat.Rgba, PixelType.UnsignedByte);
|
|
|
|
case GalImageFormat.Rgba8 | GalImageFormat.Sint: return (PixelInternalFormat.Rgba8i, PixelFormat.RgbaInteger, PixelType.Byte);
|
|
|
|
case GalImageFormat.Rgba8 | GalImageFormat.Uint: return (PixelInternalFormat.Rgba8ui, PixelFormat.RgbaInteger, PixelType.UnsignedByte);
|
|
|
|
case GalImageFormat.Rgba8 | GalImageFormat.Srgb: return (PixelInternalFormat.Srgb8Alpha8, PixelFormat.Rgba, PixelType.UnsignedByte);
|
|
|
|
case GalImageFormat.Bgra8 | GalImageFormat.Unorm: return (PixelInternalFormat.Rgba8, PixelFormat.Bgra, PixelType.UnsignedByte);
|
|
|
|
case GalImageFormat.Bgra8 | GalImageFormat.Srgb: return (PixelInternalFormat.Srgb8Alpha8, PixelFormat.Bgra, PixelType.UnsignedByte);
|
|
|
|
case GalImageFormat.Rgba4 | GalImageFormat.Unorm: return (PixelInternalFormat.Rgba4, PixelFormat.Rgba, PixelType.UnsignedShort4444Reversed);
|
|
|
|
case GalImageFormat.Rgb10A2 | GalImageFormat.Uint: return (PixelInternalFormat.Rgb10A2ui, PixelFormat.RgbaInteger, PixelType.UnsignedInt2101010Reversed);
|
|
|
|
case GalImageFormat.Rgb10A2 | GalImageFormat.Unorm: return (PixelInternalFormat.Rgb10A2, PixelFormat.Rgba, PixelType.UnsignedInt2101010Reversed);
|
2018-10-17 23:02:23 +02:00
|
|
|
case GalImageFormat.R32 | GalImageFormat.Float: return (PixelInternalFormat.R32f, PixelFormat.Red, PixelType.Float);
|
|
|
|
case GalImageFormat.R32 | GalImageFormat.Sint: return (PixelInternalFormat.R32i, PixelFormat.Red, PixelType.Int);
|
|
|
|
case GalImageFormat.R32 | GalImageFormat.Uint: return (PixelInternalFormat.R32ui, PixelFormat.Red, PixelType.UnsignedInt);
|
2019-03-04 02:45:25 +01:00
|
|
|
case GalImageFormat.Bgr5A1 | GalImageFormat.Unorm: return (PixelInternalFormat.Rgb5A1, PixelFormat.Rgba, PixelType.UnsignedShort5551);
|
|
|
|
case GalImageFormat.Rgb5A1 | GalImageFormat.Unorm: return (PixelInternalFormat.Rgb5A1, PixelFormat.Rgba, PixelType.UnsignedShort1555Reversed);
|
|
|
|
case GalImageFormat.Rgb565 | GalImageFormat.Unorm: return (PixelInternalFormat.Rgba, PixelFormat.Rgb, PixelType.UnsignedShort565Reversed);
|
|
|
|
case GalImageFormat.Bgr565 | GalImageFormat.Unorm: return (PixelInternalFormat.Rgba, PixelFormat.Rgb, PixelType.UnsignedShort565);
|
|
|
|
case GalImageFormat.Rg16 | GalImageFormat.Float: return (PixelInternalFormat.Rg16f, PixelFormat.Rg, PixelType.HalfFloat);
|
|
|
|
case GalImageFormat.Rg16 | GalImageFormat.Sint: return (PixelInternalFormat.Rg16i, PixelFormat.RgInteger, PixelType.Short);
|
|
|
|
case GalImageFormat.Rg16 | GalImageFormat.Snorm: return (PixelInternalFormat.Rg16Snorm, PixelFormat.Rg, PixelType.Short);
|
|
|
|
case GalImageFormat.Rg16 | GalImageFormat.Uint: return (PixelInternalFormat.Rg16ui, PixelFormat.RgInteger, PixelType.UnsignedShort);
|
|
|
|
case GalImageFormat.Rg16 | GalImageFormat.Unorm: return (PixelInternalFormat.Rg16, PixelFormat.Rg, PixelType.UnsignedShort);
|
|
|
|
case GalImageFormat.Rg8 | GalImageFormat.Sint: return (PixelInternalFormat.Rg8i, PixelFormat.RgInteger, PixelType.Byte);
|
|
|
|
case GalImageFormat.Rg8 | GalImageFormat.Snorm: return (PixelInternalFormat.Rg8Snorm, PixelFormat.Rg, PixelType.Byte);
|
|
|
|
case GalImageFormat.Rg8 | GalImageFormat.Uint: return (PixelInternalFormat.Rg8ui, PixelFormat.RgInteger, PixelType.UnsignedByte);
|
|
|
|
case GalImageFormat.Rg8 | GalImageFormat.Unorm: return (PixelInternalFormat.Rg8, PixelFormat.Rg, PixelType.UnsignedByte);
|
2018-10-17 23:02:23 +02:00
|
|
|
case GalImageFormat.R16 | GalImageFormat.Float: return (PixelInternalFormat.R16f, PixelFormat.Red, PixelType.HalfFloat);
|
|
|
|
case GalImageFormat.R16 | GalImageFormat.Sint: return (PixelInternalFormat.R16i, PixelFormat.RedInteger, PixelType.Short);
|
|
|
|
case GalImageFormat.R16 | GalImageFormat.Snorm: return (PixelInternalFormat.R16Snorm, PixelFormat.Red, PixelType.Short);
|
|
|
|
case GalImageFormat.R16 | GalImageFormat.Uint: return (PixelInternalFormat.R16ui, PixelFormat.RedInteger, PixelType.UnsignedShort);
|
|
|
|
case GalImageFormat.R16 | GalImageFormat.Unorm: return (PixelInternalFormat.R16, PixelFormat.Red, PixelType.UnsignedShort);
|
|
|
|
case GalImageFormat.R8 | GalImageFormat.Sint: return (PixelInternalFormat.R8i, PixelFormat.RedInteger, PixelType.Byte);
|
|
|
|
case GalImageFormat.R8 | GalImageFormat.Snorm: return (PixelInternalFormat.R8Snorm, PixelFormat.Red, PixelType.Byte);
|
|
|
|
case GalImageFormat.R8 | GalImageFormat.Uint: return (PixelInternalFormat.R8ui, PixelFormat.RedInteger, PixelType.UnsignedByte);
|
|
|
|
case GalImageFormat.R8 | GalImageFormat.Unorm: return (PixelInternalFormat.R8, PixelFormat.Red, PixelType.UnsignedByte);
|
|
|
|
case GalImageFormat.R11G11B10 | GalImageFormat.Float: return (PixelInternalFormat.R11fG11fB10f, PixelFormat.Rgb, PixelType.UnsignedInt10F11F11FRev);
|
|
|
|
|
2018-11-17 05:01:31 +01:00
|
|
|
case GalImageFormat.D16 | GalImageFormat.Unorm: return (PixelInternalFormat.DepthComponent16, PixelFormat.DepthComponent, PixelType.UnsignedShort);
|
|
|
|
case GalImageFormat.D24 | GalImageFormat.Unorm: return (PixelInternalFormat.DepthComponent24, PixelFormat.DepthComponent, PixelType.UnsignedInt);
|
2018-10-17 23:02:23 +02:00
|
|
|
case GalImageFormat.D24S8 | GalImageFormat.Uint: return (PixelInternalFormat.Depth24Stencil8, PixelFormat.DepthStencil, PixelType.UnsignedInt248);
|
|
|
|
case GalImageFormat.D24S8 | GalImageFormat.Unorm: return (PixelInternalFormat.Depth24Stencil8, PixelFormat.DepthStencil, PixelType.UnsignedInt248);
|
|
|
|
case GalImageFormat.D32 | GalImageFormat.Float: return (PixelInternalFormat.DepthComponent32f, PixelFormat.DepthComponent, PixelType.Float);
|
|
|
|
case GalImageFormat.D32S8 | GalImageFormat.Float: return (PixelInternalFormat.Depth32fStencil8, PixelFormat.DepthStencil, PixelType.Float32UnsignedInt248Rev);
|
2018-04-10 21:50:32 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
throw new NotImplementedException($"{format & GalImageFormat.FormatMask} {format & GalImageFormat.TypeMask}");
|
2018-04-10 21:50:32 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static All GetDepthCompareFunc(DepthCompareFunc depthCompareFunc)
|
2019-02-28 02:12:24 +01:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
switch (depthCompareFunc)
|
2019-02-28 02:12:24 +01:00
|
|
|
{
|
|
|
|
case DepthCompareFunc.LEqual:
|
|
|
|
return All.Lequal;
|
|
|
|
case DepthCompareFunc.GEqual:
|
|
|
|
return All.Gequal;
|
|
|
|
case DepthCompareFunc.Less:
|
|
|
|
return All.Less;
|
|
|
|
case DepthCompareFunc.Greater:
|
|
|
|
return All.Greater;
|
|
|
|
case DepthCompareFunc.Equal:
|
|
|
|
return All.Equal;
|
|
|
|
case DepthCompareFunc.NotEqual:
|
|
|
|
return All.Notequal;
|
|
|
|
case DepthCompareFunc.Always:
|
|
|
|
return All.Always;
|
|
|
|
case DepthCompareFunc.Never:
|
|
|
|
return All.Never;
|
|
|
|
default:
|
2019-03-04 02:45:25 +01:00
|
|
|
throw new ArgumentException(nameof(depthCompareFunc) + " \"" + depthCompareFunc + "\" is not valid!");
|
2019-02-28 02:12:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static InternalFormat GetCompressedImageFormat(GalImageFormat format)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
switch (format)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2018-10-17 23:02:23 +02:00
|
|
|
case GalImageFormat.BptcSfloat | GalImageFormat.Float: return InternalFormat.CompressedRgbBptcSignedFloat;
|
|
|
|
case GalImageFormat.BptcUfloat | GalImageFormat.Float: return InternalFormat.CompressedRgbBptcUnsignedFloat;
|
|
|
|
case GalImageFormat.BptcUnorm | GalImageFormat.Unorm: return InternalFormat.CompressedRgbaBptcUnorm;
|
|
|
|
case GalImageFormat.BptcUnorm | GalImageFormat.Srgb: return InternalFormat.CompressedSrgbAlphaBptcUnorm;
|
|
|
|
case GalImageFormat.BC1 | GalImageFormat.Unorm: return InternalFormat.CompressedRgbaS3tcDxt1Ext;
|
|
|
|
case GalImageFormat.BC1 | GalImageFormat.Srgb: return InternalFormat.CompressedSrgbAlphaS3tcDxt1Ext;
|
|
|
|
case GalImageFormat.BC2 | GalImageFormat.Unorm: return InternalFormat.CompressedRgbaS3tcDxt3Ext;
|
|
|
|
case GalImageFormat.BC2 | GalImageFormat.Srgb: return InternalFormat.CompressedSrgbAlphaS3tcDxt3Ext;
|
|
|
|
case GalImageFormat.BC3 | GalImageFormat.Unorm: return InternalFormat.CompressedRgbaS3tcDxt5Ext;
|
|
|
|
case GalImageFormat.BC3 | GalImageFormat.Srgb: return InternalFormat.CompressedSrgbAlphaS3tcDxt5Ext;
|
|
|
|
case GalImageFormat.BC4 | GalImageFormat.Snorm: return InternalFormat.CompressedSignedRedRgtc1;
|
|
|
|
case GalImageFormat.BC4 | GalImageFormat.Unorm: return InternalFormat.CompressedRedRgtc1;
|
|
|
|
case GalImageFormat.BC5 | GalImageFormat.Snorm: return InternalFormat.CompressedSignedRgRgtc2;
|
|
|
|
case GalImageFormat.BC5 | GalImageFormat.Unorm: return InternalFormat.CompressedRgRgtc2;
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
throw new NotImplementedException($"{format & GalImageFormat.FormatMask} {format & GalImageFormat.TypeMask}");
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static All GetTextureSwizzle(GalTextureSource source)
|
2018-05-17 20:25:42 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
switch (source)
|
2018-05-17 20:25:42 +02:00
|
|
|
{
|
|
|
|
case GalTextureSource.Zero: return All.Zero;
|
|
|
|
case GalTextureSource.Red: return All.Red;
|
|
|
|
case GalTextureSource.Green: return All.Green;
|
|
|
|
case GalTextureSource.Blue: return All.Blue;
|
|
|
|
case GalTextureSource.Alpha: return All.Alpha;
|
|
|
|
case GalTextureSource.OneInt: return All.One;
|
|
|
|
case GalTextureSource.OneFloat: return All.One;
|
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
throw new ArgumentException(nameof(source) + " \"" + source + "\" is not valid!");
|
2018-05-17 20:25:42 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static TextureWrapMode GetTextureWrapMode(GalTextureWrap wrap)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
switch (wrap)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2018-08-25 21:39:08 +02:00
|
|
|
case GalTextureWrap.Repeat: return TextureWrapMode.Repeat;
|
|
|
|
case GalTextureWrap.MirroredRepeat: return TextureWrapMode.MirroredRepeat;
|
|
|
|
case GalTextureWrap.ClampToEdge: return TextureWrapMode.ClampToEdge;
|
|
|
|
case GalTextureWrap.ClampToBorder: return TextureWrapMode.ClampToBorder;
|
|
|
|
case GalTextureWrap.Clamp: return TextureWrapMode.Clamp;
|
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
if (OglExtension.TextureMirrorClamp)
|
2018-08-25 21:39:08 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
switch (wrap)
|
2018-08-25 21:39:08 +02:00
|
|
|
{
|
|
|
|
case GalTextureWrap.MirrorClampToEdge: return (TextureWrapMode)ExtTextureMirrorClamp.MirrorClampToEdgeExt;
|
|
|
|
case GalTextureWrap.MirrorClampToBorder: return (TextureWrapMode)ExtTextureMirrorClamp.MirrorClampToBorderExt;
|
|
|
|
case GalTextureWrap.MirrorClamp: return (TextureWrapMode)ExtTextureMirrorClamp.MirrorClampExt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//Fallback to non-mirrored clamps
|
2019-03-04 02:45:25 +01:00
|
|
|
switch (wrap)
|
2018-08-25 21:39:08 +02:00
|
|
|
{
|
|
|
|
case GalTextureWrap.MirrorClampToEdge: return TextureWrapMode.ClampToEdge;
|
|
|
|
case GalTextureWrap.MirrorClampToBorder: return TextureWrapMode.ClampToBorder;
|
|
|
|
case GalTextureWrap.MirrorClamp: return TextureWrapMode.Clamp;
|
|
|
|
}
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
throw new ArgumentException(nameof(wrap) + " \"" + wrap + "\" is not valid!");
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static TextureMinFilter GetTextureMinFilter(
|
2019-03-04 02:45:25 +01:00
|
|
|
GalTextureFilter minFilter,
|
|
|
|
GalTextureMipFilter mipFilter)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
|
|
|
//TODO: Mip (needs mipmap support first).
|
2019-03-04 02:45:25 +01:00
|
|
|
switch (minFilter)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
|
|
|
case GalTextureFilter.Nearest: return TextureMinFilter.Nearest;
|
|
|
|
case GalTextureFilter.Linear: return TextureMinFilter.Linear;
|
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
throw new ArgumentException(nameof(minFilter) + " \"" + minFilter + "\" is not valid!");
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static TextureMagFilter GetTextureMagFilter(GalTextureFilter filter)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
switch (filter)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
|
|
|
case GalTextureFilter.Nearest: return TextureMagFilter.Nearest;
|
|
|
|
case GalTextureFilter.Linear: return TextureMagFilter.Linear;
|
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
throw new ArgumentException(nameof(filter) + " \"" + filter + "\" is not valid!");
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static BlendEquationMode GetBlendEquation(GalBlendEquation blendEquation)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
switch (blendEquation)
|
2018-04-13 20:12:58 +02:00
|
|
|
{
|
2018-11-01 05:22:24 +01:00
|
|
|
case GalBlendEquation.FuncAdd:
|
|
|
|
case GalBlendEquation.FuncAddGl:
|
|
|
|
return BlendEquationMode.FuncAdd;
|
|
|
|
|
|
|
|
case GalBlendEquation.FuncSubtract:
|
|
|
|
case GalBlendEquation.FuncSubtractGl:
|
|
|
|
return BlendEquationMode.FuncSubtract;
|
|
|
|
|
|
|
|
case GalBlendEquation.FuncReverseSubtract:
|
|
|
|
case GalBlendEquation.FuncReverseSubtractGl:
|
|
|
|
return BlendEquationMode.FuncReverseSubtract;
|
|
|
|
|
|
|
|
case GalBlendEquation.Min:
|
|
|
|
case GalBlendEquation.MinGl:
|
|
|
|
return BlendEquationMode.Min;
|
|
|
|
|
|
|
|
case GalBlendEquation.Max:
|
|
|
|
case GalBlendEquation.MaxGl:
|
|
|
|
return BlendEquationMode.Max;
|
2018-04-13 20:12:58 +02:00
|
|
|
}
|
2018-06-02 05:50:56 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
throw new ArgumentException(nameof(blendEquation) + " \"" + blendEquation + "\" is not valid!");
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
public static BlendingFactor GetBlendFactor(GalBlendFactor blendFactor)
|
2018-04-08 21:17:35 +02:00
|
|
|
{
|
2019-03-04 02:45:25 +01:00
|
|
|
switch (blendFactor)
|
2018-04-13 20:12:58 +02:00
|
|
|
{
|
2018-11-01 05:22:24 +01:00
|
|
|
case GalBlendFactor.Zero:
|
|
|
|
case GalBlendFactor.ZeroGl:
|
|
|
|
return BlendingFactor.Zero;
|
|
|
|
|
|
|
|
case GalBlendFactor.One:
|
|
|
|
case GalBlendFactor.OneGl:
|
|
|
|
return BlendingFactor.One;
|
|
|
|
|
|
|
|
case GalBlendFactor.SrcColor:
|
|
|
|
case GalBlendFactor.SrcColorGl:
|
|
|
|
return BlendingFactor.SrcColor;
|
|
|
|
|
|
|
|
case GalBlendFactor.OneMinusSrcColor:
|
|
|
|
case GalBlendFactor.OneMinusSrcColorGl:
|
|
|
|
return BlendingFactor.OneMinusSrcColor;
|
|
|
|
|
|
|
|
case GalBlendFactor.DstColor:
|
|
|
|
case GalBlendFactor.DstColorGl:
|
|
|
|
return BlendingFactor.DstColor;
|
|
|
|
|
|
|
|
case GalBlendFactor.OneMinusDstColor:
|
|
|
|
case GalBlendFactor.OneMinusDstColorGl:
|
|
|
|
return BlendingFactor.OneMinusDstColor;
|
|
|
|
|
|
|
|
case GalBlendFactor.SrcAlpha:
|
|
|
|
case GalBlendFactor.SrcAlphaGl:
|
|
|
|
return BlendingFactor.SrcAlpha;
|
|
|
|
|
|
|
|
case GalBlendFactor.OneMinusSrcAlpha:
|
|
|
|
case GalBlendFactor.OneMinusSrcAlphaGl:
|
|
|
|
return BlendingFactor.OneMinusSrcAlpha;
|
|
|
|
|
|
|
|
case GalBlendFactor.DstAlpha:
|
|
|
|
case GalBlendFactor.DstAlphaGl:
|
|
|
|
return BlendingFactor.DstAlpha;
|
|
|
|
|
|
|
|
case GalBlendFactor.OneMinusDstAlpha:
|
|
|
|
case GalBlendFactor.OneMinusDstAlphaGl:
|
|
|
|
return BlendingFactor.OneMinusDstAlpha;
|
|
|
|
|
|
|
|
case GalBlendFactor.OneMinusConstantColor:
|
|
|
|
case GalBlendFactor.OneMinusConstantColorGl:
|
|
|
|
return BlendingFactor.OneMinusConstantColor;
|
|
|
|
|
|
|
|
case GalBlendFactor.ConstantAlpha:
|
|
|
|
case GalBlendFactor.ConstantAlphaGl:
|
|
|
|
return BlendingFactor.ConstantAlpha;
|
|
|
|
|
|
|
|
case GalBlendFactor.OneMinusConstantAlpha:
|
|
|
|
case GalBlendFactor.OneMinusConstantAlphaGl:
|
|
|
|
return BlendingFactor.OneMinusConstantAlpha;
|
|
|
|
|
|
|
|
case GalBlendFactor.SrcAlphaSaturate:
|
|
|
|
case GalBlendFactor.SrcAlphaSaturateGl:
|
|
|
|
return BlendingFactor.SrcAlphaSaturate;
|
|
|
|
|
|
|
|
case GalBlendFactor.Src1Color:
|
|
|
|
case GalBlendFactor.Src1ColorGl:
|
|
|
|
return BlendingFactor.Src1Color;
|
|
|
|
|
|
|
|
case GalBlendFactor.OneMinusSrc1Color:
|
|
|
|
case GalBlendFactor.OneMinusSrc1ColorGl:
|
|
|
|
return (BlendingFactor)BlendingFactorSrc.OneMinusSrc1Color;
|
|
|
|
|
|
|
|
case GalBlendFactor.Src1Alpha:
|
|
|
|
case GalBlendFactor.Src1AlphaGl:
|
|
|
|
return BlendingFactor.Src1Alpha;
|
|
|
|
|
|
|
|
case GalBlendFactor.OneMinusSrc1Alpha:
|
|
|
|
case GalBlendFactor.OneMinusSrc1AlphaGl:
|
|
|
|
return (BlendingFactor)BlendingFactorSrc.OneMinusSrc1Alpha;
|
2018-07-04 01:06:13 +02:00
|
|
|
|
|
|
|
case GalBlendFactor.ConstantColor:
|
2018-11-01 05:22:24 +01:00
|
|
|
case GalBlendFactor.ConstantColorGl:
|
2018-07-04 01:06:13 +02:00
|
|
|
return BlendingFactor.ConstantColor;
|
2018-04-13 20:12:58 +02:00
|
|
|
}
|
2018-06-02 05:50:56 +02:00
|
|
|
|
2019-03-04 02:45:25 +01:00
|
|
|
throw new ArgumentException(nameof(blendFactor) + " \"" + blendFactor + "\" is not valid!");
|
2018-04-08 21:17:35 +02:00
|
|
|
}
|
|
|
|
}
|
2018-07-16 20:09:34 +02:00
|
|
|
}
|