Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Regarding drawBuffer in glClearBufferiv

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

    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
    208
    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
    208
    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?

  7. #7
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    The problem is how you're reading the data. So... how are you reading the data?

  8. #8
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    208
    Quote Originally Posted by Alfonse Reinheart View Post
    The problem is how you're reading the data. So... how are you reading the data?
    I am doing this stuff on newly created FBO and attaching it color attachment. I am applying this texture on geometry rendered on system default FBO.
    So basically, I have these calls:

    Code :
    glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 1 ,GL_RGBA16I, 32, 32,true);
    glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D_MULTISAMPLE,id1,0);
    and frag shader mentioned above for rendering on newly created FBO.

  9. #9
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    There seems to have been a failure to communicate.

    You are rendering to an integer texture. Then you are reading from that integer texture, either via a sampler in a later rendering operation or with glReadPixels/glGetTexImage.

    I'm not asking about how you're setting up your FBO and rendering to it. I'm asking about how you're reading the data and thus determining that "it sets G B bits to max values" has happened. I want to see the code wherein you are making that determination.

  10. #10
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    208
    Quote Originally Posted by Alfonse Reinheart View Post
    There seems to have been a failure to communicate.

    You are rendering to an integer texture. Then you are reading from that integer texture, either via a sampler in a later rendering operation or with glReadPixels/glGetTexImage.

    I'm not asking about how you're setting up your FBO and rendering to it. I'm asking about how you're reading the data and thus determining that "it sets G B bits to max values" has happened. I want to see the code wherein you are making that determination.
    ok, here is my frag shader for reading that texture:

    Code :
    uniform isampler2DMS tk_diffuseMap;
    in vec3 ps_texCoord;
    out vec4 fragColor;
    uniform int samples;
    uniform int factor; 
    void main(void)
    {
     
    	vec2 iTmp = textureSize(tk_diffuseMap);
    	vec2 tmp =floor(iTmp * ps_texCoord.xy);
    	ivec4 temp;	 
    	vec4 temp1;
    	vec4 color;
     
    	for(int i = 0; i < samples; ++i)
    	{
    		 temp= texelFetch(tk_diffuseMap, ivec2(tmp), i);
    		 temp1=vec4(temp);
    		 temp1=temp1/32767;
    		color = color +	temp1;
    	}
     
    	fragColor = vec4(color/samples);
    }

    i am dividing that by 32767 for normalizing the data as my type is GL_RGBA16I..

Posting Permissions

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