G3D::Framebuffer Class ReferenceAbstraction of OpenGL's Framebuffer Object extension.
More...
#include <Framebuffer.h>
Inherits G3D::ReferenceCountedObject.
List of all members.
|
Public Types |
| enum | AttachmentPoint {
COLOR_ATTACHMENT0 = 0x8CE0,
COLOR_ATTACHMENT1 = 0x8CE1,
COLOR_ATTACHMENT2 = 0x8CE2,
COLOR_ATTACHMENT3 = 0x8CE3,
COLOR_ATTACHMENT4 = 0x8CE4,
COLOR_ATTACHMENT5 = 0x8CE5,
COLOR_ATTACHMENT6 = 0x8CE6,
COLOR_ATTACHMENT7 = 0x8CE7,
COLOR_ATTACHMENT8 = 0x8CE8,
COLOR_ATTACHMENT9 = 0x8CE9,
COLOR_ATTACHMENT10 = 0x8CEA,
COLOR_ATTACHMENT11 = 0x8CEB,
COLOR_ATTACHMENT12 = 0x8CEC,
COLOR_ATTACHMENT13 = 0x8CED,
COLOR_ATTACHMENT14 = 0x8CEE,
COLOR_ATTACHMENT15 = 0x8CEF,
DEPTH_ATTACHMENT = 0x8D00,
STENCIL_ATTACHMENT = 0x8D20
} |
Public Member Functions |
| bool | has (AttachmentPoint ap) const |
| int | height () const |
| const std::string & | name () const |
| unsigned int | openGLID () const |
| Rect2D | rect2DBounds () const |
| void | ReferenceCountedObject_zeroWeakPointers () |
| void | set (AttachmentPoint ap, const RenderbufferRef &renderbuffer) |
| void | set (AttachmentPoint ap, const Texture::Ref &texture) |
| void | set (AttachmentPoint ap, const void *n) |
| Vector2 | vector2Bounds () const |
| int | width () const |
| | ~Framebuffer () |
Static Public Member Functions |
| static FramebufferRef | create (const std::string &name) |
| static FramebufferRef | fromGLFramebuffer (const std::string &name, GLuint framebufferID) |
Public Attributes |
| AtomicInt32 | ReferenceCountedObject_refCount |
| _WeakPtrLinkedList * | ReferenceCountedObject_weakPointer |
Classes |
| class | Attachment |
Detailed Description
Abstraction of OpenGL's Framebuffer Object extension.
This is a fast and efficient way of rendering to textures. This class can be used with raw OpenGL, without RenderDevice or SDL.
Basic Framebuffer Theory: Every OpenGL program has at least one Framebuffer. This framebuffer is setup by the windowing system and its image format is that specified by the OS. With the Framebuffer Object extension, OpenGL gives the developer the ability to create offscreen framebuffers that can be used to render to textures of any specified format. The Framebuffer class is used in conjunction with the RenderDevice to set a render target. The RenderDevice method setFramebuffer performs this action. If a NULL argument is passed to setFramebuffer, the render target defaults to the window display framebuffer. Framebuffer works in conjunction with the push/pop RenderDevice state, but in a limited form. The state will save the current Framebuffer, but will not save the state of the Framebuffer itself. If the attachment points are changed in the push/pop block, these will not be restored by a pop. The following example shows how to create a texture and bind it to Framebuffer for rendering.
Framebuffer Example:
Create Texture
static Texture::Ref tex = Texture::createEmpty(256, 256, "Rendered Texture", TextureFormat::RGB8, Texture::CLAMP, Texture::NEAREST_NO_MIPMAP, Texture::DIM_2D);
Create a framebuffer that uses this texture as the color buffer
static FramebufferRef fb = Framebuffer::create("Offscreen target");
bool init = false;
if (! init) {
fb->set(Framebuffer::COLOR_ATTACHMENT0, tex);
init = true;
}
rd->pushState();
rd->setFramebuffer(fb);
rd->push2D(fb->rect2DBounds());
Set framebuffer as the render target
Draw on the texture
Draw::rect2D(Rect2D::xywh(0,0,128,256), rd, Color3::white());
Draw::rect2D(Rect2D::xywh(128,0,128,256), rd, Color3::red());
Restore renderdevice state (old frame buffer)
rd->pop2D();
rd->popState();
app->renderDevice->setProjectionAndCameraMatrix(app->debugCamera);
Remove the texture from the framebuffer
fb->set(Framebuffer::COLOR_ATTACHMENT0, NULL);
Can now render from the texture
Cyan background
app->renderDevice->setColorClearValue(Color3(.1f, .5f, 1));
app->renderDevice->clear();
app->renderDevice->push2D();
rd->setTexture(0, tex);
Draw::rect2D(Rect2D::xywh(10,10,256,256), rd);
app->renderDevice->pop2D();
In addition to Textures, Renderbuffers may also be bound to the Framebuffer. This is done in a very similar manner to the Texture object in the example. Renderbuffer class contains an example of this operation.
Note: Not any combination of images may be attached to a Framebuffer. OpenGL lays out some restrictions that must be considered:
-
In order to render to a Framebuffer, there must be at least one image (Renderbuffer or Texture) attached to an attachment point.
-
All images must have the same height and width.
-
All images attached to a COLOR_ATTACHMENT[n] point must have the same internal format (RGBA8, RGBA16...etc)
-
If RenderDevice->setDrawBuffer is used then the specified attachment point must have a bound image.
-
The combination of internal formats of attached images does not violate some implementation-dependent set of restrictions (i.e., Your graphics card must completely implement all combinations that you plan to use!)
If you create a Framebuffer with a single, depth Renderbuffer attached (e.g., for shadow map rendering) it is complete in the OpenGL sense, however you will receive a completeness error because the glDrawBuffer and glReadBuffer attached to that Framebuffer have incorrect defaults. To fix this, call glDrawBuffer(GL_NONE);glReadBuffer(GL_NONE); after binding the Framebuffer to the RenderDevice but before rendering.
BETA API -- Subject to change
Member Enumeration Documentation
Specifies which channels of the framebuffer the renderbuffer or texture will define.
These mirror the OpenGL definition as do their values.
A DEPTH_STENCIL format renderbuffer or texture can be attached to either the DEPTH_ATTACHMENT or the STENCIL_ATTACHMENT, or both simultaneously; Framebuffer will understand the format and use the appropriate channels. - Enumerator:
-
| COLOR_ATTACHMENT0 |
|
| COLOR_ATTACHMENT1 |
|
| COLOR_ATTACHMENT2 |
|
| COLOR_ATTACHMENT3 |
|
| COLOR_ATTACHMENT4 |
|
| COLOR_ATTACHMENT5 |
|
| COLOR_ATTACHMENT6 |
|
| COLOR_ATTACHMENT7 |
|
| COLOR_ATTACHMENT8 |
|
| COLOR_ATTACHMENT9 |
|
| COLOR_ATTACHMENT10 |
|
| COLOR_ATTACHMENT11 |
|
| COLOR_ATTACHMENT12 |
|
| COLOR_ATTACHMENT13 |
|
| COLOR_ATTACHMENT14 |
|
| COLOR_ATTACHMENT15 |
|
| DEPTH_ATTACHMENT |
|
| STENCIL_ATTACHMENT |
|
Constructor & Destructor Documentation
| G3D::Framebuffer::~Framebuffer |
( |
|
) |
|
Reclaims OpenGL ID.
All buffers/textures are automatically detacted on destruction.
Member Function Documentation
| static FramebufferRef G3D::Framebuffer::create |
( |
const std::string & |
name |
) |
[static] |
Creates a framebuffer object from scratch.
- Parameters:
-
| static FramebufferRef G3D::Framebuffer::fromGLFramebuffer |
( |
const std::string & |
name, |
|
|
GLuint |
framebufferID | |
|
) |
| | [static] |
Creates a framebuffer object from an OpenGL context.
- Parameters:
-
| name | Name of framebuffer |
| framebufferID | OpenGL id of ramebuffer |
Returns true if this attachment is currently non-null.
| int G3D::Framebuffer::height |
( |
|
) |
const [inline] |
Gets the OpenGL ID of the framebuffer object.
| const std::string& G3D::Framebuffer::name |
( |
|
) |
const [inline] |
| unsigned int G3D::Framebuffer::openGLID |
( |
|
) |
const [inline] |
Gets the OpenGL ID of the framebuffer object.
| Rect2D G3D::Framebuffer::rect2DBounds |
( |
|
) |
const [inline] |
| void G3D::ReferenceCountedObject::ReferenceCountedObject_zeroWeakPointers |
( |
|
) |
[inline, inherited] |
Automatically called immediately before the object is deleted.
This is not called from the destructor because it needs to be invoked before the subclass destructor.
Set one of the attachment points to reference a renderbuffer.
Set to NULL to unset.
- Parameters:
-
| renderbuffer | Renderbuffer to bind to the framebuffer |
| slot | Attachment point to bind renderbuffer to. |
Set one of the attachment points to reference a texture.
Set to NULL to unset. Auto-mipmap will automatically be disabled on set. It will be re-enabled when the texture is unbound.
Do not use a texture that is bound to the *current* framebuffer for rendering, however, you can render using a texture that is bound on a different frame buffer.
- Parameters:
-
| texture | Texture to bind to the framebuffer. |
| ap | Attachment point to bind texture to. |
Overload used when setting attachment points to NULL.
| Vector2 G3D::Framebuffer::vector2Bounds |
( |
|
) |
const [inline] |
| int G3D::Framebuffer::width |
( |
|
) |
const [inline] |
Member Data Documentation
The long name is to keep this from accidentally conflicting with a subclass's variable name.
Do not use or explicitly manipulate this value--its type may change in the future and is not part of the supported API.
Linked list of all weak pointers that reference this (some may be on the stack!).
Do not use or explicitly manipulate this value.
The documentation for this class was generated from the following file:
Generated on Thu Aug 2 11:40:45 2007 for G3D by
1.5.2
Hosted by
|