Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 10 of 10

Thread: glClearColor with HDR values (>1) on RGBA16F FBO

  1. #1
    Junior Member Regular Contributor
    Join Date
    Sep 2000
    Location
    France
    Posts
    185

    glClearColor with HDR values (>1) on RGBA16F FBO

    Hi,

    I have an FBO with a single color attachment, which is a GL_RGBA16F texture.

    Whevener I call glClearColor with values > 1, I get the good result on NVidia boards, clearing with the HDR values, and a value clamped to 1 on ATI boards.

    I tried to play with glClampColor calls without much success.

    I was wondering which is the good default behaviour ? Is there any specific call to instruct GL to have a proper unclamped clear color ?

    Some quick unit test I wrote with Python & PyOpenGL is below. The second 'glReadPixelsf' returns (1,1,0,1) instead of (1,2,0,1).

    Any help would be greatly appreciated !
    Cheers,

    Code :
        width = 512
        height = 512
     
        glutInit()
        glutInitWindowSize(512, 512)
        glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH)
        win = glutCreateWindow("Test")
     
        texture_id = glGenTextures(1)
     
        glBindTexture(GL_TEXTURE_2D, texture_id)
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, None)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
     
        glBindTexture(GL_TEXTURE_2D, 0)
     
        # bind / create
        fbo = glGenFramebuffersEXT(1)
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, int(fbo))
        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, texture_id, 0)
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0)
     
        # use
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, int(fbo))
        glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT)
        glReadBuffer(GL_COLOR_ATTACHMENT0_EXT)
     
        currentBufferStatus = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)
        if (currentBufferStatus != GL_FRAMEBUFFER_COMPLETE_EXT):
          print "glCheckFramebufferStatusEXT = 0x%x" % currentBufferStatus
        self.assertEquals(currentBufferStatus, GL_FRAMEBUFFER_COMPLETE_EXT)
     
        # test
     
        glClearColor(1.0, 1.0, 0.0, 1.0)
        glClear(GL_COLOR_BUFFER_BIT)
        colors = glReadPixelsf(0, 0, 1, 1, GL_RGBA)
        pixel = _get_pixel(colors)
        self.assertEquals( pixel[0], 1.0 )
        self.assertEquals( pixel[1], 1.0 )
        self.assertEquals( pixel[2], 0.0 )
        self.assertEquals( pixel[3], 1.0 )
     
        glClearColor(1.0, 2.0, 0.0, 1.0)
        glClear(GL_COLOR_BUFFER_BIT)
        colors = glReadPixelsf(0, 0, 1, 1, GL_RGBA)
        pixel = _get_pixel(colors)
        self.assertEquals( pixel[0], 1.0 )
        self.assertEquals( pixel[1], 2.0 )
        self.assertEquals( pixel[2], 0.0 )
        self.assertEquals( pixel[3], 1.0 )
     
        # unbind
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0)
     
        glutDestroyWindow(win)

  2. #2
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948

    Re: glClearColor with HDR values (>1) on RGBA16F FBO

    The specification states that the clear should not be clamped if the buffer is not a normalized format. So ATI's doing something wrong.

    As a workaround, try glClearBuffer. That will directly clear a specific buffer to a specific color.

  3. #3
    Junior Member Regular Contributor
    Join Date
    Sep 2000
    Location
    France
    Posts
    185

    Re: glClearColor with HDR values (>1) on RGBA16F FBO

    Quote Originally Posted by Alfonse Reinheart
    As a workaround, try glClearBuffer. That will directly clear a specific buffer to a specific color.
    Thanks for the suggestion ! Alas, the behaviour is the same using :
    Code :
    glClearBufferfv(GL_COLOR, 0, (1.0, 2.0, 0.0, 1.0))
    The same clamping happens.

  4. #4
    Super Moderator Frequent Contributor Groovounet's Avatar
    Join Date
    Jul 2004
    Posts
    934

    Re: glClearColor with HDR values (>1) on RGBA16F FBO

    AMD has some known issue with glClear* and they are working on it... hope it would be fixed soon!

  5. #5
    Junior Member Regular Contributor
    Join Date
    Mar 2009
    Posts
    152

    Re: glClearColor with HDR values (>1) on RGBA16F FBO

    As a workaround, draw full screen quad and output your desired color in a fragment shader.

  6. #6
    Junior Member Regular Contributor
    Join Date
    Sep 2000
    Location
    France
    Posts
    185

    Re: glClearColor with HDR values (>1) on RGBA16F FBO

    Quote Originally Posted by Groovounet
    AMD has some known issue with glClear* and they are working on it... hope it would be fixed soon!
    Ahf, ok... I'll keep another driver bug unit test under my belt then...

    Quote Originally Posted by randall
    As a workaround, draw full screen quad and output your desired color in a fragment shader.
    It might end like this, I wanted to check to normal road first

    Thanks

  7. #7
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    985

    Re: glClearColor with HDR values (>1) on RGBA16F FBO

    Quote Originally Posted by Groovounet
    AMD has some known issue with glClear* and they are working on it... hope it would be fixed soon!
    AFAIK only the depth+stencil clears are not working but color clears are in fact functioning.
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

  8. #8
    Super Moderator Frequent Contributor Groovounet's Avatar
    Join Date
    Jul 2004
    Posts
    934

    Re: glClearColor with HDR values (>1) on RGBA16F FBO

    There are lot more problems on AMD glClear*
    What I experienced lately is a disfunctional scissor test on glClearBuffer*

  9. #9
    Junior Member Newbie
    Join Date
    Apr 2011
    Location
    tetovo
    Posts
    1

    Re: glClearColor with HDR values (>1) on RGBA16F FBO

    Please someone help me in a homework.

    Assignment One
    due 17/4/2011
    Your job is to create a freehand drawing application that will have the following options:
    1. Be able to draw shapes using the mouse.
    2. The user should be able to increase / decrease brush size using the keyboard (+ and -) keys.
    3. The user should be able to choose from a menu of at least four different colors. The menu should be bound to the right click!

    I have prouble to 1. and 2.

    Please add in this piece of code step 1. and step 2.

    #include <iostream>
    #include <GL\glut.h>

    using namespace std;

    void init()
    {
    glClearColor(1,1,1,0);
    glMatrixMode(GL_PROJECTION);
    gluOrtho2D(0, 640, 0, 480);

    }

    void display()
    {
    glClear(GL_COLOR_BUFFER_BIT);
    glPointSize(10);
    glBegin(GL_POINTS);
    glVertex2d(220,220);
    glEnd();
    glFlush();
    }


    void menuClick(int IDelementi)
    {
    switch(IDelementi)
    {
    case 1:
    glClear(GL_COLOR_BUFFER_BIT);
    glFlush();
    break;
    case 2:
    exit(0);
    break;
    case 3:
    glColor3f(1,0,0);
    break;
    case 4:
    glColor3f(0,1,0);
    break;
    case 5:
    glColor3f(0,0,1);
    break;
    case 6:
    glColor3f(0,0,0);
    break;
    }
    }

    void createMenu()
    {
    int menu = glutCreateMenu(menuClick);
    glutAddMenuEntry("Pastro ekranin", 1);
    glutAddMenuEntry("Dil nga programi", 2);
    glutAddMenuEntry("Red", 3);
    glutAddMenuEntry("Grange", 4);
    glutAddMenuEntry("Blue", 5);
    glutAddMenuEntry("Black", 6);
    glutAttachMenu(GLUT_RIGHT_BUTTON);
    }

    void keyboard(unsigned char key, int x, int y)
    {


    }

    void mouse(int button, int state, int x, int y)
    {
    if (button == GLUT_LEFT_BUTTON &amp;&amp; state == GLUT_DOWN)
    {

    glRecti(x, 480-y, x+10, (480-y)+10);
    glFlush();
    }

    }

    int main(int argc, char **argv)
    {
    glutInit(&amp;argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize(640,480);
    glutInitWindowPosition(100,100);
    glutCreateWindow("Menu Example");
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    glutMouseFunc(mouse);
    createMenu();
    init();
    glutMainLoop();
    }

  10. #10
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948

    Re: glClearColor with HDR values (>1) on RGBA16F FBO

    Please someone help me in a homework.
    1: It's homework. We're not doing it for you.

    2: What does this have to do with HDR rendering and buffer clearing?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •