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 12

Thread: Regarding drawBuffer in glClearBufferiv

Hybrid View

  1. #1
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    207

    Regarding drawBuffer in glClearBufferiv

    I am rendering geometry on non default FBO and applying it as integer texture to the geometry rendered on default FBO. To clear a color on non default FBO, i am using glClearBufferiv() call. I am not getting what is drawBuffer (2nd argument) in my case. I tried with 0, but its not working. it does not clear the color.
    Code :
    GLint cl[]={32000,32000,32000,32767};
    glClearBufferiv(GL_COLOR, 0, cl);
     
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
    My frag shader:
     
    out ivec4 fragColor;
     
    void main()
    {
    fragColor = ivec4(0,32767,0,32767);
    }

    With this, it renders green geometry but the outside color is black.

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    985
    The drawbuffer parameter must be the drawbuffer index, i.e. an index into the array of draw buffers specified through glDrawBuffers.

    E.g.:

    Code :
    GLenum drawbuffers[] = { GL_COLOR_ATTACHMENT3, GL_COLOR_ATTACHMENT1 };
    glDrawBuffers(2, drawbuffers);
    glClearBuffer*(GL_COLOR, 0, color); // clears GL_DRAW_BUFFER0, i.e. GL_COLOR_ATTACHMENT3
    glClearBuffer*(GL_COLOR, 1, color); // clears GL_DRAW_BUFFER1, i.e. GL_COLOR_ATTACHMENT1

    It works the exact same way with the default FBO, just the draw buffer enums are different there.

    E.g.

    Code :
    GLenum drawbuffers[] = { GL_FRONT, GL_BACK };
    glDrawBuffers(2, drawbuffers);
    glClearBuffer*(GL_COLOR, 0, color); // clears GL_DRAW_BUFFER0, i.e. GL_FRONT
    glClearBuffer*(GL_COLOR, 1, color); // clears GL_DRAW_BUFFER1, i.e. GL_BACK

    You probably forgot to call glDrawBuffers.
    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
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    207
    Quote Originally Posted by aqnuep View Post
    The drawbuffer parameter must be the drawbuffer index, i.e. an index into the array of draw buffers specified through glDrawBuffers.

    E.g.:

    Code :
    GLenum drawbuffers[] = { GL_COLOR_ATTACHMENT3, GL_COLOR_ATTACHMENT1 };
    glDrawBuffers(2, drawbuffers);
    glClearBuffer*(GL_COLOR, 0, color); // clears GL_DRAW_BUFFER0, i.e. GL_COLOR_ATTACHMENT3
    glClearBuffer*(GL_COLOR, 1, color); // clears GL_DRAW_BUFFER1, i.e. GL_COLOR_ATTACHMENT1

    It works the exact same way with the default FBO, just the draw buffer enums are different there.

    E.g.

    Code :
    GLenum drawbuffers[] = { GL_FRONT, GL_BACK };
    glDrawBuffers(2, drawbuffers);
    glClearBuffer*(GL_COLOR, 0, color); // clears GL_DRAW_BUFFER0, i.e. GL_FRONT
    glClearBuffer*(GL_COLOR, 1, color); // clears GL_DRAW_BUFFER1, i.e. GL_BACK

    You probably forgot to call glDrawBuffers.
    Thanks for your reply.
    I did this:
    Code :
    GLenum buffers[] = { GL_COLOR_ATTACHMENT0};
    glDrawBuffers(1,buffers);
    GLint cl[]={32000,32000,32000,32767};
    glClearBufferiv(GL_COLOR, 0, cl);

    I am binding non default fbo and then while rendering on it i put above calls. My non default FBO has color (GL_COLOR_ATTACHMENT0) and depth attachment.
    I dont understand what is wrong with above code.. Is it a driver bug?

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    985
    From what you've described it could be a driver bug (assuming there are no errors in the rest of the code).
    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
    Member Regular Contributor
    Join Date
    Aug 2008
    Posts
    456
    What is that glClear call with GL_COLOR_BUFFER_BIT included doing in your original post? Was that just a copy/paste error?

  6. #6
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    207
    Quote Originally Posted by Dan Bartlett View Post
    What is that glClear call with GL_COLOR_BUFFER_BIT included doing in your original post? Was that just a copy/paste error?
    Ok, i got it.. I removed glClear(GL_COLOR_BUFFER_BIT); and now it is working. I dont get it i was thinking that glclearbuffer will only set values for clearing buffer but actually glClear(GL_COLOR_BUFFER_BIT); it will clear out color values.

    Now, there is one problem. I have GL_RGBA16I as internal format type. now when i clear buffer with {0,50,50,32767} it sets G B bits to max values even if they are 50. What is problem here?

Posting Permissions

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