gfxGLEnumTranslate.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. GLint* GFXGLTextureSwizzle[GFXFormat_COUNT];
  36. GLenum GFXGLBufferType[GFXBufferType_COUNT];
  37. GLenum GFXGLCullMode[GFXCull_COUNT];
  38. GLenum GFXGLFillMode[GFXFill_COUNT];
  39. void GFXGLEnumTranslate::init()
  40. {
  41. // Buffer types
  42. GFXGLBufferType[GFXBufferTypeStatic] = GL_STATIC_DRAW;
  43. GFXGLBufferType[GFXBufferTypeDynamic] = GL_DYNAMIC_DRAW;
  44. GFXGLBufferType[GFXBufferTypeVolatile] = GL_STREAM_DRAW;
  45. GFXGLBufferType[GFXBufferTypeImmutable] = GL_STATIC_DRAW;
  46. // Primitives
  47. GFXGLPrimType[GFXPointList] = GL_POINTS;
  48. GFXGLPrimType[GFXLineList] = GL_LINES;
  49. GFXGLPrimType[GFXLineStrip] = GL_LINE_STRIP;
  50. GFXGLPrimType[GFXTriangleList] = GL_TRIANGLES;
  51. GFXGLPrimType[GFXTriangleStrip] = GL_TRIANGLE_STRIP;
  52. // Blend
  53. GFXGLBlend[GFXBlendZero] = GL_ZERO;
  54. GFXGLBlend[GFXBlendOne] = GL_ONE;
  55. GFXGLBlend[GFXBlendSrcColor] = GL_SRC_COLOR;
  56. GFXGLBlend[GFXBlendInvSrcColor] = GL_ONE_MINUS_SRC_COLOR;
  57. GFXGLBlend[GFXBlendSrcAlpha] = GL_SRC_ALPHA;
  58. GFXGLBlend[GFXBlendInvSrcAlpha] = GL_ONE_MINUS_SRC_ALPHA;
  59. GFXGLBlend[GFXBlendDestAlpha] = GL_DST_ALPHA;
  60. GFXGLBlend[GFXBlendInvDestAlpha] = GL_ONE_MINUS_DST_ALPHA;
  61. GFXGLBlend[GFXBlendDestColor] = GL_DST_COLOR;
  62. GFXGLBlend[GFXBlendInvDestColor] = GL_ONE_MINUS_DST_COLOR;
  63. GFXGLBlend[GFXBlendSrcAlphaSat] = GL_SRC_ALPHA_SATURATE;
  64. // Blend op
  65. GFXGLBlendOp[GFXBlendOpAdd] = GL_FUNC_ADD;
  66. GFXGLBlendOp[GFXBlendOpSubtract] = GL_FUNC_SUBTRACT;
  67. GFXGLBlendOp[GFXBlendOpRevSubtract] = GL_FUNC_REVERSE_SUBTRACT;
  68. GFXGLBlendOp[GFXBlendOpMin] = GL_MIN;
  69. GFXGLBlendOp[GFXBlendOpMax] = GL_MAX;
  70. // Sampler
  71. GFXGLSamplerState[GFXSAMPMagFilter] = GL_TEXTURE_MAG_FILTER;
  72. GFXGLSamplerState[GFXSAMPMinFilter] = GL_TEXTURE_MIN_FILTER;
  73. GFXGLSamplerState[GFXSAMPAddressU] = GL_TEXTURE_WRAP_S;
  74. GFXGLSamplerState[GFXSAMPAddressV] = GL_TEXTURE_WRAP_T;
  75. GFXGLSamplerState[GFXSAMPAddressW] = GL_TEXTURE_WRAP_R;
  76. GFXGLSamplerState[GFXSAMPMipMapLODBias] = GL_TEXTURE_LOD_BIAS;
  77. // Comparison
  78. GFXGLCmpFunc[GFXCmpNever] = GL_NEVER;
  79. GFXGLCmpFunc[GFXCmpLess] = GL_LESS;
  80. GFXGLCmpFunc[GFXCmpEqual] = GL_EQUAL;
  81. GFXGLCmpFunc[GFXCmpLessEqual] = GL_LEQUAL;
  82. GFXGLCmpFunc[GFXCmpGreater] = GL_GREATER;
  83. GFXGLCmpFunc[GFXCmpNotEqual] = GL_NOTEQUAL;
  84. GFXGLCmpFunc[GFXCmpGreaterEqual] = GL_GEQUAL;
  85. GFXGLCmpFunc[GFXCmpAlways] = GL_ALWAYS;
  86. GFXGLTextureFilter[GFXTextureFilterNone] = GL_NEAREST;
  87. GFXGLTextureFilter[GFXTextureFilterPoint] = GL_NEAREST;
  88. GFXGLTextureFilter[GFXTextureFilterLinear] = GL_LINEAR;
  89. GFXGLTextureFilter[GFXTextureFilterAnisotropic] = GL_LINEAR;
  90. GFXGLTextureFilter[GFXTextureFilterPyramidalQuad] = GL_LINEAR;
  91. GFXGLTextureFilter[GFXTextureFilterGaussianQuad] = GL_LINEAR;
  92. GFXGLTextureAddress[GFXAddressWrap] = GL_REPEAT;
  93. GFXGLTextureAddress[GFXAddressMirror] = GL_REPEAT;
  94. GFXGLTextureAddress[GFXAddressClamp] = GL_CLAMP_TO_EDGE;
  95. GFXGLTextureAddress[GFXAddressBorder] = GL_REPEAT;
  96. GFXGLTextureAddress[GFXAddressMirrorOnce] = GL_REPEAT;
  97. // Stencil ops
  98. GFXGLStencilOp[GFXStencilOpKeep] = GL_KEEP;
  99. GFXGLStencilOp[GFXStencilOpZero] = GL_ZERO;
  100. GFXGLStencilOp[GFXStencilOpReplace] = GL_REPLACE;
  101. GFXGLStencilOp[GFXStencilOpIncrSat] = GL_INCR;
  102. GFXGLStencilOp[GFXStencilOpDecrSat] = GL_DECR;
  103. GFXGLStencilOp[GFXStencilOpInvert] = GL_INVERT;
  104. GFXGLStencilOp[GFXStencilOpIncr] = GL_INCR_WRAP;
  105. GFXGLStencilOp[GFXStencilOpDecr] = GL_DECR_WRAP;
  106. // Texture formats
  107. for(int i = 0; i < GFXFormat_COUNT; ++i)
  108. {
  109. GFXGLTextureInternalFormat[i] = GL_NONE;
  110. GFXGLTextureFormat[i] = GL_NONE;
  111. GFXGLTextureType[i] = GL_NONE;
  112. GFXGLTextureSwizzle[i] = NULL;
  113. }
  114. GFXGLTextureInternalFormat[GFXFormatA8] = GL_R8;
  115. GFXGLTextureInternalFormat[GFXFormatL8] = GL_R8;
  116. GFXGLTextureInternalFormat[GFXFormatR5G5B5A1] = GL_RGB5_A1;
  117. GFXGLTextureInternalFormat[GFXFormatR5G5B5X1] = GL_RGB5_A1;
  118. GFXGLTextureInternalFormat[GFXFormatL16] = GL_R16;
  119. GFXGLTextureInternalFormat[GFXFormatD16] = GL_DEPTH_COMPONENT16;
  120. GFXGLTextureInternalFormat[GFXFormatR8G8B8] = GL_RGB8;
  121. GFXGLTextureInternalFormat[GFXFormatR8G8B8A8] = GL_RGBA8;
  122. GFXGLTextureInternalFormat[GFXFormatR8G8B8X8] = GL_RGBA8;
  123. GFXGLTextureInternalFormat[GFXFormatB8G8R8A8] = GL_RGBA8;
  124. GFXGLTextureInternalFormat[GFXFormatR10G10B10A2] = GL_RGB10_A2;
  125. GFXGLTextureInternalFormat[GFXFormatD32] = GL_DEPTH_COMPONENT32;
  126. GFXGLTextureInternalFormat[GFXFormatD24X8] = GL_DEPTH24_STENCIL8;
  127. GFXGLTextureInternalFormat[GFXFormatD24S8] = GL_DEPTH24_STENCIL8;
  128. GFXGLTextureInternalFormat[GFXFormatR16G16B16A16] = GL_RGBA16;
  129. GFXGLTextureInternalFormat[GFXFormatDXT1] = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
  130. GFXGLTextureInternalFormat[GFXFormatDXT2] = GL_ZERO;
  131. GFXGLTextureInternalFormat[GFXFormatDXT3] = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
  132. GFXGLTextureInternalFormat[GFXFormatDXT4] = GL_ZERO;
  133. GFXGLTextureInternalFormat[GFXFormatDXT5] = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
  134. GFXGLTextureFormat[GFXFormatA8] = GL_RED;
  135. GFXGLTextureFormat[GFXFormatL8] = GL_RED;
  136. GFXGLTextureFormat[GFXFormatR5G5B5A1] = GL_RGBA;
  137. GFXGLTextureFormat[GFXFormatR5G5B5X1] = GL_RGBA;
  138. GFXGLTextureFormat[GFXFormatL16] = GL_RED;
  139. GFXGLTextureFormat[GFXFormatD16] = GL_DEPTH_COMPONENT;
  140. GFXGLTextureFormat[GFXFormatR8G8B8] = GL_RGB;
  141. GFXGLTextureFormat[GFXFormatR8G8B8A8] = GL_RGBA;
  142. GFXGLTextureFormat[GFXFormatR8G8B8X8] = GL_RGBA;
  143. GFXGLTextureFormat[GFXFormatB8G8R8A8] = GL_BGRA;
  144. GFXGLTextureFormat[GFXFormatR10G10B10A2] = GL_RGBA;
  145. GFXGLTextureFormat[GFXFormatD32] = GL_DEPTH_COMPONENT;
  146. GFXGLTextureFormat[GFXFormatD24X8] = GL_DEPTH_STENCIL;
  147. GFXGLTextureFormat[GFXFormatD24S8] = GL_DEPTH_STENCIL;
  148. GFXGLTextureFormat[GFXFormatR16G16B16A16] = GL_RGBA;
  149. GFXGLTextureFormat[GFXFormatDXT1] = GL_RGBA;
  150. GFXGLTextureFormat[GFXFormatDXT2] = GL_ZERO;
  151. GFXGLTextureFormat[GFXFormatDXT3] = GL_RGBA;
  152. GFXGLTextureFormat[GFXFormatDXT4] = GL_ZERO;
  153. GFXGLTextureFormat[GFXFormatDXT5] = GL_RGBA;
  154. GFXGLTextureType[GFXFormatA8] = GL_UNSIGNED_BYTE;
  155. GFXGLTextureType[GFXFormatL8] = GL_UNSIGNED_BYTE;
  156. GFXGLTextureType[GFXFormatR5G5B5A1] = GL_UNSIGNED_SHORT_5_5_5_1;
  157. GFXGLTextureType[GFXFormatR5G5B5X1] = GL_UNSIGNED_SHORT_5_5_5_1;
  158. GFXGLTextureType[GFXFormatL16] = GL_UNSIGNED_SHORT;
  159. GFXGLTextureType[GFXFormatD16] = GL_UNSIGNED_SHORT;
  160. GFXGLTextureType[GFXFormatR8G8B8] = GL_UNSIGNED_BYTE;
  161. GFXGLTextureType[GFXFormatR8G8B8A8] = GL_UNSIGNED_BYTE;
  162. GFXGLTextureType[GFXFormatR8G8B8X8] = GL_UNSIGNED_BYTE;
  163. GFXGLTextureType[GFXFormatB8G8R8A8] = GL_UNSIGNED_BYTE;;
  164. GFXGLTextureType[GFXFormatR10G10B10A2] = GL_UNSIGNED_INT_10_10_10_2;
  165. GFXGLTextureType[GFXFormatD32] = GL_UNSIGNED_INT;
  166. GFXGLTextureType[GFXFormatD24X8] = GL_UNSIGNED_INT_24_8;
  167. GFXGLTextureType[GFXFormatD24S8] = GL_UNSIGNED_INT_24_8;
  168. GFXGLTextureType[GFXFormatR16G16B16A16] = GL_UNSIGNED_SHORT;
  169. GFXGLTextureType[GFXFormatDXT1] = GL_UNSIGNED_BYTE;
  170. GFXGLTextureType[GFXFormatDXT2] = GL_ZERO;
  171. GFXGLTextureType[GFXFormatDXT3] = GL_UNSIGNED_BYTE;
  172. GFXGLTextureType[GFXFormatDXT4] = GL_ZERO;
  173. GFXGLTextureType[GFXFormatDXT5] = GL_UNSIGNED_BYTE;
  174. GFXGLTextureType[GFXFormatR8G8B8A8_SRGB] = GL_SRGB8_ALPHA8;
  175. static GLint Swizzle_GFXFormatA8[] = { GL_NONE, GL_NONE, GL_NONE, GL_RED };
  176. static GLint Swizzle_GFXFormatL[] = { GL_RED, GL_RED, GL_RED, GL_ALPHA };
  177. GFXGLTextureSwizzle[GFXFormatA8] = Swizzle_GFXFormatA8; // old GL_ALPHA8
  178. GFXGLTextureSwizzle[GFXFormatL8] = Swizzle_GFXFormatL; // old GL_LUMINANCE8
  179. GFXGLTextureSwizzle[GFXFormatL16] = Swizzle_GFXFormatL; // old GL_LUMINANCE16
  180. GFXGLTextureInternalFormat[GFXFormatR32F] = GL_R32F;
  181. GFXGLTextureFormat[GFXFormatR32F] = GL_RED;
  182. GFXGLTextureType[GFXFormatR32F] = GL_FLOAT;
  183. GFXGLTextureInternalFormat[GFXFormatR32G32B32A32F] = GL_RGBA32F_ARB;
  184. GFXGLTextureFormat[GFXFormatR32G32B32A32F] = GL_RGBA;
  185. GFXGLTextureType[GFXFormatR32G32B32A32F] = GL_FLOAT;
  186. GFXGLTextureInternalFormat[GFXFormatR16F] = GL_R16F;
  187. GFXGLTextureFormat[GFXFormatR16F] = GL_RED;
  188. GFXGLTextureType[GFXFormatR16F] = GL_HALF_FLOAT_ARB;
  189. GFXGLTextureInternalFormat[GFXFormatR16G16F] = GL_RG16F;
  190. GFXGLTextureFormat[GFXFormatR16G16F] = GL_RG;
  191. GFXGLTextureType[GFXFormatR16G16F] = GL_HALF_FLOAT_ARB;
  192. GFXGLTextureInternalFormat[GFXFormatR16G16B16A16F] = GL_RGBA16F_ARB;
  193. GFXGLTextureFormat[GFXFormatR16G16B16A16F] = GL_RGBA;
  194. GFXGLTextureType[GFXFormatR16G16B16A16F] = GL_HALF_FLOAT_ARB;
  195. if( gglHasExtension(ARB_ES2_compatibility) )
  196. {
  197. GFXGLTextureInternalFormat[GFXFormatR5G6B5] = GL_RGB5_A1;
  198. GFXGLTextureFormat[GFXFormatR5G6B5] = GL_RGBA;
  199. GFXGLTextureType[GFXFormatR5G6B5] = GL_UNSIGNED_SHORT_5_5_5_1;
  200. }
  201. else
  202. {
  203. GFXGLTextureInternalFormat[GFXFormatR5G6B5] = GL_RGB565;
  204. GFXGLTextureFormat[GFXFormatR5G6B5] = GL_RGB;
  205. GFXGLTextureType[GFXFormatR5G6B5] = GL_UNSIGNED_SHORT_5_6_5;
  206. }
  207. if( gglHasExtension(ARB_texture_rg) )
  208. {
  209. GFXGLTextureInternalFormat[GFXFormatR16G16] = GL_RG16;
  210. GFXGLTextureFormat[GFXFormatR16G16] = GL_RG;
  211. GFXGLTextureType[GFXFormatR16G16] = GL_UNSIGNED_SHORT;
  212. }
  213. else
  214. {
  215. GFXGLTextureInternalFormat[GFXFormatR16G16] = GL_RGBA16;
  216. GFXGLTextureFormat[GFXFormatR16G16] = GL_RGBA;
  217. GFXGLTextureType[GFXFormatR16G16] = GL_UNSIGNED_SHORT;
  218. }
  219. // Cull - Opengl render upside down need to invert cull
  220. GFXGLCullMode[GFXCullNone] = GL_FRONT;
  221. GFXGLCullMode[GFXCullCW] = GL_FRONT;
  222. GFXGLCullMode[GFXCullCCW] = GL_BACK;
  223. // Fill
  224. GFXGLFillMode[GFXFillPoint] = GL_POINT;
  225. GFXGLFillMode[GFXFillWireframe] = GL_LINE;
  226. GFXGLFillMode[GFXFillSolid] = GL_FILL;
  227. }