Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Accessing FBO during deferred light pass with combined stencil/depth buffer

  1. #1
    Intern Contributor
    Join Date
    Jun 2001

    Question Accessing FBO during deferred light pass with combined stencil/depth buffer


    I've hit a problem during my attempt to write a deferred light shader using stencil light volumes. The combined depth/dtencilbuffer setup looks like this:

    Code :
        glGenTextures(1, &ids[depthbuffer]);
        glBindTexture(GL_TEXTURE_2D, ids[depthbuffer]);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, dim[0], dim[1], 0,
                GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL);
                GL_TEXTURE_2D, ids[depthbuffer], 0);

    During the lighting pass when the stencil buffer is being set it seems that I cannot access the attached depth buffer and write the final color to the screen at the same time. The problem is being discussed in some tutorials and the solution would be to write the lighting pass into a separate color buffer and then blit the color buffer to the FBOs final color buffer (screen). Is there a smarter solution without the need of creating another buffer and copy the color data around?

    Thanks & Regards

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    You cannot read back from a output buffer in a fragment shader. You always need 2 passes. One to write to a buffer and another to read. Put antohter way you cannot attach the same buffer both as an input and an output to the same shader.

  3. #3
    Member Regular Contributor
    Join Date
    Jun 2012
    Hey i am trying to implement depth stencil textures with FBO but i get a black o/p. Can you post your code or tell me algorithm to implement stencil textures, it would help me. thanks..

  4. #4
    Intern Contributor
    Join Date
    Jun 2001
    hi! take a look at my last thread:


Posting Permissions

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