Clear color buffer bug in OpenGL

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
riveranb
Posts: 28
Joined: Fri Sep 23, 2011 9:37 am

Clear color buffer bug in OpenGL

Post by riveranb »

Hello,

I just found one bug on driver when setRenderTarget or in cases of clearing color buffer,

if last time use drawAll(), the material.ColorMask is locked to ECP_NONE or any specific channel. (ex: via OverrideMaterial),

then next time the behavior for glClear( ...) will be affected. (for ECP_NONE, glClear CANNOT clear the color buffer's R, G, B, A)

So the source code is updated this way to solve this bug:

Code: Select all

 
//! clears the zbuffer and color buffer
void COpenGLDriver::clearBuffers(bool backBuffer, bool zBuffer, bool stencilBuffer, SColor color)
{
    GLbitfield mask = 0;
    if (backBuffer)
    {
        const f32 inv = 1.0f / 255.0f;
        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // <=== fix bug for glClearColor
        LastMaterial.ColorMask = ECP_ALL;
        glClearColor(color.getRed() * inv, color.getGreen() * inv,
                color.getBlue() * inv, color.getAlpha() * inv);
 
        mask |= GL_COLOR_BUFFER_BIT;
    }
 
    if (zBuffer)
    {
        glDepthMask(GL_TRUE);
        LastMaterial.ZWriteEnable=true;
        mask |= GL_DEPTH_BUFFER_BIT;
    }
 
    if (stencilBuffer)
        mask |= GL_STENCIL_BUFFER_BIT;
 
    if (mask)
        glClear(mask);
}
 
I do not know if D3D driver had the same bug,

Someone can try if interesting on this issue.
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Clear color buffer bug in OpenGL

Post by hendu »

Post Reply