Fix uninitialized data in render buffers at creation

This commit is contained in:
Magnus Norddahl 2016-08-13 18:25:25 +02:00 committed by Christoph Oelckers
parent 847d2e8862
commit af62352860
2 changed files with 28 additions and 0 deletions

View file

@ -336,6 +336,7 @@ GLuint FGLRenderBuffers::CreateFrameBuffer(GLuint colorbuffer)
glBindFramebuffer(GL_FRAMEBUFFER, handle);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorbuffer, 0);
CheckFrameBufferCompleteness();
ClearFrameBuffer();
return handle;
}
@ -350,6 +351,7 @@ GLuint FGLRenderBuffers::CreateFrameBuffer(GLuint colorbuffer, GLuint depthstenc
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorbuffer, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, depthstencil);
CheckFrameBufferCompleteness();
ClearFrameBuffer();
return handle;
}
@ -365,6 +367,7 @@ GLuint FGLRenderBuffers::CreateFrameBuffer(GLuint colorbuffer, GLuint depth, GLu
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, stencil);
CheckFrameBufferCompleteness();
ClearFrameBuffer();
return handle;
}
@ -396,6 +399,30 @@ void FGLRenderBuffers::CheckFrameBufferCompleteness()
I_FatalError(error);
}
//==========================================================================
//
// Clear frame buffer to make sure it never contains uninitialized data
//
//==========================================================================
void FGLRenderBuffers::ClearFrameBuffer()
{
GLint scissorEnabled, stencilValue;
GLdouble depthValue;
glGetIntegerv(GL_SCISSOR_TEST, &scissorEnabled);
glGetIntegerv(GL_STENCIL_CLEAR_VALUE, &stencilValue);
glGetDoublev(GL_DEPTH_CLEAR_VALUE, &depthValue);
glDisable(GL_SCISSOR_TEST);
glClearColor(0.0, 0.0, 0.0, 0.0);
glClearDepth(0.0);
glClearStencil(0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glClearStencil(stencilValue);
glClearDepth(depthValue);
if (scissorEnabled)
glEnable(GL_SCISSOR_TEST);
}
//==========================================================================
//
// Resolves the multisample frame buffer by copying it to the scene texture

View file

@ -54,6 +54,7 @@ private:
GLuint CreateFrameBuffer(GLuint colorbuffer, GLuint depthstencil, bool colorIsARenderBuffer);
GLuint CreateFrameBuffer(GLuint colorbuffer, GLuint depth, GLuint stencil, bool colorIsARenderBuffer);
void CheckFrameBufferCompleteness();
void ClearFrameBuffer();
void DeleteTexture(GLuint &handle);
void DeleteRenderBuffer(GLuint &handle);
void DeleteFrameBuffer(GLuint &handle);