OGLEnumConverter.cs 12 KB

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