From cd9baf8f89391b0e0d2054b47fc1f2b004eeda28 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Fri, 13 Sep 2013 23:02:35 +0200 Subject: [PATCH] Cleanup --HG-- branch : multipass-stereo --- code/nel/src/3d/bloom_effect.cpp | 13 ++++++++----- code/nel/src/3d/water_env_map.cpp | 13 +++++++++---- code/ryzom/client/src/decal.cpp | 25 +++++++++++++++---------- 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/code/nel/src/3d/bloom_effect.cpp b/code/nel/src/3d/bloom_effect.cpp index 25439ee46..7809aba2c 100644 --- a/code/nel/src/3d/bloom_effect.cpp +++ b/code/nel/src/3d/bloom_effect.cpp @@ -55,15 +55,18 @@ static const char *TextureOffset = END \n"; -static CVertexProgram TextureOffsetVertexProgram(TextureOffset); - -// TODO_VP_GLSL +static NLMISC::CSmartPtr TextureOffsetVertexProgram; //----------------------------------------------------------------------------------------------------------- CBloomEffect::CBloomEffect() { + if (!TextureOffsetVertexProgram) + { + TextureOffsetVertexProgram = new CVertexProgram(TextureOffset); + } + _Driver = NULL; _Scene = NULL; _SquareBloom = true; @@ -445,7 +448,7 @@ void CBloomEffect::applyBlur() } // initialize vertex program - drvInternal->activeVertexProgram(&TextureOffsetVertexProgram); + drvInternal->activeVertexProgram(TextureOffsetVertexProgram); drvInternal->setUniform4f(IDriver::VertexProgram, 8, 255.f, 255.f, 255.f, 255.f); drvInternal->setUniform4f(IDriver::VertexProgram, 9, 0.0f, 0.f, 0.f, 1.f); @@ -551,7 +554,7 @@ void CBloomEffect::doBlur(bool horizontalBlur) } // initialize vertex program - drvInternal->activeVertexProgram(&TextureOffsetVertexProgram); + drvInternal->activeVertexProgram(TextureOffsetVertexProgram); drvInternal->setUniform4f(IDriver::VertexProgram, 8, 255.f, 255.f, 255.f, 255.f); drvInternal->setUniform4f(IDriver::VertexProgram, 9, 0.0f, 0.f, 0.f, 1.f); diff --git a/code/nel/src/3d/water_env_map.cpp b/code/nel/src/3d/water_env_map.cpp index e75fd172a..6bc6beda5 100644 --- a/code/nel/src/3d/water_env_map.cpp +++ b/code/nel/src/3d/water_env_map.cpp @@ -274,13 +274,18 @@ private: }; -static CVertexProgramTestMeshVP testMeshVP; +static NLMISC::CSmartPtr testMeshVP; // ******************************************************************************* void CWaterEnvMap::renderTestMesh(IDriver &driver) { + if (!testMeshVP) + { + testMeshVP = new CVertexProgramTestMeshVP(); + } + doInit(); CMaterial testMat; testMat.setLighting(false); @@ -294,12 +299,12 @@ void CWaterEnvMap::renderTestMesh(IDriver &driver) testMat.setZWrite(false); testMat.setZFunc(CMaterial::always); // tmp : test cubemap - driver.activeVertexProgram(&testMeshVP); + driver.activeVertexProgram(testMeshVP); driver.activeVertexBuffer(_TestVB); driver.activeIndexBuffer(_TestIB); _MaterialPassThruZTest.setTexture(0, _EnvCubic); - driver.setUniformMatrix(IDriver::VertexProgram, testMeshVP.getUniformIndex(CGPUProgramIndex::ModelViewProjection), IDriver::ModelViewProjection, IDriver::Identity); - driver.setUniform2f(IDriver::VertexProgram, testMeshVP.idx().ProgramConstant0, 2.f, 1.f); + driver.setUniformMatrix(IDriver::VertexProgram, testMeshVP->getUniformIndex(CGPUProgramIndex::ModelViewProjection), IDriver::ModelViewProjection, IDriver::Identity); + driver.setUniform2f(IDriver::VertexProgram, testMeshVP->idx().ProgramConstant0, 2.f, 1.f); //driver.renderTriangles(testMat, 0, TEST_VB_NUM_TRIS); driver.renderTriangles(_MaterialPassThruZTest, 0, TEST_VB_NUM_TRIS); driver.activeVertexProgram(NULL); diff --git a/code/ryzom/client/src/decal.cpp b/code/ryzom/client/src/decal.cpp index a1cca247d..073c1ef0d 100644 --- a/code/ryzom/client/src/decal.cpp +++ b/code/ryzom/client/src/decal.cpp @@ -142,7 +142,7 @@ private: CIdx m_Idx; }; -static CVertexProgramDecalAttenuation DecalAttenuationVertexProgram; +static NLMISC::CSmartPtr DecalAttenuationVertexProgram; typedef CShadowPolyReceiver::CRGBAVertex CRGBAVertex; @@ -150,6 +150,10 @@ typedef CShadowPolyReceiver::CRGBAVertex CRGBAVertex; // **************************************************************************** CDecal::CDecal() { + if (!DecalAttenuationVertexProgram) + { + DecalAttenuationVertexProgram = new CVertexProgramDecalAttenuation(); + } _ShadowMap = new CShadowMap(&(((CSceneUser *) Scene)->getScene().getRenderTrav().getShadowMapManager())); _Material.initUnlit(); _Diffuse = CRGBA::White; @@ -361,6 +365,7 @@ void CDecal::renderTriCache(NL3D::IDriver &drv, NL3D::CShadowPolyReceiver &/* drv.setupModelMatrix(modelMat); if (useVertexProgram) { + CVertexProgramDecalAttenuation *program = DecalAttenuationVertexProgram; { CVertexBufferReadWrite vba; _VB.setNumVertices((uint32)_TriCache.size()); @@ -368,16 +373,16 @@ void CDecal::renderTriCache(NL3D::IDriver &drv, NL3D::CShadowPolyReceiver &/* memcpy(vba.getVertexCoordPointer(), &_TriCache[0], sizeof(CRGBAVertex) * _TriCache.size()); } drv.activeVertexBuffer(_VB); - drv.setUniformMatrix(IDriver::VertexProgram, DecalAttenuationVertexProgram.getUniformIndex(CGPUProgramIndex::ModelViewProjection), NL3D::IDriver::ModelViewProjection, NL3D::IDriver::Identity); - drv.setUniform4f(IDriver::VertexProgram, DecalAttenuationVertexProgram.idx().WorldToUV0, _WorldToUVMatrix[0][0], _WorldToUVMatrix[1][0], _WorldToUVMatrix[2][0], _WorldToUVMatrix[3][0]); - drv.setUniform4f(IDriver::VertexProgram, DecalAttenuationVertexProgram.idx().WorldToUV1, _WorldToUVMatrix[0][1], _WorldToUVMatrix[1][1], _WorldToUVMatrix[2][1], _WorldToUVMatrix[3][1]); - drv.setUniform4f(IDriver::VertexProgram, DecalAttenuationVertexProgram.idx().Diffuse, _Diffuse.R * (1.f / 255.f), _Diffuse.G * (1.f / 255.f), _Diffuse.B * (1.f / 255.f), 1.f); + drv.setUniformMatrix(IDriver::VertexProgram, program->getUniformIndex(CGPUProgramIndex::ModelViewProjection), NL3D::IDriver::ModelViewProjection, NL3D::IDriver::Identity); + drv.setUniform4f(IDriver::VertexProgram, program->idx().WorldToUV0, _WorldToUVMatrix[0][0], _WorldToUVMatrix[1][0], _WorldToUVMatrix[2][0], _WorldToUVMatrix[3][0]); + drv.setUniform4f(IDriver::VertexProgram, program->idx().WorldToUV1, _WorldToUVMatrix[0][1], _WorldToUVMatrix[1][1], _WorldToUVMatrix[2][1], _WorldToUVMatrix[3][1]); + drv.setUniform4f(IDriver::VertexProgram, program->idx().Diffuse, _Diffuse.R * (1.f / 255.f), _Diffuse.G * (1.f / 255.f), _Diffuse.B * (1.f / 255.f), 1.f); const NLMISC::CVector &camPos = MainCam.getMatrix().getPos(); - drv.setUniform4f(IDriver::VertexProgram, DecalAttenuationVertexProgram.idx().RefCamDist, camPos.x - _RefPosition.x, camPos.y - _RefPosition.y, camPos.z - _RefPosition.z, 1.f); + drv.setUniform4f(IDriver::VertexProgram, program->idx().RefCamDist, camPos.x - _RefPosition.x, camPos.y - _RefPosition.y, camPos.z - _RefPosition.z, 1.f); // bottom & top blend float bottomBlendScale = 1.f / favoid0(_BottomBlendZMax - _BottomBlendZMin); float topBlendScale = 1.f / favoid0(_TopBlendZMin - _TopBlendZMax); - drv.setUniform4f(IDriver::VertexProgram, DecalAttenuationVertexProgram.idx().BlendScale, bottomBlendScale, bottomBlendScale * (_RefPosition.z - _BottomBlendZMin), + drv.setUniform4f(IDriver::VertexProgram, program->idx().BlendScale, bottomBlendScale, bottomBlendScale * (_RefPosition.z - _BottomBlendZMin), topBlendScale, topBlendScale * (_RefPosition.z - _TopBlendZMax)); // static volatile bool wantSimpleMat = false; @@ -618,11 +623,11 @@ void CDecalRenderList::renderAllDecals() NL3D::IDriver *drvInternal = ((CDriverUser *) Driver)->getDriver(); // static volatile bool forceNoVertexProgram = false; - if (!forceNoVertexProgram && drvInternal->compileVertexProgram(&DecalAttenuationVertexProgram)) + if (!forceNoVertexProgram && drvInternal->compileVertexProgram(DecalAttenuationVertexProgram)) { - drvInternal->activeVertexProgram(&DecalAttenuationVertexProgram); + drvInternal->activeVertexProgram(DecalAttenuationVertexProgram); //drvInternal->setCons/tantMatrix(0, NL3D::IDriver::ModelViewProjection, NL3D::IDriver::Identity); - drvInternal->setUniform4f(IDriver::VertexProgram, DecalAttenuationVertexProgram.idx().DistScaleBias, _DistScale, _DistBias, 0.f, 1.f); + drvInternal->setUniform4f(IDriver::VertexProgram, DecalAttenuationVertexProgram->idx().DistScaleBias, _DistScale, _DistBias, 0.f, 1.f); useVertexProgram = true; } else