Browse Source

Merge pull request #1928 from lukaspj/particle-manager-lmactivate-cleanup

Cleanup when deactivating light manager instead of reinitializing
Areloch 8 years ago
parent
commit
ac19e0e84c
1 changed files with 37 additions and 29 deletions
  1. 37 29
      Engine/source/renderInstance/renderParticleMgr.cpp

+ 37 - 29
Engine/source/renderInstance/renderParticleMgr.cpp

@@ -589,43 +589,51 @@ bool RenderParticleMgr::_initShader()
 
 void RenderParticleMgr::_onLMActivate( const char*, bool activate )
 {
-   RenderPassManager *rpm = getRenderPass();
-   if ( !rpm )
-      return;
-
-   // Hunt for the pre-pass manager/target
-   RenderPrePassMgr *prePassBin = NULL;
-   for( U32 i = 0; i < rpm->getManagerCount(); i++ )
+   if ( activate )
    {
-      RenderBinManager *bin = rpm->getManager(i);
-      if( bin->getRenderInstType() == RenderPrePassMgr::RIT_PrePass )
+      RenderPassManager *rpm = getRenderPass();
+      if ( !rpm )
+         return;
+
+      // Hunt for the pre-pass manager/target
+      RenderPrePassMgr *prePassBin = NULL;
+      for( U32 i = 0; i < rpm->getManagerCount(); i++ )
       {
-         prePassBin = (RenderPrePassMgr*)bin;
-         break;
+         RenderBinManager *bin = rpm->getManager(i);
+         if( bin->getRenderInstType() == RenderPrePassMgr::RIT_PrePass )
+         {
+            prePassBin = (RenderPrePassMgr*)bin;
+            break;
+         }
       }
-   }
 
-   // If we found the prepass bin, set this bin to render very shortly afterwards
-   // and re-add this render-manager. If there is no pre-pass bin, or it doesn't
-   // have a depth-texture, we can't render offscreen.
-   mOffscreenRenderEnabled = prePassBin && (prePassBin->getTargetChainLength() > 0);
-   if(mOffscreenRenderEnabled)
-   {
-      rpm->removeManager(this);
-      setRenderOrder( prePassBin->getRenderOrder() + 0.011f );
-      rpm->addManager(this);
-   }
+      // If we found the prepass bin, set this bin to render very shortly afterwards
+      // and re-add this render-manager. If there is no pre-pass bin, or it doesn't
+      // have a depth-texture, we can't render offscreen.
+      mOffscreenRenderEnabled = prePassBin && (prePassBin->getTargetChainLength() > 0);
+      if(mOffscreenRenderEnabled)
+      {
+         rpm->removeManager(this);
+         setRenderOrder( prePassBin->getRenderOrder() + 0.011f );
+         rpm->addManager(this);
+      }
 
-   // Find the targets we use
-   mPrepassTarget = NamedTexTarget::find( "prepass" );
-   mEdgeTarget = NamedTexTarget::find( "edge" );
+      // Find the targets we use
+      mPrepassTarget = NamedTexTarget::find( "prepass" );
+      mEdgeTarget = NamedTexTarget::find( "edge" );
 
-   // Setup the shader
-   if ( activate ) 
+      // Setup the shader
       _initShader();
 
-   if ( mScreenQuadVertBuff.isNull() )
-      _initGFXResources();
+      if ( mScreenQuadVertBuff.isNull() )
+         _initGFXResources();
+   } 
+   else
+   {
+      mStencilClearSB = NULL;
+      mScreenQuadPrimBuff = NULL;
+      mScreenQuadVertBuff = NULL;
+   }
 }
 
 GFXStateBlockRef RenderParticleMgr::_getOffscreenStateBlock(ParticleRenderInst *ri)