OGLEnumConverter.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. using OpenTK.Graphics.OpenGL;
  2. using System;
  3. namespace Ryujinx.Graphics.Gal.OpenGL
  4. {
  5. static class OGLEnumConverter
  6. {
  7. public static DepthFunction GetDepthFunc(GalComparisonOp Func)
  8. {
  9. if ((int)Func >= (int)DepthFunction.Never &&
  10. (int)Func <= (int)DepthFunction.Always)
  11. {
  12. return (DepthFunction)Func;
  13. }
  14. throw new ArgumentException(nameof(Func));
  15. }
  16. public static DrawElementsType GetDrawElementsType(GalIndexFormat Format)
  17. {
  18. switch (Format)
  19. {
  20. case GalIndexFormat.Byte: return DrawElementsType.UnsignedByte;
  21. case GalIndexFormat.Int16: return DrawElementsType.UnsignedShort;
  22. case GalIndexFormat.Int32: return DrawElementsType.UnsignedInt;
  23. }
  24. throw new ArgumentException(nameof(Format));
  25. }
  26. public static PrimitiveType GetPrimitiveType(GalPrimitiveType Type)
  27. {
  28. switch (Type)
  29. {
  30. case GalPrimitiveType.Points: return PrimitiveType.Points;
  31. case GalPrimitiveType.Lines: return PrimitiveType.Lines;
  32. case GalPrimitiveType.LineLoop: return PrimitiveType.LineLoop;
  33. case GalPrimitiveType.LineStrip: return PrimitiveType.LineStrip;
  34. case GalPrimitiveType.Triangles: return PrimitiveType.Triangles;
  35. case GalPrimitiveType.TriangleStrip: return PrimitiveType.TriangleStrip;
  36. case GalPrimitiveType.TriangleFan: return PrimitiveType.TriangleFan;
  37. case GalPrimitiveType.Quads: return PrimitiveType.Quads;
  38. case GalPrimitiveType.QuadStrip: return PrimitiveType.QuadStrip;
  39. case GalPrimitiveType.Polygon: return PrimitiveType.Polygon;
  40. case GalPrimitiveType.LinesAdjacency: return PrimitiveType.LinesAdjacency;
  41. case GalPrimitiveType.LineStripAdjacency: return PrimitiveType.LineStripAdjacency;
  42. case GalPrimitiveType.TrianglesAdjacency: return PrimitiveType.TrianglesAdjacency;
  43. case GalPrimitiveType.TriangleStripAdjacency: return PrimitiveType.TriangleStripAdjacency;
  44. case GalPrimitiveType.Patches: return PrimitiveType.Patches;
  45. }
  46. throw new ArgumentException(nameof(Type));
  47. }
  48. public static ShaderType GetShaderType(GalShaderType Type)
  49. {
  50. switch (Type)
  51. {
  52. case GalShaderType.Vertex: return ShaderType.VertexShader;
  53. case GalShaderType.TessControl: return ShaderType.TessControlShader;
  54. case GalShaderType.TessEvaluation: return ShaderType.TessEvaluationShader;
  55. case GalShaderType.Geometry: return ShaderType.GeometryShader;
  56. case GalShaderType.Fragment: return ShaderType.FragmentShader;
  57. }
  58. throw new ArgumentException(nameof(Type));
  59. }
  60. public static (PixelFormat, PixelType) GetTextureFormat(GalTextureFormat Format)
  61. {
  62. switch (Format)
  63. {
  64. case GalTextureFormat.R32G32B32A32: return (PixelFormat.Rgba, PixelType.Float);
  65. case GalTextureFormat.R16G16B16A16: return (PixelFormat.Rgba, PixelType.HalfFloat);
  66. case GalTextureFormat.A8B8G8R8: return (PixelFormat.Rgba, PixelType.UnsignedByte);
  67. case GalTextureFormat.R32: return (PixelFormat.Red, PixelType.Float);
  68. case GalTextureFormat.A1B5G5R5: return (PixelFormat.Rgba, PixelType.UnsignedShort5551);
  69. case GalTextureFormat.B5G6R5: return (PixelFormat.Rgb, PixelType.UnsignedShort565);
  70. case GalTextureFormat.G8R8: return (PixelFormat.Rg, PixelType.UnsignedByte);
  71. case GalTextureFormat.R16: return (PixelFormat.Red, PixelType.HalfFloat);
  72. case GalTextureFormat.R8: return (PixelFormat.Red, PixelType.UnsignedByte);
  73. }
  74. throw new NotImplementedException(Format.ToString());
  75. }
  76. public static InternalFormat GetCompressedTextureFormat(GalTextureFormat Format)
  77. {
  78. switch (Format)
  79. {
  80. case GalTextureFormat.BC7U: return InternalFormat.CompressedRgbaBptcUnorm;
  81. case GalTextureFormat.BC1: return InternalFormat.CompressedRgbaS3tcDxt1Ext;
  82. case GalTextureFormat.BC2: return InternalFormat.CompressedRgbaS3tcDxt3Ext;
  83. case GalTextureFormat.BC3: return InternalFormat.CompressedRgbaS3tcDxt5Ext;
  84. case GalTextureFormat.BC4: return InternalFormat.CompressedRedRgtc1;
  85. case GalTextureFormat.BC5: return InternalFormat.CompressedRgRgtc2;
  86. }
  87. throw new NotImplementedException(Format.ToString());
  88. }
  89. public static All GetTextureSwizzle(GalTextureSource Source)
  90. {
  91. switch (Source)
  92. {
  93. case GalTextureSource.Zero: return All.Zero;
  94. case GalTextureSource.Red: return All.Red;
  95. case GalTextureSource.Green: return All.Green;
  96. case GalTextureSource.Blue: return All.Blue;
  97. case GalTextureSource.Alpha: return All.Alpha;
  98. case GalTextureSource.OneInt: return All.One;
  99. case GalTextureSource.OneFloat: return All.One;
  100. }
  101. throw new ArgumentException(nameof(Source));
  102. }
  103. public static TextureWrapMode GetTextureWrapMode(GalTextureWrap Wrap)
  104. {
  105. switch (Wrap)
  106. {
  107. case GalTextureWrap.Repeat: return TextureWrapMode.Repeat;
  108. case GalTextureWrap.MirroredRepeat: return TextureWrapMode.MirroredRepeat;
  109. case GalTextureWrap.ClampToEdge: return TextureWrapMode.ClampToEdge;
  110. case GalTextureWrap.ClampToBorder: return TextureWrapMode.ClampToBorder;
  111. case GalTextureWrap.Clamp: return TextureWrapMode.Clamp;
  112. //TODO: Those needs extensions (and are currently wrong).
  113. case GalTextureWrap.MirrorClampToEdge: return TextureWrapMode.ClampToEdge;
  114. case GalTextureWrap.MirrorClampToBorder: return TextureWrapMode.ClampToBorder;
  115. case GalTextureWrap.MirrorClamp: return TextureWrapMode.Clamp;
  116. }
  117. throw new ArgumentException(nameof(Wrap));
  118. }
  119. public static TextureMinFilter GetTextureMinFilter(
  120. GalTextureFilter MinFilter,
  121. GalTextureMipFilter MipFilter)
  122. {
  123. //TODO: Mip (needs mipmap support first).
  124. switch (MinFilter)
  125. {
  126. case GalTextureFilter.Nearest: return TextureMinFilter.Nearest;
  127. case GalTextureFilter.Linear: return TextureMinFilter.Linear;
  128. }
  129. throw new ArgumentException(nameof(MinFilter));
  130. }
  131. public static TextureMagFilter GetTextureMagFilter(GalTextureFilter Filter)
  132. {
  133. switch (Filter)
  134. {
  135. case GalTextureFilter.Nearest: return TextureMagFilter.Nearest;
  136. case GalTextureFilter.Linear: return TextureMagFilter.Linear;
  137. }
  138. throw new ArgumentException(nameof(Filter));
  139. }
  140. public static BlendEquationMode GetBlendEquation(GalBlendEquation BlendEquation)
  141. {
  142. switch (BlendEquation)
  143. {
  144. case GalBlendEquation.FuncAdd: return BlendEquationMode.FuncAdd;
  145. case GalBlendEquation.FuncSubtract: return BlendEquationMode.FuncSubtract;
  146. case GalBlendEquation.FuncReverseSubtract: return BlendEquationMode.FuncReverseSubtract;
  147. case GalBlendEquation.Min: return BlendEquationMode.Min;
  148. case GalBlendEquation.Max: return BlendEquationMode.Max;
  149. }
  150. throw new ArgumentException(nameof(BlendEquation));
  151. }
  152. public static BlendingFactor GetBlendFactor(GalBlendFactor BlendFactor)
  153. {
  154. switch (BlendFactor)
  155. {
  156. case GalBlendFactor.Zero: return BlendingFactor.Zero;
  157. case GalBlendFactor.One: return BlendingFactor.One;
  158. case GalBlendFactor.SrcColor: return BlendingFactor.SrcColor;
  159. case GalBlendFactor.OneMinusSrcColor: return BlendingFactor.OneMinusSrcColor;
  160. case GalBlendFactor.DstColor: return BlendingFactor.DstColor;
  161. case GalBlendFactor.OneMinusDstColor: return BlendingFactor.OneMinusDstColor;
  162. case GalBlendFactor.SrcAlpha: return BlendingFactor.SrcAlpha;
  163. case GalBlendFactor.OneMinusSrcAlpha: return BlendingFactor.OneMinusSrcAlpha;
  164. case GalBlendFactor.DstAlpha: return BlendingFactor.DstAlpha;
  165. case GalBlendFactor.OneMinusDstAlpha: return BlendingFactor.OneMinusDstAlpha;
  166. case GalBlendFactor.OneMinusConstantColor: return BlendingFactor.OneMinusConstantColor;
  167. case GalBlendFactor.ConstantAlpha: return BlendingFactor.ConstantAlpha;
  168. case GalBlendFactor.OneMinusConstantAlpha: return BlendingFactor.OneMinusConstantAlpha;
  169. case GalBlendFactor.SrcAlphaSaturate: return BlendingFactor.SrcAlphaSaturate;
  170. case GalBlendFactor.Src1Color: return BlendingFactor.Src1Color;
  171. case GalBlendFactor.OneMinusSrc1Color: return (BlendingFactor)BlendingFactorSrc.OneMinusSrc1Color;
  172. case GalBlendFactor.Src1Alpha: return BlendingFactor.Src1Alpha;
  173. case GalBlendFactor.OneMinusSrc1Alpha: return (BlendingFactor)BlendingFactorSrc.OneMinusSrc1Alpha;
  174. case GalBlendFactor.ConstantColor:
  175. case GalBlendFactor.ConstantColorG80:
  176. return BlendingFactor.ConstantColor;
  177. }
  178. throw new ArgumentException(nameof(BlendFactor));
  179. }
  180. }
  181. }