PDA

View Full Version : Working with floating point textures



Ehsan Kamrani
01-05-2011, 07:55 PM
I want to load 32 bit floating point RGB textures. So do I need to create a floating point buffer using the following code?


int pixelFormat;
UINT numFloats;
int attribtes[] = {
WGL_DOUBLE_BUFFER_ARB, TRUE,
WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
WGL_PIXEL_TYPE_ARB, WGL_RGBA_FLOAT_ARB,
0,0
}
wglChoosePixelFormat( hdc, attributes, NULL, 1, &pixelFormat, &numFormats );
//...

( The book "More OpenGL Game Programming" suggest the readers to create a floating point buffer while using the floating point textures. However, I can't create a floating point buffer! When I use the following line of code:
WGL_PIXEL_TYPE_ARB, WGL_RGBA_FLOAT_ARB,
I get an error--wglChoosePixelFormat() can't create the requested pixel format.

Alfonse Reinheart
01-05-2011, 09:10 PM
I want to load 32 bit floating point RGB textures. So do I need to create a floating point buffer using the following code?

No. That code is for the default framebuffer. Each texture can have an arbitrary image format (http://www.opengl.org/wiki/Image_Format).

Furthermore, you can't have a floating-point default. The default framebuffer needs to be visible, and floating-point images are not visible (since your screen can only show color values on [0, 1]).

Ehsan Kamrani
01-05-2011, 09:17 PM
So, why the book has suggested to use floating point frame buffers while using the floating point textures?
( If I have understood correctly, the suggestion in this book is incorrect and the texture format is independent of the frame buffer format? )
BTW, why wglChoosePixelFormat() is not able to create a floating point buffer? And what's the benefit of a floating point buffer?

Alfonse Reinheart
01-05-2011, 09:43 PM
So, why the book has suggested to use floating point frame buffers while using the floating point textures?

My guess is that you misunderstood what it was saying.


BTW, why wglChoosePixelFormat() is not able to create a floating point buffer?

In what way was "The default framebuffer needs to be visible, and floating-point images are not visible (since your screen can only show color values on [0, 1])," unclear to you?

Ehsan Kamrani
01-05-2011, 10:10 PM
No I didn't misunderstood it. It describes about the "ARB_color_buffer_float" extension. Then it introduces glClampColorARB() and explains that we must use this function to disable vertex and fragment color clamping if we want to use floating point textures.

aqnuep
01-06-2011, 02:01 AM
There is in fact possibility to ask for a floating point default framebuffer, however you cannot render it to a window so using such a context makes sense only if you are using e.g. pbuffers, still, instead of pbuffers you should rather go with FBO.

So actually you need to create a usual normalized fixed point framebuffer and just use floating point textures as specified by ARB_texture_float (http://www.opengl.org/registry/specs/ARB/texture_float.txt) and use FBOs to render to these textures if needed.

Ehsan Kamrani
01-06-2011, 03:19 PM
Thanks. Now I understand it :-)