Jump to content
  • Advertisement
Sign in to follow this  
BloodOrange1981

OpenGL glFrameBufferRenderBuffer vs glFrameBufferTexture2D...FIGHT!

This topic is 1231 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've had problems trying to use glFrameBufferRenderBuffer and glRenderBufferStorage before when experimenting with depth textures and deferred rendering etc. Usually in tutorials I'll see code using the above functions to initialize a framebuffer object.

 

However after seeing a tutorial on deferred rendering that used glFramebufferTexture2D with a GL_DEPTH_STENCIL attachment - and this worked perfectly for me.

Doing some background reading here (http://www.songho.ca/opengl/gl_fbo.html#renderbuffer) it is suggested that:

 

 

 

Renderbuffer is simply a data storage object containing a single image of a renderable internal format. It is used to store OpenGL logical buffers that do not have corresponding texture format, such as stencil or depth buffer.

 

However if you can just use glFrameBufferTexture2D anyway then what is the purpose or need of render buffers?

Share this post


Link to post
Share on other sites
Advertisement

However if you can just use glFrameBufferTexture2D anyway then what is the purpose or need of render buffers?

You can use the texture version (if supported), sure, but it is not always necessary. You need textures whenever you want to access the data directly in a shader, whereas if you just need to use the buffer during rendering (eg. depth/stencil), then there is no need for a texture. In short:

Input: Texture

Output: Buffer

Input/Output: BufferTexture

Edited by Ashaman73

Share this post


Link to post
Share on other sites

However if you can just use glFrameBufferTexture2D anyway then what is the purpose or need of render buffers?

Only renderbuffers can be presented to the screen.
Renderbuffers are write-only and optimized thusly.

Most render-targets need to have read access (in 99% of cases you are writing to a render-target with the intent of reading back the results later, often for shadow mapping or post-processing), so most of the time you should (must) use a texture.
But when you don’t need to read the results (using a depth buffer for an off-screen render when you only need to read back the color result, not the depth result) you should always use a renderbuffer. They are more efficient for that purpose.


L. Spiro

Share this post


Link to post
Share on other sites

Thank you both. Ok I see. "I think." So in the case of a deferred render where there is no post process step and the final image is just a blend of the pixels affected by lights I can just present that to the screen directly and not need to render it to a full screen quad?

To elaborate if I perform a deferred render like this:

 

g buffer -> render lights via stencil testing sphere meshes against depth values to a color attachment texture -> render to full screen quad 

 

I can make it like this

 

g buffer -> render lights via stencil testing sphere meshes against depth values to a color attachment render buffer -> present render buffer to screen direct

Am I barking up the right tree?
Or totally lost the plot?

Share this post


Link to post
Share on other sites

In order to see the final result on of your rendering..no matter how its done, you will have to draw to the windowing system provided backbuffer( if you don't care about depth ) and color buffer, there is no present render buffer to screen. Render buffers are for offscreen rendering as describe above.

Share this post


Link to post
Share on other sites

Am I barking up the right tree?
Or totally lost the plot?

Well...

 

 

 


So in the case of a deferred render where there is no post process step and the final image is just a blend of the pixels affected by lights I can just present that to the screen directly and not need to render it to a full screen quad?

There are some missunderstandings. A deferred renderer utilize 80% of the time post-processing and you don't render to a fullscreen quad.

 

First try to abstract from textures/buffers etc, you have just memory.

A deferred render pipeline works like this:

1. render all the position information (which pixel represents a world position) to a buffer , called g-buffer.

2. now apply lot of post-processing steps, which take as input the g-buffer, calculate some effects (lighting, ssao, shadow) and write it back to some other memory block/buffer

3. finish it with a final pass, where you take all necessary input buffers (light, shadow, ssao, etc.) and compose a final image, write it to some memory block/buffer.

4. display this block/buffer

 

The trick is, that you use the memory blocks sometimes as output and sometimes as input (to make it simple first, you can't use a memory block for reading and writing at the same time!). Now, to translate this to OpenGL and a graphics API, you need to know, that accessing the memory blocks works like this:

1. if you want to read from it, you need handle it as texture.

2. if you want to write to it, you need to handle it as buffer.

3. if you want to sometimes read and sometimes to write to it, you need to handle it as texture and buffer.

4. To read from, you render a screensized quad and take as texture the input buffers. This way you get access to the memory blocks you want to read from. Then you do some crazy calculation in your shader and write the result to the attached memory in form of an attached buffer.

5. The texture and buffers are just an other way to access one and the same memory block.

 

Hope this helps.

Edited by Ashaman73

Share this post


Link to post
Share on other sites

btw if you want to copy from one render target to the other you can use glBlitFramebuffer, it does a copy operation from the GL_READ_FRAMEBUFFER to GL_DRAW_FRAMEBUFFER directly. Which means that you dont need to bind a shader, nor a VAO nor issue a draw call to do a fullscreen pass to copy the pixels.

Share this post


Link to post
Share on other sites

So in the case of a deferred render where there is no post process step and the final image is just a blend of the pixels affected by lights I can just present that to the screen directly and not need to render it to a full screen quad?

There are some missunderstandings. A deferred renderer utilize 80% of the time post-processing and you don't render to a fullscreen quad.

 

 

I'd like to clarify this above statement - where I said "post process" step I meant AFTER the light blending into the render target. E.g DOF, SSAO etc

So I meant - present the rendered image to the screen directly after blending all the light volumes into the scene

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!