OGLEnumConverter.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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.R16: return (PixelFormat.Red, PixelType.HalfFloat);
  63. case GalTextureFormat.R8: return (PixelFormat.Red, PixelType.UnsignedByte);
  64. }
  65. throw new NotImplementedException(Format.ToString());
  66. }
  67. public static PixelInternalFormat GetCompressedTextureFormat(GalTextureFormat Format)
  68. {
  69. switch (Format)
  70. {
  71. case GalTextureFormat.BC7U: return PixelInternalFormat.CompressedRgbaBptcUnorm;
  72. case GalTextureFormat.BC1: return PixelInternalFormat.CompressedRgbaS3tcDxt1Ext;
  73. case GalTextureFormat.BC2: return PixelInternalFormat.CompressedRgbaS3tcDxt3Ext;
  74. case GalTextureFormat.BC3: return PixelInternalFormat.CompressedRgbaS3tcDxt5Ext;
  75. case GalTextureFormat.BC4: return PixelInternalFormat.CompressedRedRgtc1;
  76. case GalTextureFormat.BC5: return PixelInternalFormat.CompressedRgRgtc2;
  77. }
  78. throw new NotImplementedException(Format.ToString());
  79. }
  80. public static All GetTextureSwizzle(GalTextureSource Source)
  81. {
  82. switch (Source)
  83. {
  84. case GalTextureSource.Zero: return All.Zero;
  85. case GalTextureSource.Red: return All.Red;
  86. case GalTextureSource.Green: return All.Green;
  87. case GalTextureSource.Blue: return All.Blue;
  88. case GalTextureSource.Alpha: return All.Alpha;
  89. case GalTextureSource.OneInt: return All.One;
  90. case GalTextureSource.OneFloat: return All.One;
  91. }
  92. throw new ArgumentException(nameof(Source));
  93. }
  94. public static TextureWrapMode GetTextureWrapMode(GalTextureWrap Wrap)
  95. {
  96. switch (Wrap)
  97. {
  98. case GalTextureWrap.Repeat: return TextureWrapMode.Repeat;
  99. case GalTextureWrap.MirroredRepeat: return TextureWrapMode.MirroredRepeat;
  100. case GalTextureWrap.ClampToEdge: return TextureWrapMode.ClampToEdge;
  101. case GalTextureWrap.ClampToBorder: return TextureWrapMode.ClampToBorder;
  102. case GalTextureWrap.Clamp: return TextureWrapMode.Clamp;
  103. //TODO: Those needs extensions (and are currently wrong).
  104. case GalTextureWrap.MirrorClampToEdge: return TextureWrapMode.ClampToEdge;
  105. case GalTextureWrap.MirrorClampToBorder: return TextureWrapMode.ClampToBorder;
  106. case GalTextureWrap.MirrorClamp: return TextureWrapMode.Clamp;
  107. }
  108. throw new ArgumentException(nameof(Wrap));
  109. }
  110. public static TextureMinFilter GetTextureMinFilter(
  111. GalTextureFilter MinFilter,
  112. GalTextureMipFilter MipFilter)
  113. {
  114. //TODO: Mip (needs mipmap support first).
  115. switch (MinFilter)
  116. {
  117. case GalTextureFilter.Nearest: return TextureMinFilter.Nearest;
  118. case GalTextureFilter.Linear: return TextureMinFilter.Linear;
  119. }
  120. throw new ArgumentException(nameof(MinFilter));
  121. }
  122. public static TextureMagFilter GetTextureMagFilter(GalTextureFilter Filter)
  123. {
  124. switch (Filter)
  125. {
  126. case GalTextureFilter.Nearest: return TextureMagFilter.Nearest;
  127. case GalTextureFilter.Linear: return TextureMagFilter.Linear;
  128. }
  129. throw new ArgumentException(nameof(Filter));
  130. }
  131. public static BlendEquationMode GetBlendEquation(GalBlendEquation BlendEquation)
  132. {
  133. switch (BlendEquation)
  134. {
  135. case GalBlendEquation.FuncAdd: return BlendEquationMode.FuncAdd;
  136. case GalBlendEquation.FuncSubtract: return BlendEquationMode.FuncSubtract;
  137. case GalBlendEquation.FuncReverseSubtract: return BlendEquationMode.FuncReverseSubtract;
  138. case GalBlendEquation.Min: return BlendEquationMode.Min;
  139. case GalBlendEquation.Max: return BlendEquationMode.Max;
  140. }
  141. throw new ArgumentException(nameof(BlendEquation));
  142. }
  143. public static BlendingFactorSrc GetBlendFactorSrc(GalBlendFactor BlendFactor)
  144. {
  145. switch (BlendFactor)
  146. {
  147. case GalBlendFactor.Zero: return BlendingFactorSrc.Zero;
  148. case GalBlendFactor.One: return BlendingFactorSrc.One;
  149. case GalBlendFactor.SrcColor: return BlendingFactorSrc.SrcColor;
  150. case GalBlendFactor.OneMinusSrcColor: return BlendingFactorSrc.OneMinusSrcColor;
  151. case GalBlendFactor.DstColor: return BlendingFactorSrc.DstColor;
  152. case GalBlendFactor.OneMinusDstColor: return BlendingFactorSrc.OneMinusDstColor;
  153. case GalBlendFactor.SrcAlpha: return BlendingFactorSrc.SrcAlpha;
  154. case GalBlendFactor.OneMinusSrcAlpha: return BlendingFactorSrc.OneMinusSrcAlpha;
  155. case GalBlendFactor.DstAlpha: return BlendingFactorSrc.DstAlpha;
  156. case GalBlendFactor.OneMinusDstAlpha: return BlendingFactorSrc.OneMinusDstAlpha;
  157. case GalBlendFactor.ConstantColor: return BlendingFactorSrc.ConstantColor;
  158. case GalBlendFactor.OneMinusConstantColor: return BlendingFactorSrc.OneMinusConstantColor;
  159. case GalBlendFactor.ConstantAlpha: return BlendingFactorSrc.ConstantAlpha;
  160. case GalBlendFactor.OneMinusConstantAlpha: return BlendingFactorSrc.OneMinusConstantAlpha;
  161. case GalBlendFactor.SrcAlphaSaturate: return BlendingFactorSrc.SrcAlphaSaturate;
  162. case GalBlendFactor.Src1Color: return BlendingFactorSrc.Src1Color;
  163. case GalBlendFactor.OneMinusSrc1Color: return BlendingFactorSrc.OneMinusSrc1Color;
  164. case GalBlendFactor.Src1Alpha: return BlendingFactorSrc.Src1Alpha;
  165. case GalBlendFactor.OneMinusSrc1Alpha: return BlendingFactorSrc.OneMinusSrc1Alpha;
  166. }
  167. throw new ArgumentException(nameof(BlendFactor));
  168. }
  169. public static BlendingFactorDest GetBlendFactorDst(GalBlendFactor BlendFactor)
  170. {
  171. switch (BlendFactor)
  172. {
  173. case GalBlendFactor.Zero: return BlendingFactorDest.Zero;
  174. case GalBlendFactor.One: return BlendingFactorDest.One;
  175. case GalBlendFactor.SrcColor: return BlendingFactorDest.SrcColor;
  176. case GalBlendFactor.OneMinusSrcColor: return BlendingFactorDest.OneMinusSrcColor;
  177. case GalBlendFactor.DstColor: return BlendingFactorDest.DstColor;
  178. case GalBlendFactor.OneMinusDstColor: return BlendingFactorDest.OneMinusDstColor;
  179. case GalBlendFactor.SrcAlpha: return BlendingFactorDest.SrcAlpha;
  180. case GalBlendFactor.OneMinusSrcAlpha: return BlendingFactorDest.OneMinusSrcAlpha;
  181. case GalBlendFactor.DstAlpha: return BlendingFactorDest.DstAlpha;
  182. case GalBlendFactor.OneMinusDstAlpha: return BlendingFactorDest.OneMinusDstAlpha;
  183. case GalBlendFactor.ConstantColor: return BlendingFactorDest.ConstantColor;
  184. case GalBlendFactor.OneMinusConstantColor: return BlendingFactorDest.OneMinusConstantColor;
  185. case GalBlendFactor.ConstantAlpha: return BlendingFactorDest.ConstantAlpha;
  186. case GalBlendFactor.OneMinusConstantAlpha: return BlendingFactorDest.OneMinusConstantAlpha;
  187. case GalBlendFactor.SrcAlphaSaturate: return BlendingFactorDest.SrcAlphaSaturate;
  188. case GalBlendFactor.Src1Color: return BlendingFactorDest.Src1Color;
  189. case GalBlendFactor.OneMinusSrc1Color: return BlendingFactorDest.OneMinusSrc1Color;
  190. case GalBlendFactor.Src1Alpha: return BlendingFactorDest.Src1Alpha;
  191. case GalBlendFactor.OneMinusSrc1Alpha: return BlendingFactorDest.OneMinusSrc1Alpha;
  192. }
  193. throw new ArgumentException(nameof(BlendFactor));
  194. }
  195. }
  196. }