PDA

View Full Version : color masking a glTexSubImage2D call



mh104
09-03-2009, 08:45 PM
I've got a pbo that exceeds the max texture dimension. The data is actually 3d voxel data. I'm processing the data in Cuda via a pbo binding... but also need access to the same data in glsl for display. I could easily fit the data in 2 separate textures... and that's probably the route I'll end up taking.. but I wanted to try if I could use a multi channel texture to stuff it all into one texture id;

I want to copy a chunk of data to the RED channel and then copy the next chunk of data to the green channel. By default this doesn't work, and it's in the spec; If you copy just the GL_RED component to an RGB texture it will set the other components to 0. So I'm looking for the equivalent of say glColorMask.... if glColorMask worked on glTexSubImage2D I would do this;

glBindBufferARB(); // bind very large pbo
glTexSubImage2D(..., GL_RED, GL_FLOAT, 0);

glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_FALSE);
glTexSubImage2D(..., GL_GREEN, GL_FLOAT, offset);

Any ideas other than using multiple textures?

ZbuffeR
09-04-2009, 04:53 AM
render to texture :
draw textured quad with red texture
glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_FALSE);
draw textured quad with green texture
get the resulting texture.
red and green can be deleted.

mh104
09-04-2009, 08:34 AM
Yes that would certainly work in theory... I'm a little concerned about memory footprint and performance... the texture I'm rendering to will be 8192x8192... I've never tried pulling off setting up an fbo that large. My past experience makes me doubtfull. If this ends this up doubling or tripling the memory footprint then I'm shot out of the water...

Still seems that if you can copy to a certain region of a texture you should be able to copy to a certain channel....

Anyway I'll give this a shot... Thanks --vmh

skynet
09-04-2009, 01:09 PM
Bind the texture, you try to fill with glTexImage2D, onto an FBO.
Use glColorMask() to mask the appropriate channels.
You can then use glDrawPixels to fill the bound texture with the data stored in the PBO.
That should do the trick.