I’m developing a viewer for video-sequences. I use a scan-line based approach with
concurrent computation (fetching) for each row. Every row I get is separated in severals buffer (Channels) , namely R,G,B,A.
So imagine the problem as: I want to combine all my channels into one texture.
I have thought of doing it my-self, by allocating a temporary buffer in which I can upload the severals component, and give it to openGL with glTexSubImage2D(…), but the solution is very expensive…especially for image streaming!
Then I thought of multi-texturing: in short, make a separate texture (GL_LUMINANCE?) for every channel, and then combine it with a GLSL shader. I think this could work, unfortunately I have no experience in multi-texturing. Could somebody give me a link to a complete tutorial for multi-texturing please?
The last thing I could dig out of the internet is using a FBO, with a buffer texture. In
the buffer texture, use a buffer object with several indexes. But I couldn’t get much more details about indexes in a buffer object, and if it would cater my needs.
Anyway, here is the final question : Is it possible to create one texture from 4 separate component (buffers) ? Or more precisely : How to draw 4 combined buffers, efficiently , in a context of video sequences?
Multitexturing is indeed the way to go. Most important it allows you to have different formats for each channel, which allows for things like 4:2:2 subsampling or similar.
FBOs are drawing targets, not image sources, so not quite the right thing for you.
The basic idea behind multitexturing is, that there are a number of so called texture units, where the OpenGL call
glActiveTextureselects the unit following calls ofglBindTexturewill work in. It requires some bookkeeping which texture is bound where, but its not very difficult.In a fragment shader you can source samples from a texture through a so called sampler uniform. A sampler uniform is bound to a texture unit. A important pitfall is, that
glActiveTexturetakes as parameterGL_TEXTURE0 + nwhereas the unit number passed to the sampler usingglUniformiis justn.It doesn’t matter in which texture unit a texture is bound if you’re just interested in uploading data. (Personally I’d like new versions of OpenGL to have a special texturing unit which can not be used as a source, but only allows binding of textures for image upload, and where there’s no texture target precedence.)