platformGL.h 7.0 KB

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