diff --git a/source/renderer/Renderer.cpp b/source/renderer/Renderer.cpp index b82586ff2a..4d5dd29d08 100644 --- a/source/renderer/Renderer.cpp +++ b/source/renderer/Renderer.cpp @@ -530,8 +530,7 @@ bool CRenderer::Open(int width, int height, int depth) void CRenderer::Resize(int width,int height) { // need to recreate the shadow map object to resize the shadow texture - delete m->shadow; - m->shadow = new ShadowMap; + m->shadow->RecreateTexture(); m_Width = width; m_Height = height; diff --git a/source/renderer/ShadowMap.cpp b/source/renderer/ShadowMap.cpp index aca822c63f..eb1564ede9 100644 --- a/source/renderer/ShadowMap.cpp +++ b/source/renderer/ShadowMap.cpp @@ -96,6 +96,22 @@ ShadowMap::~ShadowMap() delete m; } +/////////////////////////////////////////////////////////////////////////////////////////////////// +// Force the texture/buffer/etc to be recreated, particularly when the renderer's +// size has changed +void ShadowMap::RecreateTexture() +{ + if (m->Texture) + glDeleteTextures(1, &m->Texture); + if (m->Framebuffer) + pglDeleteFramebuffersEXT(1, &m->Framebuffer); + + m->Texture = 0; + m->Framebuffer = 0; + + // (Texture will be constructed in next SetupFrame) +} + ////////////////////////////////////////////////////////////////////////////// // SetupFrame: camera and light direction for this frame void ShadowMap::SetupFrame(const CCamera& camera, const CVector3D& lightdir) @@ -234,7 +250,7 @@ void ShadowMapInternals::CalcShadowMatrices() -/////////////////////////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////// // Create the shadow map void ShadowMapInternals::CreateTexture() { diff --git a/source/renderer/ShadowMap.h b/source/renderer/ShadowMap.h index 7df8a77f6b..f83e1db056 100644 --- a/source/renderer/ShadowMap.h +++ b/source/renderer/ShadowMap.h @@ -35,6 +35,13 @@ public: ShadowMap(); ~ShadowMap(); + /** + * RecreateTexture: Destroy the current shadow texture and force creation of + * a new one. Useful when the renderer's size has changed and the texture + * should be resized too. + */ + void RecreateTexture(); + /** * GetUseDepthTexture: Return whether rendering uses a depth texture (instead of * a luminance texture).