gfxGLEnumTranslate.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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 GFXGLTextureFilter[GFXTextureFilter_COUNT];
  28. GLenum GFXGLTextureAddress[GFXAddress_COUNT];
  29. GLenum GFXGLCmpFunc[GFXCmp_COUNT];
  30. GLenum GFXGLStencilOp[GFXStencilOp_COUNT];
  31. GLenum GFXGLTextureInternalFormat[GFXFormat_COUNT];
  32. GLenum GFXGLTextureFormat[GFXFormat_COUNT];
  33. GLenum GFXGLTextureType[GFXFormat_COUNT];
  34. GLint* GFXGLTextureSwizzle[GFXFormat_COUNT];
  35. GLenum GFXGLBufferType[GFXBufferType_COUNT];
  36. GLenum GFXGLCullMode[GFXCull_COUNT];
  37. GLenum GFXGLFillMode[GFXFill_COUNT];
  38. GLenum GFXGLFaceType[6];
  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. // Comparison
  71. GFXGLCmpFunc[GFXCmpNever] = GL_NEVER;
  72. GFXGLCmpFunc[GFXCmpLess] = GL_LESS;
  73. GFXGLCmpFunc[GFXCmpEqual] = GL_EQUAL;
  74. GFXGLCmpFunc[GFXCmpLessEqual] = GL_LEQUAL;
  75. GFXGLCmpFunc[GFXCmpGreater] = GL_GREATER;
  76. GFXGLCmpFunc[GFXCmpNotEqual] = GL_NOTEQUAL;
  77. GFXGLCmpFunc[GFXCmpGreaterEqual] = GL_GEQUAL;
  78. GFXGLCmpFunc[GFXCmpAlways] = GL_ALWAYS;
  79. GFXGLTextureFilter[GFXTextureFilterNone] = GL_NEAREST;
  80. GFXGLTextureFilter[GFXTextureFilterPoint] = GL_NEAREST;
  81. GFXGLTextureFilter[GFXTextureFilterLinear] = GL_LINEAR;
  82. GFXGLTextureFilter[GFXTextureFilterAnisotropic] = GL_LINEAR;
  83. GFXGLTextureAddress[GFXAddressWrap] = GL_REPEAT;
  84. GFXGLTextureAddress[GFXAddressMirror] = GL_REPEAT;
  85. GFXGLTextureAddress[GFXAddressClamp] = GL_CLAMP_TO_EDGE;
  86. GFXGLTextureAddress[GFXAddressBorder] = GL_REPEAT;
  87. GFXGLTextureAddress[GFXAddressMirrorOnce] = GL_REPEAT;
  88. // Stencil ops
  89. GFXGLStencilOp[GFXStencilOpKeep] = GL_KEEP;
  90. GFXGLStencilOp[GFXStencilOpZero] = GL_ZERO;
  91. GFXGLStencilOp[GFXStencilOpReplace] = GL_REPLACE;
  92. GFXGLStencilOp[GFXStencilOpIncrSat] = GL_INCR;
  93. GFXGLStencilOp[GFXStencilOpDecrSat] = GL_DECR;
  94. GFXGLStencilOp[GFXStencilOpInvert] = GL_INVERT;
  95. GFXGLStencilOp[GFXStencilOpIncr] = GL_INCR_WRAP;
  96. GFXGLStencilOp[GFXStencilOpDecr] = GL_DECR_WRAP;
  97. // Texture formats
  98. for(int i = 0; i < GFXFormat_COUNT; ++i)
  99. {
  100. GFXGLTextureInternalFormat[i] = GL_NONE;
  101. GFXGLTextureFormat[i] = GL_NONE;
  102. GFXGLTextureType[i] = GL_NONE;
  103. GFXGLTextureSwizzle[i] = NULL;
  104. }
  105. GFXGLTextureInternalFormat[GFXFormatA8] = GL_R8;
  106. GFXGLTextureInternalFormat[GFXFormatL8] = GL_R8;
  107. GFXGLTextureInternalFormat[GFXFormatA8L8] = GL_RG8;
  108. GFXGLTextureInternalFormat[GFXFormatR5G5B5A1] = GL_RGB5_A1;
  109. GFXGLTextureInternalFormat[GFXFormatR5G5B5X1] = GL_RGB5_A1;
  110. GFXGLTextureInternalFormat[GFXFormatL16] = GL_R16;
  111. GFXGLTextureInternalFormat[GFXFormatD16] = GL_DEPTH_COMPONENT16;
  112. GFXGLTextureInternalFormat[GFXFormatR8G8B8] = GL_RGB8;
  113. GFXGLTextureInternalFormat[GFXFormatR8G8B8A8] = GL_RGBA8;
  114. GFXGLTextureInternalFormat[GFXFormatR8G8B8X8] = GL_RGBA8;
  115. GFXGLTextureInternalFormat[GFXFormatB8G8R8A8] = GL_RGBA8;
  116. GFXGLTextureInternalFormat[GFXFormatR10G10B10A2] = GL_RGB10_A2;
  117. GFXGLTextureInternalFormat[GFXFormatR11G11B10] = GL_R11F_G11F_B10F;
  118. GFXGLTextureInternalFormat[GFXFormatD32] = GL_DEPTH_COMPONENT32;
  119. GFXGLTextureInternalFormat[GFXFormatD24X8] = GL_DEPTH24_STENCIL8;
  120. GFXGLTextureInternalFormat[GFXFormatD24S8] = GL_DEPTH24_STENCIL8;
  121. GFXGLTextureInternalFormat[GFXFormatR16G16B16A16] = GL_RGBA16;
  122. GFXGLTextureInternalFormat[GFXFormatBC1] = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
  123. GFXGLTextureInternalFormat[GFXFormatBC2] = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
  124. GFXGLTextureInternalFormat[GFXFormatBC3] = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
  125. GFXGLTextureInternalFormat[GFXFormatBC4] = GL_COMPRESSED_RED_RGTC1;
  126. GFXGLTextureInternalFormat[GFXFormatBC5] = GL_COMPRESSED_RG_RGTC2;
  127. //sRGB
  128. GFXGLTextureInternalFormat[GFXFormatR8G8B8_SRGB] = GL_SRGB8;
  129. GFXGLTextureInternalFormat[GFXFormatR8G8B8A8_SRGB] = GL_SRGB8_ALPHA8;
  130. GFXGLTextureInternalFormat[GFXFormatBC1_SRGB] = GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;
  131. GFXGLTextureInternalFormat[GFXFormatBC2_SRGB] = GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;
  132. GFXGLTextureInternalFormat[GFXFormatBC3_SRGB] = GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT;
  133. GFXGLTextureFormat[GFXFormatA8] = GL_RED;
  134. GFXGLTextureFormat[GFXFormatL8] = GL_RED;
  135. GFXGLTextureFormat[GFXFormatA8L8] = GL_RG;
  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[GFXFormatR11G11B10] = GL_RGB;
  146. GFXGLTextureFormat[GFXFormatD32] = GL_DEPTH_COMPONENT;
  147. GFXGLTextureFormat[GFXFormatD24X8] = GL_DEPTH_STENCIL;
  148. GFXGLTextureFormat[GFXFormatD24S8] = GL_DEPTH_STENCIL;
  149. GFXGLTextureFormat[GFXFormatR16G16B16A16] = GL_RGBA;
  150. GFXGLTextureFormat[GFXFormatBC1] = GL_RGBA;
  151. GFXGLTextureFormat[GFXFormatBC2] = GL_RGBA;
  152. GFXGLTextureFormat[GFXFormatBC3] = GL_RGBA;
  153. GFXGLTextureFormat[GFXFormatBC4] = GL_RED;
  154. GFXGLTextureFormat[GFXFormatBC5] = GL_RG;
  155. //sRGB
  156. GFXGLTextureFormat[GFXFormatR8G8B8_SRGB] = GL_RGB;
  157. GFXGLTextureFormat[GFXFormatR8G8B8A8_SRGB] = GL_RGBA;
  158. GFXGLTextureFormat[GFXFormatBC1_SRGB] = GL_RGBA;
  159. GFXGLTextureFormat[GFXFormatBC2_SRGB] = GL_RGBA;
  160. GFXGLTextureFormat[GFXFormatBC3_SRGB] = GL_RGBA;
  161. GFXGLTextureType[GFXFormatA8] = GL_UNSIGNED_BYTE;
  162. GFXGLTextureType[GFXFormatL8] = GL_UNSIGNED_BYTE;
  163. GFXGLTextureType[GFXFormatA8L8] = GL_UNSIGNED_BYTE;
  164. GFXGLTextureType[GFXFormatR5G5B5A1] = GL_UNSIGNED_SHORT_5_5_5_1;
  165. GFXGLTextureType[GFXFormatR5G5B5X1] = GL_UNSIGNED_SHORT_5_5_5_1;
  166. GFXGLTextureType[GFXFormatL16] = GL_UNSIGNED_SHORT;
  167. GFXGLTextureType[GFXFormatD16] = GL_UNSIGNED_SHORT;
  168. GFXGLTextureType[GFXFormatR8G8B8] = GL_UNSIGNED_BYTE;
  169. GFXGLTextureType[GFXFormatR8G8B8A8] = GL_UNSIGNED_BYTE;
  170. GFXGLTextureType[GFXFormatR8G8B8X8] = GL_UNSIGNED_BYTE;
  171. GFXGLTextureType[GFXFormatB8G8R8A8] = GL_UNSIGNED_BYTE;;
  172. GFXGLTextureType[GFXFormatR10G10B10A2] = GL_UNSIGNED_INT_10_10_10_2;
  173. GFXGLTextureType[GFXFormatR11G11B10] = GL_UNSIGNED_INT_10F_11F_11F_REV;
  174. GFXGLTextureType[GFXFormatD32] = GL_UNSIGNED_INT;
  175. GFXGLTextureType[GFXFormatD24X8] = GL_UNSIGNED_INT_24_8;
  176. GFXGLTextureType[GFXFormatD24S8] = GL_UNSIGNED_INT_24_8;
  177. GFXGLTextureType[GFXFormatR16G16B16A16] = GL_UNSIGNED_SHORT;
  178. GFXGLTextureType[GFXFormatBC1] = GL_UNSIGNED_BYTE;
  179. GFXGLTextureType[GFXFormatBC2] = GL_UNSIGNED_BYTE;
  180. GFXGLTextureType[GFXFormatBC3] = GL_UNSIGNED_BYTE;
  181. GFXGLTextureType[GFXFormatBC4] = GL_UNSIGNED_BYTE;
  182. GFXGLTextureType[GFXFormatBC5] = GL_UNSIGNED_BYTE;
  183. // sRGB
  184. GFXGLTextureType[GFXFormatR8G8B8_SRGB] = GL_UNSIGNED_BYTE;
  185. GFXGLTextureType[GFXFormatR8G8B8A8_SRGB] = GL_UNSIGNED_BYTE;
  186. GFXGLTextureType[GFXFormatBC1_SRGB] = GL_UNSIGNED_BYTE;
  187. GFXGLTextureType[GFXFormatBC2_SRGB] = GL_UNSIGNED_BYTE;
  188. GFXGLTextureType[GFXFormatBC3_SRGB] = GL_UNSIGNED_BYTE;
  189. static GLint Swizzle_GFXFormatA8[] = { GL_NONE, GL_NONE, GL_NONE, GL_RED };
  190. static GLint Swizzle_GFXFormatL[] = { GL_RED, GL_RED, GL_RED, GL_ALPHA };
  191. GFXGLTextureSwizzle[GFXFormatA8] = Swizzle_GFXFormatA8; // old GL_ALPHA8
  192. GFXGLTextureSwizzle[GFXFormatL8] = Swizzle_GFXFormatL; // old GL_LUMINANCE8
  193. GFXGLTextureSwizzle[GFXFormatL16] = Swizzle_GFXFormatL; // old GL_LUMINANCE16
  194. GFXGLTextureInternalFormat[GFXFormatR32F] = GL_R32F;
  195. GFXGLTextureFormat[GFXFormatR32F] = GL_RED;
  196. GFXGLTextureType[GFXFormatR32F] = GL_FLOAT;
  197. GFXGLTextureInternalFormat[GFXFormatR32G32B32A32F] = GL_RGBA32F_ARB;
  198. GFXGLTextureFormat[GFXFormatR32G32B32A32F] = GL_RGBA;
  199. GFXGLTextureType[GFXFormatR32G32B32A32F] = GL_FLOAT;
  200. GFXGLTextureInternalFormat[GFXFormatR16F] = GL_R16F;
  201. GFXGLTextureFormat[GFXFormatR16F] = GL_RED;
  202. GFXGLTextureType[GFXFormatR16F] = GL_HALF_FLOAT_ARB;
  203. GFXGLTextureInternalFormat[GFXFormatR16G16F] = GL_RG16F;
  204. GFXGLTextureFormat[GFXFormatR16G16F] = GL_RG;
  205. GFXGLTextureType[GFXFormatR16G16F] = GL_HALF_FLOAT_ARB;
  206. GFXGLTextureInternalFormat[GFXFormatR16G16B16A16F] = GL_RGBA16F_ARB;
  207. GFXGLTextureFormat[GFXFormatR16G16B16A16F] = GL_RGBA;
  208. GFXGLTextureType[GFXFormatR16G16B16A16F] = GL_HALF_FLOAT_ARB;
  209. if( gglHasExtension(ARB_ES2_compatibility) )
  210. {
  211. GFXGLTextureInternalFormat[GFXFormatR5G6B5] = GL_RGB5_A1;
  212. GFXGLTextureFormat[GFXFormatR5G6B5] = GL_RGBA;
  213. GFXGLTextureType[GFXFormatR5G6B5] = GL_UNSIGNED_SHORT_5_5_5_1;
  214. }
  215. else
  216. {
  217. GFXGLTextureInternalFormat[GFXFormatR5G6B5] = GL_RGB565;
  218. GFXGLTextureFormat[GFXFormatR5G6B5] = GL_RGB;
  219. GFXGLTextureType[GFXFormatR5G6B5] = GL_UNSIGNED_SHORT_5_6_5;
  220. }
  221. if( gglHasExtension(ARB_texture_rg) )
  222. {
  223. GFXGLTextureInternalFormat[GFXFormatR16G16] = GL_RG16;
  224. GFXGLTextureFormat[GFXFormatR16G16] = GL_RG;
  225. GFXGLTextureType[GFXFormatR16G16] = GL_UNSIGNED_SHORT;
  226. }
  227. else
  228. {
  229. GFXGLTextureInternalFormat[GFXFormatR16G16] = GL_RGBA16;
  230. GFXGLTextureFormat[GFXFormatR16G16] = GL_RGBA;
  231. GFXGLTextureType[GFXFormatR16G16] = GL_UNSIGNED_SHORT;
  232. }
  233. // Cull - Opengl render upside down need to invert cull
  234. GFXGLCullMode[GFXCullNone] = GL_FRONT;
  235. GFXGLCullMode[GFXCullCW] = GL_FRONT;
  236. GFXGLCullMode[GFXCullCCW] = GL_BACK;
  237. // Fill
  238. GFXGLFillMode[GFXFillPoint] = GL_POINT;
  239. GFXGLFillMode[GFXFillWireframe] = GL_LINE;
  240. GFXGLFillMode[GFXFillSolid] = GL_FILL;
  241. //cubemap face type
  242. GFXGLFaceType[0] = GL_TEXTURE_CUBE_MAP_POSITIVE_X;
  243. GFXGLFaceType[1] = GL_TEXTURE_CUBE_MAP_NEGATIVE_X;
  244. GFXGLFaceType[2] = GL_TEXTURE_CUBE_MAP_POSITIVE_Y;
  245. GFXGLFaceType[3] = GL_TEXTURE_CUBE_MAP_NEGATIVE_Y;
  246. GFXGLFaceType[4] = GL_TEXTURE_CUBE_MAP_POSITIVE_Z;
  247. GFXGLFaceType[5] = GL_TEXTURE_CUBE_MAP_NEGATIVE_Z;
  248. }