PageRenderTime 79ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/indra/llrender/llgl.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 1707 lines | 1419 code | 180 blank | 108 comment | 214 complexity | 531c3023649f7374b910ef05abc16973 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llgl.cpp
  3. * @brief LLGL implementation
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. // This file sets some global GL parameters, and implements some
  27. // useful functions for GL operations.
  28. #define GLH_EXT_SINGLE_FILE
  29. #include "linden_common.h"
  30. #include "boost/tokenizer.hpp"
  31. #include "llsys.h"
  32. #include "llgl.h"
  33. #include "llrender.h"
  34. #include "llerror.h"
  35. #include "llerrorcontrol.h"
  36. #include "llquaternion.h"
  37. #include "llmath.h"
  38. #include "m4math.h"
  39. #include "llstring.h"
  40. #include "llmemtype.h"
  41. #include "llstacktrace.h"
  42. #include "llglheaders.h"
  43. #include "llglslshader.h"
  44. #ifdef _DEBUG
  45. //#define GL_STATE_VERIFY
  46. #endif
  47. BOOL gDebugSession = FALSE;
  48. BOOL gDebugGL = FALSE;
  49. BOOL gClothRipple = FALSE;
  50. BOOL gHeadlessClient = FALSE;
  51. BOOL gGLActive = FALSE;
  52. static const std::string HEADLESS_VENDOR_STRING("Linden Lab");
  53. static const std::string HEADLESS_RENDERER_STRING("Headless");
  54. static const std::string HEADLESS_VERSION_STRING("1.0");
  55. std::ofstream gFailLog;
  56. #if GL_ARB_debug_output
  57. #ifndef APIENTRY
  58. #define APIENTRY
  59. #endif
  60. void APIENTRY gl_debug_callback(GLenum source,
  61. GLenum type,
  62. GLuint id,
  63. GLenum severity,
  64. GLsizei length,
  65. const GLchar* message,
  66. GLvoid* userParam)
  67. {
  68. if (severity == GL_DEBUG_SEVERITY_HIGH_ARB)
  69. {
  70. llwarns << "----- GL ERROR --------" << llendl;
  71. }
  72. else
  73. {
  74. llwarns << "----- GL WARNING -------" << llendl;
  75. }
  76. llwarns << "Type: " << std::hex << type << llendl;
  77. llwarns << "ID: " << std::hex << id << llendl;
  78. llwarns << "Severity: " << std::hex << severity << llendl;
  79. llwarns << "Message: " << message << llendl;
  80. llwarns << "-----------------------" << llendl;
  81. }
  82. #endif
  83. void ll_init_fail_log(std::string filename)
  84. {
  85. gFailLog.open(filename.c_str());
  86. }
  87. void ll_fail(std::string msg)
  88. {
  89. if (gDebugSession)
  90. {
  91. std::vector<std::string> lines;
  92. gFailLog << LLError::utcTime() << " " << msg << std::endl;
  93. gFailLog << "Stack Trace:" << std::endl;
  94. ll_get_stack_trace(lines);
  95. for(size_t i = 0; i < lines.size(); ++i)
  96. {
  97. gFailLog << lines[i] << std::endl;
  98. }
  99. gFailLog << "End of Stack Trace." << std::endl << std::endl;
  100. gFailLog.flush();
  101. }
  102. };
  103. void ll_close_fail_log()
  104. {
  105. gFailLog.close();
  106. }
  107. LLMatrix4 gGLObliqueProjectionInverse;
  108. #define LL_GL_NAME_POOLING 0
  109. std::list<LLGLUpdate*> LLGLUpdate::sGLQ;
  110. #if (LL_WINDOWS || LL_LINUX || LL_SOLARIS) && !LL_MESA_HEADLESS
  111. // ATI prototypes
  112. #if LL_WINDOWS
  113. PFNGLGETSTRINGIPROC glGetStringi = NULL;
  114. #endif
  115. // vertex blending prototypes
  116. PFNGLWEIGHTPOINTERARBPROC glWeightPointerARB = NULL;
  117. PFNGLVERTEXBLENDARBPROC glVertexBlendARB = NULL;
  118. PFNGLWEIGHTFVARBPROC glWeightfvARB = NULL;
  119. // Vertex buffer object prototypes
  120. PFNGLBINDBUFFERARBPROC glBindBufferARB = NULL;
  121. PFNGLDELETEBUFFERSARBPROC glDeleteBuffersARB = NULL;
  122. PFNGLGENBUFFERSARBPROC glGenBuffersARB = NULL;
  123. PFNGLISBUFFERARBPROC glIsBufferARB = NULL;
  124. PFNGLBUFFERDATAARBPROC glBufferDataARB = NULL;
  125. PFNGLBUFFERSUBDATAARBPROC glBufferSubDataARB = NULL;
  126. PFNGLGETBUFFERSUBDATAARBPROC glGetBufferSubDataARB = NULL;
  127. PFNGLMAPBUFFERARBPROC glMapBufferARB = NULL;
  128. PFNGLUNMAPBUFFERARBPROC glUnmapBufferARB = NULL;
  129. PFNGLGETBUFFERPARAMETERIVARBPROC glGetBufferParameterivARB = NULL;
  130. PFNGLGETBUFFERPOINTERVARBPROC glGetBufferPointervARB = NULL;
  131. //GL_ARB_vertex_array_object
  132. PFNGLBINDVERTEXARRAYPROC glBindVertexArray = NULL;
  133. PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays = NULL;
  134. PFNGLGENVERTEXARRAYSPROC glGenVertexArrays = NULL;
  135. PFNGLISVERTEXARRAYPROC glIsVertexArray = NULL;
  136. // GL_ARB_map_buffer_range
  137. PFNGLMAPBUFFERRANGEPROC glMapBufferRange = NULL;
  138. PFNGLFLUSHMAPPEDBUFFERRANGEPROC glFlushMappedBufferRange = NULL;
  139. // GL_ARB_sync
  140. PFNGLFENCESYNCPROC glFenceSync = NULL;
  141. PFNGLISSYNCPROC glIsSync = NULL;
  142. PFNGLDELETESYNCPROC glDeleteSync = NULL;
  143. PFNGLCLIENTWAITSYNCPROC glClientWaitSync = NULL;
  144. PFNGLWAITSYNCPROC glWaitSync = NULL;
  145. PFNGLGETINTEGER64VPROC glGetInteger64v = NULL;
  146. PFNGLGETSYNCIVPROC glGetSynciv = NULL;
  147. // GL_APPLE_flush_buffer_range
  148. PFNGLBUFFERPARAMETERIAPPLEPROC glBufferParameteriAPPLE = NULL;
  149. PFNGLFLUSHMAPPEDBUFFERRANGEAPPLEPROC glFlushMappedBufferRangeAPPLE = NULL;
  150. // vertex object prototypes
  151. PFNGLNEWOBJECTBUFFERATIPROC glNewObjectBufferATI = NULL;
  152. PFNGLISOBJECTBUFFERATIPROC glIsObjectBufferATI = NULL;
  153. PFNGLUPDATEOBJECTBUFFERATIPROC glUpdateObjectBufferATI = NULL;
  154. PFNGLGETOBJECTBUFFERFVATIPROC glGetObjectBufferfvATI = NULL;
  155. PFNGLGETOBJECTBUFFERIVATIPROC glGetObjectBufferivATI = NULL;
  156. PFNGLFREEOBJECTBUFFERATIPROC glFreeObjectBufferATI = NULL;
  157. PFNGLARRAYOBJECTATIPROC glArrayObjectATI = NULL;
  158. PFNGLVERTEXATTRIBARRAYOBJECTATIPROC glVertexAttribArrayObjectATI = NULL;
  159. PFNGLGETARRAYOBJECTFVATIPROC glGetArrayObjectfvATI = NULL;
  160. PFNGLGETARRAYOBJECTIVATIPROC glGetArrayObjectivATI = NULL;
  161. PFNGLVARIANTARRAYOBJECTATIPROC glVariantObjectArrayATI = NULL;
  162. PFNGLGETVARIANTARRAYOBJECTFVATIPROC glGetVariantArrayObjectfvATI = NULL;
  163. PFNGLGETVARIANTARRAYOBJECTIVATIPROC glGetVariantArrayObjectivATI = NULL;
  164. // GL_ARB_occlusion_query
  165. PFNGLGENQUERIESARBPROC glGenQueriesARB = NULL;
  166. PFNGLDELETEQUERIESARBPROC glDeleteQueriesARB = NULL;
  167. PFNGLISQUERYARBPROC glIsQueryARB = NULL;
  168. PFNGLBEGINQUERYARBPROC glBeginQueryARB = NULL;
  169. PFNGLENDQUERYARBPROC glEndQueryARB = NULL;
  170. PFNGLGETQUERYIVARBPROC glGetQueryivARB = NULL;
  171. PFNGLGETQUERYOBJECTIVARBPROC glGetQueryObjectivARB = NULL;
  172. PFNGLGETQUERYOBJECTUIVARBPROC glGetQueryObjectuivARB = NULL;
  173. // GL_ARB_point_parameters
  174. PFNGLPOINTPARAMETERFARBPROC glPointParameterfARB = NULL;
  175. PFNGLPOINTPARAMETERFVARBPROC glPointParameterfvARB = NULL;
  176. // GL_ARB_framebuffer_object
  177. PFNGLISRENDERBUFFERPROC glIsRenderbuffer = NULL;
  178. PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer = NULL;
  179. PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers = NULL;
  180. PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers = NULL;
  181. PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage = NULL;
  182. PFNGLGETRENDERBUFFERPARAMETERIVPROC glGetRenderbufferParameteriv = NULL;
  183. PFNGLISFRAMEBUFFERPROC glIsFramebuffer = NULL;
  184. PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer = NULL;
  185. PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers = NULL;
  186. PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers = NULL;
  187. PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus = NULL;
  188. PFNGLFRAMEBUFFERTEXTURE1DPROC glFramebufferTexture1D = NULL;
  189. PFNGLFRAMEBUFFERTEXTURE2DPROC glFramebufferTexture2D = NULL;
  190. PFNGLFRAMEBUFFERTEXTURE3DPROC glFramebufferTexture3D = NULL;
  191. PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer = NULL;
  192. PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC glGetFramebufferAttachmentParameteriv = NULL;
  193. PFNGLGENERATEMIPMAPPROC glGenerateMipmap = NULL;
  194. PFNGLBLITFRAMEBUFFERPROC glBlitFramebuffer = NULL;
  195. PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC glRenderbufferStorageMultisample = NULL;
  196. PFNGLFRAMEBUFFERTEXTURELAYERPROC glFramebufferTextureLayer = NULL;
  197. //GL_ARB_texture_multisample
  198. PFNGLTEXIMAGE2DMULTISAMPLEPROC glTexImage2DMultisample = NULL;
  199. PFNGLTEXIMAGE3DMULTISAMPLEPROC glTexImage3DMultisample = NULL;
  200. PFNGLGETMULTISAMPLEFVPROC glGetMultisamplefv = NULL;
  201. PFNGLSAMPLEMASKIPROC glSampleMaski = NULL;
  202. //GL_ARB_debug_output
  203. PFNGLDEBUGMESSAGECONTROLARBPROC glDebugMessageControlARB = NULL;
  204. PFNGLDEBUGMESSAGEINSERTARBPROC glDebugMessageInsertARB = NULL;
  205. PFNGLDEBUGMESSAGECALLBACKARBPROC glDebugMessageCallbackARB = NULL;
  206. PFNGLGETDEBUGMESSAGELOGARBPROC glGetDebugMessageLogARB = NULL;
  207. // GL_EXT_blend_func_separate
  208. PFNGLBLENDFUNCSEPARATEEXTPROC glBlendFuncSeparateEXT = NULL;
  209. // GL_ARB_draw_buffers
  210. PFNGLDRAWBUFFERSARBPROC glDrawBuffersARB = NULL;
  211. //shader object prototypes
  212. PFNGLDELETEOBJECTARBPROC glDeleteObjectARB = NULL;
  213. PFNGLGETHANDLEARBPROC glGetHandleARB = NULL;
  214. PFNGLDETACHOBJECTARBPROC glDetachObjectARB = NULL;
  215. PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB = NULL;
  216. PFNGLSHADERSOURCEARBPROC glShaderSourceARB = NULL;
  217. PFNGLCOMPILESHADERARBPROC glCompileShaderARB = NULL;
  218. PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB = NULL;
  219. PFNGLATTACHOBJECTARBPROC glAttachObjectARB = NULL;
  220. PFNGLLINKPROGRAMARBPROC glLinkProgramARB = NULL;
  221. PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB = NULL;
  222. PFNGLVALIDATEPROGRAMARBPROC glValidateProgramARB = NULL;
  223. PFNGLUNIFORM1FARBPROC glUniform1fARB = NULL;
  224. PFNGLUNIFORM2FARBPROC glUniform2fARB = NULL;
  225. PFNGLUNIFORM3FARBPROC glUniform3fARB = NULL;
  226. PFNGLUNIFORM4FARBPROC glUniform4fARB = NULL;
  227. PFNGLUNIFORM1IARBPROC glUniform1iARB = NULL;
  228. PFNGLUNIFORM2IARBPROC glUniform2iARB = NULL;
  229. PFNGLUNIFORM3IARBPROC glUniform3iARB = NULL;
  230. PFNGLUNIFORM4IARBPROC glUniform4iARB = NULL;
  231. PFNGLUNIFORM1FVARBPROC glUniform1fvARB = NULL;
  232. PFNGLUNIFORM2FVARBPROC glUniform2fvARB = NULL;
  233. PFNGLUNIFORM3FVARBPROC glUniform3fvARB = NULL;
  234. PFNGLUNIFORM4FVARBPROC glUniform4fvARB = NULL;
  235. PFNGLUNIFORM1IVARBPROC glUniform1ivARB = NULL;
  236. PFNGLUNIFORM2IVARBPROC glUniform2ivARB = NULL;
  237. PFNGLUNIFORM3IVARBPROC glUniform3ivARB = NULL;
  238. PFNGLUNIFORM4IVARBPROC glUniform4ivARB = NULL;
  239. PFNGLUNIFORMMATRIX2FVARBPROC glUniformMatrix2fvARB = NULL;
  240. PFNGLUNIFORMMATRIX3FVARBPROC glUniformMatrix3fvARB = NULL;
  241. PFNGLUNIFORMMATRIX4FVARBPROC glUniformMatrix4fvARB = NULL;
  242. PFNGLGETOBJECTPARAMETERFVARBPROC glGetObjectParameterfvARB = NULL;
  243. PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB = NULL;
  244. PFNGLGETINFOLOGARBPROC glGetInfoLogARB = NULL;
  245. PFNGLGETATTACHEDOBJECTSARBPROC glGetAttachedObjectsARB = NULL;
  246. PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB = NULL;
  247. PFNGLGETACTIVEUNIFORMARBPROC glGetActiveUniformARB = NULL;
  248. PFNGLGETUNIFORMFVARBPROC glGetUniformfvARB = NULL;
  249. PFNGLGETUNIFORMIVARBPROC glGetUniformivARB = NULL;
  250. PFNGLGETSHADERSOURCEARBPROC glGetShaderSourceARB = NULL;
  251. #if LL_WINDOWS
  252. PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = NULL;
  253. #endif
  254. // vertex shader prototypes
  255. #if LL_LINUX || LL_SOLARIS
  256. PFNGLVERTEXATTRIB1DARBPROC glVertexAttrib1dARB = NULL;
  257. PFNGLVERTEXATTRIB1DVARBPROC glVertexAttrib1dvARB = NULL;
  258. PFNGLVERTEXATTRIB1FARBPROC glVertexAttrib1fARB = NULL;
  259. PFNGLVERTEXATTRIB1FVARBPROC glVertexAttrib1fvARB = NULL;
  260. PFNGLVERTEXATTRIB1SARBPROC glVertexAttrib1sARB = NULL;
  261. PFNGLVERTEXATTRIB1SVARBPROC glVertexAttrib1svARB = NULL;
  262. PFNGLVERTEXATTRIB2DARBPROC glVertexAttrib2dARB = NULL;
  263. PFNGLVERTEXATTRIB2DVARBPROC glVertexAttrib2dvARB = NULL;
  264. PFNGLVERTEXATTRIB2FARBPROC glVertexAttrib2fARB = NULL;
  265. PFNGLVERTEXATTRIB2FVARBPROC glVertexAttrib2fvARB = NULL;
  266. PFNGLVERTEXATTRIB2SARBPROC glVertexAttrib2sARB = NULL;
  267. PFNGLVERTEXATTRIB2SVARBPROC glVertexAttrib2svARB = NULL;
  268. PFNGLVERTEXATTRIB3DARBPROC glVertexAttrib3dARB = NULL;
  269. PFNGLVERTEXATTRIB3DVARBPROC glVertexAttrib3dvARB = NULL;
  270. PFNGLVERTEXATTRIB3FARBPROC glVertexAttrib3fARB = NULL;
  271. PFNGLVERTEXATTRIB3FVARBPROC glVertexAttrib3fvARB = NULL;
  272. PFNGLVERTEXATTRIB3SARBPROC glVertexAttrib3sARB = NULL;
  273. PFNGLVERTEXATTRIB3SVARBPROC glVertexAttrib3svARB = NULL;
  274. #endif // LL_LINUX || LL_SOLARIS
  275. PFNGLVERTEXATTRIB4NBVARBPROC glVertexAttrib4nbvARB = NULL;
  276. PFNGLVERTEXATTRIB4NIVARBPROC glVertexAttrib4nivARB = NULL;
  277. PFNGLVERTEXATTRIB4NSVARBPROC glVertexAttrib4nsvARB = NULL;
  278. PFNGLVERTEXATTRIB4NUBARBPROC glVertexAttrib4nubARB = NULL;
  279. PFNGLVERTEXATTRIB4NUBVARBPROC glVertexAttrib4nubvARB = NULL;
  280. PFNGLVERTEXATTRIB4NUIVARBPROC glVertexAttrib4nuivARB = NULL;
  281. PFNGLVERTEXATTRIB4NUSVARBPROC glVertexAttrib4nusvARB = NULL;
  282. #if LL_LINUX || LL_SOLARIS
  283. PFNGLVERTEXATTRIB4BVARBPROC glVertexAttrib4bvARB = NULL;
  284. PFNGLVERTEXATTRIB4DARBPROC glVertexAttrib4dARB = NULL;
  285. PFNGLVERTEXATTRIB4DVARBPROC glVertexAttrib4dvARB = NULL;
  286. PFNGLVERTEXATTRIB4FARBPROC glVertexAttrib4fARB = NULL;
  287. PFNGLVERTEXATTRIB4FVARBPROC glVertexAttrib4fvARB = NULL;
  288. PFNGLVERTEXATTRIB4IVARBPROC glVertexAttrib4ivARB = NULL;
  289. PFNGLVERTEXATTRIB4SARBPROC glVertexAttrib4sARB = NULL;
  290. PFNGLVERTEXATTRIB4SVARBPROC glVertexAttrib4svARB = NULL;
  291. PFNGLVERTEXATTRIB4UBVARBPROC glVertexAttrib4ubvARB = NULL;
  292. PFNGLVERTEXATTRIB4UIVARBPROC glVertexAttrib4uivARB = NULL;
  293. PFNGLVERTEXATTRIB4USVARBPROC glVertexAttrib4usvARB = NULL;
  294. PFNGLVERTEXATTRIBPOINTERARBPROC glVertexAttribPointerARB = NULL;
  295. PFNGLENABLEVERTEXATTRIBARRAYARBPROC glEnableVertexAttribArrayARB = NULL;
  296. PFNGLDISABLEVERTEXATTRIBARRAYARBPROC glDisableVertexAttribArrayARB = NULL;
  297. PFNGLPROGRAMSTRINGARBPROC glProgramStringARB = NULL;
  298. PFNGLBINDPROGRAMARBPROC glBindProgramARB = NULL;
  299. PFNGLDELETEPROGRAMSARBPROC glDeleteProgramsARB = NULL;
  300. PFNGLGENPROGRAMSARBPROC glGenProgramsARB = NULL;
  301. PFNGLPROGRAMENVPARAMETER4DARBPROC glProgramEnvParameter4dARB = NULL;
  302. PFNGLPROGRAMENVPARAMETER4DVARBPROC glProgramEnvParameter4dvARB = NULL;
  303. PFNGLPROGRAMENVPARAMETER4FARBPROC glProgramEnvParameter4fARB = NULL;
  304. PFNGLPROGRAMENVPARAMETER4FVARBPROC glProgramEnvParameter4fvARB = NULL;
  305. PFNGLPROGRAMLOCALPARAMETER4DARBPROC glProgramLocalParameter4dARB = NULL;
  306. PFNGLPROGRAMLOCALPARAMETER4DVARBPROC glProgramLocalParameter4dvARB = NULL;
  307. PFNGLPROGRAMLOCALPARAMETER4FARBPROC glProgramLocalParameter4fARB = NULL;
  308. PFNGLPROGRAMLOCALPARAMETER4FVARBPROC glProgramLocalParameter4fvARB = NULL;
  309. PFNGLGETPROGRAMENVPARAMETERDVARBPROC glGetProgramEnvParameterdvARB = NULL;
  310. PFNGLGETPROGRAMENVPARAMETERFVARBPROC glGetProgramEnvParameterfvARB = NULL;
  311. PFNGLGETPROGRAMLOCALPARAMETERDVARBPROC glGetProgramLocalParameterdvARB = NULL;
  312. PFNGLGETPROGRAMLOCALPARAMETERFVARBPROC glGetProgramLocalParameterfvARB = NULL;
  313. PFNGLGETPROGRAMIVARBPROC glGetProgramivARB = NULL;
  314. PFNGLGETPROGRAMSTRINGARBPROC glGetProgramStringARB = NULL;
  315. PFNGLGETVERTEXATTRIBDVARBPROC glGetVertexAttribdvARB = NULL;
  316. PFNGLGETVERTEXATTRIBFVARBPROC glGetVertexAttribfvARB = NULL;
  317. PFNGLGETVERTEXATTRIBIVARBPROC glGetVertexAttribivARB = NULL;
  318. PFNGLGETVERTEXATTRIBPOINTERVARBPROC glGetVertexAttribPointervARB = NULL;
  319. PFNGLISPROGRAMARBPROC glIsProgramARB = NULL;
  320. #endif // LL_LINUX || LL_SOLARIS
  321. PFNGLBINDATTRIBLOCATIONARBPROC glBindAttribLocationARB = NULL;
  322. PFNGLGETACTIVEATTRIBARBPROC glGetActiveAttribARB = NULL;
  323. PFNGLGETATTRIBLOCATIONARBPROC glGetAttribLocationARB = NULL;
  324. #if LL_WINDOWS
  325. PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = NULL;
  326. #endif
  327. #if LL_LINUX_NV_GL_HEADERS
  328. // linux nvidia headers. these define these differently to mesa's. ugh.
  329. PFNGLACTIVETEXTUREARBPROC glActiveTextureARB = NULL;
  330. PFNGLCLIENTACTIVETEXTUREARBPROC glClientActiveTextureARB = NULL;
  331. PFNGLDRAWRANGEELEMENTSPROC glDrawRangeElements = NULL;
  332. #endif // LL_LINUX_NV_GL_HEADERS
  333. #endif
  334. LLGLManager gGLManager;
  335. LLGLManager::LLGLManager() :
  336. mInited(FALSE),
  337. mIsDisabled(FALSE),
  338. mHasMultitexture(FALSE),
  339. mHasATIMemInfo(FALSE),
  340. mHasNVXMemInfo(FALSE),
  341. mNumTextureUnits(1),
  342. mHasMipMapGeneration(FALSE),
  343. mHasCompressedTextures(FALSE),
  344. mHasFramebufferObject(FALSE),
  345. mMaxSamples(0),
  346. mHasBlendFuncSeparate(FALSE),
  347. mHasSync(FALSE),
  348. mHasVertexBufferObject(FALSE),
  349. mHasVertexArrayObject(FALSE),
  350. mHasMapBufferRange(FALSE),
  351. mHasFlushBufferRange(FALSE),
  352. mHasPBuffer(FALSE),
  353. mHasShaderObjects(FALSE),
  354. mHasVertexShader(FALSE),
  355. mHasFragmentShader(FALSE),
  356. mNumTextureImageUnits(0),
  357. mHasOcclusionQuery(FALSE),
  358. mHasOcclusionQuery2(FALSE),
  359. mHasPointParameters(FALSE),
  360. mHasDrawBuffers(FALSE),
  361. mHasTextureRectangle(FALSE),
  362. mHasTextureMultisample(FALSE),
  363. mMaxSampleMaskWords(0),
  364. mMaxColorTextureSamples(0),
  365. mMaxDepthTextureSamples(0),
  366. mMaxIntegerSamples(0),
  367. mHasAnisotropic(FALSE),
  368. mHasARBEnvCombine(FALSE),
  369. mHasCubeMap(FALSE),
  370. mHasDebugOutput(FALSE),
  371. mIsATI(FALSE),
  372. mIsNVIDIA(FALSE),
  373. mIsIntel(FALSE),
  374. mIsGF2or4MX(FALSE),
  375. mIsGF3(FALSE),
  376. mIsGFFX(FALSE),
  377. mATIOffsetVerticalLines(FALSE),
  378. mATIOldDriver(FALSE),
  379. mHasRequirements(TRUE),
  380. mHasSeparateSpecularColor(FALSE),
  381. mDebugGPU(FALSE),
  382. mDriverVersionMajor(1),
  383. mDriverVersionMinor(0),
  384. mDriverVersionRelease(0),
  385. mGLVersion(1.0f),
  386. mVRAM(0),
  387. mGLMaxVertexRange(0),
  388. mGLMaxIndexRange(0)
  389. {
  390. }
  391. //---------------------------------------------------------------------
  392. // Global initialization for GL
  393. //---------------------------------------------------------------------
  394. void LLGLManager::initWGL()
  395. {
  396. mHasPBuffer = FALSE;
  397. #if LL_WINDOWS && !LL_MESA_HEADLESS
  398. if (!glh_init_extensions("WGL_ARB_pixel_format"))
  399. {
  400. LL_WARNS("RenderInit") << "No ARB pixel format extensions" << LL_ENDL;
  401. }
  402. if (ExtensionExists("WGL_ARB_create_context",gGLHExts.mSysExts))
  403. {
  404. GLH_EXT_NAME(wglCreateContextAttribsARB) = (PFNWGLCREATECONTEXTATTRIBSARBPROC)GLH_EXT_GET_PROC_ADDRESS("wglCreateContextAttribsARB");
  405. }
  406. else
  407. {
  408. LL_WARNS("RenderInit") << "No ARB create context extensions" << LL_ENDL;
  409. }
  410. if (ExtensionExists("WGL_EXT_swap_control", gGLHExts.mSysExts))
  411. {
  412. GLH_EXT_NAME(wglSwapIntervalEXT) = (PFNWGLSWAPINTERVALEXTPROC)GLH_EXT_GET_PROC_ADDRESS("wglSwapIntervalEXT");
  413. }
  414. if( !glh_init_extensions("WGL_ARB_pbuffer") )
  415. {
  416. LL_WARNS("RenderInit") << "No ARB WGL PBuffer extensions" << LL_ENDL;
  417. }
  418. if( !glh_init_extensions("WGL_ARB_render_texture") )
  419. {
  420. LL_WARNS("RenderInit") << "No ARB WGL render texture extensions" << LL_ENDL;
  421. }
  422. mHasPBuffer = ExtensionExists("WGL_ARB_pbuffer", gGLHExts.mSysExts) &&
  423. ExtensionExists("WGL_ARB_render_texture", gGLHExts.mSysExts) &&
  424. ExtensionExists("WGL_ARB_pixel_format", gGLHExts.mSysExts);
  425. #endif
  426. }
  427. // return false if unable (or unwilling due to old drivers) to init GL
  428. bool LLGLManager::initGL()
  429. {
  430. if (mInited)
  431. {
  432. LL_ERRS("RenderInit") << "Calling init on LLGLManager after already initialized!" << LL_ENDL;
  433. }
  434. stop_glerror();
  435. #if LL_WINDOWS
  436. if (!glGetStringi)
  437. {
  438. glGetStringi = (PFNGLGETSTRINGIPROC) GLH_EXT_GET_PROC_ADDRESS("glGetStringi");
  439. }
  440. //reload extensions string (may have changed after using wglCreateContextAttrib)
  441. if (glGetStringi)
  442. {
  443. std::stringstream str;
  444. GLint count = 0;
  445. glGetIntegerv(GL_NUM_EXTENSIONS, &count);
  446. for (GLint i = 0; i < count; ++i)
  447. {
  448. std::string ext((const char*) glGetStringi(GL_EXTENSIONS, i));
  449. str << ext << " ";
  450. LL_DEBUGS("GLExtensions") << ext << llendl;
  451. }
  452. {
  453. PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = 0;
  454. wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
  455. if(wglGetExtensionsStringARB)
  456. {
  457. str << (const char*) wglGetExtensionsStringARB(wglGetCurrentDC());
  458. }
  459. }
  460. free(gGLHExts.mSysExts);
  461. std::string extensions = str.str();
  462. gGLHExts.mSysExts = strdup(extensions.c_str());
  463. }
  464. #endif
  465. stop_glerror();
  466. // Extract video card strings and convert to upper case to
  467. // work around driver-to-driver variation in capitalization.
  468. mGLVendor = std::string((const char *)glGetString(GL_VENDOR));
  469. LLStringUtil::toUpper(mGLVendor);
  470. mGLRenderer = std::string((const char *)glGetString(GL_RENDERER));
  471. LLStringUtil::toUpper(mGLRenderer);
  472. parse_gl_version( &mDriverVersionMajor,
  473. &mDriverVersionMinor,
  474. &mDriverVersionRelease,
  475. &mDriverVersionVendorString );
  476. mGLVersion = mDriverVersionMajor + mDriverVersionMinor * .1f;
  477. // Trailing space necessary to keep "nVidia Corpor_ati_on" cards
  478. // from being recognized as ATI.
  479. if (mGLVendor.substr(0,4) == "ATI ")
  480. {
  481. mGLVendorShort = "ATI";
  482. BOOL mobile = FALSE;
  483. if (mGLRenderer.find("MOBILITY") != std::string::npos)
  484. {
  485. mobile = TRUE;
  486. }
  487. mIsATI = TRUE;
  488. #if LL_WINDOWS && !LL_MESA_HEADLESS
  489. if (mDriverVersionRelease < 3842)
  490. {
  491. mATIOffsetVerticalLines = TRUE;
  492. }
  493. #endif // LL_WINDOWS
  494. #if (LL_WINDOWS || LL_LINUX) && !LL_MESA_HEADLESS
  495. // release 7277 is a point at which we verify that ATI OpenGL
  496. // drivers get pretty stable with SL, ~Catalyst 8.2,
  497. // for both Win32 and Linux.
  498. if (mDriverVersionRelease < 7277 &&
  499. mDriverVersionRelease != 0) // 0 == Undetectable driver version - these get to pretend to be new ATI drivers, though that decision may be revisited.
  500. {
  501. mATIOldDriver = TRUE;
  502. }
  503. #endif // (LL_WINDOWS || LL_LINUX) && !LL_MESA_HEADLESS
  504. }
  505. else if (mGLVendor.find("NVIDIA ") != std::string::npos)
  506. {
  507. mGLVendorShort = "NVIDIA";
  508. mIsNVIDIA = TRUE;
  509. if ( mGLRenderer.find("GEFORCE4 MX") != std::string::npos
  510. || mGLRenderer.find("GEFORCE2") != std::string::npos
  511. || mGLRenderer.find("GEFORCE 2") != std::string::npos
  512. || mGLRenderer.find("GEFORCE4 460 GO") != std::string::npos
  513. || mGLRenderer.find("GEFORCE4 440 GO") != std::string::npos
  514. || mGLRenderer.find("GEFORCE4 420 GO") != std::string::npos)
  515. {
  516. mIsGF2or4MX = TRUE;
  517. }
  518. else if (mGLRenderer.find("GEFORCE FX") != std::string::npos
  519. || mGLRenderer.find("QUADRO FX") != std::string::npos
  520. || mGLRenderer.find("NV34") != std::string::npos)
  521. {
  522. mIsGFFX = TRUE;
  523. }
  524. else if(mGLRenderer.find("GEFORCE3") != std::string::npos)
  525. {
  526. mIsGF3 = TRUE;
  527. }
  528. }
  529. else if (mGLVendor.find("INTEL") != std::string::npos
  530. #if LL_LINUX
  531. // The Mesa-based drivers put this in the Renderer string,
  532. // not the Vendor string.
  533. || mGLRenderer.find("INTEL") != std::string::npos
  534. #endif //LL_LINUX
  535. )
  536. {
  537. mGLVendorShort = "INTEL";
  538. mIsIntel = TRUE;
  539. }
  540. else
  541. {
  542. mGLVendorShort = "MISC";
  543. }
  544. stop_glerror();
  545. // This is called here because it depends on the setting of mIsGF2or4MX, and sets up mHasMultitexture.
  546. initExtensions();
  547. stop_glerror();
  548. S32 old_vram = mVRAM;
  549. if (mHasATIMemInfo)
  550. { //ask the gl how much vram is free at startup and attempt to use no more than half of that
  551. S32 meminfo[4];
  552. glGetIntegerv(GL_TEXTURE_FREE_MEMORY_ATI, meminfo);
  553. mVRAM = meminfo[0]/1024;
  554. }
  555. else if (mHasNVXMemInfo)
  556. {
  557. S32 dedicated_memory;
  558. glGetIntegerv(GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX, &dedicated_memory);
  559. mVRAM = dedicated_memory/1024;
  560. }
  561. if (mVRAM < 256)
  562. { //something likely went wrong using the above extensions, fall back to old method
  563. mVRAM = old_vram;
  564. }
  565. stop_glerror();
  566. stop_glerror();
  567. if (mHasFragmentShader)
  568. {
  569. GLint num_tex_image_units;
  570. glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &num_tex_image_units);
  571. mNumTextureImageUnits = llmin(num_tex_image_units, 32);
  572. }
  573. if (LLRender::sGLCoreProfile)
  574. {
  575. mNumTextureUnits = llmin(mNumTextureImageUnits, MAX_GL_TEXTURE_UNITS);
  576. }
  577. else if (mHasMultitexture)
  578. {
  579. GLint num_tex_units;
  580. glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &num_tex_units);
  581. mNumTextureUnits = llmin(num_tex_units, (GLint)MAX_GL_TEXTURE_UNITS);
  582. if (mIsIntel)
  583. {
  584. mNumTextureUnits = llmin(mNumTextureUnits, 2);
  585. }
  586. }
  587. else
  588. {
  589. mHasRequirements = FALSE;
  590. // We don't support cards that don't support the GL_ARB_multitexture extension
  591. LL_WARNS("RenderInit") << "GL Drivers do not support GL_ARB_multitexture" << LL_ENDL;
  592. return false;
  593. }
  594. stop_glerror();
  595. if (mHasTextureMultisample)
  596. {
  597. glGetIntegerv(GL_MAX_COLOR_TEXTURE_SAMPLES, &mMaxColorTextureSamples);
  598. glGetIntegerv(GL_MAX_DEPTH_TEXTURE_SAMPLES, &mMaxDepthTextureSamples);
  599. glGetIntegerv(GL_MAX_INTEGER_SAMPLES, &mMaxIntegerSamples);
  600. glGetIntegerv(GL_MAX_SAMPLE_MASK_WORDS, &mMaxSampleMaskWords);
  601. }
  602. stop_glerror();
  603. #if LL_WINDOWS
  604. if (mHasDebugOutput && gDebugGL)
  605. { //setup debug output callback
  606. //glDebugMessageControlARB(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_LOW_ARB, 0, NULL, GL_TRUE);
  607. glDebugMessageCallbackARB((GLDEBUGPROCARB) gl_debug_callback, NULL);
  608. glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB);
  609. }
  610. #endif
  611. stop_glerror();
  612. //HACK always disable texture multisample, use FXAA instead
  613. mHasTextureMultisample = FALSE;
  614. #if LL_WINDOWS
  615. if (mIsATI)
  616. { //using multisample textures on ATI results in black screen for some reason
  617. mHasTextureMultisample = FALSE;
  618. }
  619. #endif
  620. if (mHasFramebufferObject)
  621. {
  622. glGetIntegerv(GL_MAX_SAMPLES, &mMaxSamples);
  623. }
  624. stop_glerror();
  625. setToDebugGPU();
  626. stop_glerror();
  627. initGLStates();
  628. stop_glerror();
  629. return true;
  630. }
  631. void LLGLManager::setToDebugGPU()
  632. {
  633. //"MOBILE INTEL(R) 965 EXPRESS CHIP",
  634. if (mGLRenderer.find("INTEL") != std::string::npos && mGLRenderer.find("965") != std::string::npos)
  635. {
  636. mDebugGPU = TRUE ;
  637. }
  638. return ;
  639. }
  640. void LLGLManager::getGLInfo(LLSD& info)
  641. {
  642. if (gHeadlessClient)
  643. {
  644. info["GLInfo"]["GLVendor"] = HEADLESS_VENDOR_STRING;
  645. info["GLInfo"]["GLRenderer"] = HEADLESS_RENDERER_STRING;
  646. info["GLInfo"]["GLVersion"] = HEADLESS_VERSION_STRING;
  647. return;
  648. }
  649. else
  650. {
  651. info["GLInfo"]["GLVendor"] = std::string((const char *)glGetString(GL_VENDOR));
  652. info["GLInfo"]["GLRenderer"] = std::string((const char *)glGetString(GL_RENDERER));
  653. info["GLInfo"]["GLVersion"] = std::string((const char *)glGetString(GL_VERSION));
  654. }
  655. #if !LL_MESA_HEADLESS
  656. std::string all_exts = ll_safe_string((const char *)gGLHExts.mSysExts);
  657. boost::char_separator<char> sep(" ");
  658. boost::tokenizer<boost::char_separator<char> > tok(all_exts, sep);
  659. for(boost::tokenizer<boost::char_separator<char> >::iterator i = tok.begin(); i != tok.end(); ++i)
  660. {
  661. info["GLInfo"]["GLExtensions"].append(*i);
  662. }
  663. #endif
  664. }
  665. std::string LLGLManager::getGLInfoString()
  666. {
  667. std::string info_str;
  668. if (gHeadlessClient)
  669. {
  670. info_str += std::string("GL_VENDOR ") + HEADLESS_VENDOR_STRING + std::string("\n");
  671. info_str += std::string("GL_RENDERER ") + HEADLESS_RENDERER_STRING + std::string("\n");
  672. info_str += std::string("GL_VERSION ") + HEADLESS_VERSION_STRING + std::string("\n");
  673. }
  674. else
  675. {
  676. info_str += std::string("GL_VENDOR ") + ll_safe_string((const char *)glGetString(GL_VENDOR)) + std::string("\n");
  677. info_str += std::string("GL_RENDERER ") + ll_safe_string((const char *)glGetString(GL_RENDERER)) + std::string("\n");
  678. info_str += std::string("GL_VERSION ") + ll_safe_string((const char *)glGetString(GL_VERSION)) + std::string("\n");
  679. }
  680. #if !LL_MESA_HEADLESS
  681. std::string all_exts= ll_safe_string(((const char *)gGLHExts.mSysExts));
  682. LLStringUtil::replaceChar(all_exts, ' ', '\n');
  683. info_str += std::string("GL_EXTENSIONS:\n") + all_exts + std::string("\n");
  684. #endif
  685. return info_str;
  686. }
  687. void LLGLManager::printGLInfoString()
  688. {
  689. if (gHeadlessClient)
  690. {
  691. LL_INFOS("RenderInit") << "GL_VENDOR: " << HEADLESS_VENDOR_STRING << LL_ENDL;
  692. LL_INFOS("RenderInit") << "GL_RENDERER: " << HEADLESS_RENDERER_STRING << LL_ENDL;
  693. LL_INFOS("RenderInit") << "GL_VERSION: " << HEADLESS_VERSION_STRING << LL_ENDL;
  694. }
  695. else
  696. {
  697. LL_INFOS("RenderInit") << "GL_VENDOR: " << ((const char *)glGetString(GL_VENDOR)) << LL_ENDL;
  698. LL_INFOS("RenderInit") << "GL_RENDERER: " << ((const char *)glGetString(GL_RENDERER)) << LL_ENDL;
  699. LL_INFOS("RenderInit") << "GL_VERSION: " << ((const char *)glGetString(GL_VERSION)) << LL_ENDL;
  700. }
  701. #if !LL_MESA_HEADLESS
  702. std::string all_exts= ll_safe_string(((const char *)gGLHExts.mSysExts));
  703. LLStringUtil::replaceChar(all_exts, ' ', '\n');
  704. LL_DEBUGS("RenderInit") << "GL_EXTENSIONS:\n" << all_exts << LL_ENDL;
  705. #endif
  706. }
  707. std::string LLGLManager::getRawGLString()
  708. {
  709. std::string gl_string;
  710. if (gHeadlessClient)
  711. {
  712. gl_string = HEADLESS_VENDOR_STRING + " " + HEADLESS_RENDERER_STRING;
  713. }
  714. else
  715. {
  716. gl_string = ll_safe_string((char*)glGetString(GL_VENDOR)) + " " + ll_safe_string((char*)glGetString(GL_RENDERER));
  717. }
  718. return gl_string;
  719. }
  720. void LLGLManager::shutdownGL()
  721. {
  722. if (mInited)
  723. {
  724. glFinish();
  725. stop_glerror();
  726. mInited = FALSE;
  727. }
  728. }
  729. // these are used to turn software blending on. They appear in the Debug/Avatar menu
  730. // presence of vertex skinning/blending or vertex programs will set these to FALSE by default.
  731. void LLGLManager::initExtensions()
  732. {
  733. #if LL_MESA_HEADLESS
  734. # ifdef GL_ARB_multitexture
  735. mHasMultitexture = TRUE;
  736. # else
  737. mHasMultitexture = FALSE;
  738. # endif // GL_ARB_multitexture
  739. # ifdef GL_ARB_texture_env_combine
  740. mHasARBEnvCombine = TRUE;
  741. # else
  742. mHasARBEnvCombine = FALSE;
  743. # endif // GL_ARB_texture_env_combine
  744. # ifdef GL_ARB_texture_compression
  745. mHasCompressedTextures = TRUE;
  746. # else
  747. mHasCompressedTextures = FALSE;
  748. # endif // GL_ARB_texture_compression
  749. # ifdef GL_ARB_vertex_buffer_object
  750. mHasVertexBufferObject = TRUE;
  751. # else
  752. mHasVertexBufferObject = FALSE;
  753. # endif // GL_ARB_vertex_buffer_object
  754. # ifdef GL_EXT_framebuffer_object
  755. mHasFramebufferObject = TRUE;
  756. # else
  757. mHasFramebufferObject = FALSE;
  758. # endif // GL_EXT_framebuffer_object
  759. # ifdef GL_ARB_draw_buffers
  760. mHasDrawBuffers = TRUE;
  761. #else
  762. mHasDrawBuffers = FALSE;
  763. # endif // GL_ARB_draw_buffers
  764. # if defined(GL_NV_depth_clamp) || defined(GL_ARB_depth_clamp)
  765. mHasDepthClamp = TRUE;
  766. #else
  767. mHasDepthClamp = FALSE;
  768. #endif // defined(GL_NV_depth_clamp) || defined(GL_ARB_depth_clamp)
  769. # if GL_EXT_blend_func_separate
  770. mHasBlendFuncSeparate = TRUE;
  771. #else
  772. mHasBlendFuncSeparate = FALSE;
  773. # endif // GL_EXT_blend_func_separate
  774. mHasMipMapGeneration = FALSE;
  775. mHasSeparateSpecularColor = FALSE;
  776. mHasAnisotropic = FALSE;
  777. mHasCubeMap = FALSE;
  778. mHasOcclusionQuery = FALSE;
  779. mHasPointParameters = FALSE;
  780. mHasShaderObjects = FALSE;
  781. mHasVertexShader = FALSE;
  782. mHasFragmentShader = FALSE;
  783. mHasTextureRectangle = FALSE;
  784. #else // LL_MESA_HEADLESS //important, gGLHExts.mSysExts is uninitialized until after glh_init_extensions is called
  785. mHasMultitexture = glh_init_extensions("GL_ARB_multitexture");
  786. mHasATIMemInfo = ExtensionExists("GL_ATI_meminfo", gGLHExts.mSysExts);
  787. mHasNVXMemInfo = ExtensionExists("GL_NVX_gpu_memory_info", gGLHExts.mSysExts);
  788. mHasMipMapGeneration = glh_init_extensions("GL_SGIS_generate_mipmap");
  789. mHasSeparateSpecularColor = glh_init_extensions("GL_EXT_separate_specular_color");
  790. mHasAnisotropic = glh_init_extensions("GL_EXT_texture_filter_anisotropic");
  791. glh_init_extensions("GL_ARB_texture_cube_map");
  792. mHasCubeMap = ExtensionExists("GL_ARB_texture_cube_map", gGLHExts.mSysExts);
  793. mHasARBEnvCombine = ExtensionExists("GL_ARB_texture_env_combine", gGLHExts.mSysExts);
  794. mHasCompressedTextures = glh_init_extensions("GL_ARB_texture_compression");
  795. mHasOcclusionQuery = ExtensionExists("GL_ARB_occlusion_query", gGLHExts.mSysExts);
  796. mHasOcclusionQuery2 = ExtensionExists("GL_ARB_occlusion_query2", gGLHExts.mSysExts);
  797. mHasVertexBufferObject = ExtensionExists("GL_ARB_vertex_buffer_object", gGLHExts.mSysExts);
  798. mHasVertexArrayObject = ExtensionExists("GL_ARB_vertex_array_object", gGLHExts.mSysExts);
  799. mHasSync = ExtensionExists("GL_ARB_sync", gGLHExts.mSysExts);
  800. mHasMapBufferRange = ExtensionExists("GL_ARB_map_buffer_range", gGLHExts.mSysExts);
  801. mHasFlushBufferRange = ExtensionExists("GL_APPLE_flush_buffer_range", gGLHExts.mSysExts);
  802. mHasDepthClamp = ExtensionExists("GL_ARB_depth_clamp", gGLHExts.mSysExts) || ExtensionExists("GL_NV_depth_clamp", gGLHExts.mSysExts);
  803. // mask out FBO support when packed_depth_stencil isn't there 'cause we need it for LLRenderTarget -Brad
  804. #ifdef GL_ARB_framebuffer_object
  805. mHasFramebufferObject = ExtensionExists("GL_ARB_framebuffer_object", gGLHExts.mSysExts);
  806. #else
  807. mHasFramebufferObject = ExtensionExists("GL_EXT_framebuffer_object", gGLHExts.mSysExts) &&
  808. ExtensionExists("GL_EXT_framebuffer_blit", gGLHExts.mSysExts) &&
  809. ExtensionExists("GL_EXT_framebuffer_multisample", gGLHExts.mSysExts) &&
  810. ExtensionExists("GL_EXT_packed_depth_stencil", gGLHExts.mSysExts);
  811. #endif
  812. mHasDrawBuffers = ExtensionExists("GL_ARB_draw_buffers", gGLHExts.mSysExts);
  813. mHasBlendFuncSeparate = ExtensionExists("GL_EXT_blend_func_separate", gGLHExts.mSysExts);
  814. mHasTextureRectangle = ExtensionExists("GL_ARB_texture_rectangle", gGLHExts.mSysExts);
  815. mHasTextureMultisample = ExtensionExists("GL_ARB_texture_multisample", gGLHExts.mSysExts);
  816. mHasDebugOutput = ExtensionExists("GL_ARB_debug_output", gGLHExts.mSysExts);
  817. #if !LL_DARWIN
  818. mHasPointParameters = !mIsATI && ExtensionExists("GL_ARB_point_parameters", gGLHExts.mSysExts);
  819. #endif
  820. mHasShaderObjects = ExtensionExists("GL_ARB_shader_objects", gGLHExts.mSysExts) && (LLRender::sGLCoreProfile || ExtensionExists("GL_ARB_shading_language_100", gGLHExts.mSysExts));
  821. mHasVertexShader = ExtensionExists("GL_ARB_vertex_program", gGLHExts.mSysExts) && ExtensionExists("GL_ARB_vertex_shader", gGLHExts.mSysExts)
  822. && (LLRender::sGLCoreProfile || ExtensionExists("GL_ARB_shading_language_100", gGLHExts.mSysExts));
  823. mHasFragmentShader = ExtensionExists("GL_ARB_fragment_shader", gGLHExts.mSysExts) && (LLRender::sGLCoreProfile || ExtensionExists("GL_ARB_shading_language_100", gGLHExts.mSysExts));
  824. #endif
  825. #if LL_LINUX || LL_SOLARIS
  826. llinfos << "initExtensions() checking shell variables to adjust features..." << llendl;
  827. // Our extension support for the Linux Client is very young with some
  828. // potential driver gotchas, so offer a semi-secret way to turn it off.
  829. if (getenv("LL_GL_NOEXT"))
  830. {
  831. //mHasMultitexture = FALSE; // NEEDED!
  832. mHasDepthClamp = FALSE;
  833. mHasARBEnvCombine = FALSE;
  834. mHasCompressedTextures = FALSE;
  835. mHasVertexBufferObject = FALSE;
  836. mHasFramebufferObject = FALSE;
  837. mHasDrawBuffers = FALSE;
  838. mHasBlendFuncSeparate = FALSE;
  839. mHasMipMapGeneration = FALSE;
  840. mHasSeparateSpecularColor = FALSE;
  841. mHasAnisotropic = FALSE;
  842. mHasCubeMap = FALSE;
  843. mHasOcclusionQuery = FALSE;
  844. mHasPointParameters = FALSE;
  845. mHasShaderObjects = FALSE;
  846. mHasVertexShader = FALSE;
  847. mHasFragmentShader = FALSE;
  848. LL_WARNS("RenderInit") << "GL extension support DISABLED via LL_GL_NOEXT" << LL_ENDL;
  849. }
  850. else if (getenv("LL_GL_BASICEXT")) /* Flawfinder: ignore */
  851. {
  852. // This switch attempts to turn off all support for exotic
  853. // extensions which I believe correspond to fatal driver
  854. // bug reports. This should be the default until we get a
  855. // proper blacklist/whitelist on Linux.
  856. mHasMipMapGeneration = FALSE;
  857. mHasAnisotropic = FALSE;
  858. //mHasCubeMap = FALSE; // apparently fatal on Intel 915 & similar
  859. //mHasOcclusionQuery = FALSE; // source of many ATI system hangs
  860. mHasShaderObjects = FALSE;
  861. mHasVertexShader = FALSE;
  862. mHasFragmentShader = FALSE;
  863. mHasBlendFuncSeparate = FALSE;
  864. LL_WARNS("RenderInit") << "GL extension support forced to SIMPLE level via LL_GL_BASICEXT" << LL_ENDL;
  865. }
  866. if (getenv("LL_GL_BLACKLIST")) /* Flawfinder: ignore */
  867. {
  868. // This lets advanced troubleshooters disable specific
  869. // GL extensions to isolate problems with their hardware.
  870. // SL-28126
  871. const char *const blacklist = getenv("LL_GL_BLACKLIST"); /* Flawfinder: ignore */
  872. LL_WARNS("RenderInit") << "GL extension support partially disabled via LL_GL_BLACKLIST: " << blacklist << LL_ENDL;
  873. if (strchr(blacklist,'a')) mHasARBEnvCombine = FALSE;
  874. if (strchr(blacklist,'b')) mHasCompressedTextures = FALSE;
  875. if (strchr(blacklist,'c')) mHasVertexBufferObject = FALSE;
  876. if (strchr(blacklist,'d')) mHasMipMapGeneration = FALSE;//S
  877. // if (strchr(blacklist,'f')) mHasNVVertexArrayRange = FALSE;//S
  878. // if (strchr(blacklist,'g')) mHasNVFence = FALSE;//S
  879. if (strchr(blacklist,'h')) mHasSeparateSpecularColor = FALSE;
  880. if (strchr(blacklist,'i')) mHasAnisotropic = FALSE;//S
  881. if (strchr(blacklist,'j')) mHasCubeMap = FALSE;//S
  882. // if (strchr(blacklist,'k')) mHasATIVAO = FALSE;//S
  883. if (strchr(blacklist,'l')) mHasOcclusionQuery = FALSE;
  884. if (strchr(blacklist,'m')) mHasShaderObjects = FALSE;//S
  885. if (strchr(blacklist,'n')) mHasVertexShader = FALSE;//S
  886. if (strchr(blacklist,'o')) mHasFragmentShader = FALSE;//S
  887. if (strchr(blacklist,'p')) mHasPointParameters = FALSE;//S
  888. if (strchr(blacklist,'q')) mHasFramebufferObject = FALSE;//S
  889. if (strchr(blacklist,'r')) mHasDrawBuffers = FALSE;//S
  890. if (strchr(blacklist,'s')) mHasTextureRectangle = FALSE;
  891. if (strchr(blacklist,'t')) mHasBlendFuncSeparate = FALSE;//S
  892. if (strchr(blacklist,'u')) mHasDepthClamp = FALSE;
  893. }
  894. #endif // LL_LINUX || LL_SOLARIS
  895. if (!mHasMultitexture)
  896. {
  897. LL_INFOS("RenderInit") << "Couldn't initialize multitexturing" << LL_ENDL;
  898. }
  899. if (!mHasMipMapGeneration)
  900. {
  901. LL_INFOS("RenderInit") << "Couldn't initialize mipmap generation" << LL_ENDL;
  902. }
  903. if (!mHasARBEnvCombine)
  904. {
  905. LL_INFOS("RenderInit") << "Couldn't initialize GL_ARB_texture_env_combine" << LL_ENDL;
  906. }
  907. if (!mHasSeparateSpecularColor)
  908. {
  909. LL_INFOS("RenderInit") << "Couldn't initialize separate specular color" << LL_ENDL;
  910. }
  911. if (!mHasAnisotropic)
  912. {
  913. LL_INFOS("RenderInit") << "Couldn't initialize anisotropic filtering" << LL_ENDL;
  914. }
  915. if (!mHasCompressedTextures)
  916. {
  917. LL_INFOS("RenderInit") << "Couldn't initialize GL_ARB_texture_compression" << LL_ENDL;
  918. }
  919. if (!mHasOcclusionQuery)
  920. {
  921. LL_INFOS("RenderInit") << "Couldn't initialize GL_ARB_occlusion_query" << LL_ENDL;
  922. }
  923. if (!mHasOcclusionQuery2)
  924. {
  925. LL_INFOS("RenderInit") << "Couldn't initialize GL_ARB_occlusion_query2" << LL_ENDL;
  926. }
  927. if (!mHasPointParameters)
  928. {
  929. LL_INFOS("RenderInit") << "Couldn't initialize GL_ARB_point_parameters" << LL_ENDL;
  930. }
  931. if (!mHasShaderObjects)
  932. {
  933. LL_INFOS("RenderInit") << "Couldn't initialize GL_ARB_shader_objects" << LL_ENDL;
  934. }
  935. if (!mHasVertexShader)
  936. {
  937. LL_INFOS("RenderInit") << "Couldn't initialize GL_ARB_vertex_shader" << LL_ENDL;
  938. }
  939. if (!mHasFragmentShader)
  940. {
  941. LL_INFOS("RenderInit") << "Couldn't initialize GL_ARB_fragment_shader" << LL_ENDL;
  942. }
  943. if (!mHasBlendFuncSeparate)
  944. {
  945. LL_INFOS("RenderInit") << "Couldn't initialize GL_EXT_blend_func_separate" << LL_ENDL;
  946. }
  947. if (!mHasDrawBuffers)
  948. {
  949. LL_INFOS("RenderInit") << "Couldn't initialize GL_ARB_draw_buffers" << LL_ENDL;
  950. }
  951. // Disable certain things due to known bugs
  952. if (mIsIntel && mHasMipMapGeneration)
  953. {
  954. LL_INFOS("RenderInit") << "Disabling mip-map generation for Intel GPUs" << LL_ENDL;
  955. mHasMipMapGeneration = FALSE;
  956. }
  957. #if !LL_DARWIN
  958. if (mIsATI && mHasMipMapGeneration)
  959. {
  960. LL_INFOS("RenderInit") << "Disabling mip-map generation for ATI GPUs (performance opt)" << LL_ENDL;
  961. mHasMipMapGeneration = FALSE;
  962. }
  963. #endif
  964. // Misc
  965. glGetIntegerv(GL_MAX_ELEMENTS_VERTICES, (GLint*) &mGLMaxVertexRange);
  966. glGetIntegerv(GL_MAX_ELEMENTS_INDICES, (GLint*) &mGLMaxIndexRange);
  967. #if (LL_WINDOWS || LL_LINUX || LL_SOLARIS) && !LL_MESA_HEADLESS
  968. LL_DEBUGS("RenderInit") << "GL Probe: Getting symbols" << LL_ENDL;
  969. if (mHasVertexBufferObject)
  970. {
  971. glBindBufferARB = (PFNGLBINDBUFFERARBPROC)GLH_EXT_GET_PROC_ADDRESS("glBindBufferARB");
  972. if (glBindBufferARB)
  973. {
  974. glDeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC)GLH_EXT_GET_PROC_ADDRESS("glDeleteBuffersARB");
  975. glGenBuffersARB = (PFNGLGENBUFFERSARBPROC)GLH_EXT_GET_PROC_ADDRESS("glGenBuffersARB");
  976. glIsBufferARB = (PFNGLISBUFFERARBPROC)GLH_EXT_GET_PROC_ADDRESS("glIsBufferARB");
  977. glBufferDataARB = (PFNGLBUFFERDATAARBPROC)GLH_EXT_GET_PROC_ADDRESS("glBufferDataARB");
  978. glBufferSubDataARB = (PFNGLBUFFERSUBDATAARBPROC)GLH_EXT_GET_PROC_ADDRESS("glBufferSubDataARB");
  979. glGetBufferSubDataARB = (PFNGLGETBUFFERSUBDATAARBPROC)GLH_EXT_GET_PROC_ADDRESS("glGetBufferSubDataARB");
  980. glMapBufferARB = (PFNGLMAPBUFFERARBPROC)GLH_EXT_GET_PROC_ADDRESS("glMapBufferARB");
  981. glUnmapBufferARB = (PFNGLUNMAPBUFFERARBPROC)GLH_EXT_GET_PROC_ADDRESS("glUnmapBufferARB");
  982. glGetBufferParameterivARB = (PFNGLGETBUFFERPARAMETERIVARBPROC)GLH_EXT_GET_PROC_ADDRESS("glGetBufferParameterivARB");
  983. glGetBufferPointervARB = (PFNGLGETBUFFERPOINTERVARBPROC)GLH_EXT_GET_PROC_ADDRESS("glGetBufferPointervARB");
  984. }
  985. else
  986. {
  987. mHasVertexBufferObject = FALSE;
  988. }
  989. }
  990. if (mHasVertexArrayObject)
  991. {
  992. glBindVertexArray = (PFNGLBINDVERTEXARRAYPROC) GLH_EXT_GET_PROC_ADDRESS("glBindVertexArray");
  993. glDeleteVertexArrays = (PFNGLDELETEVERTEXARRAYSPROC) GLH_EXT_GET_PROC_ADDRESS("glDeleteVertexArrays");
  994. glGenVertexArrays = (PFNGLGENVERTEXARRAYSPROC) GLH_EXT_GET_PROC_ADDRESS("glGenVertexArrays");
  995. glIsVertexArray = (PFNGLISVERTEXARRAYPROC) GLH_EXT_GET_PROC_ADDRESS("glIsVertexArray");
  996. }
  997. if (mHasSync)
  998. {
  999. glFenceSync = (PFNGLFENCESYNCPROC) GLH_EXT_GET_PROC_ADDRESS("glFenceSync");
  1000. glIsSync = (PFNGLISSYNCPROC) GLH_EXT_GET_PROC_ADDRESS("glIsSync");
  1001. glDeleteSync = (PFNGLDELETESYNCPROC) GLH_EXT_GET_PROC_ADDRESS("glDeleteSync");
  1002. glClientWaitSync = (PFNGLCLIENTWAITSYNCPROC) GLH_EXT_GET_PROC_ADDRESS("glClientWaitSync");
  1003. glWaitSync = (PFNGLWAITSYNCPROC) GLH_EXT_GET_PROC_ADDRESS("glWaitSync");
  1004. glGetInteger64v = (PFNGLGETINTEGER64VPROC) GLH_EXT_GET_PROC_ADDRESS("glGetInteger64v");
  1005. glGetSynciv = (PFNGLGETSYNCIVPROC) GLH_EXT_GET_PROC_ADDRESS("glGetSynciv");
  1006. }
  1007. if (mHasMapBufferRange)
  1008. {
  1009. glMapBufferRange = (PFNGLMAPBUFFERRANGEPROC) GLH_EXT_GET_PROC_ADDRESS("glMapBufferRange");
  1010. glFlushMappedBufferRange = (PFNGLFLUSHMAPPEDBUFFERRANGEPROC) GLH_EXT_GET_PROC_ADDRESS("glFlushMappedBufferRange");
  1011. }
  1012. if (mHasFramebufferObject)
  1013. {
  1014. llinfos << "initExtensions() FramebufferObject-related procs..." << llendl;
  1015. glIsRenderbuffer = (PFNGLISRENDERBUFFERPROC) GLH_EXT_GET_PROC_ADDRESS("glIsRenderbuffer");
  1016. glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC) GLH_EXT_GET_PROC_ADDRESS("glBindRenderbuffer");
  1017. glDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC) GLH_EXT_GET_PROC_ADDRESS("glDeleteRenderbuffers");
  1018. glGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC) GLH_EXT_GET_PROC_ADDRESS("glGenRenderbuffers");
  1019. glRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC) GLH_EXT_GET_PROC_ADDRESS("glRenderbufferStorage");
  1020. glGetRenderbufferParameteriv = (PFNGLGETRENDERBUFFERPARAMETERIVPROC) GLH_EXT_GET_PROC_ADDRESS("glGetRenderbufferParameteriv");
  1021. glIsFramebuffer = (PFNGLISFRAMEBUFFERPROC) GLH_EXT_GET_PROC_ADDRESS("glIsFramebuffer");
  1022. glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC) GLH_EXT_GET_PROC_ADDRESS("glBindFramebuffer");
  1023. glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC) GLH_EXT_GET_PROC_ADDRESS("glDeleteFramebuffers");
  1024. glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC) GLH_EXT_GET_PROC_ADDRESS("glGenFramebuffers");
  1025. glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC) GLH_EXT_GET_PROC_ADDRESS("glCheckFramebufferStatus");
  1026. glFramebufferTexture1D = (PFNGLFRAMEBUFFERTEXTURE1DPROC) GLH_EXT_GET_PROC_ADDRESS("glFramebufferTexture1D");
  1027. glFramebufferTexture2D = (PFNGLFRAMEBUFFERTEXTURE2DPROC) GLH_EXT_GET_PROC_ADDRESS("glFramebufferTexture2D");
  1028. glFramebufferTexture3D = (PFNGLFRAMEBUFFERTEXTURE3DPROC) GLH_EXT_GET_PROC_ADDRESS("glFramebufferTexture3D");
  1029. glFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC) GLH_EXT_GET_PROC_ADDRESS("glFramebufferRenderbuffer");
  1030. glGetFramebufferAttachmentParameteriv = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC) GLH_EXT_GET_PROC_ADDRESS("glGetFramebufferAttachmentParameteriv");
  1031. glGenerateMipmap = (PFNGLGENERATEMIPMAPPROC) GLH_EXT_GET_PROC_ADDRESS("glGenerateMipmap");
  1032. glBlitFramebuffer = (PFNGLBLITFRAMEBUFFERPROC) GLH_EXT_GET_PROC_ADDRESS("glBlitFramebuffer");
  1033. glRenderbufferStorageMultisample = (PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC) GLH_EXT_GET_PROC_ADDRESS("glRenderbufferStorageMultisample");
  1034. glFramebufferTextureLayer = (PFNGLFRAMEBUFFERTEXTURELAYERPROC) GLH_EXT_GET_PROC_ADDRESS("glFramebufferTextureLayer");
  1035. }
  1036. if (mHasDrawBuffers)
  1037. {
  1038. glDrawBuffersARB = (PFNGLDRAWBUFFERSARBPROC) GLH_EXT_GET_PROC_ADDRESS("glDrawBuffersARB");
  1039. }
  1040. if (mHasBlendFuncSeparate)
  1041. {
  1042. glBlendFuncSeparateEXT = (PFNGLBLENDFUNCSEPARATEEXTPROC) GLH_EXT_GET_PROC_ADDRESS("glBlendFuncSeparateEXT");
  1043. }
  1044. if (mHasTextureMultisample)
  1045. {
  1046. glTexImage2DMultisample = (PFNGLTEXIMAGE2DMULTISAMPLEPROC) GLH_EXT_GET_PROC_ADDRESS("glTexImage2DMultisample");
  1047. glTexImage3DMultisample = (PFNGLTEXIMAGE3DMULTISAMPLEPROC) GLH_EXT_GET_PROC_ADDRESS("glTexImage3DMultisample");
  1048. glGetMultisamplefv = (PFNGLGETMULTISAMPLEFVPROC) GLH_EXT_GET_PROC_ADDRESS("glGetMultisamplefv");
  1049. glSampleMaski = (PFNGLSAMPLEMASKIPROC) GLH_EXT_GET_PROC_ADDRESS("glSampleMaski");
  1050. }
  1051. if (mHasDebugOutput)
  1052. {
  1053. glDebugMessageControlARB = (PFNGLDEBUGMESSAGECONTROLARBPROC) GLH_EXT_GET_PROC_ADDRESS("glDebugMessageControlARB");
  1054. glDebugMessageInsertARB = (PFNGLDEBUGMESSAGEINSERTARBPROC) GLH_EXT_GET_PROC_ADDRESS("glDebugMessageInsertARB");
  1055. glDebugMessageCallbackARB = (PFNGLDEBUGMESSAGECALLBACKARBPROC) GLH_EXT_GET_PROC_ADDRESS("glDebugMessageCallbackARB");
  1056. glGetDebugMessageLogARB = (PFNGLGETDEBUGMESSAGELOGARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetDebugMessageLogARB");
  1057. }
  1058. #if (!LL_LINUX && !LL_SOLARIS) || LL_LINUX_NV_GL_HEADERS
  1059. // This is expected to be a static symbol on Linux GL implementations, except if we use the nvidia headers - bah
  1060. glDrawRangeElements = (PFNGLDRAWRANGEELEMENTSPROC)GLH_EXT_GET_PROC_ADDRESS("glDrawRangeElements");
  1061. if (!glDrawRangeElements)
  1062. {
  1063. mGLMaxVertexRange = 0;
  1064. mGLMaxIndexRange = 0;
  1065. }
  1066. #endif // !LL_LINUX || LL_LINUX_NV_GL_HEADERS
  1067. #if LL_LINUX_NV_GL_HEADERS
  1068. // nvidia headers are critically different from mesa-esque
  1069. glActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC)GLH_EXT_GET_PROC_ADDRESS("glActiveTextureARB");
  1070. glClientActiveTextureARB = (PFNGLCLIENTACTIVETEXTUREARBPROC)GLH_EXT_GET_PROC_ADDRESS("glClientActiveTextureARB");
  1071. #endif // LL_LINUX_NV_GL_HEADERS
  1072. if (mHasOcclusionQuery)
  1073. {
  1074. llinfos << "initExtensions() OcclusionQuery-related procs..." << llendl;
  1075. glGenQueriesARB = (PFNGLGENQUERIESARBPROC)GLH_EXT_GET_PROC_ADDRESS("glGenQueriesARB");
  1076. glDeleteQueriesARB = (PFNGLDELETEQUERIESARBPROC)GLH_EXT_GET_PROC_ADDRESS("glDeleteQueriesARB");
  1077. glIsQueryARB = (PFNGLISQUERYARBPROC)GLH_EXT_GET_PROC_ADDRESS("glIsQueryARB");
  1078. glBeginQueryARB = (PFNGLBEGINQUERYARBPROC)GLH_EXT_GET_PROC_ADDRESS("glBeginQueryARB");
  1079. glEndQueryARB = (PFNGLENDQUERYARBPROC)GLH_EXT_GET_PROC_ADDRESS("glEndQueryARB");
  1080. glGetQueryivARB = (PFNGLGETQUERYIVARBPROC)GLH_EXT_GET_PROC_ADDRESS("glGetQueryivARB");
  1081. glGetQueryObjectivARB = (PFNGLGETQUERYOBJECTIVARBPROC)GLH_EXT_GET_PROC_ADDRESS("glGetQueryObjectivARB");
  1082. glGetQueryObjectuivARB = (PFNGLGETQUERYOBJECTUIVARBPROC)GLH_EXT_GET_PROC_ADDRESS("glGetQueryObjectuivARB");
  1083. }
  1084. if (mHasPointParameters)
  1085. {
  1086. llinfos << "initExtensions() PointParameters-related procs..." << llendl;
  1087. glPointParameterfARB = (PFNGLPOINTPARAMETERFARBPROC)GLH_EXT_GET_PROC_ADDRESS("glPointParameterfARB");
  1088. glPointParameterfvARB = (PFNGLPOINTPARAMETERFVARBPROC)GLH_EXT_GET_PROC_ADDRESS("glPointParameterfvARB");
  1089. }
  1090. if (mHasShaderObjects)
  1091. {
  1092. glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC) GLH_EXT_GET_PROC_ADDRESS("glDeleteObjectARB");
  1093. glGetHandleARB = (PFNGLGETHANDLEARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetHandleARB");
  1094. glDetachObjectARB = (PFNGLDETACHOBJECTARBPROC) GLH_EXT_GET_PROC_ADDRESS("glDetachObjectARB");
  1095. glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC) GLH_EXT_GET_PROC_ADDRESS("glCreateShaderObjectARB");
  1096. glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC) GLH_EXT_GET_PROC_ADDRESS("glShaderSourceARB");
  1097. glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC) GLH_EXT_GET_PROC_ADDRESS("glCompileShaderARB");
  1098. glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC) GLH_EXT_GET_PROC_ADDRESS("glCreateProgramObjectARB");
  1099. glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC) GLH_EXT_GET_PROC_ADDRESS("glAttachObjectARB");
  1100. glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC) GLH_EXT_GET_PROC_ADDRESS("glLinkProgramARB");
  1101. glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUseProgramObjectARB");
  1102. glValidateProgramARB = (PFNGLVALIDATEPROGRAMARBPROC) GLH_EXT_GET_PROC_ADDRESS("glValidateProgramARB");
  1103. glUniform1fARB = (PFNGLUNIFORM1FARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform1fARB");
  1104. glUniform2fARB = (PFNGLUNIFORM2FARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform2fARB");
  1105. glUniform3fARB = (PFNGLUNIFORM3FARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform3fARB");
  1106. glUniform4fARB = (PFNGLUNIFORM4FARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform4fARB");
  1107. glUniform1iARB = (PFNGLUNIFORM1IARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform1iARB");
  1108. glUniform2iARB = (PFNGLUNIFORM2IARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform2iARB");
  1109. glUniform3iARB = (PFNGLUNIFORM3IARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform3iARB");
  1110. glUniform4iARB = (PFNGLUNIFORM4IARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform4iARB");
  1111. glUniform1fvARB = (PFNGLUNIFORM1FVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform1fvARB");
  1112. glUniform2fvARB = (PFNGLUNIFORM2FVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform2fvARB");
  1113. glUniform3fvARB = (PFNGLUNIFORM3FVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform3fvARB");
  1114. glUniform4fvARB = (PFNGLUNIFORM4FVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform4fvARB");
  1115. glUniform1ivARB = (PFNGLUNIFORM1IVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform1ivARB");
  1116. glUniform2ivARB = (PFNGLUNIFORM2IVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform2ivARB");
  1117. glUniform3ivARB = (PFNGLUNIFORM3IVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform3ivARB");
  1118. glUniform4ivARB = (PFNGLUNIFORM4IVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform4ivARB");
  1119. glUniformMatrix2fvARB = (PFNGLUNIFORMMATRIX2FVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniformMatrix2fvARB");
  1120. glUniformMatrix3fvARB = (PFNGLUNIFORMMATRIX3FVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniformMatrix3fvARB");
  1121. glUniformMatrix4fvARB = (PFNGLUNIFORMMATRIX4FVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniformMatrix4fvARB");
  1122. glGetObjectParameterfvARB = (PFNGLGETOBJECTPARAMETERFVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetObjectParameterfvARB");
  1123. glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetObjectParameterivARB");
  1124. glGetInfoLogARB = (PFNGLGETINFOLOGARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetInfoLogARB");
  1125. glGetAttachedObjectsARB = (PFNGLGETATTACHEDOBJECTSARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetAttachedObjectsARB");
  1126. glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetUniformLocationARB");
  1127. glGetActiveUniformARB = (PFNGLGETACTIVEUNIFORMARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetActiveUniformARB");
  1128. glGetUniformfvARB = (PFNGLGETUNIFORMFVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetUniformfvARB");
  1129. glGetUniformivARB = (PFNGLGETUNIFORMIVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetUniformivARB");
  1130. glGetShaderSourceARB = (PFNGLGETSHADERSOURCEARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetShaderSourceARB");
  1131. }
  1132. if (mHasVertexShader)
  1133. {
  1134. llinfos << "initExtensions() VertexShader-related procs..." << llendl;
  1135. glGetAttribLocationARB = (PFNGLGETATTRIBLOCATIONARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetAttribLocationARB");
  1136. glBindAttribLocationARB = (PFNGLBINDATTRIBLOCATIONARBPROC) GLH_EXT_GET_PROC_ADDRESS("glBindAttribLocationARB");
  1137. glGetActiveAttribARB = (PFNGLGETACTIVEATTRIBARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetActiveAttribARB");
  1138. glVertexAttrib1dARB = (PFNGLVERTEXATTRIB1DARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib1dARB");
  1139. glVertexAttrib1dvARB = (PFNGLVERTEXATTRIB1DVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib1dvARB");
  1140. glVertexAttrib1fARB = (PFNGLVERTEXATTRIB1FARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib1fARB");
  1141. glVertexAttrib1fvARB = (PFNGLVERTEXATTRIB1FVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib1fvARB");
  1142. glVertexAttrib1sARB = (PFNGLVERTEXATTRIB1SARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib1sARB");
  1143. glVertexAttrib1svARB = (PFNGLVERTEXATTRIB1SVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib1svARB");
  1144. glVertexAttrib2dARB = (PFNGLVERTEXATTRIB2DARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib2dARB");
  1145. glVertexAttrib2dvARB = (PFNGLVERTEXATTRIB2DVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib2dvARB");
  1146. glVertexAttrib2fARB = (PFNGLVERTEXATTRIB2FARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib2fARB");
  1147. glVertexAttrib2fvARB = (PFNGLVERTEXATTRIB2FVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib2fvARB");
  1148. glVertexAttrib2sARB = (PFNGLVERTEXATTRIB2SARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib2sARB");
  1149. glVertexAttrib2svARB = (PFNGLVERTEXATTRIB2SVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib2svARB");
  1150. glVertexAttrib3dARB = (PFNGLVERTEXATTRIB3DARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib3dARB");
  1151. glVertexAttrib3dvARB = (PFNGLVERTEXATTRIB3DVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib3dvARB");
  1152. glVertexAttrib3fARB = (PFNGLVERTEXATTRIB3FARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib3fARB");
  1153. glVertexAttrib3fvARB = (PFNGLVERTEXATTRIB3FVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib3fvARB");
  1154. glVertexAttrib3sARB = (PFNGLVERTEXATTRIB3SARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib3sARB");
  1155. glVertexAttrib3svARB = (PFNGLVERTEXATTRIB3SVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib3svARB");
  1156. glVertexAttrib4nbvARB = (PFNGLVERTEXATTRIB4NBVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4nbvARB");
  1157. glVertexAttrib4nivARB = (PFNGLVERTEXATTRIB4NIVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4nivARB");
  1158. glVertexAttrib4nsvARB = (PFNGLVERTEXATTRIB4NSVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4nsvARB");
  1159. glVertexAttrib4nubARB = (PFNGLVERTEXATTRIB4NUBARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4nubARB");
  1160. glVertexAttrib4nubvARB = (PFNGLVERTEXATTRIB4NUBVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4nubvARB");
  1161. glVertexAttrib4nuivARB = (PFNGLVERTEXATTRIB4NUIVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4nuivARB");
  1162. glVertexAttrib4nusvARB = (PFNGLVERTEXATTRIB4NUSVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4nusvARB");
  1163. glVertexAttrib4bvARB = (PFNGLVERTEXATTRIB4BVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4bvARB");
  1164. glVertexAttrib4dARB = (PFNGLVERTEXATTRIB4DARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4dARB");
  1165. glVertexAttrib4dvARB = (PFNGLVERTEXATTRIB4DVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4dvARB");
  1166. glVertexAttrib4fARB = (PFNGLVERTEXATTRIB4FARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4fARB");
  1167. glVertexAttrib4fvARB = (PFNGLVERTEXATTRIB4FVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4fvARB");
  1168. glVertexAttrib4ivARB = (PFNGLVERTEXATTRIB4IVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4ivARB");
  1169. glVertexAttrib4sARB = (PFNGLVERTEXATTRIB4SARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4sARB");
  1170. glVertexAttrib4svARB = (PFNGLVERTEXATTRIB4SVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4svARB");
  1171. glVertexAttrib4ubvARB = (PFNGLVERTEXATTRIB4UBVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4ubvARB");
  1172. glVertexAttrib4uivARB = (PFNGLVERTEXATTRIB4UIVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4uivARB");
  1173. glVertexAttrib4usvARB = (PFNGLVERTEXATTRIB4USVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4usvARB");
  1174. glVertexAttribPointerARB = (PFNGLVERTEXATTRIBPOINTERARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttribPointerARB");
  1175. glEnableVertexAttribArrayARB = (PFNGLENABLEVERTEXATTRIBARRAYARBPROC) GLH_EXT_GET_PROC_ADDRESS("glEnableVertexAttribArrayARB");
  1176. glDisableVertexAttribArrayARB = (PFNGLDISABLEVERTEXATTRIBARRAYARBPROC) GLH_EXT_GET_PROC_ADDRESS("glDisableVertexAttribArrayARB");
  1177. glProgramStringARB = (PFNGLPROGRAMSTRINGARBPROC) GLH_EXT_GET_PROC_ADDRESS("glProgramStringARB");
  1178. glBindProgramARB = (PFNGLBINDPROGRAMARBPROC) GLH_EXT_GET_PROC_ADDRESS("glBindProgramARB");
  1179. glDeleteProgramsARB = (PFNGLDELETEPROGRAMSARBPROC) GLH_EXT_GET_PROC_ADDRESS("glDeleteProgramsARB");
  1180. glGenProgramsARB = (PFNGLGENPROGRAMSARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGenProgramsARB");
  1181. glProgramEnvParameter4dARB = (PFNGLPROGRAMENVPARAMETER4DARBPROC) GLH_EXT_GET_PROC_ADDRESS("glProgramEnvParameter4dARB");
  1182. glProgramEnvParameter4dvARB = (PFNGLPROGRAMENVPARAMETER4DVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glProgramEnvParameter4dvARB");
  1183. glProgramEnvParameter4fARB = (PFNGLPROGRAMENVPARAMETER4FARBPROC) GLH_EXT_GET_PROC_ADDRESS("glProgramEnvParameter4fARB");
  1184. glProgramEnvParameter4fvARB = (PFNGLPROGRAMENVPARAMETER4FVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glProgramEnvParameter4fvARB");
  1185. glProgramLocalParameter4dARB = (PFNGLPROGRAMLOCALPARAMETER4DARBPROC) GLH_EXT_GET_PROC_ADDRESS("glProgramLocalParameter4dARB");
  1186. glProgramLocalParameter4dvARB = (PFNGLPROGRAMLOCALPARAMETER4DVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glProgramLocalParameter4dvARB");
  1187. glProgramLocalParameter4fARB = (PFNGLPROGRAMLOCALPARAMETER4FARBPROC) GLH_EXT_GET_PROC_ADDRESS("glProgramLocalParameter4fARB");
  1188. glProgramLocalParameter4fvARB = (PFNGLPROGRAMLOCALPARAMETER4FVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glProgramLocalParameter4fvARB");
  1189. glGetProgramEnvParameterdvARB = (PFNGLGETPROGRAMENVPARAMETERDVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetProgramEnvParameterdvARB");
  1190. glGetProgramEnvParameterfvARB = (PFNGLGETPROGRAMENVPARAMETERFVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetProgramEnvParameterfvARB");
  1191. glGetProgramLocalParameterdvARB = (PFNGLGETPROGRAMLOCALPARAMETERDVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetProgramLocalParameterdvARB");
  1192. glGetProgramLocalParameterfvARB = (PFNGLGETPROGRAMLOCALPARAMETERFVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetProgramLocalParameterfvARB");
  1193. glGetProgramivARB = (PFNGLGETPROGRAMIVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetProgramivARB");
  1194. glGetProgramStringARB = (PFNGLGETPROGRAMSTRINGARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetProgramStringARB");
  1195. glGetVertexAttribdvARB = (PFNGLGETVERTEXATTRIBDVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetVertexAttribdvARB");
  1196. glGetVertexAttribfvARB = (PFNGLGETVERTEXATTRIBFVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetVertexAttribfvARB");
  1197. glGetVertexAttribivARB = (PFNGLGETVERTEXATTRIBIVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetVertexAttribivARB");
  1198. glGetVertexAttribPointervARB = (PFNGLGETVERTEXATTRIBPOINTERVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glgetVertexAttribPointervARB");
  1199. glIsProgramARB = (PFNGLISPROGRAMARBPROC) GLH_EXT_GET_PROC_ADDRESS("glIsProgramARB");
  1200. }
  1201. LL_DEBUGS("RenderInit") << "GL Probe: Got symbols" << LL_ENDL;
  1202. #endif
  1203. mInited = TRUE;
  1204. }
  1205. void rotate_quat(LLQuaternion& rotation)
  1206. {
  1207. F32 angle_radians, x, y, z;
  1208. rotation.getAngleAxis(&angle_radians, &x, &y, &z);
  1209. gGL.rotatef(angle_radians * RAD_TO_DEG, x, y, z);
  1210. }
  1211. void flush_glerror()
  1212. {
  1213. glGetError();
  1214. }
  1215. //this function outputs gl error to the log file, does not crash the code.
  1216. void log_glerror()
  1217. {
  1218. if (LL_UNLIKELY(!gGLManager.mInited))
  1219. {
  1220. return ;
  1221. }
  1222. // Create or update texture to be used with this data
  1223. GLenum error;
  1224. error = glGetError();
  1225. while (LL_UNLIKELY(error))
  1226. {
  1227. GLubyte const * gl_error_msg = gluErrorString(error);
  1228. if (NULL != gl_error_msg)
  1229. {
  1230. llwarns << "GL Error: " << error << " GL Error String: " << gl_error_msg << llendl ;
  1231. }
  1232. else
  1233. {
  1234. // gluErrorString returns NULL for some extensions' error codes.
  1235. // you'll probably have to grep for the number in glext.h.
  1236. llwarns << "GL Error: UNKNOWN 0x" << std::hex << error << std::dec << llendl;
  1237. }
  1238. error = glGetError();
  1239. }
  1240. }
  1241. void do_assert_glerror()
  1242. {
  1243. // Create or update texture to be used with this data
  1244. GLenum error;
  1245. error = glGetError();
  1246. BOOL quit = FALSE;
  1247. while (LL_UNLIKELY(error))
  1248. {
  1249. quit = TRUE;
  1250. GLubyte const * gl_error_msg = gluErrorString(error);
  1251. if (NULL != gl_error_msg)
  1252. {
  1253. LL_WARNS("RenderState") << "GL Error:" << error<< LL_ENDL;
  1254. LL_WARNS("RenderState") << "GL Error String:" << gl_error_msg << LL_ENDL;
  1255. if (gDebugSession)
  1256. {
  1257. gFailLog << "GL Error:" << gl_error_msg << std::endl;
  1258. }
  1259. }
  1260. else
  1261. {
  1262. // gluErrorString returns NULL for some extensions' error codes.
  1263. // you'll probably have to grep for the number in glext.h.
  1264. LL_WARNS("RenderState") << "GL Error: UNKNOWN 0x" << std::hex << error << std::dec << LL_ENDL;
  1265. if (gDebugSession)
  1266. {
  1267. gFailLog << "GL Error: UNKNOWN 0x" << std::hex << error << std::dec << std::endl;
  1268. }
  1269. }
  1270. error = glGetError();
  1271. }
  1272. if (quit)
  1273. {
  1274. if (gDebugSession)
  1275. {
  1276. ll_fail("assert_glerror failed");
  1277. }
  1278. else
  1279. {
  1280. llerrs << "One or more unhandled GL errors." << llendl;
  1281. }
  1282. }
  1283. }
  1284. void assert_glerror()
  1285. {
  1286. if (!gGLActive)
  1287. {
  1288. //llwarns << "GL used while not active!" << llendl;
  1289. if (gDebugSession)
  1290. {
  1291. //ll_fail("GL used while not active");
  1292. }
  1293. }
  1294. if (gDebugGL)
  1295. {
  1296. do_assert_glerror();
  1297. }
  1298. }
  1299. void clear_glerror()
  1300. {
  1301. // Create or update texture to be used with this data
  1302. GLenum error;
  1303. error = glGetError();
  1304. }
  1305. ///////////////////////////////////////////////////////////////
  1306. //
  1307. // LLGLState
  1308. //
  1309. // Static members
  1310. boost::unordered_map<LLGLenum, LLGLboolean> LLGLState::sStateMap;
  1311. GLboolean LLGLDepthTest::sDepthEnabled = GL_FALSE; // OpenGL default
  1312. GLenum LLGLDepthTest::sDepthFunc = GL_LESS; // OpenGL default
  1313. GLboolean LLGLDepthTest::sWriteEnabled = GL_TRUE; // OpenGL default
  1314. //static
  1315. void LLGLState::initClass()
  1316. {
  1317. sStateMap[GL_DITHER] = GL_TRUE;
  1318. // sStateMap[GL_TEXTURE_2D] = GL_TRUE;
  1319. //make sure multisample defaults to disabled
  1320. sStateMap[GL_MULTISAMPLE_ARB] = GL_FALSE;
  1321. glDisable(GL_MULTISAMPLE_ARB);
  1322. }
  1323. //static
  1324. void LLGLState::restoreGL()
  1325. {
  1326. sStateMap.clear();
  1327. initClass();
  1328. }
  1329. //static
  1330. // Really shouldn't be needed, but seems we sometimes do.
  1331. void LLGLState::resetTextureStates()
  1332. {
  1333. gGL.flush();
  1334. GLint maxTextureUnits;
  1335. glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &maxTextureUnits);
  1336. for (S32 j = maxTextureUnits-1; j >=0; j--)
  1337. {
  1338. gGL.getTexUnit(j)->activate();
  1339. glClientActiveTextureARB(GL_TEXTURE0_ARB+j);
  1340. j == 0 ? gGL.getTexUnit(j)->enable(LLTexUnit::TT_TEXTURE) : gGL.getTexUnit(j)->disable();
  1341. }
  1342. }
  1343. void LLGLState::dumpStates()
  1344. {
  1345. LL_INFOS("RenderState") << "GL States:" << LL_ENDL;
  1346. for (boost::unordered_map<LLGLenum, LLGLboolean>::iterator iter = sStateMap.begin();
  1347. iter != sStateMap.end(); ++iter)
  1348. {
  1349. LL_INFOS("RenderState") << llformat(" 0x%04x : %s",(S32)iter->first,iter->second?"TRUE":"FALSE") << LL_ENDL;
  1350. }
  1351. }
  1352. void LLGLState::checkStates(const std::string& msg)
  1353. {
  1354. if (!gDebugGL)
  1355. {
  1356. return;
  1357. }
  1358. stop_glerror();
  1359. GLint src;
  1360. GLint dst;
  1361. glGetIntegerv(GL_BLEND_SRC, &src);
  1362. glGetIntegerv(GL_BLEND_DST, &dst);
  1363. stop_glerror();
  1364. BOOL error = FALSE;
  1365. if (src != GL_SRC_ALPHA || dst != GL_ONE_MINUS_SRC_ALPHA)
  1366. {
  1367. if (gDebugSession)
  1368. {
  1369. gFailLog << "Blend function corrupted: " << std::hex << src << " " << std::hex << dst << " " << msg << std::dec << std::endl;
  1370. error = TRUE;
  1371. }
  1372. else
  1373. {
  1374. LL_GL_ERRS << "Blend function corrupted: " << std::hex << src << " " << std::hex << dst << " " << msg << std::dec << LL_ENDL;
  1375. }
  1376. }
  1377. for (boost::unordered_map<LLGLenum, LLGLboolean>::iterator iter = sStateMap.begin();
  1378. iter != sStateMap.end(); ++iter)
  1379. {
  1380. LLGLenum state = iter->first;
  1381. LLGLboolean cur_state = iter->second;
  1382. stop_glerror();
  1383. LLGLboolean gl_state = glIsEnabled(state);
  1384. stop_glerror();
  1385. if(cur_state != gl_state)
  1386. {
  1387. dumpStates();
  1388. if (gDebugSession)
  1389. {
  1390. gFailLog << llformat("LLGLState error. State: 0x%04x",state) << std::endl;
  1391. error = TRUE;
  1392. }
  1393. else
  1394. {
  1395. LL_GL_ERRS << llformat("LLGLState error. State: 0x%04x",state) << LL_ENDL;
  1396. }
  1397. }
  1398. }
  1399. if (error)
  1400. {
  1401. ll_fail("LLGLState::checkStates failed.");
  1402. }
  1403. stop_glerror();
  1404. }
  1405. void LLGLState::checkTextureChannels(const std::string& msg)
  1406. {
  1407. #if 0
  1408. if (!gDebugGL)
  1409. {
  1410. return;
  1411. }
  1412. stop_glerror();
  1413. GLint activeTexture;
  1414. glGetIntegerv(GL_ACTIVE_TEXTURE_ARB, &activeTexture);
  1415. stop_glerror();
  1416. BOOL error = FALSE;
  1417. if (activeTexture == GL_TEXTURE0_ARB)
  1418. {
  1419. GLint tex_env_mode = 0;
  1420. glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &tex_env_mode);
  1421. stop_glerror();
  1422. if (tex_env_mode != GL_MODULATE)
  1423. {
  1424. error = TRUE;
  1425. LL_WARNS("RenderState") << "GL_TEXTURE_ENV_MODE invalid: " << std::hex << tex_env_mode << std::dec << LL_ENDL;
  1426. if (gDebugSession)
  1427. {
  1428. gFailLog << "GL_TEXTURE_ENV_MODE invalid: " << std::hex << tex_env_mode << std::dec << std::endl;
  1429. }
  1430. }
  1431. }
  1432. static const char* label[] =
  1433. {
  1434. "GL_TEXTURE_2D",
  1435. "GL_TEXTURE_COORD_ARRAY",
  1436. "GL_TEXTURE_1D",
  1437. "GL_TEXTURE_CUBE_MAP_ARB",
  1438. "GL_TEXTURE_GEN_S",
  1439. "GL_TEXTURE_GEN_T",
  1440. "GL_TEXTURE_GEN_Q",
  1441. "GL_TEXTURE_GEN_R",
  1442. "GL_TEXTURE_RECTANGLE_ARB",
  1443. "GL_TEXTURE_2D_MULTISAMPLE"
  1444. };
  1445. static GLint value[] =
  1446. {
  1447. GL_TEXTURE_2D,
  1448. GL_TEXTURE_COORD_ARRAY,
  1449. GL_TEXTURE_1D,
  1450. GL_TEXTURE_CUBE_MAP_ARB,
  1451. GL_TEXTURE_GEN_S,
  1452. GL_TEXTURE_GEN_T,
  1453. GL_TEXTURE_GEN_Q,
  1454. GL_TEXTURE_GEN_R,
  1455. GL_TEXTURE_RECTANGLE_ARB,
  1456. GL_TEXTURE_2D_MULTISAMPLE
  1457. };
  1458. GLint stackDepth = 0;
  1459. glh::matrix4f mat;
  1460. glh::matrix4f identity;
  1461. identity.identity();
  1462. for (GLint i = 1; i < gGLManager.mNumTextureUnits; i++)
  1463. {
  1464. gGL.getTexUnit(i)->activate();
  1465. if (i < gGLManager.mNumTextureUnits)
  1466. {
  1467. glClientActiveTextureARB(GL_TEXTURE0_ARB+i);
  1468. stop_glerror();
  1469. glGetIntegerv(GL_TEXTURE_STACK_DEPTH, &stackDepth);
  1470. stop_glerror();
  1471. if (stackDepth != 1)
  1472. {
  1473. error = TRUE;
  1474. LL_WARNS("RenderState") << "Texture matrix stack corrupted." << LL_ENDL;
  1475. if (gDebugSession)
  1476. {
  1477. gFailLog << "Texture matrix stack corrupted." << std::endl;
  1478. }
  1479. }
  1480. glGetFloatv(GL_TEXTURE_MATRIX, (GLfloat*) mat.m);
  1481. stop_glerror();
  1482. if (mat != identity)
  1483. {
  1484. error = TRUE;
  1485. LL_WARNS("RenderState") << "Texture matrix in channel " << i << " corrupt." << LL_ENDL;
  1486. if (gDebugSession)
  1487. {
  1488. gFailLog << "Texture matrix in channel " << i << " corrupt." << std::endl;
  1489. }
  1490. }
  1491. for (S32 j = (i == 0 ? 1 : 0);
  1492. j < 9; j++)
  1493. {
  1494. if (j == 8 && !gGLManager.mHasTextureRectangle ||
  1495. j == 9 && !gGLManager.mHasTextureMultisample)
  1496. {
  1497. continue;
  1498. }
  1499. if (glIsEnabled(value[j]))
  1500. {
  1501. error = TRUE;
  1502. LL_WARNS("RenderState") << "Texture channel " << i << " still has " << label[j] << " enabled." << LL_ENDL;
  1503. if (gDebugSession)
  1504. {
  1505. gFailLog << "Texture channel " << i << " still has " << label[j] << " enabled." << std::endl;
  1506. }
  1507. }
  1508. stop_glerror();
  1509. }
  1510. glGetFloatv(GL_TEXTURE_MATRIX, mat.m);
  1511. stop_glerror();
  1512. if (mat != identity)
  1513. {
  1514. error = TRUE;
  1515. LL_WARNS("RenderState") << "Texture matrix " << i << " is not identity." << LL_ENDL;
  1516. if (gDebugSession)
  1517. {
  1518. gFailLog << "Texture matrix " << i << " is not identity." << std::endl;
  1519. }
  1520. }
  1521. }
  1522. {
  1523. GLint tex = 0;
  1524. stop_glerror();
  1525. glGetIntegerv(GL_TEXTURE_BINDING_2D, &tex);
  1526. stop_glerror();
  1527. if (te