<p>Actually, GL_COLOR_BUFFER_BIT also need to be cleared</p>

<p>After creation of the framebuffer, draw buffer need to be set to:</p>

<pre><code>glDrawBuffer(GL_COLOR_ATTACHMENT0);
</code></pre>

<p>and then after each swap:</p>

<pre><code>glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
</code></pre>

<p>instead of only </p>

<pre><code>glClear(GL_DEPTH_BUFFER_BIT);
</code></pre>

<p>To clear current attachment 0.
I don't really understand these clearing bits extensively but this seems to fix blinking "chess board" artifact.</p>

<p>Borders seems to be connected with motion blur shader.</p>

CC BY-SA 3.0
2016-09-01T15:52:42.367Z
2016-09-01T15:52:42.367Z
mdkdy
<p>In order to optimize I'm trying to set up a setup which ping pong between same framebuffer two color attachments to apply some postprocess effects. It seems to work (effects are applied) but concurently I'm getting a lot of strange artifacts like:</p>

<ul>
<li>blinking squares</li>
<li>borders on depth discontinuities</li>
<li>color spilling on screen (window resize removes it)</li>
</ul>

<p>Which change or disappear partly when I for example remove one step (one post process effect) from "ping ponging".</p>

<p>If I do this ordinary way using different framebuffers seems to remove them but I'm not 100% sure if it is not a mess in the shaders or something but they seem fine.</p>

<p>In each frame I'm doing ping pong like that:</p>

<p>First step - render to current color attach using other fb texture</p>

<pre><code>fbDeferredLighting-&gt;bindFramebuffer(); //fb which has two color attachments
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
effect1-&gt;setConstPerFrameUniforms();
//get 0 attachment from fb scene prepass to apply effect and draw on fbDeferredLighting current color attach
effect1-&gt;setTextureUniforms(fbScene, 0); 
quad-&gt;draw();
</code></pre>

<p>And then repeating some number of times: swap step and drawing, using same fb swapped attachment:</p>

<pre><code>fbDeferredLighting-&gt;bindFramebuffer();
//after swap - now current=1, other=0 or current=0, other=1
std::swap(colorAttachment0Current, colorAttachment0Other);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texturesDiffuse[colorAttachment0Current]-&gt;getTextureID(), 0);
glClear(GL_DEPTH_BUFFER_BIT); //only clear depth
effectX-&gt;setConstPerFrameUniforms();
//get other color attach and use it to apply effect on current
effectX-&gt;setTextureUniforms(fbDeferredLighting , colorAttachment0Other); 
quad-&gt;draw();
</code></pre>

<p>Is this correct?</p>

<p>EDIT:
I wonder, maybe rewrite it to compute shaders, that would simplify things.</p>

<opengl><rendering><texture><image-processing>
ping pong between same framebuffer two color attachments
mdkdy
# ping pong between same framebuffer two color attachments

(Asked by: username_0 on 2016-08-26)

In order to optimize I'm trying to set up a setup which ping pong between same framebuffer two color attachments to apply some postprocess effects. It seems to work (effects are applied) but concurently I'm getting a lot of strange artifacts like:

* blinking squares
* borders on depth discontinuities
* color spilling on screen (window resize removes it)

Which change or disappear partly when I for example remove one step (one post process effect) from "ping ponging".

If I do this ordinary way using different framebuffers seems to remove them but I'm not 100% sure if it is not a mess in the shaders or something but they seem fine.

In each frame I'm doing ping pong like that:

First step - render to current color attach using other fb texture

```
fbDeferredLighting->bindFramebuffer(); //fb which has two color attachments
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
effect1->setConstPerFrameUniforms();
//get 0 attachment from fb scene prepass to apply effect and draw on fbDeferredLighting current color attach
effect1->setTextureUniforms(fbScene, 0); 
quad->draw();

```

And then repeating some number of times: swap step and drawing, using same fb swapped attachment:

```
fbDeferredLighting->bindFramebuffer();
//after swap - now current=1, other=0 or current=0, other=1
std::swap(colorAttachment0Current, colorAttachment0Other);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texturesDiffuse[colorAttachment0Current]->getTextureID(), 0);
glClear(GL_DEPTH_BUFFER_BIT); //only clear depth
effectX->setConstPerFrameUniforms();
//get other color attach and use it to apply effect on current
effectX->setTextureUniforms(fbDeferredLighting , colorAttachment0Other); 
quad->draw();

```

Is this correct?

EDIT:
I wonder, maybe rewrite it to compute shaders, that would simplify things.

**Tags:** opengl, rendering, texture, image-processing


---

## 1 answers

### Answer by username_0 on 2016-09-01. Score: 1 | Accepted answer

Actually, GL\_COLOR\_BUFFER\_BIT also need to be cleared

After creation of the framebuffer, draw buffer need to be set to:

```
glDrawBuffer(GL_COLOR_ATTACHMENT0);

```

and then after each swap:

```
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

```

instead of only

```
glClear(GL_DEPTH_BUFFER_BIT);

```

To clear current attachment 0.
I don't really understand these clearing bits extensively but this seems to fix blinking "chess board" artifact.

Borders seems to be connected with motion blur shader.


---

