platformGL.h 7.7 KB

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