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: Can shader read from target framebuffer?

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2008
    Posts
    20

    Can shader read from target framebuffer?

    I'm trying to use OpenGL and framebuffer/texturebuffer objects to composite some 2D mask images.

    At the moment, I'm creating a new destination texture and binding it to a framebuffer so it will accumulate the final mask. Then I iterate through all my source textures and draw them one at a time on top of my destination texture. (I'm doing this by drawing a singe quad with a simple shader that just samples the source texture).

    While this works well for simple alpha blending, I would like to be able to create more complex operations that use the current color of the destination pixel to calculate the color of the current fragment. For example, I would like to do something like:

    Code :
        vec4 src = texture2D(u_mySrcTex, v_samplingCoord);
        vec4 dst = getCurrentColorAtOutputFragmentPosition();
        vec4 finalColor = vec4(dst.rgb, max(src.a, dst.a));

    I'd also like to be able to implement Porter-Duff compositing and things like that.

  2. #2
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,171

    Re: Can shader read from target framebuffer?

    You could always just copy or blit the current framebuffer to another texture and use that copy as one of the source textures.

  3. #3
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,421

    Re: Can shader read from target framebuffer?

    ------------------------------
    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);

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Apr 2009
    Posts
    529

    Re: Can shader read from target framebuffer?

    There is GL_NV_texture_barrier which allows to a very limited extent to use a texture even if it is the texture to which one is rendering.

Posting Permissions

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