gfxGLEnumTranslate.cpp 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "platform/platform.h"
  23. #include "gfx/gl/gfxGLEnumTranslate.h"
  24. GLenum GFXGLPrimType[GFXPT_COUNT];
  25. GLenum GFXGLBlend[GFXBlend_COUNT];
  26. GLenum GFXGLBlendOp[GFXBlendOp_COUNT];
  27. GLenum GFXGLSamplerState[GFXSAMP_COUNT];
  28. GLenum GFXGLTextureFilter[GFXTextureFilter_COUNT];
  29. GLenum GFXGLTextureAddress[GFXAddress_COUNT];
  30. GLenum GFXGLCmpFunc[GFXCmp_COUNT];
  31. GLenum GFXGLStencilOp[GFXStencilOp_COUNT];
  32. GLenum GFXGLTextureInternalFormat[GFXFormat_COUNT];
  33. GLenum GFXGLTextureFormat[GFXFormat_COUNT];
  34. GLenum GFXGLTextureType[GFXFormat_COUNT];
  35. GLenum GFXGLBufferType[GFXBufferType_COUNT];
  36. GLenum GFXGLCullMode[GFXCull_COUNT];
  37. GLenum GFXGLFillMode[GFXFill_COUNT];
  38. void GFXGLEnumTranslate::init()
  39. {
  40. // Buffer types
  41. GFXGLBufferType[GFXBufferTypeStatic] = GL_STATIC_DRAW;
  42. GFXGLBufferType[GFXBufferTypeDynamic] = GL_DYNAMIC_DRAW;
  43. GFXGLBufferType[GFXBufferTypeVolatile] = GL_STREAM_DRAW;
  44. // Primitives
  45. GFXGLPrimType[GFXPointList] = GL_POINTS;
  46. GFXGLPrimType[GFXLineList] = GL_LINES;
  47. GFXGLPrimType[GFXLineStrip] = GL_LINE_STRIP;
  48. GFXGLPrimType[GFXTriangleList] = GL_TRIANGLES;
  49. GFXGLPrimType[GFXTriangleStrip] = GL_TRIANGLE_STRIP;
  50. GFXGLPrimType[GFXTriangleFan] = GL_TRIANGLE_FAN;
  51. // Blend
  52. GFXGLBlend[GFXBlendZero] = GL_ZERO;
  53. GFXGLBlend[GFXBlendOne] = GL_ONE;
  54. GFXGLBlend[GFXBlendSrcColor] = GL_SRC_COLOR;
  55. GFXGLBlend[GFXBlendInvSrcColor] = GL_ONE_MINUS_SRC_COLOR;
  56. GFXGLBlend[GFXBlendSrcAlpha] = GL_SRC_ALPHA;
  57. GFXGLBlend[GFXBlendInvSrcAlpha] = GL_ONE_MINUS_SRC_ALPHA;
  58. GFXGLBlend[GFXBlendDestAlpha] = GL_DST_ALPHA;
  59. GFXGLBlend[GFXBlendInvDestAlpha] = GL_ONE_MINUS_DST_ALPHA;
  60. GFXGLBlend[GFXBlendDestColor] = GL_DST_COLOR;
  61. GFXGLBlend[GFXBlendInvDestColor] = GL_ONE_MINUS_DST_COLOR;
  62. GFXGLBlend[GFXBlendSrcAlphaSat] = GL_SRC_ALPHA_SATURATE;
  63. // Blend op
  64. GFXGLBlendOp[GFXBlendOpAdd] = GL_FUNC_ADD;
  65. GFXGLBlendOp[GFXBlendOpSubtract] = GL_FUNC_SUBTRACT;
  66. GFXGLBlendOp[GFXBlendOpRevSubtract] = GL_FUNC_REVERSE_SUBTRACT;
  67. GFXGLBlendOp[GFXBlendOpMin] = GL_MIN;
  68. GFXGLBlendOp[GFXBlendOpMax] = GL_MAX;
  69. // Sampler
  70. GFXGLSamplerState[GFXSAMPMagFilter] = GL_TEXTURE_MAG_FILTER;
  71. GFXGLSamplerState[GFXSAMPMinFilter] = GL_TEXTURE_MIN_FILTER;
  72. GFXGLSamplerState[GFXSAMPAddressU] = GL_TEXTURE_WRAP_S;
  73. GFXGLSamplerState[GFXSAMPAddressV] = GL_TEXTURE_WRAP_T;
  74. GFXGLSamplerState[GFXSAMPAddressW] = GL_TEXTURE_WRAP_R;
  75. GFXGLSamplerState[GFXSAMPMipMapLODBias] = GL_TEXTURE_LOD_BIAS;
  76. // Comparison
  77. GFXGLCmpFunc[GFXCmpNever] = GL_NEVER;
  78. GFXGLCmpFunc[GFXCmpLess] = GL_LESS;
  79. GFXGLCmpFunc[GFXCmpEqual] = GL_EQUAL;
  80. GFXGLCmpFunc[GFXCmpLessEqual] = GL_LEQUAL;
  81. GFXGLCmpFunc[GFXCmpGreater] = GL_GREATER;
  82. GFXGLCmpFunc[GFXCmpNotEqual] = GL_NOTEQUAL;
  83. GFXGLCmpFunc[GFXCmpGreaterEqual] = GL_GEQUAL;
  84. GFXGLCmpFunc[GFXCmpAlways] = GL_ALWAYS;
  85. GFXGLTextureFilter[GFXTextureFilterNone] = GL_NEAREST;
  86. GFXGLTextureFilter[GFXTextureFilterPoint] = GL_NEAREST;
  87. GFXGLTextureFilter[GFXTextureFilterLinear] = GL_LINEAR;
  88. GFXGLTextureFilter[GFXTextureFilterAnisotropic] = GL_LINEAR;
  89. GFXGLTextureFilter[GFXTextureFilterPyramidalQuad] = GL_LINEAR;
  90. GFXGLTextureFilter[GFXTextureFilterGaussianQuad] = GL_LINEAR;
  91. GFXGLTextureAddress[GFXAddressWrap] = GL_REPEAT;
  92. GFXGLTextureAddress[GFXAddressMirror] = GL_REPEAT;
  93. GFXGLTextureAddress[GFXAddressClamp] = GL_CLAMP_TO_EDGE;
  94. GFXGLTextureAddress[GFXAddressBorder] = GL_REPEAT;
  95. GFXGLTextureAddress[GFXAddressMirrorOnce] = GL_REPEAT;
  96. // Stencil ops
  97. GFXGLStencilOp[GFXStencilOpKeep] = GL_KEEP;
  98. GFXGLStencilOp[GFXStencilOpZero] = GL_ZERO;
  99. GFXGLStencilOp[GFXStencilOpReplace] = GL_REPLACE;
  100. GFXGLStencilOp[GFXStencilOpIncrSat] = GL_INCR;
  101. GFXGLStencilOp[GFXStencilOpDecrSat] = GL_DECR;
  102. GFXGLStencilOp[GFXStencilOpInvert] = GL_INVERT;
  103. GFXGLStencilOp[GFXStencilOpIncr] = GL_INCR_WRAP;
  104. GFXGLStencilOp[GFXStencilOpDecr] = GL_DECR_WRAP;
  105. // Texture formats
  106. GFXGLTextureInternalFormat[GFXFormatA8] = GL_ALPHA8;
  107. GFXGLTextureInternalFormat[GFXFormatL8] = GL_LUMINANCE8;
  108. GFXGLTextureInternalFormat[GFXFormatR5G6B5] = GL_RGB5_A1; // OpenGL has no R5G6B5 format.
  109. GFXGLTextureInternalFormat[GFXFormatR5G5B5A1] = GL_RGB5_A1;
  110. GFXGLTextureInternalFormat[GFXFormatR5G5B5X1] = GL_RGB5_A1;
  111. GFXGLTextureInternalFormat[GFXFormatL16] = GL_LUMINANCE16;
  112. GFXGLTextureInternalFormat[GFXFormatR16F] = GL_ZERO;
  113. GFXGLTextureInternalFormat[GFXFormatD16] = GL_DEPTH_COMPONENT;
  114. GFXGLTextureInternalFormat[GFXFormatR8G8B8] = GL_RGB8;
  115. GFXGLTextureInternalFormat[GFXFormatR8G8B8A8] = GL_RGBA8;
  116. GFXGLTextureInternalFormat[GFXFormatR8G8B8X8] = GL_RGBA8;
  117. GFXGLTextureInternalFormat[GFXFormatR32F] = GL_ZERO;
  118. GFXGLTextureInternalFormat[GFXFormatR16G16] = GL_RGBA16;
  119. GFXGLTextureInternalFormat[GFXFormatR16G16F] = GL_ZERO;
  120. GFXGLTextureInternalFormat[GFXFormatR10G10B10A2] = GL_ZERO;
  121. GFXGLTextureInternalFormat[GFXFormatD32] = GL_DEPTH_COMPONENT32;
  122. GFXGLTextureInternalFormat[GFXFormatD24X8] = GL_DEPTH_COMPONENT24;
  123. GFXGLTextureInternalFormat[GFXFormatD24S8] = GL_DEPTH_COMPONENT24;
  124. GFXGLTextureInternalFormat[GFXFormatR16G16B16A16] = GL_ZERO;
  125. GFXGLTextureInternalFormat[GFXFormatR16G16B16A16F] = GL_ZERO;
  126. GFXGLTextureInternalFormat[GFXFormatR32G32B32A32F] = GL_ZERO;
  127. GFXGLTextureInternalFormat[GFXFormatDXT1] = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
  128. GFXGLTextureInternalFormat[GFXFormatDXT2] = GL_ZERO;
  129. GFXGLTextureInternalFormat[GFXFormatDXT3] = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
  130. GFXGLTextureInternalFormat[GFXFormatDXT4] = GL_ZERO;
  131. GFXGLTextureInternalFormat[GFXFormatDXT5] = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
  132. GFXGLTextureFormat[GFXFormatA8] = GL_ALPHA;
  133. GFXGLTextureFormat[GFXFormatL8] = GL_LUMINANCE;
  134. GFXGLTextureFormat[GFXFormatR5G6B5] = GL_RGBA;
  135. GFXGLTextureFormat[GFXFormatR5G5B5A1] = GL_RGBA;
  136. GFXGLTextureFormat[GFXFormatR5G5B5X1] = GL_RGBA;
  137. GFXGLTextureFormat[GFXFormatL16] = GL_LUMINANCE;
  138. GFXGLTextureFormat[GFXFormatR16F] = GL_ZERO;
  139. GFXGLTextureFormat[GFXFormatD16] = GL_DEPTH_COMPONENT;
  140. GFXGLTextureFormat[GFXFormatR8G8B8] = GL_RGB;
  141. GFXGLTextureFormat[GFXFormatR8G8B8A8] = GL_BGRA;
  142. GFXGLTextureFormat[GFXFormatR8G8B8X8] = GL_BGRA;
  143. GFXGLTextureFormat[GFXFormatR32F] = GL_RGBA;
  144. GFXGLTextureFormat[GFXFormatR16G16] = GL_RGBA;
  145. GFXGLTextureFormat[GFXFormatR16G16F] = GL_ZERO;
  146. GFXGLTextureFormat[GFXFormatR10G10B10A2] = GL_RGBA;
  147. GFXGLTextureFormat[GFXFormatD32] = GL_DEPTH_COMPONENT;
  148. GFXGLTextureFormat[GFXFormatD24X8] = GL_DEPTH_COMPONENT;
  149. GFXGLTextureFormat[GFXFormatD24S8] = GL_DEPTH_COMPONENT;
  150. GFXGLTextureFormat[GFXFormatR16G16B16A16] = GL_RGBA;
  151. GFXGLTextureFormat[GFXFormatR16G16B16A16F] = GL_RGBA;
  152. GFXGLTextureFormat[GFXFormatR32G32B32A32F] = GL_RGBA;
  153. GFXGLTextureFormat[GFXFormatDXT1] = GL_RGBA;
  154. GFXGLTextureFormat[GFXFormatDXT2] = GL_ZERO;
  155. GFXGLTextureFormat[GFXFormatDXT3] = GL_RGBA;
  156. GFXGLTextureFormat[GFXFormatDXT4] = GL_ZERO;
  157. GFXGLTextureFormat[GFXFormatDXT5] = GL_RGBA;
  158. GFXGLTextureType[GFXFormatA8] = GL_UNSIGNED_BYTE;
  159. GFXGLTextureType[GFXFormatL8] = GL_UNSIGNED_BYTE;
  160. GFXGLTextureType[GFXFormatR5G6B5] = GL_UNSIGNED_BYTE;
  161. GFXGLTextureType[GFXFormatR5G5B5A1] = GL_UNSIGNED_BYTE;
  162. GFXGLTextureType[GFXFormatR5G5B5X1] = GL_UNSIGNED_BYTE;
  163. GFXGLTextureType[GFXFormatL16] = GL_UNSIGNED_SHORT;
  164. GFXGLTextureType[GFXFormatR16F] = GL_ZERO;
  165. GFXGLTextureType[GFXFormatD16] = GL_UNSIGNED_SHORT;
  166. GFXGLTextureType[GFXFormatR8G8B8] = GL_UNSIGNED_BYTE;
  167. GFXGLTextureType[GFXFormatR8G8B8A8] = GL_UNSIGNED_BYTE;
  168. GFXGLTextureType[GFXFormatR8G8B8X8] = GL_UNSIGNED_BYTE;
  169. GFXGLTextureType[GFXFormatR32F] = GL_FLOAT;
  170. GFXGLTextureType[GFXFormatR16G16] = GL_UNSIGNED_SHORT;
  171. GFXGLTextureType[GFXFormatR16G16F] = GL_FLOAT;
  172. GFXGLTextureType[GFXFormatR10G10B10A2] = GL_UNSIGNED_SHORT;
  173. GFXGLTextureType[GFXFormatD32] = GL_UNSIGNED_BYTE;
  174. GFXGLTextureType[GFXFormatD24X8] = GL_UNSIGNED_BYTE;
  175. GFXGLTextureType[GFXFormatD24S8] = GL_UNSIGNED_BYTE;
  176. GFXGLTextureType[GFXFormatR16G16B16A16] = GL_UNSIGNED_SHORT;
  177. GFXGLTextureType[GFXFormatR16G16B16A16F] = GL_FLOAT;
  178. GFXGLTextureType[GFXFormatR32G32B32A32F] = GL_FLOAT;
  179. GFXGLTextureType[GFXFormatDXT1] = GL_UNSIGNED_BYTE;
  180. GFXGLTextureType[GFXFormatDXT2] = GL_ZERO;
  181. GFXGLTextureType[GFXFormatDXT3] = GL_UNSIGNED_BYTE;
  182. GFXGLTextureType[GFXFormatDXT4] = GL_ZERO;
  183. GFXGLTextureType[GFXFormatDXT5] = GL_UNSIGNED_BYTE;
  184. // Cull
  185. GFXGLCullMode[GFXCullNone] = GL_BACK;
  186. GFXGLCullMode[GFXCullCW] = GL_BACK;
  187. GFXGLCullMode[GFXCullCCW] = GL_FRONT;
  188. // Fill
  189. GFXGLFillMode[GFXFillPoint] = GL_POINT;
  190. GFXGLFillMode[GFXFillWireframe] = GL_LINE;
  191. GFXGLFillMode[GFXFillSolid] = GL_FILL;
  192. }