OpenGL FrameBuffer Object 201
IntroductionIn the last OpenGL Framebuffer object article we covered the basic usage of an FBO for rendering to a single texture and then applying that texture some where else. However this isn’t all the FBO extension can do; indeed one of the integrated features of this extension which was touched upon briefly in the last article was that of attachment points. In this article we’ll go a little more in-depth into this aspect of the extension, first of all showing how you can use a single FBO to cycle through a number of textures to render to and finish off with using the OpenGL Shading Language to render to multiple textures at the same time via the Draw Buffers extension. One FBO and Many TexturesIn the last article we covered how to attach a texture to an FBO as a colour render target using the following function call: glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, img, 0); As you might recall, the function attaches the texture indicated by the value held in img to the currently bound FBO. In this article the point of interest is the second parameter: GL_COLOR_ATTACHMENT0_EXT. This parameter tells OpenGL to attach the texture to attachment point 0, however FBOs have many more colour attachment points which can be bound. The current specification allows for 16 attachment points (GL_COLOR_ATTACHMENT0_EXT to GL_COLOR_ATTACHMENT15_EXT) each of which can point to a separate texture attached to it. However, the number you can render to depends on whether you are running on hardware and drivers; this can be queried using the following code: GLuint maxbuffers; glGetIntergeri(GL_MAX_COLOR_ATTACHMENTS, &maxbuffers); At this point maxbuffers holds the total number of colour attachments you can attach. On current hardware available at the time of writing the value returned will be a max of 4 buffers. So, if we wanted to attach the texture indicated by img to the 2nd colour attachment point the above function call would become: glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, GL_TEXTURE_2D, img, 0); As you can see it is pretty easy to add textures, but how do we tell OpenGL where to render to? |