Tucano
0.1
A library for rapid prototyping with modern OpenGL and GLSL
|
The Framebuffer Class holds a common and very useful OpenGL FBO. FBOs are used mainly, but certainly not only, for offscreen rendering, that is, tunneling the rendered image to a Texture instead to the screen. This is very useful for multipass effects, where the output of the first render pass is saved to a FBO Texture Attachment, that is received as input for the second pass. The second pass might render directly to the screen buffer, or yet to another Texture Attachment to serve as input for a third pass, and so on.
An FBO can hold up to a maximum number of textures (Attachments), having the restriction that all of them have the same size.
The Framebuffer Class makes FBO creation and usage very easy:
Creating a FBO with size *(w,h)* and n texture attachments.
First method:
Second method:
Third method:
You can use the create method any time you wish to recreate the fbo with different parameterss
Usually FBO are accessed as textures from the Shaders. Any Texture attachment can be handled directly as a Texture (see the Texture Tutorial for more details). It is possible to bind an Attachment and make it accessible in the Shader program with a single call:
In your Shader, the Texture will be available as a sampler. For a 2D texture for example:
However, sometimes for debugging facility it is useful to read back the pixels from a given attachment. This can be easily achieve using the readPixels methods.
To render to one specific Attachment:
where attachID is an integer to indicate the ith attachment
To render to two Attachments:
There are overloads to render up to 8 attachments, or passing a list of attachments as a reference.