platformGL.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 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. #ifndef _PLATFORMGL_H_
  23. #define _PLATFORMGL_H_
  24. //------------------------------------------------------------------------------
  25. /// Overrides and implentations of opengl API to account for ogles differences
  26. // Include after OpenGLES headers
  27. #include "platformAndroid/AndroidGL2ES.h"
  28. /// Using aglMacro.h gives us signifigant performance gains in opengl immediate mode ( glVertex etc )
  29. #if !defined(TORQUE_DEBUG)
  30. //#define USE_AGL_MACRO
  31. #endif
  32. #if defined(USE_AGL_MACRO)
  33. #if !defined(AGLContext)
  34. typedef struct __AGLContextRec *AGLContext;
  35. #endif
  36. #include <AGL/aglMacro.h>
  37. extern AGLContext agl_ctx;
  38. #endif
  39. #define MIN_RESOLUTION_X 1
  40. #define MIN_RESOLUTION_Y 1
  41. #define MIN_RESOLUTION_BIT_DEPTH 16
  42. #define MIN_RESOLUTION_XY_STRING "480 320"
  43. #define ANDROID_DEFAULT_RESOLUTION_X 1024
  44. #define ANDROID_DEFAULT_RESOLUTION_Y 768
  45. #define ANDROID_DEFAULT_RESOLUTION_BIT_DEPTH 32
  46. #define ANDROID_SCREEN_PORTRAIT 0
  47. #define ANDROID_SCREEN_LANDSCAPE 1
  48. #define ANDROID_SCREEN_RIGHT_SIDE_UP 3
  49. #define ANDROID_SCREEN_UPSIDE_DOWN 4
  50. /// Allows outline mode drawing via a function pointer swapping trick.
  51. /// Must be included AFTER all the OpenGL headers.
  52. #include "platformAndroid/AndroidOutlineGL.h"
  53. //------------------------------------------------------------------------------
  54. /// This is legacy stuff for the d3d wrapper layer.
  55. // The code that requires these stubs should probably be ifdef'd out of any non w32 build
  56. //------------------------------------------------------------------------------
  57. extern GLboolean glAvailableVertexBufferEXT();
  58. extern GLint glAllocateVertexBufferEXT(GLsizei size, GLint format, GLboolean preserve);
  59. extern void* glLockVertexBufferEXT(GLint handle, GLsizei size);
  60. extern void glUnlockVertexBufferEXT(GLint handle);
  61. extern void glSetVertexBufferEXT(GLint handle);
  62. extern void glOffsetVertexBufferEXT(GLint handle, GLuint offset);
  63. extern void glFillVertexBufferEXT(GLint handle, GLint first, GLsizei count);
  64. extern void glFreeVertexBufferEXT(GLint handle);
  65. // these are extensions for glAllocateVertexBufferEXT
  66. #define GL_V12MTVFMT_EXT 0x8702
  67. #define GL_V12MTNVFMT_EXT 0x8703
  68. #define GL_V12FTVFMT_EXT 0x8704
  69. #define GL_V12FMTVFMT_EXT 0x8705
  70. //------------------------------------------------------------------------------
  71. // make sure this is defined, as we need to use it when around.
  72. // some versions of OSX only define the SGIS version ( same hexcode )
  73. //#ifndef GL_CLAMP_TO_EDGE_EXT
  74. //#define GL_CLAMP_TO_EDGE_EXT 0x812F
  75. //#endif
  76. /// GL state information.
  77. struct GLState
  78. {
  79. bool suppARBMultitexture;
  80. bool suppEXTblendcolor;
  81. bool suppEXTblendminmax;
  82. bool suppPackedPixels;
  83. bool suppTexEnvAdd;
  84. bool suppLockedArrays;
  85. bool suppTextureEnvCombine;
  86. bool suppVertexArrayRange;
  87. bool suppFogCoord;
  88. bool suppEdgeClamp;
  89. bool suppTextureCompression;
  90. bool suppS3TC;
  91. bool suppFXT1;
  92. bool suppTexAnisotropic;
  93. bool suppPalettedTexture;
  94. bool suppVertexBuffer;
  95. bool suppSwapInterval;
  96. GLint maxFSAASamples;
  97. unsigned int triCount[4];
  98. unsigned int primCount[4];
  99. unsigned int primMode; // 0-3
  100. GLfloat maxAnisotropy;
  101. GLint maxTextureUnits;
  102. };
  103. extern GLState gGLState;
  104. extern bool gOpenGLDisablePT;
  105. extern bool gOpenGLDisableCVA;
  106. extern bool gOpenGLDisableTEC;
  107. extern bool gOpenGLDisableARBMT;
  108. extern bool gOpenGLDisableFC;
  109. extern bool gOpenGLDisableTCompress;
  110. extern bool gOpenGLNoEnvColor;
  111. extern float gOpenGLGammaCorrection;
  112. extern bool gOpenGLNoDrawArraysAlpha;
  113. //------------------------------------------------------------------------------
  114. /// Inline state getters for dgl
  115. //------------------------------------------------------------------------------
  116. inline void dglSetRenderPrimType(unsigned int type)
  117. {
  118. gGLState.primMode = type;
  119. }
  120. inline void dglClearPrimMetrics()
  121. {
  122. for(int i = 0; i < 4; i++)
  123. gGLState.triCount[i] = gGLState.primCount[i] = 0;
  124. }
  125. inline bool dglDoesSupportPalettedTexture()
  126. {
  127. return gGLState.suppPalettedTexture && (gOpenGLDisablePT == false);
  128. }
  129. inline bool dglDoesSupportCompiledVertexArray()
  130. {
  131. return gGLState.suppLockedArrays && (gOpenGLDisableCVA == false);
  132. }
  133. inline bool dglDoesSupportTextureEnvCombine()
  134. {
  135. return gGLState.suppTextureEnvCombine && (gOpenGLDisableTEC == false);
  136. }
  137. inline bool dglDoesSupportARBMultitexture()
  138. {
  139. return gGLState.suppARBMultitexture && (gOpenGLDisableARBMT == false);
  140. }
  141. inline bool dglDoesSupportEXTBlendColor()
  142. {
  143. return gGLState.suppEXTblendcolor;
  144. }
  145. inline bool dglDoesSupportEXTBlendMinMax()
  146. {
  147. return gGLState.suppEXTblendminmax;
  148. }
  149. inline bool dglDoesSupportVertexArrayRange()
  150. {
  151. return gGLState.suppVertexArrayRange;
  152. }
  153. inline bool dglDoesSupportFogCoord()
  154. {
  155. return gGLState.suppFogCoord && (gOpenGLDisableFC == false);
  156. }
  157. inline bool dglDoesSupportEdgeClamp()
  158. {
  159. return gGLState.suppEdgeClamp;
  160. }
  161. inline bool dglDoesSupportTextureCompression()
  162. {
  163. return gGLState.suppTextureCompression && (gOpenGLDisableTCompress == false);
  164. }
  165. inline bool dglDoesSupportS3TC()
  166. {
  167. return gGLState.suppS3TC;
  168. }
  169. inline bool dglDoesSupportFXT1()
  170. {
  171. return gGLState.suppFXT1;
  172. }
  173. inline bool dglDoesSupportTexEnvAdd()
  174. {
  175. return gGLState.suppTexEnvAdd;
  176. }
  177. inline bool dglDoesSupportTexAnisotropy()
  178. {
  179. return gGLState.suppTexAnisotropic;
  180. }
  181. inline bool dglDoesSupportVertexBuffer()
  182. {
  183. return false;
  184. }
  185. inline GLfloat dglGetMaxAnisotropy()
  186. {
  187. return gGLState.maxAnisotropy;
  188. }
  189. inline GLint dglGetMaxTextureUnits()
  190. {
  191. if (dglDoesSupportARBMultitexture())
  192. return gGLState.maxTextureUnits;
  193. else
  194. return 1;
  195. }
  196. //------------------------------------------------------------------------------
  197. /// For radeon cards we can do fast FSAA mode switching.
  198. /// Sets Full Scene Anti-Aliasing (FSAA) samples ( 1x, 2x, 4x ) via aglSetInteger()
  199. //------------------------------------------------------------------------------
  200. #define ATI_FSAA_LEVEL ((unsigned long)510)
  201. void dglSetFSAASamples(GLint aasamp);
  202. #endif // _PLATFORMGL_H_