aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llwindow/llgl.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:45:50 -0500
committerJacek Antonelli2008-08-15 23:45:50 -0500
commit2a4dea528f670b9bb1f77ef27a8a1dd16603d114 (patch)
tree95c68e362703c9099d571ecbdc6142b1cda1e005 /linden/indra/llwindow/llgl.cpp
parentSecond Life viewer sources 1.20.6 (diff)
downloadmeta-impy-2a4dea528f670b9bb1f77ef27a8a1dd16603d114.zip
meta-impy-2a4dea528f670b9bb1f77ef27a8a1dd16603d114.tar.gz
meta-impy-2a4dea528f670b9bb1f77ef27a8a1dd16603d114.tar.bz2
meta-impy-2a4dea528f670b9bb1f77ef27a8a1dd16603d114.tar.xz
Second Life viewer sources 1.20.7
Diffstat (limited to 'linden/indra/llwindow/llgl.cpp')
-rw-r--r--linden/indra/llwindow/llgl.cpp294
1 files changed, 150 insertions, 144 deletions
diff --git a/linden/indra/llwindow/llgl.cpp b/linden/indra/llwindow/llgl.cpp
index 229fdf2..e8169b6 100644
--- a/linden/indra/llwindow/llgl.cpp
+++ b/linden/indra/llwindow/llgl.cpp
@@ -41,7 +41,7 @@
41#include "llsys.h" 41#include "llsys.h"
42 42
43#include "llgl.h" 43#include "llgl.h"
44#include "llglimmediate.h" 44#include "llrender.h"
45 45
46#include "llerror.h" 46#include "llerror.h"
47#include "llquaternion.h" 47#include "llquaternion.h"
@@ -55,6 +55,7 @@
55//#define GL_STATE_VERIFY 55//#define GL_STATE_VERIFY
56#endif 56#endif
57 57
58BOOL gDebugGL = FALSE;
58BOOL gClothRipple = FALSE; 59BOOL gClothRipple = FALSE;
59BOOL gNoRender = FALSE; 60BOOL gNoRender = FALSE;
60LLMatrix4 gGLObliqueProjectionInverse; 61LLMatrix4 gGLObliqueProjectionInverse;
@@ -253,50 +254,50 @@ PFNGLCOLORTABLEEXTPROC glColorTableEXT = NULL;
253 254
254LLGLManager gGLManager; 255LLGLManager gGLManager;
255 256
256LLGLManager::LLGLManager() 257LLGLManager::LLGLManager() :
257{ 258 mInited(FALSE),
258 mInited = FALSE; 259 mIsDisabled(FALSE),
259 mIsDisabled = FALSE; 260
260 mHasCubeMap = FALSE; 261 mHasMultitexture(FALSE),
261 mHasMultitexture = FALSE; 262 mNumTextureUnits(1),
262 mHasMipMapGeneration = FALSE; 263 mHasMipMapGeneration(FALSE),
263 mHasAnisotropic = FALSE; 264 mHasPalettedTextures(FALSE),
264 mHasCompressedTextures = FALSE; 265 mHasCompressedTextures(FALSE),
265 mHasARBEnvCombine = FALSE; 266 mHasFramebufferObject(FALSE),
266 mIsGF2or4MX = FALSE; 267
267 mIsGF3 = FALSE; 268 mHasVertexBufferObject(FALSE),
268 mIsGFFX = FALSE; 269 mHasPBuffer(FALSE),
269 mIsATI = FALSE; 270 mHasShaderObjects(FALSE),
270 mATIOffsetVerticalLines = FALSE; 271 mHasVertexShader(FALSE),
271 mHasVertexShader = FALSE; 272 mHasFragmentShader(FALSE),
272 mHasFragmentShader = FALSE; 273 mHasOcclusionQuery(FALSE),
273 mHasShaderObjects = FALSE; 274 mHasPointParameters(FALSE),
274 mHasPointParameters = FALSE; 275
275 276 mHasAnisotropic(FALSE),
276#if LL_WINDOWS 277 mHasARBEnvCombine(FALSE),
277 mHasWGLARBPixelFormat = FALSE; 278 mHasCubeMap(FALSE),
278#endif // LL_WINDOWS 279
279 280 mIsATI(FALSE),
280#if LL_DARWIN 281 mIsNVIDIA(FALSE),
281 mHasAPPLEVertexArrayRange = FALSE; 282 mIsIntel(FALSE),
282 mHasAPPLEFence = FALSE; 283 mIsGF2or4MX(FALSE),
283 mHasAPPLEVAO = FALSE; 284 mIsGF3(FALSE),
284#endif 285 mIsGFFX(FALSE),
285 286 mATIOffsetVerticalLines(FALSE),
286 mIsNVIDIA = FALSE; 287
287 mIsIntel = FALSE; 288 mHasRequirements(TRUE),
289
290 mHasSeparateSpecularColor(FALSE),
291
292 mDriverVersionMajor(1),
293 mDriverVersionMinor(0),
294 mDriverVersionRelease(0),
295 mGLVersion(1.0f),
288 296
289 mDriverVersionMajor = 1; 297 mVRAM(0),
290 mDriverVersionMinor = 0; 298 mGLMaxVertexRange(0),
291 mDriverVersionRelease = 0; 299 mGLMaxIndexRange(0)
292 mGLVersion = 1.0f; 300{
293
294 mNumTextureUnits = 1;
295 mVRAM = 0;
296 mGLMaxVertexRange = 0;
297 mGLMaxIndexRange = 0;
298
299 mHasRequirements = TRUE;
300} 301}
301 302
302//--------------------------------------------------------------------- 303//---------------------------------------------------------------------
@@ -308,7 +309,7 @@ void LLGLManager::initWGL()
308#if LL_WINDOWS && !LL_MESA_HEADLESS 309#if LL_WINDOWS && !LL_MESA_HEADLESS
309 if (!glh_init_extensions("WGL_ARB_pixel_format")) 310 if (!glh_init_extensions("WGL_ARB_pixel_format"))
310 { 311 {
311 llwarns << "No ARB pixel format extensions" << llendl; 312 LL_WARNS("RenderInit") << "No ARB pixel format extensions" << LL_ENDL;
312 } 313 }
313 314
314 if (ExtensionExists("WGL_EXT_swap_control", gGLHExts.mSysExts)) 315 if (ExtensionExists("WGL_EXT_swap_control", gGLHExts.mSysExts))
@@ -316,15 +317,14 @@ void LLGLManager::initWGL()
316 GLH_EXT_NAME(wglSwapIntervalEXT) = (PFNWGLSWAPINTERVALEXTPROC)GLH_EXT_GET_PROC_ADDRESS("wglSwapIntervalEXT"); 317 GLH_EXT_NAME(wglSwapIntervalEXT) = (PFNWGLSWAPINTERVALEXTPROC)GLH_EXT_GET_PROC_ADDRESS("wglSwapIntervalEXT");
317 } 318 }
318 319
319 mHasWGLARBPixelFormat = glh_init_extensions("WGL_ARB_pbuffer"); 320 if( !glh_init_extensions("WGL_ARB_pbuffer") )
320 if( !mHasWGLARBPixelFormat )
321 { 321 {
322 llwarns << "No ARB WGL PBuffer extensions" << llendl; 322 LL_WARNS("RenderInit") << "No ARB WGL PBuffer extensions" << LL_ENDL;
323 } 323 }
324 324
325 if( !glh_init_extensions("WGL_ARB_render_texture") ) 325 if( !glh_init_extensions("WGL_ARB_render_texture") )
326 { 326 {
327 llwarns << "No ARB WGL render texture extensions" << llendl; 327 LL_WARNS("RenderInit") << "No ARB WGL render texture extensions" << LL_ENDL;
328 } 328 }
329 329
330 mHasPBuffer = ExtensionExists("WGL_ARB_pbuffer", gGLHExts.mSysExts) && 330 mHasPBuffer = ExtensionExists("WGL_ARB_pbuffer", gGLHExts.mSysExts) &&
@@ -338,19 +338,15 @@ bool LLGLManager::initGL()
338{ 338{
339 if (mInited) 339 if (mInited)
340 { 340 {
341 llerrs << "Calling init on LLGLManager after already initialized!" << llendl; 341 LL_ERRS("RenderInit") << "Calling init on LLGLManager after already initialized!" << LL_ENDL;
342 } 342 }
343 343
344 GLint alpha_bits; 344 GLint alpha_bits;
345 glGetIntegerv( GL_ALPHA_BITS, &alpha_bits ); 345 glGetIntegerv( GL_ALPHA_BITS, &alpha_bits );
346 if( 8 != alpha_bits ) 346 if( 8 != alpha_bits )
347 { 347 {
348 llwarns << "Frame buffer has less than 8 bits of alpha. Avatar texture compositing will fail." << llendl; 348 LL_WARNS("RenderInit") << "Frame buffer has less than 8 bits of alpha. Avatar texture compositing will fail." << LL_ENDL;
349 } 349 }
350
351 // This function uses at least one variable that's initialized below.
352 // Moved this call down to after we figure out which card we're dealing with. -- MBW 2003.10.07
353// initExtensions();
354 350
355 // Extract video card strings and convert to upper case to 351 // Extract video card strings and convert to upper case to
356 // work around driver-to-driver variation in capitalization. 352 // work around driver-to-driver variation in capitalization.
@@ -445,7 +441,7 @@ bool LLGLManager::initGL()
445 mHasRequirements = FALSE; 441 mHasRequirements = FALSE;
446 442
447 // We don't support cards that don't support the GL_ARB_multitexture extension 443 // We don't support cards that don't support the GL_ARB_multitexture extension
448 llwarns << "GL Drivers do not support GL_ARB_multitexture" << llendl; 444 LL_WARNS("RenderInit") << "GL Drivers do not support GL_ARB_multitexture" << LL_ENDL;
449 return false; 445 return false;
450 } 446 }
451 447
@@ -489,6 +485,22 @@ LLString LLGLManager::getGLInfoString()
489 return info_str; 485 return info_str;
490} 486}
491 487
488void LLGLManager::printGLInfoString()
489{
490 LLString info_str;
491 LLString all_exts, line;
492
493 LL_INFOS("RenderInit") << "GL_VENDOR: " << ((const char *)glGetString(GL_VENDOR)) << LL_ENDL;
494 LL_INFOS("RenderInit") << "GL_RENDERER: " << ((const char *)glGetString(GL_RENDERER)) << LL_ENDL;
495 LL_INFOS("RenderInit") << "GL_VERSION: " << ((const char *)glGetString(GL_VERSION)) << LL_ENDL;
496
497#if !LL_MESA_HEADLESS
498 all_exts = (const char *)gGLHExts.mSysExts;
499 LLString::replaceChar(all_exts, ' ', '\n');
500 LL_DEBUGS("RenderInit") << "GL_EXTENSIONS:\n" << all_exts << LL_ENDL;
501#endif
502}
503
492LLString LLGLManager::getRawGLString() 504LLString LLGLManager::getRawGLString()
493{ 505{
494 LLString gl_string; 506 LLString gl_string;
@@ -595,8 +607,7 @@ void LLGLManager::initExtensions()
595 mHasShaderObjects = FALSE; 607 mHasShaderObjects = FALSE;
596 mHasVertexShader = FALSE; 608 mHasVertexShader = FALSE;
597 mHasFragmentShader = FALSE; 609 mHasFragmentShader = FALSE;
598 llwarns << "GL extension support DISABLED via LL_GL_NOEXT" << 610 LL_WARNS("RenderInit") << "GL extension support DISABLED via LL_GL_NOEXT" << LL_ENDL;
599 llendl;
600 } 611 }
601 else if (getenv("LL_GL_BASICEXT")) /* Flawfinder: ignore */ 612 else if (getenv("LL_GL_BASICEXT")) /* Flawfinder: ignore */
602 { 613 {
@@ -612,8 +623,7 @@ void LLGLManager::initExtensions()
612 mHasShaderObjects = FALSE; 623 mHasShaderObjects = FALSE;
613 mHasVertexShader = FALSE; 624 mHasVertexShader = FALSE;
614 mHasFragmentShader = FALSE; 625 mHasFragmentShader = FALSE;
615 llwarns << "GL extension support forced to SIMPLE level via LL_GL_BASICEXT" << 626 LL_WARNS("RenderInit") << "GL extension support forced to SIMPLE level via LL_GL_BASICEXT" << LL_ENDL;
616 llendl;
617 } 627 }
618 if (getenv("LL_GL_BLACKLIST")) /* Flawfinder: ignore */ 628 if (getenv("LL_GL_BLACKLIST")) /* Flawfinder: ignore */
619 { 629 {
@@ -621,7 +631,7 @@ void LLGLManager::initExtensions()
621 // GL extensions to isolate problems with their hardware. 631 // GL extensions to isolate problems with their hardware.
622 // SL-28126 632 // SL-28126
623 const char *const blacklist = getenv("LL_GL_BLACKLIST"); /* Flawfinder: ignore */ 633 const char *const blacklist = getenv("LL_GL_BLACKLIST"); /* Flawfinder: ignore */
624 llwarns << "GL extension support partially disabled via LL_GL_BLACKLIST: " << blacklist << llendl; 634 LL_WARNS("RenderInit") << "GL extension support partially disabled via LL_GL_BLACKLIST: " << blacklist << LL_ENDL;
625 if (strchr(blacklist,'a')) mHasARBEnvCombine = FALSE; 635 if (strchr(blacklist,'a')) mHasARBEnvCombine = FALSE;
626 if (strchr(blacklist,'b')) mHasCompressedTextures = FALSE; 636 if (strchr(blacklist,'b')) mHasCompressedTextures = FALSE;
627 if (strchr(blacklist,'c')) mHasVertexBufferObject = FALSE; 637 if (strchr(blacklist,'c')) mHasVertexBufferObject = FALSE;
@@ -651,62 +661,62 @@ void LLGLManager::initExtensions()
651 661
652 if (!mHasMultitexture) 662 if (!mHasMultitexture)
653 { 663 {
654 llinfos << "Couldn't initialize multitexturing" << llendl; 664 LL_INFOS("RenderInit") << "Couldn't initialize multitexturing" << LL_ENDL;
655 } 665 }
656 if (!mHasMipMapGeneration) 666 if (!mHasMipMapGeneration)
657 { 667 {
658 llinfos << "Couldn't initialize mipmap generation" << llendl; 668 LL_INFOS("RenderInit") << "Couldn't initialize mipmap generation" << LL_ENDL;
659 } 669 }
660 if (!mHasARBEnvCombine) 670 if (!mHasARBEnvCombine)
661 { 671 {
662 llinfos << "Couldn't initialize GL_ARB_texture_env_combine" << llendl; 672 LL_INFOS("RenderInit") << "Couldn't initialize GL_ARB_texture_env_combine" << LL_ENDL;
663 } 673 }
664 if (!mHasPalettedTextures) 674 if (!mHasPalettedTextures)
665 { 675 {
666 llinfos << "Couldn't initialize GL_EXT_paletted_texture" << llendl; 676 LL_INFOS("RenderInit") << "Couldn't initialize GL_EXT_paletted_texture" << LL_ENDL;
667 } 677 }
668 if (!mHasSeparateSpecularColor) 678 if (!mHasSeparateSpecularColor)
669 { 679 {
670 llinfos << "Couldn't initialize separate specular color" << llendl; 680 LL_INFOS("RenderInit") << "Couldn't initialize separate specular color" << LL_ENDL;
671 } 681 }
672 if (!mHasAnisotropic) 682 if (!mHasAnisotropic)
673 { 683 {
674 llinfos << "Couldn't initialize anisotropic filtering" << llendl; 684 LL_INFOS("RenderInit") << "Couldn't initialize anisotropic filtering" << LL_ENDL;
675 } 685 }
676 if (!mHasCompressedTextures) 686 if (!mHasCompressedTextures)
677 { 687 {
678 llinfos << "Couldn't initialize GL_ARB_texture_compression" << llendl; 688 LL_INFOS("RenderInit") << "Couldn't initialize GL_ARB_texture_compression" << LL_ENDL;
679 } 689 }
680 if (!mHasOcclusionQuery) 690 if (!mHasOcclusionQuery)
681 { 691 {
682 llinfos << "Couldn't initialize GL_ARB_occlusion_query" << llendl; 692 LL_INFOS("RenderInit") << "Couldn't initialize GL_ARB_occlusion_query" << LL_ENDL;
683 } 693 }
684 if (!mHasPointParameters) 694 if (!mHasPointParameters)
685 { 695 {
686 llinfos << "Couldn't initialize GL_ARB_point_parameters" << llendl; 696 LL_INFOS("RenderInit") << "Couldn't initialize GL_ARB_point_parameters" << LL_ENDL;
687 } 697 }
688 if (!mHasShaderObjects) 698 if (!mHasShaderObjects)
689 { 699 {
690 llinfos << "Couldn't initialize GL_ARB_shader_objects" << llendl; 700 LL_INFOS("RenderInit") << "Couldn't initialize GL_ARB_shader_objects" << LL_ENDL;
691 } 701 }
692 if (!mHasVertexShader) 702 if (!mHasVertexShader)
693 { 703 {
694 llinfos << "Couldn't initialize GL_ARB_vertex_shader" << llendl; 704 LL_INFOS("RenderInit") << "Couldn't initialize GL_ARB_vertex_shader" << LL_ENDL;
695 } 705 }
696 if (!mHasFragmentShader) 706 if (!mHasFragmentShader)
697 { 707 {
698 llinfos << "Couldn't initialize GL_ARB_fragment_shader" << llendl; 708 LL_INFOS("RenderInit") << "Couldn't initialize GL_ARB_fragment_shader" << LL_ENDL;
699 } 709 }
700 710
701 // Disable certain things due to known bugs 711 // Disable certain things due to known bugs
702 if (mIsIntel && mHasMipMapGeneration) 712 if (mIsIntel && mHasMipMapGeneration)
703 { 713 {
704 llinfos << "Disabling mip-map generation for Intel GPUs" << llendl; 714 LL_INFOS("RenderInit") << "Disabling mip-map generation for Intel GPUs" << LL_ENDL;
705 mHasMipMapGeneration = FALSE; 715 mHasMipMapGeneration = FALSE;
706 } 716 }
707 if (mIsATI && mHasMipMapGeneration) 717 if (mIsATI && mHasMipMapGeneration)
708 { 718 {
709 llinfos << "Disabling mip-map generation for ATI GPUs (performance opt)" << llendl; 719 LL_INFOS("RenderInit") << "Disabling mip-map generation for ATI GPUs (performance opt)" << LL_ENDL;
710 mHasMipMapGeneration = FALSE; 720 mHasMipMapGeneration = FALSE;
711 } 721 }
712 722
@@ -714,30 +724,8 @@ void LLGLManager::initExtensions()
714 glGetIntegerv(GL_MAX_ELEMENTS_VERTICES, (GLint*) &mGLMaxVertexRange); 724 glGetIntegerv(GL_MAX_ELEMENTS_VERTICES, (GLint*) &mGLMaxVertexRange);
715 glGetIntegerv(GL_MAX_ELEMENTS_INDICES, (GLint*) &mGLMaxIndexRange); 725 glGetIntegerv(GL_MAX_ELEMENTS_INDICES, (GLint*) &mGLMaxIndexRange);
716 726
717 // Apple specific
718#if LL_DARWIN
719 mHasAPPLEVertexArrayRange = glh_init_extensions("GL_APPLE_vertex_array_range");
720 if (!mHasAPPLEVertexArrayRange)
721 {
722 llinfos << "Couldn't initialize GL_APPLE_vertex_array_range" << llendl;
723 }
724
725 mHasAPPLEFence = glh_init_extensions("GL_APPLE_fence");
726 if (!mHasAPPLEFence)
727 {
728 llinfos << "Couldn't initialize GL_APPLE_fence" << llendl;
729 }
730
731 mHasAPPLEVAO = glh_init_extensions("GL_APPLE_vertex_array_object");
732 if (mHasAPPLEVAO)
733 {
734 llinfos << "Has GL_APPLE_vertex_array_object!" << llendl;
735 }
736
737#endif // LL_DARWIN
738
739#if (LL_WINDOWS || LL_LINUX) && !LL_MESA_HEADLESS 727#if (LL_WINDOWS || LL_LINUX) && !LL_MESA_HEADLESS
740 llinfos << "GL Probe: Getting symbols" << llendl; 728 LL_DEBUGS("RenderInit") << "GL Probe: Getting symbols" << LL_ENDL;
741 if (mHasVertexBufferObject) 729 if (mHasVertexBufferObject)
742 { 730 {
743 glBindBufferARB = (PFNGLBINDBUFFERARBPROC)GLH_EXT_GET_PROC_ADDRESS("glBindBufferARB"); 731 glBindBufferARB = (PFNGLBINDBUFFERARBPROC)GLH_EXT_GET_PROC_ADDRESS("glBindBufferARB");
@@ -921,7 +909,7 @@ void LLGLManager::initExtensions()
921 glGetVertexAttribPointervARB = (PFNGLGETVERTEXATTRIBPOINTERVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glgetVertexAttribPointervARB"); 909 glGetVertexAttribPointervARB = (PFNGLGETVERTEXATTRIBPOINTERVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glgetVertexAttribPointervARB");
922 glIsProgramARB = (PFNGLISPROGRAMARBPROC) GLH_EXT_GET_PROC_ADDRESS("glIsProgramARB"); 910 glIsProgramARB = (PFNGLISPROGRAMARBPROC) GLH_EXT_GET_PROC_ADDRESS("glIsProgramARB");
923 } 911 }
924 llinfos << "GL Probe: Got symbols" << llendl; 912 LL_DEBUGS("RenderInit") << "GL Probe: Got symbols" << LL_ENDL;
925#endif 913#endif
926 914
927 mInited = TRUE; 915 mInited = TRUE;
@@ -941,33 +929,41 @@ void flush_glerror()
941 929
942void assert_glerror() 930void assert_glerror()
943{ 931{
944 if (gNoRender) 932 if (gNoRender || !gDebugGL)
945 { 933 {
946 return; 934 return;
947 } 935 }
948 if (!gGLManager.mInited) 936 if (!gGLManager.mInited)
949 { 937 {
950 llerrs << "GL not initialized" << llendl; 938 LL_ERRS("RenderInit") << "GL not initialized" << LL_ENDL;
951 } 939 }
952 // Create or update texture to be used with this data 940 // Create or update texture to be used with this data
953 GLenum error; 941 GLenum error;
954 error = glGetError(); 942 error = glGetError();
955 if (error) 943 BOOL quit = FALSE;
944 while (error)
956 { 945 {
946 quit = TRUE;
957#ifndef LL_LINUX // *FIX: ! This should be an error for linux as well. 947#ifndef LL_LINUX // *FIX: ! This should be an error for linux as well.
958 GLubyte const * gl_error_msg = gluErrorString(error); 948 GLubyte const * gl_error_msg = gluErrorString(error);
959 if (NULL != gl_error_msg) 949 if (NULL != gl_error_msg)
960 { 950 {
961 llerrs << "GL Error:" << gl_error_msg << llendl; 951 LL_WARNS("RenderState") << "GL Error:" << gl_error_msg << LL_ENDL;
962 } 952 }
963 else 953 else
964 { 954 {
965 // gluErrorString returns NULL for some extensions' error codes. 955 // gluErrorString returns NULL for some extensions' error codes.
966 // you'll probably have to grep for the number in glext.h. 956 // you'll probably have to grep for the number in glext.h.
967 llerrs << "GL Error: UNKNOWN 0x" << std::hex << error << llendl; 957 LL_WARNS("RenderState") << "GL Error: UNKNOWN 0x" << std::hex << error << LL_ENDL;
968 } 958 }
959 error = glGetError();
969#endif 960#endif
970 } 961 }
962
963 if (quit)
964 {
965 llerrs << "One or more unhandled GL errors." << llendl;
966 }
971} 967}
972 968
973void clear_glerror() 969void clear_glerror()
@@ -977,8 +973,7 @@ void clear_glerror()
977 error = glGetError(); 973 error = glGetError();
978} 974}
979 975
980//============================================================================ 976///////////////////////////////////////////////////////////////
981
982// 977//
983// LLGLState 978// LLGLState
984// 979//
@@ -1014,7 +1009,7 @@ void LLGLState::resetTextureStates()
1014 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &maxTextureUnits); 1009 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &maxTextureUnits);
1015 for (S32 j = maxTextureUnits-1; j >=0; j--) 1010 for (S32 j = maxTextureUnits-1; j >=0; j--)
1016 { 1011 {
1017 glActiveTextureARB(GL_TEXTURE0_ARB+j); 1012 gGL.getTexUnit(j)->activate();
1018 glClientActiveTextureARB(GL_TEXTURE0_ARB+j); 1013 glClientActiveTextureARB(GL_TEXTURE0_ARB+j);
1019 j == 0 ? glEnable(GL_TEXTURE_2D) : glDisable(GL_TEXTURE_2D); 1014 j == 0 ? glEnable(GL_TEXTURE_2D) : glDisable(GL_TEXTURE_2D);
1020 } 1015 }
@@ -1022,17 +1017,21 @@ void LLGLState::resetTextureStates()
1022 1017
1023void LLGLState::dumpStates() 1018void LLGLState::dumpStates()
1024{ 1019{
1025 llinfos << "GL States:" << llendl; 1020 LL_INFOS("RenderState") << "GL States:" << LL_ENDL;
1026 for (std::map<LLGLenum, LLGLboolean>::iterator iter = sStateMap.begin(); 1021 for (std::map<LLGLenum, LLGLboolean>::iterator iter = sStateMap.begin();
1027 iter != sStateMap.end(); ++iter) 1022 iter != sStateMap.end(); ++iter)
1028 { 1023 {
1029 llinfos << llformat(" 0x%04x : %s",(S32)iter->first,iter->second?"TRUE":"FALSE") << llendl; 1024 LL_INFOS("RenderState") << llformat(" 0x%04x : %s",(S32)iter->first,iter->second?"TRUE":"FALSE") << LL_ENDL;
1030 } 1025 }
1031} 1026}
1032 1027
1033void LLGLState::checkStates() 1028void LLGLState::checkStates()
1034{ 1029{
1035#if LL_DEBUG_GL 1030 if (!gDebugGL)
1031 {
1032 return;
1033 }
1034
1036 stop_glerror(); 1035 stop_glerror();
1037 1036
1038 GLint activeTexture; 1037 GLint activeTexture;
@@ -1040,7 +1039,7 @@ void LLGLState::checkStates()
1040 1039
1041 if (activeTexture != GL_TEXTURE0_ARB) 1040 if (activeTexture != GL_TEXTURE0_ARB)
1042 { 1041 {
1043 LL_GL_ERRS << "Texture channel corrupted. " << llendl; 1042 LL_GL_ERRS << "Texture channel corrupted. " << LL_ENDL;
1044 } 1043 }
1045 1044
1046 GLint src; 1045 GLint src;
@@ -1050,7 +1049,7 @@ void LLGLState::checkStates()
1050 1049
1051 if (src != GL_SRC_ALPHA || dst != GL_ONE_MINUS_SRC_ALPHA) 1050 if (src != GL_SRC_ALPHA || dst != GL_ONE_MINUS_SRC_ALPHA)
1052 { 1051 {
1053 LL_GL_ERRS << "Blend function corrupted: " << std::hex << src << " " << std::hex << dst << llendl; 1052 LL_GL_ERRS << "Blend function corrupted: " << std::hex << src << " " << std::hex << dst << LL_ENDL;
1054 } 1053 }
1055 1054
1056 for (std::map<LLGLenum, LLGLboolean>::iterator iter = sStateMap.begin(); 1055 for (std::map<LLGLenum, LLGLboolean>::iterator iter = sStateMap.begin();
@@ -1062,17 +1061,20 @@ void LLGLState::checkStates()
1062 if(cur_state != gl_state) 1061 if(cur_state != gl_state)
1063 { 1062 {
1064 dumpStates(); 1063 dumpStates();
1065 LL_GL_ERRS << llformat("LLGLState error. State: 0x%04x",state) << llendl; 1064 LL_GL_ERRS << llformat("LLGLState error. State: 0x%04x",state) << LL_ENDL;
1066 } 1065 }
1067 } 1066 }
1068 1067
1069 stop_glerror(); 1068 stop_glerror();
1070#endif
1071} 1069}
1072 1070
1073void LLGLState::checkTextureChannels() 1071void LLGLState::checkTextureChannels()
1074{ 1072{
1075#if LL_DEBUG_GL 1073 if (!gDebugGL)
1074 {
1075 return;
1076 }
1077
1076 GLint activeTexture; 1078 GLint activeTexture;
1077 glGetIntegerv(GL_ACTIVE_TEXTURE_ARB, &activeTexture); 1079 glGetIntegerv(GL_ACTIVE_TEXTURE_ARB, &activeTexture);
1078 1080
@@ -1081,12 +1083,12 @@ void LLGLState::checkTextureChannels()
1081 if (activeTexture != GL_TEXTURE0_ARB) 1083 if (activeTexture != GL_TEXTURE0_ARB)
1082 { 1084 {
1083 error = TRUE; 1085 error = TRUE;
1084 llwarns << "Active texture channel corrupted. " << llendl; 1086 LL_WARNS("RenderState") << "Active texture channel corrupted. " << LL_ENDL;
1085 } 1087 }
1086 else if (!glIsEnabled(GL_TEXTURE_2D)) 1088 else if (!glIsEnabled(GL_TEXTURE_2D))
1087 { 1089 {
1088 error = TRUE; 1090 error = TRUE;
1089 llwarns << "GL_TEXTURE_2D not enabled on texture channel 0." << llendl; 1091 LL_WARNS("RenderState") << "GL_TEXTURE_2D not enabled on texture channel 0." << LL_ENDL;
1090 } 1092 }
1091 else 1093 else
1092 { 1094 {
@@ -1096,7 +1098,7 @@ void LLGLState::checkTextureChannels()
1096 if (tex_env_mode != GL_MODULATE) 1098 if (tex_env_mode != GL_MODULATE)
1097 { 1099 {
1098 error = TRUE; 1100 error = TRUE;
1099 llwarns << "GL_TEXTURE_ENV_MODE invalid: " << std::hex << tex_env_mode << llendl; 1101 LL_WARNS("RenderState") << "GL_TEXTURE_ENV_MODE invalid: " << std::hex << tex_env_mode << LL_ENDL;
1100 } 1102 }
1101 } 1103 }
1102 1104
@@ -1133,7 +1135,7 @@ void LLGLState::checkTextureChannels()
1133 1135
1134 for (GLint i = 0; i < maxTextureUnits; i++) 1136 for (GLint i = 0; i < maxTextureUnits; i++)
1135 { 1137 {
1136 glActiveTextureARB(GL_TEXTURE0_ARB+i); 1138 gGL.getTexUnit(i)->activate();
1137 glClientActiveTextureARB(GL_TEXTURE0_ARB+i); 1139 glClientActiveTextureARB(GL_TEXTURE0_ARB+i);
1138 1140
1139 glGetIntegerv(GL_TEXTURE_STACK_DEPTH, &stackDepth); 1141 glGetIntegerv(GL_TEXTURE_STACK_DEPTH, &stackDepth);
@@ -1141,7 +1143,7 @@ void LLGLState::checkTextureChannels()
1141 if (stackDepth != 1) 1143 if (stackDepth != 1)
1142 { 1144 {
1143 error = TRUE; 1145 error = TRUE;
1144 llwarns << "Texture matrix stack corrupted." << llendl; 1146 LL_WARNS("RenderState") << "Texture matrix stack corrupted." << LL_ENDL;
1145 } 1147 }
1146 1148
1147 glGetFloatv(GL_TEXTURE_MATRIX, (GLfloat*) matrix.mMatrix); 1149 glGetFloatv(GL_TEXTURE_MATRIX, (GLfloat*) matrix.mMatrix);
@@ -1149,7 +1151,7 @@ void LLGLState::checkTextureChannels()
1149 if (matrix != identity) 1151 if (matrix != identity)
1150 { 1152 {
1151 error = TRUE; 1153 error = TRUE;
1152 llwarns << "Texture matrix in channel " << i << " corrupt." << llendl; 1154 LL_WARNS("RenderState") << "Texture matrix in channel " << i << " corrupt." << LL_ENDL;
1153 } 1155 }
1154 1156
1155 for (S32 j = (i == 0 ? 1 : 0); j < 8; j++) 1157 for (S32 j = (i == 0 ? 1 : 0); j < 8; j++)
@@ -1157,24 +1159,27 @@ void LLGLState::checkTextureChannels()
1157 if (glIsEnabled(value[j])) 1159 if (glIsEnabled(value[j]))
1158 { 1160 {
1159 error = TRUE; 1161 error = TRUE;
1160 llwarns << "Texture channel " << i << " still has " << label[j] << " enabled." << llendl; 1162 LL_WARNS("RenderState") << "Texture channel " << i << " still has " << label[j] << " enabled." << LL_ENDL;
1161 } 1163 }
1162 } 1164 }
1163 } 1165 }
1164 1166
1165 glActiveTextureARB(GL_TEXTURE0_ARB); 1167 gGL.getTexUnit(0)->activate();
1166 glClientActiveTextureARB(GL_TEXTURE0_ARB); 1168 glClientActiveTextureARB(GL_TEXTURE0_ARB);
1167 1169
1168 if (error) 1170 if (error)
1169 { 1171 {
1170 LL_GL_ERRS << "GL texture state corruption detected." << llendl; 1172 LL_GL_ERRS << "GL texture state corruption detected." << LL_ENDL;
1171 } 1173 }
1172#endif
1173} 1174}
1174 1175
1175void LLGLState::checkClientArrays(U32 data_mask) 1176void LLGLState::checkClientArrays(U32 data_mask)
1176{ 1177{
1177#if LL_DEBUG_GL 1178 if (!gDebugGL)
1179 {
1180 return;
1181 }
1182
1178 stop_glerror(); 1183 stop_glerror();
1179 BOOL error = FALSE; 1184 BOOL error = FALSE;
1180 1185
@@ -1226,7 +1231,7 @@ void LLGLState::checkClientArrays(U32 data_mask)
1226 if (!(mask[j] & data_mask)) 1231 if (!(mask[j] & data_mask))
1227 { 1232 {
1228 error = TRUE; 1233 error = TRUE;
1229 llwarns << "GL still has " << label[j] << " enabled." << llendl; 1234 LL_WARNS("RenderState") << "GL still has " << label[j] << " enabled." << LL_ENDL;
1230 } 1235 }
1231 } 1236 }
1232 else 1237 else
@@ -1234,19 +1239,19 @@ void LLGLState::checkClientArrays(U32 data_mask)
1234 if (mask[j] & data_mask) 1239 if (mask[j] & data_mask)
1235 { 1240 {
1236 error = TRUE; 1241 error = TRUE;
1237 llwarns << "GL does not have " << label[j] << " enabled." << llendl; 1242 LL_WARNS("RenderState") << "GL does not have " << label[j] << " enabled." << LL_ENDL;
1238 } 1243 }
1239 } 1244 }
1240 } 1245 }
1241 1246
1242 glClientActiveTextureARB(GL_TEXTURE1_ARB); 1247 glClientActiveTextureARB(GL_TEXTURE1_ARB);
1243 glActiveTextureARB(GL_TEXTURE1_ARB); 1248 gGL.getTexUnit(1)->activate();
1244 if (glIsEnabled(GL_TEXTURE_COORD_ARRAY)) 1249 if (glIsEnabled(GL_TEXTURE_COORD_ARRAY))
1245 { 1250 {
1246 if (!(data_mask & 0x0008)) 1251 if (!(data_mask & 0x0008))
1247 { 1252 {
1248 error = TRUE; 1253 error = TRUE;
1249 llwarns << "GL still has GL_TEXTURE_COORD_ARRAY enabled on channel 1." << llendl; 1254 LL_WARNS("RenderState") << "GL still has GL_TEXTURE_COORD_ARRAY enabled on channel 1." << LL_ENDL;
1250 } 1255 }
1251 } 1256 }
1252 else 1257 else
@@ -1254,7 +1259,7 @@ void LLGLState::checkClientArrays(U32 data_mask)
1254 if (data_mask & 0x0008) 1259 if (data_mask & 0x0008)
1255 { 1260 {
1256 error = TRUE; 1261 error = TRUE;
1257 llwarns << "GL does not have GL_TEXTURE_COORD_ARRAY enabled on channel 1." << llendl; 1262 LL_WARNS("RenderState") << "GL does not have GL_TEXTURE_COORD_ARRAY enabled on channel 1." << LL_ENDL;
1258 } 1263 }
1259 } 1264 }
1260 1265
@@ -1263,7 +1268,7 @@ void LLGLState::checkClientArrays(U32 data_mask)
1263 if (!(data_mask & 0x0008)) 1268 if (!(data_mask & 0x0008))
1264 { 1269 {
1265 error = TRUE; 1270 error = TRUE;
1266 llwarns << "GL still has GL_TEXTURE_2D enabled on channel 1." << llendl; 1271 LL_WARNS("RenderState") << "GL still has GL_TEXTURE_2D enabled on channel 1." << LL_ENDL;
1267 } 1272 }
1268 } 1273 }
1269 else 1274 else
@@ -1271,26 +1276,25 @@ void LLGLState::checkClientArrays(U32 data_mask)
1271 if (data_mask & 0x0008) 1276 if (data_mask & 0x0008)
1272 { 1277 {
1273 error = TRUE; 1278 error = TRUE;
1274 llwarns << "GL does not have GL_TEXTURE_2D enabled on channel 1." << llendl; 1279 LL_WARNS("RenderState") << "GL does not have GL_TEXTURE_2D enabled on channel 1." << LL_ENDL;
1275 } 1280 }
1276 } 1281 }
1277 1282
1278 glClientActiveTextureARB(GL_TEXTURE0_ARB); 1283 glClientActiveTextureARB(GL_TEXTURE0_ARB);
1279 glActiveTextureARB(GL_TEXTURE0_ARB); 1284 gGL.getTexUnit(0)->activate();
1280 1285
1281 if (error) 1286 if (error)
1282 { 1287 {
1283 LL_GL_ERRS << "GL client array corruption detected." << llendl; 1288 LL_GL_ERRS << "GL client array corruption detected." << LL_ENDL;
1284 } 1289 }
1285#endif
1286} 1290}
1287 1291
1288//============================================================================ 1292///////////////////////////////////////////////////////////////////////
1289 1293
1290LLGLState::LLGLState(LLGLenum state, S32 enabled) 1294LLGLState::LLGLState(LLGLenum state, S32 enabled) :
1295 mState(state), mWasEnabled(FALSE), mIsEnabled(FALSE)
1291{ 1296{
1292 stop_glerror(); 1297 stop_glerror();
1293 mState = state;
1294 if (state) 1298 if (state)
1295 { 1299 {
1296 mWasEnabled = sStateMap[state]; 1300 mWasEnabled = sStateMap[state];
@@ -1330,9 +1334,11 @@ LLGLState::~LLGLState()
1330 stop_glerror(); 1334 stop_glerror();
1331 if (mState) 1335 if (mState)
1332 { 1336 {
1333#if LL_DEBUG_GL 1337 if (gDebugGL)
1334 llassert(sStateMap[mState] == glIsEnabled(mState)); 1338 {
1335#endif 1339 llassert_always(sStateMap[mState] == glIsEnabled(mState));
1340 }
1341
1336 if (mIsEnabled != mWasEnabled) 1342 if (mIsEnabled != mWasEnabled)
1337 { 1343 {
1338 gGL.flush(); 1344 gGL.flush();
@@ -1351,7 +1357,7 @@ LLGLState::~LLGLState()
1351 stop_glerror(); 1357 stop_glerror();
1352} 1358}
1353 1359
1354//============================================================================ 1360////////////////////////////////////////////////////////////////////////////////
1355 1361
1356void LLGLManager::initGLStates() 1362void LLGLManager::initGLStates()
1357{ 1363{
@@ -1359,7 +1365,7 @@ void LLGLManager::initGLStates()
1359 LLGLState::initClass(); 1365 LLGLState::initClass();
1360} 1366}
1361 1367
1362//============================================================================ 1368////////////////////////////////////////////////////////////////////////////////
1363 1369
1364void enable_vertex_weighting(const S32 index) 1370void enable_vertex_weighting(const S32 index)
1365{ 1371{