AndroidGL.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. // Many OSX frameworks include OpenTransport, and OT's new operator conflicts
  23. // with our redefinition of 'new', so we have to pre-include platformAndroid.h,
  24. // which contains the workaround.
  25. #include "platformAndroid/platformAndroid.h"
  26. #include "platformAndroid/platformGL.h"
  27. #include "platformAndroid/AndroidUtil.h"
  28. #include "console/console.h"
  29. #include "graphics/dgl.h"
  30. GLState gGLState;
  31. bool gOpenGLDisablePT = false;
  32. bool gOpenGLDisableCVA = false;
  33. bool gOpenGLDisableTEC = false;
  34. bool gOpenGLDisableARBMT = false;
  35. bool gOpenGLDisableFC = true; //false;
  36. bool gOpenGLDisableTCompress = false;
  37. bool gOpenGLNoEnvColor = false;
  38. float gOpenGLGammaCorrection = 0.5;
  39. bool gOpenGLNoDrawArraysAlpha = false;
  40. //-----------------------------------------------------------------------------
  41. /// These stubs are legacy stuff for the d3d wrapper layer.
  42. // The code that requires these stubs should probably be ifdef'd out of any non w32 build
  43. //-----------------------------------------------------------------------------
  44. GLboolean glAvailableVertexBufferEXT() { return(false); }
  45. GLint glAllocateVertexBufferEXT(GLsizei size, GLint format, GLboolean preserve) { return(0); }
  46. void* glLockVertexBufferEXT(GLint handle, GLsizei size) { return(NULL); }
  47. void glUnlockVertexBufferEXT(GLint handle) {}
  48. void glSetVertexBufferEXT(GLint handle) {}
  49. void glOffsetVertexBufferEXT(GLint handle, GLuint offset) {}
  50. void glFillVertexBufferEXT(GLint handle, GLint first, GLsizei count) {}
  51. void glFreeVertexBufferEXT(GLint handle) {}
  52. // Find out which extensions are available for this renderer.
  53. void getGLCapabilities( )
  54. {
  55. AssertFatal(platState.engine, "getGLCapabilities() was called before a monitor was chosen!");
  56. // silently create an opengl context on the current display,
  57. // so that we can get valid renderer and capability info.
  58. // we save off the current context so that we can silently restore it.
  59. // the user should not be aware of this little shuffle.
  60. //CGLContextObj curr_ctx = CGLGetCurrentContext ();
  61. //CGLContextObj temp_ctx = getContextForCapsCheck();
  62. /*
  63. if(!temp_ctx)
  64. {
  65. Con::errorf("OpenGL may not be set up correctly!");
  66. return;
  67. }
  68. */
  69. //CGLSetCurrentContext(temp_ctx);
  70. // Get the OpenGL info strings we'll need
  71. const char* pVendString = (const char*) glGetString( GL_VENDOR );
  72. const char* pRendString = (const char*) glGetString( GL_RENDERER );
  73. const char* pVersString = (const char*) glGetString( GL_VERSION );
  74. const char* pExtString = (const char*) glGetString( GL_EXTENSIONS );
  75. // Output some driver info to the console:
  76. Con::printf( "OpenGL driver information:" );
  77. if ( pVendString )
  78. Con::printf( " Vendor: %s", pVendString );
  79. if ( pRendString )
  80. Con::printf( " Renderer: %s", pRendString );
  81. if ( pVersString )
  82. Con::printf( " Version: %s", pVersString );
  83. // pre-clear the structure
  84. dMemset(&gGLState, 0, sizeof(gGLState));
  85. if(pExtString)
  86. {
  87. // EXT_paletted_texture ========================================
  88. if (dStrstr(pExtString, (const char*)"GL_EXT_paletted_texture") != NULL)
  89. gGLState.suppPalettedTexture = true;
  90. // EXT_compiled_vertex_array ========================================
  91. gGLState.suppLockedArrays = false;
  92. if (dStrstr(pExtString, (const char*)"GL_EXT_compiled_vertex_array") != NULL)
  93. gGLState.suppLockedArrays = true;
  94. // ARB_multitexture ========================================
  95. if (dStrstr(pExtString, (const char*)"GL_ARB_multitexture") != NULL)
  96. gGLState.suppARBMultitexture = true;
  97. // EXT_blend_color
  98. if(dStrstr(pExtString, (const char*)"GL_EXT_blend_color") != NULL)
  99. gGLState.suppEXTblendcolor = true;
  100. // EXT_blend_minmax
  101. if(dStrstr(pExtString, (const char*)"GL_EXT_blend_minmax") != NULL)
  102. gGLState.suppEXTblendminmax = true;
  103. // NV_vertex_array_range ========================================
  104. // does not appear to be supported by apple, at all. ( as of 10.4.3 )
  105. // GL_APPLE_vertex_array_range is similar, and may be nearly identical.
  106. if (dStrstr(pExtString, (const char*)"GL_NV_vertex_array_range") != NULL)
  107. gGLState.suppVertexArrayRange = true;
  108. // EXT_fog_coord ========================================
  109. if (dStrstr(pExtString, (const char*)"GL_EXT_fog_coord") != NULL)
  110. gGLState.suppFogCoord = true;
  111. // ARB_texture_compression ========================================
  112. if (dStrstr(pExtString, (const char*)"GL_ARB_texture_compression") != NULL)
  113. gGLState.suppTextureCompression = true;
  114. // 3DFX_texture_compression_FXT1 ========================================
  115. if (dStrstr(pExtString, (const char*)"GL_3DFX_texture_compression_FXT1") != NULL)
  116. gGLState.suppFXT1 = true;
  117. // EXT_texture_compression_S3TC ========================================
  118. if (dStrstr(pExtString, (const char*)"GL_EXT_texture_compression_s3tc") != NULL)
  119. gGLState.suppS3TC = true;
  120. // EXT_vertex_buffer ========================================
  121. // This extension is deprecated, and not supported by Apple. ( 10.4.3 )
  122. // Instead, the ARB Vertex Buffer extension is supported.
  123. // The new extension has a different API, so TGE should be updated to use it.
  124. if (dStrstr(pExtString, (const char*)"GL_EXT_vertex_buffer") != NULL)
  125. gGLState.suppVertexBuffer = true;
  126. // Anisotropic filtering ========================================
  127. gGLState.suppTexAnisotropic = (dStrstr(pExtString, (const char*)"GL_EXT_texture_filter_anisotropic") != NULL);
  128. if (gGLState.suppTexAnisotropic)
  129. glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &gGLState.maxAnisotropy);
  130. // Binary states, i.e., no supporting functions ========================================
  131. // NOTE:
  132. // Some of these have multiple representations, via EXT and|or ARB and|or NV and|or SGIS ... etc.
  133. // Check all relative versions.
  134. gGLState.suppPackedPixels = (dStrstr(pExtString, (const char*)"GL_EXT_packed_pixels") != NULL);
  135. gGLState.suppPackedPixels |= (dStrstr(pExtString, (const char*)"GL_APPLE_packed_pixel") != NULL);
  136. gGLState.suppTextureEnvCombine = (dStrstr(pExtString, (const char*)"GL_EXT_texture_env_combine") != NULL);
  137. gGLState.suppTextureEnvCombine|= (dStrstr(pExtString, (const char*)"GL_ARB_texture_env_combine") != NULL);
  138. gGLState.suppEdgeClamp = (dStrstr(pExtString, (const char*)"GL_EXT_texture_edge_clamp") != NULL);
  139. gGLState.suppEdgeClamp |= (dStrstr(pExtString, (const char*)"GL_SGIS_texture_edge_clamp") != NULL);
  140. gGLState.suppEdgeClamp |= (dStrstr(pExtString, (const char*)"GL_ARB_texture_border_clamp") != NULL);
  141. gGLState.suppEdgeClamp = true;
  142. gGLState.suppTexEnvAdd = (dStrstr(pExtString, (const char*)"GL_ARB_texture_env_add") != NULL);
  143. gGLState.suppTexEnvAdd |= (dStrstr(pExtString, (const char*)"GL_EXT_texture_env_add") != NULL);
  144. }
  145. // Texture combine units ========================================
  146. // if (gGLState.suppARBMultitexture)
  147. // glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gGLState.maxTextureUnits);
  148. gGLState.suppARBMultitexture = false;
  149. gGLState.maxTextureUnits = 1;
  150. // Swap interval ========================================
  151. // Mac inherently supports a swap interval via AGL-set-integer.
  152. gGLState.suppSwapInterval = true;
  153. // FSAA support, TODO: check for ARB multisample support
  154. // multisample support should be checked via CGL
  155. gGLState.maxFSAASamples = 4;
  156. // dump found extensions to the console...
  157. Con::printf("OpenGL Init: Enabled Extensions");
  158. if (gGLState.suppARBMultitexture) Con::printf(" ARB_multitexture (Max Texture Units: %d)", gGLState.maxTextureUnits);
  159. if (gGLState.suppEXTblendcolor) Con::printf(" EXT_blend_color");
  160. if (gGLState.suppEXTblendminmax) Con::printf(" EXT_blend_minmax");
  161. if (gGLState.suppPalettedTexture) Con::printf(" EXT_paletted_texture");
  162. if (gGLState.suppLockedArrays) Con::printf(" EXT_compiled_vertex_array");
  163. if (gGLState.suppVertexArrayRange) Con::printf(" NV_vertex_array_range");
  164. if (gGLState.suppTextureEnvCombine) Con::printf(" EXT_texture_env_combine");
  165. if (gGLState.suppPackedPixels) Con::printf(" EXT_packed_pixels");
  166. if (gGLState.suppFogCoord) Con::printf(" EXT_fog_coord");
  167. if (gGLState.suppTextureCompression) Con::printf(" ARB_texture_compression");
  168. if (gGLState.suppS3TC) Con::printf(" EXT_texture_compression_s3tc");
  169. if (gGLState.suppFXT1) Con::printf(" 3DFX_texture_compression_FXT1");
  170. if (gGLState.suppTexEnvAdd) Con::printf(" (ARB|EXT)_texture_env_add");
  171. if (gGLState.suppTexAnisotropic) Con::printf(" EXT_texture_filter_anisotropic (Max anisotropy: %f)", gGLState.maxAnisotropy);
  172. if (gGLState.suppSwapInterval) Con::printf(" Vertical Sync");
  173. if (gGLState.maxFSAASamples) Con::printf(" ATI_FSAA");
  174. Con::warnf("OpenGL Init: Disabled Extensions");
  175. if (!gGLState.suppARBMultitexture) Con::warnf(" ARB_multitexture");
  176. if (!gGLState.suppEXTblendcolor) Con::warnf(" EXT_blend_color");
  177. if (!gGLState.suppEXTblendminmax) Con::warnf(" EXT_blend_minmax");
  178. if (!gGLState.suppPalettedTexture) Con::warnf(" EXT_paletted_texture");
  179. if (!gGLState.suppLockedArrays) Con::warnf(" EXT_compiled_vertex_array");
  180. if (!gGLState.suppVertexArrayRange) Con::warnf(" NV_vertex_array_range");
  181. if (!gGLState.suppTextureEnvCombine) Con::warnf(" EXT_texture_env_combine");
  182. if (!gGLState.suppPackedPixels) Con::warnf(" EXT_packed_pixels");
  183. if (!gGLState.suppFogCoord) Con::warnf(" EXT_fog_coord");
  184. if (!gGLState.suppTextureCompression) Con::warnf(" ARB_texture_compression");
  185. if (!gGLState.suppS3TC) Con::warnf(" EXT_texture_compression_s3tc");
  186. if (!gGLState.suppFXT1) Con::warnf(" 3DFX_texture_compression_FXT1");
  187. if (!gGLState.suppTexEnvAdd) Con::warnf(" (ARB|EXT)_texture_env_add");
  188. if (!gGLState.suppTexAnisotropic) Con::warnf(" EXT_texture_filter_anisotropic");
  189. if (!gGLState.suppSwapInterval) Con::warnf(" Vertical Sync");
  190. if (!gGLState.maxFSAASamples) Con::warnf(" ATI_FSAA");
  191. Con::printf("");
  192. // Set some console variables:
  193. Con::setBoolVariable( "$FogCoordSupported", gGLState.suppFogCoord );
  194. Con::setBoolVariable( "$TextureCompressionSupported", gGLState.suppTextureCompression );
  195. Con::setBoolVariable( "$AnisotropySupported", gGLState.suppTexAnisotropic );
  196. Con::setBoolVariable( "$PalettedTextureSupported", gGLState.suppPalettedTexture );
  197. Con::setBoolVariable( "$SwapIntervalSupported", gGLState.suppSwapInterval );
  198. if (!gGLState.suppPalettedTexture && Con::getBoolVariable("$pref::OpenGL::forcePalettedTexture",false))
  199. {
  200. Con::setBoolVariable("$pref::OpenGL::forcePalettedTexture", false);
  201. Con::setBoolVariable("$pref::OpenGL::force16BitTexture", true);
  202. }
  203. // get fsaa samples. default to normal, no antialiasing
  204. // TODO: clamp this against ARB_multisample capabilities.
  205. gFSAASamples = Con::getIntVariable("$pref::OpenGL::numFSAASamples", 1);
  206. }