diff options
Diffstat (limited to 'indra/newview/lldrawpoolterrain.cpp')
-rw-r--r-- | indra/newview/lldrawpoolterrain.cpp | 241 |
1 files changed, 132 insertions, 109 deletions
diff --git a/indra/newview/lldrawpoolterrain.cpp b/indra/newview/lldrawpoolterrain.cpp index 3daa0f8261..ce601325c8 100644 --- a/indra/newview/lldrawpoolterrain.cpp +++ b/indra/newview/lldrawpoolterrain.cpp @@ -62,13 +62,16 @@ LLDrawPoolTerrain::LLDrawPoolTerrain(LLViewerTexture *texturep) : LLFacePool(POOL_TERRAIN), mTexturep(texturep) { + U32 format = GL_ALPHA8; + U32 int_format = GL_ALPHA; + // Hack! sDetailScale = 1.f/gSavedSettings.getF32("RenderTerrainScale"); sDetailMode = gSavedSettings.getS32("RenderTerrainDetail"); mAlphaRampImagep = LLViewerTextureManager::getFetchedTextureFromFile("alpha_gradient.tga", TRUE, LLViewerTexture::BOOST_UI, LLViewerTexture::FETCHED_TEXTURE, - GL_ALPHA8, GL_ALPHA, + format, int_format, LLUUID("e97cf410-8e61-7005-ec06-629eba4cd1fb")); //gGL.getTexUnit(0)->bind(mAlphaRampImagep.get()); @@ -77,7 +80,7 @@ LLDrawPoolTerrain::LLDrawPoolTerrain(LLViewerTexture *texturep) : m2DAlphaRampImagep = LLViewerTextureManager::getFetchedTextureFromFile("alpha_gradient_2d.j2c", TRUE, LLViewerTexture::BOOST_UI, LLViewerTexture::FETCHED_TEXTURE, - GL_ALPHA8, GL_ALPHA, + format, int_format, LLUUID("38b86f85-2575-52a9-a531-23108d8da837")); //gGL.getTexUnit(0)->bind(m2DAlphaRampImagep.get()); @@ -106,6 +109,10 @@ U32 LLDrawPoolTerrain::getVertexDataMask() { return LLVertexBuffer::MAP_VERTEX; } + else if (LLGLSLShader::sCurBoundShaderPtr) + { + return VERTEX_DATA_MASK & ~(LLVertexBuffer::MAP_TEXCOORD2 | LLVertexBuffer::MAP_TEXCOORD3); + } else { return VERTEX_DATA_MASK; @@ -115,14 +122,7 @@ U32 LLDrawPoolTerrain::getVertexDataMask() void LLDrawPoolTerrain::prerender() { mVertexShaderLevel = LLViewerShaderMgr::instance()->getVertexShaderLevel(LLViewerShaderMgr::SHADER_ENVIRONMENT); - if (mVertexShaderLevel > 0) - { - sDetailMode = 1; - } - else - { - sDetailMode = gSavedSettings.getS32("RenderTerrainDetail"); - } + sDetailMode = gSavedSettings.getS32("RenderTerrainDetail"); } void LLDrawPoolTerrain::beginRenderPass( S32 pass ) @@ -130,9 +130,24 @@ void LLDrawPoolTerrain::beginRenderPass( S32 pass ) LLFastTimer t(FTM_RENDER_TERRAIN); LLFacePool::beginRenderPass(pass); - sShader = LLPipeline::sUnderWaterRender ? - &gTerrainWaterProgram : - &gTerrainProgram; + if (sDetailMode > 0) + { + sShader = LLPipeline::sUnderWaterRender ? + &gTerrainWaterProgram : + &gTerrainProgram; + } + else + { + if (LLPipeline::sUnderWaterRender) + { + sShader = &gObjectSimpleNonIndexedTexGenWaterProgram; + } + else + { + sShader = &gObjectSimpleNonIndexedTexGenProgram; + } + } + if (mVertexShaderLevel > 1 && sShader->mShaderLevel > 0) { @@ -181,7 +196,7 @@ void LLDrawPoolTerrain::render(S32 pass) return; } // Render simplified land if video card can't do sufficient multitexturing - if (!gGLManager.mHasARBEnvCombine || (gGLManager.mNumTextureUnits < 2)) + if (!LLGLSLShader::sNoFixedFunction || !gGLManager.mHasARBEnvCombine || (gGLManager.mNumTextureUnits < 2)) { renderSimple(); // Render without multitexture return; @@ -193,7 +208,15 @@ void LLDrawPoolTerrain::render(S32 pass) if (mVertexShaderLevel > 1 && sShader->mShaderLevel > 0) { gPipeline.enableLightsDynamic(); - renderFullShader(); + + if (sDetailMode > 0) + { + renderFullShader(); + } + else + { + renderSimple(); + } } else { @@ -312,16 +335,15 @@ void LLDrawPoolTerrain::renderFullShader() gGL.getTexUnit(detail0)->bind(detail_texture0p); gGL.getTexUnit(0)->activate(); - glEnable(GL_TEXTURE_GEN_S); - 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); + LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr; + llassert(shader); + + shader->uniform4fv("object_plane_s", 1, tp0.mV); + shader->uniform4fv("object_plane_t", 1, tp1.mV); - glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV); - glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV); - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); + gGL.matrixMode(LLRender::MM_TEXTURE); + gGL.loadIdentity(); + gGL.matrixMode(LLRender::MM_MODELVIEW); // // detail texture 1 @@ -331,9 +353,9 @@ void LLDrawPoolTerrain::renderFullShader() /// ALPHA TEXTURE COORDS 0: gGL.getTexUnit(1)->activate(); - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); + gGL.matrixMode(LLRender::MM_TEXTURE); + gGL.loadIdentity(); + gGL.matrixMode(LLRender::MM_MODELVIEW); // detail texture 2 // @@ -343,10 +365,10 @@ void LLDrawPoolTerrain::renderFullShader() gGL.getTexUnit(2)->activate(); /// ALPHA TEXTURE COORDS 1: - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - glTranslatef(-2.f, 0.f, 0.f); - glMatrixMode(GL_MODELVIEW); + gGL.matrixMode(LLRender::MM_TEXTURE); + gGL.loadIdentity(); + gGL.translatef(-2.f, 0.f, 0.f); + gGL.matrixMode(LLRender::MM_MODELVIEW); // // detail texture 3 @@ -356,10 +378,10 @@ void LLDrawPoolTerrain::renderFullShader() /// ALPHA TEXTURE COORDS 2: gGL.getTexUnit(3)->activate(); - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - glTranslatef(-1.f, 0.f, 0.f); - glMatrixMode(GL_MODELVIEW); + gGL.matrixMode(LLRender::MM_TEXTURE); + gGL.loadIdentity(); + gGL.translatef(-1.f, 0.f, 0.f); + gGL.matrixMode(LLRender::MM_MODELVIEW); // // Alpha Ramp @@ -380,38 +402,30 @@ void LLDrawPoolTerrain::renderFullShader() gGL.getTexUnit(alpha_ramp)->unbind(LLTexUnit::TT_TEXTURE); gGL.getTexUnit(4)->disable(); gGL.getTexUnit(4)->activate(); - glDisable(GL_TEXTURE_GEN_S); - glDisable(GL_TEXTURE_GEN_T); - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); - + gGL.getTexUnit(detail3)->unbind(LLTexUnit::TT_TEXTURE); gGL.getTexUnit(3)->disable(); gGL.getTexUnit(3)->activate(); - glDisable(GL_TEXTURE_GEN_S); - glDisable(GL_TEXTURE_GEN_T); - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); + + gGL.matrixMode(LLRender::MM_TEXTURE); + gGL.loadIdentity(); + gGL.matrixMode(LLRender::MM_MODELVIEW); gGL.getTexUnit(detail2)->unbind(LLTexUnit::TT_TEXTURE); gGL.getTexUnit(2)->disable(); gGL.getTexUnit(2)->activate(); - glDisable(GL_TEXTURE_GEN_S); - glDisable(GL_TEXTURE_GEN_T); - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); + + gGL.matrixMode(LLRender::MM_TEXTURE); + gGL.loadIdentity(); + gGL.matrixMode(LLRender::MM_MODELVIEW); gGL.getTexUnit(detail1)->unbind(LLTexUnit::TT_TEXTURE); gGL.getTexUnit(1)->disable(); gGL.getTexUnit(1)->activate(); - glDisable(GL_TEXTURE_GEN_S); - glDisable(GL_TEXTURE_GEN_T); - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); + + gGL.matrixMode(LLRender::MM_TEXTURE); + gGL.loadIdentity(); + gGL.matrixMode(LLRender::MM_MODELVIEW); //---------------------------------------------------------------------------- // Restore Texture Unit 0 defaults @@ -419,11 +433,9 @@ void LLDrawPoolTerrain::renderFullShader() gGL.getTexUnit(detail0)->unbind(LLTexUnit::TT_TEXTURE); gGL.getTexUnit(0)->enable(LLTexUnit::TT_TEXTURE); gGL.getTexUnit(0)->activate(); - glDisable(GL_TEXTURE_GEN_S); - glDisable(GL_TEXTURE_GEN_T); - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); + gGL.matrixMode(LLRender::MM_TEXTURE); + gGL.loadIdentity(); + gGL.matrixMode(LLRender::MM_MODELVIEW); } void LLDrawPoolTerrain::renderFull4TU() @@ -534,9 +546,9 @@ void LLDrawPoolTerrain::renderFull4TU() gGL.getTexUnit(1)->activate(); // Set the texture matrix - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - glTranslatef(-2.f, 0.f, 0.f); + gGL.matrixMode(LLRender::MM_TEXTURE); + gGL.loadIdentity(); + gGL.translatef(-2.f, 0.f, 0.f); // Care about alpha only gGL.getTexUnit(1)->setTextureColorBlend(LLTexUnit::TBO_REPLACE, LLTexUnit::TBS_PREV_COLOR); @@ -566,9 +578,9 @@ void LLDrawPoolTerrain::renderFull4TU() gGL.getTexUnit(3)->activate(); // Set the texture matrix - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - glTranslatef(-1.f, 0.f, 0.f); + gGL.matrixMode(LLRender::MM_TEXTURE); + gGL.loadIdentity(); + gGL.translatef(-1.f, 0.f, 0.f); // Set alpha texture and do lighting modulation gGL.getTexUnit(3)->setTextureColorBlend(LLTexUnit::TBO_MULT, LLTexUnit::TBS_PREV_COLOR, LLTexUnit::TBS_VERT_COLOR); @@ -586,9 +598,9 @@ void LLDrawPoolTerrain::renderFull4TU() gGL.getTexUnit(3)->disable(); gGL.getTexUnit(3)->activate(); - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); + gGL.matrixMode(LLRender::MM_TEXTURE); + gGL.loadIdentity(); + gGL.matrixMode(LLRender::MM_MODELVIEW); gGL.getTexUnit(2)->unbind(LLTexUnit::TT_TEXTURE); gGL.getTexUnit(2)->disable(); @@ -596,17 +608,17 @@ void LLDrawPoolTerrain::renderFull4TU() glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); + gGL.matrixMode(LLRender::MM_TEXTURE); + gGL.loadIdentity(); + gGL.matrixMode(LLRender::MM_MODELVIEW); gGL.getTexUnit(1)->unbind(LLTexUnit::TT_TEXTURE); gGL.getTexUnit(1)->disable(); gGL.getTexUnit(1)->activate(); - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); + gGL.matrixMode(LLRender::MM_TEXTURE); + gGL.loadIdentity(); + gGL.matrixMode(LLRender::MM_MODELVIEW); // Restore blend state gGL.setSceneBlendType(LLRender::BT_ALPHA); @@ -620,9 +632,9 @@ void LLDrawPoolTerrain::renderFull4TU() glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); + gGL.matrixMode(LLRender::MM_TEXTURE); + gGL.loadIdentity(); + gGL.matrixMode(LLRender::MM_MODELVIEW); gGL.getTexUnit(0)->setTextureBlendType(LLTexUnit::TB_MULT); } @@ -714,9 +726,9 @@ void LLDrawPoolTerrain::renderFull2TU() gGL.getTexUnit(0)->bind(m2DAlphaRampImagep); // Set the texture matrix - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - glTranslatef(-1.f, 0.f, 0.f); + gGL.matrixMode(LLRender::MM_TEXTURE); + gGL.loadIdentity(); + gGL.translatef(-1.f, 0.f, 0.f); // Care about alpha only gGL.getTexUnit(0)->setTextureColorBlend(LLTexUnit::TBO_REPLACE, LLTexUnit::TBS_PREV_COLOR); @@ -753,9 +765,9 @@ void LLDrawPoolTerrain::renderFull2TU() gGL.getTexUnit(0)->activate(); gGL.getTexUnit(0)->bind(m2DAlphaRampImagep); // Set the texture matrix - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - glTranslatef(-2.f, 0.f, 0.f); + gGL.matrixMode(LLRender::MM_TEXTURE); + gGL.loadIdentity(); + gGL.translatef(-2.f, 0.f, 0.f); // Care about alpha only gGL.getTexUnit(0)->setTextureColorBlend(LLTexUnit::TBO_REPLACE, LLTexUnit::TBS_PREV_COLOR); @@ -793,9 +805,9 @@ void LLDrawPoolTerrain::renderFull2TU() glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); + gGL.matrixMode(LLRender::MM_TEXTURE); + gGL.loadIdentity(); + gGL.matrixMode(LLRender::MM_MODELVIEW); //---------------------------------------------------------------------------- // Restore Texture Unit 0 defaults @@ -805,9 +817,9 @@ void LLDrawPoolTerrain::renderFull2TU() glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); + gGL.matrixMode(LLRender::MM_TEXTURE); + gGL.loadIdentity(); + gGL.matrixMode(LLRender::MM_MODELVIEW); gGL.getTexUnit(0)->setTextureBlendType(LLTexUnit::TB_MULT); } @@ -831,13 +843,21 @@ void LLDrawPoolTerrain::renderSimple() tp0.setVec(tscale, 0.f, 0.0f, -1.f*(origin_agent.mV[0]/256.f)); tp1.setVec(0.f, tscale, 0.0f, -1.f*(origin_agent.mV[1]/256.f)); - glEnable(GL_TEXTURE_GEN_S); - 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); - + if (LLGLSLShader::sNoFixedFunction) + { + sShader->uniform4fv("object_plane_s", 1, tp0.mV); + sShader->uniform4fv("object_plane_t", 1, tp1.mV); + } + else + { + glEnable(GL_TEXTURE_GEN_S); + 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); + } + gGL.getTexUnit(0)->setTextureColorBlend(LLTexUnit::TBO_MULT, LLTexUnit::TBS_TEX_COLOR, LLTexUnit::TBS_VERT_COLOR); drawLoop(); @@ -847,11 +867,14 @@ void LLDrawPoolTerrain::renderSimple() gGL.getTexUnit(0)->activate(); gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); - glDisable(GL_TEXTURE_GEN_S); - glDisable(GL_TEXTURE_GEN_T); - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); + if (!LLGLSLShader::sNoFixedFunction) + { + glDisable(GL_TEXTURE_GEN_S); + glDisable(GL_TEXTURE_GEN_T); + } + gGL.matrixMode(LLRender::MM_TEXTURE); + gGL.loadIdentity(); + gGL.matrixMode(LLRender::MM_MODELVIEW); gGL.getTexUnit(0)->setTextureBlendType(LLTexUnit::TB_MULT); } @@ -882,11 +905,11 @@ void LLDrawPoolTerrain::renderOwnership() // texture coordinates for pixel 256x256 is not 1,1. This makes the // ownership map not line up with the selection. We address this with // a texture matrix multiply. - glMatrixMode(GL_TEXTURE); - glPushMatrix(); + gGL.matrixMode(LLRender::MM_TEXTURE); + gGL.pushMatrix(); const F32 TEXTURE_FUDGE = 257.f / 256.f; - glScalef( TEXTURE_FUDGE, TEXTURE_FUDGE, 1.f ); + gGL.scalef( TEXTURE_FUDGE, TEXTURE_FUDGE, 1.f ); for (std::vector<LLFace*>::iterator iter = mDrawFace.begin(); iter != mDrawFace.end(); iter++) { @@ -895,9 +918,9 @@ void LLDrawPoolTerrain::renderOwnership() LLVertexBuffer::MAP_TEXCOORD0); } - glMatrixMode(GL_TEXTURE); - glPopMatrix(); - glMatrixMode(GL_MODELVIEW); + gGL.matrixMode(LLRender::MM_TEXTURE); + gGL.popMatrix(); + gGL.matrixMode(LLRender::MM_MODELVIEW); } |