All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
kanzi::Framebuffer Class Reference

Framebuffer allows the rendering to the user-specified texture or renderbuffer, instead of rendering directly to the window. More...

#include <kanzi/graphics_3d/framebuffer.hpp>

Inheritance diagram for kanzi::Framebuffer:
kanzi::GPUResource kanzi::Resource kanzi::Object

Public Types

enum  Attachment {
  AttachmentColor0, AttachmentColor1, AttachmentColor2, AttachmentColor3,
  AttachmentDepthStencil, AttachmentCount
}
 

Public Member Functions

 Framebuffer (Domain *domain, string_view name="")
 
virtual ~Framebuffer () KZ_OVERRIDE
 
bool isRenderable (unsigned int face, unsigned int mipLevel) const
 
void configure (unsigned int width, unsigned int height, unsigned int faceCount, unsigned int sampleCount, unsigned int mipLevelCount)
 Sets the common dimensions and sample count for the framebuffer. More...
 
TextureSharedPtr addTexture (Attachment attachment, Texture::Target target, GraphicsFormat format, Sampler::Filter minFilter, Sampler::Filter magFilter, Sampler::MipmapMode mipmapMode, Sampler::AddressingMode address)
 Creates a texture and attaches it to the framebuffer. More...
 
RenderbufferSharedPtr addRenderbuffer (Attachment attachment, GraphicsFormat format)
 Adds a renderbuffer attachment to the framebuffer. More...
 
void setAttachment (Attachment attachment, SurfaceSharedPtr surface)
 Sets the attachment for the framebuffer. More...
 
SurfaceSharedPtr getAttachment (Attachment attachment) const
 Returns the attachment from the framebuffer for the specified attachment point. More...
 
TextureSharedPtr getTexture (Attachment attachment) const
 Returns the attachment as texture from the framebuffer. More...
 
unsigned int getWidth () const
 Returns the common width of the framebuffer. More...
 
unsigned int getHeight () const
 Returns the common height of the framebuffer. More...
 
unsigned int getFaceCount () const
 Returns the face count of the framebuffer. More...
 
unsigned int getSampleCount () const
 Returns the common sample count of the framebuffer. More...
 
unsigned int getMipLevelCount () const
 Returns the number of mipmap levels in the framebuffer. More...
 
unsigned int getGLHandle (unsigned int face, unsigned int mipLevel) const
 Returns the GL API object handle for a specific (face, mipLevel) pair in the framebuffer. More...
 
void bind (unsigned int face, unsigned int mipLevel)
 Binds the framebuffer for both reading and writing. More...
 
void unbind ()
 Unbinds the framebuffer. Rendering continues to the default framebuffer (window). More...
 
virtual void loadFromKZB (const KzuResourceLoaderThreadContext *threadContext, KzcInputStream *inputStream, const KzuBinaryFileInfo *file) KZ_OVERRIDE
 Function for loading the resource from .KZB. More...
 
- Public Member Functions inherited from kanzi::GPUResource
virtual ~GPUResource () KZ_OVERRIDE
 
void deploy ()
 Make graphics API object(s) in the resource usable by preparing GPU objects and data in them. More...
 
void undeploy ()
 Free the GPU objects. After this, the resource is not usable for graphics API until deploy() is called again. More...
 
void invalidate ()
 Notify resource that graphics context was lost and all GPU resources are invalid. More...
 
unsigned int getGPUMemoryUsage () const
 
RenderergetRenderer () const
 
bool getDeployOnLoad () const
 Returns true if GPUResource is automatically deployed when loaded. More...
 
void setDeployOnLoad (bool value)
 Sets GPUResource automatic deployment on loade on or orr. More...
 
bool isDeployed () const
 
void deployed ()
 
void undeployed ()
 
virtual void finishLoadingOverride (const KzuResourceLoaderThreadContext *threadContext) KZ_OVERRIDE
 Function for finishing the loading of the resource. More...
 
virtual void unloadOverride () KZ_OVERRIDE
 Unload function for resource. More...
 
virtual unsigned int getCPUMemoryUsage () const KZ_OVERRIDE
 Function for getting the memory usage of a resource. More...
 
- Public Member Functions inherited from kanzi::Resource
KzcMemoryManagergetMemoryManager () const
 
 Resource (Domain *domain, string_view name)
 
virtual ~Resource ()
 
void setKZB (const KzuBinaryDirectory *binaryDirectory, kzString path)
 
void setLoaded ()
 
kzString getName () const
 Accessor. More...
 
void load ()
 
void unload ()
 
bool isLoaded () const
 
void kzuResourceLoad_private (const KzuResourceLoaderThreadContext *threadContext)
 Private function for kzuResourceLoad() with specified thread context. More...
 
void kzuResourceFinishLoading_private (const KzuResourceLoaderThreadContext *threadContext)
 Private function for finishing the loading of the resource. More...
 
KzuResourceLoadingStrategy getLoadingStrategy () const
 
void setLoadingStrategy (KzuResourceLoadingStrategy loadingStrategy)
 
bool getKeepAlive () const
 Tells if the resource has keep alive flag set. More...
 
void setKeepAlive (bool keepAlive)
 Sets the keep alive flag. More...
 
- Public Member Functions inherited from kanzi::Object
 Object (Domain *domain)
 
virtual ~Object ()
 
DomaingetDomain () const
 Returns the domain the object belongs to. More...
 
KzuPropertyManager * getPropertyManager () const
 Returns the property manager of the object. More...
 
KzuTaskSchedulergetTaskScheduler () const
 Returns the task scheduler of the object. More...
 
KzuMessageDispatchergetMessageDispatcher () const
 Returns the message dispatcher of the object. More...
 
ResourceManagergetResourceManager () const
 Returns the resource manager of the object. More...
 
virtual const MetaclassgetDynamicMetaclass () const
 Returns the metaclass of the dynamic type of the object. More...
 
bool isTypeOf (const Metaclass *objectType) const
 Determines if the type of this object is the given type or derived from it. More...
 
template<typename DataType >
void setProperty (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::DataType value)
 Sets the local value of a property. More...
 
void setProperty (const PropertyType< ResourceID > &propertyType, ResourceSharedPtr value)
 Sets the local value of a resource id property with a resource pointer. More...
 
template<typename DataType >
DataType getProperty (const PropertyType< DataType > &propertyType) const
 Returns the current value of a property. More...
 
template<typename DataType >
bool getProperty (const PropertyType< DataType > &propertyType, typename PropertyType< DataType >::DataType &value) const
 Evaluates the property value in the same way as the overload above but does not default to the value in property metadata if there are no inputs to the property value. More...
 
template<typename DataType >
void setAbstractProperty (AbstractPropertyType abstractPropertyType, typename PropertyType< DataType >::DataType value)
 
void setAbstractProperty (AbstractPropertyType abstractPropertyType, ResourceSharedPtr value)
 
template<typename DataType >
DataType getAbstractProperty (AbstractPropertyType abstractPropertyType) const
 
template<typename DataType >
bool getAbstractProperty (AbstractPropertyType abstractPropertyType, typename PropertyType< DataType >::DataType &value) const
 
bool hasValue (AbstractPropertyType propertyType) const
 Evaluates whether there are any inputs into the property value. More...
 
bool hasLocalValue (AbstractPropertyType propertyType) const
 Evaluates whether there is a local value set for the property. More...
 
void removeLocalValue (AbstractPropertyType propertyType)
 Removes the local value associated with the property. More...
 
void copyLocalValues (const Object &other)
 Copies all local values from another object. More...
 
virtual void onPropertyChanged (AbstractPropertyType propertyType, KzuPropertyNotificationReason reason)
 Virtual function to handle property change notifications. More...
 
AppliedStyleEntryapplyObjectStyle (kanzi::StyleSharedPtr style)
 Applies a style to an object. More...
 
void unapplyObjectStyle (AppliedStyleEntry *appliedStyleEntry)
 
void applyObjectStyles ()
 Apply all styles for an object node. More...
 
void unapplyObjectStyles ()
 Unapplies and removes all applied styles. More...
 

Static Public Member Functions

static FramebufferSharedPtr createEmpty (Domain *domain, string_view name="")
 Creates the framebuffer without specifying the shape. More...
 
static FramebufferSharedPtr create (Domain *domain, unsigned int width, unsigned int height, bool depth, string_view name="")
 Creates the framebuffer of specified size and R8G8B8A8_UNORM color attachment to it and optionally a depth attachment. More...
 
- Static Public Member Functions inherited from kanzi::Object
static const MetaclassgetStaticMetaclass ()
 Returns the metaclass of Object class. More...
 
static
PropertyTypeEditorInfoSharedPtr 
makeEditorInfo ()
 Default implementation that returns empty editor info. More...
 

Protected Member Functions

virtual void invalidateOverride () KZ_OVERRIDE
 Notify resource that graphics context was lost and all GPU resources are invalid. Called by invalidate() More...
 
virtual void deployOverride () KZ_OVERRIDE
 Make graphics API object(s) in the resource usable by preparing GPU objects and data in them. Called by deploy() More...
 
virtual void undeployOverride () KZ_OVERRIDE
 Free the GPU objects. After this, the resource is not usable for graphics API until deploy() is called again. Called by undeploy() More...
 
virtual void freeCommonData () KZ_OVERRIDE
 Notify resource that graphics context was lost and all GPU resources are invalid. More...
 
- Protected Member Functions inherited from kanzi::GPUResource
 GPUResource (Domain *domain, string_view name="")
 
virtual unsigned int getGPUMemoryUsageOverride () const
 
- Protected Member Functions inherited from kanzi::Resource
KzuResourceLoadState getLoadState ()
 Access. More...
 
- Protected Member Functions inherited from kanzi::Object
void initialize ()
 
void onCopy (const Object &other)
 

Additional Inherited Members

- Protected Types inherited from kanzi::Object
typedef vector
< AppliedStyleEntry * > 
AppliedStyleContainer
 Applied style container. More...
 
- Protected Attributes inherited from kanzi::Object
AppliedStyleContainer m_appliedStyles
 Listing of applied styles applied to this object. More...
 

Detailed Description

Framebuffer allows the rendering to the user-specified texture or renderbuffer, instead of rendering directly to the window.

Framebuffer must have at least one Surface (Texture or Renderbuffer) attached to it. Depth and stencil tests require that a Surface (typically Renderbuffer) is attached to the depth and stencil attachment point.

Member Enumeration Documentation

Enumerator
AttachmentColor0 

Color buffer 0 framebuffer attachment point (OpenGL ES 2 compatible)

AttachmentColor1 

Color buffer 1 framebuffer attachment point (Requires OpenGL ES 3)

AttachmentColor2 

Color buffer 2 framebuffer attachment point (Requires OpenGL ES 3)

AttachmentColor3 

Color buffer 3 framebuffer attachment point (Requires OpenGL ES 3)

AttachmentDepthStencil 

Depth and stencil framebuffer attachment point.

AttachmentCount 

Constructor & Destructor Documentation

kanzi::Framebuffer::Framebuffer ( Domain domain,
string_view  name = "" 
)
explicit
virtual kanzi::Framebuffer::~Framebuffer ( )
virtual

Member Function Documentation

static FramebufferSharedPtr kanzi::Framebuffer::createEmpty ( Domain domain,
string_view  name = "" 
)
static

Creates the framebuffer without specifying the shape.

You must configure the framebuffer with the configure() function, it needs one or more textures or renderbuffers to be attached to it, and you must deploy it before you can use it.

Returns
The created empty framebuffer
static FramebufferSharedPtr kanzi::Framebuffer::create ( Domain domain,
unsigned int  width,
unsigned int  height,
bool  depth,
string_view  name = "" 
)
static

Creates the framebuffer of specified size and R8G8B8A8_UNORM color attachment to it and optionally a depth attachment.

The framebuffer is deployed and ready to use.

Parameters
domainDomain for the graphics resource
widthWidth of the framebuffer
heightHeight of the framebuffer
depthWhen true, a D24_UNORM_S8_UINT depth and stencil renderbuffer are created and attached to the framebuffer.
Returns
The created framebuffer
bool kanzi::Framebuffer::isRenderable ( unsigned int  face,
unsigned int  mipLevel 
) const
void kanzi::Framebuffer::configure ( unsigned int  width,
unsigned int  height,
unsigned int  faceCount,
unsigned int  sampleCount,
unsigned int  mipLevelCount 
)

Sets the common dimensions and sample count for the framebuffer.

These are used by new attachments created with the addTexture() and addRenderbuffer() functions.

Parameters
widthWidth of the framebuffer
heightHeight of the framebuffer
faceCountNumber of faces. Must be 6 for cubemap framebuffers and 1 for all other framebuffers.
mipLevelCountNumber of mipmap levels. Must be at least one.
TextureSharedPtr kanzi::Framebuffer::addTexture ( Attachment  attachment,
Texture::Target  target,
GraphicsFormat  format,
Sampler::Filter  minFilter,
Sampler::Filter  magFilter,
Sampler::MipmapMode  mipmapMode,
Sampler::AddressingMode  address 
)

Creates a texture and attaches it to the framebuffer.

Contents of the texture are not defined, it is expected that the texture is not sampled until framebuffer has been rendered to. The added texture is not deployed. It is expected that framebuffer is deployed after surfaces have been attached to it, and this will deploy all surfaces attached to it.

Note
Not every GraphicsFormat can be rendered to.
Parameters
attachmentAttachment point for the texture. For OpenGL ES 2, use either Framebuffer::AttachmentColor0 or Framebuffer::AttachmentDepthStencil.
targetTexture target. For OpenGL ES 2, use either Texture::TargetTwoDimensional or Texture::TargetCubeMap, and possibly Texture::TargetExternal if the required extension is supported.
formatFormat for the texture
minFilterMinification filter for the texture
magFilterMagnification filter for the texture
mipmapModeMipmap mode for the texture. Texture will only get mipmap images if mipmap mode given here needs mipmap images.
addressAddressing mode for the texture
Returns
Newly created texture which is attached to the framebuffer. The texture is not yet deployed.
RenderbufferSharedPtr kanzi::Framebuffer::addRenderbuffer ( Attachment  attachment,
GraphicsFormat  format 
)

Adds a renderbuffer attachment to the framebuffer.

Note
Not every GraphicsFormat can be rendered to.
Parameters
attachemntAttachment point for the renderbuffer. For OpenGL ES 2, use either Framebuffer::AttachmentColor0 or Framebuffer::AttachmentDepthStencil.
formatFormat for the renderbuffer.
Returns
Newly created renderbuffer which is attached to the framebuffer.
void kanzi::Framebuffer::setAttachment ( Attachment  attachment,
SurfaceSharedPtr  surface 
)

Sets the attachment for the framebuffer.

You can attach textures and renderbuffers to framebuffer. Note that not every GraphicsFormat can be rendered to, so not all textures be rendered to.

Parameters
attachmentAttachment point for the surface. For OpenGL ES 2, use either Framebuffer::AttachmentColor0 or Framebuffer::AttachmentDepthStencil.
surfaceSurface to attach to the framebuffer (either Texture or Renderbuffer)
SurfaceSharedPtr kanzi::Framebuffer::getAttachment ( Attachment  attachment) const

Returns the attachment from the framebuffer for the specified attachment point.

Parameters
attachmentAttachment point to examine
Returns
The attachment for the specified attachment point in the framebuffer
TextureSharedPtr kanzi::Framebuffer::getTexture ( Attachment  attachment) const

Returns the attachment as texture from the framebuffer.

Parameters
attachmentAttachment point to query from the framebuffer. For OpenGL ES 2, either Framebuffer::AttachmentColor0 or Framebuffer::AttachmentDepthStencil.
Returns
Texture attached to the specified attachment point, or empty if there is no texture.
unsigned int kanzi::Framebuffer::getWidth ( ) const

Returns the common width of the framebuffer.

Returns
The width of the framebuffer in pixels
unsigned int kanzi::Framebuffer::getHeight ( ) const

Returns the common height of the framebuffer.

Returns
The height of the framebuffer in pixels
unsigned int kanzi::Framebuffer::getFaceCount ( ) const

Returns the face count of the framebuffer.

Returns
The number of faces in the framebuffer
unsigned int kanzi::Framebuffer::getSampleCount ( ) const

Returns the common sample count of the framebuffer.

Returns
The number of multisample samples in the framebuffer. In OpenGL ES 2 this is zero.
unsigned int kanzi::Framebuffer::getMipLevelCount ( ) const

Returns the number of mipmap levels in the framebuffer.

Returns
The number of mipmap levels in the framebuffer
unsigned int kanzi::Framebuffer::getGLHandle ( unsigned int  face,
unsigned int  mipLevel 
) const

Returns the GL API object handle for a specific (face, mipLevel) pair in the framebuffer.

Parameters
faceFace for the query
mipLevelMipmap level for the query
Returns
GL API framebuffer object handle
void kanzi::Framebuffer::bind ( unsigned int  face,
unsigned int  mipLevel 
)

Binds the framebuffer for both reading and writing.

After bind() is called, all rendering happens to the textures or renderbuffers that are attached to the framebuffer. To resume rendering to window (default framebuffer), call unbind().

Parameters
faceFace to bind
mipLevelMipmap level to bind
void kanzi::Framebuffer::unbind ( )

Unbinds the framebuffer. Rendering continues to the default framebuffer (window).

virtual void kanzi::Framebuffer::loadFromKZB ( const KzuResourceLoaderThreadContext threadContext,
KzcInputStream inputStream,
const KzuBinaryFileInfo file 
)
virtual

Function for loading the resource from .KZB.

This function is called when loading the data from .KZB file. Implementations should call super class loadFromKZB before reading anything else from inputStream. This function is called from arbitrary loading threads. The parameter threadContext contains thread safe memory manager and a thread specific Property manager which can be locked with the threadLock in the threadContext. This function may not access resource manager or the UIDomain due to race conditions.

Reimplemented from kanzi::GPUResource.

virtual void kanzi::Framebuffer::invalidateOverride ( )
protectedvirtual

Notify resource that graphics context was lost and all GPU resources are invalid. Called by invalidate()

Reimplemented from kanzi::GPUResource.

virtual void kanzi::Framebuffer::deployOverride ( )
protectedvirtual

Make graphics API object(s) in the resource usable by preparing GPU objects and data in them. Called by deploy()

Reimplemented from kanzi::GPUResource.

virtual void kanzi::Framebuffer::undeployOverride ( )
protectedvirtual

Free the GPU objects. After this, the resource is not usable for graphics API until deploy() is called again. Called by undeploy()

Reimplemented from kanzi::GPUResource.

virtual void kanzi::Framebuffer::freeCommonData ( )
protectedvirtual

Notify resource that graphics context was lost and all GPU resources are invalid.

Reimplemented from kanzi::GPUResource.


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