diff options
author | Alexander Gavriliuk <alexandrgproductengine@lindenlab.com> | 2023-11-30 17:47:58 +0100 |
---|---|---|
committer | Alexander Gavriliuk <alexandrgproductengine@lindenlab.com> | 2023-12-05 03:37:06 +0100 |
commit | c9cd5631e4b149f83c5a49c8fbf869cf2fb5b6a7 (patch) | |
tree | d09566a4132530ea65574a886540e0f258103017 /indra/newview/lldrawpoolmaterials.cpp | |
parent | 54db4206e9302e7510bc4f103ff59714c1be942d (diff) | |
parent | 683bf84bb38adc88d4a4b7fedaed89b41fcac45e (diff) |
Merge branch 'main' into DRTVWR-489
Diffstat (limited to 'indra/newview/lldrawpoolmaterials.cpp')
-rw-r--r-- | indra/newview/lldrawpoolmaterials.cpp | 247 |
1 files changed, 133 insertions, 114 deletions
diff --git a/indra/newview/lldrawpoolmaterials.cpp b/indra/newview/lldrawpoolmaterials.cpp index f2408a3294..6a7e05ac74 100644 --- a/indra/newview/lldrawpoolmaterials.cpp +++ b/indra/newview/lldrawpoolmaterials.cpp @@ -32,9 +32,6 @@ #include "pipeline.h" #include "llglcommonfunc.h" #include "llvoavatar.h" -#include "llperfstats.h" - -S32 diffuse_channel = -1; LLDrawPoolMaterials::LLDrawPoolMaterials() : LLRenderPass(LLDrawPool::POOL_MATERIALS) @@ -99,18 +96,8 @@ void LLDrawPoolMaterials::beginDeferredPass(S32 pass) llassert(mShader->mRiggedVariant != nullptr); mShader = mShader->mRiggedVariant; } - mShader->bind(); - - if (LLPipeline::sRenderingHUDs) - { - mShader->uniform1i(LLShaderMgr::NO_ATMO, 1); - } - else - { - mShader->uniform1i(LLShaderMgr::NO_ATMO, 0); - } - diffuse_channel = mShader->enableTexture(LLShaderMgr::DIFFUSE_MAP); + gPipeline.bindDeferredShader(*mShader); } void LLDrawPoolMaterials::endDeferredPass(S32 pass) @@ -160,128 +147,160 @@ void LLDrawPoolMaterials::renderDeferred(S32 pass) type += 1; } - U32 mask = mShader->mAttributeMask; - LLCullResult::drawinfo_iterator begin = gPipeline.beginRenderMap(type); LLCullResult::drawinfo_iterator end = gPipeline.endRenderMap(type); - std::unique_ptr<LLPerfStats::RecordAttachmentTime> ratPtr{}; - for (LLCullResult::drawinfo_iterator i = begin; i != end; ++i) + F32 lastIntensity = 0.f; + F32 lastFullbright = 0.f; + F32 lastMinimumAlpha = 0.f; + LLVector4 lastSpecular = LLVector4(0, 0, 0, 0); + + GLint intensity = mShader->getUniformLocation(LLShaderMgr::ENVIRONMENT_INTENSITY); + GLint brightness = mShader->getUniformLocation(LLShaderMgr::EMISSIVE_BRIGHTNESS); + GLint minAlpha = mShader->getUniformLocation(LLShaderMgr::MINIMUM_ALPHA); + GLint specular = mShader->getUniformLocation(LLShaderMgr::SPECULAR_COLOR); + + GLint diffuseChannel = mShader->enableTexture(LLShaderMgr::DIFFUSE_MAP); + GLint specChannel = mShader->enableTexture(LLShaderMgr::SPECULAR_MAP); + GLint normChannel = mShader->enableTexture(LLShaderMgr::BUMP_MAP); + + LLTexture* lastNormalMap = nullptr; + LLTexture* lastSpecMap = nullptr; + LLTexture* lastDiffuse = nullptr; + + gGL.getTexUnit(diffuseChannel)->unbindFast(LLTexUnit::TT_TEXTURE); + + if (intensity > -1) + { + glUniform1f(intensity, lastIntensity); + } + + if (brightness > -1) + { + glUniform1f(brightness, lastFullbright); + } + + if (minAlpha > -1) + { + glUniform1f(minAlpha, lastMinimumAlpha); + } + + if (specular > -1) + { + glUniform4fv(specular, 1, lastSpecular.mV); + } + + LLVOAvatar* lastAvatar = nullptr; + + for (LLCullResult::drawinfo_iterator i = begin; i != end; ) { + LL_PROFILE_ZONE_NAMED_CATEGORY_MATERIAL("materials draw loop"); LLDrawInfo& params = **i; + + LLCullResult::increment_iterator(i, end); + + if (specular > -1 && params.mSpecColor != lastSpecular) + { + lastSpecular = params.mSpecColor; + glUniform4fv(specular, 1, lastSpecular.mV); + } - if(params.mFace) + if (intensity != -1 && lastIntensity != params.mEnvIntensity) { - LLViewerObject* vobj = (LLViewerObject *)params.mFace->getViewerObject(); + lastIntensity = params.mEnvIntensity; + glUniform1f(intensity, lastIntensity); + } + + if (minAlpha > -1 && lastMinimumAlpha != params.mAlphaMaskCutoff) + { + lastMinimumAlpha = params.mAlphaMaskCutoff; + glUniform1f(minAlpha, lastMinimumAlpha); + } + + F32 fullbright = params.mFullbright ? 1.f : 0.f; + if (brightness > -1 && lastFullbright != fullbright) + { + lastFullbright = fullbright; + glUniform1f(brightness, lastFullbright); + } - if( vobj && vobj->isAttachment() ) + if (normChannel > -1 && params.mNormalMap != lastNormalMap) + { + lastNormalMap = params.mNormalMap; + llassert(lastNormalMap); + gGL.getTexUnit(normChannel)->bindFast(lastNormalMap); + } + + if (specChannel > -1 && params.mSpecularMap != lastSpecMap) + { + lastSpecMap = params.mSpecularMap; + llassert(lastSpecMap); + gGL.getTexUnit(specChannel)->bindFast(lastSpecMap); + } + + if (params.mTexture != lastDiffuse) + { + lastDiffuse = params.mTexture; + if (lastDiffuse) + { + gGL.getTexUnit(diffuseChannel)->bindFast(lastDiffuse); + } + else { - trackAttachments( vobj, params.mFace->isState(LLFace::RIGGED), &ratPtr ); + gGL.getTexUnit(diffuseChannel)->unbindFast(LLTexUnit::TT_TEXTURE); } } - - mShader->uniform4f(LLShaderMgr::SPECULAR_COLOR, params.mSpecColor.mV[0], params.mSpecColor.mV[1], params.mSpecColor.mV[2], params.mSpecColor.mV[3]); - mShader->uniform1f(LLShaderMgr::ENVIRONMENT_INTENSITY, params.mEnvIntensity); - - if (params.mNormalMap) - { - params.mNormalMap->addTextureStats(params.mVSize); - bindNormalMap(params.mNormalMap); - } - - if (params.mSpecularMap) - { - params.mSpecularMap->addTextureStats(params.mVSize); - bindSpecularMap(params.mSpecularMap); - } - - mShader->setMinimumAlpha(params.mAlphaMaskCutoff); - mShader->uniform1f(LLShaderMgr::EMISSIVE_BRIGHTNESS, params.mFullbright ? 1.f : 0.f); + // upload matrix palette to shader + if (rigged && params.mAvatar.notNull()) { - LL_PROFILE_ZONE_SCOPED_CATEGORY_MATERIAL; - pushMaterialsBatch(params, mask, rigged); + if (params.mAvatar != lastAvatar) + { + const LLVOAvatar::MatrixPaletteCache& mpc = params.mAvatar->updateSkinInfoMatrixPalette(params.mSkinInfo); + U32 count = mpc.mMatrixPalette.size(); + + if (count == 0) + { + //skin info not loaded yet, don't render + return; + } + + mShader->uniformMatrix3x4fv(LLViewerShaderMgr::AVATAR_MATRIX, + count, + FALSE, + (GLfloat*)&(mpc.mGLMp[0])); + } } - } -} -void LLDrawPoolMaterials::bindSpecularMap(LLViewerTexture* tex) -{ - mShader->bindTexture(LLShaderMgr::SPECULAR_MAP, tex); -} + applyModelMatrix(params); -void LLDrawPoolMaterials::bindNormalMap(LLViewerTexture* tex) -{ - mShader->bindTexture(LLShaderMgr::BUMP_MAP, tex); -} + bool tex_setup = false; -void LLDrawPoolMaterials::pushMaterialsBatch(LLDrawInfo& params, U32 mask, bool rigged) -{ - LL_PROFILE_ZONE_SCOPED_CATEGORY_MATERIAL; - applyModelMatrix(params); - - bool tex_setup = false; - - //not batching textures or batch has only 1 texture -- might need a texture matrix - if (params.mTextureMatrix) - { - //if (mShiny) - { - gGL.getTexUnit(0)->activate(); - gGL.matrixMode(LLRender::MM_TEXTURE); - } - - gGL.loadMatrix((GLfloat*) params.mTextureMatrix->mMatrix); - gPipeline.mTextureMatrixOps++; - - tex_setup = true; - } - - if (mShaderLevel > 1) - { - if (params.mTexture.notNull()) - { - gGL.getTexUnit(diffuse_channel)->bindFast(params.mTexture); - } - else - { - gGL.getTexUnit(diffuse_channel)->unbindFast(LLTexUnit::TT_TEXTURE); - } - } - - if (params.mGroup) - { - params.mGroup->rebuildMesh(); - } + //not batching textures or batch has only 1 texture -- might need a texture matrix + if (params.mTextureMatrix) + { + gGL.getTexUnit(0)->activate(); + gGL.matrixMode(LLRender::MM_TEXTURE); - // upload matrix palette to shader - if (rigged && params.mAvatar.notNull()) - { - const LLVOAvatar::MatrixPaletteCache& mpc = params.mAvatar->updateSkinInfoMatrixPalette(params.mSkinInfo); - U32 count = mpc.mMatrixPalette.size(); + gGL.loadMatrix((GLfloat*)params.mTextureMatrix->mMatrix); + gPipeline.mTextureMatrixOps++; - if (count == 0) - { - //skin info not loaded yet, don't render - return; + tex_setup = true; } - mShader->uniformMatrix3x4fv(LLViewerShaderMgr::AVATAR_MATRIX, - count, - FALSE, - (GLfloat*)&(mpc.mGLMp[0])); - } - - LLGLEnableFunc stencil_test(GL_STENCIL_TEST, params.mSelected, &LLGLCommonFunc::selected_stencil_test); + /*if (params.mGroup) // TOO LATE + { + params.mGroup->rebuildMesh(); + }*/ - params.mVertexBuffer->setBufferFast(mask); - params.mVertexBuffer->drawRangeFast(params.mDrawMode, params.mStart, params.mEnd, params.mCount, params.mOffset); + params.mVertexBuffer->setBuffer(); + params.mVertexBuffer->drawRange(LLRender::TRIANGLES, params.mStart, params.mEnd, params.mCount, params.mOffset); - if (tex_setup) - { - gGL.getTexUnit(0)->activate(); - gGL.loadIdentity(); - gGL.matrixMode(LLRender::MM_MODELVIEW); + if (tex_setup) + { + gGL.getTexUnit(0)->activate(); + gGL.loadIdentity(); + gGL.matrixMode(LLRender::MM_MODELVIEW); + } } } - |