platformGL.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. // Portions Copyright (c) 2014 James S Urquhart
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to
  7. // deal in the Software without restriction, including without limitation the
  8. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9. // sell copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. // IN THE SOFTWARE.
  22. //-----------------------------------------------------------------------------
  23. #ifndef _PLATFORMGL_H_
  24. #define _PLATFORMGL_H_
  25. //#define DUMMY_GL
  26. #ifdef DUMMY_GL
  27. #include "platformWin32/gl_types.h"
  28. #define GLAPI
  29. #define GLAPIENTRY
  30. #include "platformWin32/gl_types.h"
  31. #define GL_FUNCTION(fn_type,fn_name,fn_args, fn_value) fn_type fn_name fn_args;
  32. #include "platform/GLCoreFunc.h"
  33. #include "platform/GLExtFunc.h"
  34. #undef GL_FUNCTION
  35. void gluOrtho2D( GLfloat, GLfloat, GLfloat, GLfloat );
  36. GLint gluProject( GLdouble winx, GLdouble winy, GLdouble winz, const F64 *model, const F64 * proj, const GLint * vp, F64 * x, F64 * y, F64 * z );
  37. GLint gluUnProject( GLdouble winx, GLdouble winy, GLdouble winz, const F64 *model, const F64 * proj, const GLint * vp, F64 * x, F64 * y, F64 * z );
  38. #else
  39. #include <GL/gl.h>
  40. #include <GL/glext.h>
  41. void gluOrtho2D( GLfloat, GLfloat, GLfloat, GLfloat );
  42. GLint gluProject( GLdouble winx, GLdouble winy, GLdouble winz, const F64 *model, const F64 * proj, const GLint * vp, F64 * x, F64 * y, F64 * z );
  43. GLint gluUnProject( GLdouble winx, GLdouble winy, GLdouble winz, const F64 *model, const F64 * proj, const GLint * vp, F64 * x, F64 * y, F64 * z );
  44. #endif
  45. #define MIN_RESOLUTION_X 1
  46. #define MIN_RESOLUTION_Y 1
  47. #define MIN_RESOLUTION_BIT_DEPTH 16
  48. #define MIN_RESOLUTION_XY_STRING "480 320"
  49. #define EMSCRIPTEN_DEFAULT_RESOLUTION_X 1024
  50. #define EMSCRIPTEN_DEFAULT_RESOLUTION_Y 768
  51. #define EMSCRIPTEN_DEFAULT_RESOLUTION_BIT_DEPTH 32
  52. #define EMSCRIPTEN_SCREEN_PORTRAIT 0
  53. #define EMSCRIPTEN_SCREEN_LANDSCAPE 1
  54. #define EMSCRIPTEN_SCREEN_RIGHT_SIDE_UP 3
  55. #define EMSCRIPTEN_SCREEN_UPSIDE_DOWN 4
  56. /// Allows outline mode drawing via a function pointer swapping trick.
  57. /// Must be included AFTER all the OpenGL headers.
  58. #include "platformEmscripten/EmscriptenOutlineGL.h"
  59. // these are extensions for glAllocateVertexBufferEXT
  60. #define GL_V12MTVFMT_EXT 0x8702
  61. #define GL_V12MTNVFMT_EXT 0x8703
  62. #define GL_V12FTVFMT_EXT 0x8704
  63. #define GL_V12FMTVFMT_EXT 0x8705
  64. //------------------------------------------------------------------------------
  65. // make sure this is defined, as we need to use it when around.
  66. // some versions of OSX only define the SGIS version ( same hexcode )
  67. //#ifndef GL_CLAMP_TO_EDGE_EXT
  68. //#define GL_CLAMP_TO_EDGE_EXT 0x812F
  69. //#endif
  70. /// GL state information.
  71. struct GLState
  72. {
  73. bool suppARBMultitexture;
  74. bool suppEXTblendcolor;
  75. bool suppEXTblendminmax;
  76. bool suppPackedPixels;
  77. bool suppTexEnvAdd;
  78. bool suppLockedArrays;
  79. bool suppTextureEnvCombine;
  80. bool suppVertexArrayRange;
  81. bool suppFogCoord;
  82. bool suppEdgeClamp;
  83. bool suppTextureCompression;
  84. bool suppS3TC;
  85. bool suppFXT1;
  86. bool suppTexAnisotropic;
  87. bool suppPalettedTexture;
  88. bool suppVertexBuffer;
  89. bool suppSwapInterval;
  90. GLint maxFSAASamples;
  91. unsigned int triCount[4];
  92. unsigned int primCount[4];
  93. unsigned int primMode; // 0-3
  94. GLfloat maxAnisotropy;
  95. GLint maxTextureUnits;
  96. };
  97. extern GLState gGLState;
  98. extern bool gOpenGLDisablePT;
  99. extern bool gOpenGLDisableCVA;
  100. extern bool gOpenGLDisableTEC;
  101. extern bool gOpenGLDisableARBMT;
  102. extern bool gOpenGLDisableFC;
  103. extern bool gOpenGLDisableTCompress;
  104. extern bool gOpenGLNoEnvColor;
  105. extern float gOpenGLGammaCorrection;
  106. extern bool gOpenGLNoDrawArraysAlpha;
  107. //------------------------------------------------------------------------------
  108. /// Inline state getters for dgl
  109. //------------------------------------------------------------------------------
  110. inline void dglSetRenderPrimType(unsigned int type)
  111. {
  112. gGLState.primMode = type;
  113. }
  114. inline void dglClearPrimMetrics()
  115. {
  116. for(int i = 0; i < 4; i++)
  117. gGLState.triCount[i] = gGLState.primCount[i] = 0;
  118. }
  119. inline bool dglDoesSupportPalettedTexture()
  120. {
  121. return gGLState.suppPalettedTexture && (gOpenGLDisablePT == false);
  122. }
  123. inline bool dglDoesSupportCompiledVertexArray()
  124. {
  125. return gGLState.suppLockedArrays && (gOpenGLDisableCVA == false);
  126. }
  127. inline bool dglDoesSupportTextureEnvCombine()
  128. {
  129. return gGLState.suppTextureEnvCombine && (gOpenGLDisableTEC == false);
  130. }
  131. inline bool dglDoesSupportARBMultitexture()
  132. {
  133. return gGLState.suppARBMultitexture && (gOpenGLDisableARBMT == false);
  134. }
  135. inline bool dglDoesSupportEXTBlendColor()
  136. {
  137. return gGLState.suppEXTblendcolor;
  138. }
  139. inline bool dglDoesSupportEXTBlendMinMax()
  140. {
  141. return gGLState.suppEXTblendminmax;
  142. }
  143. inline bool dglDoesSupportVertexArrayRange()
  144. {
  145. return gGLState.suppVertexArrayRange;
  146. }
  147. inline bool dglDoesSupportFogCoord()
  148. {
  149. return gGLState.suppFogCoord && (gOpenGLDisableFC == false);
  150. }
  151. inline bool dglDoesSupportEdgeClamp()
  152. {
  153. return gGLState.suppEdgeClamp;
  154. }
  155. inline bool dglDoesSupportTextureCompression()
  156. {
  157. return gGLState.suppTextureCompression && (gOpenGLDisableTCompress == false);
  158. }
  159. inline bool dglDoesSupportS3TC()
  160. {
  161. return gGLState.suppS3TC;
  162. }
  163. inline bool dglDoesSupportFXT1()
  164. {
  165. return gGLState.suppFXT1;
  166. }
  167. inline bool dglDoesSupportTexEnvAdd()
  168. {
  169. return gGLState.suppTexEnvAdd;
  170. }
  171. inline bool dglDoesSupportTexAnisotropy()
  172. {
  173. return gGLState.suppTexAnisotropic;
  174. }
  175. inline bool dglDoesSupportVertexBuffer()
  176. {
  177. return false;
  178. }
  179. inline GLfloat dglGetMaxAnisotropy()
  180. {
  181. return gGLState.maxAnisotropy;
  182. }
  183. inline GLint dglGetMaxTextureUnits()
  184. {
  185. if (dglDoesSupportARBMultitexture())
  186. return gGLState.maxTextureUnits;
  187. else
  188. return 1;
  189. }
  190. //------------------------------------------------------------------------------
  191. /// For radeon cards we can do fast FSAA mode switching.
  192. /// Sets Full Scene Anti-Aliasing (FSAA) samples ( 1x, 2x, 4x ) via aglSetInteger()
  193. //------------------------------------------------------------------------------
  194. #define ATI_FSAA_LEVEL ((unsigned long)510)
  195. void dglSetFSAASamples(GLint aasamp);
  196. #endif // _PLATFORMGL_H_