platformGL.h 7.5 KB

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