From c0b2e6536bee08511c4180b437c375180cc8e2c6 Mon Sep 17 00:00:00 2001 From: LuisAntonRebollo Date: Sat, 8 Nov 2014 02:02:30 +0100 Subject: [PATCH] Reduce innecesary changes on Render Target textures. --- .../shadowMap/dualParaboloidLightShadowMap.cpp | 4 ++-- Engine/source/lighting/shadowMap/lightShadowMap.h | 1 + .../lighting/shadowMap/pssmLightShadowMap.cpp | 6 ++++-- .../source/renderInstance/renderFormatChanger.cpp | 15 +++++++++++++-- .../renderInstance/renderTexTargetBinManager.cpp | 5 +++++ Engine/source/scene/reflector.cpp | 5 +++-- Engine/source/scene/reflector.h | 2 +- 7 files changed, 29 insertions(+), 9 deletions(-) diff --git a/Engine/source/lighting/shadowMap/dualParaboloidLightShadowMap.cpp b/Engine/source/lighting/shadowMap/dualParaboloidLightShadowMap.cpp index 39072b0f4..6f4685006 100644 --- a/Engine/source/lighting/shadowMap/dualParaboloidLightShadowMap.cpp +++ b/Engine/source/lighting/shadowMap/dualParaboloidLightShadowMap.cpp @@ -59,6 +59,7 @@ void DualParaboloidLightShadowMap::_render( RenderPassManager* renderPass, mShadowMapTex.set( mTexSize * 2, mTexSize, ShadowMapFormat, &ShadowMapProfile, "DualParaboloidLightShadowMap" ); + mShadowMapDepth = _getDepthTarget( mShadowMapTex->getWidth(), mShadowMapTex->getHeight() ); } GFXFrustumSaver frustSaver; @@ -68,8 +69,7 @@ void DualParaboloidLightShadowMap::_render( RenderPassManager* renderPass, GFX->pushActiveRenderTarget(); mTarget->attachTexture(GFXTextureTarget::Color0, mShadowMapTex); - mTarget->attachTexture( GFXTextureTarget::DepthStencil, - _getDepthTarget( mShadowMapTex->getWidth(), mShadowMapTex->getHeight() ) ); + mTarget->attachTexture( GFXTextureTarget::DepthStencil, mShadowMapDepth ); GFX->setActiveRenderTarget(mTarget); GFX->clear(GFXClearTarget | GFXClearStencil | GFXClearZBuffer, ColorI::WHITE, 1.0f, 0); diff --git a/Engine/source/lighting/shadowMap/lightShadowMap.h b/Engine/source/lighting/shadowMap/lightShadowMap.h index 94746d806..af45b32fe 100644 --- a/Engine/source/lighting/shadowMap/lightShadowMap.h +++ b/Engine/source/lighting/shadowMap/lightShadowMap.h @@ -259,6 +259,7 @@ protected: GFXTextureTargetRef mTarget; U32 mTexSize; GFXTexHandle mShadowMapTex; + GFXTexHandle mShadowMapDepth; // The light we are rendering. LightInfo *mLight; diff --git a/Engine/source/lighting/shadowMap/pssmLightShadowMap.cpp b/Engine/source/lighting/shadowMap/pssmLightShadowMap.cpp index 71a4fe585..257112686 100644 --- a/Engine/source/lighting/shadowMap/pssmLightShadowMap.cpp +++ b/Engine/source/lighting/shadowMap/pssmLightShadowMap.cpp @@ -204,7 +204,10 @@ void PSSMLightShadowMap::_render( RenderPassManager* renderPass, if ( mShadowMapTex.isNull() || mNumSplits != params->numSplits || mTexSize != texSize ) + { _setNumSplits( params->numSplits, texSize ); + mShadowMapDepth = _getDepthTarget( mShadowMapTex->getWidth(), mShadowMapTex->getHeight() ); + } mLogWeight = params->logWeight; Frustum fullFrustum( diffuseState->getCameraFrustum() ); @@ -216,8 +219,7 @@ void PSSMLightShadowMap::_render( RenderPassManager* renderPass, // Set our render target GFX->pushActiveRenderTarget(); mTarget->attachTexture( GFXTextureTarget::Color0, mShadowMapTex ); - mTarget->attachTexture( GFXTextureTarget::DepthStencil, - _getDepthTarget( mShadowMapTex->getWidth(), mShadowMapTex->getHeight() ) ); + mTarget->attachTexture( GFXTextureTarget::DepthStencil, mShadowMapDepth ); GFX->setActiveRenderTarget( mTarget ); GFX->clear( GFXClearStencil | GFXClearZBuffer | GFXClearTarget, ColorI(255,255,255), 1.0f, 0 ); diff --git a/Engine/source/renderInstance/renderFormatChanger.cpp b/Engine/source/renderInstance/renderFormatChanger.cpp index c9042c766..a4568c877 100644 --- a/Engine/source/renderInstance/renderFormatChanger.cpp +++ b/Engine/source/renderInstance/renderFormatChanger.cpp @@ -218,24 +218,35 @@ void RenderFormatToken::_updateTargets() // Update color target if(mColorFormat != GFXFormat_COUNT) { + // try reuse of old color texture + if( !mTargetColorTexture[i] || mTargetColorTexture[i].getFormat() != mColorFormat + || mTargetColorTexture[i].getWidthHeight() != rtSize) + { mTargetColorTexture[i].set( rtSize.x, rtSize.y, mColorFormat, &GFXDefaultRenderTargetProfile, avar( "%s() - (line %d)", __FUNCTION__, __LINE__ ), 1, mTargetAALevel ); mTargetChain[i]->attachTexture( GFXTextureTarget::Color0, mTargetColorTexture[i] ); } + } + - mTargetChain[i]->attachTexture( GFXTextureTarget::Color0, mTargetColorTexture[i] ); // Update depth target if(mDepthFormat != GFXFormat_COUNT) { + // try reuse of old depth texture + if( !mTargetDepthStencilTexture[i] || mTargetDepthStencilTexture[i].getFormat() != mColorFormat + || mTargetDepthStencilTexture[i].getWidthHeight() != rtSize) + { mTargetDepthStencilTexture[i].set( rtSize.x, rtSize.y, mDepthFormat, &GFXDefaultZTargetProfile, avar( "%s() - (line %d)", __FUNCTION__, __LINE__ ), 1, mTargetAALevel ); + mTargetChain[i]->attachTexture( GFXTextureTarget::DepthStencil, mTargetDepthStencilTexture[i] ); + } } - mTargetChain[i]->attachTexture( GFXTextureTarget::DepthStencil, mTargetDepthStencilTexture[i] ); + } } diff --git a/Engine/source/renderInstance/renderTexTargetBinManager.cpp b/Engine/source/renderInstance/renderTexTargetBinManager.cpp index 6dab6256a..c26231152 100644 --- a/Engine/source/renderInstance/renderTexTargetBinManager.cpp +++ b/Engine/source/renderInstance/renderTexTargetBinManager.cpp @@ -166,11 +166,16 @@ bool RenderTexTargetBinManager::_updateTargets() for( U32 j = 0; j < mNumRenderTargets; j++ ) { + // try reuse of old color texture + if( mTargetChainTextures[i][j].getWidthHeight() != mTargetSize + || mTargetChainTextures[i][j].getFormat() != mTargetFormat) + { ret &= mTargetChainTextures[i][j].set( mTargetSize.x, mTargetSize.y, mTargetFormat, &GFXDefaultRenderTargetProfile, avar( "%s() - (line %d)", __FUNCTION__, __LINE__ ), 1, GFXTextureManager::AA_MATCH_BACKBUFFER ); mTargetChain[i]->attachTexture( GFXTextureTarget::RenderSlot(GFXTextureTarget::Color0 + j), mTargetChainTextures[i][j] ); + } } } diff --git a/Engine/source/scene/reflector.cpp b/Engine/source/scene/reflector.cpp index f224a913a..ab53c2bdd 100644 --- a/Engine/source/scene/reflector.cpp +++ b/Engine/source/scene/reflector.cpp @@ -539,9 +539,10 @@ void PlaneReflector::updateReflection( const ReflectParams ¶ms ) if ( texResize || reflectTex.isNull() || reflectTex->getFormat() != REFLECTMGR->getReflectFormat() ) + { reflectTex = REFLECTMGR->allocRenderTarget( texSize ); - - GFXTexHandle depthBuff = LightShadowMap::_getDepthTarget( texSize.x, texSize.y ); + depthBuff = LightShadowMap::_getDepthTarget( texSize.x, texSize.y ); + } // store current matrices GFXTransformSaver saver; diff --git a/Engine/source/scene/reflector.h b/Engine/source/scene/reflector.h index bc5dca698..671c88f9b 100644 --- a/Engine/source/scene/reflector.h +++ b/Engine/source/scene/reflector.h @@ -224,7 +224,7 @@ protected: public: GFXTextureTargetRef reflectTarget; - GFXTexHandle reflectTex; + GFXTexHandle reflectTex, depthBuff;; PlaneF refplane; bool objectSpace; };