View Full Version : How to clear part of texture buffer

08-16-2012, 05:30 AM
I have a FBO with one texture buffer attached. The idea is to have an atlas of billboards dynamically created and updated, as needed. When one of the sub images in the texture is going to be updated, I need to first clear the old content. What way is best to do that?

One way is to disable depth tests and overwrite with a "blank" bitmap. But it would be inefficient.

Another way would be to use glBlitFramebuffer(). Maybe it is possible to use with mask 0?

Or maybe there is a much better solution available? Obviously, I could have one separate texture for each billboard, but I just have the feeling it would be more efficient with a single atlas.

Alfonse Reinheart
08-16-2012, 05:48 AM
When you say "one texture buffer" do you mean a "buffer texture (http://www.opengl.org/wiki/Buffer_Texture)", or just a texture?

08-16-2012, 06:37 AM
When you say "one texture buffer" do you mean a "buffer texture (http://www.opengl.org/wiki/Buffer_Texture)", or just a texture?
Sorry, I don't know the definition exactly, but I have glGenTextures() + glTexImage2D() + glFramebufferTexture2D().

So I would say I have a texture, "attached" to an image, and "bound" as a render target in the FBO.

08-16-2012, 07:13 AM
You can attach the texture to a framebuffer, set the scissor in a way that it only covers the area you want to clear using glScissor, then do glClear/glClearBuffer to clear the texture attached to the FBO.

08-16-2012, 10:00 AM
Thanks, this was exactly what I was looking for!