From 736696ac36c925b355c9d1e795830aaf20d700fd Mon Sep 17 00:00:00 2001 From: Shyotl Date: Mon, 19 Nov 2018 00:37:48 -0600 Subject: [PATCH] Track glEnable states via static refs instead of map lookups. Sync light state, bound shader, and various gl context states similarly to render matrices. Texture handles now refcounted, as multiple viewer textures could ref the same handle (cubemaps do this) Clean up gl extension loading a bit. Not necessary, but only look for ARB variants if not included in current core version. Removed unused extensions. Use core shader api if supported, else use ARB. (FN signatures are identical. Just doing some pointer substitution to ARB if not core.) Attempt at improving VBO update batching. Subdata updates better batched to gether per-frame. There's probably other stuff I forgot that is in this changeset, too. Todo: Fix lightstate assertion when toggling fullscreen with shaders off. --- indra/llappearance/llavatarappearance.h | 2 +- indra/llappearance/lltexlayer.cpp | 23 +- indra/llappearance/lltexlayerparams.cpp | 2 +- indra/llrender/llcubemap.cpp | 10 +- indra/llrender/llcubemap.h | 2 +- indra/llrender/llgl.cpp | 558 +++++---- indra/llrender/llgl.h | 150 ++- indra/llrender/llglheaders.h | 30 +- indra/llrender/llglslshader.cpp | 17 +- indra/llrender/llglslshader.h | 24 + indra/llrender/llglstates.h | 195 ++-- indra/llrender/llgltexture.cpp | 2 +- indra/llrender/llgltexture.h | 3 +- indra/llrender/llimagegl.cpp | 290 +++-- indra/llrender/llimagegl.h | 66 +- indra/llrender/llpostprocess.cpp | 36 +- indra/llrender/llpostprocess.h | 4 +- indra/llrender/llrender.cpp | 747 +++++++----- indra/llrender/llrender.h | 220 +++- indra/llrender/llrender2dutils.cpp | 4 +- indra/llrender/llrendertarget.cpp | 49 +- indra/llrender/llrendertarget.h | 4 +- indra/llrender/llshadermgr.cpp | 43 +- indra/llrender/llshadermgr.h | 2 +- indra/llrender/llvertexbuffer.cpp | 325 ++++-- indra/llrender/llvertexbuffer.h | 16 +- indra/llui/lllocalcliprect.cpp | 29 +- indra/llui/lllocalcliprect.h | 9 +- indra/llwindow/llwindowwin32.cpp | 1 + .../shaders/class1/lighting/lightFuncV.glsl | 5 +- .../class1/lighting/sumLightsSpecularV.glsl | 15 +- .../shaders/class1/lighting/sumLightsV.glsl | 28 +- .../shaders/class1/objects/previewV.glsl | 2 +- .../class2/lighting/sumLightsSpecularV.glsl | 6 +- .../shaders/class2/lighting/sumLightsV.glsl | 18 +- .../class3/lighting/sumLightsSpecularV.glsl | 6 +- .../shaders/class3/lighting/sumLightsV.glsl | 16 +- indra/newview/llappviewer.cpp | 9 +- indra/newview/lldrawpoolalpha.cpp | 46 +- indra/newview/lldrawpoolavatar.cpp | 23 +- indra/newview/lldrawpoolbump.cpp | 18 +- indra/newview/lldrawpoolground.cpp | 2 - indra/newview/lldrawpoolsimple.cpp | 48 +- indra/newview/lldrawpoolsky.cpp | 8 +- indra/newview/lldrawpoolterrain.cpp | 57 +- indra/newview/lldrawpooltree.cpp | 12 +- indra/newview/lldrawpoolwater.cpp | 23 +- indra/newview/lldrawpoolwlsky.cpp | 21 +- indra/newview/lldynamictexture.cpp | 8 +- indra/newview/llface.cpp | 8 +- indra/newview/llfasttimerview.cpp | 12 +- indra/newview/llfloateravatarpicker.cpp | 2 +- indra/newview/llfloatercolorpicker.cpp | 2 +- indra/newview/llfloaterimagepreview.cpp | 17 +- indra/newview/llfloatermodelpreview.cpp | 53 +- indra/newview/llfloaterreporter.cpp | 2 +- indra/newview/llfloatersnapshot.cpp | 7 +- indra/newview/llglsandbox.cpp | 11 +- indra/newview/llhudeffectlookat.cpp | 2 +- indra/newview/llhudnametag.cpp | 4 +- indra/newview/llhudtext.cpp | 20 +- indra/newview/llmaniprotate.cpp | 12 +- indra/newview/llmanipscale.cpp | 10 +- indra/newview/llmaniptranslate.cpp | 21 +- indra/newview/llmediactrl.cpp | 2 +- indra/newview/llpaneldisplay.cpp | 8 +- indra/newview/llselectmgr.cpp | 20 +- indra/newview/llsky.cpp | 34 +- indra/newview/llspatialpartition.cpp | 109 +- indra/newview/llstartup.cpp | 8 +- indra/newview/lltexturectrl.cpp | 2 +- indra/newview/lltracker.cpp | 2 +- indra/newview/llviewercamera.cpp | 11 +- indra/newview/llviewercontrol.cpp | 2 +- indra/newview/llviewerdisplay.cpp | 118 +- indra/newview/llviewerjoint.cpp | 2 +- indra/newview/llviewerjointattachment.cpp | 2 +- indra/newview/llvieweroctree.cpp | 4 +- indra/newview/llviewershadermgr.cpp | 9 +- indra/newview/llviewerstats.cpp | 2 +- indra/newview/llviewertexture.cpp | 7 +- indra/newview/llviewertexture.h | 2 +- indra/newview/llviewertexturelist.cpp | 1 + indra/newview/llviewerwindow.cpp | 112 +- indra/newview/llvoavatar.cpp | 29 +- indra/newview/llvosky.cpp | 2 +- indra/newview/llwaterparammanager.cpp | 22 +- indra/newview/llwlparammanager.cpp | 12 +- indra/newview/llwlparammanager.h | 4 +- indra/newview/llwlparamset.cpp | 93 +- indra/newview/llwlparamset.h | 3 +- indra/newview/llworldmapview.cpp | 2 +- indra/newview/m7wlinterface.cpp | 12 +- indra/newview/pipeline.cpp | 1018 ++++++++--------- indra/newview/pipeline.h | 61 +- indra/newview/qtoolalign.cpp | 4 +- 96 files changed, 2870 insertions(+), 2266 deletions(-) diff --git a/indra/llappearance/llavatarappearance.h b/indra/llappearance/llavatarappearance.h index e77dcac0e..aaee5ed13 100644 --- a/indra/llappearance/llavatarappearance.h +++ b/indra/llappearance/llavatarappearance.h @@ -341,7 +341,7 @@ protected: bool mIsLoaded; bool mIsUsed; LLAvatarAppearanceDefines::ETextureIndex mTextureIndex; - U32 mMaskTexName; + LLImageGL::GLTextureName mMaskTexName; // Stores pointers to the joint meshes that this baked texture deals with avatar_joint_mesh_list_t mJointMeshes; morph_list_t mMaskedMorphs; diff --git a/indra/llappearance/lltexlayer.cpp b/indra/llappearance/lltexlayer.cpp index 5e6ed7f45..a222bc208 100644 --- a/indra/llappearance/lltexlayer.cpp +++ b/indra/llappearance/lltexlayer.cpp @@ -397,7 +397,7 @@ BOOL LLTexLayerSet::render( S32 x, S32 y, S32 width, S32 height ) // clear buffer area to ensure we don't pick up UI elements { gGL.flush(); - LLGLDisable no_alpha(GL_ALPHA_TEST); + LLGLDisable no_alpha; if (use_shaders) { gAlphaMaskProgram.setMinimumAlpha(0.0f); @@ -437,7 +437,7 @@ BOOL LLTexLayerSet::render( S32 x, S32 y, S32 width, S32 height ) gGL.flush(); gGL.setSceneBlendType(LLRender::BT_REPLACE); - LLGLDisable no_alpha(GL_ALPHA_TEST); + LLGLDisable no_alpha; if (use_shaders) { gAlphaMaskProgram.setMinimumAlpha(0.f); @@ -568,7 +568,7 @@ void LLTexLayerSet::renderAlphaMaskTextures(S32 x, S32 y, S32 width, S32 height, { // Set the alpha channel to one (clean up after previous blending) gGL.flush(); - LLGLDisable no_alpha(GL_ALPHA_TEST); + LLGLDisable no_alpha; if (use_shaders) { gAlphaMaskProgram.setMinimumAlpha(0.f); @@ -1123,14 +1123,11 @@ void LLTexLayer::calculateTexLayerColor(const param_color_list_t ¶m_list, LL BOOL LLTexLayer::render(S32 x, S32 y, S32 width, S32 height) { - LLGLEnable color_mat(GL_COLOR_MATERIAL); + LLGLEnable color_mat; // *TODO: Is this correct? //gPipeline.disableLights(); stop_glerror(); - if (!LLGLSLShader::sNoFixedFunction) - { - glDisable(GL_LIGHTING); - } + LLGLDisable no_lighting(!LLGLSLShader::sNoFixedFunction); stop_glerror(); bool use_shaders = LLGLSLShader::sNoFixedFunction; @@ -1217,7 +1214,7 @@ BOOL LLTexLayer::render(S32 x, S32 y, S32 width, S32 height) if( tex ) { bool no_alpha_test = getInfo()->mWriteAllChannels; - LLGLDisable alpha_test(no_alpha_test ? GL_ALPHA_TEST : 0); + LLGLDisable alpha_test(no_alpha_test); if (no_alpha_test) { if (use_shaders) @@ -1273,7 +1270,7 @@ BOOL LLTexLayer::render(S32 x, S32 y, S32 width, S32 height) getInfo()->mStaticImageFileName.empty() && color_specified ) { - LLGLDisable no_alpha(GL_ALPHA_TEST); + LLGLDisable no_alpha; if (use_shaders) { gAlphaMaskProgram.setMinimumAlpha(0.000f); @@ -1456,7 +1453,7 @@ void LLTexLayer::renderMorphMasks(S32 x, S32 y, S32 width, S32 height, const LLC // Note: if the first param is a mulitply, multiply against the current buffer's alpha if( !first_param || !first_param->getMultiplyBlend() ) { - LLGLDisable no_alpha(GL_ALPHA_TEST); + LLGLDisable no_alpha; gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); // Clear the alpha @@ -1528,7 +1525,7 @@ void LLTexLayer::renderMorphMasks(S32 x, S32 y, S32 width, S32 height, const LLC // Note: we're still using gGL.blendFunc( GL_DST_ALPHA, GL_ZERO ); if ( !is_approx_equal(layer_color.mV[VW], 1.f) ) { - LLGLDisable no_alpha(GL_ALPHA_TEST); + LLGLDisable no_alpha; gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); gGL.color4fv(layer_color.mV); gl_rect_2d_simple( width, height ); @@ -1993,7 +1990,7 @@ LLGLTexture* LLTexLayerStaticImageList::getTexture(const std::string& file_name, image_raw->copyUnscaledAlphaMask(alpha_image_raw, LLColor4U::black); } - tex->createGLTexture(0, image_raw, 0, TRUE, LLGLTexture::LOCAL); + tex->createGLTexture(0, image_raw, LLImageGL::GLTextureName(), TRUE, LLGLTexture::LOCAL); gGL.getTexUnit(0)->bind(tex); tex->setAddressMode(LLTexUnit::TAM_CLAMP); diff --git a/indra/llappearance/lltexlayerparams.cpp b/indra/llappearance/lltexlayerparams.cpp index c7a02c76b..98dbd90fe 100644 --- a/indra/llappearance/lltexlayerparams.cpp +++ b/indra/llappearance/lltexlayerparams.cpp @@ -363,7 +363,7 @@ BOOL LLTexLayerParamAlpha::render(S32 x, S32 y, S32 width, S32 height) } else { - LLGLDisable no_alpha(GL_ALPHA_TEST); + LLGLDisable no_alpha; gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); gGL.color4f(0.f, 0.f, 0.f, effective_weight); gl_rect_2d_simple(width, height); diff --git a/indra/llrender/llcubemap.cpp b/indra/llrender/llcubemap.cpp index 395b2af02..bd5ddab15 100644 --- a/indra/llrender/llcubemap.cpp +++ b/indra/llrender/llcubemap.cpp @@ -80,9 +80,7 @@ void LLCubeMap::initGL() // Not initialized, do stuff. if (mImages[0].isNull()) { - U32 texname = 0; - - LLImageGL::generateTextures(1, &texname); + auto texname = LLImageGL::createTextureName(); for (int i = 0; i < 6; i++) { @@ -91,7 +89,7 @@ void LLCubeMap::initGL() mRawImages[i] = new LLImageRaw(64, 64, 4); mImages[i]->createGLTexture(0, mRawImages[i], texname); - gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_CUBE_MAP, texname); + gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_CUBE_MAP, texname->getTexName()); mImages[i]->setAddressMode(LLTexUnit::TAM_CLAMP); stop_glerror(); } @@ -169,7 +167,7 @@ void LLCubeMap::init(const std::vector >& rawimages) } } -GLuint LLCubeMap::getGLName() +GLuint LLCubeMap::getTexName() { return mImages[0]->getTexName(); } @@ -301,7 +299,7 @@ void LLCubeMap::restoreMatrix() void LLCubeMap::setReflection (void) { - gGL.getTexUnit(mTextureStage)->bindManual(LLTexUnit::TT_CUBE_MAP, getGLName()); + gGL.getTexUnit(mTextureStage)->bindManual(LLTexUnit::TT_CUBE_MAP, getTexName()); mImages[0]->setFilteringOption(LLTexUnit::TFO_ANISOTROPIC); mImages[0]->setAddressMode(LLTexUnit::TAM_CLAMP); } diff --git a/indra/llrender/llcubemap.h b/indra/llrender/llcubemap.h index ee2c41e02..78975f216 100644 --- a/indra/llrender/llcubemap.h +++ b/indra/llrender/llcubemap.h @@ -59,7 +59,7 @@ public: void finishPaint(); - GLuint getGLName(); + GLuint getTexName(); LLVector3 map(U8 side, U16 v_val, U16 h_val) const; BOOL project(F32& v_val, F32& h_val, BOOL& outside, diff --git a/indra/llrender/llgl.cpp b/indra/llrender/llgl.cpp index 012630f22..ef56c507c 100644 --- a/indra/llrender/llgl.cpp +++ b/indra/llrender/llgl.cpp @@ -72,6 +72,12 @@ void* gl_get_proc_address(const char *pStr) } #undef GLH_EXT_GET_PROC_ADDRESS #define GLH_EXT_GET_PROC_ADDRESS(p) gl_get_proc_address(p) +#undef GLH_EXT_GET_PROC_ADDRESS_CORE +#define GLH_EXT_GET_PROC_ADDRESS_CORE(ver, p) gl_get_proc_address((mGLVersion >= ver) ? p : p##"ARB") +#undef GLH_EXT_GET_PROC_ADDRESS_CORE_EXT +#define GLH_EXT_GET_PROC_ADDRESS_CORE_EXT(ver, p) gl_get_proc_address((mGLVersion >= ver) ? p : p##"EXT") +#undef GLH_EXT_GET_PROC_ADDRESS_CORE_OR_ARB +#define GLH_EXT_GET_PROC_ADDRESS_CORE_OR_ARB(ver, p, arb) gl_get_proc_address((mGLVersion >= ver) ? p : arb) #endif //!LL_DARWIN #if GL_ARB_debug_output @@ -96,6 +102,7 @@ void APIENTRY gl_debug_callback(GLenum source, { LL_WARNS() << "----- GL WARNING -------" << LL_ENDL; } + LL_WARNS() << "Source: " << std::hex << source << std::dec << LL_ENDL; LL_WARNS() << "Type: " << std::hex << type << std::dec << LL_ENDL; LL_WARNS() << "ID: " << std::hex << id << std::dec<< LL_ENDL; LL_WARNS() << "Severity: " << std::hex << severity << std::dec << LL_ENDL; @@ -276,7 +283,8 @@ PFNGLBLENDFUNCSEPARATEEXTPROC glBlendFuncSeparateEXT = NULL; PFNGLDRAWBUFFERSARBPROC glDrawBuffersARB = NULL; //shader object prototypes -PFNGLDELETEOBJECTARBPROC glDeleteObjectARB = NULL; +PFNGLDELETEOBJECTARBPROC glDeleteShader = NULL; +PFNGLDELETEOBJECTARBPROC glDeleteProgram = NULL; PFNGLGETHANDLEARBPROC glGetHandleARB = NULL; PFNGLDETACHOBJECTARBPROC glDetachObjectARB = NULL; PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB = NULL; @@ -307,9 +315,10 @@ PFNGLUNIFORMMATRIX2FVARBPROC glUniformMatrix2fvARB = NULL; PFNGLUNIFORMMATRIX3FVARBPROC glUniformMatrix3fvARB = NULL; PFNGLUNIFORMMATRIX3X4FVPROC glUniformMatrix3x4fv = NULL; PFNGLUNIFORMMATRIX4FVARBPROC glUniformMatrix4fvARB = NULL; -PFNGLGETOBJECTPARAMETERFVARBPROC glGetObjectParameterfvARB = NULL; -PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB = NULL; -PFNGLGETINFOLOGARBPROC glGetInfoLogARB = NULL; +PFNGLGETOBJECTPARAMETERIVARBPROC glGetShaderiv = NULL; +PFNGLGETOBJECTPARAMETERIVARBPROC glGetProgramiv = NULL; +PFNGLGETINFOLOGARBPROC glGetShaderInfoLog = NULL; +PFNGLGETINFOLOGARBPROC glGetProgramInfoLog = NULL; PFNGLGETATTACHEDOBJECTSARBPROC glGetAttachedObjectsARB = NULL; PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB = NULL; PFNGLGETACTIVEUNIFORMARBPROC glGetActiveUniformARB = NULL; @@ -435,7 +444,6 @@ LLGLManager::LLGLManager() : mHasOcclusionQuery2(FALSE), mHasPointParameters(FALSE), mHasDrawBuffers(FALSE), - mHasTextureRectangle(FALSE), mHasTransformFeedback(FALSE), mMaxIntegerSamples(0), @@ -462,8 +470,6 @@ LLGLManager::LLGLManager() : #endif mHasRequirements(TRUE), - mHasSeparateSpecularColor(FALSE), - mDebugGPU(FALSE), mDriverVersionMajor(1), @@ -742,6 +748,7 @@ bool LLGLManager::initGL() if (LLRender::sGLCoreProfile) { + // If core is true, then mNumTextureUnits is pretty much unused. mNumTextureUnits = llmin(mNumTextureImageUnits, MAX_GL_TEXTURE_UNITS); } else if (mHasMultitexture) @@ -776,8 +783,10 @@ bool LLGLManager::initGL() #if LL_WINDOWS if (mHasDebugOutput && gDebugGL) { //setup debug output callback + glEnable(GL_DEBUG_OUTPUT); glDebugMessageCallbackARB((GLDEBUGPROCARB) gl_debug_callback, NULL); glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB); + glDebugMessageControlARB(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, true); } #endif stop_glerror(); @@ -929,7 +938,6 @@ void LLGLManager::initExtensions() mHasBlendFuncSeparate = FALSE; # endif // GL_EXT_blend_func_separate mHasMipMapGeneration = FALSE; - mHasSeparateSpecularColor = FALSE; mHasAnisotropic = FALSE; mHasCubeMap = FALSE; mHasOcclusionQuery = FALSE; @@ -937,7 +945,6 @@ void LLGLManager::initExtensions() mHasShaderObjects = FALSE; mHasVertexShader = FALSE; mHasFragmentShader = FALSE; - mHasTextureRectangle = FALSE; #ifdef GL_ARB_gpu_shader5 mHasGpuShader5 = FALSE; #endif @@ -945,48 +952,46 @@ void LLGLManager::initExtensions() mHasMultitexture = glh_init_extensions("GL_ARB_multitexture"); mHasATIMemInfo = ExtensionExists("GL_ATI_meminfo", gGLHExts.mSysExts); mHasNVXMemInfo = ExtensionExists("GL_NVX_gpu_memory_info", gGLHExts.mSysExts); - mHasSeparateSpecularColor = glh_init_extensions("GL_EXT_separate_specular_color"); mHasAnisotropic = glh_init_extensions("GL_EXT_texture_filter_anisotropic"); glh_init_extensions("GL_ARB_texture_cube_map"); - mHasCubeMap = ExtensionExists("GL_ARB_texture_cube_map", gGLHExts.mSysExts); + mHasCubeMap = mGLVersion >= 1.3f || ExtensionExists("GL_ARB_texture_cube_map", gGLHExts.mSysExts); mHasARBEnvCombine = ExtensionExists("GL_ARB_texture_env_combine", gGLHExts.mSysExts); - mHasCompressedTextures = glh_init_extensions("GL_ARB_texture_compression"); - mHasOcclusionQuery = ExtensionExists("GL_ARB_occlusion_query", gGLHExts.mSysExts); - mHasOcclusionQuery2 = ExtensionExists("GL_ARB_occlusion_query2", gGLHExts.mSysExts); - mHasVertexBufferObject = ExtensionExists("GL_ARB_vertex_buffer_object", gGLHExts.mSysExts); - mHasVertexArrayObject = ExtensionExists("GL_ARB_vertex_array_object", gGLHExts.mSysExts); - mHasSync = ExtensionExists("GL_ARB_sync", gGLHExts.mSysExts); - mHasMapBufferRange = ExtensionExists("GL_ARB_map_buffer_range", gGLHExts.mSysExts); + mHasCompressedTextures = mGLVersion >= 1.3f || glh_init_extensions("GL_ARB_texture_compression"); + mHasOcclusionQuery = mGLVersion >= 1.5f || ExtensionExists("GL_ARB_occlusion_query", gGLHExts.mSysExts); + mHasOcclusionQuery2 = mGLVersion >= 3.3f || ExtensionExists("GL_ARB_occlusion_query2", gGLHExts.mSysExts); + mHasVertexBufferObject = mGLVersion >= 1.5f || ExtensionExists("GL_ARB_vertex_buffer_object", gGLHExts.mSysExts); + mHasVertexArrayObject = mGLVersion >= 3.f || ExtensionExists("GL_ARB_vertex_array_object", gGLHExts.mSysExts); + mHasSync = mGLVersion >= 3.2f || ExtensionExists("GL_ARB_sync", gGLHExts.mSysExts); + mHasMapBufferRange = mGLVersion >= 3.f || ExtensionExists("GL_ARB_map_buffer_range", gGLHExts.mSysExts); mHasFlushBufferRange = ExtensionExists("GL_APPLE_flush_buffer_range", gGLHExts.mSysExts); - mHasDepthClamp = ExtensionExists("GL_ARB_depth_clamp", gGLHExts.mSysExts) || ExtensionExists("GL_NV_depth_clamp", gGLHExts.mSysExts); + mHasDepthClamp = mGLVersion >= 3.2f || ExtensionExists("GL_ARB_depth_clamp", gGLHExts.mSysExts) || ExtensionExists("GL_NV_depth_clamp", gGLHExts.mSysExts); // mask out FBO support when packed_depth_stencil isn't there 'cause we need it for LLRenderTarget -Brad #ifdef GL_ARB_framebuffer_object - mHasFramebufferObject = ExtensionExists("GL_ARB_framebuffer_object", gGLHExts.mSysExts); + mHasFramebufferObject = mGLVersion >= 3.f || ExtensionExists("GL_ARB_framebuffer_object", gGLHExts.mSysExts); #else - mHasFramebufferObject = ExtensionExists("GL_EXT_framebuffer_object", gGLHExts.mSysExts) && + mHasFramebufferObject = mGLVersion >= 3.f || (ExtensionExists("GL_EXT_framebuffer_object", gGLHExts.mSysExts) && ExtensionExists("GL_EXT_framebuffer_blit", gGLHExts.mSysExts) && ExtensionExists("GL_EXT_framebuffer_multisample", gGLHExts.mSysExts) && - ExtensionExists("GL_EXT_packed_depth_stencil", gGLHExts.mSysExts); + ExtensionExists("GL_EXT_packed_depth_stencil", gGLHExts.mSysExts)); #endif - mHasFramebufferMultisample = mHasFramebufferObject && ExtensionExists("GL_EXT_framebuffer_multisample", gGLHExts.mSysExts); + mHasFramebufferMultisample = mGLVersion >= 3.f || (mHasFramebufferObject && ExtensionExists("GL_EXT_framebuffer_multisample", gGLHExts.mSysExts)); mHasMipMapGeneration = mHasFramebufferObject || mGLVersion >= 1.4f; - mHasDrawBuffers = ExtensionExists("GL_ARB_draw_buffers", gGLHExts.mSysExts); - mHasBlendFuncSeparate = ExtensionExists("GL_EXT_blend_func_separate", gGLHExts.mSysExts); - mHasTextureRectangle = ExtensionExists("GL_ARB_texture_rectangle", gGLHExts.mSysExts); - mHasDebugOutput = ExtensionExists("GL_ARB_debug_output", gGLHExts.mSysExts); + mHasDrawBuffers = mGLVersion >= 2.f || ExtensionExists("GL_ARB_draw_buffers", gGLHExts.mSysExts); + mHasBlendFuncSeparate = mGLVersion >= 1.4f || ExtensionExists("GL_EXT_blend_func_separate", gGLHExts.mSysExts); + mHasDebugOutput = mGLVersion >= 4.3f || ExtensionExists("GL_ARB_debug_output", gGLHExts.mSysExts); mHasTransformFeedback = mGLVersion >= 4.f || ExtensionExists("GL_EXT_transform_feedback", gGLHExts.mSysExts); #if !LL_DARWIN - mHasPointParameters = !mIsATI && ExtensionExists("GL_ARB_point_parameters", gGLHExts.mSysExts); + mHasPointParameters = mGLVersion >= 2.f || (!mIsATI && ExtensionExists("GL_ARB_point_parameters", gGLHExts.mSysExts)); #endif - mHasShaderObjects = ExtensionExists("GL_ARB_shader_objects", gGLHExts.mSysExts) && (LLRender::sGLCoreProfile || ExtensionExists("GL_ARB_shading_language_100", gGLHExts.mSysExts)); - mHasVertexShader = ExtensionExists("GL_ARB_vertex_program", gGLHExts.mSysExts) && ExtensionExists("GL_ARB_vertex_shader", gGLHExts.mSysExts) - && (LLRender::sGLCoreProfile || ExtensionExists("GL_ARB_shading_language_100", gGLHExts.mSysExts)); - mHasFragmentShader = ExtensionExists("GL_ARB_fragment_shader", gGLHExts.mSysExts) && (LLRender::sGLCoreProfile || ExtensionExists("GL_ARB_shading_language_100", gGLHExts.mSysExts)); + mHasShaderObjects = mGLVersion >= 2.f || ExtensionExists("GL_ARB_shader_objects", gGLHExts.mSysExts) && (LLRender::sGLCoreProfile || ExtensionExists("GL_ARB_shading_language_100", gGLHExts.mSysExts)); + mHasVertexShader = mGLVersion >= 2.f || (ExtensionExists("GL_ARB_vertex_program", gGLHExts.mSysExts) && ExtensionExists("GL_ARB_vertex_shader", gGLHExts.mSysExts) + && (LLRender::sGLCoreProfile || ExtensionExists("GL_ARB_shading_language_100", gGLHExts.mSysExts))); + mHasFragmentShader = mGLVersion >= 2.f || ExtensionExists("GL_ARB_fragment_shader", gGLHExts.mSysExts) && (LLRender::sGLCoreProfile || ExtensionExists("GL_ARB_shading_language_100", gGLHExts.mSysExts)); #endif #ifdef GL_ARB_gpu_shader5 - mHasGpuShader5 = ExtensionExists("GL_ARB_gpu_shader5", gGLHExts.mSysExts);; + mHasGpuShader5 = mGLVersion >= 4.f || ExtensionExists("GL_ARB_gpu_shader5", gGLHExts.mSysExts);; #endif #if LL_WINDOWS mHasAdaptiveVsync = ExtensionExists("WGL_EXT_swap_control_tear", gGLHExts.mSysExts); @@ -995,7 +1000,7 @@ void LLGLManager::initExtensions() #endif #ifdef GL_ARB_texture_swizzle - mHasTextureSwizzle = ExtensionExists("GL_ARB_texture_swizzle", gGLHExts.mSysExts); + mHasTextureSwizzle = mGLVersion >= 3.3f || ExtensionExists("GL_ARB_texture_swizzle", gGLHExts.mSysExts); #endif #if LL_LINUX || LL_SOLARIS @@ -1014,7 +1019,6 @@ void LLGLManager::initExtensions() mHasDrawBuffers = FALSE; mHasBlendFuncSeparate = FALSE; mHasMipMapGeneration = FALSE; - mHasSeparateSpecularColor = FALSE; mHasAnisotropic = FALSE; mHasCubeMap = FALSE; mHasOcclusionQuery = FALSE; @@ -1055,7 +1059,6 @@ void LLGLManager::initExtensions() if (strchr(blacklist,'d')) mHasMipMapGeneration = FALSE;//S // if (strchr(blacklist,'f')) mHasNVVertexArrayRange = FALSE;//S // if (strchr(blacklist,'g')) mHasNVFence = FALSE;//S - if (strchr(blacklist,'h')) mHasSeparateSpecularColor = FALSE; if (strchr(blacklist,'i')) mHasAnisotropic = FALSE;//S if (strchr(blacklist,'j')) mHasCubeMap = FALSE;//S // if (strchr(blacklist,'k')) mHasATIVAO = FALSE;//S @@ -1067,7 +1070,6 @@ void LLGLManager::initExtensions() if (strchr(blacklist,'q')) mHasFramebufferObject = FALSE;//S if (strchr(blacklist,'r')) mHasDrawBuffers = FALSE;//S if (strchr(blacklist,'s')) mHasFramebufferMultisample = FALSE; - if (strchr(blacklist,'t')) mHasTextureRectangle = FALSE; if (strchr(blacklist,'u')) mHasBlendFuncSeparate = FALSE;//S if (strchr(blacklist,'v')) mHasDepthClamp = FALSE; @@ -1086,10 +1088,6 @@ void LLGLManager::initExtensions() { LL_INFOS("RenderInit") << "Couldn't initialize GL_ARB_texture_env_combine" << LL_ENDL; } - if (!mHasSeparateSpecularColor) - { - LL_INFOS("RenderInit") << "Couldn't initialize separate specular color" << LL_ENDL; - } if (!mHasAnisotropic) { LL_INFOS("RenderInit") << "Couldn't initialize anisotropic filtering" << LL_ENDL; @@ -1153,19 +1151,19 @@ void LLGLManager::initExtensions() LL_DEBUGS("RenderInit") << "GL Probe: Getting symbols" << LL_ENDL; if (mHasVertexBufferObject) { - glBindBufferARB = (PFNGLBINDBUFFERARBPROC)GLH_EXT_GET_PROC_ADDRESS("glBindBufferARB"); + glBindBufferARB = (PFNGLBINDBUFFERARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(1.5, "glBindBuffer"); if (glBindBufferARB) { - glDeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC)GLH_EXT_GET_PROC_ADDRESS("glDeleteBuffersARB"); - glGenBuffersARB = (PFNGLGENBUFFERSARBPROC)GLH_EXT_GET_PROC_ADDRESS("glGenBuffersARB"); - glIsBufferARB = (PFNGLISBUFFERARBPROC)GLH_EXT_GET_PROC_ADDRESS("glIsBufferARB"); - glBufferDataARB = (PFNGLBUFFERDATAARBPROC)GLH_EXT_GET_PROC_ADDRESS("glBufferDataARB"); - glBufferSubDataARB = (PFNGLBUFFERSUBDATAARBPROC)GLH_EXT_GET_PROC_ADDRESS("glBufferSubDataARB"); - glGetBufferSubDataARB = (PFNGLGETBUFFERSUBDATAARBPROC)GLH_EXT_GET_PROC_ADDRESS("glGetBufferSubDataARB"); - glMapBufferARB = (PFNGLMAPBUFFERARBPROC)GLH_EXT_GET_PROC_ADDRESS("glMapBufferARB"); - glUnmapBufferARB = (PFNGLUNMAPBUFFERARBPROC)GLH_EXT_GET_PROC_ADDRESS("glUnmapBufferARB"); - glGetBufferParameterivARB = (PFNGLGETBUFFERPARAMETERIVARBPROC)GLH_EXT_GET_PROC_ADDRESS("glGetBufferParameterivARB"); - glGetBufferPointervARB = (PFNGLGETBUFFERPOINTERVARBPROC)GLH_EXT_GET_PROC_ADDRESS("glGetBufferPointervARB"); + glDeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(1.5, "glDeleteBuffers"); + glGenBuffersARB = (PFNGLGENBUFFERSARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(1.5, "glGenBuffers"); + glIsBufferARB = (PFNGLISBUFFERARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(1.5, "glIsBuffer"); + glBufferDataARB = (PFNGLBUFFERDATAARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(1.5, "glBufferData"); + glBufferSubDataARB = (PFNGLBUFFERSUBDATAARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(1.5, "glBufferSubData"); + glGetBufferSubDataARB = (PFNGLGETBUFFERSUBDATAARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(1.5, "glGetBufferSubData"); + glMapBufferARB = (PFNGLMAPBUFFERARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(1.5, "glMapBuffer"); + glUnmapBufferARB = (PFNGLUNMAPBUFFERARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(1.5, "glUnmapBuffer"); + glGetBufferParameterivARB = (PFNGLGETBUFFERPARAMETERIVARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(1.5, "glGetBufferParameteriv"); + glGetBufferPointervARB = (PFNGLGETBUFFERPOINTERVARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(1.5, "glGetBufferPointerv"); } else { @@ -1220,25 +1218,25 @@ void LLGLManager::initExtensions() } if (mHasDrawBuffers) { - glDrawBuffersARB = (PFNGLDRAWBUFFERSARBPROC) GLH_EXT_GET_PROC_ADDRESS("glDrawBuffersARB"); + glDrawBuffersARB = (PFNGLDRAWBUFFERSARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glDrawBuffers"); } if (mHasBlendFuncSeparate) { - glBlendFuncSeparateEXT = (PFNGLBLENDFUNCSEPARATEEXTPROC) GLH_EXT_GET_PROC_ADDRESS("glBlendFuncSeparateEXT"); + glBlendFuncSeparateEXT = (PFNGLBLENDFUNCSEPARATEEXTPROC)GLH_EXT_GET_PROC_ADDRESS_CORE_EXT(1.4, "glBlendFuncSeparate"); } if (mHasTransformFeedback) { - glBeginTransformFeedback = (PFNGLBEGINTRANSFORMFEEDBACKPROC) GLH_EXT_GET_PROC_ADDRESS("glBeginTransformFeedback"); - glEndTransformFeedback = (PFNGLENDTRANSFORMFEEDBACKPROC) GLH_EXT_GET_PROC_ADDRESS("glEndTransformFeedback"); - glTransformFeedbackVaryings = (PFNGLTRANSFORMFEEDBACKVARYINGSPROC) GLH_EXT_GET_PROC_ADDRESS("glTransformFeedbackVaryings"); - glBindBufferRange = (PFNGLBINDBUFFERRANGEPROC) GLH_EXT_GET_PROC_ADDRESS("glBindBufferRange"); + glBeginTransformFeedback = (PFNGLBEGINTRANSFORMFEEDBACKPROC)GLH_EXT_GET_PROC_ADDRESS_CORE_EXT(4.0, "glBeginTransformFeedback"); + glEndTransformFeedback = (PFNGLENDTRANSFORMFEEDBACKPROC)GLH_EXT_GET_PROC_ADDRESS_CORE_EXT(4.0, "glEndTransformFeedback"); + glTransformFeedbackVaryings = (PFNGLTRANSFORMFEEDBACKVARYINGSPROC)GLH_EXT_GET_PROC_ADDRESS_CORE_EXT(4.0, "glTransformFeedbackVaryings"); + glBindBufferRange = (PFNGLBINDBUFFERRANGEPROC)GLH_EXT_GET_PROC_ADDRESS_CORE_EXT(3.0, "glBindBufferRange"); } if (mHasDebugOutput) { - glDebugMessageControlARB = (PFNGLDEBUGMESSAGECONTROLARBPROC) GLH_EXT_GET_PROC_ADDRESS("glDebugMessageControlARB"); - glDebugMessageInsertARB = (PFNGLDEBUGMESSAGEINSERTARBPROC) GLH_EXT_GET_PROC_ADDRESS("glDebugMessageInsertARB"); - glDebugMessageCallbackARB = (PFNGLDEBUGMESSAGECALLBACKARBPROC) GLH_EXT_GET_PROC_ADDRESS("glDebugMessageCallbackARB"); - glGetDebugMessageLogARB = (PFNGLGETDEBUGMESSAGELOGARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetDebugMessageLogARB"); + glDebugMessageControlARB = (PFNGLDEBUGMESSAGECONTROLARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(4.3, "glDebugMessageControl"); + glDebugMessageInsertARB = (PFNGLDEBUGMESSAGEINSERTARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(4.3, "glDebugMessageInsert"); + glDebugMessageCallbackARB = (PFNGLDEBUGMESSAGECALLBACKARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(4.3, "glDebugMessageCallback"); + glGetDebugMessageLogARB = (PFNGLGETDEBUGMESSAGELOGARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(4.3, "glGetDebugMessageLog"); } #if (!LL_LINUX && !LL_SOLARIS) || LL_LINUX_NV_GL_HEADERS // This is expected to be a static symbol on Linux GL implementations, except if we use the nvidia headers - bah @@ -1258,114 +1256,117 @@ void LLGLManager::initExtensions() if (mHasOcclusionQuery) { LL_INFOS() << "initExtensions() OcclusionQuery-related procs..." << LL_ENDL; - glGenQueriesARB = (PFNGLGENQUERIESARBPROC)GLH_EXT_GET_PROC_ADDRESS("glGenQueriesARB"); - glDeleteQueriesARB = (PFNGLDELETEQUERIESARBPROC)GLH_EXT_GET_PROC_ADDRESS("glDeleteQueriesARB"); - glIsQueryARB = (PFNGLISQUERYARBPROC)GLH_EXT_GET_PROC_ADDRESS("glIsQueryARB"); - glBeginQueryARB = (PFNGLBEGINQUERYARBPROC)GLH_EXT_GET_PROC_ADDRESS("glBeginQueryARB"); - glEndQueryARB = (PFNGLENDQUERYARBPROC)GLH_EXT_GET_PROC_ADDRESS("glEndQueryARB"); - glGetQueryivARB = (PFNGLGETQUERYIVARBPROC)GLH_EXT_GET_PROC_ADDRESS("glGetQueryivARB"); - glGetQueryObjectivARB = (PFNGLGETQUERYOBJECTIVARBPROC)GLH_EXT_GET_PROC_ADDRESS("glGetQueryObjectivARB"); - glGetQueryObjectuivARB = (PFNGLGETQUERYOBJECTUIVARBPROC)GLH_EXT_GET_PROC_ADDRESS("glGetQueryObjectuivARB"); + glGenQueriesARB = (PFNGLGENQUERIESARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(1.4, "glGenQueries"); + glDeleteQueriesARB = (PFNGLDELETEQUERIESARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(1.4, "glDeleteQueries"); + glIsQueryARB = (PFNGLISQUERYARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(1.4, "glIsQuery"); + glBeginQueryARB = (PFNGLBEGINQUERYARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(1.4, "glBeginQuery"); + glEndQueryARB = (PFNGLENDQUERYARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(1.4, "glEndQuery"); + glGetQueryivARB = (PFNGLGETQUERYIVARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(1.4, "glGetQueryiv"); + glGetQueryObjectivARB = (PFNGLGETQUERYOBJECTIVARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(1.4, "glGetQueryObjectiv"); + glGetQueryObjectuivARB = (PFNGLGETQUERYOBJECTUIVARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(1.4, "glGetQueryObjectuiv"); } #if !LL_DARWIN - glGetQueryObjectui64vEXT = (PFNGLGETQUERYOBJECTUI64VEXTPROC)GLH_EXT_GET_PROC_ADDRESS("glGetQueryObjectui64vEXT"); + glGetQueryObjectui64vEXT = (PFNGLGETQUERYOBJECTUI64VEXTPROC)GLH_EXT_GET_PROC_ADDRESS_CORE_EXT(3.2, "glGetQueryObjectui64v"); #endif if (mHasPointParameters) { LL_INFOS() << "initExtensions() PointParameters-related procs..." << LL_ENDL; - glPointParameterfARB = (PFNGLPOINTPARAMETERFARBPROC)GLH_EXT_GET_PROC_ADDRESS("glPointParameterfARB"); - glPointParameterfvARB = (PFNGLPOINTPARAMETERFVARBPROC)GLH_EXT_GET_PROC_ADDRESS("glPointParameterfvARB"); + glPointParameterfARB = (PFNGLPOINTPARAMETERFARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glPointParameterf"); + glPointParameterfvARB = (PFNGLPOINTPARAMETERFVARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glPointParameterfv"); } if (mHasShaderObjects) { - glDeleteObjectARB = (PFNGLDELETEOBJECTARBPROC) GLH_EXT_GET_PROC_ADDRESS("glDeleteObjectARB"); - glGetHandleARB = (PFNGLGETHANDLEARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetHandleARB"); - glDetachObjectARB = (PFNGLDETACHOBJECTARBPROC) GLH_EXT_GET_PROC_ADDRESS("glDetachObjectARB"); - glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC) GLH_EXT_GET_PROC_ADDRESS("glCreateShaderObjectARB"); - glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC) GLH_EXT_GET_PROC_ADDRESS("glShaderSourceARB"); - glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC) GLH_EXT_GET_PROC_ADDRESS("glCompileShaderARB"); - glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC) GLH_EXT_GET_PROC_ADDRESS("glCreateProgramObjectARB"); - glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC) GLH_EXT_GET_PROC_ADDRESS("glAttachObjectARB"); - glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC) GLH_EXT_GET_PROC_ADDRESS("glLinkProgramARB"); - glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUseProgramObjectARB"); - glValidateProgramARB = (PFNGLVALIDATEPROGRAMARBPROC) GLH_EXT_GET_PROC_ADDRESS("glValidateProgramARB"); - glUniform1fARB = (PFNGLUNIFORM1FARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform1fARB"); - glUniform2fARB = (PFNGLUNIFORM2FARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform2fARB"); - glUniform3fARB = (PFNGLUNIFORM3FARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform3fARB"); - glUniform4fARB = (PFNGLUNIFORM4FARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform4fARB"); - glUniform1iARB = (PFNGLUNIFORM1IARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform1iARB"); - glUniform2iARB = (PFNGLUNIFORM2IARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform2iARB"); - glUniform3iARB = (PFNGLUNIFORM3IARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform3iARB"); - glUniform4iARB = (PFNGLUNIFORM4IARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform4iARB"); - glUniform1fvARB = (PFNGLUNIFORM1FVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform1fvARB"); - glUniform2fvARB = (PFNGLUNIFORM2FVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform2fvARB"); - glUniform3fvARB = (PFNGLUNIFORM3FVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform3fvARB"); - glUniform4fvARB = (PFNGLUNIFORM4FVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform4fvARB"); - glUniform1ivARB = (PFNGLUNIFORM1IVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform1ivARB"); - glUniform2ivARB = (PFNGLUNIFORM2IVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform2ivARB"); - glUniform3ivARB = (PFNGLUNIFORM3IVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform3ivARB"); - glUniform4ivARB = (PFNGLUNIFORM4IVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniform4ivARB"); - glUniformMatrix2fvARB = (PFNGLUNIFORMMATRIX2FVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniformMatrix2fvARB"); - glUniformMatrix3fvARB = (PFNGLUNIFORMMATRIX3FVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniformMatrix3fvARB"); - glUniformMatrix3x4fv = (PFNGLUNIFORMMATRIX3X4FVPROC) GLH_EXT_GET_PROC_ADDRESS("glUniformMatrix3x4fv"); - glUniformMatrix4fvARB = (PFNGLUNIFORMMATRIX4FVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glUniformMatrix4fvARB"); - glGetObjectParameterfvARB = (PFNGLGETOBJECTPARAMETERFVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetObjectParameterfvARB"); - glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetObjectParameterivARB"); - glGetInfoLogARB = (PFNGLGETINFOLOGARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetInfoLogARB"); - glGetAttachedObjectsARB = (PFNGLGETATTACHEDOBJECTSARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetAttachedObjectsARB"); - glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetUniformLocationARB"); - glGetActiveUniformARB = (PFNGLGETACTIVEUNIFORMARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetActiveUniformARB"); - glGetUniformfvARB = (PFNGLGETUNIFORMFVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetUniformfvARB"); - glGetUniformivARB = (PFNGLGETUNIFORMIVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetUniformivARB"); - glGetShaderSourceARB = (PFNGLGETSHADERSOURCEARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetShaderSourceARB"); + glDeleteShader = (PFNGLDELETEOBJECTARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE_OR_ARB(2.0, "glDeleteShader", "glDeleteObjectARB"); + glDeleteProgram = (PFNGLDELETEOBJECTARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE_OR_ARB(2.0, "glDeleteProgram", "glDeleteObjectARB"); + glGetHandleARB = (PFNGLGETHANDLEARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glGetHandle"); + glDetachObjectARB = (PFNGLDETACHOBJECTARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE_OR_ARB(2.0, "glDetachShader", "glDetachObjectARB"); + glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE_OR_ARB(2.0, "glCreateShader", "glCreateShaderObjectARB"); + glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glShaderSource"); + glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glCompileShader"); + glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE_OR_ARB(2.0, "glCreateProgram", "glCreateProgramObjectARB"); + glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE_OR_ARB(2.0, "glAttachShader", "glAttachObjectARB"); + glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glLinkProgram"); + glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE_OR_ARB(2.0, "glUseProgram", "glUseProgramObjectARB"); + glValidateProgramARB = (PFNGLVALIDATEPROGRAMARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glValidateProgram"); + glUniform1fARB = (PFNGLUNIFORM1FARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glUniform1f"); + glUniform2fARB = (PFNGLUNIFORM2FARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glUniform2f"); + glUniform3fARB = (PFNGLUNIFORM3FARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glUniform3f"); + glUniform4fARB = (PFNGLUNIFORM4FARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glUniform4f"); + glUniform1iARB = (PFNGLUNIFORM1IARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glUniform1i"); + glUniform2iARB = (PFNGLUNIFORM2IARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glUniform2i"); + glUniform3iARB = (PFNGLUNIFORM3IARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glUniform3i"); + glUniform4iARB = (PFNGLUNIFORM4IARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glUniform4i"); + glUniform1fvARB = (PFNGLUNIFORM1FVARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glUniform1fv"); + glUniform2fvARB = (PFNGLUNIFORM2FVARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glUniform2fv"); + glUniform3fvARB = (PFNGLUNIFORM3FVARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glUniform3fv"); + glUniform4fvARB = (PFNGLUNIFORM4FVARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glUniform4fv"); + glUniform1ivARB = (PFNGLUNIFORM1IVARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glUniform1iv"); + glUniform2ivARB = (PFNGLUNIFORM2IVARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glUniform2iv"); + glUniform3ivARB = (PFNGLUNIFORM3IVARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glUniform3iv"); + glUniform4ivARB = (PFNGLUNIFORM4IVARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glUniform4iv"); + glUniformMatrix2fvARB = (PFNGLUNIFORMMATRIX2FVARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glUniformMatrix2fv"); + glUniformMatrix3fvARB = (PFNGLUNIFORMMATRIX3FVARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glUniformMatrix3fv"); + glUniformMatrix3x4fv = (PFNGLUNIFORMMATRIX3X4FVPROC) GLH_EXT_GET_PROC_ADDRESS_CORE(2.1, "glUniformMatrix3x4fv"); + glUniformMatrix4fvARB = (PFNGLUNIFORMMATRIX4FVARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glUniformMatrix4fv"); + glGetShaderiv = (PFNGLGETOBJECTPARAMETERIVARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE_OR_ARB(2.0, "glGetShaderiv", "glGetObjectParameterivARB"); + glGetProgramiv = (PFNGLGETOBJECTPARAMETERIVARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE_OR_ARB(2.0, "glGetProgramiv", "glGetObjectParameterivARB"); + glGetShaderInfoLog = (PFNGLGETINFOLOGARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE_OR_ARB(2.0, "glGetShaderInfoLog", "glGetInfoLogARB"); + glGetProgramInfoLog = (PFNGLGETINFOLOGARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE_OR_ARB(2.0, "glGetProgramInfoLog", "glGetInfoLogARB"); + glGetAttachedObjectsARB = (PFNGLGETATTACHEDOBJECTSARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE_OR_ARB(2.0, "glGetAttachedShaders", "glGetAttachedObjectsARB"); + glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glGetUniformLocation"); + glGetActiveUniformARB = (PFNGLGETACTIVEUNIFORMARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glGetActiveUniform"); + glGetUniformfvARB = (PFNGLGETUNIFORMFVARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glGetUniformfv"); + glGetUniformivARB = (PFNGLGETUNIFORMIVARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glGetUniformiv"); + glGetShaderSourceARB = (PFNGLGETSHADERSOURCEARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glGetShaderSource"); } if (mHasVertexShader) { LL_INFOS() << "initExtensions() VertexShader-related procs..." << LL_ENDL; - glGetAttribLocationARB = (PFNGLGETATTRIBLOCATIONARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetAttribLocationARB"); - glBindAttribLocationARB = (PFNGLBINDATTRIBLOCATIONARBPROC) GLH_EXT_GET_PROC_ADDRESS("glBindAttribLocationARB"); - glGetActiveAttribARB = (PFNGLGETACTIVEATTRIBARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetActiveAttribARB"); - glVertexAttrib1dARB = (PFNGLVERTEXATTRIB1DARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib1dARB"); - glVertexAttrib1dvARB = (PFNGLVERTEXATTRIB1DVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib1dvARB"); - glVertexAttrib1fARB = (PFNGLVERTEXATTRIB1FARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib1fARB"); - glVertexAttrib1fvARB = (PFNGLVERTEXATTRIB1FVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib1fvARB"); - glVertexAttrib1sARB = (PFNGLVERTEXATTRIB1SARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib1sARB"); - glVertexAttrib1svARB = (PFNGLVERTEXATTRIB1SVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib1svARB"); - glVertexAttrib2dARB = (PFNGLVERTEXATTRIB2DARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib2dARB"); - glVertexAttrib2dvARB = (PFNGLVERTEXATTRIB2DVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib2dvARB"); - glVertexAttrib2fARB = (PFNGLVERTEXATTRIB2FARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib2fARB"); - glVertexAttrib2fvARB = (PFNGLVERTEXATTRIB2FVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib2fvARB"); - glVertexAttrib2sARB = (PFNGLVERTEXATTRIB2SARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib2sARB"); - glVertexAttrib2svARB = (PFNGLVERTEXATTRIB2SVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib2svARB"); - glVertexAttrib3dARB = (PFNGLVERTEXATTRIB3DARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib3dARB"); - glVertexAttrib3dvARB = (PFNGLVERTEXATTRIB3DVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib3dvARB"); - glVertexAttrib3fARB = (PFNGLVERTEXATTRIB3FARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib3fARB"); - glVertexAttrib3fvARB = (PFNGLVERTEXATTRIB3FVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib3fvARB"); - glVertexAttrib3sARB = (PFNGLVERTEXATTRIB3SARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib3sARB"); - glVertexAttrib3svARB = (PFNGLVERTEXATTRIB3SVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib3svARB"); - glVertexAttrib4nbvARB = (PFNGLVERTEXATTRIB4NBVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4nbvARB"); - glVertexAttrib4nivARB = (PFNGLVERTEXATTRIB4NIVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4nivARB"); - glVertexAttrib4nsvARB = (PFNGLVERTEXATTRIB4NSVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4nsvARB"); - glVertexAttrib4nubARB = (PFNGLVERTEXATTRIB4NUBARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4nubARB"); - glVertexAttrib4nubvARB = (PFNGLVERTEXATTRIB4NUBVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4nubvARB"); - glVertexAttrib4nuivARB = (PFNGLVERTEXATTRIB4NUIVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4nuivARB"); - glVertexAttrib4nusvARB = (PFNGLVERTEXATTRIB4NUSVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4nusvARB"); - glVertexAttrib4bvARB = (PFNGLVERTEXATTRIB4BVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4bvARB"); - glVertexAttrib4dARB = (PFNGLVERTEXATTRIB4DARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4dARB"); - glVertexAttrib4dvARB = (PFNGLVERTEXATTRIB4DVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4dvARB"); - glVertexAttrib4fARB = (PFNGLVERTEXATTRIB4FARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4fARB"); - glVertexAttrib4fvARB = (PFNGLVERTEXATTRIB4FVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4fvARB"); - glVertexAttrib4ivARB = (PFNGLVERTEXATTRIB4IVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4ivARB"); - glVertexAttrib4sARB = (PFNGLVERTEXATTRIB4SARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4sARB"); - glVertexAttrib4svARB = (PFNGLVERTEXATTRIB4SVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4svARB"); - glVertexAttrib4ubvARB = (PFNGLVERTEXATTRIB4UBVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4ubvARB"); - glVertexAttrib4uivARB = (PFNGLVERTEXATTRIB4UIVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4uivARB"); - glVertexAttrib4usvARB = (PFNGLVERTEXATTRIB4USVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttrib4usvARB"); - glVertexAttribPointerARB = (PFNGLVERTEXATTRIBPOINTERARBPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttribPointerARB"); - glVertexAttribIPointer = (PFNGLVERTEXATTRIBIPOINTERPROC) GLH_EXT_GET_PROC_ADDRESS("glVertexAttribIPointer"); - glEnableVertexAttribArrayARB = (PFNGLENABLEVERTEXATTRIBARRAYARBPROC) GLH_EXT_GET_PROC_ADDRESS("glEnableVertexAttribArrayARB"); - glDisableVertexAttribArrayARB = (PFNGLDISABLEVERTEXATTRIBARRAYARBPROC) GLH_EXT_GET_PROC_ADDRESS("glDisableVertexAttribArrayARB"); - glProgramStringARB = (PFNGLPROGRAMSTRINGARBPROC) GLH_EXT_GET_PROC_ADDRESS("glProgramStringARB"); + glGetAttribLocationARB = (PFNGLGETATTRIBLOCATIONARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glGetAttribLocation"); + glBindAttribLocationARB = (PFNGLBINDATTRIBLOCATIONARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glBindAttribLocation"); + glGetActiveAttribARB = (PFNGLGETACTIVEATTRIBARBPROC) GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glGetActiveAttrib"); + glVertexAttrib1dARB = (PFNGLVERTEXATTRIB1DARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glVertexAttrib1d"); + glVertexAttrib1dvARB = (PFNGLVERTEXATTRIB1DVARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glVertexAttrib1dv"); + glVertexAttrib1fARB = (PFNGLVERTEXATTRIB1FARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glVertexAttrib1f"); + glVertexAttrib1fvARB = (PFNGLVERTEXATTRIB1FVARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glVertexAttrib1fv"); + glVertexAttrib1sARB = (PFNGLVERTEXATTRIB1SARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glVertexAttrib1s"); + glVertexAttrib1svARB = (PFNGLVERTEXATTRIB1SVARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glVertexAttrib1sv"); + glVertexAttrib2dARB = (PFNGLVERTEXATTRIB2DARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glVertexAttrib2d"); + glVertexAttrib2dvARB = (PFNGLVERTEXATTRIB2DVARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glVertexAttrib2dv"); + glVertexAttrib2fARB = (PFNGLVERTEXATTRIB2FARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glVertexAttrib2f"); + glVertexAttrib2fvARB = (PFNGLVERTEXATTRIB2FVARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glVertexAttrib2fv"); + glVertexAttrib2sARB = (PFNGLVERTEXATTRIB2SARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glVertexAttrib2s"); + glVertexAttrib2svARB = (PFNGLVERTEXATTRIB2SVARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glVertexAttrib2sv"); + glVertexAttrib3dARB = (PFNGLVERTEXATTRIB3DARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glVertexAttrib3d"); + glVertexAttrib3dvARB = (PFNGLVERTEXATTRIB3DVARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glVertexAttrib3dv"); + glVertexAttrib3fARB = (PFNGLVERTEXATTRIB3FARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glVertexAttrib3f"); + glVertexAttrib3fvARB = (PFNGLVERTEXATTRIB3FVARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glVertexAttrib3fv"); + glVertexAttrib3sARB = (PFNGLVERTEXATTRIB3SARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glVertexAttrib3s"); + glVertexAttrib3svARB = (PFNGLVERTEXATTRIB3SVARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glVertexAttrib3sv"); + glVertexAttrib4nbvARB = (PFNGLVERTEXATTRIB4NBVARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glVertexAttrib4Nbv"); + glVertexAttrib4nivARB = (PFNGLVERTEXATTRIB4NIVARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glVertexAttrib4Niv"); + glVertexAttrib4nsvARB = (PFNGLVERTEXATTRIB4NSVARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glVertexAttrib4Nsv"); + glVertexAttrib4nubARB = (PFNGLVERTEXATTRIB4NUBARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glVertexAttrib4Nub"); + glVertexAttrib4nubvARB = (PFNGLVERTEXATTRIB4NUBVARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glVertexAttrib4Nubv"); + glVertexAttrib4nuivARB = (PFNGLVERTEXATTRIB4NUIVARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glVertexAttrib4Nuiv"); + glVertexAttrib4nusvARB = (PFNGLVERTEXATTRIB4NUSVARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glVertexAttrib4Nusv"); + glVertexAttrib4bvARB = (PFNGLVERTEXATTRIB4BVARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glVertexAttrib4bv"); + glVertexAttrib4dARB = (PFNGLVERTEXATTRIB4DARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glVertexAttrib4d"); + glVertexAttrib4dvARB = (PFNGLVERTEXATTRIB4DVARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glVertexAttrib4dv"); + glVertexAttrib4fARB = (PFNGLVERTEXATTRIB4FARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glVertexAttrib4f"); + glVertexAttrib4fvARB = (PFNGLVERTEXATTRIB4FVARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glVertexAttrib4fv"); + glVertexAttrib4ivARB = (PFNGLVERTEXATTRIB4IVARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glVertexAttrib4iv"); + glVertexAttrib4sARB = (PFNGLVERTEXATTRIB4SARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glVertexAttrib4s"); + glVertexAttrib4svARB = (PFNGLVERTEXATTRIB4SVARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glVertexAttrib4sv"); + glVertexAttrib4ubvARB = (PFNGLVERTEXATTRIB4UBVARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glVertexAttrib4ubv"); + glVertexAttrib4uivARB = (PFNGLVERTEXATTRIB4UIVARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glVertexAttrib4uiv"); + glVertexAttrib4usvARB = (PFNGLVERTEXATTRIB4USVARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glVertexAttrib4usv"); + glVertexAttribPointerARB = (PFNGLVERTEXATTRIBPOINTERARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glVertexAttribPointer"); + glVertexAttribIPointer = (PFNGLVERTEXATTRIBIPOINTERPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(3.0, "glVertexAttribIPointer"); + glEnableVertexAttribArrayARB = (PFNGLENABLEVERTEXATTRIBARRAYARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glEnableVertexAttribArray"); + glDisableVertexAttribArrayARB = (PFNGLDISABLEVERTEXATTRIBARRAYARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glDisableVertexAttribArray"); + // These are all related to defunct ARB assembly language. + /*glProgramStringARB = (PFNGLPROGRAMSTRINGARBPROC) GLH_EXT_GET_PROC_ADDRESS("glProgramStringARB"); glBindProgramARB = (PFNGLBINDPROGRAMARBPROC) GLH_EXT_GET_PROC_ADDRESS("glBindProgramARB"); glDeleteProgramsARB = (PFNGLDELETEPROGRAMSARBPROC) GLH_EXT_GET_PROC_ADDRESS("glDeleteProgramsARB"); glGenProgramsARB = (PFNGLGENPROGRAMSARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGenProgramsARB"); @@ -1382,12 +1383,12 @@ void LLGLManager::initExtensions() glGetProgramLocalParameterdvARB = (PFNGLGETPROGRAMLOCALPARAMETERDVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetProgramLocalParameterdvARB"); glGetProgramLocalParameterfvARB = (PFNGLGETPROGRAMLOCALPARAMETERFVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetProgramLocalParameterfvARB"); glGetProgramivARB = (PFNGLGETPROGRAMIVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetProgramivARB"); - glGetProgramStringARB = (PFNGLGETPROGRAMSTRINGARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetProgramStringARB"); - glGetVertexAttribdvARB = (PFNGLGETVERTEXATTRIBDVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetVertexAttribdvARB"); - glGetVertexAttribfvARB = (PFNGLGETVERTEXATTRIBFVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetVertexAttribfvARB"); - glGetVertexAttribivARB = (PFNGLGETVERTEXATTRIBIVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetVertexAttribivARB"); - glGetVertexAttribPointervARB = (PFNGLGETVERTEXATTRIBPOINTERVARBPROC) GLH_EXT_GET_PROC_ADDRESS("glgetVertexAttribPointervARB"); - glIsProgramARB = (PFNGLISPROGRAMARBPROC) GLH_EXT_GET_PROC_ADDRESS("glIsProgramARB"); + glGetProgramStringARB = (PFNGLGETPROGRAMSTRINGARBPROC) GLH_EXT_GET_PROC_ADDRESS("glGetProgramStringARB");*/ + glGetVertexAttribdvARB = (PFNGLGETVERTEXATTRIBDVARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glGetVertexAttribdv"); + glGetVertexAttribfvARB = (PFNGLGETVERTEXATTRIBFVARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glGetVertexAttribfv"); + glGetVertexAttribivARB = (PFNGLGETVERTEXATTRIBIVARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glGetVertexAttribiv"); + glGetVertexAttribPointervARB = (PFNGLGETVERTEXATTRIBPOINTERVARBPROC)GLH_EXT_GET_PROC_ADDRESS_CORE(2.0, "glGetVertexAttribPointerv"); + //glIsProgramARB = (PFNGLISPROGRAMARBPROC) GLH_EXT_GET_PROC_ADDRESS("glIsProgramARB"); } LL_DEBUGS("RenderInit") << "GL Probe: Got symbols" << LL_ENDL; #endif @@ -1530,33 +1531,49 @@ void clear_glerror() // // Static members -boost::unordered_map LLGLState::sStateMap; +std::vector LLGLStateValidator::sStateDataVec; GLboolean LLGLDepthTest::sDepthEnabled = GL_FALSE; // OpenGL default GLenum LLGLDepthTest::sDepthFunc = GL_LESS; // OpenGL default GLboolean LLGLDepthTest::sWriteEnabled = GL_TRUE; // OpenGL default //static -void LLGLState::initClass() +void LLGLStateValidator::initClass() { - sStateMap[GL_DITHER] = GL_TRUE; - // sStateMap[GL_TEXTURE_2D] = GL_TRUE; - + stop_glerror(); + + gGL.setSceneBlendType(LLRender::BT_ALPHA); //make sure multisample defaults to disabled - sStateMap[GL_MULTISAMPLE_ARB] = GL_FALSE; glDisable(GL_MULTISAMPLE_ARB); + stop_glerror(); + for (auto data : sStateDataVec) + { + llassert_always(data->depth == 0); + llassert_always(data->activeInstance == nullptr); + if (data->disabler && *data->disabler) + { + continue; + } + const char* stateStr = data->stateStr; + LLGLenum state = data->state; + LLGLboolean cur_state = data->currentState; + llassert_always_msg(cur_state == glIsEnabled(state), llformat("%s expected %s", stateStr, cur_state ? "TRUE" : "FALSE")); + } + const bool old = gDebugGL; + gDebugGL = true; + checkStates(); + gDebugGL = old; } //static -void LLGLState::restoreGL() +void LLGLStateValidator::restoreGL() { - sStateMap.clear(); initClass(); } //static // Really shouldn't be needed, but seems we sometimes do. -void LLGLState::resetTextureStates() +void LLGLStateValidator::resetTextureStates() { gGL.flush(); GLint maxTextureUnits; @@ -1570,35 +1587,60 @@ void LLGLState::resetTextureStates() } } -void LLGLState::dumpStates() +void LLGLStateValidator::dumpStates() { LL_INFOS("RenderState") << "GL States:" << LL_ENDL; - for (boost::unordered_map::iterator iter = sStateMap.begin(); - iter != sStateMap.end(); ++iter) + for (auto data : sStateDataVec) { - LL_INFOS("RenderState") << llformat(" 0x%04x : %s",(S32)iter->first,iter->second?"TRUE":"FALSE") << LL_ENDL; + LL_INFOS("RenderState") << llformat("%s : %s", data->stateStr, data->currentState ? "TRUE" : "FALSE") << LL_ENDL; } } -void LLGLState::checkStates(const std::string& msg) +void LLGLStateValidator::checkState(LLGLStateStaticData& data) { - if (!gDebugGL) + if (gDebugGL) + { + if (data.disabler && *data.disabler) + { + return; + } + if (!gDebugSession) + { + llassert_always(data.currentState == (bool)glIsEnabled(data.state)); + } + else + { + if (data.currentState != (bool)glIsEnabled(data.state)) + { + ll_fail(llformat("GL enabled state for %s does not match expected state of %s.", data.stateStr, data.currentState ? "TRUE" : "FALSE")); + } + } + } +} + +bool LLGLStateValidator::registerStateData(LLGLStateStaticData& data) +{ + sStateDataVec.emplace_back(&data); + return true; +} + +void LLGLStateValidator::checkStates(const std::string& msg) +{ + if (!gDebugGL || gGLManager.mIsDisabled) { return; } stop_glerror(); - GLint src; - GLint dst; - glGetIntegerv(GL_BLEND_SRC, &src); - glGetIntegerv(GL_BLEND_DST, &dst); + GLint src = gGL.getContextSnapshot().blendColorSFactor; + GLint dst = gGL.getContextSnapshot().blendColorDFactor; stop_glerror(); BOOL error = FALSE; - if (src != GL_SRC_ALPHA || dst != GL_ONE_MINUS_SRC_ALPHA) + if (src != LLRender::BF_SOURCE_ALPHA || dst != LLRender::BF_ONE_MINUS_SOURCE_ALPHA) { if (gDebugSession) { @@ -1611,11 +1653,15 @@ void LLGLState::checkStates(const std::string& msg) } } - for (boost::unordered_map::iterator iter = sStateMap.begin(); - iter != sStateMap.end(); ++iter) + for (auto data : sStateDataVec) { - LLGLenum state = iter->first; - LLGLboolean cur_state = iter->second; + if (data->disabler && *data->disabler) + { + continue; + } + const char* stateStr = data->stateStr; + LLGLenum state = data->state; + LLGLboolean cur_state = data->currentState; stop_glerror(); LLGLboolean gl_state = glIsEnabled(state); stop_glerror(); @@ -1624,24 +1670,24 @@ void LLGLState::checkStates(const std::string& msg) dumpStates(); if (gDebugSession) { - gFailLog << llformat("LLGLState error. State: 0x%04x",state) << std::endl; + gFailLog << llformat("LLGLState error. State: %s 0x%04x. Expected %s", stateStr, state, cur_state ? "TRUE" : "FALSE") << std::endl; error = TRUE; } else { - LL_GL_ERRS << llformat("LLGLState error. State: 0x%04x",state) << LL_ENDL; + LL_GL_ERRS << llformat("LLGLState error. State: %s 0x%04x. Expected %s", stateStr, state, cur_state ? "TRUE" : "FALSE") << LL_ENDL; } } } if (error) { - ll_fail("LLGLState::checkStates failed."); + ll_fail("LLGLStateValidator::checkStates failed."); } stop_glerror(); } -void LLGLState::checkTextureChannels(const std::string& msg) +void LLGLStateValidator::checkTextureChannels(const std::string& msg) { #if 0 if (!gDebugGL) @@ -1738,7 +1784,7 @@ void LLGLState::checkTextureChannels(const std::string& msg) for (S32 j = (i == 0 ? 1 : 0); - j < (gGLManager.mHasTextureRectangle ? 9 : 8); j++) + j < 8; j++) { if (glIsEnabled(value[j])) { @@ -1793,7 +1839,7 @@ void LLGLState::checkTextureChannels(const std::string& msg) { if (gDebugSession) { - ll_fail("LLGLState::checkTextureChannels failed."); + ll_fail("LLGLStateValidator::checkTextureChannels failed."); } else { @@ -1803,7 +1849,7 @@ void LLGLState::checkTextureChannels(const std::string& msg) #endif } -void LLGLState::checkClientArrays(const std::string& msg, U32 data_mask) +void LLGLStateValidator::checkClientArrays(const std::string& msg, U32 data_mask) { if (!gDebugGL || LLGLSLShader::sNoFixedFunction) { @@ -1969,7 +2015,7 @@ void LLGLState::checkClientArrays(const std::string& msg, U32 data_mask) { if (gDebugSession) { - ll_fail("LLGLState::checkClientArrays failed."); + ll_fail("LLGLStateValidator::checkClientArrays failed."); } else { @@ -1980,108 +2026,36 @@ void LLGLState::checkClientArrays(const std::string& msg, U32 data_mask) /////////////////////////////////////////////////////////////////////// -LLGLState::LLGLState(LLGLenum state, S32 enabled) : - mState(state), mWasEnabled(FALSE), mIsEnabled(FALSE) -{ - if (LLGLSLShader::sNoFixedFunction) - { //always ignore state that's deprecated post GL 3.0 - switch (state) - { - case GL_ALPHA_TEST: - case GL_NORMALIZE: - case GL_TEXTURE_GEN_R: - case GL_TEXTURE_GEN_S: - case GL_TEXTURE_GEN_T: - case GL_TEXTURE_GEN_Q: - case GL_LIGHTING: - case GL_COLOR_MATERIAL: - case GL_FOG: - case GL_LINE_STIPPLE: - case GL_POLYGON_STIPPLE: - mState = 0; - break; - } - } - - stop_glerror(); - if (mState) - { - mWasEnabled = sStateMap[state]; - llassert(mWasEnabled == glIsEnabled(state)); - setEnabled(enabled); - stop_glerror(); - } -} - -void LLGLState::setEnabled(S32 enabled) -{ - if (!mState) - { - return; - } - if (enabled == CURRENT_STATE) - { - enabled = sStateMap[mState] == GL_TRUE ? TRUE : FALSE; - } - else if (enabled == TRUE && sStateMap[mState] != GL_TRUE) - { - gGL.flush(); - glEnable(mState); - sStateMap[mState] = GL_TRUE; - } - else if (enabled == FALSE && sStateMap[mState] != GL_FALSE) - { - gGL.flush(); - glDisable(mState); - sStateMap[mState] = GL_FALSE; - } - mIsEnabled = enabled; -} - -LLGLState::~LLGLState() -{ - stop_glerror(); - if (mState) - { - if (gDebugGL) - { - if (!gDebugSession) - { - llassert_always(sStateMap[mState] == glIsEnabled(mState)); - } - else - { - if (sStateMap[mState] != glIsEnabled(mState)) - { - ll_fail("GL enabled state does not match expected"); - } - } - } - - if (mIsEnabled != mWasEnabled) - { - gGL.flush(); - if (mWasEnabled) - { - glEnable(mState); - sStateMap[mState] = GL_TRUE; - } - else - { - glDisable(mState); - sStateMap[mState] = GL_FALSE; - } - } - } - stop_glerror(); -} - //////////////////////////////////////////////////////////////////////////////// +initLLGLState(GL_BLEND, false, nullptr); +initLLGLState(GL_CLIP_PLANE0, false, nullptr); +initLLGLState(GL_CULL_FACE, false, nullptr); +initLLGLState(GL_DEPTH_CLAMP, false, nullptr); +initLLGLState(GL_DITHER, true, nullptr); +initLLGLState(GL_LINE_SMOOTH, false, nullptr); +initLLGLState(GL_MULTISAMPLE_ARB, false, nullptr); +initLLGLState(GL_POLYGON_OFFSET_FILL, false, nullptr); +initLLGLState(GL_POLYGON_OFFSET_LINE, false, nullptr); +initLLGLState(GL_POLYGON_SMOOTH, false, nullptr); +initLLGLState(GL_SCISSOR_TEST, false, nullptr); +initLLGLState(GL_STENCIL_TEST, false, nullptr); +initLLGLState(GL_ALPHA_TEST, false, &LLGLSLShader::sNoFixedFunction); +initLLGLState(GL_COLOR_MATERIAL, false, &LLGLSLShader::sNoFixedFunction); +initLLGLState(GL_FOG, false, &LLGLSLShader::sNoFixedFunction); +initLLGLState(GL_LINE_STIPPLE, false, &LLGLSLShader::sNoFixedFunction); +initLLGLState(GL_LIGHTING, false, &LLGLSLShader::sNoFixedFunction); +initLLGLState(GL_NORMALIZE, false, &LLGLSLShader::sNoFixedFunction); +initLLGLState(GL_POLYGON_STIPPLE, false, &LLGLSLShader::sNoFixedFunction); +initLLGLState(GL_TEXTURE_GEN_Q, false, &LLGLSLShader::sNoFixedFunction); +initLLGLState(GL_TEXTURE_GEN_R, false, &LLGLSLShader::sNoFixedFunction); +initLLGLState(GL_TEXTURE_GEN_S, false, &LLGLSLShader::sNoFixedFunction); +initLLGLState(GL_TEXTURE_GEN_T, false, &LLGLSLShader::sNoFixedFunction); + void LLGLManager::initGLStates() { //gl states moved to classes in llglstates.h - LLGLState::initClass(); + LLGLStateValidator::initClass(); } //////////////////////////////////////////////////////////////////////////////// diff --git a/indra/llrender/llgl.h b/indra/llrender/llgl.h index b3d7faa12..409c9eea6 100644 --- a/indra/llrender/llgl.h +++ b/indra/llrender/llgl.h @@ -30,7 +30,7 @@ // This file contains various stuff for handling gl extensions and other gl related stuff. #include -#include +#include #include #include "llerror.h" @@ -41,6 +41,7 @@ #include "llmatrix4a.h" #include "llplane.h" #include "llgltypes.h" +#include "llrender.h" #include "llinstancetracker.h" #include "llglheaders.h" @@ -103,7 +104,6 @@ public: BOOL mHasPointParameters; BOOL mHasDrawBuffers; BOOL mHasDepthClamp; - BOOL mHasTextureRectangle; BOOL mHasTransformFeedback; S32 mMaxIntegerSamples; @@ -136,7 +136,6 @@ public: BOOL mHasRequirements; // Misc extensions - BOOL mHasSeparateSpecularColor; //whether this GPU is in the debug list. BOOL mDebugGPU; @@ -227,13 +226,13 @@ void clear_glerror(); //disable lighting for rendering hud objects //INCORRECT USAGE - LLGLEnable lighting(GL_LIGHTING); + LLGLEnable lighting; renderHUD(); - LLGLDisable lighting(GL_LIGHTING); + LLGLDisable lighting; //CORRECT USAGE { - LLGLEnable lighting(GL_LIGHTING); + LLGLEnable lighting; renderHUD(); } @@ -241,12 +240,10 @@ void clear_glerror(); is useful: { - LLGLEnable lighting(light_hud ? GL_LIGHTING : 0); + LLGLEnable lighting(light_hud); renderHUD(); } - A LLGLState initialized with a parameter of 0 does nothing. - LLGLState works by maintaining a map of the current GL states, and ignoring redundant enables/disables. If a redundant call is attempted, it becomes a noop, otherwise, it is set in the constructor and reset in the destructor. @@ -255,59 +252,116 @@ void clear_glerror(); if the existing GL state does not match the expected GL state. */ -class LLGLState -{ -public: - static void initClass(); - static void restoreGL(); +struct LLGLStateStaticData +{ + const char* stateStr; + LLGLenum state; + bool currentState; + U32 depth; + char* activeInstance; + bool* disabler; +}; + +class LLGLStateValidator { +public: static void resetTextureStates(); static void dumpStates(); static void checkStates(const std::string& msg = ""); static void checkTextureChannels(const std::string& msg = ""); static void checkClientArrays(const std::string& msg = "", U32 data_mask = 0); - -protected: - static boost::unordered_map sStateMap; - + static void checkState(LLGLStateStaticData& data); + static void initClass(); + static void restoreGL(); + static bool registerStateData(LLGLStateStaticData& data); +private: + static std::vector sStateDataVec; +}; + +class LLGLStateIface { public: enum { CURRENT_STATE = -2 }; - LLGLState(LLGLenum state, S32 enabled = CURRENT_STATE); - ~LLGLState(); - void setEnabled(S32 enabled); - void enable() { setEnabled(TRUE); } - void disable() { setEnabled(FALSE); } -protected: - LLGLenum mState; - BOOL mWasEnabled; - BOOL mIsEnabled; + virtual ~LLGLStateIface() {} + virtual void enable() = 0; + virtual void disable() = 0; }; -// New LLGLState class wrappers that don't depend on actual GL flags. -class LLGLEnableBlending : public LLGLState +template +class LLGLState : public LLGLStateIface { public: - LLGLEnableBlending(bool enable); + + LLGLState(S8 newState = CURRENT_STATE) + { + ++staticData.depth; + mPriorInstance = staticData.activeInstance; + staticData.activeInstance = (char*)this; + mPriorState = staticData.currentState; + setEnabled(newState); + } + virtual ~LLGLState() + { + llassert_always(staticData.activeInstance == (char*)this); + if (staticData.depth != 0) + { + staticData.activeInstance = mPriorInstance; + --staticData.depth; + if (gDebugGL) { + LLGLStateValidator::checkState(staticData); + } + setState(mPriorState); + } + else + { + llassert_always(mPriorInstance == nullptr); + } + } + + virtual void enable() { setEnabled(true); } + virtual void disable() { setEnabled(false); } + + static LLGLStateStaticData staticData; + // Getter + static bool isEnabled() { return staticData.currentState && (!staticData.disabler || !*staticData.disabler); } + // For assertions. If feature is on or unsupported, return true. + static bool checkEnabled() { return (!staticData.disabler || !*staticData.disabler) ? staticData.currentState : true; } + // For assertions. If feature is off or unsupported, return true. + static bool checkDisabled() { return (!staticData.disabler || !*staticData.disabler) ? !staticData.currentState : true; } +private: + char *mPriorInstance; + bool mPriorState; + + void setEnabled(S32 newState) + { + llassert_always(staticData.activeInstance == (char*)this); + bool enabled = newState == CURRENT_STATE ? staticData.currentState : !!newState; + setState(enabled); + } + + static void setState(bool enabled) + { + if (staticData.currentState != enabled && (!staticData.disabler || !*staticData.disabler)) + { + gGL.flush(); + staticData.currentState = enabled; + staticData.currentState ? glEnable(state) : glDisable(state); + } + } +}; +#define initLLGLState(state, value, disabler_ptr) \ + LLGLStateStaticData LLGLState::staticData = {#state, state, value, 0, nullptr, disabler_ptr}; \ + bool registered_##state = LLGLStateValidator::registerStateData(LLGLState::staticData); + +template +struct LLGLEnable : public LLGLState +{ + LLGLEnable(bool noskip = true) : LLGLState(noskip ? TRUE : LLGLState::CURRENT_STATE) {} }; -class LLGLEnableAlphaReject : public LLGLState +template +struct LLGLDisable : public LLGLState { -public: - LLGLEnableAlphaReject(bool enable); -}; - -/// TODO: Being deprecated. -class LLGLEnable : public LLGLState -{ -public: - LLGLEnable(LLGLenum state) : LLGLState(state, TRUE) {} -}; - -/// TODO: Being deprecated. -class LLGLDisable : public LLGLState -{ -public: - LLGLDisable(LLGLenum state) : LLGLState(state, FALSE) {} + LLGLDisable(bool noskip = true) : LLGLState(noskip ? FALSE : LLGLState::CURRENT_STATE) {} }; /* @@ -460,8 +514,6 @@ public: #include "llglstates.h" -void init_glstates(); - void parse_gl_version( S32* major, S32* minor, S32* release, std::string* vendor_specific, std::string* version_string ); extern BOOL gClothRipple; diff --git a/indra/llrender/llglheaders.h b/indra/llrender/llglheaders.h index 044c4f1f6..301099f39 100644 --- a/indra/llrender/llglheaders.h +++ b/indra/llrender/llglheaders.h @@ -122,7 +122,8 @@ extern PFNGLPOINTPARAMETERFARBPROC glPointParameterfARB; extern PFNGLPOINTPARAMETERFVARBPROC glPointParameterfvARB; // GL_ARB_shader_objects -extern PFNGLDELETEOBJECTARBPROC glDeleteObjectARB; +extern PFNGLDELETEOBJECTARBPROC glDeleteShader; +extern PFNGLDELETEOBJECTARBPROC glDeleteProgram; extern PFNGLGETHANDLEARBPROC glGetHandleARB; extern PFNGLDETACHOBJECTARBPROC glDetachObjectARB; extern PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB; @@ -153,9 +154,10 @@ extern PFNGLUNIFORMMATRIX2FVARBPROC glUniformMatrix2fvARB; extern PFNGLUNIFORMMATRIX3FVARBPROC glUniformMatrix3fvARB; extern PFNGLUNIFORMMATRIX3X4FVPROC glUniformMatrix3x4fv; extern PFNGLUNIFORMMATRIX4FVARBPROC glUniformMatrix4fvARB; -extern PFNGLGETOBJECTPARAMETERFVARBPROC glGetObjectParameterfvARB; -extern PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB; -extern PFNGLGETINFOLOGARBPROC glGetInfoLogARB; +extern PFNGLGETOBJECTPARAMETERIVARBPROC glGetShaderiv; +extern PFNGLGETOBJECTPARAMETERIVARBPROC glGetProgramiv; +extern PFNGLGETINFOLOGARBPROC glGetShaderInfoLog; +extern PFNGLGETINFOLOGARBPROC glGetProgramInfoLog; extern PFNGLGETATTACHEDOBJECTSARBPROC glGetAttachedObjectsARB; extern PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB; extern PFNGLGETACTIVEUNIFORMARBPROC glGetActiveUniformARB; @@ -386,7 +388,8 @@ extern PFNGLPOINTPARAMETERFARBPROC glPointParameterfARB; extern PFNGLPOINTPARAMETERFVARBPROC glPointParameterfvARB; // GL_ARB_shader_objects -extern PFNGLDELETEOBJECTARBPROC glDeleteObjectARB; +extern PFNGLDELETEOBJECTARBPROC glDeleteShader; +extern PFNGLDELETEOBJECTARBPROC glDeleteProgram; extern PFNGLGETHANDLEARBPROC glGetHandleARB; extern PFNGLDETACHOBJECTARBPROC glDetachObjectARB; extern PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB; @@ -417,9 +420,10 @@ extern PFNGLUNIFORMMATRIX2FVARBPROC glUniformMatrix2fvARB; extern PFNGLUNIFORMMATRIX3FVARBPROC glUniformMatrix3fvARB; extern PFNGLUNIFORMMATRIX3X4FVPROC glUniformMatrix3x4fv; extern PFNGLUNIFORMMATRIX4FVARBPROC glUniformMatrix4fvARB; -extern PFNGLGETOBJECTPARAMETERFVARBPROC glGetObjectParameterfvARB; -extern PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB; -extern PFNGLGETINFOLOGARBPROC glGetInfoLogARB; +extern PFNGLGETOBJECTPARAMETERIVARBPROC glGetShaderiv; +extern PFNGLGETOBJECTPARAMETERIVARBPROC glGetProgramiv; +extern PFNGLGETINFOLOGARBPROC glGetShaderInfoLog; +extern PFNGLGETINFOLOGARBPROC glGetProgramInfoLog; extern PFNGLGETATTACHEDOBJECTSARBPROC glGetAttachedObjectsARB; extern PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB; extern PFNGLGETACTIVEUNIFORMARBPROC glGetActiveUniformARB; @@ -626,7 +630,8 @@ extern PFNGLPOINTPARAMETERFARBPROC glPointParameterfARB; extern PFNGLPOINTPARAMETERFVARBPROC glPointParameterfvARB; // GL_ARB_shader_objects -extern PFNGLDELETEOBJECTARBPROC glDeleteObjectARB; +extern PFNGLDELETEOBJECTARBPROC glDeleteShader; +extern PFNGLDELETEOBJECTARBPROC glDeleteProgram; extern PFNGLGETHANDLEARBPROC glGetHandleARB; extern PFNGLDETACHOBJECTARBPROC glDetachObjectARB; extern PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB; @@ -657,9 +662,10 @@ extern PFNGLUNIFORMMATRIX2FVARBPROC glUniformMatrix2fvARB; extern PFNGLUNIFORMMATRIX3FVARBPROC glUniformMatrix3fvARB; extern PFNGLUNIFORMMATRIX3X4FVPROC glUniformMatrix3x4fv; extern PFNGLUNIFORMMATRIX4FVARBPROC glUniformMatrix4fvARB; -extern PFNGLGETOBJECTPARAMETERFVARBPROC glGetObjectParameterfvARB; -extern PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB; -extern PFNGLGETINFOLOGARBPROC glGetInfoLogARB; +extern PFNGLGETOBJECTPARAMETERIVARBPROC glGetShaderiv; +extern PFNGLGETOBJECTPARAMETERIVARBPROC glGetProgramiv; +extern PFNGLGETINFOLOGARBPROC glGetShaderInfoLog; +extern PFNGLGETINFOLOGARBPROC glGetProgramInfoLog; extern PFNGLGETATTACHEDOBJECTSARBPROC glGetAttachedObjectsARB; extern PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB; extern PFNGLGETACTIVEUNIFORMARBPROC glGetActiveUniformARB; diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index fede4f87b..cf87d2e5b 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -348,7 +348,7 @@ void LLGLSLShader::unload() glDeleteObjectARB(obj[i]); }*/ if(mProgramObject) - glDeleteObjectARB(mProgramObject); + glDeleteProgram(mProgramObject); mProgramObject = 0; } @@ -388,7 +388,7 @@ BOOL LLGLSLShader::createShader(std::vector * attributes, BOOL success = TRUE; if(mProgramObject) //purge the old program - glDeleteObjectARB(mProgramObject); + glDeleteProgram(mProgramObject); // Create program mProgramObject = glCreateProgramObjectARB(); @@ -417,7 +417,7 @@ BOOL LLGLSLShader::createShader(std::vector * attributes, if (!LLShaderMgr::instance()->attachClassSharedShaders(*this, mShaderClass) || !LLShaderMgr::instance()->attachShaderFeatures(this)) { if(mProgramObject) - glDeleteObjectARB(mProgramObject); + glDeleteProgram(mProgramObject); mProgramObject = 0; return FALSE; } @@ -447,7 +447,7 @@ BOOL LLGLSLShader::createShader(std::vector * attributes, if( !success ) { if(mProgramObject) - glDeleteObjectARB(mProgramObject); + glDeleteProgram(mProgramObject); mProgramObject = 0; LL_WARNS("ShaderLoading") << "Failed to link shader: " << mName << LL_ENDL; @@ -723,6 +723,7 @@ GLint LLGLSLShader::mapUniformTextureChannel(GLint location, GLenum type) if (type >= GL_SAMPLER_1D_ARB && type <= GL_SAMPLER_2D_RECT_SHADOW_ARB /*|| type == GL_SAMPLER_2D_MULTISAMPLE*/) { //this here is a texture + gGL.syncShaders(); glUniform1iARB(location, mActiveTextureChannels); LL_DEBUGS("ShaderLoading") << "Assigned to texture channel " << mActiveTextureChannels << LL_ENDL; return mActiveTextureChannels++; @@ -752,7 +753,7 @@ BOOL LLGLSLShader::mapUniforms(const vector * uniforms) //get the number of active uniforms GLint activeCount; - glGetObjectParameterivARB(mProgramObject, GL_OBJECT_ACTIVE_UNIFORMS_ARB, &activeCount); + glGetProgramiv(mProgramObject, GL_OBJECT_ACTIVE_UNIFORMS_ARB, &activeCount); for (S32 i = 0; i < activeCount; i++) { @@ -776,7 +777,7 @@ void LLGLSLShader::bind() if (gGLManager.mHasShaderObjects) { LLVertexBuffer::unbind(); - glUseProgramObjectARB(mProgramObject); + gGL.setShader(mProgramObject); sCurBoundShader = mProgramObject; sCurBoundShaderPtr = this; if (mUniformsDirty) @@ -802,7 +803,7 @@ void LLGLSLShader::unbind() } } LLVertexBuffer::unbind(); - glUseProgramObjectARB(0); + gGL.setShader(0); sCurBoundShader = 0; sCurBoundShaderPtr = NULL; stop_glerror(); @@ -814,7 +815,7 @@ void LLGLSLShader::bindNoShader(void) LLVertexBuffer::unbind(); if (gGLManager.mHasShaderObjects) { - glUseProgramObjectARB(0); + gGL.setShader(0); sCurBoundShader = 0; sCurBoundShaderPtr = NULL; } diff --git a/indra/llrender/llglslshader.h b/indra/llrender/llglslshader.h index 050af2a1e..3a44cf207 100644 --- a/indra/llrender/llglslshader.h +++ b/indra/llrender/llglslshader.h @@ -82,6 +82,7 @@ public: static GLhandleARB sCurBoundShader; static LLGLSLShader* sCurBoundShaderPtr; + static S32 sIndexedTextureChannels; static bool sNoFixedFunction; @@ -145,6 +146,7 @@ public: F32 val = x; if (updateUniform(mValueVec4, getUniformFromIndex(index), &val)) { + gGL.syncShaders(); glUniform1iARB(mUniform[index], x); } } @@ -152,6 +154,7 @@ public: { if (updateUniform(mValueVec4, getUniformFromIndex(index), &x)) { + gGL.syncShaders(); glUniform1fARB(mUniform[index], x); } } @@ -160,6 +163,7 @@ public: F32 val[] = { x, y }; if (updateUniform(mValueVec4, getUniformFromIndex(index), val)) { + gGL.syncShaders(); glUniform2fARB(mUniform[index], x, y); } } @@ -168,6 +172,7 @@ public: F32 val[] = { x, y, z }; if (updateUniform(mValueVec4, getUniformFromIndex(index), val)) { + gGL.syncShaders(); glUniform3fARB(mUniform[index], x, y, z); } } @@ -176,6 +181,7 @@ public: F32 val[] = { x, y, z, w }; if (updateUniform(mValueVec4, getUniformFromIndex(index), val)) { + gGL.syncShaders(); glUniform4fARB(mUniform[index], x, y, z, w); } } @@ -184,6 +190,7 @@ public: F32 val[] = { static_cast(v[0]) }; if (updateUniform(mValueVec4, getUniformFromIndex(index), val) || count > 1) { + gGL.syncShaders(); glUniform1ivARB(mUniform[index], count, v); } } @@ -191,6 +198,7 @@ public: { if (updateUniform(mValueVec4, getUniformFromIndex(index), v) || count > 1) { + gGL.syncShaders(); glUniform1fvARB(mUniform[index], count, v); } } @@ -198,6 +206,7 @@ public: { if (updateUniform(mValueVec4, getUniformFromIndex(index), v) || count > 1) { + gGL.syncShaders(); glUniform2fvARB(mUniform[index], count, v); } } @@ -205,6 +214,7 @@ public: { if (updateUniform(mValueVec4, getUniformFromIndex(index), v) || count > 1) { + gGL.syncShaders(); glUniform3fvARB(mUniform[index], count, v); } } @@ -212,6 +222,7 @@ public: { if (updateUniform(mValueVec4, getUniformFromIndex(index), v) || count > 1) { + gGL.syncShaders(); glUniform4fvARB(mUniform[index], count, v); } } @@ -219,6 +230,7 @@ public: { if (updateUniform(mValueMat3, getUniformFromIndex(index), v) || count > 1) { + gGL.syncShaders(); glUniformMatrix3fvARB(mUniform[index], count, transpose, v); } } @@ -226,6 +238,7 @@ public: { if (updateUniform(mValueMat4, getUniformFromIndex(index), v) || count > 1) { + gGL.syncShaders(); glUniformMatrix3x4fv(mUniform[index], count, transpose, v); } } @@ -233,6 +246,7 @@ public: { if (updateUniform(mValueMat4, getUniformFromIndex(index), v) || count > 1) { + gGL.syncShaders(); glUniformMatrix4fvARB(mUniform[index], count, transpose, v); } } @@ -244,6 +258,7 @@ public: F32 val = i; if (updateUniform(mValueVec4, getUniformLocation(uniform), &val)) { + gGL.syncShaders(); glUniform1iARB(location, i); } } @@ -254,6 +269,7 @@ public: return; if (updateUniform(mValueVec4, location, &v)) { + gGL.syncShaders(); glUniform1fARB(location, v); } } @@ -265,6 +281,7 @@ public: F32 val[] = { x, y }; if (updateUniform(mValueVec4, location, val)) { + gGL.syncShaders(); glUniform2fARB(location, x, y); } } @@ -276,6 +293,7 @@ public: F32 val[] = { x, y, z }; if (updateUniform(mValueVec4, location, val)) { + gGL.syncShaders(); glUniform3fARB(location, x, y, z); } } @@ -286,6 +304,7 @@ public: return; if (updateUniform(mValueVec4, location, v)) { + gGL.syncShaders(); glUniform1fvARB(location, count, v); } } @@ -296,6 +315,7 @@ public: return; if (updateUniform(mValueVec4, location, v)) { + gGL.syncShaders(); glUniform2fvARB(location, count, v); } } @@ -306,6 +326,7 @@ public: return; if (updateUniform(mValueVec4, location, v)) { + gGL.syncShaders(); glUniform3fvARB(location, count, v); } } @@ -316,6 +337,7 @@ public: return; if (updateUniform(mValueVec4, location, v)) { + gGL.syncShaders(); glUniform4fvARB(location, count, v); } } @@ -326,6 +348,7 @@ public: return; if (updateUniform(mValueMat4, location, v)) { + gGL.syncShaders(); glUniformMatrix4fvARB(location, count, transpose, v); } } @@ -344,6 +367,7 @@ public: { if (gDebugGL) { + gGL.syncShaders(); stop_glerror(); if (iter->second != glGetUniformLocationARB(mProgramObject, uniform.String().c_str())) { diff --git a/indra/llrender/llglstates.h b/indra/llrender/llglstates.h index 266f266a6..3a81eac94 100644 --- a/indra/llrender/llglstates.h +++ b/indra/llrender/llglstates.h @@ -53,181 +53,128 @@ private: //---------------------------------------------------------------------------- -class LLGLSDefault +struct LLGLSDefault { -protected: - LLGLEnable mColorMaterial; - LLGLDisable mAlphaTest, mBlend, mCullFace, mDither, mFog, - mLineSmooth, mLineStipple, mNormalize, mPolygonSmooth, - mGLMultisample; -public: - LLGLSDefault() - : - // Enable - mColorMaterial(GL_COLOR_MATERIAL), - // Disable - mAlphaTest(GL_ALPHA_TEST), - mBlend(GL_BLEND), - mCullFace(GL_CULL_FACE), - mDither(GL_DITHER), - mFog(GL_FOG), - mLineSmooth(GL_LINE_SMOOTH), - mLineStipple(GL_LINE_STIPPLE), - mNormalize(GL_NORMALIZE), - mPolygonSmooth(GL_POLYGON_SMOOTH), - mGLMultisample(GL_MULTISAMPLE_ARB) - { } +private: + LLGLEnable mColorMaterial; + LLGLDisable mAlphaTest; + LLGLDisable mBlend; + LLGLDisable mCullFace; + LLGLDisable mDither; + LLGLDisable mFog; + LLGLDisable mLineSmooth; + LLGLDisable mLineStipple; + LLGLDisable mNormalize; + LLGLDisable mPolygonSmooth; + LLGLDisable mGLMultisample; + LLGLDisable lighting; }; -class LLGLSObjectSelect -{ -protected: - LLGLDisable mBlend, mFog, mAlphaTest; - LLGLEnable mCullFace; -public: - LLGLSObjectSelect() - : mBlend(GL_BLEND), mFog(GL_FOG), - mAlphaTest(GL_ALPHA_TEST), - mCullFace(GL_CULL_FACE) - { } +struct LLGLSObjectSelect +{ +private: + LLGLDisable mBlend; + LLGLDisable mAlphaTest; + LLGLDisable mFog; + LLGLEnable mCullFace; }; -class LLGLSObjectSelectAlpha +struct LLGLSObjectSelectAlpha { -protected: - LLGLEnable mAlphaTest; -public: - LLGLSObjectSelectAlpha() - : mAlphaTest(GL_ALPHA_TEST) - {} +private: + LLGLEnable mAlphaTest; }; //---------------------------------------------------------------------------- -class LLGLSUIDefault +struct LLGLSUIDefault { -protected: - LLGLEnable mBlend, mAlphaTest; - LLGLDisable mCullFace; +private: + LLGLEnable mBlend; + LLGLEnable mAlphaTest; + LLGLDisable mCullFace; + LLGLDisable mMSAA; + //LLGLEnable mScissor; LLGLDepthTest mDepthTest; - LLGLDisable mMSAA; public: - LLGLSUIDefault() - : mBlend(GL_BLEND), mAlphaTest(GL_ALPHA_TEST), - mCullFace(GL_CULL_FACE), - mDepthTest(GL_FALSE, GL_TRUE, GL_LEQUAL), - mMSAA(GL_MULTISAMPLE_ARB) + LLGLSUIDefault() + : mDepthTest(GL_FALSE, GL_TRUE, GL_LEQUAL) {} }; -class LLGLSNoAlphaTest // : public LLGLSUIDefault +struct LLGLSNoAlphaTest // : public LLGLSUIDefault { -protected: - LLGLDisable mAlphaTest; -public: - LLGLSNoAlphaTest() - : mAlphaTest(GL_ALPHA_TEST) - {} +private: + LLGLDisable mAlphaTest; }; //---------------------------------------------------------------------------- -class LLGLSFog +struct LLGLSFog { -protected: - LLGLEnable mFog; -public: - LLGLSFog() - : mFog(GL_FOG) - {} +private: + LLGLEnable mFog; }; -class LLGLSNoFog +struct LLGLSNoFog { -protected: - LLGLDisable mFog; -public: - LLGLSNoFog() - : mFog(GL_FOG) - {} +private: + LLGLDisable mFog; }; //---------------------------------------------------------------------------- -class LLGLSPipeline +struct LLGLSPipeline { -protected: - LLGLEnable mCullFace; +private: + LLGLEnable mCullFace; LLGLDepthTest mDepthTest; public: LLGLSPipeline() - : mCullFace(GL_CULL_FACE), - mDepthTest(GL_TRUE, GL_TRUE, GL_LEQUAL) - { } + : mDepthTest(GL_TRUE, GL_TRUE, GL_LEQUAL) + {} }; -class LLGLSPipelineAlpha // : public LLGLSPipeline +struct LLGLSPipelineAlpha // : public LLGLSPipeline { -protected: - LLGLEnable mBlend, mAlphaTest; -public: - LLGLSPipelineAlpha() - : mBlend(GL_BLEND), - mAlphaTest(GL_ALPHA_TEST) - { } +private: + LLGLEnable mAlphaTest; + LLGLEnable mBlend; }; -class LLGLSPipelineEmbossBump +struct LLGLSPipelineEmbossBump { -protected: - LLGLDisable mFog; -public: - LLGLSPipelineEmbossBump() - : mFog(GL_FOG) - { } +private: + LLGLDisable mFog; }; -class LLGLSPipelineSelection +struct LLGLSPipelineSelection { -protected: - LLGLDisable mCullFace; -public: - LLGLSPipelineSelection() - : mCullFace(GL_CULL_FACE) - {} +private: + LLGLDisable mCullFace; }; -class LLGLSPipelineAvatar +struct LLGLSPipelineAvatar { -protected: - LLGLEnable mNormalize; -public: - LLGLSPipelineAvatar() - : mNormalize(GL_NORMALIZE) - {} +private: + LLGLEnable mNormalize; }; -class LLGLSPipelineSkyBox +struct LLGLSPipelineSkyBox { -protected: - LLGLDisable mAlphaTest, mCullFace, mFog; -public: - LLGLSPipelineSkyBox() - : mAlphaTest(GL_ALPHA_TEST), mCullFace(GL_CULL_FACE), mFog(GL_FOG) - { } +private: + LLGLDisable mAlphaTest; + LLGLDisable mCullFace; + LLGLDisable mFog; + LLGLDisable mLighting; }; -class LLGLSTracker +struct LLGLSTracker { -protected: - LLGLEnable mCullFace, mBlend, mAlphaTest; -public: - LLGLSTracker() : - mCullFace(GL_CULL_FACE), - mBlend(GL_BLEND), - mAlphaTest(GL_ALPHA_TEST) - - { } +private: + LLGLEnable mAlphaTest; + LLGLEnable mBlend; + LLGLEnable mCullFace; }; //---------------------------------------------------------------------------- diff --git a/indra/llrender/llgltexture.cpp b/indra/llrender/llgltexture.cpp index 0e70a0d6e..b3c8a5d6d 100644 --- a/indra/llrender/llgltexture.cpp +++ b/indra/llrender/llgltexture.cpp @@ -167,7 +167,7 @@ BOOL LLGLTexture::createGLTexture() return mGLTexturep->createGLTexture() ; } -BOOL LLGLTexture::createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S32 usename, BOOL to_create, S32 category) +BOOL LLGLTexture::createGLTexture(S32 discard_level, const LLImageRaw* imageraw, LLImageGL::GLTextureName& usename, BOOL to_create, S32 category) { llassert(mGLTexturep.notNull()) ; diff --git a/indra/llrender/llgltexture.h b/indra/llrender/llgltexture.h index 569a28af4..81c994347 100644 --- a/indra/llrender/llgltexture.h +++ b/indra/llrender/llgltexture.h @@ -123,8 +123,7 @@ public: BOOL hasGLTexture() const ; LLGLuint getTexName() const ; BOOL createGLTexture() ; - BOOL createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S32 usename = 0, BOOL to_create = TRUE, S32 category = LLGLTexture::OTHER); - + BOOL createGLTexture(S32 discard_level, const LLImageRaw* imageraw, LLImageGL::GLTextureName& usename = LLImageGL::GLTextureName(), BOOL to_create = TRUE, S32 category = LLGLTexture::OTHER); void setFilteringOption(LLTexUnit::eTextureFilterOptions option); void setExplicitFormat(LLGLint internal_format, LLGLenum primary_format, LLGLenum type_format = 0, BOOL swap_bytes = FALSE); void setAddressMode(LLTexUnit::eTextureAddressMode mode); diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp index 968897dde..2534ba429 100644 --- a/indra/llrender/llimagegl.cpp +++ b/indra/llrender/llimagegl.cpp @@ -86,6 +86,9 @@ std::vector LLImageGL::sTextureCurMemByCategoryBound ; //End for texture auditing use only // **************************************************************************************************** +//static std::vector sActiveTextureNames; +//static std::vector sDeletedTextureNames; + // ************************************************************************************** //below are functions for debug use //do not delete them even though they are not currently being used. @@ -118,9 +121,9 @@ void LLImageGL::checkTexSize(bool forced) const GLint texname; glGetIntegerv(GL_TEXTURE_BINDING_2D, &texname); BOOL error = FALSE; - if (texname != mTexName) + if (texname != getTexName()) { - LL_INFOS() << "Bound: " << texname << " Should bind: " << mTexName << " Default: " << LLImageGL::sDefaultGLTexture->getTexName() << LL_ENDL; + LL_INFOS() << "Bound: " << texname << " Should bind: " << getTexName() << " Default: " << (LLImageGL::sDefaultGLTexture ? LLImageGL::sDefaultGLTexture->getTexName() : 0) << LL_ENDL; error = TRUE; if (gDebugSession) @@ -219,7 +222,7 @@ void LLImageGL::setHighlightTexture(S32 category) } } } - sHighlightTexturep->createGLTexture(0, image_raw, 0, TRUE, category); + sHighlightTexturep->createGLTexture(0, image_raw, LLImageGL::GLTextureName(), TRUE, category); image_raw = NULL; } @@ -328,47 +331,48 @@ S32 LLImageGL::updateBoundTexMem(const S32Bytes mem, const S32 ncomponents, S32 //static void LLImageGL::destroyGL(BOOL save_state) { + LLTexUnit::sWhiteTexture = 0; + if (save_state) + { + U32 count = 0; + sAllowReadBackRaw = true; + for (std::set::iterator iter = sImageList.begin(); + iter != sImageList.end(); iter++) + { + LLImageGL* glimage = *iter; + GLuint tex = glimage->getTexName(); + if (tex) + { + if (glimage->isGLTextureCreated()) + { + glimage->mSaveData = new LLImageRaw; + if (glimage->mComponents && glimage->readBackRaw(-1, glimage->mSaveData, false))//necessary, keep it. + { + ++count; + glimage->mSaveDiscardLevel = glimage->mCurrentDiscardLevel; + glimage->destroyGLTexture(); + continue; + } + } + } + glimage->mSaveData = nullptr; + glimage->forceToInvalidateGLTexture(); + stop_glerror(); + } + LL_INFOS() << "Storing " << count << " images..." << LL_ENDL; + sAllowReadBackRaw = false; + } for (S32 stage = 0; stage < gGLManager.mNumTextureUnits; stage++) { gGL.getTexUnit(stage)->unbind(LLTexUnit::TT_TEXTURE); } - - sAllowReadBackRaw = true ; - std::set stored_images; - for (std::set::iterator iter = sImageList.begin(); - iter != sImageList.end(); iter++) - { - LLImageGL* glimage = *iter; - if (glimage->mTexName) - { - if (save_state && glimage->isGLTextureCreated() && glimage->mComponents) - { - glimage->mSaveData = new LLImageRaw; - if(!glimage->readBackRaw(glimage->mCurrentDiscardLevel, glimage->mSaveData, false)) //necessary, keep it. - { - delete glimage; - } - else - { - glimage->mSaveDiscardLevel = glimage->mCurrentDiscardLevel; - stored_images.insert(glimage); - glimage->destroyGLTexture(); - } - } - - stop_glerror(); - } - } - sImageList = stored_images; - LL_INFOS() << "Storing " << stored_images.size() << " images..." << LL_ENDL; - sAllowReadBackRaw = false ; + //clean_validate_buffers(); } //static void LLImageGL::restoreGL() { - - std::set restored_images; + U32 count = 0; for (std::set::iterator iter = sImageList.begin(); iter != sImageList.end(); iter++) { @@ -377,22 +381,32 @@ void LLImageGL::restoreGL() { LL_ERRS() << "tex name is not 0." << LL_ENDL ; } - if (glimage->mSaveData.notNull() && glimage->getComponents() && - glimage->mSaveData->getComponents() && + LLPointer data = glimage->mSaveData; + glimage->mSaveData = nullptr; + if (data.notNull() && glimage->getComponents() && + data->getComponents() && glimage->mSaveDiscardLevel >= 0 && - glimage->createGLTexture(glimage->mSaveDiscardLevel, glimage->mSaveData, 0, TRUE, glimage->getCategory())) + glimage->createGLTexture(glimage->mSaveDiscardLevel, data, LLImageGL::GLTextureName(), TRUE, glimage->getCategory())) { stop_glerror(); - restored_images.insert(glimage); + /*if (glimage->getHasGLTexture()) + { + LL_INFOS() << "Restored " << glimage << " texid:" << glimage->getTexName() << LL_ENDL; + } + else + { + LL_INFOS() << "Restored " << glimage << " texid: (null)" << LL_ENDL; + }*/ + ++count; } else { - delete glimage; + //LL_INFOS() << "Skipped " << glimage << LL_ENDL; + glimage->forceToInvalidateGLTexture(); } } - restored_images = restored_images; - LL_INFOS() << "Restored " << restored_images.size() << " images" << LL_ENDL; + LL_INFOS() << "Restored " << count << " images" << LL_ENDL; } //static @@ -499,7 +513,7 @@ void LLImageGL::init(BOOL usemipmaps) mAlphaOffset = INVALID_OFFSET ; mGLTextureCreated = FALSE ; - mTexName = 0; + mTexName.reset(); mWidth = 0; mHeight = 0; mCurrentDiscardLevel = -1; @@ -577,7 +591,7 @@ void LLImageGL::setSize(S32 width, S32 height, S32 ncomponents, S32 discard_leve if (mTexName) { -// LL_WARNS() << "Setting Size of LLImageGL with existing mTexName = " << mTexName << LL_ENDL; +// LL_WARNS() << "Setting Size of LLImageGL with existing mTexName = " << getTexName() << LL_ENDL; destroyGLTexture(); } @@ -634,7 +648,7 @@ void LLImageGL::dump() << LL_ENDL; LL_INFOS() << " mTextureMemory " << mTextureMemory - << " mTexNames " << mTexName + << " mTexNames " << getTexName() << " mIsResident " << S32(mIsResident) << LL_ENDL; } @@ -647,7 +661,7 @@ void LLImageGL::forceUpdateBindStats(void) const BOOL LLImageGL::updateBindStats(S32Bytes tex_mem) const { - if (mTexName != 0) + if (getTexName()) { #ifdef DEBUG_MISS mMissed = ! getIsResident(TRUE); @@ -959,7 +973,7 @@ BOOL LLImageGL::setSubImage(const U8* datap, S32 data_width, S32 data_height, S3 { return TRUE; } - if (mTexName == 0) + if (!getTexName()) { // *TODO: Re-enable warning? Ran into thread locking issues? DK 2011-02-18 //LL_WARNS() << "Setting subimage on image without GL texture" << LL_ENDL; @@ -1027,7 +1041,7 @@ BOOL LLImageGL::setSubImage(const U8* datap, S32 data_width, S32 data_height, S3 datap += (y_pos * data_width + x_pos) * getComponents(); // Update the GL texture - BOOL res = gGL.getTexUnit(0)->bindManual(mBindTarget, mTexName); + BOOL res = gGL.getTexUnit(0)->bindManual(mBindTarget, getTexName()); if (!res) LL_ERRS() << "LLImageGL::setSubImage(): bindTexture failed" << LL_ENDL; stop_glerror(); @@ -1071,23 +1085,118 @@ BOOL LLImageGL::setSubImageFromFrameBuffer(S32 fb_x, S32 fb_y, S32 x_pos, S32 y_ } } +/*void validate_add_texture(U32 name) +{ + auto found = std::find(sActiveTextureNames.begin(), sActiveTextureNames.end(), name); + if (found != sActiveTextureNames.end()) + { + LL_ERRS() << "Allocating allocated texture name " << name << LL_ENDL; + } + else + { + //LL_INFOS() << "Allocated buffer name " << name << LL_ENDL; + sActiveTextureNames.push_back(name); + } +} + +void validate_del_texture(U32 name) +{ + auto found = std::find(sActiveTextureNames.begin(), sActiveTextureNames.end(), name); + if (found == sActiveTextureNames.end()) + { + if (std::find(sDeletedTextureNames.begin(), sDeletedTextureNames.end(), name) == sDeletedTextureNames.end()) + { + LL_ERRS() << "Deleting unknown texture name " << name << LL_ENDL; + } + else + { + LL_ERRS() << "Deleting deleted texture name " << name << LL_ENDL; + } + } + else + { + //LL_INFOS() << "Deleted buffer name " << name << LL_ENDL; + sActiveTextureNames.erase(found); + sDeletedTextureNames.push_back(name); + } + +} + +void validate_bind_texture(U32 name) +{ + auto found = std::find(sActiveTextureNames.begin(), sActiveTextureNames.end(), name); + if (found == sActiveTextureNames.end()) + { + if (std::find(sDeletedTextureNames.begin(), sDeletedTextureNames.end(), name) == sDeletedTextureNames.end()) + { + LL_ERRS() << "Binding unknown texture name " << name << LL_ENDL; + } + else + { + LL_ERRS() << "Binding deleted texture name " << name << LL_ENDL; + } + } +} + +void clean_validate_buffers() +{ + LL_INFOS() << "Clearing active buffer names. Count " << sActiveBufferNames.size() << LL_ENDL; + sActiveTextureNames.clear(); + LL_INFOS() << "Clearing deleted buffer names. Count " << sDeletedBufferNames.size() << LL_ENDL; + sDeletedTextureNames.clear(); +}*/ + // static static LLTrace::BlockTimerStatHandle FTM_GENERATE_TEXTURES("generate textures"); void LLImageGL::generateTextures(S32 numTextures, U32 *textures) { LL_RECORD_BLOCK_TIME(FTM_GENERATE_TEXTURES); glGenTextures(numTextures, textures); + /*for (S32 i = 0; i < numTextures; ++i) + { + validate_add_texture(textures[i]); + }*/ } // static -void LLImageGL::deleteTextures(S32 numTextures, U32 *textures) +void LLImageGL::deleteTextures(S32 numTextures, U32 *textures, const std::vector& allocationData) { if (gGLManager.mInited) { + for (auto& entry : allocationData) + { + texMemoryDeallocated(entry); + } + glDeleteTextures(numTextures, textures); + /*for (S32 i = 0; i < numTextures; ++i) + { + validate_del_texture(textures[i]); + }*/ } } +// static +void LLImageGL::texMemoryAllocated(const AllocationInfo& entry) +{ + sGlobalTextureMemory += (S64Bytes)entry.size; + if (gAuditTexture) + { + incTextureCounter((S64Bytes)entry.size, entry.components, entry.category); + } +} + +// static +void LLImageGL::texMemoryDeallocated(const AllocationInfo& entry) +{ + sGlobalTextureMemory -= (S64Bytes)entry.size; + if (gAuditTexture) + { + decTextureCounter((S64Bytes)entry.size, entry.components, entry.category); + } +} + + //#include "crnlib.h" struct DDS_PIXELFORMAT { U32 dwSize; @@ -1512,15 +1621,10 @@ BOOL LLImageGL::createGLTexture() llassert(gGLManager.mInited); stop_glerror(); - if(mTexName) - { - LLImageGL::deleteTextures(1, (reinterpret_cast(&mTexName))) ; - } - + mTexName = createTextureName(); - LLImageGL::generateTextures(1, &mTexName); stop_glerror(); - if (!mTexName) + if (!getTexName()) { LL_ERRS() << "LLImageGL::createGLTexture failed to make an empty texture" << LL_ENDL; } @@ -1529,7 +1633,7 @@ BOOL LLImageGL::createGLTexture() } static LLTrace::BlockTimerStatHandle FTM_CREATE_GL_TEXTURE2("createGLTexture(raw)"); -BOOL LLImageGL::createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S32 usename/*=0*/, BOOL to_create, S32 category) +BOOL LLImageGL::createGLTexture(S32 discard_level, const LLImageRaw* imageraw, GLTextureName& usename, BOOL to_create, S32 category) { LL_RECORD_BLOCK_TIME(FTM_CREATE_GL_TEXTURE2); if (gGLManager.mIsDisabled) @@ -1606,7 +1710,7 @@ BOOL LLImageGL::createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S } static LLTrace::BlockTimerStatHandle FTM_CREATE_GL_TEXTURE3("createGLTexture3(data)"); -BOOL LLImageGL::createGLTexture(S32 discard_level, const U8* data_in, BOOL data_hasmips, S32 usename) +BOOL LLImageGL::createGLTexture(S32 discard_level, const U8* data_in, BOOL data_hasmips, GLTextureName& usename) { LL_RECORD_BLOCK_TIME(FTM_CREATE_GL_TEXTURE3); llassert(data_in); @@ -1619,23 +1723,23 @@ BOOL LLImageGL::createGLTexture(S32 discard_level, const U8* data_in, BOOL data_ } discard_level = llclamp(discard_level, 0, (S32)mMaxDiscardLevel); - if (mTexName != 0 && discard_level == mCurrentDiscardLevel) + if (getTexName() != 0 && discard_level == mCurrentDiscardLevel) { // This will only be true if the size has not changed setImage(data_in, data_hasmips); + //checkTexSize(); return TRUE; } - U32 old_name = mTexName; // S32 old_discard = mCurrentDiscardLevel; - if (usename != 0) + if (usename) { mTexName = usename; } else { - LLImageGL::generateTextures(1, &mTexName); + mTexName = createTextureName(); stop_glerror(); { llverify(gGL.getTexUnit(0)->bind(this)); @@ -1646,7 +1750,7 @@ BOOL LLImageGL::createGLTexture(S32 discard_level, const U8* data_in, BOOL data_ stop_glerror(); } } - if (!mTexName) + if (!getTexName()) { LL_ERRS() << "LLImageGL::createGLTexture failed to make texture" << LL_ENDL; } @@ -1666,37 +1770,25 @@ BOOL LLImageGL::createGLTexture(S32 discard_level, const U8* data_in, BOOL data_ mCurrentDiscardLevel = discard_level; setImage(data_in, data_hasmips); + glTexParameteri(LLTexUnit::getInternalType(mBindTarget), GL_TEXTURE_MAX_LEVEL, mMaxDiscardLevel - discard_level); // Set texture options to our defaults. gGL.getTexUnit(0)->setHasMipMaps(mHasMipMaps); gGL.getTexUnit(0)->setTextureAddressMode(mAddressMode); gGL.getTexUnit(0)->setTextureFilteringOption(mFilterOption); + //gGL.getTexUnit(0)->unbind(mBindTarget); + //llverify(gGL.getTexUnit(0)->bindManual(mBindTarget, getTexName())); + //checkTexSize(); + // things will break if we don't unbind after creation gGL.getTexUnit(0)->unbind(mBindTarget); stop_glerror(); - if (old_name != 0) - { - sGlobalTextureMemory -= mTextureMemory; - - if(gAuditTexture) - { - decTextureCounter(mTextureMemory, mComponents, mCategory) ; - } - - LLImageGL::deleteTextures(1, &old_name); - - stop_glerror(); - } - mTextureMemory = (S32Bytes)getMipBytes(discard_level); - sGlobalTextureMemory += mTextureMemory; - if(gAuditTexture) - { - incTextureCounter(mTextureMemory, mComponents, mCategory) ; - } + mTexName->addAllocatedMemory(mTextureMemory, mComponents, mCategory); + // mark this as bound at this point, so we don't throw it out immediately mLastBindTime = sLastFrameTime; return TRUE; @@ -1715,7 +1807,7 @@ BOOL LLImageGL::readBackRaw(S32 discard_level, LLImageRaw* imageraw, bool compre return FALSE; } - if (mTexName == 0 || discard_level < mCurrentDiscardLevel || discard_level > mMaxDiscardLevel ) + if (getTexName() == 0 || discard_level < mCurrentDiscardLevel || discard_level > mMaxDiscardLevel ) { return FALSE; } @@ -1724,7 +1816,7 @@ BOOL LLImageGL::readBackRaw(S32 discard_level, LLImageRaw* imageraw, bool compre //explicitly unbind texture gGL.getTexUnit(0)->unbind(mBindTarget); - llverify(gGL.getTexUnit(0)->bindManual(mBindTarget, mTexName)); + llverify(gGL.getTexUnit(0)->bindManual(mBindTarget, getTexName())); //debug code, leave it there commented. checkTexSize() ; @@ -1828,21 +1920,10 @@ void LLImageGL::deleteDeadTextures() void LLImageGL::destroyGLTexture() { - if (mTexName != 0) + if (getTexName()) { - if(mTextureMemory != S32Bytes(0)) - { - if(gAuditTexture) - { - decTextureCounter(mTextureMemory, mComponents, mCategory) ; - } - sGlobalTextureMemory -= mTextureMemory; - mTextureMemory = (S32Bytes)0; - } - - LLImageGL::deleteTextures(1, &mTexName); - mCurrentDiscardLevel = -1 ; //invalidate mCurrentDiscardLevel. - mTexName = 0; + mTexName.reset(); + mCurrentDiscardLevel = -1 ; //invalidate mCurrentDiscardLevel. mGLTextureCreated = FALSE ; } } @@ -1850,7 +1931,7 @@ void LLImageGL::destroyGLTexture() //force to invalidate the gl texture, most likely a sculpty texture void LLImageGL::forceToInvalidateGLTexture() { - if (mTexName != 0) + if (getTexName() != 0) { destroyGLTexture(); } @@ -1870,7 +1951,8 @@ void LLImageGL::setAddressMode(LLTexUnit::eTextureAddressMode mode) mAddressMode = mode; } - if (gGL.getTexUnit(gGL.getCurrentTexUnitIndex())->getCurrTexture() == mTexName) + GLuint tex = getTexName(); + if (tex && gGL.getTexUnit(gGL.getCurrentTexUnitIndex())->getCurrTexture() == tex) { gGL.getTexUnit(gGL.getCurrentTexUnitIndex())->setTextureAddressMode(mode); mTexOptionsDirty = false; @@ -1885,7 +1967,8 @@ void LLImageGL::setFilteringOption(LLTexUnit::eTextureFilterOptions option) mFilterOption = option; } - if (mTexName != 0 && gGL.getTexUnit(gGL.getCurrentTexUnitIndex())->getCurrTexture() == mTexName) + GLuint tex = getTexName(); + if (tex && gGL.getTexUnit(gGL.getCurrentTexUnitIndex())->getCurrTexture() == tex) { gGL.getTexUnit(gGL.getCurrentTexUnitIndex())->setTextureFilteringOption(option); mTexOptionsDirty = false; @@ -1897,9 +1980,10 @@ BOOL LLImageGL::getIsResident(BOOL test_now) { if (test_now) { - if (mTexName != 0) + GLuint tex = getTexName(); + if (tex) { - glAreTexturesResident(1, (GLuint*)&mTexName, &mIsResident); + glAreTexturesResident(1, (GLuint*)&tex, &mIsResident); } else { diff --git a/indra/llrender/llimagegl.h b/indra/llrender/llimagegl.h index f2d32c087..8366d1a2f 100644 --- a/indra/llrender/llimagegl.h +++ b/indra/llrender/llimagegl.h @@ -45,12 +45,66 @@ class LLImageGL : public LLRefCount { friend class LLTexUnit; + friend class GLTextureName; public: + struct AllocationInfo; +private: // These 2 functions replace glGenTextures() and glDeleteTextures() static void generateTextures(S32 numTextures, U32 *textures); - static void deleteTextures(S32 numTextures, U32 *textures); + static void deleteTextures(S32 numTextures, U32 *textures, const std::vector& allocationData); + static void texMemoryAllocated(const AllocationInfo& entry); + static void texMemoryDeallocated(const AllocationInfo& entry); +public: static void deleteDeadTextures(); + struct AllocationInfo + { + AllocationInfo(S32Bytes& _size, U8 _components, U32 _category) : + size(_size), components(_components), category(_category) + {} + S32Bytes size; + U8 components; + U32 category; + }; + // Singu Note: + // The topology of GLImageGL is wrong. As a result, tex names are shared across multiple LLImageGL + // instances. To avoid redundant glDelete calls gl tex names have been wrapped in GLTextureName, + // which is refcounted via std::shared_ptr. + class GLTextureNameInstance { + public: + GLTextureNameInstance(U32 size = 1) : mTexCount(size) + { + mTexNames.resize(mTexCount, 0); + LLImageGL::generateTextures(1, mTexNames.data()); + } + ~GLTextureNameInstance() + { + LLImageGL::deleteTextures(1, mTexNames.data(), mAllocationData); + } + GLuint getTexName(U32 idx = 0) const + { + return mTexNames[idx]; + } + void addAllocatedMemory(S32Bytes size, U8 components, U32 category) + { + mAllocationData.emplace_back(size, components, category); + LLImageGL::texMemoryAllocated(mAllocationData.back()); + } + const std::vector& getAllocatedMemoryInfo() const + { + return mAllocationData; + } + private: + const size_t mTexCount; + std::vector mTexNames; + std::vector mAllocationData; + }; + typedef std::shared_ptr GLTextureName; + + static GLTextureName createTextureName(U32 size = 0) { + return std::make_shared(); + } + // Size calculation static S32 dataFormatBits(S32 dataformat); static S32 dataFormatBytes(S32 dataformat, S32 width, S32 height); @@ -101,9 +155,9 @@ public: static void setManualImage(U32 target, S32 miplevel, S32 intformat, S32 width, S32 height, U32 pixformat, U32 pixtype, const void *pixels, bool allow_compression = true); BOOL createGLTexture() ; - BOOL createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S32 usename = 0, BOOL to_create = TRUE, + BOOL createGLTexture(S32 discard_level, const LLImageRaw* imageraw, GLTextureName& usename = GLTextureName(), BOOL to_create = TRUE, S32 category = sMaxCategories-1); - BOOL createGLTexture(S32 discard_level, const U8* data, BOOL data_hasmips = FALSE, S32 usename = 0); + BOOL createGLTexture(S32 discard_level, const U8* data, BOOL data_hasmips = FALSE, GLTextureName& usename = GLTextureName()); void setImage(const LLImageRaw* imageraw); void setImage(const U8* data_in, BOOL data_hasmips = FALSE); BOOL setSubImage(const LLImageRaw* imageraw, S32 x_pos, S32 y_pos, S32 width, S32 height, BOOL force_fast_update = FALSE); @@ -133,8 +187,8 @@ public: LLGLenum getPrimaryFormat() const { return mFormatPrimary; } LLGLenum getFormatType() const { return mFormatType; } - BOOL getHasGLTexture() const { return mTexName != 0; } - LLGLuint getTexName() const { return mTexName; } + BOOL getHasGLTexture() const { return mTexName != nullptr; } + LLGLuint getTexName() const { return mTexName ? mTexName->getTexName() : 0; } BOOL getIsAlphaMask(const F32 max_rmse, const F32 max_mid) const { return mNeedsAlphaAndPickMask && (max_rmse < 0.f ? (bool)mIsMask : (mMaskRMSE <= max_rmse && mMaskMidPercentile <= max_mid)); } @@ -197,7 +251,7 @@ private: S8 mAlphaOffset ; bool mGLTextureCreated ; - LLGLuint mTexName; + GLTextureName mTexName; U16 mWidth; U16 mHeight; S8 mCurrentDiscardLevel; diff --git a/indra/llrender/llpostprocess.cpp b/indra/llrender/llpostprocess.cpp index a2fbeb9ee..e1c0d90e3 100644 --- a/indra/llrender/llpostprocess.cpp +++ b/indra/llrender/llpostprocess.cpp @@ -294,6 +294,7 @@ public: { if((S32)pass > mNumPasses*2) return false; + gGL.syncShaders(); glUniform1iARB(mPassLoc, (pass-1) % 2); return true; } @@ -445,18 +446,14 @@ void LLPostProcess::createScreenTextures() mRenderTarget[1].allocate(mScreenWidth,mScreenHeight,GL_RGBA,FALSE,FALSE,type,FALSE); stop_glerror(); - if(mDepthTexture) - { - LLImageGL::deleteTextures(1, &mDepthTexture); - mDepthTexture = 0; - } + mDepthTexture.reset(); for(std::list >::iterator it=mShaders.begin();it!=mShaders.end();++it) { if((*it)->getDepthChannel()>=0) { - LLImageGL::generateTextures(1, &mDepthTexture); - gGL.getTexUnit(0)->bindManual(type, mDepthTexture); + mDepthTexture = LLImageGL::createTextureName(); + gGL.getTexUnit(0)->bindManual(type, mDepthTexture->getTexName()); LLImageGL::setManualImage(LLTexUnit::getInternalType(type), 0, GL_DEPTH_COMPONENT24, mScreenWidth, mScreenHeight, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL, false); stop_glerror(); gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_POINT); @@ -477,15 +474,9 @@ void LLPostProcess::createNoiseTexture() } } - if(mNoiseTexture) - { - LLImageGL::deleteTextures(1, &mNoiseTexture); - mNoiseTexture = 0; - } - - LLImageGL::generateTextures(1, &mNoiseTexture); + mNoiseTexture = LLImageGL::createTextureName(); stop_glerror(); - gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mNoiseTexture); + gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mNoiseTexture->getTexName()); stop_glerror(); LLImageGL::setManualImage(GL_TEXTURE_2D, 0, GL_LUMINANCE8, NOISE_SIZE, NOISE_SIZE, GL_LUMINANCE, GL_UNSIGNED_BYTE, &buffer[0], false); @@ -500,11 +491,8 @@ void LLPostProcess::destroyGL() { mRenderTarget[0].release(); mRenderTarget[1].release(); - if(mDepthTexture) - LLImageGL::deleteTextures(1, &mDepthTexture); - mDepthTexture=0; - if(mNoiseTexture) - LLImageGL::deleteTextures(1, &mNoiseTexture); + mDepthTexture.reset(); + mNoiseTexture.reset(); mNoiseTexture=0 ; mVBO = NULL ; } @@ -527,7 +515,7 @@ void LLPostProcess::copyFrameBuffer() { if((*it)->isEnabled() && (*it)->getDepthChannel()>=0) { - gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mDepthTexture); + gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mDepthTexture->getTexName()); glCopyTexSubImage2D(GL_TEXTURE_2D,0,0,0,0,0,mScreenWidth, mScreenHeight); stop_glerror(); break; @@ -539,7 +527,7 @@ void LLPostProcess::copyFrameBuffer() void LLPostProcess::bindNoise(U32 channel) { - gGL.getTexUnit(channel)->bindManual(LLTexUnit::TT_TEXTURE,mNoiseTexture); + gGL.getTexUnit(channel)->bindManual(LLTexUnit::TT_TEXTURE,mNoiseTexture->getTexName()); } void LLPostProcess::renderEffects(unsigned int width, unsigned int height) @@ -570,7 +558,7 @@ void LLPostProcess::doEffects(void) //Disable depth. Set blendmode to replace. LLGLDepthTest depth(GL_FALSE,GL_FALSE); - LLGLEnable blend(GL_BLEND); + LLGLEnable blend; gGL.setSceneBlendType(LLRender::BT_REPLACE); /// Change to an orthogonal view @@ -608,7 +596,7 @@ void LLPostProcess::applyShaders(void) S32 color_channel = (*it)->getColorChannel(); S32 depth_channel = (*it)->getDepthChannel(); if(depth_channel >= 0) - gGL.getTexUnit(depth_channel)->bindManual(LLTexUnit::TT_TEXTURE, mDepthTexture); + gGL.getTexUnit(depth_channel)->bindManual(LLTexUnit::TT_TEXTURE, mDepthTexture->getTexName()); U32 pass = 1; (*it)->bindShader(); diff --git a/indra/llrender/llpostprocess.h b/indra/llrender/llpostprocess.h index 57bd58ef0..14ea2881d 100644 --- a/indra/llrender/llpostprocess.h +++ b/indra/llrender/llpostprocess.h @@ -89,8 +89,8 @@ private: U32 mNextDrawTarget; //Need to pingpong between two rendertargets. Cannot sample target texture of currently bound FBO. // However this is ONLY the case if fbos are actually supported, else swapping isn't needed. LLRenderTarget mRenderTarget[2]; - U32 mDepthTexture; - U32 mNoiseTexture ; + LLImageGL::GLTextureName mDepthTexture; + LLImageGL::GLTextureName mNoiseTexture ; U32 mScreenWidth; U32 mScreenHeight; diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index d292b4952..dfa73ffa0 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -46,7 +46,7 @@ LLMatrix4a gGLLastModelView; LLMatrix4a gGLPreviousModelView; LLMatrix4a gGLLastProjection; LLMatrix4a gGLProjection; -S32 gGLViewport[4]; +LLRect gGLViewport; U32 LLRender::sUICalls = 0; U32 LLRender::sUIVerts = 0; @@ -54,7 +54,6 @@ U32 LLTexUnit::sWhiteTexture = 0; bool LLRender::sGLCoreProfile = false; static const U32 LL_NUM_TEXTURE_LAYERS = 32; -static const U32 LL_NUM_LIGHT_UNITS = 8; static const GLenum sGLTextureType[] = { @@ -99,6 +98,20 @@ static const GLenum sGLBlendFactor[] = GL_ZERO // 'BF_UNDEF' }; +static const GLenum sGLPolygonFaceType[] = +{ + GL_FRONT, + GL_BACK, + GL_FRONT_AND_BACK +}; + +static const GLenum sGLPolygonMode[] = +{ + GL_POINT, + GL_LINE, + GL_FILL +}; + LLTexUnit::LLTexUnit(S32 index) : mCurrTexType(TT_NONE), mCurrBlendType(TB_MULT), mCurrColorOp(TBO_MULT), mCurrAlphaOp(TBO_MULT), @@ -117,6 +130,8 @@ U32 LLTexUnit::getInternalType(eTextureType type) return sGLTextureType[type]; } +//void validate_bind_texture(U32 name); + void LLTexUnit::refreshState(void) { // We set dirty to true so that the tex unit knows to ignore caching @@ -140,6 +155,7 @@ void LLTexUnit::refreshState(void) glEnable(sGLTextureType[mCurrTexType]); } + //if (mCurrTexture) validate_bind_texture(mCurrTexture); glBindTexture(sGLTextureType[mCurrTexType], mCurrTexture); } else @@ -167,11 +183,12 @@ void LLTexUnit::activate(void) { if (mIndex < 0) return; - if ((S32)gGL.mCurrTextureUnitIndex != mIndex || gGL.mDirty) + if ((S32)gGL.getCurrentTexUnitIndex() != mIndex || gGL.mDirty) { //gGL.flush(); + // Apply immediately. glActiveTextureARB(GL_TEXTURE0_ARB + mIndex); - gGL.mCurrTextureUnitIndex = mIndex; + gGL.mContext.texUnit = gGL.mNewContext.texUnit = mIndex; } } @@ -251,6 +268,7 @@ bool LLTexUnit::bind(LLTexture* texture, bool for_rendering, bool forceBind) activate(); enable(gl_tex->getTarget()); mCurrTexture = gl_tex->getTexName(); + //validate_bind_texture(mCurrTexture); glBindTexture(sGLTextureType[gl_tex->getTarget()], mCurrTexture); if(gl_tex->updateBindStats(gl_tex->mTextureMemory)) { @@ -291,7 +309,6 @@ bool LLTexUnit::bind(LLTexture* texture, bool for_rendering, bool forceBind) bool LLTexUnit::bind(LLImageGL* texture, bool for_rendering, bool forceBind) { - stop_glerror(); if (mIndex < 0) return false; if(!texture) @@ -306,35 +323,27 @@ bool LLTexUnit::bind(LLImageGL* texture, bool for_rendering, bool forceBind) { return bind(LLImageGL::sDefaultGLTexture) ; } - stop_glerror(); return false ; } if ((mCurrTexture != texture->getTexName()) || forceBind) { gGL.flush(); - stop_glerror(); activate(); - stop_glerror(); enable(texture->getTarget()); - stop_glerror(); mCurrTexture = texture->getTexName(); + //validate_bind_texture(mCurrTexture); glBindTexture(sGLTextureType[texture->getTarget()], mCurrTexture); - stop_glerror(); texture->updateBindStats(texture->mTextureMemory); mHasMipMaps = texture->mHasMipMaps; if (texture->mTexOptionsDirty) { - stop_glerror(); texture->mTexOptionsDirty = false; setTextureAddressMode(texture->mAddressMode); setTextureFilteringOption(texture->mFilterOption); - stop_glerror(); } } - stop_glerror(); - return true; } @@ -361,6 +370,7 @@ bool LLTexUnit::bind(LLCubeMap* cubeMap) activate(); enable(LLTexUnit::TT_CUBE_MAP); mCurrTexture = cubeMap->mImages[0]->getTexName(); + //validate_bind_texture(mCurrTexture); glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, mCurrTexture); mHasMipMaps = cubeMap->mImages[0]->mHasMipMaps; cubeMap->mImages[0]->updateBindStats(cubeMap->mImages[0]->mTextureMemory); @@ -421,6 +431,7 @@ bool LLTexUnit::bindManual(eTextureType type, U32 texture, bool hasMips) activate(); enable(type); mCurrTexture = texture; + //validate_bind_texture(texture); glBindTexture(sGLTextureType[type], texture); mHasMipMaps = hasMips; } @@ -429,13 +440,11 @@ bool LLTexUnit::bindManual(eTextureType type, U32 texture, bool hasMips) void LLTexUnit::unbind(eTextureType type) { - stop_glerror(); - if (mIndex < 0) return; //always flush and activate for consistency // some code paths assume unbind always flushes and sets the active texture - if (gGL.mCurrTextureUnitIndex != mIndex || gGL.mDirty) + if (gGL.getCurrentTexUnitIndex() != mIndex || gGL.mDirty) { gGL.flush(); activate(); @@ -448,13 +457,14 @@ void LLTexUnit::unbind(eTextureType type) mCurrTexture = 0; if (LLGLSLShader::sNoFixedFunction && type == LLTexUnit::TT_TEXTURE) { + //if (sWhiteTexture) + // validate_bind_texture(sWhiteTexture); glBindTexture(sGLTextureType[type], sWhiteTexture); } else { glBindTexture(sGLTextureType[type], 0); } - stop_glerror(); } } @@ -543,7 +553,7 @@ void LLTexUnit::setTextureBlendType(eTextureBlendType type) return; } - if (mIndex < 0) return; + if (mIndex < 0 || mIndex >= gGLManager.mNumTextureUnits) return; // Do nothing if it's already correctly set. if (mCurrBlendType == type && !gGL.mDirty) @@ -668,7 +678,7 @@ void LLTexUnit::setTextureCombiner(eTextureBlendOp op, eTextureBlendSrc src1, eT return; } - if (mIndex < 0) return; + if (mIndex < 0 || mIndex >= gGLManager.mNumTextureUnits) return; activate(); if (mCurrBlendType != TB_COMBINE || gGL.mDirty) @@ -818,8 +828,8 @@ void LLTexUnit::setColorScale(S32 scale) { if (mCurrColorScale != scale || gGL.mDirty) { - mCurrColorScale = scale; gGL.flush(); + mCurrColorScale = scale; glTexEnvi( GL_TEXTURE_ENV, GL_RGB_SCALE, scale ); } } @@ -828,8 +838,8 @@ void LLTexUnit::setAlphaScale(S32 scale) { if (mCurrAlphaScale != scale || gGL.mDirty) { - mCurrAlphaScale = scale; gGL.flush(); + mCurrAlphaScale = scale; glTexEnvi( GL_TEXTURE_ENV, GL_ALPHA_SCALE, scale ); } } @@ -849,203 +859,90 @@ void LLTexUnit::debugTextureUnit(void) } } -LLLightState::LLLightState(S32 index) -: mIndex(index), - mEnabled(false), - mConstantAtten(1.f), - mLinearAtten(0.f), - mQuadraticAtten(0.f), - mSpotExponent(0.f), - mSpotCutoff(180.f) +LLLightState::LLLightState(S32 index) : + mState(index), + mIndex(index) { - if (mIndex == 0) - { - mDiffuse.set(1,1,1,1); - mSpecular.set(1,1,1,1); - } - - mAmbient.set(0,0,0,1); - mPosition.set(0,0,1,0); - mSpotDirection.set(0,0,-1); + mPosMatrix.setIdentity(); + mSpotMatrix.setIdentity(); } -void LLLightState::enable() -{ - if (!mEnabled) - { - if (!LLGLSLShader::sNoFixedFunction) - { - glEnable(GL_LIGHT0+mIndex); - } - mEnabled = true; +#define UPDATE_LIGHTSTATE(state, value) \ + if (mState.state != value) { \ + mState.state = value; \ + ++gGL.mLightHash; \ } -} -void LLLightState::disable() -{ - if (mEnabled) - { - if (!LLGLSLShader::sNoFixedFunction) - { - glDisable(GL_LIGHT0+mIndex); - } - mEnabled = false; +#define UPDATE_LIGHTSTATE_AND_TRANSFORM(state, value, matrix, transformhash) \ + if (mState.state != value || memcmp(matrix.getF32ptr(), gGL.getModelviewMatrix().getF32ptr(), sizeof(LLMatrix4a))) { \ + mState.state = value; \ + ++gGL.mLightHash; \ + ++gGL.transformhash[mIndex]; \ + matrix = gGL.getModelviewMatrix(); \ } -} void LLLightState::setDiffuse(const LLColor4& diffuse) { - if (mDiffuse != diffuse) - { - ++gGL.mLightHash; - mDiffuse = diffuse; - if (!LLGLSLShader::sNoFixedFunction) - { - glLightfv(GL_LIGHT0+mIndex, GL_DIFFUSE, mDiffuse.mV); - } - } -} - -void LLLightState::setAmbient(const LLColor4& ambient) -{ - if (mAmbient != ambient) - { - ++gGL.mLightHash; - mAmbient = ambient; - if (!LLGLSLShader::sNoFixedFunction) - { - glLightfv(GL_LIGHT0+mIndex, GL_AMBIENT, mAmbient.mV); - } - } + UPDATE_LIGHTSTATE(mDiffuse, diffuse); } void LLLightState::setSpecular(const LLColor4& specular) { - if (mSpecular != specular) - { - ++gGL.mLightHash; - mSpecular = specular; - if (!LLGLSLShader::sNoFixedFunction) - { - glLightfv(GL_LIGHT0+mIndex, GL_SPECULAR, mSpecular.mV); - } - } + UPDATE_LIGHTSTATE(mSpecular, specular); } void LLLightState::setPosition(const LLVector4& position) { - //always set position because modelview matrix may have changed - ++gGL.mLightHash; - mPosition = position; - if (!LLGLSLShader::sNoFixedFunction) - { - glLightfv(GL_LIGHT0+mIndex, GL_POSITION, mPosition.mV); - } - else - { //transform position by current modelview matrix - LLVector4a pos; - pos.loadua(position.mV); - - gGL.getModelviewMatrix().rotate4(pos,pos); - - mPosition.set(pos.getF32ptr()); - } - + UPDATE_LIGHTSTATE_AND_TRANSFORM(mPosition, position, mPosMatrix, mLightPositionTransformHash); } void LLLightState::setConstantAttenuation(const F32& atten) { - if (mConstantAtten != atten) - { - mConstantAtten = atten; - ++gGL.mLightHash; - if (!LLGLSLShader::sNoFixedFunction) - { - glLightf(GL_LIGHT0+mIndex, GL_CONSTANT_ATTENUATION, atten); - } - } + UPDATE_LIGHTSTATE(mConstantAtten, atten); } void LLLightState::setLinearAttenuation(const F32& atten) { - if (mLinearAtten != atten) - { - ++gGL.mLightHash; - mLinearAtten = atten; - if (!LLGLSLShader::sNoFixedFunction) - { - glLightf(GL_LIGHT0+mIndex, GL_LINEAR_ATTENUATION, atten); - } - } + UPDATE_LIGHTSTATE(mLinearAtten, atten); } void LLLightState::setQuadraticAttenuation(const F32& atten) { - if (mQuadraticAtten != atten) - { - ++gGL.mLightHash; - mQuadraticAtten = atten; - if (!LLGLSLShader::sNoFixedFunction) - { - glLightf(GL_LIGHT0+mIndex, GL_QUADRATIC_ATTENUATION, atten); - } - } + UPDATE_LIGHTSTATE(mQuadraticAtten, atten); } void LLLightState::setSpotExponent(const F32& exponent) { - if (mSpotExponent != exponent) - { - ++gGL.mLightHash; - mSpotExponent = exponent; - if (!LLGLSLShader::sNoFixedFunction) - { - glLightf(GL_LIGHT0+mIndex, GL_SPOT_EXPONENT, exponent); - } - } + UPDATE_LIGHTSTATE(mSpotExponent, exponent); } void LLLightState::setSpotCutoff(const F32& cutoff) { - if (mSpotCutoff != cutoff) - { - ++gGL.mLightHash; - mSpotCutoff = cutoff; - if (!LLGLSLShader::sNoFixedFunction) - { - glLightf(GL_LIGHT0+mIndex, GL_SPOT_CUTOFF, cutoff); - } - } + UPDATE_LIGHTSTATE(mSpotCutoff, cutoff); } void LLLightState::setSpotDirection(const LLVector3& direction) { - //always set direction because modelview matrix may have changed - ++gGL.mLightHash; - mSpotDirection = direction; - if (!LLGLSLShader::sNoFixedFunction) + UPDATE_LIGHTSTATE_AND_TRANSFORM(mSpotDirection, direction, mSpotMatrix, mLightSpotTransformHash); +} + +void LLLightState::setEnabled(const bool enabled) +{ + if (mEnabled != enabled) { - glLightfv(GL_LIGHT0+mIndex, GL_SPOT_DIRECTION, direction.mV); - } - else - { //transform direction by current modelview matrix - LLVector4a dir; - dir.load3(direction.mV); - - gGL.getModelviewMatrix().rotate(dir,dir); - - mSpotDirection.set(dir.getF32ptr()); + mEnabled = enabled; + ++gGL.mLightHash; } } -LLRender::eBlendFactor blendfunc_debug[4]={LLRender::BF_UNDEF}; + LLRender::LLRender() : mDirty(false), mCount(0), mMode(LLRender::TRIANGLES), - mCurrTextureUnitIndex(0), + mMatrixMode(LLRender::MM_MODELVIEW), + mMatIdx{ 0 }, mMaxAnisotropy(0.f), - mLineWidth(1.f), mPrimitiveReset(false) { mTexUnits.reserve(LL_NUM_TEXTURE_LAYERS); @@ -1055,33 +952,12 @@ LLRender::LLRender() } mDummyTexUnit = new LLTexUnit(-1); - for (U32 i = 0; i < LL_NUM_LIGHT_UNITS; ++i) + for (U32 i = 0; i < NUM_LIGHTS; ++i) { mLightState.push_back(new LLLightState(i)); } - - for (U32 i = 0; i < 4; i++) - { - mCurrColorMask[i] = true; - } - - mCurrAlphaFunc = CF_DEFAULT; - mCurrAlphaFuncVal = 0.01f; - mCurrBlendColorSFactor = BF_UNDEF; - mCurrBlendAlphaSFactor = BF_UNDEF; - mCurrBlendColorDFactor = BF_UNDEF; - mCurrBlendAlphaDFactor = BF_UNDEF; - - mMatrixMode = LLRender::MM_MODELVIEW; - for (U32 i = 0; i < NUM_MATRIX_MODES; ++i) - { - mMatIdx[i] = 0; - mMatHash[i] = 0; - mCurMatHash[i] = 0xFFFFFFFF; - } - - mLightHash = 0; + resetSyncHashes(); //Init base matrix for each mode for(S32 i = 0; i < NUM_MATRIX_MODES; ++i) @@ -1111,6 +987,7 @@ void LLRender::init() glBindVertexArray(ret); #endif } + stop_glerror(); restoreVertexBuffers(); } @@ -1132,25 +1009,48 @@ void LLRender::shutdown() mBuffer = NULL ; } +void LLRender::destroyGL() +{ + // Reset gl state cache + mCurShader = 0; + mContext = Context(); + resetSyncHashes(); + LLTexUnit::sWhiteTexture = 0; // Also done in LLImageGL::destroyGL. + for (auto unit : mTexUnits) + { + if (unit->getCurrTexture() > 0) + { + unit->unbind(unit->getCurrType()); + } + } + + resetVertexBuffers(); +} + void LLRender::refreshState(void) { mDirty = true; - U32 active_unit = mCurrTextureUnitIndex; + U32 active_unit = getCurrentTexUnitIndex(); for (U32 i = 0; i < mTexUnits.size(); i++) { mTexUnits[i]->refreshState(); + stop_glerror(); } mTexUnits[active_unit]->activate(); + stop_glerror(); - setColorMask(mCurrColorMask[0], mCurrColorMask[1], mCurrColorMask[2], mCurrColorMask[3]); + /*setColorMask(mCurrColorMask[0], mCurrColorMask[1], mCurrColorMask[2], mCurrColorMask[3]); + stop_glerror(); setAlphaRejectSettings(mCurrAlphaFunc, mCurrAlphaFuncVal); + stop_glerror(); //Singu note: Also reset glBlendFunc blendFunc(mCurrBlendColorSFactor,mCurrBlendColorDFactor,mCurrBlendAlphaSFactor,mCurrBlendAlphaDFactor); + stop_glerror();*/ mDirty = false; } @@ -1162,48 +1062,233 @@ void LLRender::resetVertexBuffers() void LLRender::restoreVertexBuffers() { - llassert_always(mBuffer.isNull()); + if (!mBuffer.isNull()) + return; stop_glerror(); mBuffer = new LLVertexBuffer(immediate_mask, 0); + stop_glerror(); mBuffer->allocateBuffer(4096, 0, TRUE); + stop_glerror(); mBuffer->getVertexStrider(mVerticesp); + stop_glerror(); mBuffer->getTexCoord0Strider(mTexcoordsp); + stop_glerror(); mBuffer->getColorStrider(mColorsp); stop_glerror(); } +void LLRender::syncShaders() +{ + if (mCurShader != mNextShader) + { + glUseProgramObjectARB(mNextShader); + mCurShader = mNextShader; + } +} + +void LLRender::syncContextState() +{ + if (mContext.color != mNewContext.color) + { + mContext.color = mNewContext.color; + glColor4fv(mContext.color.mV); + } + if (mContext.colorMask != mNewContext.colorMask) + { + mContext.colorMask = mNewContext.colorMask; + glColorMask( + mContext.colorMask & (1 << 0), + mContext.colorMask & (1 << 1), + mContext.colorMask & (1 << 2), + mContext.colorMask & (1 << 3)); + } + if (mContext.alphaFunc != mNewContext.alphaFunc || + mContext.alphaVal != mNewContext.alphaVal) + { + mContext.alphaFunc = mNewContext.alphaFunc; + mContext.alphaVal = mNewContext.alphaVal; + if (mContext.alphaFunc == CF_DEFAULT) + { + glAlphaFunc(GL_GREATER, 0.01f); + } + else + { + glAlphaFunc(sGLCompareFunc[mContext.alphaFunc], mContext.alphaVal); + } + } + if (LLGLState::isEnabled() && ( + mContext.blendColorSFactor != mNewContext.blendColorSFactor || + mContext.blendAlphaSFactor != mNewContext.blendAlphaSFactor || + mContext.blendColorDFactor != mNewContext.blendColorDFactor || + mContext.blendAlphaDFactor != mNewContext.blendAlphaDFactor)) + { + mContext.blendColorSFactor = mNewContext.blendColorSFactor; + mContext.blendAlphaSFactor = mNewContext.blendAlphaSFactor; + mContext.blendColorDFactor = mNewContext.blendColorDFactor; + mContext.blendAlphaDFactor = mNewContext.blendAlphaDFactor; + if (mContext.blendColorSFactor == mContext.blendAlphaSFactor && + mContext.blendColorDFactor == mContext.blendAlphaDFactor) + { + glBlendFunc(sGLBlendFactor[mContext.blendColorSFactor], sGLBlendFactor[mContext.blendColorDFactor]); + } + else + { + glBlendFuncSeparateEXT(sGLBlendFactor[mContext.blendColorSFactor], sGLBlendFactor[mContext.blendColorDFactor], + sGLBlendFactor[mContext.blendAlphaSFactor], sGLBlendFactor[mContext.blendAlphaDFactor]); + } + } + if (mContext.lineWidth != mNewContext.lineWidth) + { + mContext.lineWidth = mNewContext.lineWidth; + glLineWidth(mContext.lineWidth); + } + if (mContext.pointSize != mNewContext.pointSize) + { + mContext.pointSize = mNewContext.pointSize; + glPointSize(mContext.pointSize); + } + if (mContext.polygonMode[0] != mNewContext.polygonMode[0] || mContext.polygonMode[1] != mNewContext.polygonMode[1]) + { + if (mNewContext.polygonMode[0] == mNewContext.polygonMode[1]) + { + glPolygonMode(GL_FRONT_AND_BACK, sGLPolygonMode[mNewContext.polygonMode[0]]); + } + else + { + if (mContext.polygonMode[0] != mNewContext.polygonMode[0]) + { + glPolygonMode(GL_FRONT, sGLPolygonMode[mNewContext.polygonMode[0]]); + } + if (mContext.polygonMode[1] != mNewContext.polygonMode[1]) + { + glPolygonMode(GL_BACK, sGLPolygonMode[mNewContext.polygonMode[1]]); + } + } + + mContext.polygonMode[0] = mNewContext.polygonMode[0]; + mContext.polygonMode[1] = mNewContext.polygonMode[1]; + } + if (mContext.polygonOffset[0] != mNewContext.polygonOffset[0] || mContext.polygonOffset[1] != mNewContext.polygonOffset[1]) + { + mContext.polygonOffset[0] = mNewContext.polygonOffset[0]; + mContext.polygonOffset[1] = mNewContext.polygonOffset[1]; + glPolygonOffset(mContext.polygonOffset[0], mContext.polygonOffset[1]); + } + if (mContext.viewPort != mNewContext.viewPort) + { + mContext.viewPort = mNewContext.viewPort; + glViewport(mContext.viewPort.mLeft, mContext.viewPort.mBottom, mContext.viewPort.getWidth(), mContext.viewPort.getHeight()); + } + if (LLGLState::isEnabled() && mContext.scissor != mNewContext.scissor) + { + mContext.scissor = mNewContext.scissor; + glScissor(mContext.scissor.mLeft, mContext.scissor.mBottom, mContext.scissor.getWidth(), mContext.scissor.getHeight()); + } +} + +U32 sLightMask = 0xFFFFFFFF; void LLRender::syncLightState() { - LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr; - - if (!shader) + if (!LLGLSLShader::sNoFixedFunction) { + // Legacy + if (mCurLegacyLightHash != mLightHash) + { + mCurLegacyLightHash = mLightHash; + for (U32 i = 0; i < NUM_LIGHTS; i++) + { + const LLLightState* light = mLightState[i]; + const U32 idx = GL_LIGHT0 + i; + const LLLightStateData& state = light->mState; + + if (light->mEnabled && (1 << i) & sLightMask) { + glEnable(idx); + if (mLightSpotTransformHash[i] != mCurLightSpotTransformHash[i] || + mLightPositionTransformHash[i] != mCurLightPositionTransformHash[i]) + { + + glPushAttrib(GL_TRANSFORM_BIT); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + if (mLightPositionTransformHash[i] != mCurLightPositionTransformHash[i]) + { + glLoadMatrixf(light->mPosMatrix.getF32ptr()); + glLightfv(idx, GL_POSITION, state.mPosition.mV); + } + if (mLightSpotTransformHash[i] != mCurLightSpotTransformHash[i]) + { + glLoadMatrixf(light->mSpotMatrix.getF32ptr()); + glLightfv(idx, GL_SPOT_DIRECTION, state.mSpotDirection.mV); + } + mCurLightPositionTransformHash[i] = mLightPositionTransformHash[i]; + mCurLightSpotTransformHash[i] = mLightSpotTransformHash[i]; + + glPopMatrix(); + glPopAttrib(); + } + glLightfv(idx, GL_DIFFUSE, state.mDiffuse.mV); + glLightfv(idx, GL_SPECULAR, state.mSpecular.mV); + glLightf(idx, GL_CONSTANT_ATTENUATION, state.mConstantAtten); + glLightf(idx, GL_LINEAR_ATTENUATION, state.mLinearAtten); + glLightf(idx, GL_QUADRATIC_ATTENUATION, state.mQuadraticAtten); + glLightf(idx, GL_SPOT_EXPONENT, state.mSpotExponent); + glLightf(idx, GL_SPOT_CUTOFF, state.mSpotCutoff); + } + else + { + glDisable(idx); + } + } + + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, mAmbientLightColor.mV); + } return; } + LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr; + if (!shader || (!shader->mFeatures.hasLighting && !shader->mFeatures.calculatesLighting)) + { + return; + } if (shader->mLightHash != mLightHash) { shader->mLightHash = mLightHash; - LLVector4 position[8]; - LLVector3 direction[8]; LLVector3 attenuation[8]; LLVector3 diffuse[8]; - for (U32 i = 0; i < 8; i++) + for (U32 i = 0; i < NUM_LIGHTS; i++) { - LLLightState* light = mLightState[i]; + const LLLightState* light = mLightState[i]; + const LLLightStateData& state = light->mState; - position[i] = light->mPosition; - direction[i] = light->mSpotDirection; - attenuation[i].set(light->mLinearAtten, light->mQuadraticAtten, light->mSpecular.mV[3]); - diffuse[i].set(light->mDiffuse.mV); + attenuation[i].set(state.mLinearAtten, state.mQuadraticAtten, state.mSpecular.mV[3]); + diffuse[i].set((light->mEnabled && (1 << i) & sLightMask) ? state.mDiffuse.mV : LLVector3::zero.mV); + + if (mLightPositionTransformHash[i] != mCurLightPositionTransformHash[i]) + { + LLVector4a pos; + pos.loadua(state.mPosition.mV); + light->mPosMatrix.rotate4(pos, pos); + mCurLightPosition[i].set(pos.getF32ptr()); + mCurLightPositionTransformHash[i] = mLightPositionTransformHash[i]; + } + // If state.mSpecular.mV[3] == 0.f then this light is a spotlight, thus update the direction... + // Otherwise don't bother and leave the hash stale in case it turns into a spotlight later. + if (state.mSpecular.mV[3] == 0.f && mLightSpotTransformHash[i] != mCurLightSpotTransformHash[i]) + { + LLVector4a dir; + dir.load3(state.mSpotDirection.mV); + light->mSpotMatrix.rotate(dir, dir); + mCurSpotDirection[i].set(dir.getF32ptr()); + mCurLightSpotTransformHash[i] = mLightSpotTransformHash[i]; + } } - shader->uniform4fv(LLShaderMgr::LIGHT_POSITION, 8, position[0].mV); - shader->uniform3fv(LLShaderMgr::LIGHT_DIRECTION, 8, direction[0].mV); - shader->uniform3fv(LLShaderMgr::LIGHT_ATTENUATION, 8, attenuation[0].mV); - shader->uniform3fv(LLShaderMgr::LIGHT_DIFFUSE, 8, diffuse[0].mV); + shader->uniform4fv(LLShaderMgr::LIGHT_POSITION, NUM_LIGHTS, mCurLightPosition[0].mV); + shader->uniform3fv(LLShaderMgr::LIGHT_DIRECTION, NUM_LIGHTS, mCurSpotDirection[0].mV); + shader->uniform3fv(LLShaderMgr::LIGHT_ATTENUATION, NUM_LIGHTS, attenuation[0].mV); + shader->uniform3fv(LLShaderMgr::LIGHT_DIFFUSE, NUM_LIGHTS, diffuse[0].mV); shader->uniform4fv(LLShaderMgr::LIGHT_AMBIENT, 1, mAmbientLightColor.mV); //HACK -- duplicate sunlight color for compatibility with drivers that can't deal with multiple shader objects referencing the same uniform shader->uniform3fv(LLShaderMgr::SUNLIGHT_COLOR, 1, diffuse[0].mV); @@ -1214,6 +1299,8 @@ void LLRender::syncMatrices() { stop_glerror(); + syncShaders(); + static const U32 name[] = { LLShaderMgr::MODELVIEW_MATRIX, @@ -1322,12 +1409,6 @@ void LLRender::syncMatrices() shader->mMatHash[i] = mMatHash[i]; } } - - - if (shader->mFeatures.hasLighting || shader->mFeatures.calculatesLighting) - { //also sync light state - syncLightState(); - } } else if (!LLGLSLShader::sNoFixedFunction) { @@ -1343,26 +1424,31 @@ void LLRender::syncMatrices() for (U32 i = 0; i < 2; ++i) { - if (mMatHash[i] != mCurMatHash[i]) + if (mMatHash[i] != mCurLegacyMatHash[i]) { glMatrixMode(mode[i]); glLoadMatrixf(mMatrix[i][mMatIdx[i]].getF32ptr()); - mCurMatHash[i] = mMatHash[i]; + mCurLegacyMatHash[i] = mMatHash[i]; } } for (U32 i = 2; i < NUM_MATRIX_MODES; ++i) { - if (mMatHash[i] != mCurMatHash[i]) + if (mMatHash[i] != mCurLegacyMatHash[i]) { gGL.getTexUnit(i-2)->activate(); glMatrixMode(mode[i]); glLoadMatrixf(mMatrix[i][mMatIdx[i]].getF32ptr()); - mCurMatHash[i] = mMatHash[i]; + mCurLegacyMatHash[i] = mMatHash[i]; } } } + //also sync light state + syncLightState(); + //sync context. + syncContextState(); + stop_glerror(); } @@ -1866,21 +1952,11 @@ void LLRender::setColorMask(bool writeColor, bool writeAlpha) void LLRender::setColorMask(bool writeColorR, bool writeColorG, bool writeColorB, bool writeAlpha) { - if (mCurrColorMask[0] != writeColorR || - mCurrColorMask[1] != writeColorG || - mCurrColorMask[2] != writeColorB || - mCurrColorMask[3] != writeAlpha || mDirty) + const U8 mask = (U8)writeColorR | ((U8)writeColorG << 1) | ((U8)writeColorB << 2) | ((U8)writeAlpha << 3); + if (mNewContext.colorMask != mask || mDirty) { - mCurrColorMask[0] = writeColorR; - mCurrColorMask[1] = writeColorG; - mCurrColorMask[2] = writeColorB; - mCurrColorMask[3] = writeAlpha; - flush(); - glColorMask(writeColorR ? GL_TRUE : GL_FALSE, - writeColorG ? GL_TRUE : GL_FALSE, - writeColorB ? GL_TRUE : GL_FALSE, - writeAlpha ? GL_TRUE : GL_FALSE); + mNewContext.colorMask = mask; } } @@ -1922,23 +1998,15 @@ void LLRender::setAlphaRejectSettings(eCompareFunc func, F32 value) return; } - if (mCurrAlphaFunc != func || - mCurrAlphaFuncVal != value || mDirty) + if (mNewContext.alphaFunc != func || + mNewContext.alphaVal != value || mDirty) { flush(); - mCurrAlphaFunc = func; - mCurrAlphaFuncVal = value; - if (func == CF_DEFAULT) - { - glAlphaFunc(GL_GREATER, 0.01f); - } - else - { - glAlphaFunc(sGLCompareFunc[func], value); - } + mNewContext.alphaFunc = func; + mNewContext.alphaVal = value; } - if (gDebugGL) + /*if (gDebugGL) { //make sure cached state is correct GLint cur_func = 0; glGetIntegerv(GL_ALPHA_TEST_FUNC, &cur_func); @@ -1960,32 +2028,53 @@ void LLRender::setAlphaRejectSettings(eCompareFunc func, F32 value) { LL_ERRS() << "Alpha test value corrupted!" << LL_ENDL; } + }*/ +} + +void LLRender::setViewport(const LLRect& rect) +{ + if (mNewContext.viewPort != rect || mDirty) + { + flush(); + mNewContext.viewPort = rect; + } +} + +void LLRender::setScissor(const LLRect& rect) +{ + if (mNewContext.scissor != rect || mDirty) + { + if (LLGLState::isEnabled()) + { + flush(); + } + mNewContext.scissor = rect; } } void check_blend_funcs() { - llassert_always(blendfunc_debug[0] == LLRender::BF_SOURCE_ALPHA ); - llassert_always(blendfunc_debug[1] == LLRender::BF_SOURCE_ALPHA ); - llassert_always(blendfunc_debug[2] == LLRender::BF_ONE_MINUS_SOURCE_ALPHA ); - llassert_always(blendfunc_debug[3] == LLRender::BF_ONE_MINUS_SOURCE_ALPHA ); + llassert_always(gGL.mNewContext.blendColorSFactor == LLRender::BF_SOURCE_ALPHA ); + llassert_always(gGL.mNewContext.blendAlphaSFactor == LLRender::BF_SOURCE_ALPHA ); + llassert_always(gGL.mNewContext.blendColorDFactor == LLRender::BF_ONE_MINUS_SOURCE_ALPHA); + llassert_always(gGL.mNewContext.blendAlphaDFactor == LLRender::BF_ONE_MINUS_SOURCE_ALPHA ); } void LLRender::blendFunc(eBlendFactor sfactor, eBlendFactor dfactor) { llassert(sfactor < BF_UNDEF); llassert(dfactor < BF_UNDEF); - if (mCurrBlendColorSFactor != sfactor || mCurrBlendColorDFactor != dfactor || - mCurrBlendAlphaSFactor != sfactor || mCurrBlendAlphaDFactor != dfactor || mDirty) + if (mNewContext.blendColorSFactor != sfactor || mNewContext.blendColorDFactor != dfactor || + mNewContext.blendAlphaSFactor != sfactor || mNewContext.blendAlphaDFactor != dfactor || mDirty) { - mCurrBlendColorSFactor = sfactor; - mCurrBlendAlphaSFactor = sfactor; - mCurrBlendColorDFactor = dfactor; - mCurrBlendAlphaDFactor = dfactor; - blendfunc_debug[0]=blendfunc_debug[1]=sfactor; - blendfunc_debug[2]=blendfunc_debug[3]=dfactor; - flush(); - glBlendFunc(sGLBlendFactor[sfactor], sGLBlendFactor[dfactor]); + if (LLGLState::isEnabled()) + { + flush(); + } + mNewContext.blendColorSFactor = sfactor; + mNewContext.blendAlphaSFactor = sfactor; + mNewContext.blendColorDFactor = dfactor; + mNewContext.blendAlphaDFactor = dfactor; } } @@ -2002,20 +2091,17 @@ void LLRender::blendFunc(eBlendFactor color_sfactor, eBlendFactor color_dfactor, blendFunc(color_sfactor, color_dfactor); return; } - if (mCurrBlendColorSFactor != color_sfactor || mCurrBlendColorDFactor != color_dfactor || - mCurrBlendAlphaSFactor != alpha_sfactor || mCurrBlendAlphaDFactor != alpha_dfactor || mDirty) + if (mNewContext.blendColorSFactor != color_sfactor || mNewContext.blendColorDFactor != color_dfactor || + mNewContext.blendAlphaSFactor != alpha_sfactor || mNewContext.blendAlphaDFactor != alpha_dfactor || mDirty) { - mCurrBlendColorSFactor = color_sfactor; - mCurrBlendAlphaSFactor = alpha_sfactor; - mCurrBlendColorDFactor = color_dfactor; - mCurrBlendAlphaDFactor = alpha_dfactor; - blendfunc_debug[0]=color_sfactor; - blendfunc_debug[1]=alpha_sfactor; - blendfunc_debug[2]=color_dfactor; - blendfunc_debug[3]=alpha_dfactor; - flush(); - glBlendFuncSeparateEXT(sGLBlendFactor[color_sfactor], sGLBlendFactor[color_dfactor], - sGLBlendFactor[alpha_sfactor], sGLBlendFactor[alpha_dfactor]); + if (LLGLState::isEnabled()) + { + flush(); + } + mNewContext.blendColorSFactor = color_sfactor; + mNewContext.blendAlphaSFactor = alpha_sfactor; + mNewContext.blendColorDFactor = color_dfactor; + mNewContext.blendAlphaDFactor = alpha_dfactor; } } @@ -2044,43 +2130,82 @@ LLLightState* LLRender::getLight(U32 index) void LLRender::setAmbientLightColor(const LLColor4& color) { - if (color != mAmbientLightColor) + if (color != mAmbientLightColor || mDirty) { ++mLightHash; mAmbientLightColor = color; - if (!LLGLSLShader::sNoFixedFunction) - { - glLightModelfv(GL_LIGHT_MODEL_AMBIENT, color.mV); - } } } void LLRender::setLineWidth(F32 line_width) { - if (LLRender::sGLCoreProfile) + //if (LLRender::sGLCoreProfile) { - line_width = 1.f; + mNewContext.lineWidth = 1.f; + return; } - if (mLineWidth != line_width) + if (mNewContext.lineWidth != line_width || mDirty) { if (mMode == LLRender::LINES || LLRender::LINE_STRIP) { flush(); } - mLineWidth = line_width; - glLineWidth(line_width); + mNewContext.lineWidth = line_width; + } +} + +void LLRender::setPointSize(F32 point_size) +{ + if (mNewContext.pointSize != point_size || mDirty) + { + if (mMode == LLRender::POINTS) + { + flush(); + } + mNewContext.pointSize = point_size; + } +} + +void LLRender::setPolygonMode(ePolygonFaceType type, ePolygonMode mode) +{ + ePolygonMode newMode[] = { + (type == PF_FRONT_AND_BACK || type == PF_FRONT) ? mode : mNewContext.polygonMode[0], + (type == PF_FRONT_AND_BACK || type == PF_BACK) ? mode : mNewContext.polygonMode[1] + }; + + if (newMode[0] != mNewContext.polygonMode[0] || newMode[1] != mNewContext.polygonMode[1] || mDirty) + { + flush(); + mNewContext.polygonMode[0] = newMode[0]; + mNewContext.polygonMode[1] = newMode[1]; + } +} + +void LLRender::setPolygonOffset(F32 factor, F32 bias) +{ + if (factor != mNewContext.polygonOffset[0] || + bias != mNewContext.polygonOffset[1] || mDirty) + { + if (LLGLState::isEnabled() || + LLGLState::isEnabled() /*|| + Unused: LLGLState::isEnabled()*/ ) + { + flush(); + } + mNewContext.polygonOffset[0] = factor; + mNewContext.polygonOffset[1] = bias; } } bool LLRender::verifyTexUnitActive(U32 unitToVerify) { - if (mCurrTextureUnitIndex == unitToVerify) + if (getCurrentTexUnitIndex() == unitToVerify) { return true; } else { - LL_WARNS() << "TexUnit currently active: " << mCurrTextureUnitIndex << " (expecting " << unitToVerify << ")" << LL_ENDL; + LL_WARNS() << "TexUnit currently active: " << getCurrentTexUnitIndex() << " (expecting " << unitToVerify << ")" << LL_ENDL; return false; } } @@ -2093,6 +2218,17 @@ void LLRender::clearErrors() } } +void LLRender::resetSyncHashes() { + memset(&mLightHash, 0, sizeof(mLightHash)); + memset(&mCurLegacyLightHash, 0xFF, sizeof(mCurLegacyLightHash)); + memset(mMatHash, 0, sizeof(mMatHash)); + memset(mCurLegacyMatHash, 0xFF, sizeof(mCurLegacyMatHash)); + memset(mLightPositionTransformHash, 0, sizeof(mLightPositionTransformHash)); + memset(mCurLightPositionTransformHash, 0xFF, sizeof(mCurLightPositionTransformHash)); + memset(mLightSpotTransformHash, 0, sizeof(mLightSpotTransformHash)); + memset(mCurLightSpotTransformHash, 0xFF, sizeof(mLightSpotTransformHash)); +} + void LLRender::begin(const GLuint& mode) { if (mode != mMode) @@ -2499,9 +2635,10 @@ void LLRender::diffuseColor3f(F32 r, F32 g, F32 b) { shader->uniform4f(LLShaderMgr::DIFFUSE_COLOR, r,g,b,1.f); } - else + else if (r != mNewContext.color.mV[0] || g != mNewContext.color.mV[1] || b != mNewContext.color.mV[2] || mNewContext.color.mV[3] != 1.f || mDirty) { - glColor3f(r,g,b); + flush(); + mNewContext.color.set(r, g, b, 1.f); } } @@ -2514,9 +2651,10 @@ void LLRender::diffuseColor3fv(const F32* c) { shader->uniform4f(LLShaderMgr::DIFFUSE_COLOR, c[0], c[1], c[2], 1.f); } - else + else if (c[0] != mNewContext.color.mV[0] || c[1] != mNewContext.color.mV[1] || c[2] != mNewContext.color.mV[2] || mNewContext.color.mV[3] != 1.f || mDirty) { - glColor3fv(c); + flush(); + mNewContext.color.set(c[0], c[1], c[2], 1.f); } } @@ -2529,9 +2667,10 @@ void LLRender::diffuseColor4f(F32 r, F32 g, F32 b, F32 a) { shader->uniform4f(LLShaderMgr::DIFFUSE_COLOR, r,g,b,a); } - else + else if (r != mNewContext.color.mV[0] || g != mNewContext.color.mV[1] || b != mNewContext.color.mV[2] || a != mNewContext.color.mV[3] || mDirty) { - glColor4f(r,g,b,a); + flush(); + mNewContext.color = { r, g, b, a }; } } @@ -2544,9 +2683,10 @@ void LLRender::diffuseColor4fv(const F32* c) { shader->uniform4fv(LLShaderMgr::DIFFUSE_COLOR, 1, c); } - else + else if (c[0] != mNewContext.color.mV[0] || c[1] != mNewContext.color.mV[1] || c[2] != mNewContext.color.mV[2] || c[3] != mNewContext.color.mV[3] || mDirty) { - glColor4fv(c); + flush(); + mNewContext.color = c; } } @@ -2559,9 +2699,13 @@ void LLRender::diffuseColor4ubv(const U8* c) { shader->uniform4f(LLShaderMgr::DIFFUSE_COLOR, c[0]/255.f, c[1]/255.f, c[2]/255.f, c[3]/255.f); } - else + else if (c[0] / 255.f != mNewContext.color.mV[0] || c[1] / 255.f != mNewContext.color.mV[1] || c[2] / 255.f != mNewContext.color.mV[2] || c[3] / 255.f != mNewContext.color.mV[3] || mDirty) { - glColor4ubv(c); + flush(); + mNewContext.color.mV[0] = c[0] / 255.f; + mNewContext.color.mV[1] = c[1] / 255.f; + mNewContext.color.mV[2] = c[2] / 255.f; + mNewContext.color.mV[3] = c[3] / 255.f; } } @@ -2574,22 +2718,25 @@ void LLRender::diffuseColor4ub(U8 r, U8 g, U8 b, U8 a) { shader->uniform4f(LLShaderMgr::DIFFUSE_COLOR, r/255.f, g/255.f, b/255.f, a/255.f); } - else + else if (r / 255.f != mNewContext.color.mV[0] || g / 255.f != mNewContext.color.mV[1] || b / 255.f != mNewContext.color.mV[2] || a / 255.f != mNewContext.color.mV[3] || mDirty) { - glColor4ub(r,g,b,a); + flush(); + mNewContext.color.mV[0] = r / 255.f; + mNewContext.color.mV[1] = g / 255.f; + mNewContext.color.mV[2] = b / 255.f; + mNewContext.color.mV[3] = a / 255.f; } } - void LLRender::debugTexUnits(void) { - LL_INFOS("TextureUnit") << "Active TexUnit: " << mCurrTextureUnitIndex << LL_ENDL; + LL_INFOS("TextureUnit") << "Active TexUnit: " << getCurrentTexUnitIndex() << LL_ENDL; std::string active_enabled = "false"; for (U32 i = 0; i < mTexUnits.size(); i++) { if (getTexUnit(i)->mCurrTexType != LLTexUnit::TT_NONE) { - if (i == mCurrTextureUnitIndex) active_enabled = "true"; + if (i == getCurrentTexUnitIndex()) active_enabled = "true"; LL_INFOS("TextureUnit") << "TexUnit: " << i << " Enabled" << LL_ENDL; LL_INFOS("TextureUnit") << "Enabled As: " ; switch (getTexUnit(i)->mCurrTexType) diff --git a/indra/llrender/llrender.h b/indra/llrender/llrender.h index 5f7bb74df..86da8c449 100644 --- a/indra/llrender/llrender.h +++ b/indra/llrender/llrender.h @@ -221,31 +221,26 @@ protected: void setTextureCombiner(eTextureBlendOp op, eTextureBlendSrc src1, eTextureBlendSrc src2, bool isAlpha = false); }; -class LLLightState +struct LLLightStateData { -public: - LLLightState(S32 index); + LLLightStateData(bool notSun=true) : + mConstantAtten(1.f), + mLinearAtten(0.f), + mQuadraticAtten(0.f), + mSpotExponent(0.f), + mSpotCutoff(180.f) + { + if (!notSun) + { + mDiffuse.set(1, 1, 1, 1); + mSpecular.set(1, 1, 1, 1); + } +; + mPosition.set(0, 0, 1, 0); + mSpotDirection.set(0, 0, -1); + } - void enable(); - void disable(); - void setDiffuse(const LLColor4& diffuse); - void setAmbient(const LLColor4& ambient); - void setSpecular(const LLColor4& specular); - void setPosition(const LLVector4& position); - void setConstantAttenuation(const F32& atten); - void setLinearAttenuation(const F32& atten); - void setQuadraticAttenuation(const F32& atten); - void setSpotExponent(const F32& exponent); - void setSpotCutoff(const F32& cutoff); - void setSpotDirection(const LLVector3& direction); - -protected: - friend class LLRender; - - S32 mIndex; - bool mEnabled; LLColor4 mDiffuse; - LLColor4 mAmbient; LLColor4 mSpecular; LLVector4 mPosition; LLVector3 mSpotDirection; @@ -258,10 +253,51 @@ protected: F32 mSpotCutoff; }; +class LLLightState +{ +public: + LLLightState(S32 index); + + void enable() { setEnabled(true); } + void disable() { setEnabled(false); } + void setState(LLLightStateData& state) { + setDiffuse(state.mDiffuse); + setSpecular(state.mSpecular); + setPosition(state.mPosition); + setConstantAttenuation(state.mConstantAtten); + setLinearAttenuation(state.mLinearAtten); + setQuadraticAttenuation(state.mQuadraticAtten); + setSpotExponent(state.mSpotExponent); + setSpotCutoff(state.mSpotCutoff); + setSpotDirection(state.mSpotDirection); + } + const LLColor4& getDiffuse() const { return mState.mDiffuse; } + void setDiffuse(const LLColor4& diffuse); + void setSpecular(const LLColor4& specular); + void setPosition(const LLVector4& position); + void setConstantAttenuation(const F32& atten); + void setLinearAttenuation(const F32& atten); + void setQuadraticAttenuation(const F32& atten); + void setSpotExponent(const F32& exponent); + void setSpotCutoff(const F32& cutoff); + void setSpotDirection(const LLVector3& direction); + void setEnabled(const bool enabled); + +protected: + friend class LLRender; + + S32 mIndex; + LLLightStateData mState; + bool mEnabled; + LLMatrix4a mPosMatrix; + LLMatrix4a mSpotMatrix; +}; + LL_ALIGN_PREFIX(16) class LLRender { friend class LLTexUnit; + friend void check_blend_funcs(); public: enum eTexIndex @@ -335,10 +371,101 @@ public: MM_TEXTURE } eMatrixMode; + typedef enum + { + PF_FRONT, + PF_BACK, + PF_FRONT_AND_BACK + } ePolygonFaceType; + + typedef enum + { + PM_POINT, + PM_LINE, + PM_FILL + } ePolygonMode; + + static const U8 NUM_LIGHTS = 8; + + // Cache of global gl state. (excludes nested texunit/light states) + struct Context { + Context() : + texUnit(0), + color{ 1.f,1.f,1.f,1.f }, + colorMask{ true }, + alphaFunc(CF_ALWAYS), + alphaVal(0.f), + blendColorSFactor(BF_ONE), + blendAlphaDFactor(BF_ZERO), + blendAlphaSFactor(BF_ONE), + blendColorDFactor(BF_ZERO), + lineWidth(1.f), + pointSize(1.f), + polygonMode{ PM_FILL, PM_FILL }, + polygonOffset{ 0.f, 0.f }, + viewPort(), + scissor() + { + } + U32 texUnit; + LLColor4 color; + U8 colorMask : 4; + eCompareFunc alphaFunc; + F32 alphaVal; + eBlendFactor blendColorSFactor; + eBlendFactor blendColorDFactor; + eBlendFactor blendAlphaSFactor; + eBlendFactor blendAlphaDFactor; + F32 lineWidth; + F32 pointSize; + ePolygonMode polygonMode[2]; + F32 polygonOffset[2]; + LLRect viewPort; + LLRect scissor; + void printDiff(const Context& other) const + { + if (memcmp(this, &other, sizeof(other)) == 0) + { + return; + } +#define PRINT_DIFF(prop) \ + LL_INFOS() << #prop << ": " << other.prop; \ + if (prop != other.prop) { LL_CONT << " -> " << prop; } \ + LL_CONT << LL_ENDL; +#define PRINT_DIFF_BIT(prop, bit) \ + LL_INFOS() << #prop << "(1<<" << #bit << "): " << (other.prop&(1< " << (prop&(1< mBuffer; LLStrider mVerticesp; @@ -488,11 +643,6 @@ private: LLTexUnit* mDummyTexUnit; std::vector mLightState; - eBlendFactor mCurrBlendColorSFactor; - eBlendFactor mCurrBlendColorDFactor; - eBlendFactor mCurrBlendAlphaSFactor; - eBlendFactor mCurrBlendAlphaDFactor; - F32 mMaxAnisotropy; std::vector > mUIOffset; @@ -508,7 +658,7 @@ extern LLMatrix4a gGLLastModelView; extern LLMatrix4a gGLLastProjection; extern LLMatrix4a gGLPreviousModelView; extern LLMatrix4a gGLProjection; -extern S32 gGLViewport[4]; +extern LLRect gGLViewport; extern LLRender gGL; diff --git a/indra/llrender/llrender2dutils.cpp b/indra/llrender/llrender2dutils.cpp index 15c6baf8d..c86938186 100644 --- a/indra/llrender/llrender2dutils.cpp +++ b/indra/llrender/llrender2dutils.cpp @@ -759,12 +759,12 @@ void gl_stippled_line_3d( const LLVector3& start, const LLVector3& end, const LL S32 shift = S32(phase * 4.f) % 4; // Stippled line - LLGLEnable stipple(GL_LINE_STIPPLE); + LLGLEnable stipple; gGL.color4f(color.mV[VRED], color.mV[VGREEN], color.mV[VBLUE], color.mV[VALPHA]); gGL.flush(); - glLineWidth(2.5f); + gGL.setLineWidth(2.5f); if (!LLGLSLShader::sNoFixedFunction) { diff --git a/indra/llrender/llrendertarget.cpp b/indra/llrender/llrendertarget.cpp index c9051b10c..e01ca4a3e 100644 --- a/indra/llrender/llrendertarget.cpp +++ b/indra/llrender/llrendertarget.cpp @@ -195,8 +195,8 @@ bool LLRenderTarget::addColorAttachment(U32 color_fmt) return false; } - U32 tex; - LLImageGL::generateTextures(1, &tex); + auto texName = LLImageGL::createTextureName(); + U32 tex = texName->getTexName(); gGL.getTexUnit(0)->bindManual(mUsage, tex); stop_glerror(); @@ -245,6 +245,7 @@ bool LLRenderTarget::addColorAttachment(U32 color_fmt) } mTex.push_back(tex); + mTexName.push_back(texName); mInternalFormat.push_back(color_fmt); if (gDebugGL) @@ -258,6 +259,7 @@ bool LLRenderTarget::addColorAttachment(U32 color_fmt) bool LLRenderTarget::allocateDepth() { + mDepthName.reset(); if (mStencil && mFBO) { //use render buffers where stencil buffers are in play @@ -270,7 +272,9 @@ bool LLRenderTarget::allocateDepth() } else { - LLImageGL::generateTextures(1, &mDepth); + mDepthName = LLImageGL::createTextureName(); + mDepth = mDepthName->getTexName(); + gGL.getTexUnit(0)->bindManual(mUsage, mDepth); U32 internal_type = LLTexUnit::getInternalType(mUsage); @@ -357,7 +361,6 @@ void LLRenderTarget::release() glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, LLTexUnit::getInternalType(mUsage), 0, 0); glBindFramebuffer(GL_FRAMEBUFFER,0); } - LLImageGL::deleteTextures(1, &mDepth); stop_glerror(); } mDepth = 0; @@ -387,13 +390,11 @@ void LLRenderTarget::release() mFBO = 0; } - if (mTex.size() > 0) - { - sBytesAllocated -= mResX*mResY*4*mTex.size(); - LLImageGL::deleteTextures(mTex.size(), &mTex[0]); - mTex.clear(); - mInternalFormat.clear(); - } + sBytesAllocated -= mResX * mResY * 4 * mTex.size(); + mTex.clear(); + mInternalFormat.clear(); + mDepthName.reset(); + mTexName.clear(); // Were textures not being released at all..? mResX = mResY = 0; @@ -440,8 +441,7 @@ void LLRenderTarget::bindTarget() stop_glerror(); } } - - glViewport(0, 0, mResX, mResY); + gGL.setViewport(0, 0, mResX, mResY); sBoundTarget = this; } @@ -452,18 +452,22 @@ void LLRenderTarget::clear(U32 mask_in) { mask |= GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT; } + if (mFBO) { check_framebuffer_status(); stop_glerror(); + LLGLDisable scissor; + gGL.syncContextState(); glClear(mask & mask_in); stop_glerror(); } else { - LLGLEnable scissor(GL_SCISSOR_TEST); - glScissor(0, 0, mResX, mResY); + LLGLEnable scissor; + gGL.setScissor(0, 0, mResX, mResY); stop_glerror(); + gGL.syncContextState(); glClear(mask & mask_in); } } @@ -515,7 +519,7 @@ void LLRenderTarget::flush(bool fetch_depth) stop_glerror(); if(mSampleBuffer) { - LLGLEnable multisample(GL_MULTISAMPLE); + LLGLEnable multisample; stop_glerror(); glBindFramebuffer(GL_FRAMEBUFFER, mFBO); stop_glerror(); @@ -575,12 +579,12 @@ void LLRenderTarget::flush(bool fetch_depth) if(mPreviousFBO) { - glViewport(0, 0, mPreviousFBO->mResX, mPreviousFBO->mResY); + gGL.setViewport(0, 0, mPreviousFBO->mResX, mPreviousFBO->mResY); mPreviousFBO = NULL; } else { - glViewport(gGLViewport[0],gGLViewport[1],gGLViewport[2],gGLViewport[3]); + gGL.setViewport(gGLViewport); } stop_glerror(); } @@ -683,12 +687,9 @@ bool LLRenderTarget::isComplete() const return (!mTex.empty() || mDepth) ? true : false; } -void LLRenderTarget::getViewport(S32* viewport) +void LLRenderTarget::getViewport(LLRect& viewport) { - viewport[0] = 0; - viewport[1] = 0; - viewport[2] = mResX; - viewport[3] = mResY; + viewport = LLRect(0, mResY, mResX, 0); } //================================================== @@ -754,7 +755,7 @@ void LLMultisampleBuffer::bindTarget(LLRenderTarget* ref) check_framebuffer_status(); - glViewport(0, 0, mResX, mResY); + gGL.setViewport(0, 0, mResX, mResY); sBoundTarget = this; } diff --git a/indra/llrender/llrendertarget.h b/indra/llrender/llrendertarget.h index a0f409334..bf37cba2b 100644 --- a/indra/llrender/llrendertarget.h +++ b/indra/llrender/llrendertarget.h @@ -107,7 +107,7 @@ public: void clear(U32 mask = 0xFFFFFFFF); //get applied viewport - void getViewport(S32* viewport); + void getViewport(LLRect& viewport); //get X resolution U32 getWidth() const { return mResX; } @@ -152,9 +152,11 @@ protected: U32 mResX; U32 mResY; std::vector mTex; + std::vector mTexName; std::vector mInternalFormat; U32 mFBO; LLRenderTarget* mPreviousFBO; + LLImageGL::GLTextureName mDepthName; U32 mDepth; bool mStencil; bool mUseDepth; diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 69566cbcf..37a0ea424 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -498,27 +498,28 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader) //============================================================================ // Load Shader -static std::string get_object_log(GLhandleARB ret) +static std::string get_object_log(GLhandleARB ret, bool isProgram) { std::string res; //get log length GLint length; - glGetObjectParameterivARB(ret, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length); + (isProgram ? glGetProgramiv : glGetShaderiv)(ret, GL_INFO_LOG_LENGTH, &length); + if (length > 0) { //the log could be any size, so allocate appropriately GLcharARB* log = new GLcharARB[length]; - glGetInfoLogARB(ret, length, &length, log); + (isProgram ? glGetProgramInfoLog : glGetShaderInfoLog)(ret, length, &length, log); res = std::string((char *)log); delete[] log; } return res; } -void LLShaderMgr::dumpObjectLog(GLhandleARB ret, BOOL warns) +void LLShaderMgr::dumpObjectLog(GLhandleARB ret, bool isProgram, bool warns) { - std::string log = get_object_log(ret); + std::string log = get_object_log(ret, isProgram); if ( log.length() > 0 ) { if (warns) @@ -555,7 +556,7 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade } } - LL_DEBUGS("ShaderLoading") << "Loading shader file: " << filename << " class " << shader_level << LL_ENDL; + LL_INFOS("ShaderLoading") << "Loading shader file: " << filename << " class " << shader_level << LL_ENDL; if (filename.empty()) { @@ -811,7 +812,7 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade if (error != GL_NO_ERROR) { LL_WARNS("ShaderLoading") << "GL ERROR in glCreateShaderObjectARB: " << error << LL_ENDL; - glDeleteObjectARB(ret); //no longer need handle + glDeleteShader(ret); //no longer need handle ret=0; } } @@ -827,7 +828,7 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade if (error != GL_NO_ERROR) { LL_WARNS("ShaderLoading") << "GL ERROR in glShaderSourceARB: " << error << LL_ENDL; - glDeleteObjectARB(ret); //no longer need handle + glDeleteShader(ret); //no longer need handle ret=0; } } @@ -844,7 +845,7 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade if (error != GL_NO_ERROR) { LL_WARNS("ShaderLoading") << "GL ERROR in glCompileShaderARB: " << error << LL_ENDL; - glDeleteObjectARB(ret); //no longer need handle + glDeleteShader(ret); //no longer need handle ret=0; } } @@ -856,7 +857,7 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade { //check for errors GLint success = GL_TRUE; - glGetObjectParameterivARB(ret, GL_OBJECT_COMPILE_STATUS_ARB, &success); + glGetShaderiv(ret, GL_COMPILE_STATUS, &success); if (gDebugGL || success == GL_FALSE) { error = glGetError(); @@ -864,8 +865,8 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade { //an error occured, print log LL_WARNS("ShaderLoading") << "GLSL Compilation Error: (" << error << ") in " << filename << LL_ENDL; - dumpObjectLog(ret); - error_str = get_object_log(ret); + dumpObjectLog(ret, false); + error_str = get_object_log(ret, false); std::stringstream ostr; //dump shader source for debugging @@ -884,12 +885,12 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade } LL_WARNS("ShaderLoading") << "\n" << ostr.str() << LL_ENDL; - glDeleteObjectARB(ret); //no longer need handle + glDeleteShader(ret); //no longer need handle ret = 0; } } if(ret) - dumpObjectLog(ret,false); + dumpObjectLog(ret, false, false); } static const LLCachedControl dump_raw_shaders("ShyotlDumpRawShaders",false); @@ -961,7 +962,7 @@ void LLShaderMgr::unloadShaderObjects() std::multimap::iterator it = mShaderObjects.begin(); for (; it != mShaderObjects.end(); ++it) if (it->second.mHandle) - glDeleteObjectARB(it->second.mHandle); + glDeleteShader(it->second.mHandle); mShaderObjects.clear(); cleanupShaderSources(); } @@ -1007,7 +1008,7 @@ BOOL LLShaderMgr::linkProgramObject(GLhandleARB obj, BOOL suppress_errors) //check for errors glLinkProgramARB(obj); GLint success = GL_TRUE; - glGetObjectParameterivARB(obj, GL_OBJECT_LINK_STATUS_ARB, &success); + glGetProgramiv(obj, GL_LINK_STATUS, &success); if (!suppress_errors && success == GL_FALSE) { //an error occured, print log @@ -1051,7 +1052,7 @@ BOOL LLShaderMgr::linkProgramObject(GLhandleARB obj, BOOL suppress_errors) } #else - std::string log = get_object_log(obj); + std::string log = get_object_log(obj, true); LLStringUtil::toLower(log); if (log.find("software") != std::string::npos) { @@ -1062,7 +1063,7 @@ BOOL LLShaderMgr::linkProgramObject(GLhandleARB obj, BOOL suppress_errors) #endif if (!suppress_errors) { - dumpObjectLog(obj, !success); + dumpObjectLog(obj, true, !success); } return success; @@ -1073,15 +1074,15 @@ BOOL LLShaderMgr::validateProgramObject(GLhandleARB obj) //check program validity against current GL glValidateProgramARB(obj); GLint success = GL_TRUE; - glGetObjectParameterivARB(obj, GL_OBJECT_VALIDATE_STATUS_ARB, &success); + glGetProgramiv(obj, GL_VALIDATE_STATUS, &success); if (success == GL_FALSE) { LL_WARNS("ShaderLoading") << "GLSL program not valid: " << LL_ENDL; - dumpObjectLog(obj); + dumpObjectLog(obj, true); } else { - dumpObjectLog(obj, FALSE); + dumpObjectLog(obj, true, false); } return success; diff --git a/indra/llrender/llshadermgr.h b/indra/llrender/llshadermgr.h index f10487710..61c949c54 100644 --- a/indra/llrender/llshadermgr.h +++ b/indra/llrender/llshadermgr.h @@ -228,7 +228,7 @@ DISPLAY_GAMMA, virtual void initAttribsAndUniforms(void); BOOL attachShaderFeatures(LLGLSLShader * shader); - void dumpObjectLog(GLhandleARB ret, BOOL warns = TRUE); + void dumpObjectLog(GLhandleARB ret, bool isProgram, bool warns = TRUE); BOOL linkProgramObject(GLhandleARB obj, BOOL suppress_errors = FALSE); BOOL validateProgramObject(GLhandleARB obj); GLhandleARB loadShaderFile(const std::string& filename, S32 & shader_level, GLenum type, std::map* defines = NULL, S32 texture_index_channels = -1); diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index c4977e9bc..e46fc679f 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -90,6 +90,7 @@ LLVBOPool LLVertexBuffer::sDynamicIBOPool(GL_DYNAMIC_DRAW_ARB, GL_ELEMENT_ARRAY_ U32 LLVBOPool::sBytesPooled = 0; U32 LLVBOPool::sIndexBytesPooled = 0; +std::vector LLVBOPool::sPendingDeletions; std::list LLVertexBuffer::sAvailableVAOName; U32 LLVertexBuffer::sCurVAOName = 1; @@ -118,12 +119,75 @@ bool LLVertexBuffer::sUseVAO = false; bool LLVertexBuffer::sPreferStreamDraw = false; LLVertexBuffer* LLVertexBuffer::sUtilityBuffer = nullptr; +static std::vector sActiveBufferNames; +static std::vector sDeletedBufferNames; + +/*void validate_add_buffer(U32 name) +{ + auto found = std::find(sActiveBufferNames.begin(), sActiveBufferNames.end(), name); + if (found != sActiveBufferNames.end()) + { + LL_ERRS() << "Allocating allocated buffer name " << name << LL_ENDL; + } + else + { + //LL_INFOS() << "Allocated buffer name " << name << LL_ENDL; + sActiveBufferNames.push_back(name); + } +} + +void validate_del_buffer(U32 name) +{ + auto found = std::find(sActiveBufferNames.begin(), sActiveBufferNames.end(), name); + if (found == sActiveBufferNames.end()) + { + if (std::find(sDeletedBufferNames.begin(), sDeletedBufferNames.end(), name) == sDeletedBufferNames.end()) + { + LL_ERRS() << "Deleting unknown buffer name " << name << LL_ENDL; + } + else + { + LL_ERRS() << "Deleting deleted buffer name " << name << LL_ENDL; + } + } + else + { + //LL_INFOS() << "Deleted buffer name " << name << LL_ENDL; + sActiveBufferNames.erase(found); + sDeletedBufferNames.push_back(name); + } +} + +void validate_bind_buffer(U32 name) +{ + auto found = std::find(sActiveBufferNames.begin(), sActiveBufferNames.end(), name); + if (found == sActiveBufferNames.end()) + { + if (std::find(sDeletedBufferNames.begin(), sDeletedBufferNames.end(), name) == sDeletedBufferNames.end()) + { + LL_ERRS() << "Binding unknown buffer name " << name << LL_ENDL; + } + else + { + LL_ERRS() << "Binding deleted buffer name " << name << LL_ENDL; + } + } +} + +void clean_validate_buffers() +{ + LL_INFOS() << "Clearing active buffer names. Count " << sActiveBufferNames.size() << LL_ENDL; + sActiveBufferNames.clear(); + LL_INFOS() << "Clearing deleted buffer names. Count " << sDeletedBufferNames.size() << LL_ENDL; + sDeletedBufferNames.clear(); +}*/ U32 LLVBOPool::genBuffer() { U32 ret = 0; glGenBuffersARB(1, &ret); + //validate_add_buffer(ret); return ret; } @@ -132,13 +196,20 @@ void LLVBOPool::deleteBuffer(U32 name) { if (gGLManager.mInited) { - LLVertexBuffer::unbind(); + //LLVertexBuffer::unbind(); - glBindBufferARB(mType, name); - glBufferDataARB(mType, 0, nullptr, mUsage); - glBindBufferARB(mType, 0); + //validate_bind_buffer(name); + //glBindBufferARB(mType, name); + //glBufferDataARB(mType, 0, nullptr, mUsage); + //glBindBufferARB(mType, 0); - glDeleteBuffersARB(1, &name); + //validate_del_buffer(name); + if (LLVertexBuffer::sGLRenderBuffer == name) { + //LLVertexBuffer::sGLRenderBuffer = 0; + LLVertexBuffer::unbind(); + } + sPendingDeletions.emplace_back(name); + //glDeleteBuffersARB(1, &name); } } @@ -150,7 +221,7 @@ LLVBOPool::LLVBOPool(U32 vboUsage, U32 vboType) std::fill(mMissCount.begin(), mMissCount.end(), 0); } -volatile U8* LLVBOPool::allocate(U32& name, U32 size, bool for_seed) +volatile U8* LLVBOPool::allocate(U32& name, U32 size, U32 seed) { llassert(vbo_block_size(size) == size); @@ -163,16 +234,17 @@ volatile U8* LLVBOPool::allocate(U32& name, U32 size, bool for_seed) mFreeList.resize(i+1); } - if (mFreeList[i].empty() || for_seed) + if (mFreeList[i].empty() || seed) { //make a new buffer - name = genBuffer(); - + name = seed > 0 ? seed : genBuffer(); + + //validate_bind_buffer(name); glBindBufferARB(mType, name); - if (!for_seed && i < LL_VBO_POOL_SEED_COUNT) + if (!seed && i < LL_VBO_POOL_SEED_COUNT) { //record this miss - mMissCount[i]++; + mMissCount[i]++; } if (mType == GL_ARRAY_BUFFER_ARB) @@ -187,16 +259,19 @@ volatile U8* LLVBOPool::allocate(U32& name, U32 size, bool for_seed) if (LLVertexBuffer::sDisableVBOMapping || mUsage != GL_DYNAMIC_DRAW_ARB) { glBufferDataARB(mType, size, nullptr, mUsage); - ret = (U8*) ll_aligned_malloc<64>(size); + ret = (U8*)ll_aligned_malloc<64>(size); } else { //always use a true hint of static draw when allocating non-client-backed buffers glBufferDataARB(mType, size, nullptr, GL_STATIC_DRAW_ARB); } - glBindBufferARB(mType, 0); + if (!seed) + { + glBindBufferARB(mType, 0); + } - if (for_seed) + if (seed) { //put into pool for future use llassert(mFreeList.size() > i); @@ -206,11 +281,11 @@ volatile U8* LLVBOPool::allocate(U32& name, U32 size, bool for_seed) if (mType == GL_ARRAY_BUFFER_ARB) { - sBytesPooled += size; - } - else - { - sIndexBytesPooled += size; + sBytesPooled += size; + } + else + { + sIndexBytesPooled += size; } mFreeList[i].push_back(rec); } @@ -261,22 +336,45 @@ void LLVBOPool::seedPool() mFreeList.resize(LL_VBO_POOL_SEED_COUNT); } + static std::vector< U32 > sizes; for (U32 i = 0; i < LL_VBO_POOL_SEED_COUNT; i++) { if (mMissCount[i] > mFreeList[i].size()) - { - U32 size = i*LL_VBO_BLOCK_SIZE; - + { + U32 size = i * LL_VBO_BLOCK_SIZE; + S32 count = mMissCount[i] - mFreeList[i].size(); for (S32 j = 0; j < count; ++j) { - allocate(dummy_name, size, true); + sizes.push_back(size); } } } + + + if (!sizes.empty()) + { + const U32 len = sizes.size(); + U32* names = new U32[len]; + glGenBuffersARB(len, names); + for (U32 i = 0; i < len; ++i) + { + allocate(dummy_name, sizes[i], names[i]); + } + delete[] names; + glBindBufferARB(mType, 0); + } + sizes.clear(); } - +void LLVBOPool::deleteReleasedBuffers() +{ + if (!sPendingDeletions.empty()) + { + glDeleteBuffersARB(sPendingDeletions.size(), sPendingDeletions.data()); + sPendingDeletions.clear(); + } +} void LLVBOPool::cleanup() { @@ -316,6 +414,7 @@ void LLVBOPool::cleanup() //reset miss counts std::fill(mMissCount.begin(), mMissCount.end(), 0); + deleteReleasedBuffers(); } @@ -895,6 +994,14 @@ void LLVertexBuffer::cleanupClass() sDynamicIBOPool.cleanup(); sStreamVBOPool.cleanup(); sDynamicVBOPool.cleanup(); + //clean_validate_buffers(); + + if (!sAvailableVAOName.empty()) + { + glDeleteVertexArrays(1, &sAvailableVAOName.front()); + sAvailableVAOName.pop_front(); + } + sLastMask = 0; delete sUtilityBuffer; sUtilityBuffer = nullptr; @@ -949,7 +1056,9 @@ LLVertexBuffer::LLVertexBuffer(U32 typemask, S32 usage) : mAlignedOffset(0), mAlignedIndexOffset(0), mSize(0), + mResidentSize(0), mIndicesSize(0), + mResidentIndicesSize(0), mTypeMask(typemask), mUsage(LLVertexBuffer::determineUsage(usage)), mGLBuffer(0), @@ -997,7 +1106,7 @@ S32 LLVertexBuffer::calcOffsets(const U32& typemask, S32* offsets, S32 num_verti offsets[TYPE_TEXTURE_INDEX] = offsets[TYPE_VERTEX] + 12; - return offset+16; + return offset; } //static @@ -1155,6 +1264,7 @@ void LLVertexBuffer::createGLBuffer(U32 size) } mEmpty = true; + mResidentSize = size; mMappedDataUsingVBOs = useVBOs(); @@ -1184,6 +1294,7 @@ void LLVertexBuffer::createGLIndices(U32 size) } mEmpty = true; + mResidentIndicesSize = size; //pad by 16 bytes for aligned copies size += 16; @@ -1394,8 +1505,8 @@ void LLVertexBuffer::setupVertexArray() GL_FALSE, //TYPE_TEXTURE_INDEX }; - bindGLBuffer(true); - bindGLIndices(true); + bindGLBuffer(); + bindGLIndices(); for (U32 i = 0; i < TYPE_MAX; ++i) { @@ -1457,21 +1568,21 @@ bool LLVertexBuffer::useVBOs() const //---------------------------------------------------------------------------- -bool expand_region(LLVertexBuffer::MappedRegion& region, S32 index, S32 count) +bool expand_region(LLVertexBuffer::MappedRegion& region, U32 offset, U32 length) { - S32 end = index+count; - S32 region_end = region.mIndex+region.mCount; + U32 end = offset + length; + U32 region_end = region.mOffset + region.mLength; - if (end < region.mIndex || - index > region_end) + if (end < region.mOffset || + offset > region_end) { //gap exists, do not merge return false; } - S32 new_end = llmax(end, region_end); - S32 new_index = llmin(index, region.mIndex); - region.mIndex = new_index; - region.mCount = new_end-new_index; + U32 new_end = llmax(end, region_end); + U32 new_offset = llmin(offset, region.mOffset); + region.mOffset = new_offset; + region.mLength = new_end-new_offset; return true; } @@ -1481,7 +1592,7 @@ static LLTrace::BlockTimerStatHandle FTM_VBO_MAP_BUFFER("VBO Map"); // Map for data access volatile U8* LLVertexBuffer::mapVertexBuffer(S32 type, S32 index, S32 count, bool map_range) { - bindGLBuffer(true); + bindGLBuffer(); if (mFinal) { LL_ERRS() << "LLVertexBuffer::mapVeretxBuffer() called on a finalized buffer." << LL_ENDL; @@ -1500,26 +1611,41 @@ volatile U8* LLVertexBuffer::mapVertexBuffer(S32 type, S32 index, S32 count, boo count = mNumVerts-index; } - bool mapped = false; - //see if range is already mapped - for (U32 i = 0; i < mMappedVertexRegions.size(); ++i) + if (getSize() > LL_VBO_BLOCK_SIZE) { - MappedRegion& region = mMappedVertexRegions[i]; - if (region.mType == type) + U32 offset = mOffsets[type] + sTypeSize[type] * index; + U32 length = sTypeSize[type] * count; + + bool mapped = false; + //see if range is already mapped + for (U32 i = 0; i < mMappedVertexRegions.size(); ++i) { - if (expand_region(region, index, count)) + MappedRegion& region = mMappedVertexRegions[i]; + if (expand_region(region, offset, length)) { + ++i; + while (MappedRegion* pNext = i < mMappedVertexRegions.size() ? &mMappedVertexRegions[i] : nullptr) + { + if (expand_region(region, pNext->mOffset, pNext->mLength)) + { + mMappedVertexRegions.erase(mMappedVertexRegions.begin() + i); + } + else + { + ++i; + } + } mapped = true; break; } } - } - if (!mapped) - { - //not already mapped, map new region - MappedRegion region(type, mMappable && map_range ? -1 : index, count); - mMappedVertexRegions.push_back(region); + if (!mapped) + { + //not already mapped, map new region + MappedRegion region(type, mMappable && map_range ? -1 : offset, length); + mMappedVertexRegions.push_back(region); + } } } @@ -1660,7 +1786,7 @@ static LLTrace::BlockTimerStatHandle FTM_VBO_MAP_INDEX("IBO Map"); volatile U8* LLVertexBuffer::mapIndexBuffer(S32 index, S32 count, bool map_range) { - bindGLIndices(true); + bindGLIndices(); if (mFinal) { LL_ERRS() << "LLVertexBuffer::mapIndexBuffer() called on a finalized buffer." << LL_ENDL; @@ -1679,23 +1805,41 @@ volatile U8* LLVertexBuffer::mapIndexBuffer(S32 index, S32 count, bool map_range count = mNumIndices-index; } - bool mapped = false; - //see if range is already mapped - for (U32 i = 0; i < mMappedIndexRegions.size(); ++i) + if (getIndicesSize() > LL_VBO_BLOCK_SIZE) { - MappedRegion& region = mMappedIndexRegions[i]; - if (expand_region(region, index, count)) - { - mapped = true; - break; - } - } + U32 offset = sizeof(U16) * index; + U32 length = sizeof(U16) * count; - if (!mapped) - { - //not already mapped, map new region - MappedRegion region(TYPE_INDEX, mMappable && map_range ? -1 : index, count); - mMappedIndexRegions.push_back(region); + bool mapped = false; + //see if range is already mapped + for (U32 i = 0; i < mMappedIndexRegions.size(); ++i) + { + MappedRegion& region = mMappedIndexRegions[i]; + if (expand_region(region, offset, length)) + { + ++i; + while (MappedRegion* pNext = i < mMappedIndexRegions.size() ? &mMappedIndexRegions[i] : nullptr) + { + if (expand_region(region, pNext->mOffset, pNext->mLength)) + { + mMappedIndexRegions.erase(mMappedIndexRegions.begin() + i); + } + else + { + ++i; + } + } + mapped = true; + break; + } + } + + if (!mapped) + { + //not already mapped, map new region + MappedRegion region(TYPE_INDEX, mMappable && map_range ? -1 : offset, length); + mMappedIndexRegions.push_back(region); + } } } @@ -1838,7 +1982,7 @@ void LLVertexBuffer::unmapBuffer() if (mMappedData && mVertexLocked) { //LL_RECORD_BLOCK_TIME(FTM_VBO_UNMAP); - bindGLBuffer(true); + bindGLBuffer(); updated_all = mIndexLocked; //both vertex and index buffers done updating if(!mMappable) @@ -1849,9 +1993,18 @@ void LLVertexBuffer::unmapBuffer() for (U32 i = 0; i < mMappedVertexRegions.size(); ++i) { const MappedRegion& region = mMappedVertexRegions[i]; - S32 offset = region.mIndex >= 0 ? mOffsets[region.mType]+sTypeSize[region.mType]*region.mIndex : 0; - S32 length = sTypeSize[region.mType]*region.mCount; - glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, offset, length, (U8*) mMappedData+offset); + U32 offset = region.mOffset; + U32 length = region.mLength; + if ((mResidentSize - length) <= LL_VBO_BLOCK_SIZE * 2 || (offset == 0 && length >= mResidentSize)) + { + glBufferDataARB(GL_ARRAY_BUFFER_ARB, getSize(), nullptr, mUsage); + glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, getSize(), (U8*)mMappedData); + break; + } + else + { + glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, offset, length, (U8*)mMappedData + offset); + } stop_glerror(); } @@ -1875,8 +2028,8 @@ void LLVertexBuffer::unmapBuffer() for (U32 i = 0; i < mMappedVertexRegions.size(); ++i) { const MappedRegion& region = mMappedVertexRegions[i]; - S32 offset = region.mIndex >= 0 ? mOffsets[region.mType]+sTypeSize[region.mType]*region.mIndex : 0; - S32 length = sTypeSize[region.mType]*region.mCount; + U32 offset = region.mOffset; + U32 length = region.mLength; if (gGLManager.mHasMapBufferRange) { //LL_RECORD_BLOCK_TIME(FTM_VBO_FLUSH_RANGE); @@ -1916,9 +2069,18 @@ void LLVertexBuffer::unmapBuffer() for (U32 i = 0; i < mMappedIndexRegions.size(); ++i) { const MappedRegion& region = mMappedIndexRegions[i]; - S32 offset = region.mIndex >= 0 ? sizeof(U16)*region.mIndex : 0; - S32 length = sizeof(U16)*region.mCount; - glBufferSubDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, offset, length, (U8*) mMappedIndexData+offset); + U32 offset = region.mOffset; + U32 length = region.mLength; + if ((mResidentIndicesSize - length) <= LL_VBO_BLOCK_SIZE * 2 || (offset == 0 && length >= mResidentIndicesSize)) + { + glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, getIndicesSize(), nullptr, mUsage); // + glBufferSubDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0, getIndicesSize(), (U8*)mMappedIndexData); + break; + } + else + { + glBufferSubDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, offset, length, (U8*)mMappedIndexData + offset); + } stop_glerror(); } @@ -1941,8 +2103,8 @@ void LLVertexBuffer::unmapBuffer() for (U32 i = 0; i < mMappedIndexRegions.size(); ++i) { const MappedRegion& region = mMappedIndexRegions[i]; - S32 offset = region.mIndex >= 0 ? sizeof(U16)*region.mIndex : 0; - S32 length = sizeof(U16)*region.mCount; + U32 offset = region.mOffset; + U32 length = region.mLength; if (gGLManager.mHasMapBufferRange) { //LL_RECORD_BLOCK_TIME(FTM_IBO_FLUSH_RANGE); @@ -2127,7 +2289,9 @@ static LLTrace::BlockTimerStatHandle FTM_BIND_GL_BUFFER("Bind Buffer"); bool LLVertexBuffer::bindGLBuffer(bool force_bind) { + //stop_glerror(); bindGLArray(); + //stop_glerror(); bool ret = false; @@ -2138,7 +2302,11 @@ bool LLVertexBuffer::bindGLBuffer(bool force_bind) { LL_ERRS() << "VBO bound while another VBO mapped!" << LL_ENDL; }*/ + //stop_glerror(); + + //validate_bind_buffer(mGLBuffer); glBindBufferARB(GL_ARRAY_BUFFER_ARB, mGLBuffer); + //stop_glerror(); sGLRenderBuffer = mGLBuffer; sBindCount++; sVBOActive = true; @@ -2169,6 +2337,7 @@ bool LLVertexBuffer::bindGLIndices(bool force_bind) { LL_ERRS() << "VBO bound while another VBO mapped!" << LL_ENDL; }*/ + //validate_bind_buffer(mGLIndices); glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, mGLIndices); sGLRenderIndices = mGLIndices; stop_glerror(); @@ -2485,8 +2654,8 @@ void LLVertexBuffer::setupVertexBuffer(U32 data_mask) llglassertok(); } -LLVertexBuffer::MappedRegion::MappedRegion(S32 type, S32 index, S32 count) -: mType(type), mIndex(index), mCount(count) +LLVertexBuffer::MappedRegion::MappedRegion(S32 type, U32 offset, U32 length) +: mType(type), mOffset(offset), mLength(length) { llassert(mType == LLVertexBuffer::TYPE_INDEX || mType < LLVertexBuffer::TYPE_TEXTURE_INDEX); diff --git a/indra/llrender/llvertexbuffer.h b/indra/llrender/llvertexbuffer.h index afddf5ad2..c48335070 100644 --- a/indra/llrender/llvertexbuffer.h +++ b/indra/llrender/llvertexbuffer.h @@ -56,14 +56,18 @@ class LLVBOPool public: static U32 sBytesPooled; static U32 sIndexBytesPooled; - + static std::vector sPendingDeletions; + + // Periodically call from render loop. Batches VBO deletions together in a single call. + static void deleteReleasedBuffers(); + LLVBOPool(U32 vboUsage, U32 vboType); const U32 mUsage; const U32 mType; //size MUST be a power of 2 - volatile U8* allocate(U32& name, U32 size, bool for_seed = false); + volatile U8* allocate(U32& name, U32 size, U32 seed = 0); //size MUST be the size provided to allocate that returned the given name void release(U32 name, volatile U8* buffer, U32 size); @@ -100,10 +104,10 @@ public: { public: S32 mType; - S32 mIndex; - S32 mCount; + U32 mOffset; + U32 mLength; - MappedRegion(S32 type, S32 index, S32 count); + MappedRegion(S32 type, U32 offset, U32 length); }; LLVertexBuffer(const LLVertexBuffer& rhs) @@ -291,7 +295,9 @@ protected: ptrdiff_t mAlignedOffset; ptrdiff_t mAlignedIndexOffset; S32 mSize; + S32 mResidentSize; S32 mIndicesSize; + S32 mResidentIndicesSize; U32 mTypeMask; const S32 mUsage; // GL usage diff --git a/indra/llui/lllocalcliprect.cpp b/indra/llui/lllocalcliprect.cpp index f3a526fae..cacc9e022 100644 --- a/indra/llui/lllocalcliprect.cpp +++ b/indra/llui/lllocalcliprect.cpp @@ -33,14 +33,13 @@ LLScreenClipRect::LLScreenClipRect(const LLRect& rect, BOOL enabled) -: mScissorState(GL_SCISSOR_TEST), - mEnabled(enabled) +: mScissorState(enabled), + mEnabled(enabled), + mRootScissorRect(gGL.getScissor()) { if (mEnabled) { pushClipRect(rect); - mScissorState.setEnabled(!sClipRectStack.empty()); - updateScissorRegion(); } } @@ -49,11 +48,9 @@ LLScreenClipRect::~LLScreenClipRect() if (mEnabled) { popClipRect(); - updateScissorRegion(); } } -//static void LLScreenClipRect::pushClipRect(const LLRect& rect) { LLRect combined_clip_rect = rect; @@ -68,23 +65,27 @@ void LLScreenClipRect::pushClipRect(const LLRect& rect) combined_clip_rect = LLRect::null; } } + sClipRectStack.push(combined_clip_rect); + updateScissorRegion(); } -//static void LLScreenClipRect::popClipRect() { sClipRectStack.pop(); + if (!sClipRectStack.empty()) + { + updateScissorRegion(); + } + else + { + gGL.setScissor(mRootScissorRect); + } } -//static +// static void LLScreenClipRect::updateScissorRegion() { - if (sClipRectStack.empty()) return; - - // finish any deferred calls in the old clipping region - gGL.flush(); - LLRect rect = sClipRectStack.top(); stop_glerror(); S32 x,y,w,h; @@ -92,7 +93,7 @@ void LLScreenClipRect::updateScissorRegion() y = llfloor(rect.mBottom * LLUI::getScaleFactor().mV[VY]); w = llmax(0, llceil(rect.getWidth() * LLUI::getScaleFactor().mV[VX])) + 1; h = llmax(0, llceil(rect.getHeight() * LLUI::getScaleFactor().mV[VY])) + 1; - glScissor( x,y,w,h ); + gGL.setScissor( x,y,w,h ); stop_glerror(); } diff --git a/indra/llui/lllocalcliprect.h b/indra/llui/lllocalcliprect.h index eeeaf2adb..18b0eccad 100644 --- a/indra/llui/lllocalcliprect.h +++ b/indra/llui/lllocalcliprect.h @@ -42,13 +42,14 @@ public: virtual ~LLScreenClipRect(); private: - static void pushClipRect(const LLRect& rect); - static void popClipRect(); + void pushClipRect(const LLRect& rect); + void popClipRect(); static void updateScissorRegion(); private: - LLGLState mScissorState; - BOOL mEnabled; + LLGLState mScissorState; + const BOOL mEnabled; + const LLRect mRootScissorRect; static std::stack sClipRectStack; }; diff --git a/indra/llwindow/llwindowwin32.cpp b/indra/llwindow/llwindowwin32.cpp index 4a3a043d4..c6cf352f6 100644 --- a/indra/llwindow/llwindowwin32.cpp +++ b/indra/llwindow/llwindowwin32.cpp @@ -1617,6 +1617,7 @@ BOOL LLWindowWin32::switchContext(BOOL fullscreen, const LLCoordScreen &size, co { show(); glClearColor(0.0f, 0.0f, 0.0f, 0.f); + gGL.syncContextState(); glClear(GL_COLOR_BUFFER_BIT); swapBuffers(); } diff --git a/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl b/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl index a9288b3df..7d493d74c 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/lightFuncV.glsl @@ -43,16 +43,17 @@ float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, floa //normalize light vector lv *= 1.0/d; + //lv = normalize(lv); //distance attenuation float da = clamp(1.0/(la * d), 0.0, 1.0); // spotlight coefficient. - float spot = max(dot(-ln, lv), is_pointlight); + float spot = max(dot(normalize(-ln), lv), is_pointlight); da *= spot*spot; // GL_SPOT_EXPONENT=2 //angular attenuation - da *= calcDirectionalLight(n, lv); + da = max(lp.w * da * calcDirectionalLight(n, lv), (1.0 - lp.w) * calcDirectionalLight(n, lp.xyz)); return da; } diff --git a/indra/newview/app_settings/shaders/class1/lighting/sumLightsSpecularV.glsl b/indra/newview/app_settings/shaders/class1/lighting/sumLightsSpecularV.glsl index 7059ff31a..4e86aa179 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/sumLightsSpecularV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/sumLightsSpecularV.glsl @@ -22,35 +22,40 @@ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ - - + float calcDirectionalLightSpecular(inout vec4 specular, vec3 view, vec3 n, vec3 l, vec3 lightCol, float da); +vec3 calcPointLightSpecular(inout vec4 specular, vec3 view, vec3 v, vec3 n, vec3 l, float r, float pw, vec3 lightCol); + vec3 atmosAmbient(vec3 light); vec3 atmosAffectDirectionalLight(float lightIntensity); vec3 atmosGetDiffuseSunlightColor(); vec3 scaleDownLight(vec3 light); uniform vec4 light_position[8]; +uniform vec3 light_attenuation[8]; uniform vec3 light_diffuse[8]; vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor, vec4 baseCol) { - vec4 col = vec4(0,0,0, color.a); + vec4 col = vec4(0.0, 0.0, 0.0, color.a); vec3 view = normalize(pos); /// collect all the specular values from each calcXXXLightSpecular() function vec4 specularSum = vec4(0.0); - col.rgb += light_diffuse[1].rgb * calcDirectionalLightSpecular(specularColor, view, norm, light_position[1].xyz,light_diffuse[1].rgb, 1.0); + // Collect normal lights (need to be divided by two, as we later multiply by 2) + col.rgb += calcPointLightSpecular(specularSum, view, pos, norm, light_position[1].xyz, light_attenuation[1].x, light_attenuation[1].y, light_diffuse[1].rgb); col.rgb = scaleDownLight(col.rgb); + + // Add windlight lights col.rgb += atmosAmbient(baseCol.rgb); col.rgb += atmosAffectDirectionalLight(calcDirectionalLightSpecular(specularSum, view, norm, light_position[0].xyz,atmosGetDiffuseSunlightColor()*baseCol.a, 1.0)); col.rgb = min(col.rgb * color.rgb, 1.0); specularColor.rgb = min(specularColor.rgb * specularSum.rgb, 1.0); - + col.rgb += specularColor.rgb; return col; diff --git a/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl b/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl index 41288c21c..752becf78 100644 --- a/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl +++ b/indra/newview/app_settings/shaders/class1/lighting/sumLightsV.glsl @@ -23,28 +23,36 @@ * $/LicenseInfo$ */ -uniform vec4 light_position[8]; -uniform vec3 light_diffuse[8]; float calcDirectionalLight(vec3 n, vec3 l); +float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float is_pointlight); vec3 atmosAmbient(vec3 light); vec3 atmosAffectDirectionalLight(float lightIntensity); vec3 scaleDownLight(vec3 light); + +uniform vec4 light_position[8]; +uniform vec3 light_direction[8]; +uniform vec3 light_attenuation[8]; +uniform vec3 light_diffuse[8]; + vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight) { - vec4 col; - col.a = color.a; - - col.rgb = light_diffuse[1].rgb * calcDirectionalLight(norm, light_position[1].xyz); + vec4 col = vec4(0.0, 0.0, 0.0, color.a); + + // Collect normal lights (need to be divided by two, as we later multiply by 2) + + // Collect normal lights + col.rgb += light_diffuse[1].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[1], light_direction[1], light_attenuation[1].x, light_attenuation[1].z); col.rgb = scaleDownLight(col.rgb); + + // Add windlight lights col.rgb += atmosAmbient(baseLight.rgb); col.rgb += atmosAffectDirectionalLight(calcDirectionalLight(norm, light_position[0].xyz)); - + col.rgb = min(col.rgb*color.rgb, 1.0); - - return col; + + return col; } - diff --git a/indra/newview/app_settings/shaders/class1/objects/previewV.glsl b/indra/newview/app_settings/shaders/class1/objects/previewV.glsl index 7f3f84398..3ad9d61f7 100644 --- a/indra/newview/app_settings/shaders/class1/objects/previewV.glsl +++ b/indra/newview/app_settings/shaders/class1/objects/previewV.glsl @@ -90,7 +90,7 @@ void main() vec4 col = vec4(0,0,0,1); // Collect normal lights (need to be divided by two, as we later multiply by 2) - col.rgb += light_diffuse[1].rgb * calcDirectionalLight(norm, light_position[1].xyz); + col.rgb += light_diffuse[1].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[1], light_direction[1], light_attenuation[1].x, light_attenuation[1].z); col.rgb += light_diffuse[2].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[2], light_direction[2], light_attenuation[2].x, light_attenuation[2].z); col.rgb += light_diffuse[3].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[3], light_direction[3], light_attenuation[3].x, light_attenuation[3].z); diff --git a/indra/newview/app_settings/shaders/class2/lighting/sumLightsSpecularV.glsl b/indra/newview/app_settings/shaders/class2/lighting/sumLightsSpecularV.glsl index 5a0272260..d956a18f7 100644 --- a/indra/newview/app_settings/shaders/class2/lighting/sumLightsSpecularV.glsl +++ b/indra/newview/app_settings/shaders/class2/lighting/sumLightsSpecularV.glsl @@ -24,7 +24,6 @@ */ - float calcDirectionalLightSpecular(inout vec4 specular, vec3 view, vec3 n, vec3 l, vec3 lightCol, float da); vec3 calcPointLightSpecular(inout vec4 specular, vec3 view, vec3 v, vec3 n, vec3 l, float r, float pw, vec3 lightCol); @@ -47,9 +46,9 @@ vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor vec4 specularSum = vec4(0.0); // Collect normal lights (need to be divided by two, as we later multiply by 2) - col.rgb += light_diffuse[1].rgb * calcDirectionalLightSpecular(specularColor, view, norm, light_position[1].xyz,light_diffuse[1].rgb, 1.0); + col.rgb += calcPointLightSpecular(specularSum, view, pos, norm, light_position[1].xyz, light_attenuation[1].x, light_attenuation[1].y, light_diffuse[1].rgb); col.rgb += calcPointLightSpecular(specularSum, view, pos, norm, light_position[2].xyz, light_attenuation[2].x, light_attenuation[2].y, light_diffuse[2].rgb); - col.rgb += calcPointLightSpecular(specularSum, view, pos, norm, light_position[3].xyz, light_attenuation[3].x, light_attenuation[3].y, light_diffuse[3].rgb); + col.rgb += calcPointLightSpecular(specularSum, view, pos, norm, light_position[3].xyz, light_attenuation[3].x, light_attenuation[3].y, light_diffuse[3].rgb); col.rgb = scaleDownLight(col.rgb); // Add windlight lights @@ -58,6 +57,7 @@ vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor col.rgb = min(col.rgb*color.rgb, 1.0); specularColor.rgb = min(specularColor.rgb*specularSum.rgb, 1.0); + col.rgb += specularColor.rgb; return col; diff --git a/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl b/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl index c9987ef3b..13af09c25 100644 --- a/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl +++ b/indra/newview/app_settings/shaders/class2/lighting/sumLightsV.glsl @@ -23,6 +23,7 @@ * $/LicenseInfo$ */ + float calcDirectionalLight(vec3 n, vec3 l); float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, float is_pointlight); @@ -30,29 +31,30 @@ vec3 atmosAmbient(vec3 light); vec3 atmosAffectDirectionalLight(float lightIntensity); vec3 scaleDownLight(vec3 light); + uniform vec4 light_position[8]; uniform vec3 light_direction[8]; -uniform vec3 light_attenuation[8]; +uniform vec3 light_attenuation[8]; uniform vec3 light_diffuse[8]; vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight) { vec4 col = vec4(0.0, 0.0, 0.0, color.a); - - // Collect normal lights (need to be divided by two, as we later multiply by 2) - col.rgb += light_diffuse[1].rgb * calcDirectionalLight(norm, light_position[1].xyz); + // Collect normal lights (need to be divided by two, as we later multiply by 2) + + // Collect normal lights + col.rgb += light_diffuse[1].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[1], light_direction[1], light_attenuation[1].x, light_attenuation[1].z); col.rgb += light_diffuse[2].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[2], light_direction[2], light_attenuation[2].x, light_attenuation[2].z); col.rgb += light_diffuse[3].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[3], light_direction[3], light_attenuation[3].x, light_attenuation[3].z); - col.rgb = scaleDownLight(col.rgb); // Add windlight lights col.rgb += atmosAmbient(baseLight.rgb); col.rgb += atmosAffectDirectionalLight(calcDirectionalLight(norm, light_position[0].xyz)); - + col.rgb = min(col.rgb*color.rgb, 1.0); - - return col; + + return col; } diff --git a/indra/newview/app_settings/shaders/class3/lighting/sumLightsSpecularV.glsl b/indra/newview/app_settings/shaders/class3/lighting/sumLightsSpecularV.glsl index e043ac873..66a127a59 100644 --- a/indra/newview/app_settings/shaders/class3/lighting/sumLightsSpecularV.glsl +++ b/indra/newview/app_settings/shaders/class3/lighting/sumLightsSpecularV.glsl @@ -1,5 +1,5 @@ /** - * @file sumLightsV.glsl + * @file sumLightsSpecularV.glsl * * $LicenseInfo:firstyear=2005&license=viewerlgpl$ * Second Life Viewer Source Code @@ -23,6 +23,7 @@ * $/LicenseInfo$ */ + float calcDirectionalLightSpecular(inout vec4 specular, vec3 view, vec3 n, vec3 l, vec3 lightCol, float da); vec3 calcPointLightSpecular(inout vec4 specular, vec3 view, vec3 v, vec3 n, vec3 l, float r, float pw, vec3 lightCol); @@ -45,7 +46,7 @@ vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor vec4 specularSum = vec4(0.0); // Collect normal lights (need to be divided by two, as we later multiply by 2) - col.rgb += light_diffuse[1].rgb * calcDirectionalLightSpecular(specularColor, view, norm, light_position[1].xyz,light_diffuse[1].rgb, 1.0); + col.rgb += calcPointLightSpecular(specularSum, view, pos, norm, light_position[1].xyz, light_attenuation[1].x, light_attenuation[1].y, light_diffuse[1].rgb); col.rgb += calcPointLightSpecular(specularSum, view, pos, norm, light_position[2].xyz, light_attenuation[2].x, light_attenuation[2].y, light_diffuse[2].rgb); col.rgb += calcPointLightSpecular(specularSum, view, pos, norm, light_position[3].xyz, light_attenuation[3].x, light_attenuation[3].y, light_diffuse[3].rgb); col.rgb += calcPointLightSpecular(specularSum, view, pos, norm, light_position[4].xyz, light_attenuation[4].x, light_attenuation[4].y, light_diffuse[4].rgb); @@ -62,5 +63,6 @@ vec4 sumLightsSpecular(vec3 pos, vec3 norm, vec4 color, inout vec4 specularColor specularColor.rgb = min(specularColor.rgb*specularSum.rgb, 1.0); col.rgb += specularColor.rgb; + return col; } diff --git a/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl b/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl index dadff4093..f6f2ad574 100644 --- a/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl +++ b/indra/newview/app_settings/shaders/class3/lighting/sumLightsV.glsl @@ -30,35 +30,35 @@ float calcPointLightOrSpotLight(vec3 v, vec3 n, vec4 lp, vec3 ln, float la, floa vec3 atmosAmbient(vec3 light); vec3 atmosAffectDirectionalLight(float lightIntensity); vec3 scaleDownLight(vec3 light); -vec3 scaleUpLight(vec3 light); + uniform vec4 light_position[8]; uniform vec3 light_direction[8]; -uniform vec3 light_attenuation[8]; +uniform vec3 light_attenuation[8]; uniform vec3 light_diffuse[8]; vec4 sumLights(vec3 pos, vec3 norm, vec4 color, vec4 baseLight) { vec4 col = vec4(0.0, 0.0, 0.0, color.a); - + // Collect normal lights (need to be divided by two, as we later multiply by 2) - + // Collect normal lights + col.rgb += light_diffuse[1].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[1], light_direction[1], light_attenuation[1].x, light_attenuation[1].z); col.rgb += light_diffuse[2].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[2], light_direction[2], light_attenuation[2].x, light_attenuation[2].z); col.rgb += light_diffuse[3].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[3], light_direction[3], light_attenuation[3].x, light_attenuation[3].z); col.rgb += light_diffuse[4].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[4], light_direction[4], light_attenuation[4].x, light_attenuation[4].z); col.rgb += light_diffuse[5].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[5], light_direction[5], light_attenuation[5].x, light_attenuation[5].z); col.rgb += light_diffuse[6].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[6], light_direction[6], light_attenuation[6].x, light_attenuation[6].z); col.rgb += light_diffuse[7].rgb*calcPointLightOrSpotLight(pos.xyz, norm, light_position[7], light_direction[7], light_attenuation[7].x, light_attenuation[7].z); - col.rgb += light_diffuse[1].rgb*calcDirectionalLight(norm, light_position[1].xyz); col.rgb = scaleDownLight(col.rgb); // Add windlight lights - col.rgb += atmosAffectDirectionalLight(calcDirectionalLight(norm, light_position[0].xyz)); col.rgb += atmosAmbient(baseLight.rgb); + col.rgb += atmosAffectDirectionalLight(calcDirectionalLight(norm, light_position[0].xyz)); col.rgb = min(col.rgb*color.rgb, 1.0); - - return col; + + return col; } diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp index 6cdf1fb46..2f9062047 100644 --- a/indra/newview/llappviewer.cpp +++ b/indra/newview/llappviewer.cpp @@ -475,7 +475,7 @@ static void settings_to_globals() LLSurface::setTextureSize(gSavedSettings.getU32("RegionTextureSize")); - LLRender::sGLCoreProfile = gSavedSettings.getBOOL("RenderGLCoreProfile"); + LLRender::sGLCoreProfile = LLGLSLShader::sNoFixedFunction = gSavedSettings.getBOOL("RenderGLCoreProfile"); LLImageGL::sGlobalUseAnisotropic = gSavedSettings.getBOOL("RenderAnisotropic"); LLImageGL::sCompressTextures = gSavedSettings.getBOOL("RenderCompressTextures"); @@ -1621,6 +1621,9 @@ bool LLAppViewer::cleanup() // Clean up before GL is shut down because we might be holding on to objects with texture references LLSelectMgr::cleanupGlobals(); + // Clean up before shutdownGL. + LLPostProcess::cleanupClass(); + LL_INFOS() << "Shutting down OpenGL" << LL_ENDL; // Shut down OpenGL @@ -1650,8 +1653,6 @@ bool LLAppViewer::cleanup() LLAvatarAppearance::cleanupClass(); LLAvatarAppearance::cleanupClass(); - - LLPostProcess::cleanupClass(); LLTracker::cleanupInstance(); @@ -2594,6 +2595,8 @@ bool LLAppViewer::initWindow() gPipeline.init(); LL_INFOS("AppInit") << "gPipeline Initialized" << LL_ENDL; stop_glerror(); + + gGL.restoreVertexBuffers(); gViewerWindow->initGLDefaults(); gSavedSettings.setBOOL("RenderInitError", FALSE); diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp index f61f317d4..328d514d0 100644 --- a/indra/newview/lldrawpoolalpha.cpp +++ b/indra/newview/lldrawpoolalpha.cpp @@ -150,8 +150,6 @@ void LLDrawPoolAlpha::beginPostDeferredPass(S32 pass) current_shader = target_shader = NULL; LLGLSLShader::bindNoShader(); - - gPipeline.enableLightsDynamic(); } void LLDrawPoolAlpha::endPostDeferredPass(S32 pass) @@ -191,8 +189,6 @@ void LLDrawPoolAlpha::beginRenderPass(S32 pass) { LLGLSLShader::bindNoShader(); } - - gPipeline.enableLightsDynamic(); } void LLDrawPoolAlpha::endRenderPass( S32 pass ) @@ -211,6 +207,8 @@ void LLDrawPoolAlpha::render(S32 pass) LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA); LLGLSPipelineAlpha gls_pipeline_alpha; + LLGLState light_state; + gPipeline.enableLightsDynamic(light_state); if (deferred_render && pass == 1) { //depth only @@ -275,13 +273,14 @@ void LLDrawPoolAlpha::render(S32 pass) if (sShowDebugAlpha) { + LLGLState light_state; if (LLGLSLShader::sNoFixedFunction) { gHighlightProgram.bind(); } else { - gPipeline.enableLightsFullbright(LLColor4(1,1,1,1)); + gPipeline.enableLightsFullbright(light_state); } gGL.diffuseColor4f(0.9f,0.f,0.f,0.4f); @@ -299,6 +298,10 @@ void LLDrawPoolAlpha::render(S32 pass) { gHighlightProgram.unbind(); } + else + { + gPipeline.enableLightsDynamic(light_state); + } } gGL.setSceneBlendType(LLRender::BT_ALPHA); } @@ -337,12 +340,10 @@ void LLDrawPoolAlpha::renderAlphaHighlight(U32 mask) void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) { - BOOL initialized_lighting = FALSE; - BOOL light_enabled = TRUE; - - BOOL use_shaders = LLGLSLShader::sNoFixedFunction; - - BOOL depth_only = (pass == 1 && !LLPipeline::sImpostorRender); + LLGLState light_state; + bool light_enabled = TRUE; + bool use_shaders = LLGLSLShader::sNoFixedFunction; + bool depth_only = (pass == 1 && !LLPipeline::sImpostorRender); for (LLCullResult::sg_iterator i = gPipeline.beginAlphaGroups(); i != gPipeline.endAlphaGroups(); ++i) { @@ -363,7 +364,7 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_GROUP_LOOP); bool disable_cull = is_particle_or_hud_particle; - LLGLDisable cull(disable_cull ? GL_CULL_FACE : 0); + LLGLDisable cull(disable_cull); LLSpatialGroup::drawmap_elem_t& draw_info = group->mDrawMap[LLRenderPass::PASS_ALPHA]; @@ -405,7 +406,6 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) } LLMaterial* mat = deferred_render ? params.mMaterial.get() : NULL; - if (!use_shaders) { llassert_always(!target_shader); @@ -414,18 +414,17 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) llassert_always(!LLGLSLShader::sCurBoundShaderPtr); bool fullbright = depth_only || params.mFullbright; - if(fullbright == !!light_enabled || !initialized_lighting) + if(light_enabled == fullbright) { light_enabled = !fullbright; - initialized_lighting = true; - if (light_enabled) // Turn off lighting if it hasn't already been so. + if (light_enabled) // Set local lights { - gPipeline.enableLightsDynamic(); + gPipeline.enableLightsDynamic(light_state); } - else // Turn on lighting if it isn't already. + else // Set fullbright { - gPipeline.enableLightsFullbright(LLColor4(1,1,1,1)); + gPipeline.enableLightsFullbright(light_state); } } } @@ -580,13 +579,12 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, S32 pass) } } } + if (!light_enabled) + { + gPipeline.enableLightsDynamic(light_state); + } gGL.setSceneBlendType(LLRender::BT_ALPHA); LLVertexBuffer::unbind(); - - if (!light_enabled) - { - gPipeline.enableLightsDynamic(); - } } diff --git a/indra/newview/lldrawpoolavatar.cpp b/indra/newview/lldrawpoolavatar.cpp index 4927a5c70..f2800e3d7 100644 --- a/indra/newview/lldrawpoolavatar.cpp +++ b/indra/newview/lldrawpoolavatar.cpp @@ -292,7 +292,7 @@ void LLDrawPoolAvatar::beginDeferredRiggedAlpha() sVertexProgram = &gDeferredSkinnedAlphaProgram; gPipeline.bindDeferredShader(*sVertexProgram); sDiffuseChannel = sVertexProgram->enableTexture(LLViewerShaderMgr::DIFFUSE_MAP); - gPipeline.enableLightsDynamic(); + gPipeline.enableLightsDynamic(*(LLGLState*)gPipeline.pushRenderPassState()); } void LLDrawPoolAvatar::beginDeferredRiggedMaterialAlpha(S32 pass) @@ -314,7 +314,7 @@ void LLDrawPoolAvatar::beginDeferredRiggedMaterialAlpha(S32 pass) sDiffuseChannel = sVertexProgram->enableTexture(LLViewerShaderMgr::DIFFUSE_MAP); normal_channel = sVertexProgram->enableTexture(LLViewerShaderMgr::BUMP_MAP); specular_channel = sVertexProgram->enableTexture(LLViewerShaderMgr::SPECULAR_MAP); - gPipeline.enableLightsDynamic(); + gPipeline.enableLightsDynamic(*(LLGLState*)gPipeline.pushRenderPassState()); } void LLDrawPoolAvatar::endDeferredRiggedAlpha() { @@ -631,7 +631,7 @@ void LLDrawPoolAvatar::beginImpostor() gImpostorProgram.setMinimumAlpha(0.01f); } - gPipeline.enableLightsFullbright(LLColor4(1,1,1,1)); + gPipeline.enableLightsFullbright(*(LLGLState*)gPipeline.pushRenderPassState()); sDiffuseChannel = 0; } @@ -641,7 +641,6 @@ void LLDrawPoolAvatar::endImpostor() { gImpostorProgram.unbind(); } - gPipeline.enableLightsDynamic(); } void LLDrawPoolAvatar::beginRigid() @@ -1273,7 +1272,7 @@ void LLDrawPoolAvatar::renderAvatars(LLVOAvatar* single_avatar, S32 pass) renderRiggedAlpha(avatarp); if (LLPipeline::sRenderDeferred && !is_post_deferred_render) { //render transparent materials under water - LLGLEnable blend(GL_BLEND); + LLGLEnable blend; gGL.setColorMask(true, true); gGL.blendFunc(LLRender::BF_SOURCE_ALPHA, LLRender::BF_ONE_MINUS_SOURCE_ALPHA, @@ -1305,7 +1304,7 @@ void LLDrawPoolAvatar::renderAvatars(LLVOAvatar* single_avatar, S32 pass) case 12: p = 13; break; } { - LLGLEnable blend(GL_BLEND); + LLGLEnable blend; renderDeferredRiggedMaterial(avatarp, p); } return; @@ -1770,7 +1769,7 @@ void LLDrawPoolAvatar::renderRiggedAlpha(LLVOAvatar* avatar) { if (!mRiggedFace[RIGGED_ALPHA].empty()) { - LLGLEnable blend(GL_BLEND); + LLGLEnable blend; gGL.setColorMask(true, true); gGL.blendFunc(LLRender::BF_SOURCE_ALPHA, @@ -1788,7 +1787,7 @@ void LLDrawPoolAvatar::renderRiggedFullbrightAlpha(LLVOAvatar* avatar) { if (!mRiggedFace[RIGGED_FULLBRIGHT_ALPHA].empty()) { - LLGLEnable blend(GL_BLEND); + LLGLEnable blend; gGL.setColorMask(true, true); gGL.blendFunc(LLRender::BF_SOURCE_ALPHA, @@ -1806,12 +1805,12 @@ void LLDrawPoolAvatar::renderRiggedGlow(LLVOAvatar* avatar) { if (!mRiggedFace[RIGGED_GLOW].empty()) { - LLGLEnable blend(GL_BLEND); - LLGLDisable test(GL_ALPHA_TEST); + LLGLEnable blend; + LLGLDisable test; gGL.flush(); - LLGLEnable polyOffset(GL_POLYGON_OFFSET_FILL); - glPolygonOffset(-1.0f, -1.0f); + LLGLEnable polyOffset; + gGL.setPolygonOffset(-1.0f, -1.0f); gGL.setSceneBlendType(LLRender::BT_ADD); LLGLDepthTest depth(GL_TRUE, GL_FALSE); diff --git a/indra/newview/lldrawpoolbump.cpp b/indra/newview/lldrawpoolbump.cpp index d793454e0..d9a9365cf 100644 --- a/indra/newview/lldrawpoolbump.cpp +++ b/indra/newview/lldrawpoolbump.cpp @@ -421,7 +421,7 @@ void LLDrawPoolBump::renderShiny() if( gSky.mVOSkyp->getCubeMap() ) { - LLGLEnable blend_enable(GL_BLEND); + LLGLEnable blend_enable; if (mVertexShaderLevel > 1) { LLRenderPass::pushBatches(LLRenderPass::PASS_SHINY, sVertexMask | LLVertexBuffer::MAP_TEXTURE_INDEX, TRUE, TRUE); @@ -547,7 +547,7 @@ void LLDrawPoolBump::renderFullbrightShiny() if( gSky.mVOSkyp->getCubeMap() ) { - LLGLEnable blend_enable(GL_BLEND); + LLGLEnable blend_enable; gGL.setSceneBlendType(LLRender::BT_REPLACE); if (mVertexShaderLevel > 1) @@ -748,13 +748,13 @@ void LLDrawPoolBump::renderBump(U32 pass) } LL_RECORD_BLOCK_TIME(FTM_RENDER_BUMP); - LLGLDisable fog(GL_FOG); + LLGLDisable fog; LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE, GL_LEQUAL); - LLGLEnable blend(GL_BLEND); + LLGLEnable blend; gGL.diffuseColor4f(1,1,1,1); /// Get rid of z-fighting with non-bump pass. - LLGLEnable polyOffset(GL_POLYGON_OFFSET_FILL); - glPolygonOffset(-1.0f, -1.0f); + LLGLEnable polyOffset; + gGL.setPolygonOffset(-1.0f, -1.0f); renderBump(pass, sVertexMask); } @@ -1349,8 +1349,8 @@ void LLBumpImageList::onSourceLoaded( BOOL success, LLViewerTexture *src_vi, LLI gPipeline.mScreen.bindTarget(); LLGLDepthTest depth(GL_FALSE); - LLGLDisable cull(GL_CULL_FACE); - LLGLDisable blend(GL_BLEND); + LLGLDisable cull; + LLGLDisable blend; gGL.setColorMask(TRUE, TRUE); gNormalMapGenProgram.bind(); @@ -1373,7 +1373,7 @@ void LLBumpImageList::onSourceLoaded( BOOL success, LLViewerTexture *src_vi, LLI S32 screen_width = gPipeline.mScreen.getWidth(); S32 screen_height = gPipeline.mScreen.getHeight(); - glViewport(0, 0, screen_width, screen_height); + gGL.setViewport(0, 0, screen_width, screen_height); for (S32 left = 0; left < width; left += screen_width) { diff --git a/indra/newview/lldrawpoolground.cpp b/indra/newview/lldrawpoolground.cpp index 2f5849bb0..d3d63a792 100644 --- a/indra/newview/lldrawpoolground.cpp +++ b/indra/newview/lldrawpoolground.cpp @@ -83,8 +83,6 @@ void LLDrawPoolGround::render(S32 pass) LLFace *facep = mDrawFace[0]; - gPipeline.disableLights(); - LLOverrideFaceColor col(this, gSky.mVOSkyp->getGLFogColor()); facep->renderIndexed(); diff --git a/indra/newview/lldrawpoolsimple.cpp b/indra/newview/lldrawpoolsimple.cpp index bc6c108c9..ff864fb85 100644 --- a/indra/newview/lldrawpoolsimple.cpp +++ b/indra/newview/lldrawpoolsimple.cpp @@ -54,12 +54,12 @@ static LLTrace::BlockTimerStatHandle FTM_RENDER_GLOW_PUSH("Glow Push"); void LLDrawPoolGlow::renderPostDeferred(S32 pass) { LL_RECORD_BLOCK_TIME(FTM_RENDER_GLOW); - LLGLEnable blend(GL_BLEND); - LLGLDisable test(GL_ALPHA_TEST); + LLGLEnable blend; + LLGLDisable test; gGL.flush(); /// Get rid of z-fighting with non-glow pass. - LLGLEnable polyOffset(GL_POLYGON_OFFSET_FILL); - glPolygonOffset(-1.0f, -1.0f); + LLGLEnable polyOffset; + gGL.setPolygonOffset(-1.0f, -1.0f); gGL.setSceneBlendType(LLRender::BT_ADD); LLGLDepthTest depth(GL_TRUE, GL_FALSE); @@ -95,12 +95,12 @@ S32 LLDrawPoolGlow::getNumPasses() void LLDrawPoolGlow::render(S32 pass) { LL_RECORD_BLOCK_TIME(FTM_RENDER_GLOW); - LLGLEnable blend(GL_BLEND); - LLGLDisable test(GL_ALPHA_TEST); + LLGLEnable blend; + LLGLDisable test; gGL.flush(); /// Get rid of z-fighting with non-glow pass. - LLGLEnable polyOffset(GL_POLYGON_OFFSET_FILL); - glPolygonOffset(-1.0f, -1.0f); + LLGLEnable polyOffset; + gGL.setPolygonOffset(-1.0f, -1.0f); gGL.setSceneBlendType(LLRender::BT_ADD); U32 shader_level = LLViewerShaderMgr::instance()->getVertexShaderLevel(LLViewerShaderMgr::SHADER_OBJECT); @@ -184,11 +184,12 @@ void LLDrawPoolSimple::endRenderPass(S32 pass) void LLDrawPoolSimple::render(S32 pass) { - LLGLDisable blend(GL_BLEND); + LLGLDisable blend; { //render simple LL_RECORD_BLOCK_TIME(FTM_RENDER_SIMPLE); - gPipeline.enableLightsDynamic(); + LLGLState lighting; + gPipeline.enableLightsDynamic(lighting); if (mVertexShaderLevel > 0) { @@ -208,7 +209,7 @@ void LLDrawPoolSimple::render(S32 pass) } else { - LLGLDisable alpha_test(GL_ALPHA_TEST); + LLGLDisable alpha_test; renderTexture(LLRenderPass::PASS_SIMPLE, getVertexDataMask()); } @@ -270,7 +271,7 @@ void LLDrawPoolAlphaMask::endRenderPass(S32 pass) void LLDrawPoolAlphaMask::render(S32 pass) { - LLGLDisable blend(GL_BLEND); + LLGLDisable blend; LL_RECORD_BLOCK_TIME(FTM_RENDER_ALPHA_MASK); if (mVertexShaderLevel > 0) @@ -286,7 +287,7 @@ void LLDrawPoolAlphaMask::render(S32 pass) } else { - LLGLEnable test(GL_ALPHA_TEST); + LLGLEnable test; pushMaskBatches(LLRenderPass::PASS_ALPHA_MASK, getVertexDataMask(), TRUE, FALSE); gGL.setAlphaRejectSettings(LLRender::CF_DEFAULT); //OK } @@ -356,10 +357,10 @@ void LLDrawPoolFullbrightAlphaMask::render(S32 pass) } else { - LLGLEnable test(GL_ALPHA_TEST); - gPipeline.enableLightsFullbright(LLColor4(1,1,1,1)); + LLGLEnable test; + LLGLState lighting; + gPipeline.enableLightsFullbright(lighting); pushMaskBatches(LLRenderPass::PASS_FULLBRIGHT_ALPHA_MASK, getVertexDataMask(), TRUE, FALSE); - gPipeline.enableLightsDynamic(); gGL.setAlphaRejectSettings(LLRender::CF_DEFAULT); //OK } } @@ -384,8 +385,8 @@ void LLDrawPoolSimple::endDeferredPass(S32 pass) void LLDrawPoolSimple::renderDeferred(S32 pass) { - LLGLDisable blend(GL_BLEND); - LLGLDisable alpha_test(GL_ALPHA_TEST); + LLGLDisable blend; + LLGLDisable alpha_test; { //render simple LL_RECORD_BLOCK_TIME(FTM_RENDER_SIMPLE_DEFERRED); @@ -471,11 +472,11 @@ void LLDrawPoolGrass::endRenderPass(S32 pass) void LLDrawPoolGrass::render(S32 pass) { - LLGLDisable blend(GL_BLEND); + LLGLDisable blend; { LL_RECORD_BLOCK_TIME(FTM_RENDER_GRASS); - LLGLEnable test(GL_ALPHA_TEST); + LLGLEnable test; gGL.setSceneBlendType(LLRender::BT_ALPHA); //render grass LLRenderPass::renderTexture(LLRenderPass::PASS_GRASS, getVertexDataMask()); @@ -538,7 +539,7 @@ void LLDrawPoolFullbright::renderPostDeferred(S32 pass) { LL_RECORD_BLOCK_TIME(FTM_RENDER_FULLBRIGHT); gGL.setColorMask(true, true); - LLGLDisable blend(GL_BLEND); + LLGLDisable blend; U32 fullbright_mask = LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_TEXCOORD0 | LLVertexBuffer::MAP_COLOR | LLVertexBuffer::MAP_TEXTURE_INDEX; pushBatches(LLRenderPass::PASS_FULLBRIGHT, fullbright_mask, TRUE, TRUE); @@ -603,7 +604,8 @@ void LLDrawPoolFullbright::render(S32 pass) } else { - gPipeline.enableLightsFullbright(LLColor4(1,1,1,1)); + LLGLState light_state; + gPipeline.enableLightsFullbright(light_state); U32 fullbright_mask = LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_TEXCOORD0 | LLVertexBuffer::MAP_COLOR; renderTexture(LLRenderPass::PASS_FULLBRIGHT, fullbright_mask); pushBatches(LLRenderPass::PASS_MATERIAL_ALPHA_EMISSIVE, fullbright_mask); @@ -649,7 +651,7 @@ void LLDrawPoolFullbrightAlphaMask::renderPostDeferred(S32 pass) { LL_RECORD_BLOCK_TIME(FTM_RENDER_FULLBRIGHT); gGL.setColorMask(true, true); - LLGLDisable blend(GL_BLEND); + LLGLDisable blend; U32 fullbright_mask = LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_TEXCOORD0 | LLVertexBuffer::MAP_COLOR | LLVertexBuffer::MAP_TEXTURE_INDEX; pushMaskBatches(LLRenderPass::PASS_FULLBRIGHT_ALPHA_MASK, fullbright_mask, TRUE, TRUE); gGL.setColorMask(true, false); diff --git a/indra/newview/lldrawpoolsky.cpp b/indra/newview/lldrawpoolsky.cpp index eb00d1155..c66a1d330 100644 --- a/indra/newview/lldrawpoolsky.cpp +++ b/indra/newview/lldrawpoolsky.cpp @@ -113,11 +113,9 @@ void LLDrawPoolSky::render(S32 pass) LLGLSquashToFarClip far_clip(glh_get_current_projection()); - LLGLEnable fog_enable( (mVertexShaderLevel < 1 && LLViewerCamera::getInstance()->cameraUnderWater()) ? GL_FOG : 0); - - gPipeline.disableLights(); + LLGLEnable fog_enable(mVertexShaderLevel < 1 && LLViewerCamera::getInstance()->cameraUnderWater()); - LLGLDisable clip(GL_CLIP_PLANE0); + LLGLDisable clip; gGL.pushMatrix(); LLVector3 origin = LLViewerCamera::getInstance()->getOrigin(); @@ -152,7 +150,7 @@ void LLDrawPoolSky::renderSkyCubeFace(U8 side) if (LLSkyTex::doInterpolate()) { - LLGLEnable blend(GL_BLEND); + LLGLEnable blend; mSkyTex[side].bindTexture(FALSE); gGL.diffuseColor4f(1, 1, 1, LLSkyTex::getInterpVal()); // lighting is disabled face.renderIndexed(); diff --git a/indra/newview/lldrawpoolterrain.cpp b/indra/newview/lldrawpoolterrain.cpp index 805820b9f..c3fcc5461 100644 --- a/indra/newview/lldrawpoolterrain.cpp +++ b/indra/newview/lldrawpoolterrain.cpp @@ -189,30 +189,33 @@ void LLDrawPoolTerrain::render(S32 pass) } LLGLSPipeline gls; - - if (mVertexShaderLevel > 1 && sShader->mShaderLevel > 0) { - gPipeline.enableLightsDynamic(); + LLGLState light_state; - renderFullShader(); - } - else - { - gPipeline.enableLightsStatic(); + if (mVertexShaderLevel > 1 && sShader->mShaderLevel > 0) + { + gPipeline.enableLightsDynamic(light_state); - if (sDetailMode == 0) + renderFullShader(); + } + else { - renderSimple(); - } - else if (gGLManager.mNumTextureUnits < 4) - { - renderFull2TU(); - gGL.setSceneBlendType(LLRender::BT_ALPHA); - } - else - { - renderFull4TU(); - gGL.setSceneBlendType(LLRender::BT_ALPHA); + gPipeline.enableLightsStatic(light_state); + + if (sDetailMode == 0) + { + renderSimple(); + } + else if (gGLManager.mNumTextureUnits < 4) + { + renderFull2TU(); + gGL.setSceneBlendType(LLRender::BT_ALPHA); + } + else + { + renderFull4TU(); + gGL.setSceneBlendType(LLRender::BT_ALPHA); + } } } @@ -227,15 +230,14 @@ void LLDrawPoolTerrain::render(S32 pass) sShader = &gHighlightProgram; sShader->bind(); gGL.diffuseColor4f(1,1,1,1); - LLGLEnable polyOffset(GL_POLYGON_OFFSET_FILL); - glPolygonOffset(-1.0f, -1.0f); + LLGLEnable polyOffset; + gGL.setPolygonOffset(-1.0f, -1.0f); renderOwnership(); sShader = old_shader; sShader->bind(); } else { - gPipeline.disableLights(); renderOwnership(); } } @@ -491,7 +493,6 @@ void LLDrawPoolTerrain::renderFull4TU() glEnable(GL_TEXTURE_GEN_T); glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); - glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV); glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV); @@ -609,7 +610,7 @@ void LLDrawPoolTerrain::renderFull4TU() gGL.getTexUnit(0)->activate(); { - LLGLEnable blend(GL_BLEND); + LLGLEnable blend; drawLoop(); } @@ -735,7 +736,7 @@ void LLDrawPoolTerrain::renderFull2TU() gGL.getTexUnit(0)->activate(); { - LLGLEnable blend(GL_BLEND); + LLGLEnable blend; drawLoop(); } //---------------------------------------------------------------------------- @@ -774,7 +775,7 @@ void LLDrawPoolTerrain::renderFull2TU() gGL.getTexUnit(1)->setTextureAlphaBlend(LLTexUnit::TBO_REPLACE, LLTexUnit::TBS_PREV_ALPHA); { - LLGLEnable blend(GL_BLEND); + LLGLEnable blend; drawLoop(); } @@ -813,7 +814,7 @@ void LLDrawPoolTerrain::renderFull2TU() gGL.getTexUnit(0)->activate(); { - LLGLEnable blend(GL_BLEND); + LLGLEnable blend; drawLoop(); } diff --git a/indra/newview/lldrawpooltree.cpp b/indra/newview/lldrawpooltree.cpp index c70b17593..c02c55d68 100644 --- a/indra/newview/lldrawpooltree.cpp +++ b/indra/newview/lldrawpooltree.cpp @@ -87,7 +87,6 @@ void LLDrawPoolTree::beginRenderPass(S32 pass) } else { - gPipeline.enableLightsDynamic(); gGL.setAlphaRejectSettings(LLRender::CF_GREATER, 0.5f); } } @@ -101,7 +100,12 @@ void LLDrawPoolTree::render(S32 pass) return; } - LLGLState test(GL_ALPHA_TEST, LLGLSLShader::sNoFixedFunction ? 0 : 1); + LLGLState test(LLGLSLShader::sNoFixedFunction ? 0 : 1); + LLGLState light_state; + if (!LLGLSLShader::sNoFixedFunction) + { + gPipeline.enableLightsDynamic(light_state); + } LLOverrideFaceColor color(this, 1.f, 1.f, 1.f, 1.f); gGL.getTexUnit(sDiffTex)->bind(mTexturep); @@ -211,7 +215,7 @@ void LLDrawPoolTree::beginShadowPass(S32 pass) static const LLCachedControl render_deferred_offset("RenderDeferredTreeShadowOffset",1.f); static const LLCachedControl render_deferred_bias("RenderDeferredTreeShadowBias",1.f); - glPolygonOffset(render_deferred_offset,render_deferred_bias); + gGL.setPolygonOffset(render_deferred_offset,render_deferred_bias); gDeferredTreeShadowProgram.bind(); gDeferredTreeShadowProgram.setMinimumAlpha(0.5f); } @@ -227,7 +231,7 @@ void LLDrawPoolTree::endShadowPass(S32 pass) static const LLCachedControl render_deferred_offset("RenderDeferredSpotShadowOffset",1.f); static const LLCachedControl render_deferred_bias("RenderDeferredSpotShadowBias",1.f); - glPolygonOffset(render_deferred_offset,render_deferred_bias); + gGL.setPolygonOffset(render_deferred_offset,render_deferred_bias); gDeferredTreeShadowProgram.unbind(); } diff --git a/indra/newview/lldrawpoolwater.cpp b/indra/newview/lldrawpoolwater.cpp index 2b8195de2..1928794f2 100644 --- a/indra/newview/lldrawpoolwater.cpp +++ b/indra/newview/lldrawpoolwater.cpp @@ -182,7 +182,7 @@ void LLDrawPoolWater::render(S32 pass) return; } - LLGLEnable blend(GL_BLEND); + LLGLEnable blend; if (mVertexShaderLevel > 0) { @@ -202,11 +202,12 @@ void LLDrawPoolWater::render(S32 pass) LLFace* refl_face = voskyp->getReflFace(); - gPipeline.disableLights(); + LLGLState light_state; + gPipeline.disableLights(light_state); LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE); - LLGLDisable cullFace(GL_CULL_FACE); + LLGLDisable cullFace; // Set up second pass first mWaterImagep->addTextureStats(1024.f*1024.f); @@ -253,7 +254,7 @@ void LLDrawPoolWater::render(S32 pass) glClearStencil(1); glClear(GL_STENCIL_BUFFER_BIT); glClearStencil(0); - LLGLEnable gls_stencil(GL_STENCIL_TEST); + LLGLEnable gls_stencil; glStencilOp(GL_KEEP, GL_REPLACE, GL_KEEP); glStencilFunc(GL_ALWAYS, 0, 0xFFFFFFFF); @@ -369,10 +370,10 @@ void LLDrawPoolWater::renderOpaqueLegacyWater() // of no transparency. And no face culling so // that the underside of the water is also opaque. LLGLDepthTest gls_depth(GL_TRUE, GL_TRUE); - LLGLDisable no_cull(GL_CULL_FACE); - LLGLDisable no_blend(GL_BLEND); - - gPipeline.disableLights(); + LLGLDisable no_cull; + LLGLDisable no_blend; + LLGLState light_state; + gPipeline.disableLights(light_state); //Singu note: This is a hack around bizarre opensim behavior. The opaque water texture we get is pure white and only has one channel. // This behavior is clearly incorrect, so we try to detect that case, purge it from the cache, and try to re-fetch the texture. @@ -522,7 +523,7 @@ void LLDrawPoolWater::shade() return; } - LLGLDisable blend(GL_BLEND); + LLGLDisable blend; LLColor3 light_diffuse(0,0,0); F32 light_exp = 0.0f; @@ -700,8 +701,8 @@ void LLDrawPoolWater::shade() } { - LLGLEnable depth_clamp(gGLManager.mHasDepthClamp ? GL_DEPTH_CLAMP : 0); - LLGLDisable cullface(GL_CULL_FACE); + LLGLEnable depth_clamp(gGLManager.mHasDepthClamp); + LLGLDisable cullface; for (std::vector::iterator iter = mDrawFace.begin(); iter != mDrawFace.end(); iter++) { diff --git a/indra/newview/lldrawpoolwlsky.cpp b/indra/newview/lldrawpoolwlsky.cpp index 11e6525cf..6257187dc 100644 --- a/indra/newview/lldrawpoolwlsky.cpp +++ b/indra/newview/lldrawpoolwlsky.cpp @@ -179,7 +179,7 @@ void LLDrawPoolWLSky::renderSkyHaze(F32 camHeightLocal) const { if (gPipeline.canUseWindLightShaders() && gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_SKY)) { - LLGLDisable blend(GL_BLEND); + LLGLDisable blend; sky_shader->bind(); @@ -202,15 +202,16 @@ void LLDrawPoolWLSky::renderStars(void) const return; LLGLSPipelineSkyBox gls_sky; - LLGLEnable blend(GL_BLEND); + LLGLEnable blend; gGL.setSceneBlendType(LLRender::BT_ALPHA); // *NOTE: have to have bound the cloud noise texture already since register // combiners blending below requires something to be bound // and we might as well only bind once. gGL.getTexUnit(0)->enable(LLTexUnit::TT_TEXTURE); - - gPipeline.disableLights(); + + LLGLState light_state; + gPipeline.disableLights(light_state); /*if (!LLPipeline::sReflectionRender) { @@ -251,7 +252,7 @@ void LLDrawPoolWLSky::renderSkyClouds(F32 camHeightLocal) const { if (gPipeline.canUseWindLightShaders() && gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_WL_CLOUDS) && sCloudNoiseTexture.notNull()) { - LLGLEnable blend(GL_BLEND); + LLGLEnable blend; gGL.setSceneBlendType(LLRender::BT_ALPHA); gGL.getTexUnit(0)->bind(sCloudNoiseTexture); @@ -274,9 +275,9 @@ void LLDrawPoolWLSky::renderHeavenlyBodies() color.mV[VW] = llclamp(color.mV[VW]*color.mV[VW]*4.f,0.f,1.f); LLGLSPipelineSkyBox gls_skybox; - LLGLEnable blend_on(GL_BLEND); + LLGLEnable blend_on; + LLGLDisable lighting; gGL.setSceneBlendType(LLRender::BT_ALPHA); - gPipeline.disableLights(); #if 0 // when we want to re-add a texture sun disc, here's where to do it. LLFace * face = gSky.mVOSkyp->mFace[LLVOSky::FACE_SUN]; @@ -332,10 +333,10 @@ void LLDrawPoolWLSky::renderDeferred(S32 pass) const F32 camHeightLocal = LLWLParamManager::getInstance()->getDomeOffset() * LLWLParamManager::getInstance()->getDomeRadius(); - LLGLDisable stencil(GL_STENCIL_TEST); + LLGLDisable stencil; LLGLSNoFog disableFog; LLGLDepthTest depth(GL_TRUE, GL_FALSE); - LLGLDisable clip(GL_CLIP_PLANE0); + LLGLDisable clip; LLGLSquashToFarClip far_clip(glh_get_current_projection()); @@ -379,7 +380,7 @@ void LLDrawPoolWLSky::render(S32 pass) LLGLSNoFog disableFog; LLGLDepthTest depth(GL_TRUE, GL_FALSE); - LLGLDisable clip(GL_CLIP_PLANE0); + LLGLDisable clip; LLGLSquashToFarClip far_clip(glh_get_current_projection()); diff --git a/indra/newview/lldynamictexture.cpp b/indra/newview/lldynamictexture.cpp index 15c86d0c3..329ef4be6 100644 --- a/indra/newview/lldynamictexture.cpp +++ b/indra/newview/lldynamictexture.cpp @@ -109,7 +109,7 @@ void LLViewerDynamicTexture::generateGLTexture(LLGLint internal_format, LLGLenum } if(fill_color) raw_image->fill(*fill_color); - createGLTexture(0, raw_image, 0, TRUE, LLViewerTexture::DYNAMIC_TEX); + createGLTexture(0, raw_image, LLImageGL::GLTextureName(), TRUE, LLViewerTexture::DYNAMIC_TEX); setAddressMode((mClamp) ? LLTexUnit::TAM_CLAMP : LLTexUnit::TAM_WRAP); mGLTexturep->setGLTextureCreated(false); } @@ -161,9 +161,10 @@ void LLViewerDynamicTexture::preRender(BOOL clear_depth) mCamera.setView(camera->getView()); mCamera.setNear(camera->getNear()); - glViewport(mOrigin.mX, mOrigin.mY, mFullWidth, mFullHeight); + gGL.setViewport(mOrigin.mX, mOrigin.mY, mFullWidth, mFullHeight); if (clear_depth) { + gGL.syncContextState(); glClear(GL_DEPTH_BUFFER_BIT); } } @@ -237,7 +238,8 @@ BOOL LLViewerDynamicTexture::updateAllInstances() { LLViewerDynamicTexture *dynamicTexture = *iter; if (dynamicTexture->needsRender()) - { + { + gGL.syncContextState(); glClear(GL_DEPTH_BUFFER_BIT); gDepthDirty = TRUE; diff --git a/indra/newview/llface.cpp b/indra/newview/llface.cpp index f826f3548..b89053fa3 100644 --- a/indra/newview/llface.cpp +++ b/indra/newview/llface.cpp @@ -576,8 +576,8 @@ void LLFace::renderSelected(LLViewerTexture *imagep, const LLColor4& color) LLRiggedVolume* rigged = volume->getRiggedVolume(); if (rigged) { - LLGLEnable offset(GL_POLYGON_OFFSET_FILL); - glPolygonOffset(-1.f, -1.f); + LLGLEnable offset; + gGL.setPolygonOffset(-1.f, -1.f); gGL.multMatrix(volume->getRelativeXform()); const LLVolumeFace& vol_face = rigged->getVolumeFace(getTEOffset()); @@ -620,8 +620,8 @@ void LLFace::renderSelected(LLViewerTexture *imagep, const LLColor4& color) else { gGL.diffuseColor4fv(color.mV); - LLGLEnable poly_offset(GL_POLYGON_OFFSET_FILL); - glPolygonOffset(-1.f,-1.f); + LLGLEnable poly_offset; + gGL.setPolygonOffset(-1.f,-1.f); // Singu Note: Disable per-vertex color to prevent fixed-function pipeline from using it. We want glColor color, not vertex color! mVertexBuffer->setBuffer(mVertexBuffer->getTypeMask() & ~(LLVertexBuffer::MAP_COLOR)); mVertexBuffer->draw(LLRender::TRIANGLES, mIndicesCount, mIndicesIndex); diff --git a/indra/newview/llfasttimerview.cpp b/indra/newview/llfasttimerview.cpp index 811ccc6f3..98bdcf0f6 100644 --- a/indra/newview/llfasttimerview.cpp +++ b/indra/newview/llfasttimerview.cpp @@ -965,7 +965,7 @@ void LLFastTimerView::draw() if (mHoverID == idp) { gGL.flush(); - glLineWidth(3); + gGL.setLineWidth(3); } const F32 * col = sTimerColors[idp].mV;// ft_display_table[idx].color->mV; @@ -1015,7 +1015,7 @@ void LLFastTimerView::draw() if (mHoverID == idp) { gGL.flush(); - glLineWidth(1); + gGL.setLineWidth(1); } if (idp->getCollapsed()) @@ -1306,7 +1306,7 @@ void LLFastTimerView::exportCharts(const std::string& base, const std::string& t last_p.clear(); - LLGLDisable cull(GL_CULL_FACE); + LLGLDisable cull; LLVector3 base_col(0, 0.7f, 0.f); LLVector3 cur_col(1.f, 0.f, 0.f); @@ -1330,7 +1330,7 @@ void LLFastTimerView::exportCharts(const std::string& base, const std::string& t last_p.clear(); { - LLGLEnable blend(GL_BLEND); + LLGLEnable blend; gGL.color3fv(cur_col.mV); for (U32 i = 0; i < cur_times.size(); ++i) @@ -1371,7 +1371,7 @@ void LLFastTimerView::exportCharts(const std::string& base, const std::string& t gGL.flush(); { - LLGLEnable blend(GL_BLEND); + LLGLEnable blend; gGL.color3fv(cur_col.mV); last_p.clear(); @@ -1419,7 +1419,7 @@ void LLFastTimerView::exportCharts(const std::string& base, const std::string& t last_p.clear(); { - LLGLEnable blend(GL_BLEND); + LLGLEnable blend; gGL.color3fv(cur_col.mV); count = 0; total_count = cur_execution.size(); diff --git a/indra/newview/llfloateravatarpicker.cpp b/indra/newview/llfloateravatarpicker.cpp index 865c64aad..50669c006 100644 --- a/indra/newview/llfloateravatarpicker.cpp +++ b/indra/newview/llfloateravatarpicker.cpp @@ -396,7 +396,7 @@ void LLFloaterAvatarPicker::drawFrustum() if (hasFocus() && frustumOrigin->isInVisibleChain() && mContextConeOpacity > 0.001f) { gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); - LLGLEnable(GL_CULL_FACE); + LLGLEnable clip; gGL.begin(LLRender::TRIANGLE_STRIP); { gGL.color4f(0.f, 0.f, 0.f, mContextConeOutAlpha * mContextConeOpacity); diff --git a/indra/newview/llfloatercolorpicker.cpp b/indra/newview/llfloatercolorpicker.cpp index f7a5e698e..487cccc49 100644 --- a/indra/newview/llfloatercolorpicker.cpp +++ b/indra/newview/llfloatercolorpicker.cpp @@ -503,7 +503,7 @@ void LLFloaterColorPicker::draw() if (hasFocus() && mSwatch->isInVisibleChain() && mContextConeOpacity > 0.001f) { gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); - LLGLEnable(GL_CULL_FACE); + LLGLEnable cull; gGL.begin(LLRender::TRIANGLE_STRIP); { gGL.color4f(0.f, 0.f, 0.f, CONTEXT_CONE_OUT_ALPHA * mContextConeOpacity); diff --git a/indra/newview/llfloaterimagepreview.cpp b/indra/newview/llfloaterimagepreview.cpp index 06553d16f..05964fb81 100644 --- a/indra/newview/llfloaterimagepreview.cpp +++ b/indra/newview/llfloaterimagepreview.cpp @@ -252,7 +252,7 @@ void LLFloaterImagePreview::draw() if (selected <= 0) { gl_rect_2d_checkerboard( calcScreenRect(), mPreviewRect); - LLGLDisable gls_alpha(GL_ALPHA_TEST); + LLGLDisable gls_alpha; if(mImagep.notNull()) { @@ -757,13 +757,14 @@ BOOL LLImagePreviewAvatar::render() { LLGLDepthTest gls_depth(GL_TRUE, GL_TRUE); // make sure alpha=0 shows avatar material color - LLGLDisable no_blend(GL_BLEND); + LLGLDisable no_blend; LLFace* face = avatarp->mDrawable->getFace(0); if (face) { LLDrawPoolAvatar *avatarPoolp = (LLDrawPoolAvatar *)face->getPool(); - gPipeline.enableLightsPreview(); + LLGLState light_state; + gPipeline.enableLightsPreview(light_state); avatarPoolp->renderAvatars(avatarp); // renders only one avatar } } @@ -900,8 +901,8 @@ BOOL LLImagePreviewSculpted::render() { mNeedsUpdate = FALSE; LLGLSUIDefault def; - LLGLDisable no_blend(GL_BLEND); - LLGLEnable cull(GL_CULL_FACE); + LLGLDisable no_blend; + LLGLEnable cull; LLGLDepthTest depth(GL_TRUE); gGL.matrixMode(LLRender::MM_PROJECTION); @@ -928,6 +929,7 @@ BOOL LLImagePreviewSculpted::render() gGL.matrixMode(LLRender::MM_MODELVIEW); gGL.popMatrix(); + gGL.syncContextState(); glClear(GL_DEPTH_BUFFER_BIT); LLVector3 target_pos(0, 0, 0); @@ -950,13 +952,14 @@ BOOL LLImagePreviewSculpted::render() const LLVolumeFace &vf = mVolume->getVolumeFace(0); U32 num_indices = vf.mNumIndices; - gPipeline.enableLightsAvatar(); + LLGLState light_state; + gPipeline.enableLightsAvatar(light_state); if (LLGLSLShader::sNoFixedFunction) { gObjectPreviewProgram.bind(); } - gPipeline.enableLightsPreview(); + gPipeline.enableLightsPreview(light_state); gGL.pushMatrix(); const F32 SCALE = 1.25f; diff --git a/indra/newview/llfloatermodelpreview.cpp b/indra/newview/llfloatermodelpreview.cpp index 68098cb4a..84b19e252 100644 --- a/indra/newview/llfloatermodelpreview.cpp +++ b/indra/newview/llfloatermodelpreview.cpp @@ -3647,10 +3647,10 @@ BOOL LLModelPreview::render() S32 height = getHeight(); LLGLSUIDefault def; - LLGLDisable no_blend(GL_BLEND); - LLGLEnable cull(GL_CULL_FACE); + LLGLDisable no_blend; + LLGLEnable cull; LLGLDepthTest depth(GL_TRUE); - LLGLDisable fog(GL_FOG); + LLGLDisable fog; { if (use_shaders) @@ -3752,6 +3752,7 @@ BOOL LLModelPreview::render() F32 explode = mFMP->childGetValue("physics_explode").asReal(); + gGL.syncContextState(); glClear(GL_DEPTH_BUFFER_BIT); LLRect preview_rect; @@ -3787,7 +3788,8 @@ BOOL LLModelPreview::render() } gGL.loadIdentity(); - gPipeline.enableLightsPreview(); + LLGLState light_state; + gPipeline.enableLightsPreview(light_state); LLQuaternion camera_rot = LLQuaternion(mCameraPitch, LLVector3::y_axis) * LLQuaternion(mCameraYaw, LLVector3::z_axis); @@ -3811,7 +3813,7 @@ BOOL LLModelPreview::render() const U32 type_mask = LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL | LLVertexBuffer::MAP_TEXCOORD0; - LLGLEnable normalize(GL_NORMALIZE); + LLGLEnable normalize; if (!mBaseModel.empty() && mVertexBuffer[5].empty()) { @@ -3906,11 +3908,11 @@ BOOL LLModelPreview::render() if (edges) { - glLineWidth(3.f); - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + gGL.setLineWidth(3.f); + gGL.setPolygonMode(LLRender::PF_FRONT_AND_BACK, LLRender::PM_LINE); buffer->drawRange(LLRender::TRIANGLES, 0, buffer->getNumVerts()-1, buffer->getNumIndices(), 0); - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - glLineWidth(1.f); + gGL.setPolygonMode(LLRender::PF_FRONT_AND_BACK, LLRender::PM_FILL); + gGL.setLineWidth(1.f); } } gGL.popMatrix(); @@ -3918,6 +3920,7 @@ BOOL LLModelPreview::render() if (physics) { + gGL.syncContextState(); glClear(GL_DEPTH_BUFFER_BIT); for (U32 i = 0; i < 2; i++) @@ -3932,7 +3935,7 @@ BOOL LLModelPreview::render() } //enable alpha blending on second pass but not first pass - LLGLState blend(GL_BLEND, i); + LLGLState blend(i); gGL.blendFunc(LLRender::BF_SOURCE_ALPHA, LLRender::BF_ONE_MINUS_SOURCE_ALPHA); @@ -4025,24 +4028,25 @@ BOOL LLModelPreview::render() gGL.diffuseColor3f(1.f, 1.f, 0.f); - glLineWidth(2.f); - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + gGL.setLineWidth(2.f); + gGL.setPolygonMode(LLRender::PF_FRONT_AND_BACK, LLRender::PM_LINE); buffer->drawRange(LLRender::TRIANGLES, 0, buffer->getNumVerts()-1, buffer->getNumIndices(), 0); - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - glLineWidth(1.f); + gGL.setPolygonMode(LLRender::PF_FRONT_AND_BACK, LLRender::PM_FILL); + gGL.setLineWidth(1.f); } } gGL.popMatrix(); } - glLineWidth(3.f); - glPointSize(8.f); - gPipeline.enableLightsFullbright(LLColor4::white); + gGL.setLineWidth(3.f); + gGL.setPointSize(8.f); + LLGLState light_state; + gPipeline.enableLightsFullbright(light_state); //show degenerate triangles LLGLDepthTest depth(GL_TRUE, GL_TRUE, GL_ALWAYS); - LLGLDisable cull(GL_CULL_FACE); + LLGLDisable cull; gGL.diffuseColor4f(1.f,0.f,0.f,1.f); const LLVector4a scale(0.5f); @@ -4109,9 +4113,8 @@ BOOL LLModelPreview::render() gGL.popMatrix(); } - glLineWidth(1.f); - glPointSize(1.f); - gPipeline.enableLightsPreview(); + gGL.setLineWidth(1.f); + gGL.setPointSize(1.f); gGL.setSceneBlendType(LLRender::BT_ALPHA); } } @@ -4163,11 +4166,11 @@ BOOL LLModelPreview::render() if (edges) { - glLineWidth(3.f); - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + gGL.setLineWidth(3.f); + gGL.setPolygonMode(LLRender::PF_FRONT_AND_BACK, LLRender::PM_LINE); buffer->draw(LLRender::TRIANGLES, buffer->getNumIndices(), 0); - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - glLineWidth(1.f); + gGL.setPolygonMode(LLRender::PF_FRONT_AND_BACK, LLRender::PM_FILL); + gGL.setLineWidth(1.f); } } } diff --git a/indra/newview/llfloaterreporter.cpp b/indra/newview/llfloaterreporter.cpp index 0b175dcfa..c9a3d9362 100644 --- a/indra/newview/llfloaterreporter.cpp +++ b/indra/newview/llfloaterreporter.cpp @@ -783,7 +783,7 @@ void LLFloaterReporter::takeScreenshot() // store in the image list so it doesn't try to fetch from the server LLPointer image_in_list = LLViewerTextureManager::getFetchedTexture(mResourceDatap->mAssetInfo.mUuid, FTT_LOCAL_FILE, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::FETCHED_TEXTURE); - image_in_list->createGLTexture(0, raw, 0, TRUE, LLViewerTexture::OTHER); + image_in_list->createGLTexture(0, raw, LLImageGL::GLTextureName(), TRUE, LLViewerTexture::OTHER); // the texture picker then uses that texture LLTexturePicker* texture = getChild("screenshot"); diff --git a/indra/newview/llfloatersnapshot.cpp b/indra/newview/llfloatersnapshot.cpp index 5c96b7c47..009cb3008 100644 --- a/indra/newview/llfloatersnapshot.cpp +++ b/indra/newview/llfloatersnapshot.cpp @@ -552,13 +552,12 @@ void LLSnapshotLivePreview::drawPreviewRect(S32 offset_x, S32 offset_y) alpha_color, TRUE); } // Draw border around captured part. - F32 line_width; - glGetFloatv(GL_LINE_WIDTH, &line_width); - glLineWidth(2.0f * line_width); + F32 line_width = gGL.getLineWidth(); + gGL.setLineWidth(2.0f * line_width); gl_rect_2d( mThumbnailPreviewRect.mLeft + offset_x, mThumbnailPreviewRect.mTop + offset_y, mThumbnailPreviewRect.mRight + offset_x, mThumbnailPreviewRect.mBottom + offset_y, LLColor4::black, FALSE); - glLineWidth(line_width); + gGL.setLineWidth(line_width); } //called when the frame is frozen. diff --git a/indra/newview/llglsandbox.cpp b/indra/newview/llglsandbox.cpp index 0ea1ea384..6dca4a376 100644 --- a/indra/newview/llglsandbox.cpp +++ b/indra/newview/llglsandbox.cpp @@ -670,7 +670,7 @@ void LLViewerParcelMgr::renderCollisionSegments(U8* segments, BOOL use_pass, LLV LLGLSUIDefault gls_ui; LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE); - LLGLDisable cull(GL_CULL_FACE); + LLGLDisable cull; if (mCollisionBanned == BA_BANNED || regionp->getRegionFlag(REGION_FLAGS_BLOCK_FLYOVER)) @@ -846,8 +846,7 @@ void LLViewerObjectList::renderObjectBeacons() S32 line_width = debug_beacon.mLineWidth; if (line_width != last_line_width) { - gGL.flush(); - glLineWidth( (F32)line_width ); + gGL.setLineWidth(line_width); last_line_width = line_width; } @@ -882,8 +881,7 @@ void LLViewerObjectList::renderObjectBeacons() S32 line_width = debug_beacon.mLineWidth; if (line_width != last_line_width) { - gGL.flush(); - glLineWidth( (F32)line_width ); + gGL.setLineWidth(line_width); last_line_width = line_width; } @@ -902,8 +900,7 @@ void LLViewerObjectList::renderObjectBeacons() gGL.end(); } - gGL.flush(); - glLineWidth(1.f); + gGL.setLineWidth(1.f); for (std::vector::iterator iter = mDebugBeacons.begin(); iter != mDebugBeacons.end(); ++iter) { diff --git a/indra/newview/llhudeffectlookat.cpp b/indra/newview/llhudeffectlookat.cpp index 29d2ca87a..0c529f41b 100644 --- a/indra/newview/llhudeffectlookat.cpp +++ b/indra/newview/llhudeffectlookat.cpp @@ -572,7 +572,7 @@ void LLHUDEffectLookAt::render() offset.normalize(); LLVector3 shadow_offset = offset * 0.49f; offset *= 0.5f; - LLGLEnable gl_blend(GL_BLEND); + LLGLEnable gl_blend; const LLFontGL* fontp = LLFontGL::getFontSansSerif(); gGL.pushMatrix(); diff --git a/indra/newview/llhudnametag.cpp b/indra/newview/llhudnametag.cpp index 4c4401795..c80f1818e 100644 --- a/indra/newview/llhudnametag.cpp +++ b/indra/newview/llhudnametag.cpp @@ -281,8 +281,8 @@ void LLHUDNameTag::renderText(BOOL for_select) gGL.getTexUnit(0)->enable(LLTexUnit::TT_TEXTURE); } - LLGLState gls_blend(GL_BLEND, for_select ? FALSE : TRUE); - LLGLState gls_alpha(GL_ALPHA_TEST, for_select ? FALSE : TRUE); + LLGLState gls_blend(for_select ? FALSE : TRUE); + LLGLState gls_alpha(for_select ? FALSE : TRUE); gGL.setSceneBlendType(LLRender::BT_ALPHA); //Workaround avoiding inheriting stale blendstate from... something. LLColor4 shadow_color(0.f, 0.f, 0.f, 1.f); diff --git a/indra/newview/llhudtext.cpp b/indra/newview/llhudtext.cpp index 3227f7d85..c996c462e 100644 --- a/indra/newview/llhudtext.cpp +++ b/indra/newview/llhudtext.cpp @@ -134,9 +134,9 @@ void LLHUDText::renderText() return; } - gGL.getTexUnit(0)->enable(LLTexUnit::TT_TEXTURE); - LLGLState gls_blend(GL_BLEND, TRUE); - LLGLState gls_alpha(GL_ALPHA_TEST, TRUE); + gGL.getTexUnit(0)->enable(LLTexUnit::TT_TEXTURE); + LLGLEnable gls_blend; + LLGLEnable gls_alpha; LLColor4 shadow_color(0.f, 0.f, 0.f, 1.f); F32 alpha_factor = 1.f; @@ -613,12 +613,12 @@ void LLHUDText::markDead() void LLHUDText::renderAllHUD() { - LLGLState::checkStates(); - LLGLState::checkTextureChannels(); - LLGLState::checkClientArrays(); + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkTextureChannels(); + LLGLStateValidator::checkClientArrays(); { - LLGLEnable color_mat(GL_COLOR_MATERIAL); + LLGLEnable color_mat; LLGLDepthTest depth(GL_FALSE, GL_FALSE); VisibleTextObjectIterator text_it; @@ -633,9 +633,9 @@ void LLHUDText::renderAllHUD() LLVertexBuffer::unbind(); - LLGLState::checkStates(); - LLGLState::checkTextureChannels(); - LLGLState::checkClientArrays(); + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkTextureChannels(); + LLGLStateValidator::checkClientArrays(); } void LLHUDText::shiftAll(const LLVector3& offset) diff --git a/indra/newview/llmaniprotate.cpp b/indra/newview/llmaniprotate.cpp index 334e4faf7..6204b8ba1 100644 --- a/indra/newview/llmaniprotate.cpp +++ b/indra/newview/llmaniprotate.cpp @@ -115,8 +115,8 @@ void LLManipRotate::render() LLGLSUIDefault gls_ui; gGL.getTexUnit(0)->bind(LLViewerFetchedTexture::sWhiteImagep); LLGLDepthTest gls_depth(GL_TRUE); - LLGLEnable gl_blend(GL_BLEND); - LLGLEnable gls_alpha_test(GL_ALPHA_TEST); + LLGLEnable gl_blend; + LLGLEnable gls_alpha_test; // You can rotate if you can move LLViewerObject* first_object = mObjectSelection->getFirstMoveableObject(TRUE); @@ -160,7 +160,7 @@ void LLManipRotate::render() gDebugProgram.bind(); } - LLGLEnable cull_face(GL_CULL_FACE); + LLGLEnable cull_face; LLGLDepthTest gls_depth(GL_FALSE); gGL.pushMatrix(); { @@ -286,8 +286,8 @@ void LLManipRotate::render() mManipulatorScales = lerp(mManipulatorScales, LLVector4(1.f, 1.f, 1.f, 1.f), LLSmoothInterpolation::getInterpolant(MANIPULATOR_SCALE_HALF_LIFE)); } - LLGLEnable cull_face(GL_CULL_FACE); - LLGLEnable clip_plane0(GL_CLIP_PLANE0); + LLGLEnable cull_face; + LLGLEnable clip_plane0; LLGLDepthTest gls_depth(GL_FALSE); // First pass: centers. Second pass: sides. @@ -736,7 +736,7 @@ void LLManipRotate::drag( S32 x, S32 y ) void LLManipRotate::renderActiveRing( F32 radius, F32 width, const LLColor4& front_color, const LLColor4& back_color) { - LLGLEnable cull_face(GL_CULL_FACE); + LLGLEnable cull_face; { gl_ring(radius, width, back_color, back_color * 0.5f, CIRCLE_STEPS, FALSE); gl_ring(radius, width, back_color, back_color * 0.5f, CIRCLE_STEPS, TRUE); diff --git a/indra/newview/llmanipscale.cpp b/indra/newview/llmanipscale.cpp index e3574d21b..fedebbd10 100644 --- a/indra/newview/llmanipscale.cpp +++ b/indra/newview/llmanipscale.cpp @@ -213,8 +213,8 @@ void LLManipScale::render() LLGLSUIDefault gls_ui; gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); LLGLDepthTest gls_depth(GL_TRUE); - LLGLEnable gl_blend(GL_BLEND); - LLGLEnable gls_alpha_test(GL_ALPHA_TEST); + LLGLEnable gl_blend; + LLGLEnable gls_alpha_test; LLBBox bbox = LLSelectMgr::getInstance()->getBBoxOfSelection(); if( canAffectSelection() ) @@ -293,8 +293,8 @@ void LLManipScale::render() { - LLGLEnable poly_offset(GL_POLYGON_OFFSET_FILL); - glPolygonOffset( -2.f, -2.f); + LLGLEnable poly_offset; + gGL.setPolygonOffset( -2.f, -2.f); // JC - Band-aid until edge stretch working similar to side stretch // in non-uniform. @@ -308,7 +308,7 @@ void LLManipScale::render() renderGuidelinesPart( bbox ); } - glPolygonOffset( 0.f, 0.f); + gGL.setPolygonOffset( 0.f, 0.f); } } gGL.popMatrix(); diff --git a/indra/newview/llmaniptranslate.cpp b/indra/newview/llmaniptranslate.cpp index 4b8597ff0..5d8c30fb1 100644 --- a/indra/newview/llmaniptranslate.cpp +++ b/indra/newview/llmaniptranslate.cpp @@ -1103,7 +1103,7 @@ void LLManipTranslate::renderSnapGuides() gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); LLGLDepthTest gls_depth(GL_TRUE); - LLGLDisable gls_cull(GL_CULL_FACE); + LLGLDisable gls_cull; LLVector3 translate_axis; if (mManipPart == LL_NO_PART) @@ -1546,7 +1546,7 @@ void LLManipTranslate::renderSnapGuides() LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE); { - LLGLDisable stencil(GL_STENCIL_TEST); + LLGLDisable stencil; { LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE, GL_GREATER); gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, getGridTexName()); @@ -1558,7 +1558,7 @@ void LLManipTranslate::renderSnapGuides() } { - LLGLDisable alpha_test(GL_ALPHA_TEST); + LLGLDisable alpha_test; //draw black overlay gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); renderGrid(u,v,tiles,0.0f, 0.0f, 0.0f,a*0.16f); @@ -1579,7 +1579,7 @@ void LLManipTranslate::renderSnapGuides() { LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE, GL_GREATER); - LLGLEnable stipple(GL_LINE_STIPPLE); + LLGLEnable stipple; gGL.flush(); if (!LLGLSLShader::sNoFixedFunction) @@ -1675,10 +1675,11 @@ void LLManipTranslate::highlightIntersection(LLVector3 normal, { glStencilMask(stencil_mask); glClearStencil(1); + gGL.syncContextState(); glClear(GL_STENCIL_BUFFER_BIT); glClearStencil(0); - LLGLEnable cull_face(GL_CULL_FACE); - LLGLEnable stencil(GL_STENCIL_TEST); + LLGLEnable cull_face; + LLGLEnable stencil; LLGLDepthTest depth (GL_TRUE, GL_FALSE, GL_ALWAYS); glStencilFunc(GL_ALWAYS, 0, stencil_mask); gGL.setColorMask(false, false); @@ -1768,7 +1769,7 @@ void LLManipTranslate::highlightIntersection(LLVector3 normal, { gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); LLGLDepthTest depth(GL_FALSE); - LLGLEnable stencil(GL_STENCIL_TEST); + LLGLEnable stencil; glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); glStencilFunc(GL_EQUAL, 0, stencil_mask); renderGrid(0,0,tiles,inner_color.mV[0], inner_color.mV[1], inner_color.mV[2], 0.25f); @@ -1915,7 +1916,7 @@ void LLManipTranslate::renderTranslationHandles() { gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); - LLGLDisable cull_face(GL_CULL_FACE); + LLGLDisable cull_face; LLColor4 color1; LLColor4 color2; @@ -2207,8 +2208,8 @@ void LLManipTranslate::renderTranslationHandles() void LLManipTranslate::renderArrow(S32 which_arrow, S32 selected_arrow, F32 box_size, F32 arrow_size, F32 handle_size, BOOL reverse_direction) { gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); - LLGLEnable gls_blend(GL_BLEND); - LLGLEnable gls_color_material(GL_COLOR_MATERIAL); + LLGLEnable gls_blend; + LLGLEnable gls_color_material; for (S32 pass = 1; pass <= 2; pass++) { diff --git a/indra/newview/llmediactrl.cpp b/indra/newview/llmediactrl.cpp index bcf77429e..577d2a4b6 100644 --- a/indra/newview/llmediactrl.cpp +++ b/indra/newview/llmediactrl.cpp @@ -756,7 +756,7 @@ void LLMediaCtrl::draw() // alpha off for this LLGLSUIDefault gls_ui; - LLGLDisable gls_alphaTest( GL_ALPHA_TEST ); + LLGLDisable gls_alpha_test; bool draw_media = false; diff --git a/indra/newview/llpaneldisplay.cpp b/indra/newview/llpaneldisplay.cpp index a001c7eae..3bc5db91c 100644 --- a/indra/newview/llpaneldisplay.cpp +++ b/indra/newview/llpaneldisplay.cpp @@ -754,14 +754,14 @@ void LLPanelDisplay::apply() bool logged_in = (LLStartUp::getStartupState() >= STATE_STARTED); LLCoordScreen size; window->getSize(&size); - LLGLState::checkStates(); - LLGLState::checkTextureChannels(); + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkTextureChannels(); gViewerWindow->changeDisplaySettings(window->getFullscreen(), size, vsync_value, logged_in); - LLGLState::checkStates(); - LLGLState::checkTextureChannels(); + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkTextureChannels(); } } diff --git a/indra/newview/llselectmgr.cpp b/indra/newview/llselectmgr.cpp index e36764d02..99c4a5a1c 100644 --- a/indra/newview/llselectmgr.cpp +++ b/indra/newview/llselectmgr.cpp @@ -5683,7 +5683,7 @@ void LLSelectMgr::renderSilhouettes(BOOL for_hud) gGL.getTexUnit(0)->bind(mSilhouetteImagep); LLGLSPipelineSelection gls_select; - LLGLEnable blend(GL_BLEND); + LLGLEnable blend; LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE); if (isAgentAvatarValid() && for_hud) @@ -6188,7 +6188,7 @@ void LLSelectNode::renderOneWireframe(const LLColor4& color) gGL.translatef(trans.mV[0], trans.mV[1], trans.mV[2]); } - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + gGL.setPolygonMode(LLRender::PF_FRONT_AND_BACK, LLRender::PM_LINE); //Singu Note: Diverges from v3. If sRenderHiddenSelections set, draw non-z-culled wireframe, else draw occluded 'thick' wireframe to create an outline. if (LLSelectMgr::sRenderHiddenSelections) // && gFloaterTools && gFloaterTools->getVisible()) @@ -6205,7 +6205,7 @@ void LLSelectNode::renderOneWireframe(const LLColor4& color) { if (!LLGLSLShader::sNoFixedFunction) { - LLGLEnable fog(GL_FOG); + LLGLEnable fog; glFogi(GL_FOG_MODE, GL_LINEAR); float d = (LLViewerCamera::getInstance()->getPointOfInterest() - LLViewerCamera::getInstance()->getOrigin()).magVec(); LLColor4 fogCol = color * (F32)llclamp((LLSelectMgr::getInstance()->getSelectionCenterGlobal() - gAgentCamera.getCameraPositionGlobal()).magVec() / (LLSelectMgr::getInstance()->getBBoxOfSelection().getExtentLocal().magVec() * 4), 0.0, 1.0); @@ -6224,18 +6224,18 @@ void LLSelectNode::renderOneWireframe(const LLColor4& color) } else { - LLGLEnable cull_face(GL_CULL_FACE); - LLGLEnable offset(GL_POLYGON_OFFSET_LINE); + LLGLEnable cull_face; + LLGLEnable offset; gGL.setSceneBlendType(LLRender::BT_ALPHA); gGL.diffuseColor4f(color.mV[VRED]*2, color.mV[VGREEN]*2, color.mV[VBLUE]*2, LLSelectMgr::sHighlightAlpha*2); - glPolygonOffset(3.f, 3.f); - glLineWidth(3.f); + gGL.setPolygonOffset(3.f, 3.f); + gGL.setLineWidth(3.f); pushWireframe(drawable); - glLineWidth(1.f); + gGL.setLineWidth(1.f); } - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + gGL.setPolygonMode(LLRender::PF_FRONT_AND_BACK, LLRender::PM_FILL); gGL.popMatrix(); if (shader) @@ -6330,7 +6330,7 @@ void LLSelectNode::renderOneSilhouette(const LLColor4 &color) gGL.blendFunc(LLRender::BF_SOURCE_COLOR, LLRender::BF_ONE); if (!LLGLSLShader::sNoFixedFunction) { - LLGLEnable fog(GL_FOG); + LLGLEnable fog; glFogi(GL_FOG_MODE, GL_LINEAR); float d = (LLViewerCamera::getInstance()->getPointOfInterest() - LLViewerCamera::getInstance()->getOrigin()).magVec(); LLColor4 fogCol = color * (F32)llclamp((LLSelectMgr::getInstance()->getSelectionCenterGlobal() - gAgentCamera.getCameraPositionGlobal()).magVec() / (LLSelectMgr::getInstance()->getBBoxOfSelection().getExtentLocal().magVec() * 4), 0.0, 1.0); diff --git a/indra/newview/llsky.cpp b/indra/newview/llsky.cpp index de99cb86f..b223acf78 100644 --- a/indra/newview/llsky.cpp +++ b/indra/newview/llsky.cpp @@ -287,38 +287,38 @@ LLColor4U LLSky::getFadeColor() const void LLSky::init(const LLVector3 &sun_direction) { - LLGLState::checkStates(); - LLGLState::checkTextureChannels(); + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkTextureChannels(); mVOWLSkyp = static_cast(gObjectList.createObjectViewer(LLViewerObject::LL_VO_WL_SKY, NULL)); mVOWLSkyp->initSunDirection(sun_direction, LLVector3::zero); gPipeline.createObject(mVOWLSkyp.get()); - LLGLState::checkStates(); - LLGLState::checkTextureChannels(); + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkTextureChannels(); mVOSkyp = (LLVOSky *)gObjectList.createObjectViewer(LLViewerObject::LL_VO_SKY, NULL); - LLGLState::checkStates(); - LLGLState::checkTextureChannels(); + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkTextureChannels(); mVOSkyp->initSunDirection(sun_direction, LLVector3()); - LLGLState::checkStates(); - LLGLState::checkTextureChannels(); + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkTextureChannels(); gPipeline.createObject((LLViewerObject *)mVOSkyp); - LLGLState::checkStates(); - LLGLState::checkTextureChannels(); + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkTextureChannels(); mVOGroundp = (LLVOGround*)gObjectList.createObjectViewer(LLViewerObject::LL_VO_GROUND, NULL); LLVOGround *groundp = mVOGroundp; gPipeline.createObject((LLViewerObject *)groundp); - LLGLState::checkStates(); - LLGLState::checkTextureChannels(); - + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkTextureChannels(); + gSky.setFogRatio(gSavedSettings.getF32("RenderFogRatio")); //////////////////////////// @@ -330,8 +330,8 @@ void LLSky::init(const LLVector3 &sun_direction) // Get the parameters. mSunDefaultPosition = gSavedSettings.getVector3("SkySunDefaultPosition"); - LLGLState::checkStates(); - LLGLState::checkTextureChannels(); + //LLGLStateValidator::checkStates(); + //LLGLStateValidator::checkTextureChannels(); if (gSavedSettings.getBOOL("SkyOverrideSimSunPosition") || mOverrideSimSunPosition) { @@ -342,8 +342,8 @@ void LLSky::init(const LLVector3 &sun_direction) setSunDirection(sun_direction, LLVector3(0.f, 0.f, 0.f)); } - LLGLState::checkStates(); - LLGLState::checkTextureChannels(); + //LLGLStateValidator::checkStates(); + //LLGLStateValidator::checkTextureChannels(); mUpdatedThisFrame = TRUE; } diff --git a/indra/newview/llspatialpartition.cpp b/indra/newview/llspatialpartition.cpp index 7299f6b8e..b10192ca9 100644 --- a/indra/newview/llspatialpartition.cpp +++ b/indra/newview/llspatialpartition.cpp @@ -1558,17 +1558,15 @@ void renderOctree(LLSpatialGroup* group) if (group->mBufferUsage != GL_STATIC_DRAW_ARB) { LLGLDepthTest gl_depth(FALSE, FALSE); - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + gGL.setPolygonMode(LLRender::PF_FRONT_AND_BACK, LLRender::PM_LINE); gGL.diffuseColor4f(1,0,0,group->mBuilt); - gGL.flush(); - glLineWidth(5.f); + gGL.setLineWidth(5.f); const LLVector4a* bounds = group->getObjectBounds(); drawBoxOutline(bounds[0], bounds[1]); - gGL.flush(); - glLineWidth(1.f); - gGL.flush(); + gGL.setLineWidth(1.f); + OctreeGuard guard(group->getOctreeNode()); for (LLSpatialGroup::element_iter i = group->getDataBegin(); i != group->getDataEnd(); ++i) { @@ -1614,7 +1612,7 @@ void renderOctree(LLSpatialGroup* group) gGL.popMatrix(); } } - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + gGL.setPolygonMode(LLRender::PF_FRONT_AND_BACK, LLRender::PM_FILL); gGL.diffuseColor4f(1,1,1,1); } } @@ -1685,10 +1683,10 @@ void renderOctree(LLSpatialGroup* group) void renderVisibility(LLSpatialGroup* group, LLCamera* camera) { - LLGLEnable blend(GL_BLEND); + LLGLEnable blend; gGL.setSceneBlendType(LLRender::BT_ALPHA); - LLGLEnable cull(GL_CULL_FACE); - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + LLGLEnable cull; + gGL.setPolygonMode(LLRender::PF_FRONT_AND_BACK, LLRender::PM_LINE); BOOL render_objects = (!LLPipeline::sUseOcclusion || !group->isOcclusionState(LLSpatialGroup::OCCLUDED)) && group->isVisible() && !group->isEmpty(); @@ -1709,7 +1707,7 @@ void renderVisibility(LLSpatialGroup* group, LLCamera* camera) pushBufferVerts(group, LLVertexBuffer::MAP_VERTEX); } - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + gGL.setPolygonMode(LLRender::PF_FRONT_AND_BACK, LLRender::PM_FILL); if (render_objects) { @@ -1723,11 +1721,11 @@ void renderVisibility(LLSpatialGroup* group, LLCamera* camera) gGL.diffuseColor4f(1.0f, 0.f, 0.f, 0.5f); glDrawRangeElements(GL_TRIANGLE_FAN, 0, 7, 8, GL_UNSIGNED_BYTE, get_box_fan_indices(camera, group->mBounds[0])); - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + gGL.setPolygonMode(LLRender::PF_FRONT_AND_BACK, LLRender::PM_LINE); gGL.diffuseColor4f(1.0f, 1.f, 1.f, 1.0f); glDrawRangeElements(GL_TRIANGLE_FAN, 0, 7, 8, GL_UNSIGNED_BYTE, get_box_fan_indices(camera, group->mBounds[0])); - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + gGL.setPolygonMode(LLRender::PF_FRONT_AND_BACK, LLRender::PM_FILL); }*/ } } @@ -1754,7 +1752,7 @@ void renderUpdateType(LLDrawable* drawablep) { return; } - LLGLEnable blend(GL_BLEND); + LLGLEnable blend; switch (vobj->getLastUpdateType()) { case OUT_FULL: @@ -1847,7 +1845,7 @@ void renderComplexityDisplay(LLDrawable* drawablep) // cap cost ratio at 1.0f in case cost_max is at a low threshold cost_ratio = cost_ratio > 1.0f ? 1.0f : cost_ratio; - LLGLEnable blend(GL_BLEND); + LLGLEnable blend; LLColor4 color; const LLColor4 color_min = gSavedSettings.getColor4("RenderComplexityColorMin"); @@ -1985,13 +1983,11 @@ void renderBoundingBox(LLDrawable* drawable, BOOL set_color = TRUE) LLViewerObject* vobj = drawable->getVObj(); if (vobj && vobj->onActiveList()) { - gGL.flush(); - glLineWidth(llmax(4.f*sinf(gFrameTimeSeconds*2.f)+1.f, 1.f)); + gGL.setLineWidth(llmax(4.f*sinf(gFrameTimeSeconds*2.f)+1.f, 1.f)); //glLineWidth(4.f*(sinf(gFrameTimeSeconds*2.f)*0.25f+0.75f)); stop_glerror(); drawBoxOutline(pos,size); - gGL.flush(); - glLineWidth(1.f); + gGL.setLineWidth(1.f); } else { @@ -2104,14 +2100,14 @@ void render_hull(LLModel::PhysicsMesh& mesh, const LLColor4& color, const LLColo return; gGL.diffuseColor4fv(color.mV); LLVertexBuffer::drawArrays(LLRender::TRIANGLES, mesh.mPositions, mesh.mNormals); - LLGLEnable offset(GL_POLYGON_OFFSET_LINE); - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - glPolygonOffset(3.f, 3.f); - glLineWidth(3.f); + LLGLEnable offset; + gGL.setPolygonMode(LLRender::PF_FRONT_AND_BACK, LLRender::PM_LINE); + gGL.setPolygonOffset(3.f, 3.f); + gGL.setLineWidth(3.f); gGL.diffuseColor4fv(line_color.mV); LLVertexBuffer::drawArrays(LLRender::TRIANGLES, mesh.mPositions, mesh.mNormals); - glLineWidth(1.f); - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + gGL.setLineWidth(1.f); + gGL.setPolygonMode(LLRender::PF_FRONT_AND_BACK, LLRender::PM_FILL); } void renderPhysicsShape(LLDrawable* drawable, LLVOVolume* volume) @@ -2194,10 +2190,10 @@ void renderPhysicsShape(LLDrawable* drawable, LLVOVolume* volume) gGL.diffuseColor4fv(color.mV); LLVertexBuffer::drawArrays(LLRender::TRIANGLES, decomp->mPhysicsShapeMesh.mPositions, decomp->mPhysicsShapeMesh.mNormals); - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + gGL.setPolygonMode(LLRender::PF_FRONT_AND_BACK, LLRender::PM_LINE); gGL.diffuseColor4fv(line_color.mV); LLVertexBuffer::drawArrays(LLRender::TRIANGLES, decomp->mPhysicsShapeMesh.mPositions, decomp->mPhysicsShapeMesh.mNormals); - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + gGL.setPolygonMode(LLRender::PF_FRONT_AND_BACK, LLRender::PM_FILL); } else { //no mesh or decomposition, render base hull @@ -2318,7 +2314,7 @@ void renderPhysicsShape(LLDrawable* drawable, LLVOVolume* volume) { //render hull - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + gGL.setPolygonMode(LLRender::PF_FRONT_AND_BACK, LLRender::PM_LINE); gGL.diffuseColor4fv(line_color.mV); LLVertexBuffer::unbind(); @@ -2328,7 +2324,7 @@ void renderPhysicsShape(LLDrawable* drawable, LLVOVolume* volume) LLVertexBuffer::drawElements(LLRender::TRIANGLES, phys_volume->mNumHullPoints phys_volume->mHullPoints, NULL, phys_volume->mNumHullIndices, phys_volume->mHullIndices); gGL.diffuseColor4fv(color.mV); - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + gGL.setPolygonMode(LLRender::PF_FRONT_AND_BACK, LLRender::PM_FILL); LLVertexBuffer::drawElements(LLRender::TRIANGLES, phys_volume->mNumHullPoints phys_volume->mHullPoints, NULL, phys_volume->mNumHullIndices, phys_volume->mHullIndices); } @@ -2385,13 +2381,13 @@ void renderPhysicsShape(LLDrawable* drawable, LLVOVolume* volume) S32 detail = get_physics_detail(volume_params, volume->getScale()); LLVolume* phys_volume = LLPrimitive::getVolumeManager()->refVolume(volume_params, detail); - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + gGL.setPolygonMode(LLRender::PF_FRONT_AND_BACK, LLRender::PM_LINE); gGL.diffuseColor4fv(line_color.mV); pushVerts(phys_volume); gGL.diffuseColor4fv(color.mV); - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + gGL.setPolygonMode(LLRender::PF_FRONT_AND_BACK, LLRender::PM_FILL); pushVerts(phys_volume); LLPrimitive::getVolumeManager()->unrefVolume(phys_volume); } @@ -2404,11 +2400,11 @@ void renderPhysicsShape(LLDrawable* drawable, LLVOVolume* volume) if (phys_volume->mHullPoints && phys_volume->mHullIndices) { - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + gGL.setPolygonMode(LLRender::PF_FRONT_AND_BACK, LLRender::PM_LINE); gGL.diffuseColor4fv(line_color.mV); LLVertexBuffer::drawElements(LLRender::TRIANGLES, phys_volume->mNumHullPoints, phys_volume->mHullPoints, NULL, phys_volume->mNumHullIndices, phys_volume->mHullIndices); - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + gGL.setPolygonMode(LLRender::PF_FRONT_AND_BACK, LLRender::PM_FILL); gGL.diffuseColor4fv(color.mV); LLVertexBuffer::drawElements(LLRender::TRIANGLES, phys_volume->mNumHullPoints, phys_volume->mHullPoints, NULL, phys_volume->mNumHullIndices, phys_volume->mHullIndices); } @@ -2489,14 +2485,14 @@ void renderPhysicsShapes(LLSpatialGroup* group) LLVertexBuffer* buff = face->getVertexBuffer(); if (buff) { - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + gGL.setPolygonMode(LLRender::PF_FRONT_AND_BACK, LLRender::PM_LINE); buff->setBuffer(LLVertexBuffer::MAP_VERTEX); gGL.diffuseColor3f(0.2f, 0.5f, 0.3f); buff->draw(LLRender::TRIANGLES, buff->getNumIndices(), 0); gGL.diffuseColor3f(0.2f, 1.f, 0.3f); - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + gGL.setPolygonMode(LLRender::PF_FRONT_AND_BACK, LLRender::PM_FILL); buff->draw(LLRender::TRIANGLES, buff->getNumIndices(), 0); } } @@ -2520,7 +2516,7 @@ void renderTexturePriority(LLDrawable* drawable) LLVector4 boost_cold(0,0,0,0); LLVector4 boost_hot(0,1,0,1); - LLGLDisable blend(GL_BLEND); + LLGLDisable blend; //LLViewerTexture* imagep = facep->getTexture(); //if (imagep) @@ -2594,22 +2590,22 @@ void renderTextureAnim(LLDrawInfo* params) return; } - LLGLEnable blend(GL_BLEND); + LLGLEnable blend; gGL.diffuseColor4f(1,1,0,0.5f); pushVerts(params, LLVertexBuffer::MAP_VERTEX); } void renderBatchSize(LLDrawInfo* params) { - LLGLEnable offset(GL_POLYGON_OFFSET_FILL); - glPolygonOffset(-1.f, 1.f); + LLGLEnable offset; + gGL.setPolygonOffset(-1.f, 1.f); gGL.diffuseColor4ubv((GLubyte*) &(params->mDebugColor)); pushVerts(params, LLVertexBuffer::MAP_VERTEX); } void renderShadowFrusta(LLDrawInfo* params) { - LLGLEnable blend(GL_BLEND); + LLGLEnable blend; gGL.setSceneBlendType(LLRender::BT_ADD); LLVector4a center; @@ -2653,7 +2649,7 @@ void renderLights(LLDrawable* drawablep) if (drawablep->getNumFaces()) { - LLGLEnable blend(GL_BLEND); + LLGLEnable blend; gGL.diffuseColor4f(0,1,1,0.5f); for (S32 i = 0; i < drawablep->getNumFaces(); i++) @@ -2736,8 +2732,7 @@ public: if (i == 1) { - gGL.flush(); - glLineWidth(3.f); + gGL.setLineWidth(3.f); } gGL.begin(LLRender::TRIANGLES); @@ -2755,8 +2750,7 @@ public: if (i == 1) { - gGL.flush(); - glLineWidth(1.f); + gGL.setLineWidth(1.f); } } } @@ -2766,14 +2760,14 @@ void renderRaycast(LLDrawable* drawablep) { if (drawablep->getNumFaces()) { - LLGLEnable blend(GL_BLEND); + LLGLEnable blend; gGL.diffuseColor4f(0,1,1,0.5f); if (drawablep->getVOVolume()) { - //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + //gGL.setPolygonMode(LLRender::PF_FRONT_AND_BACK, LLRender::PM_LINE); //pushVerts(drawablep->getFace(gDebugRaycastFaceHit), LLVertexBuffer::MAP_VERTEX); - //glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + //gGL.setPolygonMode(LLRender::PF_FRONT_AND_BACK, LLRender::PM_FILL); LLVOVolume* vobj = drawablep->getVOVolume(); LLVolume* volume = vobj->getVolume(); @@ -2819,7 +2813,7 @@ void renderRaycast(LLDrawable* drawablep) dir.setSub(end, start); gGL.flush(); - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + gGL.setPolygonMode(LLRender::PF_FRONT_AND_BACK, LLRender::PM_LINE); { //render face positions @@ -2842,7 +2836,7 @@ void renderRaycast(LLDrawable* drawablep) } gGL.popMatrix(); - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + gGL.setPolygonMode(LLRender::PF_FRONT_AND_BACK, LLRender::PM_FILL); } } } @@ -2989,7 +2983,7 @@ public: return; } - LLGLDisable stencil(GL_STENCIL_TEST); + LLGLDisable stencil; group->rebuildGeom(); group->rebuildMesh(); @@ -3304,13 +3298,11 @@ void LLSpatialPartition::renderPhysicsShapes() camera = NULL; } - gGL.flush(); gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); - glLineWidth(3.f); + gGL.setLineWidth(3.f); LLOctreeRenderPhysicsShapes render_physics(camera); render_physics.traverse(mOctree); - gGL.flush(); - glLineWidth(1.f); + gGL.setLineWidth(1.f); } void LLSpatialPartition::renderDebug() @@ -3348,11 +3340,12 @@ void LLSpatialPartition::renderDebug() sCurMaxTexPriority = 0.f; } - LLGLDisable cullface(GL_CULL_FACE); - LLGLEnable blend(GL_BLEND); + LLGLDisable cullface; + LLGLEnable blend; gGL.setSceneBlendType(LLRender::BT_ALPHA); gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); - gPipeline.disableLights(); + LLGLState light_state; + gPipeline.disableLights(light_state); LLSpatialBridge* bridge = asBridge(); LLCamera* camera = LLViewerCamera::getInstance(); diff --git a/indra/newview/llstartup.cpp b/indra/newview/llstartup.cpp index ea17267b9..aad89a949 100644 --- a/indra/newview/llstartup.cpp +++ b/indra/newview/llstartup.cpp @@ -1922,13 +1922,13 @@ bool idle_startup() { LL_DEBUGS("AppInit") << "Initializing sky..." << LL_ENDL; // Initialize all of the viewer object classes for the first time (doing things like texture fetches. - LLGLState::checkStates(); - LLGLState::checkTextureChannels(); + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkTextureChannels(); gSky.init(initial_sun_direction); - LLGLState::checkStates(); - LLGLState::checkTextureChannels(); + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkTextureChannels(); } display_startup(); diff --git a/indra/newview/lltexturectrl.cpp b/indra/newview/lltexturectrl.cpp index 5481c3c1f..b7358fa60 100644 --- a/indra/newview/lltexturectrl.cpp +++ b/indra/newview/lltexturectrl.cpp @@ -572,7 +572,7 @@ void LLFloaterTexturePicker::draw() if (gFocusMgr.childHasKeyboardFocus(this) && mOwner->isInVisibleChain() && mContextConeOpacity > 0.001f) { gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); - LLGLEnable(GL_CULL_FACE); + LLGLEnable clip; gGL.begin(LLRender::TRIANGLE_STRIP); { gGL.color4f(0.f, 0.f, 0.f, CONTEXT_CONE_OUT_ALPHA * mContextConeOpacity); diff --git a/indra/newview/lltracker.cpp b/indra/newview/lltracker.cpp index 903b65a04..53abe129e 100644 --- a/indra/newview/lltracker.cpp +++ b/indra/newview/lltracker.cpp @@ -596,7 +596,7 @@ void LLTracker::renderBeacon(LLVector3d pos_global, LLGLSTracker gls_tracker; // default+ CULL_FACE + LIGHTING + GL_BLEND + GL_ALPHA_TEST gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); - LLGLDisable cull_face(GL_CULL_FACE); + LLGLDisable cull_face; LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE); draw_beacon(pos_agent, true, fogged_color, dist); diff --git a/indra/newview/llviewercamera.cpp b/indra/newview/llviewercamera.cpp index abe6ef8bd..92f6421a7 100644 --- a/indra/newview/llviewercamera.cpp +++ b/indra/newview/llviewercamera.cpp @@ -156,7 +156,7 @@ void LLViewerCamera::updateFrustumPlanes(LLCamera& camera, BOOL ortho, BOOL zfli { LLVector3 frust[8]; - LLRect view_port(gGLViewport[0],gGLViewport[1]+gGLViewport[3],gGLViewport[0]+gGLViewport[2],gGLViewport[1]); + const LLRect& view_port = gGLViewport; if (no_hacks) { @@ -280,11 +280,8 @@ void LLViewerCamera::setPerspective(BOOL for_selection, { z_far = MAX_FAR_CLIP; } - glViewport(x, y_from_bot, width, height); - gGLViewport[0] = x; - gGLViewport[1] = y_from_bot; - gGLViewport[2] = width; - gGLViewport[3] = height; + gGLViewport.set(x, y_from_bot + height, x + width, y_from_bot); + gGL.setViewport(gGLViewport); } if (mZoomFactor > 1.f) @@ -352,7 +349,7 @@ void LLViewerCamera::projectScreenToPosAgent(const S32 screen_x, const S32 scree { gGL.unprojectf( LLVector3(screen_x,screen_y,0.f), - gGLModelView, gGLProjection, LLRect(gGLViewport[0],gGLViewport[1]+gGLViewport[3],gGLViewport[0]+gGLViewport[2],gGLViewport[1]), + gGLModelView, gGLProjection, gGLViewport, *pos_agent ); } diff --git a/indra/newview/llviewercontrol.cpp b/indra/newview/llviewercontrol.cpp index ecb6c3c30..c13e2d9c1 100644 --- a/indra/newview/llviewercontrol.cpp +++ b/indra/newview/llviewercontrol.cpp @@ -459,7 +459,7 @@ static bool handleRenderDynamicLODChanged(const LLSD& newvalue) static bool handleRenderLocalLightsChanged(const LLSD& newvalue) { - gPipeline.setLightingDetail(-1); + gPipeline.updateLocalLightingEnabled(); return true; } diff --git a/indra/newview/llviewerdisplay.cpp b/indra/newview/llviewerdisplay.cpp index af647b912..5aa8239d4 100644 --- a/indra/newview/llviewerdisplay.cpp +++ b/indra/newview/llviewerdisplay.cpp @@ -147,22 +147,22 @@ void display_startup() // Required for HTML update in login screen static S32 frame_count = 0; - LLGLState::checkStates(); - LLGLState::checkTextureChannels(); + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkTextureChannels(); if (frame_count++ > 1) // make sure we have rendered a frame first { LLViewerDynamicTexture::updateAllInstances(); } - LLGLState::checkStates(); - LLGLState::checkTextureChannels(); + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkTextureChannels(); gViewerWindow->updateUI(); // Fix ui flicker. + gGL.syncContextState(); glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); LLGLSUIDefault gls_ui; - gPipeline.disableLights(); gViewerWindow->setup2DRender(); gGL.getTexUnit(0)->setTextureBlendType(LLTexUnit::TB_MULT); @@ -173,10 +173,11 @@ void display_startup() LLVertexBuffer::unbind(); - LLGLState::checkStates(); - LLGLState::checkTextureChannels(); + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkTextureChannels(); gViewerWindow->getWindow()->swapBuffers(); + gGL.syncContextState(); glClear(GL_DEPTH_BUFFER_BIT); } @@ -264,6 +265,12 @@ int sCurCacheHit = 0; void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot, bool tiling) { LL_RECORD_BLOCK_TIME(FTM_RENDER); + /*if (gViewerWindow->getWindow()->getFullscreen() && (!gViewerWindow->getWindow() || !gViewerWindow->getWindow()->getVisible() || !gFocusMgr.getAppHasFocus())) + { + return; + }*/ + gViewerWindow->checkSettings(); + LLVBOPool::deleteReleasedBuffers(); for (auto avatar : LLCharacter::sInstances) { @@ -277,6 +284,7 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot, boo if (gWindowResized) { //skip render on frames where window has been resized gGL.flush(); + gGL.syncContextState(); glClear(GL_COLOR_BUFFER_BIT); gViewerWindow->getWindow()->swapBuffers(); LLPipeline::refreshCachedSettings(); @@ -304,12 +312,13 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot, boo LLVertexBuffer::unbind(); - LLGLState::checkStates(); - LLGLState::checkTextureChannels(); + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkTextureChannels(); stop_glerror(); - gPipeline.disableLights(); + LLGLState light_state; + gPipeline.disableLights(light_state); //reset vertex buffers if needed gPipeline.doResetVertexBuffers(); @@ -337,13 +346,6 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot, boo stop_glerror(); return; } - - gViewerWindow->checkSettings(); - - if(gWindowResized) //Singu Note: gViewerWindow->checkSettings() can call LLViewerWindow::reshape(). If it has then skip this frame. - { - return; - } { LL_RECORD_BLOCK_TIME(FTM_PICK); @@ -352,8 +354,8 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot, boo } LLAppViewer::instance()->pingMainloopTimeout("Display:CheckStates"); - LLGLState::checkStates(); - LLGLState::checkTextureChannels(); + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkTextureChannels(); ////////////////////////////////////////////////////////// // @@ -652,6 +654,7 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot, boo if (LLViewerDynamicTexture::updateAllInstances()) { gGL.setColorMask(true, true); + gGL.syncContextState(); glClear(GL_DEPTH_BUFFER_BIT); } } @@ -691,7 +694,7 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot, boo const F32 max_geom_update_time = 0.005f*10.f*gFrameIntervalSeconds; // 50 ms/second update time gPipeline.createObjects(max_geom_update_time); gPipeline.processPartitionQ(); - gPipeline.updateGeom(max_geom_update_time); + gPipeline.updateGeom(max_geom_update_time, *LLViewerCamera::getInstance()); stop_glerror(); gPipeline.updateGL(); stop_glerror(); @@ -733,9 +736,9 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot, boo } gDepthDirty = FALSE; - LLGLState::checkStates(); - LLGLState::checkTextureChannels(); - LLGLState::checkClientArrays(); + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkTextureChannels(); + LLGLStateValidator::checkClientArrays(); static LLCullResult result; LLViewerCamera::sCurCameraID = LLViewerCamera::CAMERA_WORLD; @@ -743,9 +746,9 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot, boo gPipeline.updateCull(*LLViewerCamera::getInstance(), result, water_clip); stop_glerror(); - LLGLState::checkStates(); - LLGLState::checkTextureChannels(); - LLGLState::checkClientArrays(); + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkTextureChannels(); + LLGLStateValidator::checkClientArrays(); BOOL to_texture = LLGLSLShader::sNoFixedFunction && LLPipeline::sRenderGlow; @@ -763,9 +766,9 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot, boo gGL.setColorMask(true, true); glClearColor(0,0,0,0); - LLGLState::checkStates(); - LLGLState::checkTextureChannels(); - LLGLState::checkClientArrays(); + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkTextureChannels(); + LLGLStateValidator::checkClientArrays(); if (!for_snapshot || LLPipeline::sRenderDeferred) { @@ -777,13 +780,13 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot, boo LLVertexBuffer::unbind(); - LLGLState::checkStates(); - LLGLState::checkTextureChannels(); - LLGLState::checkClientArrays(); + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkTextureChannels(); + LLGLStateValidator::checkClientArrays(); const LLMatrix4a saved_proj = glh_get_current_projection(); const LLMatrix4a saved_mod = glh_get_current_modelview(); - glViewport(0,0,512,512); + gGL.setViewport(0,0,512,512); LLVOAvatar::updateFreezeCounter() ; if(!LLPipeline::sMemAllocationThrottled) @@ -799,16 +802,17 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot, boo gGL.loadMatrix(saved_mod); gViewerWindow->setup3DViewport(); - LLGLState::checkStates(); - LLGLState::checkTextureChannels(); - LLGLState::checkClientArrays(); + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkTextureChannels(); + LLGLStateValidator::checkClientArrays(); } + gGL.syncContextState(); glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); } - LLGLState::checkStates(); - LLGLState::checkClientArrays(); + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkClientArrays(); //if (!for_snapshot) { @@ -817,8 +821,8 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot, boo gPipeline.renderPhysicsDisplay(); } - LLGLState::checkStates(); - LLGLState::checkClientArrays(); + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkClientArrays(); ////////////////////////////////////// // @@ -862,8 +866,8 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot, boo }*/ } LL_PUSH_CALLSTACKS(); - LLGLState::checkStates(); - LLGLState::checkClientArrays(); + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkClientArrays(); /////////////////////////////////// // @@ -893,8 +897,8 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot, boo } } - LLGLState::checkStates(); - LLGLState::checkClientArrays(); + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkClientArrays(); LLPipeline::sUseOcclusion = occlusion; @@ -910,10 +914,13 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot, boo // [/RLVa:KB] { glClearColor(0.5f, 0.5f, 0.5f, 0.f); + gGL.syncContextState(); glClear(GL_COLOR_BUFFER_BIT); - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + gGL.setPolygonMode(LLRender::PF_FRONT_AND_BACK, LLRender::PM_LINE); } + LLVBOPool::deleteReleasedBuffers(); + LLAppViewer::instance()->pingMainloopTimeout("Display:RenderStart"); //// render frontmost floater opaque for occlusion culling purposes @@ -955,8 +962,8 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot, boo LLPipeline::sUnderWaterRender = LLViewerCamera::getInstance()->cameraUnderWater() ? TRUE : FALSE; - LLGLState::checkStates(); - LLGLState::checkClientArrays(); + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkClientArrays(); stop_glerror(); @@ -1031,7 +1038,7 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot, boo if (render_depth_pre_pass && LLGLSLShader::sNoFixedFunction) { LLGLDepthTest depth(GL_TRUE, GL_TRUE); - LLGLEnable cull_face(GL_CULL_FACE); + LLGLEnable cull_face; gGL.setColorMask(false, false); U32 types[] = { @@ -1050,6 +1057,8 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot, boo } gGL.setColorMask(true, false); + LLGLEnable lighting; + LLGLEnable normalize; if (LLPipeline::sRenderDeferred) { gPipeline.renderGeomDeferred(*LLViewerCamera::getInstance()); @@ -1148,6 +1157,8 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot, boo LLAppViewer::instance()->pingMainloopTimeout("Display:Done"); gShiftFrame = false; + + LLVBOPool::deleteReleasedBuffers(); } void render_hud_attachments() @@ -1343,7 +1354,7 @@ static LLTrace::BlockTimerStatHandle FTM_SWAP("Swap"); void render_ui(F32 zoom_factor, int subfield, bool tiling) { - LLGLState::checkStates(); + LLGLStateValidator::checkStates(); const LLMatrix4a saved_view = glh_get_current_modelview(); @@ -1374,9 +1385,6 @@ void render_ui(F32 zoom_factor, int subfield, bool tiling) LLGLSDefault gls_default; LLGLSUIDefault gls_ui; - { - gPipeline.disableLights(); - } { gGL.color4f(1,1,1,1); @@ -1387,7 +1395,7 @@ void render_ui(F32 zoom_factor, int subfield, bool tiling) if (!gDisconnected) { render_ui_3d(); - LLGLState::checkStates(); + LLGLStateValidator::checkStates(); } else { @@ -1395,7 +1403,7 @@ void render_ui(F32 zoom_factor, int subfield, bool tiling) } render_ui_2d(); - LLGLState::checkStates(); + LLGLStateValidator::checkStates(); } gGL.flush(); @@ -1537,7 +1545,7 @@ void render_ui_2d() // Render 2D UI elements that overlay the world (no z compare) // Disable wireframe mode below here, as this is HUD/menus - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + gGL.setPolygonMode(LLRender::PF_FRONT_AND_BACK, LLRender::PM_FILL); // Menu overlays, HUD, etc gViewerWindow->setup2DRender(); diff --git a/indra/newview/llviewerjoint.cpp b/indra/newview/llviewerjoint.cpp index 6e08ca8a4..47f967a35 100644 --- a/indra/newview/llviewerjoint.cpp +++ b/indra/newview/llviewerjoint.cpp @@ -98,7 +98,7 @@ U32 LLViewerJoint::render( F32 pixelArea, BOOL first_pass, BOOL is_dummy ) if ((pixelArea > MIN_PIXEL_AREA_3PASS_HAIR)) { // render all three passes - LLGLDisable cull(GL_CULL_FACE); + LLGLDisable cull; // first pass renders without writing to the z buffer { LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE); diff --git a/indra/newview/llviewerjointattachment.cpp b/indra/newview/llviewerjointattachment.cpp index a2e2f7811..c80963db3 100644 --- a/indra/newview/llviewerjointattachment.cpp +++ b/indra/newview/llviewerjointattachment.cpp @@ -83,7 +83,7 @@ U32 LLViewerJointAttachment::drawShape( F32 pixelArea, BOOL first_pass, BOOL is_ { if (LLVOAvatar::sShowAttachmentPoints) { - LLGLDisable cull_face(GL_CULL_FACE); + LLGLDisable cull_face; gGL.color4f(1.f, 1.f, 1.f, 1.f); gGL.begin(LLRender::TRIANGLE_STRIP); diff --git a/indra/newview/llvieweroctree.cpp b/indra/newview/llvieweroctree.cpp index 43954da25..937fc7e3d 100644 --- a/indra/newview/llvieweroctree.cpp +++ b/indra/newview/llvieweroctree.cpp @@ -1177,7 +1177,7 @@ static LLTrace::BlockTimerStatHandle FTM_OCCLUSION_DRAW("Draw"); void LLOcclusionCullingGroup::doOcclusion(LLCamera* camera, const LLVector4a* shift) { - LLGLDisable stencil(GL_STENCIL_TEST); + LLGLDisable stencil; if (mSpatialPartition->isOcclusionEnabled() && LLPipeline::sUseOcclusion > 1) { //move mBounds to the agent space if necessary @@ -1218,7 +1218,7 @@ void LLOcclusionCullingGroup::doOcclusion(LLCamera* camera, const LLVector4a* sh (mSpatialPartition->mDrawableType == LLDrawPool::POOL_WATER || mSpatialPartition->mDrawableType == LLDrawPool::POOL_VOIDWATER); - LLGLEnable clamp(use_depth_clamp ? GL_DEPTH_CLAMP : 0); + LLGLEnable clamp(use_depth_clamp); #if !LL_DARWIN U32 mode = gGLManager.mHasOcclusionQuery2 ? GL_ANY_SAMPLES_PASSED : GL_SAMPLES_PASSED_ARB; diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp index f1b8223ca..0c78b8c23 100644 --- a/indra/newview/llviewershadermgr.cpp +++ b/indra/newview/llviewershadermgr.cpp @@ -309,7 +309,7 @@ void LLViewerShaderMgr::setShaders() } // Lighting - gPipeline.setLightingDetail(-1); + gPipeline.updateLocalLightingEnabled(); // Shaders LL_INFOS("ShaderLoading") << "\n~~~~~~~~~~~~~~~~~~\n Loading Shaders:\n~~~~~~~~~~~~~~~~~~" << LL_ENDL; @@ -523,11 +523,14 @@ void LLViewerShaderMgr::unloadShaders() mVertexShaderLevel[i] = 0; //Unset all shader-dependent static variables. - LLGLSLShader::sNoFixedFunction = false; + LLGLSLShader::sNoFixedFunction = LLRender::sGLCoreProfile; LLGLSLShader::sIndexedTextureChannels = 1; LLPipeline::sRenderDeferred = false; LLPipeline::sWaterReflections = FALSE; LLPipeline::sRenderGlow = FALSE; + + // Clear sync hashes. If shaders were just turned off then glLight state needs to be resynced. + gGL.resetSyncHashes(); } BOOL LLViewerShaderMgr::loadBasicShaders() @@ -547,7 +550,7 @@ BOOL LLViewerShaderMgr::loadBasicShaders() } // If we have sun and moon only checked, then only sum those lights. - if (gPipeline.getLightingDetail() == 0) + if (!gPipeline.isLocalLightingEnabled()) { sum_lights_class = 1; } diff --git a/indra/newview/llviewerstats.cpp b/indra/newview/llviewerstats.cpp index af6c56891..15023ff5d 100644 --- a/indra/newview/llviewerstats.cpp +++ b/indra/newview/llviewerstats.cpp @@ -618,7 +618,7 @@ void update_statistics() } } stats.setStat(LLViewerStats::ST_ENABLE_VBO, (F64)gSavedSettings.getBOOL("RenderVBOEnable")); - stats.setStat(LLViewerStats::ST_LIGHTING_DETAIL, (F64)gPipeline.getLightingDetail()); + stats.setStat(LLViewerStats::ST_LIGHTING_DETAIL, (F64)gPipeline.isLocalLightingEnabled()); stats.setStat(LLViewerStats::ST_DRAW_DIST, (F64)gSavedSettings.getF32("RenderFarClip")); stats.setStat(LLViewerStats::ST_CHAT_BUBBLES, (F64)gSavedSettings.getBOOL("UseChatBubbles")); #if 0 // 1.9.2 diff --git a/indra/newview/llviewertexture.cpp b/indra/newview/llviewertexture.cpp index 9379995c6..2ebf1681a 100644 --- a/indra/newview/llviewertexture.cpp +++ b/indra/newview/llviewertexture.cpp @@ -1297,7 +1297,7 @@ void LLViewerFetchedTexture::addToCreateTexture() if(isForSculptOnly()) { //just update some variables, not to create a real GL texture. - createGLTexture(mRawDiscardLevel, mRawImage, 0, FALSE); + createGLTexture(mRawDiscardLevel, mRawImage, LLImageGL::GLTextureName(), FALSE); mNeedsCreateTexture = FALSE; destroyRawImage(); } @@ -1360,7 +1360,7 @@ void LLViewerFetchedTexture::addToCreateTexture() } // ONLY called from LLViewerTextureList -BOOL LLViewerFetchedTexture::createTexture(S32 usename/*= 0*/) +BOOL LLViewerFetchedTexture::createTexture(LLImageGL::GLTextureName& usename) { if (!mNeedsCreateTexture) { @@ -1370,8 +1370,7 @@ BOOL LLViewerFetchedTexture::createTexture(S32 usename/*= 0*/) mNeedsCreateTexture = FALSE; if (mRawImage.isNull()) { - LL_ERRS() << "LLViewerTexture trying to create texture with no Raw Image" << LL_ENDL; - + LL_WARNS() << "LLViewerTexture trying to create texture with no Raw Image" << LL_ENDL; } // LL_INFOS() << llformat("IMAGE Creating (%d) [%d x %d] Bytes: %d ", // mRawDiscardLevel, diff --git a/indra/newview/llviewertexture.h b/indra/newview/llviewertexture.h index 5b5ae3dfe..d5fb51114 100644 --- a/indra/newview/llviewertexture.h +++ b/indra/newview/llviewertexture.h @@ -318,7 +318,7 @@ public: void addToCreateTexture(); // ONLY call from LLViewerTextureList - BOOL createTexture(S32 usename = 0); + BOOL createTexture(LLImageGL::GLTextureName& usename = LLImageGL::GLTextureName()); void destroyTexture() ; virtual void processTextureStats() ; diff --git a/indra/newview/llviewertexturelist.cpp b/indra/newview/llviewertexturelist.cpp index f3e57ec72..885ba2d87 100644 --- a/indra/newview/llviewertexturelist.cpp +++ b/indra/newview/llviewertexturelist.cpp @@ -351,6 +351,7 @@ void LLViewerTextureList::dump() void LLViewerTextureList::destroyGL(BOOL save_state) { + clearFetchingRequests(); LLImageGL::destroyGL(save_state); } diff --git a/indra/newview/llviewerwindow.cpp b/indra/newview/llviewerwindow.cpp index f0b9ee732..3ae1c9733 100644 --- a/indra/newview/llviewerwindow.cpp +++ b/indra/newview/llviewerwindow.cpp @@ -187,6 +187,7 @@ #include "llfloaternotificationsconsole.h" #include "llpanelnearbymedia.h" +#include "llmessagetemplate.h" // [RLVa:KB] #include "rlvhandler.h" @@ -504,7 +505,7 @@ public: //show streaming cost/triangle count of known prims in current region OR selection //Note: This is SUPER slow - { + /*{ F32 cost = 0.f; S32 count = 0; S32 vcount = 0; @@ -553,7 +554,7 @@ public: count/1000.f, vcount/1000.f, visible_bytes/1024.f, total_bytes/1024.f, object_count)); ypos += y_inc; - } + }*/ addText(xpos, ypos, llformat("%d MB Index Data (%d MB Pooled, %d KIndices)", LLVertexBuffer::sAllocatedIndexBytes/(1024*1024), LLVBOPool::sIndexBytesPooled/(1024*1024), LLVertexBuffer::sIndexCount/1024)); ypos += y_inc; @@ -690,10 +691,16 @@ public: ypos += y_inc; } + addText(xpos, ypos, llformat("%d/%d bytes allocted to messages", sMsgDataAllocSize, sMsgdataAllocCount)); + LLVertexBuffer::sBindCount = LLImageGL::sBindCount = LLVertexBuffer::sSetCount = LLImageGL::sUniqueCount = gPipeline.mNumVisibleNodes = LLPipeline::sVisibleLightCount = 0; } + + sMsgDataAllocSize = 0; + sMsgdataAllocCount = 0; + static const LLCachedControl debug_show_render_matrices("DebugShowRenderMatrices"); if (debug_show_render_matrices) { @@ -1399,6 +1406,9 @@ void LLViewerWindow::handleScanKey(KEY key, BOOL key_down, BOOL key_up, BOOL key BOOL LLViewerWindow::handleActivate(LLWindow *window, BOOL activated) { + if (mActive == (bool)activated) { + return TRUE; + } if (activated) { mActive = true; @@ -1406,7 +1416,8 @@ BOOL LLViewerWindow::handleActivate(LLWindow *window, BOOL activated) gAgent.clearAFK(); if (mWindow->getFullscreen() && !mIgnoreActivate) { - if (!LLApp::isExiting() ) + // Opengl doesn't need torn down when alt tabbing. + /*if (!LLApp::isExiting() ) { if (LLStartUp::getStartupState() >= STATE_STARTED) { @@ -1420,7 +1431,7 @@ BOOL LLViewerWindow::handleActivate(LLWindow *window, BOOL activated) restoreGL(); } } - else + else*/ { LL_WARNS() << "Activating while quitting" << LL_ENDL; } @@ -1446,11 +1457,12 @@ BOOL LLViewerWindow::handleActivate(LLWindow *window, BOOL activated) send_agent_pause(); - if (mWindow->getFullscreen() && !mIgnoreActivate) + // Opengl doesn't need torn down when alt tabbing. + /*if (mWindow->getFullscreen() && !mIgnoreActivate) { LL_INFOS() << "Stopping GL during deactivation" << LL_ENDL; stopGL(); - } + }*/ // Mute audio audio_update_volume(false); } @@ -2382,7 +2394,7 @@ void LLViewerWindow::reshape(S32 width, S32 height) // reshape messages. We don't care about these, and we // don't want to send messages because the message system // may have been destructed. - if (!LLApp::isExiting()) + if (!LLApp::isExiting()/* && !gGLManager.mIsDisabled*/) { if (gNoRender) { @@ -2390,7 +2402,7 @@ void LLViewerWindow::reshape(S32 width, S32 height) } gWindowResized = TRUE; - glViewport(0, 0, width, height ); + gGL.setViewport(0, 0, width, height ); if (height > 0) { @@ -2554,8 +2566,6 @@ void LLViewerWindow::draw() LLView::sIsDrawing = TRUE; #endif stop_glerror(); - - LLUI::setLineWidth(1.f); LLUI::setLineWidth(1.f); // Reset any left-over transforms @@ -3764,8 +3774,8 @@ void LLViewerWindow::renderSelections( BOOL for_gl_pick, BOOL pick_parcel_walls, if (LLSelectMgr::sRenderLightRadius && LLToolMgr::getInstance()->inEdit()) { gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); - LLGLEnable gls_blend(GL_BLEND); - LLGLEnable gls_cull(GL_CULL_FACE); + LLGLEnable gls_blend; + LLGLEnable gls_cull; LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE); gGL.matrixMode(LLRender::MM_MODELVIEW); gGL.pushMatrix(); @@ -4540,14 +4550,14 @@ void LLViewerWindow::movieSize(S32 new_width, S32 new_height) if (gViewerWindow->getWindow()->getFullscreen()) { - LLGLState::checkStates(); - LLGLState::checkTextureChannels(); + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkTextureChannels(); gViewerWindow->changeDisplaySettings(FALSE, new_size, vsync_mode, TRUE); - LLGLState::checkStates(); - LLGLState::checkTextureChannels(); + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkTextureChannels(); } else { @@ -4765,6 +4775,7 @@ bool LLViewerWindow::rawRawSnapshot(LLImageRaw *raw, // PRE SNAPSHOT gDisplaySwapBuffers = FALSE; + gGL.syncContextState(); glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); setCursor(UI_CURSOR_WAIT); @@ -5217,11 +5228,10 @@ void LLViewerWindow::setup2DRender() void LLViewerWindow::setup2DViewport(S32 x_offset, S32 y_offset) { - gGLViewport[0] = mWindowRectRaw.mLeft + x_offset; - gGLViewport[1] = mWindowRectRaw.mBottom + y_offset; - gGLViewport[2] = mWindowRectRaw.getWidth(); - gGLViewport[3] = mWindowRectRaw.getHeight(); - glViewport(gGLViewport[0], gGLViewport[1], gGLViewport[2], gGLViewport[3]); + gGLViewport = mWindowRectRaw; + gGLViewport.translate(x_offset, y_offset); + gGL.setViewport(gGLViewport); + gGL.setScissor(gGLViewport); } @@ -5234,11 +5244,10 @@ void LLViewerWindow::setup3DRender() void LLViewerWindow::setup3DViewport(S32 x_offset, S32 y_offset) { - gGLViewport[0] = getWindowRectRaw().mLeft + x_offset; - gGLViewport[1] = getWindowRectRaw().mBottom + y_offset; - gGLViewport[2] = getWindowRectRaw().getWidth(); - gGLViewport[3] = getWindowRectRaw().getHeight(); - glViewport(gGLViewport[0], gGLViewport[1], gGLViewport[2], gGLViewport[3]); + gGLViewport = mWindowRectRaw; + gGLViewport.translate(x_offset, y_offset); + gGL.setViewport(gGLViewport); + gGL.setScissor(gGLViewport); } void LLViewerWindow::revealIntroPanel() @@ -5318,6 +5327,7 @@ void LLViewerWindow::dumpState() void LLViewerWindow::stopGL(BOOL save_state) { + stop_glerror(); //Note: --bao //if not necessary, do not change the order of the function calls in this function. //if change something, make sure it will not break anything. @@ -5347,6 +5357,7 @@ void LLViewerWindow::stopGL(BOOL save_state) stop_glerror(); LLVOPartGroup::destroyGL(); + stop_glerror(); LLViewerDynamicTexture::destroyGL(); stop_glerror(); @@ -5355,8 +5366,10 @@ void LLViewerWindow::stopGL(BOOL save_state) { gPipeline.destroyGL(); } + stop_glerror(); gBox.cleanupGL(); + stop_glerror(); if(LLPostProcess::instanceExists()) { @@ -5365,11 +5378,15 @@ void LLViewerWindow::stopGL(BOOL save_state) gTextureList.destroyGL(save_state); stop_glerror(); + gGL.destroyGL(); + stop_glerror(); gGLManager.mIsDisabled = TRUE; stop_glerror(); - gGL.resetVertexBuffers(); + LLVertexBuffer::cleanupClass(); + + stop_glerror(); LL_INFOS() << "Remaining allocated texture memory: " << LLImageGL::sGlobalTextureMemory << " bytes" << LL_ENDL; } @@ -5383,28 +5400,43 @@ void LLViewerWindow::restoreGL(const std::string& progress_message) //especially, be careful to put something before gTextureList.restoreGL(); if (gGLManager.mIsDisabled) { + stop_glerror(); LL_INFOS() << "Restoring GL..." << LL_ENDL; gGLManager.mIsDisabled = FALSE; gGL.init(); + stop_glerror(); initGLDefaults(); + stop_glerror(); gGL.refreshState(); //Singu Note: Call immediately. Cached states may have prevented initGLDefaults from actually applying changes. - LLGLState::restoreGL(); + stop_glerror(); + LLGLStateValidator::restoreGL(); + stop_glerror(); gTextureList.restoreGL(); + stop_glerror(); // for future support of non-square pixels, and fonts that are properly stretched //LLFontGL::destroyDefaultFonts(); initFonts(); + stop_glerror(); gSky.restoreGL(); + stop_glerror(); gPipeline.restoreGL(); + stop_glerror(); LLDrawPoolWater::restoreGL(); + stop_glerror(); LLManipTranslate::restoreGL(); + stop_glerror(); gBumpImageList.restoreGL(); + stop_glerror(); LLViewerDynamicTexture::restoreGL(); + stop_glerror(); LLVOAvatar::restoreGL(); + stop_glerror(); LLVOPartGroup::restoreGL(); + stop_glerror(); gResizeScreenTexture = TRUE; gWindowResized = TRUE; @@ -5426,8 +5458,9 @@ void LLViewerWindow::restoreGL(const std::string& progress_message) { LL_WARNS() << " Someone took over my signal/exception handler (post restoreGL)!" << LL_ENDL; } - + stop_glerror(); } + } void LLViewerWindow::initFonts(F32 zoom_factor) @@ -5486,7 +5519,7 @@ BOOL LLViewerWindow::checkSettings() { //Singu Note: Don't do the following. //setShaders is already called in restoreGL(), and gGL.refreshState() is too as to maintain blend states. - //This maintaining of blend states is needed for LLGLState::checkStates() to not error out. + //This maintaining of blend states is needed for LLGLStateValidator::checkStates() to not error out. /*if (mStatesDirty) { gGL.refreshState(); @@ -5520,6 +5553,9 @@ BOOL LLViewerWindow::checkSettings() BOOL is_fullscreen = mWindow->getFullscreen(); if(mWantFullscreen) { + if (mWindow->getMinimized()) { + return FALSE; + } LLCoordScreen screen_size; LLCoordScreen desired_screen_size(gSavedSettings.getS32("FullScreenWidth"), gSavedSettings.getS32("FullScreenHeight")); @@ -5533,8 +5569,8 @@ BOOL LLViewerWindow::checkSettings() return FALSE; } - LLGLState::checkStates(); - LLGLState::checkTextureChannels(); + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkTextureChannels(); S32 vsync_mode = gSavedSettings.getS32("SHRenderVsyncMode"); if(vsync_mode == -1 && !gGLManager.mHasAdaptiveVsync) @@ -5546,8 +5582,8 @@ BOOL LLViewerWindow::checkSettings() desired_screen_size, vsync_mode, mShowFullscreenProgress); - LLGLState::checkStates(); - LLGLState::checkTextureChannels(); + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkTextureChannels(); return TRUE; } } @@ -5556,15 +5592,15 @@ BOOL LLViewerWindow::checkSettings() if(is_fullscreen) { // Changing to windowed mode. - LLGLState::checkStates(); - LLGLState::checkTextureChannels(); + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkTextureChannels(); changeDisplaySettings(FALSE, LLCoordScreen(gSavedSettings.getS32("WindowWidth"), gSavedSettings.getS32("WindowHeight")), TRUE, mShowFullscreenProgress); - LLGLState::checkStates(); - LLGLState::checkTextureChannels(); + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkTextureChannels(); return TRUE; } } diff --git a/indra/newview/llvoavatar.cpp b/indra/newview/llvoavatar.cpp index 5b22d4613..53e34f3bb 100644 --- a/indra/newview/llvoavatar.cpp +++ b/indra/newview/llvoavatar.cpp @@ -1352,11 +1352,7 @@ void LLVOAvatar::deleteLayerSetCaches(bool clearAll) mBakedTextureDatas[i].mTexLayerSet->deleteCaches(); } } - if (mBakedTextureDatas[i].mMaskTexName) - { - LLImageGL::deleteTextures(1, (GLuint*)&(mBakedTextureDatas[i].mMaskTexName)); - mBakedTextureDatas[i].mMaskTexName = 0 ; - } + mBakedTextureDatas[i].mMaskTexName.reset(); } } @@ -1914,7 +1910,7 @@ void LLVOAvatar::renderCollisionVolumes() void LLVOAvatar::renderBones() { - LLGLEnable blend(GL_BLEND); + LLGLEnable blend; avatar_joint_list_t::iterator iter = mSkeleton.begin(); avatar_joint_list_t::iterator end = mSkeleton.end(); @@ -5090,7 +5086,7 @@ U32 LLVOAvatar::renderSkinned(EAvatarRenderPass pass) { bool is_muted = LLPipeline::sImpostorRender && isVisuallyMuted(); //Disable masking and also disable alpha in LLViewerJoint::render const bool should_alpha_mask = !is_muted && shouldAlphaMask(); - LLGLState test(GL_ALPHA_TEST, should_alpha_mask); + LLGLState test(should_alpha_mask); if (should_alpha_mask && !LLGLSLShader::sNoFixedFunction) { @@ -5140,8 +5136,8 @@ U32 LLVOAvatar::renderSkinned(EAvatarRenderPass pass) if (!LLDrawPoolAvatar::sSkipTransparent || LLPipeline::sImpostorRender) { - LLGLState blend(GL_BLEND, !mIsDummy); - LLGLState test(GL_ALPHA_TEST, !mIsDummy); + LLGLState blend(!mIsDummy); + LLGLState test(!mIsDummy); num_indices += renderTransparent(first_pass); } } @@ -5226,7 +5222,7 @@ U32 LLVOAvatar::renderRigid() } const bool should_alpha_mask = shouldAlphaMask(); - LLGLState test(GL_ALPHA_TEST, should_alpha_mask); + LLGLState test(should_alpha_mask); if (should_alpha_mask && !LLGLSLShader::sNoFixedFunction) { @@ -5293,7 +5289,7 @@ U32 LLVOAvatar::renderRigid() LLGLDepthTest test(GL_TRUE, GL_FALSE); //render foot shadows - LLGLEnable blend(GL_BLEND); + LLGLEnable blend; gGL.getTexUnit(0)->bind(mShadowImagep.get(), TRUE); gGL.diffuseColor4fv(mShadow0Facep->getRenderColor().mV); mShadow0Facep->renderIndexed(foot_mask); @@ -5319,7 +5315,7 @@ U32 LLVOAvatar::renderImpostor(LLColor4U color, S32 diffuse_channel) left *= mImpostorDim.mV[0]; up *= mImpostorDim.mV[1]; - LLGLEnable test(GL_ALPHA_TEST); + LLGLEnable test; gGL.setAlphaRejectSettings(LLRender::CF_GREATER, 0.f); gGL.color4ubv(color.mV); @@ -9174,11 +9170,10 @@ void LLVOAvatar::onBakedTextureMasksLoaded( BOOL success, LLViewerFetchedTexture return; } - U32 gl_name; - LLImageGL::generateTextures(1, &gl_name ); + auto gl_name = LLImageGL::createTextureName(); stop_glerror(); - gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, gl_name); + gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, gl_name->getTexName()); stop_glerror(); LLImageGL::setManualImage( @@ -9210,10 +9205,6 @@ void LLVOAvatar::onBakedTextureMasksLoaded( BOOL success, LLViewerFetchedTexture const EBakedTextureIndex baked_index = texture_dict->mBakedTextureIndex; self->applyMorphMask(aux_src->getData(), aux_src->getWidth(), aux_src->getHeight(), 1, baked_index); maskData->mLastDiscardLevel = discard_level; - if (self->mBakedTextureDatas[baked_index].mMaskTexName) - { - LLImageGL::deleteTextures(1, &(self->mBakedTextureDatas[baked_index].mMaskTexName)); - } self->mBakedTextureDatas[baked_index].mMaskTexName = gl_name; found_texture_id = true; break; diff --git a/indra/newview/llvosky.cpp b/indra/newview/llvosky.cpp index 2ef89327b..2ef1c6e2c 100644 --- a/indra/newview/llvosky.cpp +++ b/indra/newview/llvosky.cpp @@ -298,7 +298,7 @@ void LLSkyTex::create(const F32 brightness) void LLSkyTex::createGLImage(S32 which) { - mTexture[which]->createGLTexture(0, mImageRaw[which], 0, TRUE, LLGLTexture::LOCAL); + mTexture[which]->createGLTexture(0, mImageRaw[which], LLImageGL::GLTextureName(), TRUE, LLGLTexture::LOCAL); mTexture[which]->setAddressMode(LLTexUnit::TAM_CLAMP); } diff --git a/indra/newview/llwaterparammanager.cpp b/indra/newview/llwaterparammanager.cpp index 9390a2733..764662079 100644 --- a/indra/newview/llwaterparammanager.cpp +++ b/indra/newview/llwaterparammanager.cpp @@ -76,6 +76,14 @@ #include "llagentcamera.h" +static LLStaticHashedString sLightNorm ("lightnorm"); +static LLStaticHashedString sCamPosLocal("camPosLocal"); +static LLStaticHashedString sWaterFogColor("waterFogColor"); +static LLStaticHashedString sWaterPlane("waterPlane"); +static LLStaticHashedString sWaterFogDensity("waterFogDensity"); +static LLStaticHashedString sWaterFogKS("waterFogKS"); +static LLStaticHashedString sDistanceMultiplier("distance_multiplier"); + LLWaterParamManager::LLWaterParamManager() : mFogColor(22.f/255.f, 43.f/255.f, 54.f/255.f, 0.0f, 0.0f, "waterFogColor", "WaterFogColor"), mFogDensity(4, "waterFogDensity", 2), @@ -359,13 +367,13 @@ void LLWaterParamManager::updateShaderLinks() if (shaders_iter->mProgramObject != 0 && shaders_iter->mShaderGroup == LLGLSLShader::SG_WATER) { - if( glGetUniformLocationARB(shaders_iter->mProgramObject,"lightnorm")>=0 || - glGetUniformLocationARB(shaders_iter->mProgramObject,"camPosLocal")>=0 || - glGetUniformLocationARB(shaders_iter->mProgramObject,"waterFogColor")>=0 || - glGetUniformLocationARB(shaders_iter->mProgramObject,"waterPlane")>=0 || - glGetUniformLocationARB(shaders_iter->mProgramObject,"waterFogDensity")>=0 || - glGetUniformLocationARB(shaders_iter->mProgramObject,"waterFogKS")>=0 || - glGetUniformLocationARB(shaders_iter->mProgramObject,"distance_multiplier")>=0) + if( shaders_iter->getUniformLocation(sLightNorm) >=0 || + shaders_iter->getUniformLocation(sCamPosLocal) >=0 || + shaders_iter->getUniformLocation(sWaterFogColor) >=0 || + shaders_iter->getUniformLocation(sWaterPlane) >=0 || + shaders_iter->getUniformLocation(sWaterFogDensity) >=0 || + shaders_iter->getUniformLocation(sWaterFogKS) >=0 || + shaders_iter->getUniformLocation(sDistanceMultiplier) >=0) mShaderList.push_back(&(*shaders_iter)); } } diff --git a/indra/newview/llwlparammanager.cpp b/indra/newview/llwlparammanager.cpp index 7175354e7..b5c01ff0b 100644 --- a/indra/newview/llwlparammanager.cpp +++ b/indra/newview/llwlparammanager.cpp @@ -268,9 +268,7 @@ void LLWLParamManager::addAllSkies(const LLWLParamKey::EScope scope, const LLSD& { for(LLSD::map_const_iterator iter = sky_presets.beginMap(); iter != sky_presets.endMap(); ++iter) { - LLWLParamSet set; - set.setAll(iter->second); - mParamList[LLWLParamKey(iter->first, scope)] = set; + setParamSet(LLWLParamKey(iter->first, scope), iter->second); } } @@ -606,9 +604,9 @@ bool LLWLParamManager::hasParamSet(const LLWLParamKey& key) return getParamSet(key, dummy); } -bool LLWLParamManager::setParamSet(const std::string& name, LLWLParamSet& param) +bool LLWLParamManager::setParamSet(const std::string& name, LLWLParamSet& param, LLEnvKey::EScope scope) { - const LLWLParamKey key(name, LLEnvKey::SCOPE_LOCAL); + const LLWLParamKey key(name, scope); return setParamSet(key, param); } @@ -621,9 +619,9 @@ bool LLWLParamManager::setParamSet(const LLWLParamKey& key, LLWLParamSet& param) return true; } -bool LLWLParamManager::setParamSet(const std::string& name, const LLSD & param) +bool LLWLParamManager::setParamSet(const std::string& name, const LLSD & param, LLEnvKey::EScope scope) { - const LLWLParamKey key(name, LLEnvKey::SCOPE_LOCAL); + const LLWLParamKey key(name, scope); return setParamSet(key, param); } diff --git a/indra/newview/llwlparammanager.h b/indra/newview/llwlparammanager.h index d244d4c47..8318f0414 100644 --- a/indra/newview/llwlparammanager.h +++ b/indra/newview/llwlparammanager.h @@ -205,11 +205,11 @@ public: bool hasParamSet(const LLWLParamKey& key); /// set the param in the list with a new param - bool setParamSet(const std::string& name, LLWLParamSet& param); + bool setParamSet(const std::string& name, LLWLParamSet& param, LLEnvKey::EScope scope = LLEnvKey::SCOPE_LOCAL); bool setParamSet(const LLWLParamKey& key, LLWLParamSet& param); /// set the param in the list with a new param - bool setParamSet(const std::string& name, LLSD const & param); + bool setParamSet(const std::string& name, LLSD const & param, LLEnvKey::EScope scope = LLEnvKey::SCOPE_LOCAL); bool setParamSet(const LLWLParamKey& key, LLSD const & param); /// gets rid of a parameter and any references to it diff --git a/indra/newview/llwlparamset.cpp b/indra/newview/llwlparamset.cpp index 9e88a12a8..0e2769df2 100644 --- a/indra/newview/llwlparamset.cpp +++ b/indra/newview/llwlparamset.cpp @@ -86,8 +86,7 @@ void LLWLParamSet::update(LLGLSLShader * shader) const { continue; } - - if (param == sCloudDensity) + else if (param == sCloudDensity) { LLVector4 val; val.mV[0] = F32(i->second[0].asReal()) + mCloudScrollXOffset; @@ -99,55 +98,58 @@ void LLWLParamSet::update(LLGLSLShader * shader) const shader->uniform4fv(param, 1, val.mV); stop_glerror(); } - else if (param == sCloudScale || param == sCloudShadow || - param == sDensityMultiplier || param == sDistanceMultiplier || - param == sHazeDensity || param == sHazeHorizon || - param == sMaxY ) - { - F32 val = (F32) i->second[0].asReal(); - - stop_glerror(); - shader->uniform1f(param, val); - stop_glerror(); - } else // param is the uniform name { // handle all the different cases - if (i->second.isArray() && i->second.size() == 4) + if (i->second.isArray()) { - LLVector4 val; - - val.mV[0] = (F32) i->second[0].asReal(); - val.mV[1] = (F32) i->second[1].asReal(); - val.mV[2] = (F32) i->second[2].asReal(); - val.mV[3] = (F32) i->second[3].asReal(); - stop_glerror(); - shader->uniform4fv(param, 1, val.mV); + // Switch statement here breaks msbuild for some reason + if (i->second.size() == 4) + { + LLVector4 val( + i->second[0].asFloat(), + i->second[1].asFloat(), + i->second[2].asFloat(), + i->second[3].asFloat() + ); + shader->uniform4fv(param, 1, val.mV); + } + else if (i->second.size() == 3) + { + shader->uniform3f(param, + i->second[0].asFloat(), + i->second[1].asFloat(), + i->second[2].asFloat()); + } + else if (i->second.size() == 2) + { + shader->uniform2f(param, + i->second[0].asFloat(), + i->second[1].asFloat()); + } + else if (i->second.size() == 1) + { + shader->uniform1f(param, i->second[0].asFloat()); + } stop_glerror(); } else if (i->second.isReal()) { - F32 val = (F32) i->second.asReal(); - stop_glerror(); - shader->uniform1f(param, val); + shader->uniform1f(param, i->second.asFloat()); stop_glerror(); } else if (i->second.isInteger()) { - S32 val = (S32) i->second.asInteger(); - stop_glerror(); - shader->uniform1i(param, val); + shader->uniform1i(param, i->second.asInteger()); stop_glerror(); } else if (i->second.isBoolean()) { - S32 val = (i->second.asBoolean() ? 1 : 0); - stop_glerror(); - shader->uniform1i(param, val); + shader->uniform1i(param, i->second.asBoolean() ? 1 : 0); stop_glerror(); } } @@ -155,9 +157,9 @@ void LLWLParamSet::update(LLGLSLShader * shader) const } void LLWLParamSet::set(const std::string& paramName, float x) -{ +{ // handle case where no array - if(mParamValues[paramName].isReal()) + if(mParamValues.isUndefined() || mParamValues[paramName].isReal()) { mParamValues[paramName] = x; } @@ -265,7 +267,7 @@ void LLWLParamSet::setSunAngle(float val) val = F_TWO_PI * num; } - mParamValues["sun_angle"] = val; + set("sun_angle", val); } @@ -279,7 +281,7 @@ void LLWLParamSet::setEastAngle(float val) val = F_TWO_PI * num; } - mParamValues["east_angle"] = val; + set("east_angle", val); } void LLWLParamSet::mix(LLWLParamSet& src, LLWLParamSet& dest, F32 weight) @@ -292,7 +294,7 @@ void LLWLParamSet::mix(LLWLParamSet& src, LLWLParamSet& dest, F32 weight) F32 cloudPos1Y = (F32) mParamValues["cloud_pos_density1"][1].asReal(); F32 cloudPos2X = (F32) mParamValues["cloud_pos_density2"][0].asReal(); F32 cloudPos2Y = (F32) mParamValues["cloud_pos_density2"][1].asReal(); - F32 cloudCover = (F32) mParamValues["cloud_shadow"][0].asReal(); + F32 cloudCover = (F32) mParamValues["cloud_shadow"].asReal(); LLSD srcVal; LLSD destVal; @@ -381,11 +383,9 @@ void LLWLParamSet::mix(LLWLParamSet& src, LLWLParamSet& dest, F32 weight) // now setup the sun properly // reset those cloud positions - mParamValues["cloud_pos_density1"][0] = cloudPos1X; - mParamValues["cloud_pos_density1"][1] = cloudPos1Y; - mParamValues["cloud_pos_density2"][0] = cloudPos2X; - mParamValues["cloud_pos_density2"][1] = cloudPos2Y; - mParamValues["cloud_shadow"][0] = cloudCover; + set("cloud_pos_density1", cloudPos1X, cloudPos1Y); + set("cloud_pos_density2", cloudPos2X, cloudPos2Y); + set("cloud_shadow", cloudCover); } void LLWLParamSet::updateCloudScrolling(void) @@ -410,7 +410,16 @@ void LLWLParamSet::updateHashedNames() // Iterate through values for(LLSD::map_iterator iter = mParamValues.beginMap(); iter != mParamValues.endMap(); ++iter) { - mParamHashedNames.push_back(LLStaticHashedString(iter->first)); + LLStaticHashedString param(iter->first); + mParamHashedNames.push_back(param); + if (iter->second.isArray() && (param == sCloudScale || param == sCloudShadow || + param == sDensityMultiplier || param == sDistanceMultiplier || + param == sHazeDensity || param == sHazeHorizon || + param == sMaxY)) + { + // Params are incorrect in the XML files. These SHOULD be F32, not arrays. + iter->second.assign(iter->second[0]); + } } } diff --git a/indra/newview/llwlparamset.h b/indra/newview/llwlparamset.h index 16bdf8ba3..afede29f1 100644 --- a/indra/newview/llwlparamset.h +++ b/indra/newview/llwlparamset.h @@ -198,7 +198,7 @@ inline const LLSD& LLWLParamSet::getAll() } inline void LLWLParamSet::setStarBrightness(float val) { - mParamValues["star_brightness"] = val; + set("star_brightness", val); } inline F32 LLWLParamSet::getStarBrightness() { @@ -213,7 +213,6 @@ inline F32 LLWLParamSet::getEastAngle() { return (F32) mParamValues["east_angle"].asReal(); } - inline void LLWLParamSet::setEnableCloudScrollX(bool val) { mParamValues["enable_cloud_scroll"][0] = val; } diff --git a/indra/newview/llworldmapview.cpp b/indra/newview/llworldmapview.cpp index d9f85ec9b..5fd4821dd 100644 --- a/indra/newview/llworldmapview.cpp +++ b/indra/newview/llworldmapview.cpp @@ -741,7 +741,7 @@ void LLWorldMapView::draw() } // turn off the scissor - LLGLDisable no_scissor(GL_SCISSOR_TEST); + LLGLDisable no_scissor; updateDirections(); diff --git a/indra/newview/m7wlinterface.cpp b/indra/newview/m7wlinterface.cpp index c2bceeaf2..e57bf4c05 100644 --- a/indra/newview/m7wlinterface.cpp +++ b/indra/newview/m7wlinterface.cpp @@ -110,17 +110,17 @@ void M7WindlightInterface::receiveMessage(LLMessageSystem* msg) mWindlight.set("ambient", wl->ambient.red * 3.0f, wl->ambient.green * 3.0f, wl->ambient.blue * 3.0f, wl->ambient.alpha * 3.0f); mWindlight.set("blue_horizon", wl->horizon.red * 2.0f, wl->horizon.green *2.0f, wl->horizon.blue * 2.0f, wl->horizon.alpha * 2.0f); mWindlight.set("blue_density", wl->blueDensity.red * 2.0f, wl->blueDensity.green * 2.0f, wl->blueDensity.blue * 2.0f, wl->blueDensity.alpha * 2.0f); - mWindlight.set("haze_horizon", wl->hazeHorizon, wl->hazeHorizon, wl->hazeHorizon, 1.f); - mWindlight.set("haze_density", wl->hazeDensity, wl->hazeDensity, wl->hazeDensity, 1.f); - mWindlight.set("cloud_shadow", wl->cloudCoverage, wl->cloudCoverage, wl->cloudCoverage, wl->cloudCoverage); + mWindlight.set("haze_horizon", wl->hazeHorizon); + mWindlight.set("haze_density", wl->hazeDensity); + mWindlight.set("cloud_shadow", wl->cloudCoverage); mWindlight.set("density_multiplier", wl->densityMultiplier / 1000.0f); - mWindlight.set("distance_multiplier", wl->distanceMultiplier, wl->distanceMultiplier, wl->distanceMultiplier, wl->distanceMultiplier); + mWindlight.set("distance_multiplier", wl->distanceMultiplier); mWindlight.set("max_y",(F32)wl->maxAltitude); mWindlight.set("cloud_color", wl->cloudColor.red, wl->cloudColor.green, wl->cloudColor.blue, wl->cloudColor.alpha); mWindlight.set("cloud_pos_density1", wl->cloudXYDensity.X, wl->cloudXYDensity.Y, wl->cloudXYDensity.Z); mWindlight.set("cloud_pos_density2", wl->cloudDetailXYDensity.X, wl->cloudDetailXYDensity.Y, wl->cloudDetailXYDensity.Z); - mWindlight.set("cloud_scale", wl->cloudScale, 0.f, 0.f, 1.f); - mWindlight.set("gamma", wl->sceneGamma, wl->sceneGamma, wl->sceneGamma, 0.0f); + mWindlight.set("cloud_scale", wl->cloudScale); + mWindlight.set("gamma", wl->sceneGamma); mWindlight.set("glow",(2 - wl->sunGlowSize) * 20 , 0.f, -wl->sunGlowFocus * 5); mWindlight.setCloudScrollX(wl->cloudScrollX + 10.0f); mWindlight.setCloudScrollY(wl->cloudScrollY + 10.0f); diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index 679250abb..afb4666f0 100644 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -157,6 +157,14 @@ const U32 AUX_VB_MASK = LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_TEXCOOR // Max number of occluders to search for. JC const S32 MAX_OCCLUDER_COUNT = 2; +enum { + LIGHT_MODE_NORMAL, + LIGHT_MODE_EDIT, + LIGHT_MODE_BACKLIGHT, + LIGHT_MODE_PREVIEW +}; + + extern S32 gBoxFrame; //extern BOOL gHideSelectedObjects; extern BOOL gDisplaySwapBuffers; @@ -362,6 +370,7 @@ LLPipeline::LLPipeline() : mGroupQ1Locked(false), mGroupQ2Locked(false), mResetVertexBuffers(false), + mInRenderPass(false), mLastRebuildPool(NULL), mAlphaPool(NULL), mSkyPool(NULL), @@ -378,28 +387,14 @@ LLPipeline::LLPipeline() : mMaterialsPool(NULL), mWLSkyPool(NULL), mLightMask(0), - mLightMovingMask(0), - mLightingDetail(0) -{ - mNoiseMap = 0; - mLightFunc = 0; -} + mLightMode(LIGHT_MODE_NORMAL) +{} void LLPipeline::init() { refreshCachedSettings(); - gOctreeMaxCapacity = gSavedSettings.getU32("OctreeMaxNodeCapacity"); - gOctreeReserveCapacity = llmin(gSavedSettings.getU32("OctreeReserveNodeCapacity"),U32(512)); - sDynamicLOD = gSavedSettings.getBOOL("RenderDynamicLOD"); - sRenderBump = gSavedSettings.getBOOL("RenderObjectBump"); - LLVertexBuffer::sUseStreamDraw = gSavedSettings.getBOOL("ShyotlRenderUseStreamVBO"); - LLVertexBuffer::sUseVAO = gSavedSettings.getBOOL("RenderUseVAO") && gSavedSettings.getBOOL("VertexShaderEnable"); //Temporary workaround for vaos being broken when shaders are off - LLVertexBuffer::sPreferStreamDraw = gSavedSettings.getBOOL("RenderPreferStreamDraw"); - sRenderAttachedLights = gSavedSettings.getBOOL("RenderAttachedLights"); - sRenderAttachedParticles = gSavedSettings.getBOOL("RenderAttachedParticles"); - - mInitialized = TRUE; + mInitialized = true; stop_glerror(); @@ -455,19 +450,20 @@ void LLPipeline::init() mBackfaceCull = TRUE; stop_glerror(); - + // Enable features - + LLViewerShaderMgr::instance()->setShaders(); stop_glerror(); + for (U32 i = 0; i < 2; ++i) { mSpotLightFade[i] = 1.f; } - setLightingDetail(-1); + updateLocalLightingEnabled(); gSavedSettings.getControl("RenderAutoMaskAlphaDeferred")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings)); gSavedSettings.getControl("RenderAutoMaskAlphaNonDeferred")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings)); gSavedSettings.getControl("RenderUseFarClip")->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings)); @@ -570,9 +566,8 @@ void LLPipeline::destroyGL() unloadShaders(); mHighlightFaces.clear(); - resetDrawOrders(); - resetVertexBuffers(); + releaseVertexBuffers(); releaseGLBuffers(); @@ -709,7 +704,6 @@ LLPipeline::eFBOStatus LLPipeline::doAllocateScreenBuffer(U32 resX, U32 resY) // - on failure, shrink number of samples and try again // - if not multisampled, shrink resolution and try again (favor X resolution over Y) // Make sure to call "releaseScreenBuffers" after each failure to cleanup the partially loaded state - eFBOStatus ret = FBO_SUCCESS_FULLRES; if (!allocateScreenBuffer(resX, resY, samples)) { @@ -960,6 +954,18 @@ void LLPipeline::refreshCachedSettings() LLPipeline::sUseFarClip = gSavedSettings.getBOOL("RenderUseFarClip"); LLVOAvatar::sMaxVisible = (U32)gSavedSettings.getS32("RenderAvatarMaxVisible"); //LLPipeline::sDelayVBUpdate = gSavedSettings.getBOOL("RenderDelayVBUpdate"); + gOctreeMaxCapacity = gSavedSettings.getU32("OctreeMaxNodeCapacity"); + gOctreeReserveCapacity = llmin(gSavedSettings.getU32("OctreeReserveNodeCapacity"), U32(512)); + LLPipeline::sDynamicLOD = gSavedSettings.getBOOL("RenderDynamicLOD"); + LLPipeline::sRenderBump = gSavedSettings.getBOOL("RenderObjectBump"); + LLVertexBuffer::sUseStreamDraw = gSavedSettings.getBOOL("ShyotlRenderUseStreamVBO"); + LLVertexBuffer::sEnableVBOs = gSavedSettings.getBOOL("RenderVBOEnable"); + LLVertexBuffer::sUseVAO = gSavedSettings.getBOOL("RenderUseVAO") && gSavedSettings.getBOOL("VertexShaderEnable"); //Temporary workaround for vaos being broken when shaders are off + LLVertexBuffer::sDisableVBOMapping = LLVertexBuffer::sEnableVBOs;// && gSavedSettings.getBOOL("RenderVBOMappingDisable") ; //Temporary workaround for vbo mapping being straight up broken + LLVertexBuffer::sPreferStreamDraw = gSavedSettings.getBOOL("RenderPreferStreamDraw"); + LLPipeline::sRenderAttachedLights = gSavedSettings.getBOOL("RenderAttachedLights"); + LLPipeline::sRenderAttachedParticles = gSavedSettings.getBOOL("RenderAttachedParticles"); + LLPipeline::sTextureBindTest = gSavedSettings.getBOOL("RenderDebugTextureBind"); LLPipeline::sUseOcclusion = (!gUseWireframe @@ -969,15 +975,56 @@ void LLPipeline::refreshCachedSettings() && gGLManager.mHasOcclusionQuery) ? 2 : 0; } +void LLPipeline::releaseVertexBuffers() +{ + mCubeVB = NULL; + mAuxScreenRectVB = NULL; + + for (LLWorld::region_list_t::const_iterator iter = LLWorld::getInstance()->getRegionList().begin(); + iter != LLWorld::getInstance()->getRegionList().end(); ++iter) + { + LLViewerRegion* region = *iter; + for (U32 i = 0; i < LLViewerRegion::NUM_PARTITIONS; i++) + { + LLSpatialPartition* part = region->getSpatialPartition(i); + if (part) + { + part->resetVertexBuffers(); + } + } + } + + resetDrawOrders(); + + gSky.resetVertexBuffers(); + + LLVOPartGroup::destroyGL(); + + if (LLPostProcess::instanceExists()) + LLPostProcess::getInstance()->destroyGL(); + + LLVOPartGroup::destroyGL(); + + //delete all name pool caches + LLGLNamePool::cleanupPools(); + + gGL.resetVertexBuffers(); + + LLVertexBuffer::cleanupClass(); + + if (LLVertexBuffer::sGLCount > 0) + { + LL_WARNS() << "VBO wipe failed -- " << LLVertexBuffer::sGLCount << " buffers remaining. " << LLVertexBuffer::sCount << LL_ENDL; + } + + LLVertexBuffer::unbind(); +} + void LLPipeline::releaseGLBuffers() { assertInitialized(); - if (mNoiseMap) - { - LLImageGL::deleteTextures(1, &mNoiseMap); - mNoiseMap = 0; - } + mNoiseMap.reset(); releaseLUTBuffers(); @@ -1000,11 +1047,7 @@ void LLPipeline::releaseGLBuffers() void LLPipeline::releaseLUTBuffers() { - if (mLightFunc) - { - LLImageGL::deleteTextures(1, &mLightFunc); - mLightFunc = 0; - } + mLightFunc.reset(); } void LLPipeline::releaseScreenBuffers() @@ -1100,9 +1143,9 @@ void LLPipeline::createGLBuffers() val.mV[2] = ll_frand()*scaler+1.f-scaler/2.f; } - LLImageGL::generateTextures(1, &mNoiseMap); + mNoiseMap = LLImageGL::createTextureName(); - gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mNoiseMap); + gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mNoiseMap->getTexName()); LLImageGL::setManualImage(LLTexUnit::getInternalType(LLTexUnit::TT_TEXTURE), 0, GL_RGB16F_ARB, NOISE_MAP_RES, NOISE_MAP_RES, GL_RGB, GL_FLOAT, noise, false); gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_POINT); } @@ -1164,8 +1207,8 @@ void LLPipeline::createLUTBuffers() // pix_format = GL_R32F; #endif - LLImageGL::generateTextures(1, &mLightFunc); - gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mLightFunc); + mLightFunc = LLImageGL::createTextureName(); + gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mLightFunc->getTexName()); LLImageGL::setManualImage(LLTexUnit::getInternalType(LLTexUnit::TT_TEXTURE), 0, pix_format, lightResX, lightResY, GL_RED, GL_FLOAT, ls, false); //LLImageGL::setManualImage(LLTexUnit::getInternalType(LLTexUnit::TT_TEXTURE), 0, GL_UNSIGNED_BYTE, lightResX, lightResY, GL_RED, GL_UNSIGNED_BYTE, ls, false); gGL.getTexUnit(0)->setTextureAddressMode(LLTexUnit::TAM_CLAMP); @@ -1199,7 +1242,7 @@ void LLPipeline::restoreGL() } } - resetLocalLights(); //Default all gl light parameters. Fixes light brightness problems on fullscren toggle + updateLocalLightingEnabled(); //Default all gl light parameters. Fixes light brightness problems on fullscren toggle } BOOL LLPipeline::canUseWindLightShaders() const @@ -1236,43 +1279,18 @@ void LLPipeline::enableShadows(const BOOL enable_shadows) //should probably do something here to wrangle shadows.... } -S32 LLPipeline::getMaxLightingDetail() const -{ - /*if (mVertexShaderLevel[SHADER_OBJECT] >= LLDrawPoolSimple::SHADER_LEVEL_LOCAL_LIGHTS) - { - return 3; - } - else*/ - { - return 1; - } -} - -S32 LLPipeline::setLightingDetail(S32 level) +void LLPipeline::updateLocalLightingEnabled() { refreshCachedSettings(); - if (level < 0) - { - if (gSavedSettings.getBOOL("RenderLocalLights")) - { - level = 1; - } - else - { - level = 0; - } - } - level = llclamp(level, 0, getMaxLightingDetail()); + static const LLCachedControl render_local_lights("RenderLocalLights", true); //Bugfix: If setshaders was called with RenderLocalLights off then enabling RenderLocalLights later will not work. Reloading shaders fixes this. - if (level != mLightingDetail) + if (render_local_lights != mLightingEnabled) { - mLightingDetail = level; + mLightingEnabled = render_local_lights; if (LLGLSLShader::sNoFixedFunction) LLViewerShaderMgr::instance()->setShaders(); } - - return mLightingDetail; } class LLOctreeDirtyTexture : public OctreeTraveler @@ -1429,6 +1447,7 @@ LLDrawPool *LLPipeline::getPool(const U32 type, LLViewerTexture *tex0) return poolp; } + LLDrawPool *new_poolp = LLDrawPool::createPool(type, tex0); addPool( new_poolp ); @@ -2254,9 +2273,9 @@ void LLPipeline::updateCull(LLCamera& camera, LLCullResult& result, S32 water_cl gGLLastMatrix = NULL; gGL.loadMatrix(glh_get_last_modelview()); - LLGLDisable blend(GL_BLEND); - LLGLDisable test(GL_ALPHA_TEST); - LLGLDisable stencil(GL_STENCIL_TEST); + LLGLDisable blend; + LLGLDisable test; + LLGLDisable stencil; gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); @@ -2507,12 +2526,12 @@ void LLPipeline::doOcclusion(LLCamera& camera) { gGL.setColorMask(false, false); } - LLGLDisable blend(GL_BLEND); - LLGLDisable test(GL_ALPHA_TEST); + LLGLDisable blend; + LLGLDisable test; gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); LLGLDepthTest depth(GL_TRUE, GL_FALSE); - LLGLDisable cull(GL_CULL_FACE); + LLGLDisable cull; bool bind_shader = LLGLSLShader::sNoFixedFunction && LLGLSLShader::sCurBoundShader == 0; @@ -2724,7 +2743,7 @@ void LLPipeline::rebuildGroups() updateMovedList(mMovedBridge); } -void LLPipeline::updateGeom(F32 max_dtime) +void LLPipeline::updateGeom(F32 max_dtime, LLCamera& camera) { LLTimer update_timer; LLPointer drawablep; @@ -2825,6 +2844,9 @@ void LLPipeline::updateGeom(F32 max_dtime) } updateMovedList(mMovedBridge); + calcNearbyLights(camera); + mLightMode = LIGHT_MODE_NORMAL; + setupHWLights(); } void LLPipeline::markVisible(LLDrawable *drawablep, LLCamera& camera) @@ -2943,6 +2965,7 @@ void LLPipeline::shiftObjects(const LLVector3 &offset) { assertInitialized(); + gGL.syncContextState(); glClear(GL_DEPTH_BUFFER_BIT); gDepthDirty = TRUE; @@ -3823,12 +3846,11 @@ void LLPipeline::postSort(LLCamera& camera) void render_hud_elements() { LL_RECORD_BLOCK_TIME(FTM_RENDER_UI); - gPipeline.disableLights(); - LLGLDisable fog(GL_FOG); + LLGLDisable fog; LLGLSUIDefault gls_ui; - LLGLEnable stencil(GL_STENCIL_TEST); + LLGLEnable stencil; glStencilFunc(GL_ALWAYS, 255, 0xFFFFFFFF); glStencilMask(0xFFFFFFFF); glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); @@ -3844,7 +3866,7 @@ void render_hud_elements() if (!LLPipeline::sReflectionRender && gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_UI)) { static const LLCachedControl RenderFSAASamples("RenderFSAASamples",0); - LLGLEnable multisample(RenderFSAASamples > 0 ? GL_MULTISAMPLE_ARB : 0); + LLGLEnable multisample(RenderFSAASamples > 0); gViewerWindow->renderSelections(FALSE, FALSE, FALSE); // For HUD version in render_ui_3d() // Draw the tracking overlays @@ -3943,8 +3965,9 @@ void LLPipeline::renderHighlights() // Draw 3D UI elements here (before we clear the Z buffer in POOL_HUD) // Render highlighted faces. LLGLSPipelineAlpha gls_pipeline_alpha; - LLGLEnable color_mat(GL_COLOR_MATERIAL); - disableLights(); + LLGLEnable color_mat; + LLGLState light_state; + gPipeline.disableLights(light_state); // Singu Note: Logic here changed, and behavior changed as well. Always draw overlays of some nature over all selected faces. // Faces that wont undergo any change if the current active channel is edited should have a 'faded' overlay @@ -4002,9 +4025,9 @@ void LLPipeline::renderGeom(LLCamera& camera, BOOL forceVBOUpdate) LLVertexBuffer::unbind(); // Do verification of GL state - LLGLState::checkStates(); - LLGLState::checkTextureChannels(); - LLGLState::checkClientArrays(); + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkTextureChannels(); + LLGLStateValidator::checkClientArrays(); if (mRenderDebugMask & RENDER_DEBUG_VERIFY) { if (!verify()) @@ -4025,21 +4048,17 @@ void LLPipeline::renderGeom(LLCamera& camera, BOOL forceVBOUpdate) LLGLSPipeline gls_pipeline; static const LLCachedControl RenderFSAASamples("RenderFSAASamples",0); - LLGLEnable multisample(RenderFSAASamples > 0 ? GL_MULTISAMPLE_ARB : 0); + LLGLEnable multisample(RenderFSAASamples > 0); - LLGLState gls_color_material(GL_COLOR_MATERIAL, mLightingDetail < 2); + LLGLEnable gls_color_material; // Toggle backface culling for debugging - LLGLEnable cull_face(mBackfaceCull ? GL_CULL_FACE : 0); - // Set fog + LLGLEnable cull_face(mBackfaceCull); + + // Set fog only if not using shaders and is underwater render. BOOL use_fog = hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_FOG); - LLGLEnable fog_enable(use_fog && - !gPipeline.canUseWindLightShadersOnObjects() ? GL_FOG : 0); + LLGLEnable fog_enable(use_fog && sUnderWaterRender && !LLGLSLShader::sNoFixedFunction); gSky.updateFog(camera.getFar()); - if (!use_fog) - { - sUnderWaterRender = FALSE; - } gGL.getTexUnit(0)->bind(LLViewerFetchedTexture::sDefaultImagep); LLViewerFetchedTexture::sDefaultImagep->setAddressMode(LLTexUnit::TAM_WRAP); @@ -4070,10 +4089,11 @@ void LLPipeline::renderGeom(LLCamera& camera, BOOL forceVBOUpdate) // HUD elements being rendered AND the user is in flycam mode -nyx if (!gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_HUD)) { - calcNearbyLights(camera); - setupHWLights(NULL); + updateHWLightMode(LIGHT_MODE_NORMAL); } + llassert_always(LLGLState::checkEnabled()); + BOOL occlude = sUseOcclusion > 1; U32 cur_type = 0; @@ -4108,6 +4128,7 @@ void LLPipeline::renderGeom(LLCamera& camera, BOOL forceVBOUpdate) { LLVertexBuffer::unbind(); if(gDebugGL)check_blend_funcs(); + mInRenderPass = true; poolp->beginRenderPass(i); for (iter2 = iter1; iter2 != mPools.end(); iter2++) { @@ -4119,14 +4140,15 @@ void LLPipeline::renderGeom(LLCamera& camera, BOOL forceVBOUpdate) p->render(i); } poolp->endRenderPass(i); + clearRenderPassStates(); if(gDebugGL)check_blend_funcs(); LLVertexBuffer::unbind(); if (gDebugGL) { std::string msg = llformat("%s pass %d", gPoolNames[cur_type].c_str(), i); - LLGLState::checkStates(msg); - //LLGLState::checkTextureChannels(msg); - //LLGLState::checkClientArrays(msg); + LLGLStateValidator::checkStates(msg); + //LLGLStateValidator::checkTextureChannels(msg); + //LLGLStateValidator::checkClientArrays(msg); } } } @@ -4164,17 +4186,17 @@ void LLPipeline::renderGeom(LLCamera& camera, BOOL forceVBOUpdate) } LLVertexBuffer::unbind(); - LLGLState::checkStates(); - //LLGLState::checkTextureChannels(); - //LLGLState::checkClientArrays(); + LLGLStateValidator::checkStates(); + //LLGLStateValidator::checkTextureChannels(); + //LLGLStateValidator::checkClientArrays(); //stop_glerror(); - //LLGLState::checkStates(); - //LLGLState::checkTextureChannels(); - //LLGLState::checkClientArrays(); + //LLGLStateValidator::checkStates(); + //LLGLStateValidator::checkTextureChannels(); + //LLGLStateValidator::checkClientArrays(); if (!LLPipeline::sImpostorRender) { @@ -4227,9 +4249,9 @@ void LLPipeline::renderGeom(LLCamera& camera, BOOL forceVBOUpdate) LLVertexBuffer::unbind(); - LLGLState::checkStates(); - //LLGLState::checkTextureChannels(); - //LLGLState::checkClientArrays(); + LLGLStateValidator::checkStates(); + //LLGLStateValidator::checkTextureChannels(); + //LLGLStateValidator::checkClientArrays(); } void LLPipeline::renderGeomDeferred(LLCamera& camera) @@ -4239,9 +4261,9 @@ void LLPipeline::renderGeomDeferred(LLCamera& camera) LL_RECORD_BLOCK_TIME(FTM_DEFERRED_POOLS); - LLGLEnable cull(GL_CULL_FACE); + LLGLEnable cull; - LLGLEnable stencil(GL_STENCIL_TEST); + LLGLEnable stencil; glStencilFunc(GL_ALWAYS, 1, 0xFFFFFFFF); stop_glerror(); glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); @@ -4256,14 +4278,14 @@ void LLPipeline::renderGeomDeferred(LLCamera& camera) } } - static const LLCachedControl fsaa_samples("RenderFSAASamples",0); - LLGLEnable multisample(fsaa_samples > 0 ? GL_MULTISAMPLE_ARB : 0); + static const LLCachedControl RenderFSAASamples("RenderFSAASamples",0); + LLGLEnable multisample(RenderFSAASamples > 0); LLVertexBuffer::unbind(); - LLGLState::checkStates(); - LLGLState::checkTextureChannels(); - LLGLState::checkClientArrays(); + //LLGLStateValidator::checkStates(); + //LLGLStateValidator::checkTextureChannels(); + //LLGLStateValidator::checkClientArrays(); U32 cur_type = 0; @@ -4288,6 +4310,7 @@ void LLPipeline::renderGeomDeferred(LLCamera& camera) for( S32 i = 0; i < poolp->getNumDeferredPasses(); i++ ) { LLVertexBuffer::unbind(); + mInRenderPass = true; poolp->beginDeferredPass(i); for (iter2 = iter1; iter2 != mPools.end(); iter2++) { @@ -4300,13 +4323,14 @@ void LLPipeline::renderGeomDeferred(LLCamera& camera) p->renderDeferred(i); } poolp->endDeferredPass(i); + clearRenderPassStates(); LLVertexBuffer::unbind(); if (gDebugGL || gDebugPipeline) { - LLGLState::checkStates(); - //LLGLState::checkTextureChannels(); - //LLGLState::checkClientArrays(); + LLGLStateValidator::checkStates(); + //LLGLStateValidator::checkTextureChannels(); + //LLGLStateValidator::checkClientArrays(); } } } @@ -4337,13 +4361,14 @@ void LLPipeline::renderGeomPostDeferred(LLCamera& camera, bool do_occlusion) LL_RECORD_BLOCK_TIME(FTM_POST_DEFERRED_POOLS); U32 cur_type = 0; - LLGLEnable cull(GL_CULL_FACE); + LLGLEnable cull; static const LLCachedControl RenderFSAASamples("RenderFSAASamples",0); - LLGLEnable multisample(RenderFSAASamples > 0 ? GL_MULTISAMPLE_ARB : 0); + LLGLEnable multisample(RenderFSAASamples > 0); - calcNearbyLights(camera); - setupHWLights(NULL); + updateHWLightMode(LIGHT_MODE_NORMAL); + + llassert_always(LLGLState::checkEnabled()); gGL.setColorMask(true, false); @@ -4377,6 +4402,7 @@ void LLPipeline::renderGeomPostDeferred(LLCamera& camera, bool do_occlusion) for( S32 i = 0; i < poolp->getNumPostDeferredPasses(); i++ ) { LLVertexBuffer::unbind(); + mInRenderPass = true; poolp->beginPostDeferredPass(i); for (iter2 = iter1; iter2 != mPools.end(); iter2++) { @@ -4389,11 +4415,12 @@ void LLPipeline::renderGeomPostDeferred(LLCamera& camera, bool do_occlusion) p->renderPostDeferred(i); } poolp->endPostDeferredPass(i); + clearRenderPassStates(); LLVertexBuffer::unbind(); if (gDebugGL || gDebugPipeline) { - LLGLState::checkStates(); + LLGLStateValidator::checkStates(); } } } @@ -4432,7 +4459,7 @@ void LLPipeline::renderGeomShadow(LLCamera& camera) { U32 cur_type = 0; - LLGLEnable cull(GL_CULL_FACE); + LLGLEnable cull; LLVertexBuffer::unbind(); @@ -4455,6 +4482,7 @@ void LLPipeline::renderGeomShadow(LLCamera& camera) for( S32 i = 0; i < poolp->getNumShadowPasses(); i++ ) { LLVertexBuffer::unbind(); + mInRenderPass = true; poolp->beginShadowPass(i); for (iter2 = iter1; iter2 != mPools.end(); iter2++) { @@ -4467,9 +4495,10 @@ void LLPipeline::renderGeomShadow(LLCamera& camera) p->renderShadow(i); } poolp->endShadowPass(i); + clearRenderPassStates(); LLVertexBuffer::unbind(); - LLGLState::checkStates(); + LLGLStateValidator::checkStates(); } } else @@ -4590,7 +4619,7 @@ void LLPipeline::renderDebug() gGL.getTexUnit(0)->bind(LLViewerFetchedTexture::sWhiteImagep, true); - glPointSize(8.f); + gGL.setPointSize(8.f); LLGLDepthTest depth(GL_TRUE, GL_TRUE, GL_ALWAYS); gGL.begin(LLRender::POINTS); @@ -4614,8 +4643,7 @@ void LLPipeline::renderDebug() gGL.vertex3fv(blip.mPosition.mV); } gGL.end(); - gGL.flush(); - glPointSize(1.f); + gGL.setPointSize(1.f); if (LLGLSLShader::sNoFixedFunction) { @@ -4669,9 +4697,9 @@ void LLPipeline::renderDebug() { LLVertexBuffer::unbind(); - LLGLEnable blend(GL_BLEND); + LLGLEnable blend; LLGLDepthTest depth(TRUE, FALSE); - LLGLDisable cull(GL_CULL_FACE); + LLGLDisable cull; gGL.color4f(1,1,1,1); gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); @@ -4735,8 +4763,7 @@ void LLPipeline::renderDebug() //if (i == 0 || !mShadowFrustPoints[i].empty()) { //render visible point cloud - gGL.flush(); - glPointSize(8.f); + gGL.setPointSize(8.f); gGL.begin(LLRender::POINTS); F32* c = col+i*4; @@ -4749,8 +4776,7 @@ void LLPipeline::renderDebug() } gGL.end(); - gGL.flush(); - glPointSize(1.f); + gGL.setPointSize(1.f); LLVector3* ext = mShadowExtents[i]; LLVector3 pos = (ext[0]+ext[1])*0.5f; @@ -4843,7 +4869,7 @@ void LLPipeline::renderDebug() LLColor4 col; LLVertexBuffer::unbind(); - LLGLEnable blend(GL_BLEND); + LLGLEnable blend; gGL.setSceneBlendType(LLRender::BT_ALPHA); LLGLDepthTest depth(GL_TRUE, GL_FALSE); gGL.getTexUnit(0)->bind(LLViewerFetchedTexture::sWhiteImagep); @@ -5242,11 +5268,11 @@ void LLPipeline::resetDrawOrders() // Once-per-frame setup of hardware lights, // including sun/moon, avatar backlight, and up to 6 local lights -void LLPipeline::setupAvatarLights(BOOL for_edit) +U8 LLPipeline::setupFeatureLights(U8 cur_count) { - assertInitialized(); + //assertInitialized(); - if (for_edit) + if (mLightMode == LIGHT_MODE_EDIT) { LLColor4 diffuse(1.f, 1.f, 1.f, 0.f); LLVector4a light_pos_cam(-8.f, 0.25f, 10.f, 0.f); // w==0 => directional light @@ -5259,12 +5285,9 @@ void LLPipeline::setupAvatarLights(BOOL for_edit) light_pos.normalize3fast(); - LLLightState* light = gGL.getLight(1); - - mHWLightColors[1] = diffuse; + LLLightState* light = gGL.getLight(cur_count++); light->setDiffuse(diffuse); - light->setAmbient(LLColor4::black); light->setSpecular(LLColor4::black); light->setPosition(LLVector4(light_pos.getF32ptr())); light->setConstantAttenuation(1.f); @@ -5273,7 +5296,7 @@ void LLPipeline::setupAvatarLights(BOOL for_edit) light->setSpotExponent(0.f); light->setSpotCutoff(180.f); } - else if (gAvatarBacklight) // Always true (unless overridden in a devs .ini) + else if (mLightMode == LIGHT_MODE_BACKLIGHT) // Always true (unless overridden in a devs .ini) { LLVector3 opposite_pos = -1.f * mSunDir; LLVector3 orthog_light_pos = mSunDir % LLVector3::z_axis; @@ -5301,13 +5324,10 @@ void LLPipeline::setupAvatarLights(BOOL for_edit) } backlight_diffuse *= backlight_mag / max_component; - mHWLightColors[1] = backlight_diffuse; - - LLLightState* light = gGL.getLight(1); + LLLightState* light = gGL.getLight(cur_count++); light->setPosition(backlight_pos); light->setDiffuse(backlight_diffuse); - light->setAmbient(LLColor4::black); light->setSpecular(LLColor4::black); light->setConstantAttenuation(1.f); light->setLinearAttenuation(0.f); @@ -5315,16 +5335,69 @@ void LLPipeline::setupAvatarLights(BOOL for_edit) light->setSpotExponent(0.f); light->setSpotCutoff(180.f); } - else + else if (mLightMode == LIGHT_MODE_PREVIEW) { - LLLightState* light = gGL.getLight(1); + static LLCachedControl PreviewAmbientColor("PreviewAmbientColor"); - mHWLightColors[1] = LLColor4::black; + LLColor4 ambient = PreviewAmbientColor; + gGL.setAmbientLightColor(ambient); - light->setDiffuse(LLColor4::black); - light->setAmbient(LLColor4::black); - light->setSpecular(LLColor4::black); + static LLCachedControl PreviewDiffuse0("PreviewDiffuse0"); + static LLCachedControl PreviewSpecular0("PreviewSpecular0"); + static LLCachedControl PreviewDiffuse1("PreviewDiffuse1"); + static LLCachedControl PreviewSpecular1("PreviewSpecular1"); + static LLCachedControl PreviewDiffuse2("PreviewDiffuse2"); + static LLCachedControl PreviewSpecular2("PreviewSpecular2"); + static LLCachedControl PreviewDirection0("PreviewDirection0"); + static LLCachedControl PreviewDirection1("PreviewDirection1"); + static LLCachedControl PreviewDirection2("PreviewDirection2"); + + LLColor4 diffuse0 = PreviewDiffuse0; + LLColor4 specular0 = PreviewSpecular0; + LLColor4 diffuse1 = PreviewDiffuse1; + LLColor4 specular1 = PreviewSpecular1; + LLColor4 diffuse2 = PreviewDiffuse2; + LLColor4 specular2 = PreviewSpecular2; + + LLVector3 dir0 = PreviewDirection0; + LLVector3 dir1 = PreviewDirection1; + LLVector3 dir2 = PreviewDirection2; + + dir0.normVec(); + dir1.normVec(); + dir2.normVec(); + + LLVector4 light_pos(dir0, 0.0f); + + LLLightState* light = gGL.getLight(cur_count++); + + light->enable(); + light->setPosition(light_pos); + light->setDiffuse(diffuse0); + light->setSpecular(specular0); + light->setSpotExponent(0.f); + light->setSpotCutoff(180.f); + + light_pos = LLVector4(dir1, 0.f); + + light = gGL.getLight(cur_count++); + light->enable(); + light->setPosition(light_pos); + light->setDiffuse(diffuse1); + light->setSpecular(specular1); + light->setSpotExponent(0.f); + light->setSpotCutoff(180.f); + + light_pos = LLVector4(dir2, 0.f); + light = gGL.getLight(cur_count++); + light->enable(); + light->setPosition(light_pos); + light->setDiffuse(diffuse2); + light->setSpecular(specular2); + light->setSpotExponent(0.f); + light->setSpotCutoff(180.f); } + return cur_count; } static F32 calc_light_dist(LLVOVolume* light, const LLVector3& cam_pos, F32 max_dist) @@ -5360,13 +5433,11 @@ static F32 calc_light_dist(LLVOVolume* light, const LLVector3& cam_pos, F32 max_ //Default all gl light parameters. Used upon restoreGL. Fixes brightness problems on fullscren toggle void LLPipeline::resetLocalLights() { - if (!LLGLSLShader::sNoFixedFunction) - glEnable(GL_LIGHTING); - for (S32 i = 0; i < 8; ++i) + LLGLEnable enable; + for (S32 i = 0; i < LLRender::NUM_LIGHTS; ++i) { LLLightState *pLight = gGL.getLight(i); pLight->enable(); - pLight->setAmbient(LLColor4::black); pLight->setConstantAttenuation(0.f); pLight->setDiffuse(LLColor4::black); pLight->setLinearAttenuation(0.f); @@ -5378,8 +5449,6 @@ void LLPipeline::resetLocalLights() pLight->setSpotExponent(0.f); pLight->disable(); } - if (!LLGLSLShader::sNoFixedFunction) - glDisable(GL_LIGHTING); } void LLPipeline::calcNearbyLights(LLCamera& camera) @@ -5391,11 +5460,11 @@ void LLPipeline::calcNearbyLights(LLCamera& camera) return; } - if (mLightingDetail >= 1) + if (isLocalLightingEnabled()) { // mNearbyLight (and all light_set_t's) are sorted such that // begin() == the closest light and rbegin() == the farthest light - const S32 MAX_LOCAL_LIGHTS = 6; + const S32 MAX_LOCAL_LIGHTS = 7; // LLVector3 cam_pos = gAgentCamera.getCameraPositionAgent(); LLVector3 cam_pos = LLViewerJoystick::getInstance()->getOverrideCamera() ? camera.getOrigin() : @@ -5494,68 +5563,15 @@ void LLPipeline::calcNearbyLights(LLCamera& camera) } } } - } + gatherLocalLights(); } -void LLPipeline::setupHWLights(LLDrawPool* pool) + +void LLPipeline::gatherLocalLights() { - assertInitialized(); - - // Ambient - if (!LLGLSLShader::sNoFixedFunction) - { - gGL.syncMatrices(); - LLColor4 ambient = gSky.getTotalAmbientColor(); - gGL.setAmbientLightColor(ambient); - } - - // Light 0 = Sun or Moon (All objects) - { - if (gSky.getSunDirection().mV[2] >= LLSky::NIGHTTIME_ELEVATION_COS) - { - mSunDir.setVec(gSky.getSunDirection()); - mSunDiffuse.setVec(gSky.getSunDiffuseColor()); - } - else - { - mSunDir.setVec(gSky.getMoonDirection()); - mSunDiffuse.setVec(gSky.getMoonDiffuseColor()); - } - - F32 max_color = llmax(mSunDiffuse.mV[0], mSunDiffuse.mV[1], mSunDiffuse.mV[2]); - if (max_color > 1.f) - { - mSunDiffuse *= 1.f/max_color; - } - mSunDiffuse.clamp(); - - LLVector4 light_pos(mSunDir, 0.0f); - LLColor4 light_diffuse = mSunDiffuse; - mHWLightColors[0] = light_diffuse; - - LLLightState* light = gGL.getLight(0); - light->setPosition(light_pos); - light->setDiffuse(light_diffuse); - light->setAmbient(LLColor4::black); - light->setSpecular(LLColor4::black); - light->setConstantAttenuation(1.f); - light->setLinearAttenuation(0.f); - light->setQuadraticAttenuation(0.f); - light->setSpotExponent(0.f); - light->setSpotCutoff(180.f); - } - - // Light 1 = Backlight (for avatars) - // (set by enableLightsAvatar) - - S32 cur_light = 2; - - // Nearby lights = LIGHT 2-7 - - mLightMovingMask = 0; - - if (mLightingDetail >= 1) + mLocalLights.clear(); + if (isLocalLightingEnabled()) { for (light_set_t::iterator iter = mNearbyLights.begin(); iter != mNearbyLights.end(); ++iter) @@ -5566,11 +5582,7 @@ void LLPipeline::setupHWLights(LLDrawPool* pool) { continue; } - if (drawable->isState(LLDrawable::ACTIVE)) - { - mLightMovingMask |= (1<getLightColor(); light_color.mV[3] = 0.0f; @@ -5600,23 +5612,19 @@ void LLPipeline::setupHWLights(LLDrawPool* pool) F32 x = (3.f * (1.f + light->getLightFalloff())); // why this magic? probably trying to match a historic behavior. float linatten = x / (light_radius); // % of brightness at radius - mHWLightColors[cur_light] = light_color; - LLLightState* light_state = gGL.getLight(cur_light); - - light_state->setPosition(light_pos_gl); - light_state->setDiffuse(light_color); - light_state->setAmbient(LLColor4::black); - light_state->setConstantAttenuation(0.f); + LLLightStateData& light_state = LLLightStateData(); + light_state.mPosition = light_pos_gl; + light_state.mDiffuse = light_color; + light_state.mConstantAtten = 0.f; + if (sRenderDeferred) { - F32 size = light_radius*1.5f; - light_state->setLinearAttenuation(size); - light_state->setQuadraticAttenuation(light->getLightFalloff()*0.5f+1.f); + light_state.mLinearAtten = light_radius * 1.5f; + light_state.mQuadraticAtten = light->getLightFalloff()*0.5f + 1.f; } else { - light_state->setLinearAttenuation(linatten); - light_state->setQuadraticAttenuation(0.f); + light_state.mLinearAtten = linatten; } static const LLCachedControl RenderSpotLightsInNondeferred("RenderSpotLightsInNondeferred",false); @@ -5627,266 +5635,214 @@ void LLPipeline::setupHWLights(LLDrawPool* pool) LLVector3 at_axis(0,0,-1); // this matches deferred rendering's object light direction at_axis *= quat; - light_state->setSpotDirection(at_axis); - light_state->setSpotCutoff(90.f); - light_state->setSpotExponent(2.f); - - const LLColor4 specular(0.f, 0.f, 0.f, 0.f); - light_state->setSpecular(specular); + light_state.mSpotDirection = at_axis; + light_state.mSpotCutoff = 90.f; + light_state.mSpotExponent = 2.f; + light_state.mSpecular = LLColor4::transparent; } else // omnidirectional (point) light { - light_state->setSpotExponent(0.f); - light_state->setSpotCutoff(180.f); - // we use specular.w = 1.0 as a cheap hack for the shaders to know that this is omnidirectional rather than a spotlight - const LLColor4 specular(0.f, 0.f, 0.f, 1.f); - light_state->setSpecular(specular); - } - cur_light++; - if (cur_light >= 8) - { - break; // safety + light_state.mSpecular = LLColor4::black; } + mLocalLights.push_back(light_state); } } - for ( ; cur_light < 8 ; cur_light++) - { - mHWLightColors[cur_light] = LLColor4::black; - LLLightState* light = gGL.getLight(cur_light); +} - light->setDiffuse(LLColor4::black); - light->setAmbient(LLColor4::black); - light->setSpecular(LLColor4::black); +LLVector3 getSunDir() +{ + if (gSky.getSunDirection().mV[2] >= LLSky::NIGHTTIME_ELEVATION_COS) + { + return gSky.getSunDirection(); } - if (gAgentAvatarp && - gAgentAvatarp->mSpecialRenderMode == 3) + else { - LLColor4 light_color = LLColor4::white; - light_color.mV[3] = 0.0f; + return gSky.getMoonDirection(); + } +} - LLVector3 light_pos(LLViewerCamera::getInstance()->getOrigin()); - LLVector4 light_pos_gl(light_pos, 1.0f); - F32 light_radius = 16.f; +extern U32 sLightMask; +void LLPipeline::setupHWLights() +{ + static LLCachedControl LightMask("LightMask", 0xFFFFFFFF); + sLightMask = LightMask; - F32 x = 3.f; - float linatten = x / (light_radius); // % of brightness at radius + // Ambient + if (mLightMode == LIGHT_MODE_PREVIEW) + { + static LLCachedControl PreviewAmbientColor("PreviewAmbientColor"); + LLColor4 ambient = PreviewAmbientColor; + gGL.setAmbientLightColor(ambient); + } + else if (!LLGLSLShader::sNoFixedFunction) + { + LLColor4 ambient = gSky.getTotalAmbientColor(); + gGL.setAmbientLightColor(ambient); + } - mHWLightColors[2] = light_color; - LLLightState* light = gGL.getLight(2); + U8 cur_light = 0; + // Light 0 = Sun or Moon (All objects) + { + if (gSky.getSunDirection().mV[2] >= LLSky::NIGHTTIME_ELEVATION_COS) + { + mSunDir.setVec(gSky.getSunDirection()); + mSunDiffuse.setVec(gSky.getSunDiffuseColor()); + } + else + { + mSunDir.setVec(gSky.getMoonDirection()); + mSunDiffuse.setVec(gSky.getMoonDiffuseColor()); + } - light->setPosition(light_pos_gl); - light->setDiffuse(light_color); - light->setAmbient(LLColor4::black); + F32 max_color = llmax(mSunDiffuse.mV[0], mSunDiffuse.mV[1], mSunDiffuse.mV[2]); + if (max_color > 1.f) + { + mSunDiffuse *= 1.f/max_color; + } + mSunDiffuse.clamp(); + + LLVector4 light_pos(mSunDir, 0.0f); + LLColor4 light_diffuse = mSunDiffuse; + + LLLightState* light = gGL.getLight(cur_light++); + light->setPosition(light_pos); + light->setDiffuse(light_diffuse); light->setSpecular(LLColor4::black); + light->setConstantAttenuation(1.f); + light->setLinearAttenuation(0.f); light->setQuadraticAttenuation(0.f); - light->setConstantAttenuation(0.f); - light->setLinearAttenuation(linatten); light->setSpotExponent(0.f); light->setSpotCutoff(180.f); } - - // Init GL state - if (!LLGLSLShader::sNoFixedFunction) + + // Edit mode lights + cur_light = setupFeatureLights(cur_light); + + // Nearby lights + if (isLocalLightingEnabled()) { - glDisable(GL_LIGHTING); + for (auto& local_light : mLocalLights) + { + gGL.getLight(cur_light++)->setState(local_light); + if (cur_light >= LLRender::NUM_LIGHTS) + break; + } } - - for (S32 i = 0; i < 8; ++i) + for (S32 i = cur_light; i < LLRender::NUM_LIGHTS; ++i) + { + //gGL.getLight(cur_light++)->setState(LLLightStateData()); + gGL.getLight(i)->disable(); + } + /*for (S32 i = 0; i < LLRender::NUM_LIGHTS; ++i) { gGL.getLight(i)->disable(); } - mLightMask = 0; + mLightMask = 0;*/ + mHWLightCount = cur_light; } -void LLPipeline::enableLights(U32 mask) -{ - assertInitialized(); - if (mLightingDetail == 0) +void LLPipeline::updateHWLightMode(U8 mode) +{ + if (mLightMode != mode) { - mask &= 0xf003; // sun and backlight only (and fullbright bit) + mLightMode = mode; + setupHWLights(); } +} + +void LLPipeline::enableLights(U32 mask, LLGLState& light_state, const LLColor4* color) +{ if (mLightMask != mask) { stop_glerror(); if (!mLightMask) { - if (!LLGLSLShader::sNoFixedFunction) - { - glEnable(GL_LIGHTING); - } + light_state.enable(); } if (mask) { stop_glerror(); - for (S32 i=0; i<8; i++) + for (S32 i=0; i < LLRender::NUM_LIGHTS; i++) { LLLightState* light = gGL.getLight(i); - if (mask & (1<enable(); - light->setDiffuse(mHWLightColors[i]); } else { light->disable(); - light->setDiffuse(LLColor4::black); } } stop_glerror(); } else { - if (!LLGLSLShader::sNoFixedFunction) - { - glDisable(GL_LIGHTING); - } + light_state.disable(); } mLightMask = mask; stop_glerror(); - - LLColor4 ambient = gSky.getTotalAmbientColor(); - gGL.setAmbientLightColor(ambient); } + LLColor4 ambient = color ? *color : gSky.getTotalAmbientColor(); + gGL.setAmbientLightColor(ambient); } -void LLPipeline::enableLightsStatic() +void LLPipeline::enableLightsStatic(LLGLState& light_state) { - assertInitialized(); - U32 mask = 0x01; // Sun - if (mLightingDetail >= 2) - { - mask |= mLightMovingMask; // Hardware moving lights - } - else - { - mask |= 0xff & (~2); // Hardware local lights - } - enableLights(mask); + updateHWLightMode(LIGHT_MODE_NORMAL); + enableLights(0xFFFFFFFF, light_state); } -void LLPipeline::enableLightsDynamic() +void LLPipeline::enableLightsDynamic(LLGLState& light_state) { assertInitialized(); - U32 mask = 0xff & (~2); // Local lights - enableLights(mask); - if (isAgentAvatarValid() && getLightingDetail() <= 0) + if (isAgentAvatarValid() && !isLocalLightingEnabled()) { if (gAgentAvatarp->mSpecialRenderMode == 0) // normal { - gPipeline.enableLightsAvatar(); + gPipeline.enableLightsAvatar(light_state); + return; } else if (gAgentAvatarp->mSpecialRenderMode >= 1) // anim preview { - gPipeline.enableLightsAvatarEdit(LLColor4(0.7f, 0.6f, 0.3f, 1.f)); + gPipeline.enableLightsAvatarEdit(light_state, LLColor4(0.7f, 0.6f, 0.3f, 1.f)); + return; } } + + updateHWLightMode(LIGHT_MODE_NORMAL); + enableLights(0xFFFFFFFF, light_state); } -void LLPipeline::enableLightsAvatar() +void LLPipeline::enableLightsAvatar(LLGLState& light_state) { - U32 mask = 0xff; // All lights - setupAvatarLights(FALSE); - enableLights(mask); + updateHWLightMode(gAvatarBacklight ? LIGHT_MODE_BACKLIGHT : LIGHT_MODE_NORMAL); // Avatar backlight only, set ambient + enableLights(0xFFFFFFFF, light_state); } -void LLPipeline::enableLightsPreview() +void LLPipeline::enableLightsPreview(LLGLState& light_state) { - disableLights(); - - if (!LLGLSLShader::sNoFixedFunction) - { - glEnable(GL_LIGHTING); - } - - static LLCachedControl PreviewAmbientColor("PreviewAmbientColor"); - - LLColor4 ambient = PreviewAmbientColor; - gGL.setAmbientLightColor(ambient); - - static LLCachedControl PreviewDiffuse0("PreviewDiffuse0"); - static LLCachedControl PreviewSpecular0("PreviewSpecular0"); - static LLCachedControl PreviewDiffuse1("PreviewDiffuse1"); - static LLCachedControl PreviewSpecular1("PreviewSpecular1"); - static LLCachedControl PreviewDiffuse2("PreviewDiffuse2"); - static LLCachedControl PreviewSpecular2("PreviewSpecular2"); - static LLCachedControl PreviewDirection0("PreviewDirection0"); - static LLCachedControl PreviewDirection1("PreviewDirection1"); - static LLCachedControl PreviewDirection2("PreviewDirection2"); - - LLColor4 diffuse0 = PreviewDiffuse0; - LLColor4 specular0 = PreviewSpecular0; - LLColor4 diffuse1 = PreviewDiffuse1; - LLColor4 specular1 = PreviewSpecular1; - LLColor4 diffuse2 = PreviewDiffuse2; - LLColor4 specular2 = PreviewSpecular2; - - LLVector3 dir0 = PreviewDirection0; - LLVector3 dir1 = PreviewDirection1; - LLVector3 dir2 = PreviewDirection2; - - dir0.normVec(); - dir1.normVec(); - dir2.normVec(); - - LLVector4 light_pos(dir0, 0.0f); - - LLLightState* light = gGL.getLight(1); - - light->enable(); - light->setPosition(light_pos); - light->setDiffuse(diffuse0); - light->setAmbient(LLColor4::black); - light->setSpecular(specular0); - light->setSpotExponent(0.f); - light->setSpotCutoff(180.f); - - light_pos = LLVector4(dir1, 0.f); - - light = gGL.getLight(2); - light->enable(); - light->setPosition(light_pos); - light->setDiffuse(diffuse1); - light->setAmbient(LLColor4::black); - light->setSpecular(specular1); - light->setSpotExponent(0.f); - light->setSpotCutoff(180.f); - - light_pos = LLVector4(dir2, 0.f); - light = gGL.getLight(3); - light->enable(); - light->setPosition(light_pos); - light->setDiffuse(diffuse2); - light->setAmbient(LLColor4::black); - light->setSpecular(specular2); - light->setSpotExponent(0.f); - light->setSpotCutoff(180.f); + updateHWLightMode(LIGHT_MODE_PREVIEW); + enableLights(0xFFFFFFFF, light_state); } -void LLPipeline::enableLightsAvatarEdit(const LLColor4& color) +void LLPipeline::enableLightsAvatarEdit(LLGLState& light_state, const LLColor4& color) { - U32 mask = 0x2002; // Avatar backlight only, set ambient - setupAvatarLights(TRUE); - enableLights(mask); - - gGL.setAmbientLightColor(color); + updateHWLightMode(LIGHT_MODE_EDIT); + enableLights(0xFFFFFFFF, light_state, &color); } -void LLPipeline::enableLightsFullbright(const LLColor4& color) +void LLPipeline::enableLightsFullbright(LLGLState& light_state) { - assertInitialized(); - U32 mask = 0x1000; // Non-0 mask, set ambient - enableLights(mask); - - gGL.setAmbientLightColor(color); + enableLights(0, light_state); } -void LLPipeline::disableLights() +void LLPipeline::disableLights(LLGLState& light_state) { - enableLights(0); // no lighting (full bright) -// gGL.diffuseColor4f(1.f, 1.f, 1.f, 1.f); + enableLights(0, light_state); // no lighting (full bright) } //============================================================================ @@ -6628,6 +6584,8 @@ void LLPipeline::resetVertexBuffers(LLDrawable* drawable) void LLPipeline::resetVertexBuffers() { + // Only set to true if pipeline has been initialized (No vbo's to reset, otherwise) + //if (mInitialized) mResetVertexBuffers = true; } @@ -6635,64 +6593,16 @@ static LLTrace::BlockTimerStatHandle FTM_RESET_VB("Reset VB"); void LLPipeline::doResetVertexBuffers() { - if (!mResetVertexBuffers) + if ( !mResetVertexBuffers) { return; } - - LL_RECORD_BLOCK_TIME(FTM_RESET_VB); mResetVertexBuffers = false; - mCubeVB = NULL; - mAuxScreenRectVB = NULL; + LL_RECORD_BLOCK_TIME(FTM_RESET_VB); + releaseVertexBuffers(); - for (LLWorld::region_list_t::const_iterator iter = LLWorld::getInstance()->getRegionList().begin(); - iter != LLWorld::getInstance()->getRegionList().end(); ++iter) - { - LLViewerRegion* region = *iter; - for (U32 i = 0; i < LLViewerRegion::NUM_PARTITIONS; i++) - { - LLSpatialPartition* part = region->getSpatialPartition(i); - if (part) - { - part->resetVertexBuffers(); - } - } - } - - resetDrawOrders(); - - gSky.resetVertexBuffers(); - - LLVOPartGroup::destroyGL(); - - if(LLPostProcess::instanceExists()) - LLPostProcess::getInstance()->destroyGL(); - - LLVOPartGroup::destroyGL(); - - LLVertexBuffer::cleanupClass(); - - //delete all name pool caches - LLGLNamePool::cleanupPools(); - - gGL.resetVertexBuffers(); - - if (LLVertexBuffer::sGLCount > 0) - { - LL_WARNS() << "VBO wipe failed -- " << LLVertexBuffer::sGLCount << " buffers remaining. " << LLVertexBuffer::sCount << LL_ENDL; - } - - LLVertexBuffer::unbind(); - - sRenderBump = gSavedSettings.getBOOL("RenderObjectBump"); - LLVertexBuffer::sUseStreamDraw = gSavedSettings.getBOOL("ShyotlRenderUseStreamVBO"); - LLVertexBuffer::sUseVAO = gSavedSettings.getBOOL("RenderUseVAO") && LLGLSLShader::sNoFixedFunction; //Temporary workaround for vaos being broken when shaders are off - LLVertexBuffer::sPreferStreamDraw = gSavedSettings.getBOOL("RenderPreferStreamDraw"); - LLVertexBuffer::sEnableVBOs = gSavedSettings.getBOOL("RenderVBOEnable"); - LLVertexBuffer::sDisableVBOMapping = LLVertexBuffer::sEnableVBOs;// && gSavedSettings.getBOOL("RenderVBOMappingDisable") ; //Temporary workaround for vbo mapping being straight up broken - sNoAlpha = gSavedSettings.getBOOL("RenderNoAlpha"); - LLPipeline::sTextureBindTest = gSavedSettings.getBOOL("RenderDebugTextureBind"); + refreshCachedSettings(); LLVertexBuffer::initClass(LLVertexBuffer::sEnableVBOs, LLVertexBuffer::sDisableVBOMapping); @@ -6825,14 +6735,14 @@ void LLPipeline::renderBloom(BOOL for_snapshot, F32 zoom_factor, int subfield, b static const LLCachedControl RenderFSAASamples("RenderFSAASamples",0); LLVertexBuffer::unbind(); - LLGLState::checkStates(); - LLGLState::checkTextureChannels(); + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkTextureChannels(); assertInitialized(); if (gUseWireframe) { - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + gGL.setPolygonMode(LLRender::PF_FRONT_AND_BACK, LLRender::PM_FILL); } //U32 res_mod = RenderResolutionDivisor;//.get(); @@ -6845,10 +6755,11 @@ void LLPipeline::renderBloom(BOOL for_snapshot, F32 zoom_factor, int subfield, b LL_RECORD_BLOCK_TIME(FTM_RENDER_BLOOM); gGL.color4f(1,1,1,1); LLGLDepthTest depth(GL_FALSE); - LLGLDisable blend(GL_BLEND); - LLGLDisable cull(GL_CULL_FACE); + LLGLDisable blend; + LLGLDisable cull; - enableLightsFullbright(LLColor4(1,1,1,1)); + LLGLState light_state; + enableLightsFullbright(light_state); gGL.matrixMode(LLRender::MM_PROJECTION); gGL.pushMatrix(); @@ -6857,11 +6768,19 @@ void LLPipeline::renderBloom(BOOL for_snapshot, F32 zoom_factor, int subfield, b gGL.pushMatrix(); gGL.loadIdentity(); - LLGLDisable test(GL_ALPHA_TEST); + LLGLDisable test; gGL.setColorMask(true, true); glClearColor(0,0,0,0); + //static LLRender::Context sOldContext = LLRender::Context(); + //const LLRender::Context& newContext = gGL.getContextSnapshot(); + //if (memcmp(&sOldContext, &newContext, sizeof(LLRender::Context)) != 0) + //{ + //newContext.printDiff(sOldContext); + //} + //sOldContext = newContext; + if (tiling && !LLPipeline::sRenderDeferred) //Need to coax this into working with deferred now that tiling is back. { gGlowCombineProgram.bind(); @@ -6871,7 +6790,7 @@ void LLPipeline::renderBloom(BOOL for_snapshot, F32 zoom_factor, int subfield, b //LLGLEnable stencil(GL_STENCIL_TEST); //glStencilFunc(GL_NOTEQUAL, 255, 0xFFFFFFFF); //glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); - //LLGLDisable blend(GL_BLEND); + //LLGLDisable blend; // If the snapshot is constructed from tiles, calculate which // tile we're in. @@ -6884,7 +6803,7 @@ void LLPipeline::renderBloom(BOOL for_snapshot, F32 zoom_factor, int subfield, b LLVector2 tc1 = tile*tile_size; // Top left texture coordinates LLVector2 tc2 = (tile+LLVector2(1,1))*tile_size; // Bottom right texture coordinates - LLGLEnable blend(GL_BLEND); + LLGLEnable blend; gGL.setSceneBlendType(LLRender::BT_ADD); LLPointer buff = new LLVertexBuffer(AUX_VB_MASK, 0); @@ -6945,8 +6864,8 @@ void LLPipeline::renderBloom(BOOL for_snapshot, F32 zoom_factor, int subfield, b gGlowExtractProgram.uniform3f(LLShaderMgr::GLOW_LUM_WEIGHTS, lumWeights.mV[0], lumWeights.mV[1], lumWeights.mV[2]); gGlowExtractProgram.uniform3f(LLShaderMgr::GLOW_WARMTH_WEIGHTS, warmthWeights.mV[0], warmthWeights.mV[1], warmthWeights.mV[2]); gGlowExtractProgram.uniform1f(LLShaderMgr::GLOW_WARMTH_AMOUNT, warmthAmount); - LLGLEnable blend_on(GL_BLEND); - LLGLEnable test(GL_ALPHA_TEST); + LLGLEnable blend_on; + LLGLEnable test; gGL.setSceneBlendType(LLRender::BT_ADD_WITH_ALPHA); @@ -6954,7 +6873,8 @@ void LLPipeline::renderBloom(BOOL for_snapshot, F32 zoom_factor, int subfield, b render_target.bindTexture(0, 0); gGL.color4f(1,1,1,1); - gPipeline.enableLightsFullbright(LLColor4(1,1,1,1)); + LLGLState light_state; + gPipeline.enableLightsFullbright(light_state); drawFullScreenRect(); @@ -7013,11 +6933,8 @@ void LLPipeline::renderBloom(BOOL for_snapshot, F32 zoom_factor, int subfield, b glBindFramebuffer(GL_FRAMEBUFFER, 0); }*/ - gGLViewport[0] = gViewerWindow->getWorldViewRectRaw().mLeft; - gGLViewport[1] = gViewerWindow->getWorldViewRectRaw().mBottom; - gGLViewport[2] = gViewerWindow->getWorldViewRectRaw().getWidth(); - gGLViewport[3] = gViewerWindow->getWorldViewRectRaw().getHeight(); - glViewport(gGLViewport[0], gGLViewport[1], gGLViewport[2], gGLViewport[3]); + gGLViewport = gViewerWindow->getWorldViewRectRaw(); + gGL.setViewport(gGLViewport); gGL.flush(); @@ -7038,7 +6955,7 @@ void LLPipeline::renderBloom(BOOL for_snapshot, F32 zoom_factor, int subfield, b if (dof_enabled) { LLGLSLShader* shader = &gDeferredPostProgram; - LLGLDisable blend(GL_BLEND); + LLGLDisable blend; //depth of field focal plane calculations static F32 current_distance = 16.f; @@ -7165,7 +7082,7 @@ void LLPipeline::renderBloom(BOOL for_snapshot, F32 zoom_factor, int subfield, b { //perform DoF sampling at half-res (preserve alpha channel) mFinalScreen.bindTarget(); - glViewport(0,0, dof_width, dof_height); + gGL.setViewport(0,0, dof_width, dof_height); gGL.setColorMask(true, false); shader = &gDeferredPostProgram; @@ -7185,15 +7102,12 @@ void LLPipeline::renderBloom(BOOL for_snapshot, F32 zoom_factor, int subfield, b if (multisample) { mScreen.bindTarget(); - glViewport(0, 0, mDeferredScreen.getWidth(), mDeferredScreen.getHeight()); + gGL.setViewport(0, 0, mDeferredScreen.getWidth(), mDeferredScreen.getHeight()); } else { - gGLViewport[0] = gViewerWindow->getWorldViewRectRaw().mLeft; - gGLViewport[1] = gViewerWindow->getWorldViewRectRaw().mBottom; - gGLViewport[2] = gViewerWindow->getWorldViewRectRaw().getWidth(); - gGLViewport[3] = gViewerWindow->getWorldViewRectRaw().getHeight(); - glViewport(gGLViewport[0], gGLViewport[1], gGLViewport[2], gGLViewport[3]); + gGLViewport = gViewerWindow->getWorldViewRectRaw(); + gGL.setViewport(gGLViewport); } shader = &gDeferredDoFCombineProgram; @@ -7278,7 +7192,7 @@ void LLPipeline::renderBloom(BOOL for_snapshot, F32 zoom_factor, int subfield, b LLRenderTarget& render_target = dof_enabled ? mScreen : mDeferredLight; S32 width = render_target.getWidth(); S32 height = render_target.getHeight(); - glViewport(0, 0, width, height); + gGL.setViewport(0, 0, width, height); LLGLSLShader* shader = &gGlowCombineFXAAProgram; @@ -7311,11 +7225,8 @@ void LLPipeline::renderBloom(BOOL for_snapshot, F32 zoom_factor, int subfield, b gGL.getTexUnit(channel)->setTextureFilteringOption(LLTexUnit::TFO_BILINEAR); } - gGLViewport[0] = gViewerWindow->getWorldViewRectRaw().mLeft; - gGLViewport[1] = gViewerWindow->getWorldViewRectRaw().mBottom; - gGLViewport[2] = gViewerWindow->getWorldViewRectRaw().getWidth(); - gGLViewport[3] = gViewerWindow->getWorldViewRectRaw().getHeight(); - glViewport(gGLViewport[0], gGLViewport[1], gGLViewport[2], gGLViewport[3]); + gGLViewport = gViewerWindow->getWorldViewRectRaw(); + gGL.setViewport(gGLViewport); shader->uniform2f(LLShaderMgr::FXAA_RCP_SCREEN_RES, 1.f/width, 1.f/height); shader->uniform4f(LLShaderMgr::FXAA_RCP_FRAME_OPT, -0.5f/width, -0.5f/height, 0.5f/width, 0.5f/height); @@ -7333,7 +7244,7 @@ void LLPipeline::renderBloom(BOOL for_snapshot, F32 zoom_factor, int subfield, b tc2 /= (F32) res_mod; }*/ - LLGLDisable blend(GL_BLEND); + LLGLDisable blend; if (LLGLSLShader::sNoFixedFunction) { @@ -7350,7 +7261,7 @@ void LLPipeline::renderBloom(BOOL for_snapshot, F32 zoom_factor, int subfield, b gGL.getTexUnit(0)->bind(&mGlow[1]); gGL.getTexUnit(1)->bind(&mScreen); - LLGLEnable multisample(RenderFSAASamples > 0 ? GL_MULTISAMPLE_ARB : 0); + LLGLEnable multisample(RenderFSAASamples > 0); drawFullScreenRect(); @@ -7380,7 +7291,7 @@ void LLPipeline::renderBloom(BOOL for_snapshot, F32 zoom_factor, int subfield, b gGL.setColorMask(true, false); - LLGLEnable blend(GL_BLEND); + LLGLEnable blend; gGL.color4f(1,1,1,0.75f); gGL.getTexUnit(0)->bind(&mPhysicsDisplay); @@ -7416,8 +7327,8 @@ void LLPipeline::renderBloom(BOOL for_snapshot, F32 zoom_factor, int subfield, b LLVertexBuffer::unbind(); - LLGLState::checkStates(); - LLGLState::checkTextureChannels(); + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkTextureChannels(); } @@ -7508,14 +7419,14 @@ void LLPipeline::bindDeferredShader(LLGLSLShader& shader, LLRenderTarget* diffus channel = shader.enableTexture(LLShaderMgr::DEFERRED_NOISE); if (channel > -1) { - gGL.getTexUnit(channel)->bindManual(LLTexUnit::TT_TEXTURE, mNoiseMap); + gGL.getTexUnit(channel)->bindManual(LLTexUnit::TT_TEXTURE, mNoiseMap->getTexName()); gGL.getTexUnit(channel)->setTextureFilteringOption(LLTexUnit::TFO_POINT); } channel = shader.enableTexture(LLShaderMgr::DEFERRED_LIGHTFUNC); if (channel > -1) { - gGL.getTexUnit(channel)->bindManual(LLTexUnit::TT_TEXTURE, mLightFunc); + gGL.getTexUnit(channel)->bindManual(LLTexUnit::TT_TEXTURE, mLightFunc->getTexName()); } stop_glerror(); @@ -7680,7 +7591,7 @@ void LLPipeline::renderDeferredLighting() 0, 0, mDeferredDepth.getWidth(), mDeferredDepth.getHeight(), GL_DEPTH_BUFFER_BIT, GL_NEAREST); } - LLGLEnable multisample(RenderFSAASamples > 0 ? GL_MULTISAMPLE_ARB : 0); + LLGLEnable multisample(RenderFSAASamples > 0); if (gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_HUD)) { @@ -7688,7 +7599,7 @@ void LLPipeline::renderDeferredLighting() } //ati doesn't seem to love actually using the stencil buffer on FBO's - LLGLDisable stencil(GL_STENCIL_TEST); + LLGLDisable stencil; //glStencilFunc(GL_EQUAL, 1, 0xFFFFFFFF); //glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); @@ -7697,15 +7608,16 @@ void LLPipeline::renderDeferredLighting() //draw a cube around every light LLVertexBuffer::unbind(); - LLGLEnable cull(GL_CULL_FACE); - LLGLEnable blend(GL_BLEND); + LLGLEnable cull; + LLGLEnable blend; { - setupHWLights(NULL); //to set mSunDir; - mTransformedSunDir.load3(mSunDir.mV); + mTransformedSunDir.load3(getSunDir().mV); glh_get_current_modelview().rotate(mTransformedSunDir,mTransformedSunDir); } + llassert_always(LLGLState::checkEnabled()); + gGL.pushMatrix(); gGL.loadIdentity(); gGL.matrixMode(LLRender::MM_PROJECTION); @@ -7716,7 +7628,7 @@ void LLPipeline::renderDeferredLighting() { F32 ssao_scale = llclamp(RenderSSAOResolutionScale.get(),.01f,1.f); - LLGLDisable blend(GL_BLEND); + LLGLDisable blend; //Downsample with fullscreen quad. GL_NEAREST if(ssao_scale < 1.f) @@ -7741,7 +7653,7 @@ void LLPipeline::renderDeferredLighting() bindDeferredShader(gDeferredSSAOProgram); if(ssao_scale < 1.f) { - glViewport(0,0,mDeferredDownsampledDepth.getWidth(),mDeferredDownsampledDepth.getHeight()); + gGL.setViewport(0,0,mDeferredDownsampledDepth.getWidth(),mDeferredDownsampledDepth.getHeight()); } { LLGLDepthTest depth(GL_FALSE); @@ -7775,7 +7687,7 @@ void LLPipeline::renderDeferredLighting() } { - LLGLDisable blend(GL_BLEND); + LLGLDisable blend; LLGLDepthTest depth(GL_TRUE, GL_FALSE, GL_ALWAYS); drawFullScreenRect(); } @@ -7810,7 +7722,7 @@ void LLPipeline::renderDeferredLighting() gDeferredBlurLightProgram.uniform1f(sDistFactor, dist_factor); { - LLGLDisable blend(GL_BLEND); + LLGLDisable blend; LLGLDepthTest depth(GL_TRUE, GL_FALSE, GL_ALWAYS); drawFullScreenRect(); } @@ -7824,7 +7736,7 @@ void LLPipeline::renderDeferredLighting() gDeferredBlurLightProgram.uniform2f(sDelta, 0.f, (blur_size * (kern_length / 2.f - 0.5f)) / mScreen.getHeight()); { - LLGLDisable blend(GL_BLEND); + LLGLDisable blend; LLGLDepthTest depth(GL_TRUE, GL_FALSE, GL_ALWAYS); drawFullScreenRect(); } @@ -7851,8 +7763,8 @@ void LLPipeline::renderDeferredLighting() bindDeferredShader(LLPipeline::sUnderWaterRender ? gDeferredSoftenWaterProgram : gDeferredSoftenProgram); { LLGLDepthTest depth(GL_FALSE); - LLGLDisable blend(GL_BLEND); - LLGLDisable test(GL_ALPHA_TEST); + LLGLDisable blend; + LLGLDisable test; //full screen blit gGL.pushMatrix(); @@ -7872,8 +7784,8 @@ void LLPipeline::renderDeferredLighting() } { //render non-deferred geometry (fullbright, alpha, etc) - LLGLDisable blend(GL_BLEND); - LLGLDisable stencil(GL_STENCIL_TEST); + LLGLDisable blend; + LLGLDisable stencil; gGL.setSceneBlendType(LLRender::BT_ALPHA); gPipeline.pushRenderTypeMask(); @@ -7987,7 +7899,6 @@ void LLPipeline::renderDeferredLighting() gDeferredLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s); gDeferredLightProgram.uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, col.mV); gDeferredLightProgram.uniform1f(LLShaderMgr::LIGHT_FALLOFF, volume->getLightFalloff()*0.5f); - gGL.syncMatrices(); mCubeVB->drawRange(LLRender::TRIANGLE_FAN, 0, 7, 8, get_box_fan_indices(camera, center)); stop_glerror(); @@ -8044,7 +7955,6 @@ void LLPipeline::renderDeferredLighting() gDeferredSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s); gDeferredSpotLightProgram.uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, col.mV); gDeferredSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_FALLOFF, volume->getLightFalloff()*0.5f); - gGL.syncMatrices(); mCubeVB->drawRange(LLRender::TRIANGLE_FAN, 0, 7, 8, get_box_fan_indices(camera, center)); } @@ -8185,8 +8095,8 @@ void LLPipeline::renderDeferredLighting() mFinalScreen.bindTarget(); { //render non-deferred geometry (alpha, fullbright, glow) - LLGLDisable blend(GL_BLEND); - LLGLDisable stencil(GL_STENCIL_TEST); + LLGLDisable blend; + LLGLDisable stencil; pushRenderTypeMask(); andRenderTypeMask(LLPipeline::RENDER_TYPE_ALPHA, @@ -8262,7 +8172,7 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target) 0, 0, mDeferredDepth.getWidth(), mDeferredDepth.getHeight(), GL_DEPTH_BUFFER_BIT, GL_NEAREST); } - LLGLEnable multisample(RenderFSAASamples > 0 ? GL_MULTISAMPLE_ARB : 0); + LLGLEnable multisample(RenderFSAASamples > 0); if (gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_HUD)) { @@ -8270,7 +8180,7 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target) } //ati doesn't seem to love actually using the stencil buffer on FBO's - LLGLDisable stencil(GL_STENCIL_TEST); + LLGLDisable stencil; //glStencilFunc(GL_EQUAL, 1, 0xFFFFFFFF); //glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); @@ -8279,15 +8189,16 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target) //draw a cube around every light LLVertexBuffer::unbind(); - LLGLEnable cull(GL_CULL_FACE); - LLGLEnable blend(GL_BLEND); + LLGLEnable cull; + LLGLEnable blend; { - setupHWLights(NULL); //to set mSunDir; - mTransformedSunDir.load3(mSunDir.mV); + mTransformedSunDir.load3(getSunDir().mV); glh_get_current_modelview().rotate(mTransformedSunDir,mTransformedSunDir); } + llassert_always(LLGLState::checkEnabled()); + gGL.pushMatrix(); gGL.loadIdentity(); gGL.matrixMode(LLRender::MM_PROJECTION); @@ -8298,7 +8209,7 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target) { F32 ssao_scale = llclamp(RenderSSAOResolutionScale.get(),.01f,1.f); - LLGLDisable blend(GL_BLEND); + LLGLDisable blend; //Downsample with fullscreen quad. GL_NEAREST if(ssao_scale < 1.f) @@ -8323,7 +8234,7 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target) bindDeferredShader(gDeferredSSAOProgram); if(ssao_scale < 1.f) { - glViewport(0,0,mDeferredDownsampledDepth.getWidth(),mDeferredDownsampledDepth.getHeight()); + gGL.setViewport(0,0,mDeferredDownsampledDepth.getWidth(),mDeferredDownsampledDepth.getHeight()); } { LLGLDepthTest depth(GL_FALSE); @@ -8358,7 +8269,7 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target) } { - LLGLDisable blend(GL_BLEND); + LLGLDisable blend; LLGLDepthTest depth(GL_TRUE, GL_FALSE, GL_ALWAYS); drawFullScreenRect(); } @@ -8393,8 +8304,8 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target) bindDeferredShader(gDeferredSoftenProgram); { LLGLDepthTest depth(GL_FALSE); - LLGLDisable blend(GL_BLEND); - LLGLDisable test(GL_ALPHA_TEST); + LLGLDisable blend; + LLGLDisable test; //full screen blit gGL.pushMatrix(); @@ -8414,8 +8325,8 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target) } { //render non-deferred geometry (fullbright, alpha, etc) - LLGLDisable blend(GL_BLEND); - LLGLDisable stencil(GL_STENCIL_TEST); + LLGLDisable blend; + LLGLDisable stencil; gGL.setSceneBlendType(LLRender::BT_ALPHA); gPipeline.pushRenderTypeMask(); @@ -8533,7 +8444,6 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target) gDeferredLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s); gDeferredLightProgram.uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, col.mV); gDeferredLightProgram.uniform1f(LLShaderMgr::LIGHT_FALLOFF, volume->getLightFalloff()*0.5f); - gGL.syncMatrices(); mCubeVB->drawRange(LLRender::TRIANGLE_FAN, 0, 7, 8, get_box_fan_indices(camera, center)); stop_glerror(); @@ -8593,7 +8503,6 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target) gDeferredSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s); gDeferredSpotLightProgram.uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, col.mV); gDeferredSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_FALLOFF, volume->getLightFalloff()*0.5f); - gGL.syncMatrices(); mCubeVB->drawRange(LLRender::TRIANGLE_FAN, 0, 7, 8, get_box_fan_indices(camera, center)); } @@ -8735,8 +8644,8 @@ void LLPipeline::renderDeferredLightingToRT(LLRenderTarget* target) mFinalScreen.bindTarget(); { //render non-deferred geometry (alpha, fullbright, glow) - LLGLDisable blend(GL_BLEND); - LLGLDisable stencil(GL_STENCIL_TEST); + LLGLDisable blend; + LLGLDisable stencil; pushRenderTypeMask(); andRenderTypeMask(LLPipeline::RENDER_TYPE_ALPHA, @@ -8983,9 +8892,9 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) } LLVertexBuffer::unbind(); - LLGLState::checkStates(); - LLGLState::checkTextureChannels(); - LLGLState::checkClientArrays(); + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkTextureChannels(); + LLGLStateValidator::checkClientArrays(); LLCamera camera = camera_in; camera.setFar(camera.getFar()*0.87654321f); @@ -9102,7 +9011,7 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) } else { - renderGeom(camera, TRUE); + renderGeom(camera, TRUE); } gPipeline.popRenderTypeMask(); @@ -9140,7 +9049,7 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) static const LLCachedControl skip_distortion_updates("SkipReflectOcclusionUpdates",false); LLPipeline::sSkipUpdate = skip_distortion_updates; LLGLUserClipPlane clip_plane(plane, mat, projection); - LLGLDisable cull(GL_CULL_FACE); + LLGLDisable cull; updateCull(camera, ref_result, -water_clip, &plane); stateSort(camera, ref_result); @@ -9262,6 +9171,7 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) if (!LLRenderTarget::sUseFBO) { + gGL.syncContextState(); glClear(GL_DEPTH_BUFFER_BIT); } glClearColor(0.f, 0.f, 0.f, 0.f); @@ -9272,7 +9182,7 @@ void LLPipeline::generateWaterReflection(LLCamera& camera_in) LLPlane npnorm(-pnorm, -pd); LLViewerCamera::getInstance()->setUserClipPlane(npnorm); - LLGLState::checkStates(); + LLGLStateValidator::checkStates(); if (!skip_avatar_update) { @@ -9315,7 +9225,7 @@ void LLPipeline::renderShadow(const LLMatrix4a& view, const LLMatrix4a& proj, LL LLRenderPass::PASS_NORMSPEC_EMISSIVE, }; - LLGLEnable cull(GL_CULL_FACE); + LLGLEnable cull; if (use_shader) { @@ -9709,14 +9619,16 @@ void LLPipeline::generateSunShadow(LLCamera& camera) //F32 nearDist[] = { n.mV[0], n.mV[1], n.mV[2], n.mV[2] }; //put together a universal "near clip" plane for shadow frusta + LLVector3 sunDir = getSunDir(); LLPlane shadow_near_clip; { + ; LLVector3 p = gAgent.getPositionAgent(); - p += mSunDir * RenderFarClip*2.f; - shadow_near_clip.setVec(p, mSunDir); + p += sunDir * RenderFarClip*2.f; + shadow_near_clip.setVec(p, sunDir); } - LLVector3 lightDir = -mSunDir; + LLVector3 lightDir = -sunDir; lightDir.normVec(); //create light space camera matrix @@ -10373,9 +10285,9 @@ static LLTrace::BlockTimerStatHandle FTM_IMPOSTOR_RESIZE("Impostor Resize"); void LLPipeline::generateImpostor(LLVOAvatar* avatar) { - LLGLState::checkStates(); - LLGLState::checkTextureChannels(); - LLGLState::checkClientArrays(); + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkTextureChannels(); + LLGLStateValidator::checkClientArrays(); static LLCullResult result; result.clear(); @@ -10580,8 +10492,8 @@ void LLPipeline::generateImpostor(LLVOAvatar* avatar) } else { - LLGLEnable scissor(GL_SCISSOR_TEST); - glScissor(0, 0, resX, resY); + LLGLEnable scissor; + gGL.setScissor(0, 0, resX, resY); avatar->mImpostor.clear(); renderGeom(camera); @@ -10611,7 +10523,7 @@ void LLPipeline::generateImpostor(LLVOAvatar* avatar) glDrawBuffersARB(1, &buff); } - LLGLDisable blend(GL_BLEND); + LLGLDisable blend; if (visually_muted) { @@ -10680,9 +10592,9 @@ void LLPipeline::generateImpostor(LLVOAvatar* avatar) avatar->cacheImpostorValues(); LLVertexBuffer::unbind(); - LLGLState::checkStates(); - LLGLState::checkTextureChannels(); - LLGLState::checkClientArrays(); + LLGLStateValidator::checkStates(); + LLGLStateValidator::checkTextureChannels(); + LLGLStateValidator::checkClientArrays(); } BOOL LLPipeline::hasRenderBatches(const U32 type) const diff --git a/indra/newview/pipeline.h b/indra/newview/pipeline.h index 22d1a99da..bbe736d8c 100644 --- a/indra/newview/pipeline.h +++ b/indra/newview/pipeline.h @@ -117,6 +117,7 @@ public: void resetVertexBuffers(); void doResetVertexBuffers(); void resizeScreenTexture(); + void releaseVertexBuffers(); void releaseGLBuffers(); void releaseLUTBuffers(); void releaseScreenBuffers(); @@ -227,11 +228,8 @@ public: void enableShadows(const BOOL enable_shadows); -// void setLocalLighting(const BOOL local_lighting); -// BOOL isLocalLightingEnabled() const; - S32 setLightingDetail(S32 level); - S32 getLightingDetail() const { return mLightingDetail; } - S32 getMaxLightingDetail() const; + void updateLocalLightingEnabled(); + bool isLocalLightingEnabled() const { return mLightingEnabled; } BOOL canUseWindLightShaders() const; BOOL canUseWindLightShadersOnObjects() const; @@ -251,7 +249,7 @@ public: void createObjects(F32 max_dtime); void createObject(LLViewerObject* vobj); void processPartitionQ(); - void updateGeom(F32 max_dtime); + void updateGeom(F32 max_dtime, LLCamera& camera); void updateGL(); void rebuildPriorityGroups(); void rebuildGroups(); @@ -311,16 +309,18 @@ public: void resetLocalLights(); //Default all gl light parameters. Used upon restoreGL. Fixes light brightness problems on fullscren toggle void calcNearbyLights(LLCamera& camera); - void setupHWLights(LLDrawPool* pool); - void setupAvatarLights(BOOL for_edit = FALSE); - void enableLights(U32 mask); - void enableLightsStatic(); - void enableLightsDynamic(); - void enableLightsAvatar(); - void enableLightsPreview(); - void enableLightsAvatarEdit(const LLColor4& color); - void enableLightsFullbright(const LLColor4& color); - void disableLights(); + void gatherLocalLights(); + void setupHWLights(); + void updateHWLightMode(U8 mode); + U8 setupFeatureLights(U8 cur_count); + void enableLights(U32 mask, LLGLState& light_state, const LLColor4* color = nullptr); + void enableLightsStatic(LLGLState& light_state); + void enableLightsDynamic(LLGLState& light_state); + void enableLightsAvatar(LLGLState& light_state); + void enableLightsPreview(LLGLState& light_state); + void enableLightsAvatarEdit(LLGLState& light_state, const LLColor4& color); + void enableLightsFullbright(LLGLState& light_state); + void disableLights(LLGLState& light_state); void shiftObjects(const LLVector3 &offset); @@ -359,6 +359,14 @@ public: void pushRenderDebugFeatureMask(); void popRenderDebugFeatureMask(); + template + LLGLStateIface* pushRenderPassState(U8 newState = LLGLStateIface::CURRENT_STATE) { + llassert_always(mInRenderPass); + LLGLStateIface* stateObject = new LLGLState(newState); + mRenderPassStates.emplace_back(stateObject); + return stateObject; + } + static void toggleRenderType(U32 type); // For UI control of render features @@ -429,6 +437,13 @@ private: void unhideDrawable( LLDrawable *pDrawable ); void drawFullScreenRect(); + + void clearRenderPassStates() { + while (!mRenderPassStates.empty()) { + mRenderPassStates.pop_back(); + } + mInRenderPass = false; + } public: enum {GPU_CLASS_MAX = 3 }; @@ -637,8 +652,8 @@ private: LLRenderTarget mGlow[2]; //noise map - U32 mNoiseMap; - U32 mLightFunc; + LLImageGL::GLTextureName mNoiseMap; + LLImageGL::GLTextureName mLightFunc; LLColor4 mSunDiffuse; LLVector3 mSunDir; @@ -696,7 +711,6 @@ private: LLDrawable::drawable_set_t mLights; light_set_t mNearbyLights; // lights near camera - LLColor4 mHWLightColors[8]; ///////////////////////////////////////////// // @@ -723,6 +737,9 @@ private: LLDrawable::drawable_set_t mRetexturedList; + bool mInRenderPass; + std::vector< std::unique_ptr > mRenderPassStates; + ////////////////////////////////////////////////// // // Draw pools are responsible for storing all rendered data, @@ -793,9 +810,11 @@ protected: LLPointer mFaceSelectImagep; + std::vector mLocalLights; + U8 mHWLightCount; + U8 mLightMode; U32 mLightMask; - U32 mLightMovingMask; - S32 mLightingDetail; + bool mLightingEnabled; static BOOL sRenderPhysicalBeacons; static BOOL sRenderMOAPBeacons; diff --git a/indra/newview/qtoolalign.cpp b/indra/newview/qtoolalign.cpp index 240bbffcb..7e537233b 100644 --- a/indra/newview/qtoolalign.cpp +++ b/indra/newview/qtoolalign.cpp @@ -370,8 +370,8 @@ void QToolAlign::render() // Draw bounding box LLGLSUIDefault gls_ui; - LLGLEnable gl_blend(GL_BLEND); - LLGLEnable gls_alpha_test(GL_ALPHA_TEST); + LLGLEnable gl_blend; + LLGLEnable gls_alpha_test; LLGLDepthTest gls_depth(GL_FALSE); gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);