platformGL.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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 __cplusplus
  25. extern "C" {
  26. #endif
  27. #define GLAPI extern
  28. #define GLAPIENTRY
  29. #include "platformX86UNIX/gl_types.h"
  30. #define GL_FUNCTION(fn_return,fn_name,fn_args,fn_value) extern fn_return (*fn_name)fn_args;
  31. #include "platform/GLCoreFunc.h"
  32. #include "platform/GLExtFunc.h"
  33. #undef GL_FUNCTION
  34. // GLU functions are linked at compile time, except in the dedicated server build
  35. #ifndef DEDICATED
  36. #define GL_FUNCTION(fn_return,fn_name,fn_args,fn_value) fn_return fn_name fn_args;
  37. #else
  38. #define GL_FUNCTION(fn_return,fn_name,fn_args,fn_value) extern fn_return (*fn_name)fn_args;
  39. #endif
  40. #include "platform/GLUFunc.h"
  41. #undef GL_FUNCTION
  42. namespace GLLoader
  43. {
  44. bool OpenGLInit();
  45. void OpenGLShutdown();
  46. bool OpenGLDLLInit();
  47. void OpenGLDLLShutdown();
  48. }
  49. /*
  50. * GL state information.
  51. */
  52. struct GLState
  53. {
  54. bool suppARBMultitexture;
  55. bool suppEXTblendcolor;
  56. bool suppEXTblendminmax;
  57. bool suppPackedPixels;
  58. bool suppTexEnvAdd;
  59. bool suppLockedArrays;
  60. bool suppTextureEnvCombine;
  61. bool suppVertexArrayRange;
  62. bool suppFogCoord;
  63. bool suppEdgeClamp;
  64. bool suppTextureCompression;
  65. bool suppS3TC;
  66. bool suppFXT1;
  67. bool suppTexAnisotropic;
  68. bool suppPalettedTexture;
  69. bool suppVertexBuffer;
  70. bool suppSwapInterval;
  71. unsigned int triCount[4];
  72. unsigned int primCount[4];
  73. unsigned int primMode; // 0-3
  74. GLfloat maxAnisotropy;
  75. GLint maxTextureUnits;
  76. };
  77. extern GLState gGLState;
  78. extern bool gOpenGLDisablePT;
  79. extern bool gOpenGLDisableCVA;
  80. extern bool gOpenGLDisableTEC;
  81. extern bool gOpenGLDisableARBMT;
  82. extern bool gOpenGLDisableFC;
  83. extern bool gOpenGLDisableTCompress;
  84. extern bool gOpenGLNoEnvColor;
  85. extern float gOpenGLGammaCorrection;
  86. extern bool gOpenGLNoDrawArraysAlpha;
  87. inline void dglSetRenderPrimType(unsigned int type)
  88. {
  89. gGLState.primMode = type;
  90. }
  91. inline void dglClearPrimMetrics()
  92. {
  93. for(int i = 0; i < 4; i++)
  94. gGLState.triCount[i] = gGLState.primCount[i] = 0;
  95. }
  96. inline bool dglDoesSupportPalettedTexture()
  97. {
  98. return gGLState.suppPalettedTexture && (gOpenGLDisablePT == false);
  99. }
  100. inline bool dglDoesSupportCompiledVertexArray()
  101. {
  102. return gGLState.suppLockedArrays && (gOpenGLDisableCVA == false);
  103. }
  104. inline bool dglDoesSupportTextureEnvCombine()
  105. {
  106. return gGLState.suppTextureEnvCombine && (gOpenGLDisableTEC == false);
  107. }
  108. inline bool dglDoesSupportARBMultitexture()
  109. {
  110. return gGLState.suppARBMultitexture && (gOpenGLDisableARBMT == false);
  111. }
  112. inline bool dglDoesSupportEXTBlendColor()
  113. {
  114. return gGLState.suppEXTblendcolor;
  115. }
  116. inline bool dglDoesSupportEXTBlendMinMax()
  117. {
  118. return gGLState.suppEXTblendminmax;
  119. }
  120. inline bool dglDoesSupportVertexArrayRange()
  121. {
  122. return gGLState.suppVertexArrayRange;
  123. }
  124. inline bool dglDoesSupportFogCoord()
  125. {
  126. return gGLState.suppFogCoord && (gOpenGLDisableFC == false);
  127. }
  128. inline bool dglDoesSupportEdgeClamp()
  129. {
  130. return gGLState.suppEdgeClamp;
  131. }
  132. inline bool dglDoesSupportTextureCompression()
  133. {
  134. return gGLState.suppTextureCompression && (gOpenGLDisableTCompress == false);
  135. }
  136. inline bool dglDoesSupportS3TC()
  137. {
  138. return gGLState.suppS3TC;
  139. }
  140. inline bool dglDoesSupportFXT1()
  141. {
  142. return gGLState.suppFXT1;
  143. }
  144. inline bool dglDoesSupportTexEnvAdd()
  145. {
  146. return gGLState.suppTexEnvAdd;
  147. }
  148. inline bool dglDoesSupportTexAnisotropy()
  149. {
  150. return gGLState.suppTexAnisotropic;
  151. }
  152. inline bool dglDoesSupportVertexBuffer()
  153. {
  154. return gGLState.suppVertexBuffer;
  155. }
  156. inline GLfloat dglGetMaxAnisotropy()
  157. {
  158. return gGLState.maxAnisotropy;
  159. }
  160. inline GLint dglGetMaxTextureUnits()
  161. {
  162. if (dglDoesSupportARBMultitexture())
  163. return gGLState.maxTextureUnits;
  164. else
  165. return 1;
  166. }
  167. #ifdef __cplusplus
  168. }
  169. #endif
  170. #endif