From 8990b521fda9f097f18d3a54836d6c583fa0f23f Mon Sep 17 00:00:00 2001 From: kaetemi Date: Tue, 2 Jul 2013 00:53:45 +0200 Subject: [PATCH] Fix a render target issue, see #43 --- code/nel/include/nel/3d/driver.h | 2 ++ code/nel/src/3d/driver/direct3d/driver_direct3d.h | 1 + .../3d/driver/direct3d/driver_direct3d_texture.cpp | 5 +++++ code/nel/src/3d/driver/opengl/driver_opengl.cpp | 2 -- code/nel/src/3d/driver/opengl/driver_opengl.h | 4 +++- .../src/3d/driver/opengl/driver_opengl_texture.cpp | 11 ++++++++--- code/nel/src/3d/shadow_map_manager.cpp | 5 +++-- 7 files changed, 22 insertions(+), 8 deletions(-) diff --git a/code/nel/include/nel/3d/driver.h b/code/nel/include/nel/3d/driver.h index 14595e05c..655a9e62b 100644 --- a/code/nel/include/nel/3d/driver.h +++ b/code/nel/include/nel/3d/driver.h @@ -859,6 +859,8 @@ public: uint32 cubeFace = 0 ) = 0 ; + virtual ITexture *getRenderTarget() const = 0; + /** Trick method : copy the current texture target into another texture without updating the current texture. * * This method copies the current texture into another texture. diff --git a/code/nel/src/3d/driver/direct3d/driver_direct3d.h b/code/nel/src/3d/driver/direct3d/driver_direct3d.h index 779a62a5c..085bb7512 100644 --- a/code/nel/src/3d/driver/direct3d/driver_direct3d.h +++ b/code/nel/src/3d/driver/direct3d/driver_direct3d.h @@ -855,6 +855,7 @@ public: // todo hulud d3d buffers virtual void getZBufferPart (std::vector &zbuffer, NLMISC::CRect &rect); virtual bool setRenderTarget (ITexture *tex, uint32 x, uint32 y, uint32 width, uint32 height, uint32 mipmapLevel, uint32 cubeFace); + virtual ITexture *getRenderTarget() const; virtual bool copyTargetToTexture (ITexture *tex, uint32 offsetx, uint32 offsety, uint32 x, uint32 y, uint32 width, uint32 height, uint32 mipmapLevel); virtual bool getRenderTargetSize (uint32 &width, uint32 &height); diff --git a/code/nel/src/3d/driver/direct3d/driver_direct3d_texture.cpp b/code/nel/src/3d/driver/direct3d/driver_direct3d_texture.cpp index 7922b30ea..87f41678b 100644 --- a/code/nel/src/3d/driver/direct3d/driver_direct3d_texture.cpp +++ b/code/nel/src/3d/driver/direct3d/driver_direct3d_texture.cpp @@ -1187,6 +1187,11 @@ bool CDriverD3D::setRenderTarget (ITexture *tex, uint32 /* x */, uint32 /* y */, return true; } +ITexture *CDriverD3D::getRenderTarget() const +{ + return _RenderTarget.Texture; +} + // *************************************************************************** bool CDriverD3D::copyTargetToTexture (ITexture * /* tex */, uint32 /* offsetx */, uint32 /* offsety */, uint32 /* x */, uint32 /* y */, uint32 /* width */, diff --git a/code/nel/src/3d/driver/opengl/driver_opengl.cpp b/code/nel/src/3d/driver/opengl/driver_opengl.cpp index 42d8b4834..32244edbe 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl.cpp +++ b/code/nel/src/3d/driver/opengl/driver_opengl.cpp @@ -263,8 +263,6 @@ CDriverGL::CDriverGL() _CurrentFogColor[2]= 0; _CurrentFogColor[3]= 0; - _RenderTargetFBO = false; - _LightSetupDirty= false; _ModelViewMatrixDirty= false; _RenderSetupDirty= false; diff --git a/code/nel/src/3d/driver/opengl/driver_opengl.h b/code/nel/src/3d/driver/opengl/driver_opengl.h index f88936a8a..3f0675276 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl.h +++ b/code/nel/src/3d/driver/opengl/driver_opengl.h @@ -564,6 +564,8 @@ public: virtual bool setRenderTarget (ITexture *tex, uint32 x, uint32 y, uint32 width, uint32 height, uint32 mipmapLevel, uint32 cubeFace); + virtual ITexture *getRenderTarget() const; + virtual bool copyTargetToTexture (ITexture *tex, uint32 offsetx, uint32 offsety, uint32 x, uint32 y, uint32 width, uint32 height, uint32 mipmapLevel); @@ -889,7 +891,7 @@ private: // viewport before call to setRenderTarget, if BFO extension is supported CViewport _OldViewport; - bool _RenderTargetFBO; + CSmartPtr _RenderTargetFBO; // Num lights return by GL_MAX_LIGHTS diff --git a/code/nel/src/3d/driver/opengl/driver_opengl_texture.cpp b/code/nel/src/3d/driver/opengl/driver_opengl_texture.cpp index 77954a8e3..7ded32b27 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl_texture.cpp +++ b/code/nel/src/3d/driver/opengl/driver_opengl_texture.cpp @@ -2314,7 +2314,7 @@ bool CDriverGL::setRenderTarget (ITexture *tex, uint32 x, uint32 y, uint32 width newVP.init(0, 0, ((float)width/(float)w), ((float)height/(float)h)); setupViewport(newVP); - _RenderTargetFBO = true; + _RenderTargetFBO = tex; return activeFrameBufferObject(tex); } @@ -2334,7 +2334,7 @@ bool CDriverGL::setRenderTarget (ITexture *tex, uint32 x, uint32 y, uint32 width setupViewport(_OldViewport); _OldViewport = _CurrViewport; - _RenderTargetFBO = false; + _RenderTargetFBO = NULL; return false; } @@ -2347,12 +2347,17 @@ bool CDriverGL::setRenderTarget (ITexture *tex, uint32 x, uint32 y, uint32 width // Update the scissor setupScissor (_CurrScissor); - _RenderTargetFBO = false; + _RenderTargetFBO = NULL; _OldViewport = _CurrViewport; return true; } +ITexture *CDriverGL::getRenderTarget() const +{ + return _RenderTargetFBO ? _RenderTargetFBO : _TextureTarget; +} + // *************************************************************************** bool CDriverGL::copyTargetToTexture (ITexture *tex, diff --git a/code/nel/src/3d/shadow_map_manager.cpp b/code/nel/src/3d/shadow_map_manager.cpp index 79f4ade20..383a28184 100644 --- a/code/nel/src/3d/shadow_map_manager.cpp +++ b/code/nel/src/3d/shadow_map_manager.cpp @@ -244,11 +244,12 @@ void CShadowMapManager::addShadowReceiver(CTransform *model) void CShadowMapManager::renderGenerate(CScene *scene) { H_AUTO( NL3D_ShadowManager_Generate ); - + // Each frame, do a small garbage collector for unused free textures. garbageShadowTextures(scene); IDriver *driverForShadowGeneration= scene->getRenderTrav().getAuxDriver(); + CSmartPtr previousRenderTarget = driverForShadowGeneration->getRenderTarget(); // Init // ******** @@ -488,7 +489,7 @@ void CShadowMapManager::renderGenerate(CScene *scene) } // Set default render target - driverForShadowGeneration->setRenderTarget (NULL); + driverForShadowGeneration->setRenderTarget (previousRenderTarget); // Allow Writing on all. driverForShadowGeneration->setColorMask(true, true, true, true);