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 10 of 10

Thread: glBlitFrameBuffer renders empty when using vec3 as output for fragment

  1. #1
    Intern Contributor
    Join Date
    Mar 2011
    Location
    Israel
    Posts
    53

    glBlitFrameBuffer renders empty when using vec3 as output for fragment

    Hi all. Strange problem I am experiencing. I am rendering color data from frag shader to fbo texture attachment. If the fragment out is of type vec3 the glBlitFrameBuffer shows nothing. But if I set it to vec4 out then it shows all right. For the color attachment of the fbo I am using GL_RGB32F. Can it be the problem. Also I work with OpenGL 4.0

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    985
    I don't understand what you fragment shader has to do with glBlitFramebuffer as your bound GLSL program does not affect glBlitFramebuffer, in fact, this function only performs a simple stretched copy.
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

  3. #3
    Intern Contributor
    Join Date
    Mar 2011
    Location
    Israel
    Posts
    53
    I blit the color attachments from FBO. The data to thead attachments comes from the texture which is passed to some fragment shader I am using to render geometry. Now seems logical?

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    985
    It still isn't. So the blit is not working or the rendering? The attachment is itself a texture. Also what do you mean by "passing the texture to some fragment shader"? Do you render to the texture or fetch from it?
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

  5. #5
    Intern Contributor
    Join Date
    Mar 2011
    Location
    Israel
    Posts
    53
    That is GBuffer which I currently checking using blitting.So I attach it , draw some geometry with one of its color attachments active,then blit to viewport. That is what I am doing

  6. #6
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,128
    You seem to confuse blitting with rendering. Blitting is nothing more than copying a number of pixels from a read framebuffer to a draw framebuffer. Nothing is rendered during a blit.

    To be able to blit you need two things:

    1. A framebuffer which is bound to GL_READ_FRAMEBUFFER, which serves as the source of pixels, where glReadBuffer(ATTACHMENT_i) defines the concrete attachment to copy from (you'll notice that there is no glReadBuffers())
    2. A framebuffer which is bound to GL_DRAW_FRAMEBUFFER, which obviously serves as the target, where glDrawBuffer(ATTACHMANT_i) or glDrawBuffers() specify one or more attachments to copy to

    Mind the following call, in part shamelessly copied from the reference pages:

    Code :
    glBlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, GL_COLOR_BUFFER_BIT, GL_NEAREST);

    Assuming that all is well with the FBOs involved, this call will simply copy the area defined by (srcX0, srcY0) to (srcX1, srcY1) to (dstX0, dstY0) to (dstX1, dstY1). If the source and destination areas are equal you get en exact copy of the read buffer. If they aren't the filter argument defines how the resulting image is filtered. You can copy multiple attachments at the same time by choosing an appropriate mask, e.g. GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT to copy both the color attachment set as the read buffer and the depth attachment.


    Edit: Note that glBlitFramebuffer() is can also be used with the default framebuffer, which is implicitly active if either one of GL_READ_FRAMEBUFFER or GL_DRAW_FRAMEBUFFER is zero. That means, you can blit from the default framebuffer to a FBO and vice versa. Just set you glReadBuffer() and your glDrawBuffers() accordingly and remember to bind the FBO to the right target.
    Last edited by thokra; 07-03-2012 at 03:28 AM. Reason: Clarification.

  7. #7
    Intern Contributor
    Join Date
    Mar 2011
    Location
    Israel
    Posts
    53
    Man ,you are completely right. That is what I do.let me explain once again.I have an FBO .I render some geometry to attachments of that FBO.Then I switch to the default FBO and read the color attachment from the first FBO ,
    then blit. It is all fine.Again ,read my issue in the first post.I don't have a problem with blit procedure.My Problem is that in the fragment shader where I output color map ,if I set the value to be of type vec3 then after the blit to default fbo the screen is empty.If I use vec4 for fragment outputs then my geometry shows after the blitting. Therefore my question is why it happend.My FBO textures are set like this( JAVA WRAPPER FOR OGL:
    Code :
     
            glBindTexture(GL_TEXTURE_2D, m_textures.get(i));[COLOR=gray]//[/COLOR]
            glTexImage2D(GL_TEXTURE_2D, [COLOR=#800000]0[/COLOR], GL_RGB32F, width, height, [COLOR=#800000]0[/COLOR], GL_RGB, GL_FLOAT, ([COLOR=#2B91AF]ByteBuffer[/COLOR]) null);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
     
            glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0+i , GL_TEXTURE_2D,m_textures.get(i), [COLOR=#800000]0[/COLOR]);

    So GL_RGB32F seems to be ok for accepting vec3 output from the fragment?
    For the full code here is my post on stackoverflow

  8. #8
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,213
    Quote Originally Posted by SasMaster View Post
    ...let me explain once again. I have an FBO ... then blit. It is all fine. Again, read my issue in the first post. I don't have a problem with blit procedure. ... then after the blit to default fbo the screen is empty. If I use vec4 for fragment outputs then my geometry shows after the blitting.
    What's confusing about your post is that you first say the blit works fine. But then you say it doesn't work fine due to some mysterious fragment (shader?) output format thing without giving any details.

    Post a short GLUT test program that illustrates your problem.

    Also (a shot in the dark), Blit in my experience honors the buffer writemasks, so I would make sure that glColorMask, glDepthMask, and glStencilMask are wide-open before you do the Blit.

    And when you're doing the mysterious "fragment" piece of this, make sure that you have GL_BLEND and GL_ALPHA_TEST disabled. Just for now. So nothing special gets done with alpha (present or not). To that point, what are you writing in your "fragment shader" for the alpha value (regardless whether the RT format is vec3 or vec4).
    Last edited by Dark Photon; 07-03-2012 at 05:28 AM.

  9. #9
    Intern Contributor
    Join Date
    Mar 2011
    Location
    Israel
    Posts
    53
    the mysterious "fragment" piece of this
    He He , like that. I am writing nothing to alpha. Just rgb if it is vec3 .And if it is vec4 I write rgba from the input sampler which is RGBA texture.

  10. #10
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,213
    Quote Originally Posted by SasMaster View Post
    He He , like that. I am writing nothing to alpha. Just rgb if it is vec3 .And if it is vec4 I write rgba from the input sampler which is RGBA texture.
    If you have GL_BLEND or GL_ALPHA_TEST enabled, that is potentially a problem, as these are processed before we go writing to the framebuffer.
    In the vec3 case, try writing 1 for alpha. Or just disable GL_BLEND and GL_ALPHA_TEST.

Tags for this 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
  •