Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Combine 4 separate component R G B A in one texture

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2012
    Posts
    6

    Combine 4 separate component R G B A in one texture

    Here's a short description of my problem :

    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?

    Thanks in advance,

    Regards,

    Lex

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,106
    Could somebody give me a link to a complete tutorial for multi-texturing please?
    For your exercise you only need to supply one set texture coordinates tothe shader so any texture rendering tutorial will do for that like
    http://www.swiftless.com/tutorials/g...texturing.html

    But you will load 4 textures (probably on GL_TEXTURE0, GL_TEXTURE1, GL_TEXTURE2, GL_TEXTURE3) to 4 different samplers. Then fetch from each of these samplers with the same texture u,v and combine the red (.r) components from each (assuming you create textures with say an internal format of GL_RED).

    I cannot say if OpenGL would be quicker than just combining on the cpu given you have to copy the textures up to the graphics card for each frame.

    You may also have a look at texture streaming. I have not used this but I believe it is designed for your task type.

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2012
    Posts
    6
    Hey, thanks tonyo_au for your answer.

    Indeed that's the path I have taken since yesterday , I load 4 different textures in the fragment shader and combine the .red of each texture (except alpha texture) and multiply it by the alpha, as such:

    color= r*a + g*a +b*a

    I have read a little while around the internet about texture streaming, and apparently I could upload the texture on the GPU while avoiding the call to glTexSubImage2d().

    I also have a question, since every time I compute a row for one frame I'm calling glTexSubImage2d ( or whatever the sequence of calls it would be if I use the texture streaming technique) ,
    would it be possible to draw every time I compute a row ? It would sort of fill-up the window until the texture is not full, wouldn't it?
    Otherwise I think I would fall back on a drawing coupled with a timer to respect a frame-rate of 25 fps

    Again thanks for your answer

  4. #4
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,264
    If you want to stream, then look into PBO (pixel buffer object). It does use glTexSubImage2D. You just need to bind the PBO before you call glTexSubImage2D. It would help hide the latency of the driver actually uploading the texture to VRAM.
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •