Search code examples
openglopengl-esframebufferrender-to-texture

How to draw Renderbuffer as Texturebuffer in FBO?


I succeeded in render to texture with Texturebuffer, using VAO and shaders.

But FBO has another options for color buffer, it's Renderbuffer. I searched a lot on the internet, but cannot found any example related to draw Renderbuffer as Texturebuffer with shaders

If I ain't wrong, Renderbuffer is released in OpenGL 3.30, and it's faster than Texturebuffer.

Can I use Renderbuffer as Texturebuffer? (stupid question huh? I think it should be absolutely, isn't it?)

If yes, please lead me or give any example to draw render buffer as texture buffer.

My target is just for study, but I'd like to know is that a better way to draw textures? Should we use it frequently?


Solution

  • First of all, don't use the term "texture buffer" when you really just mean texture. A "buffer texture"/"texture buffer object" is a different conecpt, completely unrelated here.

    If I ain't wrong, Renderbuffer is released in OpenGL 3.30, and it's faster than Texturebuffer.

    No. Renderbuffers were there when FBOs were first invented. One being faster than the other is not generally true either, but these are implementation details. But it is also irrelevant.

    Can I use Renderbuffer as Texturebuffer? (stupid question huh? I think it should be absolutely, isn't it?)

    Nope. You cant use the contents of a renderbuffer directly as a source for texture mapping. Renderbuffesr are just abstract memory regions the GPU renders to, and they are not in the format required for texturing. You can read back the results to the CPU using glReadPixels, our you could copy the data into a texture object, e.g. via glCopyTexSubImage - but that would be much slower than directly rendering into textures.

    So renderbuffers are good for a different set of use cases:

    • offscreen rendering (e.g. where the image results will be written to a file, or encoded to a video)
    • as helper buffers during rendering, like the depth buffer or stencil buffer, where you do not care anbout the final contents of these buffers anyway
    • as intermediate buffer when the image data can't be directly used by the follwoing steps, e.g. when using multisampling, and copying the result to a non-multisampled framebuffer or texture