PDA

View Full Version : PBO and multitexturing



sharp_pixel
02-05-2007, 03:06 PM
Hi there

I want to use to PBOs as textures and put them in two separate texture units (TEXUNIT0 and TEXUNIT1) for input to a shader.

I made some tests and it seems that all the units are set to the latest PBO I bound.
I checked the GL_ARB_pixel_buffer_object specification and didn't see anything regarding multitexturing. No luck with google too.

I am using a GeForce 7800GS on Windows XP with 93.50 (intrumented) drivers.

The test code I use looks like this:

glActiveTexture(GL_TEXTURE1);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, m_pbo2);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, GL_BGRA, GL_UNSIGNED_BYTE, NULL);

glActiveTexture(GL_TEXTURE0);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, m_pbo1);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 2, 2, GL_BGRA, GL_UNSIGNED_BYTE, NULL);At this point m_pbo1 is bound to both TEXUNIT0 and TEXUNIT1.
I want m_pbo1 bound to TEXUNIT0 and m_pbo2 bound to TEXUNIT1.

Has anyone an idea about my problem ? Thanks.

Frogblast
02-05-2007, 04:41 PM
I think you have the wrong idea about PBOs, because you don't bind a PBO to a texture unit.

PBO only provide a new data source for pixel data (ie, for texture creation), but beyond creation, they don't change how the texture is used. They are entirely orthoginal to multitexturing.

In your code, assuming the texture storage was already specified via glTexImage2D(), should be just fine.

sharp_pixel
02-05-2007, 11:48 PM
I may have simplified my explanation too much but I wanted to get to the point.
What I meant is really setting the pbo as source for the textures bound to the texture units.

I have two textures created with:

glActiveTexture(GL_TEXTURE0);
// + glTexParameter, glTexEnv
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 2, 2, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, m_pbo1);
glBufferData(GL_PIXEL_UNPACK_BUFFER, 2*2*4, data1, GL_DYNAMIC_DRAW);same for GL_TEXTURE1

Without PBOs (using texture IDs) it works fine, with PBOs it just doesn't.

I've used PBOs quite some time but never got to multitexturing with them before.

The code I provided is only to update the pbos in my render loop (GL_DYNAMIC_DRAW).

Yes PBOs and multitexturing are orthogonal but PBO seem to change a thing: glBindTexture and glGenTextures don't seem to be needed for single texturing. This may be the source of my problem.

sharp_pixel
02-06-2007, 12:36 AM
Alright it seems that glGenTextures and glBindTexture are needed.
The driver shouldn't allow it to work without them but it does in single texturing. A GL_INVALID_OPERATION error or at least a black result would have been nice.

yooyo
02-06-2007, 11:00 AM
PBO is jus a buffer. Read PBO spec, and at end of docoment you'll find C code example.

In short...
- create ONE pbo
- allocate pbo buffer
- create many textures
- bind pbo
- map pbo buffer to get pointer to video memory (pbo_ptr)
- for each texture
* bind texture
* copy image data to pbo_ptr
* call glTexImage2D/glTexSubImage2D to upload texture data from pbo. Pass 0 instead of pointer to image data
- unmap pbo

Make sure that PBO have enough size to keep largest texture.