PDA

View Full Version : glClearColor with HDR values (>1) on RGBA16F FBO



Nicolas Lelong
12-08-2010, 04:11 AM
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,



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)

Alfonse Reinheart
12-08-2010, 04:40 AM
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.

Nicolas Lelong
12-08-2010, 09:32 AM
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 :


glClearBufferfv(GL_COLOR, 0, (1.0, 2.0, 0.0, 1.0))

The same clamping happens.

Groovounet
12-08-2010, 10:54 AM
AMD has some known issue with glClear* and they are working on it... hope it would be fixed soon!

randall
12-08-2010, 11:47 AM
As a workaround, draw full screen quad and output your desired color in a fragment shader.

Nicolas Lelong
12-08-2010, 01:02 PM
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...


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

aqnuep
12-09-2010, 02:20 AM
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.

Groovounet
12-09-2010, 06:38 AM
There are lot more problems on AMD glClear*
What I experienced lately is a disfunctional scissor test on glClearBuffer*

besim
04-13-2011, 11:19 AM
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();
}

Alfonse Reinheart
04-13-2011, 02:47 PM
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?