Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ion::gfx::FramebufferObject Class Reference

A FramebufferObject describes an off-screen framebuffer that can be drawn to and read from like a regular framebuffer. More...

#include "framebufferobject.h"

Inheritance diagram for ion::gfx::FramebufferObject:
Collaboration diagram for ion::gfx::FramebufferObject:

Classes

class  Attachment
 An attachment represents a data store attached to one of the framebuffer's targets. More...
 

Public Types

enum  Changes {
  kColorAttachmentChanged = kNumBaseChanges,
  kDepthAttachmentChanged,
  kDimensionsChanged,
  kStencilAttachmentChanged,
  kNumChanges
}
 Changes that affect the resource. More...
 
enum  AttachmentBinding {
  kCubeMapTexture,
  kRenderbuffer,
  kTexture,
  kUnbound
}
 The type of binding for an Attachment. More...
 
enum  BaseChanges {
  kLabelChanged,
  kResourceChanged,
  kNumBaseChanges
}
 All ResourceHolders derived from this should start their own change enums from kNumBaseChanges. More...
 

Public Member Functions

 FramebufferObject (uint32 width, uint32 height)
 Creates a FramebufferObject with the passed dimensions and unbound attachments. More...
 
void Resize (uint32 width, uint32 height)
 Resizes the FramebufferObject to the passed dimensions. More...
 
uint32 GetWidth () const
 Gets the width of the FramebufferObject and its attachments. More...
 
uint32 GetHeight () const
 Gets the height of the FramebufferObject and its attachments. More...
 
const AttachmentGetColorAttachment (size_t i) const
 Gets and sets the i-th color Attachment. More...
 
void SetColorAttachment (size_t i, const Attachment &attachment)
 
const AttachmentGetDepthAttachment () const
 Gets and sets the depth Attachment. More...
 
void SetDepthAttachment (const Attachment &attachment)
 
const AttachmentGetStencilAttachment () const
 Gets and sets the stencil Attachment. More...
 
void SetStencilAttachment (const Attachment &attachment)
 
void SetResource (size_t index, ResourceKey key, ResourceBase *resource) const
 Sets the resource at the passed index and key. More...
 
ResourceBaseGetResource (size_t index, ResourceKey key) const
 Returns the Resource at the given index and key, or NULL if no resource was previously set at that location. More...
 
int GetResourceCount () const
 Returns the number of resources that this holder holds. More...
 
size_t GetGpuMemoryUsed () const
 Returns the total amount of GPU memory used by this Holder's resource. More...
 
const std::string & GetLabel () const
 Returns/sets the label of this. More...
 
void SetLabel (const std::string &label)
 
void AddReceiver (Notifier *receiver)
 Adds a Notifier to be notified. More...
 
void RemoveReceiver (Notifier *receiver)
 Removes a Notifier to be notified. More...
 
size_t GetReceiverCount () const
 Returns the number of Notifiers that will be notified. More...
 
const AllocatorPtr & GetAllocator () const
 Returns the Allocator that was used for the instance. More...
 
const AllocatorPtr & GetNonNullAllocator () const
 Return our allocator, or the default allocator if the instance was declared on the stack. More...
 
const AllocatorPtr & GetAllocatorForLifetime (AllocationLifetime lifetime) const
 Convenience function that returns the Allocator to use to allocate an object with a specific lifetime. More...
 
void * operator new (size_t size)
 The standard no-parameter new operator uses the default Allocator. More...
 
void * operator new (size_t size, AllocationLifetime lifetime)
 This overloaded version of the new operator uses the AllocationManager's default Allocator for the specified lifetime. More...
 
void * operator new (size_t size, const AllocatorPtr &allocator)
 This overloaded version of the new operator takes the Allocator to use directly as a parameter. More...
 
void * operator new (size_t size, const AllocatorPtr &allocator, void *ptr)
 Special operator new for using placement new with Allocatables. More...
 
void * operator new (size_t size, void *ptr)
 The placement new operator is defined conventionally. More...
 
void operator delete (void *ptr)
 Define the delete operator to use specialized functions dealing with an Allocator. More...
 
void operator delete (void *ptr, AllocationLifetime lifetime)
 Windows requires these (or it issues C4291 warnings). More...
 
void operator delete (void *ptr, const AllocatorPtr &allocator)
 
void operator delete (void *ptr, void *ptr2)
 The placement delete operator does nothing, as usual. More...
 
int GetRefCount () const
 GetRefCount() is part of the interface necessary for SharedPtr. More...
 

Static Public Member Functions

static bool IsColorRenderable (uint32 gl_format)
 Returns whether the passed GL formats are renderable. More...
 
static bool IsDepthRenderable (uint32 gl_format)
 
static bool IsStencilRenderable (uint32 gl_format)
 

Protected Types

typedef WeakReferentPtr< NotifierNotifierPtr
 
typedef AllocVector< NotifierPtrNotifierPtrVector
 

Protected Member Functions

 ~FramebufferObject () override
 The destructor is protected because all base::Referent classes must have protected or private destructors. More...
 
void OnChanged (int bit) const
 Forwards OnChanged to all resources. More...
 
const NotifierPtrVectorGetReceivers () const
 Returns the set of Notifiers that will be notified. More...
 
void Notify () const
 Notifies all contained Notifiers by calling their OnNotify(). More...
 

Detailed Description

A FramebufferObject describes an off-screen framebuffer that can be drawn to and read from like a regular framebuffer.

While the FramebufferObject is active, nothing is drawn to the screen; all draw commands draw into its Attachments.

An Attachment can be in one of three states, unbound, bound to a renderbuffer, or bound to a texture. If an attachment is unbound any data written into it is discarded. For example, if a FramebufferObject has no depth attachment then there is effectively no depth buffer.

If an Attachment is bound to a renderbuffer, Ion will allocate an internal data store (the renderbuffer) on the graphics hardware. The only way to get the data back after a draw call is through a ReadPixels command, though rendering may (depending on the platform) be faster than with a texture binding.

If an Attachment is bound to a texture, then the passed TexturePtr is used as the target for all draw commands sent to the Attachment. The Texture must contain an Image (which may have NULL data) to specify the format of the framebuffer. The Texture can then be used, for example, as a Uniform input to a shader (a sampler). Note that not all platforms support binding textures to depth and stencil Attachments. If a particular texture format is unsupported, then the Attachment will be created as unbound.

Definition at line 54 of file framebufferobject.h.

Member Typedef Documentation

Definition at line 49 of file notifier.h.

typedef AllocVector<NotifierPtr> ion::base::Notifier::NotifierPtrVector
protectedinherited

Definition at line 50 of file notifier.h.

Member Enumeration Documentation

The type of binding for an Attachment.

Enumerator
kCubeMapTexture 
kRenderbuffer 
kTexture 
kUnbound 

Definition at line 66 of file framebufferobject.h.

All ResourceHolders derived from this should start their own change enums from kNumBaseChanges.

Enumerator
kLabelChanged 
kResourceChanged 
kNumBaseChanges 

Definition at line 56 of file resourceholder.h.

Changes that affect the resource.

Enumerator
kColorAttachmentChanged 
kDepthAttachmentChanged 
kDimensionsChanged 
kStencilAttachmentChanged 
kNumChanges 

Definition at line 57 of file framebufferobject.h.

Constructor & Destructor Documentation

ion::gfx::FramebufferObject::FramebufferObject ( uint32  width,
uint32  height 
)

Creates a FramebufferObject with the passed dimensions and unbound attachments.

Definition at line 152 of file framebufferobject.cc.

References ion::port::ERROR, and LOG.

ion::gfx::FramebufferObject::~FramebufferObject ( )
overrideprotected

The destructor is protected because all base::Referent classes must have protected or private destructors.

Definition at line 163 of file framebufferobject.cc.

Member Function Documentation

void ion::base::Notifier::AddReceiver ( Notifier receiver)
inherited

Adds a Notifier to be notified.

Does nothing if the receiver is NULL or is already in the receiver vector.

Definition at line 25 of file notifier.cc.

const AllocatorPtr& ion::base::Allocatable::GetAllocator ( ) const
inlineinherited

Returns the Allocator that was used for the instance.

This will be NULL if the instance was declared on the stack or created with normal placement new.

Definition at line 68 of file allocatable.h.

References allocator_.

Referenced by ion::base::DataContainer::CreateAndCopy(), ion::text::DynamicFontImage::FindContainingImageDataIndex(), and ion::text::DynamicFontImage::FindImageDataIndex().

const AllocatorPtr& ion::base::Allocatable::GetAllocatorForLifetime ( AllocationLifetime  lifetime) const
inlineinherited
const Attachment& ion::gfx::FramebufferObject::GetColorAttachment ( size_t  i) const
inline

Gets and sets the i-th color Attachment.

For now, only a single color attachment is supported.

Todo:
(user): Support multiple color attachments.

Definition at line 163 of file framebufferobject.h.

References DCHECK_EQ.

const Attachment& ion::gfx::FramebufferObject::GetDepthAttachment ( ) const
inline

Gets and sets the depth Attachment.

Definition at line 169 of file framebufferobject.h.

size_t ion::gfx::ResourceHolder::GetGpuMemoryUsed ( ) const
inlineinherited

Returns the total amount of GPU memory used by this Holder's resource.

Definition at line 78 of file resourceholder.h.

uint32 ion::gfx::FramebufferObject::GetHeight ( ) const
inline

Gets the height of the FramebufferObject and its attachments.

Definition at line 158 of file framebufferobject.h.

const std::string& ion::gfx::ResourceHolder::GetLabel ( ) const
inlineinherited

Returns/sets the label of this.

Definition at line 89 of file resourceholder.h.

const AllocatorPtr& ion::base::Allocatable::GetNonNullAllocator ( ) const
inlineinherited

Return our allocator, or the default allocator if the instance was declared on the stack.

Definition at line 72 of file allocatable.h.

References allocator_, and ion::base::AllocationManager::GetNonNullAllocator().

size_t ion::base::Notifier::GetReceiverCount ( ) const
inherited

Returns the number of Notifiers that will be notified.

Definition at line 71 of file notifier.cc.

const Notifier::NotifierPtrVector & ion::base::Notifier::GetReceivers ( ) const
protectedinherited

Returns the set of Notifiers that will be notified.

Definition at line 77 of file notifier.cc.

int ion::base::Shareable::GetRefCount ( ) const
inlineinherited

GetRefCount() is part of the interface necessary for SharedPtr.

Definition at line 34 of file shareable.h.

Referenced by ion::base::Notifier::RemoveReceiver().

ResourceBase * ion::gfx::ResourceHolder::GetResource ( size_t  index,
ResourceKey  key 
) const
inherited

Returns the Resource at the given index and key, or NULL if no resource was previously set at that location.

Definition at line 122 of file resourceholder.cc.

int ion::gfx::ResourceHolder::GetResourceCount ( ) const
inlineinherited

Returns the number of resources that this holder holds.

Note that this is not necessarily the number of indices that have non-NULL resources. This can be used as a fast trivial check to see if the holder has any resources.

Definition at line 73 of file resourceholder.h.

const Attachment& ion::gfx::FramebufferObject::GetStencilAttachment ( ) const
inline

Gets and sets the stencil Attachment.

Definition at line 172 of file framebufferobject.h.

uint32 ion::gfx::FramebufferObject::GetWidth ( ) const
inline

Gets the width of the FramebufferObject and its attachments.

Definition at line 156 of file framebufferobject.h.

bool ion::gfx::FramebufferObject::IsColorRenderable ( uint32  gl_format)
static

Returns whether the passed GL formats are renderable.

Definition at line 187 of file framebufferobject.cc.

bool ion::gfx::FramebufferObject::IsDepthRenderable ( uint32  gl_format)
static

Definition at line 207 of file framebufferobject.cc.

bool ion::gfx::FramebufferObject::IsStencilRenderable ( uint32  gl_format)
static

Definition at line 213 of file framebufferobject.cc.

void ion::base::Notifier::Notify ( ) const
protectedinherited

Notifies all contained Notifiers by calling their OnNotify().

Any receivers that have been destroyed will be removed from the vector of receivers.

Definition at line 81 of file notifier.cc.

References ion::base::SharedPtr< T >::Get().

void ion::gfx::ResourceHolder::OnChanged ( int  bit) const
inlineprotectedinherited

Forwards OnChanged to all resources.

Definition at line 326 of file resourceholder.h.

void ion::base::Allocatable::operator delete ( void *  ptr)
inlineinherited

Define the delete operator to use specialized functions dealing with an Allocator.

Definition at line 109 of file allocatable.h.

void ion::base::Allocatable::operator delete ( void *  ptr,
AllocationLifetime  lifetime 
)
inlineinherited

Windows requires these (or it issues C4291 warnings).

Definition at line 112 of file allocatable.h.

void ion::base::Allocatable::operator delete ( void *  ptr,
const AllocatorPtr allocator 
)
inlineinherited

Definition at line 113 of file allocatable.h.

void ion::base::Allocatable::operator delete ( void *  ptr,
void *  ptr2 
)
inlineinherited

The placement delete operator does nothing, as usual.

Definition at line 118 of file allocatable.h.

void* ion::base::Allocatable::operator new ( size_t  size)
inlineinherited

The standard no-parameter new operator uses the default Allocator.

Definition at line 84 of file allocatable.h.

void* ion::base::Allocatable::operator new ( size_t  size,
AllocationLifetime  lifetime 
)
inlineinherited

This overloaded version of the new operator uses the AllocationManager's default Allocator for the specified lifetime.

Definition at line 88 of file allocatable.h.

void* ion::base::Allocatable::operator new ( size_t  size,
const AllocatorPtr allocator 
)
inlineinherited

This overloaded version of the new operator takes the Allocator to use directly as a parameter.

If the Allocator pointer is NULL, this uses the default Allocator.

Definition at line 95 of file allocatable.h.

void* ion::base::Allocatable::operator new ( size_t  size,
const AllocatorPtr allocator,
void *  ptr 
)
inlineinherited

Special operator new for using placement new with Allocatables.

Definition at line 100 of file allocatable.h.

void* ion::base::Allocatable::operator new ( size_t  size,
void *  ptr 
)
inlineinherited

The placement new operator is defined conventionally.

Definition at line 105 of file allocatable.h.

void ion::base::Notifier::RemoveReceiver ( Notifier receiver)
inherited

Removes a Notifier to be notified.

Does nothing if the receiver is NULL or not in the set of receivers.

Definition at line 38 of file notifier.cc.

References ion::base::Shareable::GetRefCount().

Referenced by ion::gfx::AttributeArray::~AttributeArray().

void ion::gfx::FramebufferObject::Resize ( uint32  width,
uint32  height 
)

Resizes the FramebufferObject to the passed dimensions.

Definition at line 169 of file framebufferobject.cc.

void ion::gfx::FramebufferObject::SetColorAttachment ( size_t  i,
const Attachment attachment 
)

Definition at line 174 of file framebufferobject.cc.

References DCHECK_EQ.

void ion::gfx::FramebufferObject::SetDepthAttachment ( const Attachment attachment)

Definition at line 179 of file framebufferobject.cc.

void ion::gfx::ResourceHolder::SetLabel ( const std::string &  label)
inlineinherited

Definition at line 90 of file resourceholder.h.

void ion::gfx::ResourceHolder::SetResource ( size_t  index,
ResourceKey  key,
ResourceBase resource 
) const
inherited

Sets the resource at the passed index and key.

The size of the internal vector is automatically managed so that it has the smallest possible size.

Definition at line 51 of file resourceholder.cc.

References DCHECK, DCHECK_EQ, ion::gfx::ResourceBase::GetKey(), and ion::gfx::ResourceBase::OnChanged().

void ion::gfx::FramebufferObject::SetStencilAttachment ( const Attachment attachment)

Definition at line 183 of file framebufferobject.cc.


The documentation for this class was generated from the following files: