Results 1 to 2 of 2

Thread: How to clear selected buffers in an FBO?

  1. #1
    Senior Member Regular Contributor Kopelrativ's Avatar
    Join Date
    Apr 2011
    Posts
    214

    How to clear selected buffers in an FBO?

    I am using an FBO with 4 color buffers to implement deferred shaders. It all works quite well, except that I can't find out how to do selective clear of buffers. I want to initiate the first buffer (the diffuse data to gray), and set the others to 0. How are you supposed to do that?

    I try as follows:
    Code :
    	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboName);
    	float zero[] = { 0.0f, 0.0f, 0.0f, 0.0f };
    	float gray[] = { 0.584f, 0.620f, 0.698f, 1.0f };
    	GLenum bufferlist[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 };
    	glDrawBuffers(4, bufferlist);
    	glClear(GL_DEPTH_BUFFER_BIT);
    	glClearBufferfv(GL_COLOR, 0, gray);
    	glClearBufferfv(GL_COLOR, 1, zero);
    	glClearBufferfv(GL_COLOR, 2, zero);
    	glClearBufferfv(GL_COLOR, 3, zero);
    But this will not initialize buffer 0 to gray. If I remove the clearing of buffer 1 to 3, then buffer 0 will be gray! It is as if the second argument (drawbuffer) is ignored.

    Next try, I did as follows:
    Code :
    	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboName);
    	glDrawBuffer(GL_COLOR_ATTACHMENT0); // Select the diffuse buffer
    	glClearColor(0.584f, 0.620f, 0.698f, 1.0f); // Gray background
    	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    	GLenum bufferlist[] = { GL_NONE, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 };
    	glDrawBuffers(4, bufferlist); // Select all but the diffuse buffer
    	glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Set everything else to zero.
    	glClear(GL_COLOR_BUFFER_BIT);
    Again, the second call to glClear() will also clear buffer 0. Maybe you can't use glDrawBuffers() to control what buffers are cleared.

  2. #2
    Senior Member Regular Contributor Kopelrativ's Avatar
    Join Date
    Apr 2011
    Posts
    214

    [SOLVED]: How to clear selected buffers in an FBO?

    Problem solved, seems as if the problem was in the shader (having a dependency on other buffers).

Similar Threads

  1. Texture buffers are much slower than uniform buffers
    By glnoob in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 11-14-2018, 02:00 PM
  2. efficiently clear buffers
    By Chris Lux in forum OpenGL: Advanced Coding
    Replies: 13
    Last Post: 02-20-2011, 01:05 AM
  3. front buffers, back buffers & wglMakeCurrent
    By mark ds in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 01-22-2010, 05:15 AM
  4. Selected edges always in front
    By devdept in forum OpenGL: Advanced Coding
    Replies: 25
    Last Post: 11-11-2009, 01:07 AM
  5. Vertex Buffers and render/texture Buffers
    By schelter in forum OpenGL: General
    Replies: 4
    Last Post: 02-03-2002, 08:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean