10-02-2007, 06:06 AM
Hi, I'm working on understanding some sample GLSL code I was sent, but am rather inexperienced, so am just working through it one line at a time. I've come to a point where it begins generating FBOs with glGenFramebuffersEXT but I don't have much of an understanding of the exact architecture of a framebuffer and its applications. Could someone explain the basics of framebuffers to me? Is it the equivalent of a 2d array or wat? What is its relation to textures? And what does binding framebuffers do?
10-02-2007, 06:29 AM
A framebuffer is conceptually a struct with several pointers in it. These pointers indicate buffers which can be rendered to.
Usually, rendering is done to the *default* framebuffer, which has pointers to GL_FRONT and GL_BACK, and corresponds to the rendering window. You're rendering to this if glBindFramebufferEXT is never called, or if it's called with glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,0);.
However, sometimes we don't want to render directly to the screen. When that's the case, we can render to a Framebuffer Object's attachment point instead. This can point either to a "renderbuffer" or to a texture. For simplicity, let's just talk about render-to-texture.
An FBO's attachment points are:
If I want to render directly into a texture, I first need to bind an FBO, to tell OpenGL that I don't want to render to the default framebuffer. I then need to attach the texture to the FBO, with glFramebufferTexture2dEXT(). Let's say I attach it to GL_COLOR_ATTACHMENT0_EXT.
I then need to tell OpenGL that I'm interested in rendering to GL_COLOR_ATTACHMENT0_EXT within the bound FBO; that's done with glDrawBuffer().
After that, any rendering command (glBegin()/glEnd(), glDrawArrays, glClear, etc) will modify pixels in the texture rather than pixels in the drawing window. Once I'm done, I can immediately bind the texture and use it for future render commands.
Note that these render commands will be done as if I've called glDisable(GL_DEPTH_TEST) unless I create a renderbuffer with a depth format and attach it to GL_DEPTH_ATTACHMENT_EXT on the current FBO.
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.