PDA

View Full Version : PBuffer & Render to Texture (read & write)



habicht
02-07-2005, 06:49 PM
Hi,

I'm trying to render into a pbuffer subbuffer (e.g. WGL_FRONT_LEFT_ARB) and at the same time I want to use subbuffers of the pbuffer (WGL_BACK_LEFT_ARB, WGL_AUX0_ARB) as texture uniforms for my fragment program. I don't even know if that's possible, but I think I read about that somewhere.

This is roughly how I thought it could work:
(using a GeForce 6800 GT)


_oFPBuffer.activate();
...

glActiveTexture(GL_TEXTURE2);
glEnable(GL_TEXTURE_2D);
glGenTextures(1, _iTexRead);
glBindTexture(GL_TEXTURE_2D, _iTexRead);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
...

glDrawBuffer(WGL_FRONT_LEFT_ARB);

glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, _iTexRead);

if( !wglBindTexImageARB(&_oFPBuffer, WGL_BACK_LEFT_ARB) )
{ ... error ... }

glUniform1iARB(_iTexUnitDiagN1, 2);
...

glBegin(GL_QUADS);
{ ... }
glEnd();

glActiveTexture(GL_TEXTURE2);
wglReleaseTexImageARB(&_oFPBuffer, WGL_BACK_LEFT_ARB);
...For the next pass I want to render into the buffer that I used for reading in this pass. Accordingly I want to read the buffer that has the results from the previous pass.

wglBindTexImageARB() always results (GetLastError) in error code 3221684230 which is neither ERROR_INVALID_OPERATION, ERROR_INVALID_DATA, nor ERROR_INVALID_WINDOW_HANDLE.

I use the following attributes for my pbuffer:


int attribList[] =
{
WGL_SUPPORT_OPENGL_ARB, true,
WGL_RED_BITS_ARB, 32,
WGL_GREEN_BITS_ARB, 32,
WGL_BLUE_BITS_ARB, 32,
WGL_ALPHA_BITS_ARB, 32,
WGL_STENCIL_BITS_ARB, 8,
WGL_DEPTH_BITS_ARB, 24,
WGL_FLOAT_COMPONENTS_NV, true,
WGL_BIND_TO_TEXTURE_RGBA_ARB, true,
WGL_DRAW_TO_PBUFFER_ARB, true,
WGL_DOUBLE_BUFFER_ARB, true,
WGL_AUX_BUFFERS_ARB, true,
0,
};and the following pbuffer related extensions in my program:


"GL_NV_float_buffer " \
"WGL_ARB_pixel_format " \
"WGL_ARB_pbuffer " \
"WGL_ARB_render_texture " \
"WGL_ARB_extension_string "Any idea how I can get this working?

Thanks a lot!

-NiCo-
02-07-2005, 07:32 PM
I believe the problem is situated in your pbuffer attribute list. It looks like you're trying to bind a TEXTURE_2D texture to a pbuffer with nv float components which are only supported for TEXTURE_RECTANGLE_NV.

Try the following attributes for texture rectangles:

int attribList[] =

{

WGL_SUPPORT_OPENGL_ARB, true,

WGL_RED_BITS_ARB, 32,

WGL_GREEN_BITS_ARB, 32,

WGL_BLUE_BITS_ARB, 32,

WGL_ALPHA_BITS_ARB, 32,

WGL_STENCIL_BITS_ARB, 8,

WGL_DEPTH_BITS_ARB, 24,

WGL_FLOAT_COMPONENTS_NV, true,

WGL_TEXTURE_TARGET_ARB, WGL_TEXTURE_RECTANGLE_NV,

WGL_BIND_TO_TEXTURE_RECTANGLE_FLOAT_RGBA_NV, true

WGL_TEXTURE_FORMAT_ARB, WGL_TEXTURE_FLOAT_RGBA_NV

WGL_DRAW_TO_PBUFFER_ARB, true,

WGL_DOUBLE_BUFFER_ARB, true,

WGL_AUX_BUFFERS_ARB, true,

0,

};

Nico

habicht
02-08-2005, 01:49 AM
You're right. I mixed it up. But it still doesn't work.

I tried to leave out WGL_FLOAT_COMPONENTS_NV, because I'd like to use TEXTURE_2D. But then wglChoosePixelFormatARB fails.

habicht
02-08-2005, 02:12 AM
Do I need to use WGL_ARB_pixel_format_float instead of GL_NV_float_buffer? I tried, but it wouldn't work.

-NiCo-
02-08-2005, 02:38 AM
Here's the attrib list for 2D 32fp rgba:

int attribList[] =

{

WGL_SUPPORT_OPENGL_ARB, true,

WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_FLOAT_ATI,

WGL_TEXTURE_TARGET_ARB, WGL_TEXTURE_2D_ARB,

WGL_BIND_TO_TEXTURE_RGBA_ARB, true,

WGL_TEXTURE_FORMAT_ARB, WGL_TEXTURE_RGBA_ARB,

WGL_RED_BITS_ARB, 32,

WGL_GREEN_BITS_ARB, 32,

WGL_BLUE_BITS_ARB, 32,

WGL_ALPHA_BITS_ARB, 32,

WGL_STENCIL_BITS_ARB, 8,

WGL_DEPTH_BITS_ARB, 24,

WGL_DRAW_TO_PBUFFER_ARB, true,

WGL_DOUBLE_BUFFER_ARB, true,

WGL_AUX_BUFFERS_ARB, true,

0,

};

Nico