Overte C++ Documentation
gpu::Framebuffer Class Reference

#include <Framebuffer.h>

Collaboration diagram for gpu::Framebuffer:

Public Types

enum  BufferMask
 

Public Member Functions

void removeRenderBuffers ()
 Removes all render buffers from the current framebuffer.
 
uint32 getNumRenderBuffers () const
 
const TextureViews & getRenderBuffers () const
 
int32 setRenderBuffer (uint32 slot, const TexturePointer &texture, uint32 subresource=0)
 Sets a given render buffer slot in the framebuffer. More...
 
const TexturePointer & getRenderBuffer (uint32 slot) const
 Returns render buffer from particular slot. More...
 
uint32 getRenderBufferSubresource (uint32 slot) const
 Get subresource index for a give slot. More...
 
bool setDepthBuffer (const TexturePointer &texture, const Format &format, uint32 subresource=0)
 Sets depth render buffer. More...
 
bool setStencilBuffer (const TexturePointer &texture, const Format &format, uint32 subresource=0)
 Sets stencil render buffer. More...
 
bool setDepthStencilBuffer (const TexturePointer &texture, const Format &format, uint32 subresource=0)
 Sets the combined depth stencil render buffer. More...
 
const TexturePointer & getDepthStencilBuffer () const
 
uint32 getDepthStencilBufferSubresource () const
 
Format getDepthStencilBufferFormat () const
 
Masks getBufferMask () const
 
bool isEmpty () const
 
bool hasColor () const
 
bool hasDepthStencil () const
 
bool hasDepth () const
 
bool hasStencil () const
 
bool validateTargetCompatibility (const Texture &texture, uint32 subresource=0) const
 Checks if a texture is compatible with being a render attachment. More...
 
Vec2u getSize () const
 
uint16 getWidth () const
 
uint16 getHeight () const
 
uint16 getNumSamples () const
 
const std::string & getName () const
 
void setName (const std::string &name)
 Sets the framebuffer name. More...
 
float getAspectRatio () const
 
Stamp getDepthStamp () const
 
const std::vector< Stamp > & getColorStamps () const
 

Static Public Member Functions

static Framebuffer * create (const std::string &name)
 Creates a framebuffer with a given name. Does not create any render buffers. More...
 
static Framebuffer * create (const std::string &name, const Format &colorBufferFormat, uint16 width, uint16 height)
 Creates a framebuffer with a color render buffer. More...
 
static Framebuffer * create (const std::string &name, const Format &colorBufferFormat, const Format &depthStencilBufferFormat, uint16 width, uint16 height)
 Creates a framebuffer with a color and depth stencil render buffers. More...
 
static uint32 getMaxNumRenderBuffers ()
 
static glm::vec4 evalSubregionTexcoordTransformCoefficients (const glm::ivec2 &sourceSurface, const glm::ivec2 &destRegionSize, const glm::ivec2 &destRegionOffset=glm::ivec2(0))
 Used to get coefficients for mapping one surface to an area on the other surface. More...
 
static glm::vec4 evalSubregionTexcoordTransformCoefficients (const glm::ivec2 &sourceSurface, const glm::ivec4 &destViewport)
 Used to get coefficients for mapping one surface to an area on the other surface. More...
 
static Transform evalSubregionTexcoordTransform (const glm::ivec2 &sourceSurface, const glm::ivec2 &destRegionSize, const glm::ivec2 &destRegionOffset=glm::ivec2(0))
 Used to get transform for mapping one surface to an area on the other surface. More...
 
static Transform evalSubregionTexcoordTransform (const glm::ivec2 &sourceSurface, const glm::ivec4 &destViewport)
 Used to get transform for mapping one surface to an area on the other surface. More...
 

Public Attributes

const GPUObjectPointer gpuObject {}
 

Protected Member Functions

void updateSize (const TexturePointer &texture)
 Copy width, height and sample count from a texture. More...
 
bool assignDepthStencilBuffer (const TexturePointer &texture, const Format &format, uint32 subresource)
 Sets depth stencil buffer. More...
 

Protected Attributes

std::string _name
 Framebuffer name.
 
Stamp _depthStamp { 0 }
 
std::vector< Stamp > _colorStamps
 
TextureViews _renderBuffers
 Color render buffers.
 
TextureView _depthStencilBuffer
 Depth, stencil, or combined depth stencil rneder buffer.
 
Masks _bufferMask = 0
 Bit sum of BufferMask enums. Used to check which buffers are populated.
 
uint16 _width = 0
 Framebuffer width in pixels.
 
uint16 _height = 0
 Framebuffer height in pixels.
 
uint16 _numSamples = 0
 Number of samples per pixel. Greater than 1 when MSAA is used.
 

Detailed Description

API-independent class representing a framebuffer.

Member Enumeration Documentation

◆ BufferMask

Member Function Documentation

◆ assignDepthStencilBuffer()

bool Framebuffer::assignDepthStencilBuffer ( const TexturePointer &  texture,
const Format &  format,
uint32  subresource 
)
protected

Sets depth stencil buffer.

Parameters
textureShared pointer to a texture. Can be nullptr.
formatDepth stencil format.
subresourceSubresource index. Used when texture has multiple subresources, for example with shadow cascades.
Returns
true if depth stencil render buffer was assigned successfully.

◆ create() [1/3]

Framebuffer * Framebuffer::create ( const std::string &  name)
static

Creates a framebuffer with a given name. Does not create any render buffers.

Parameters
nameName of the framebuffer.
Returns
Pointer to the framebuffer object.

◆ create() [2/3]

Framebuffer * Framebuffer::create ( const std::string &  name,
const Format &  colorBufferFormat,
const Format &  depthStencilBufferFormat,
uint16  width,
uint16  height 
)
static

Creates a framebuffer with a color and depth stencil render buffers.

Parameters
nameName of the framebuffer.
colorBufferFormatFormat of the color render buffer to be created.
depthStencilBufferFormatFormat of the depth stencil render buffer to be created.
widthWith of the framebuffer.
heightHeight of the framebuffer.
Returns
Pointer to the framebuffer object.

◆ create() [3/3]

Framebuffer * Framebuffer::create ( const std::string &  name,
const Format &  colorBufferFormat,
uint16  width,
uint16  height 
)
static

Creates a framebuffer with a color render buffer.

Parameters
nameName of the framebuffer.
colorBufferFormatFormat of the color render buffer to be created.
widthWith of the framebuffer.
heightHeight of the framebuffer.
Returns
Pointer to the framebuffer object.

◆ evalSubregionTexcoordTransform() [1/2]

Transform Framebuffer::evalSubregionTexcoordTransform ( const glm::ivec2 &  sourceSurface,
const glm::ivec2 &  destRegionSize,
const glm::ivec2 &  destRegionOffset = glm::ivec2(0) 
)
static

Used to get transform for mapping one surface to an area on the other surface.

Parameters
sourceSurfaceSize of the source surface in pixels.
destRegionSizeSize of the destination region in pixels.
destRegionOffsetStart position of the destination region in pixels.
Returns
Transform from source to destination.

◆ evalSubregionTexcoordTransform() [2/2]

Transform Framebuffer::evalSubregionTexcoordTransform ( const glm::ivec2 &  sourceSurface,
const glm::ivec4 &  destViewport 
)
static

Used to get transform for mapping one surface to an area on the other surface.

Parameters
sourceSurfaceSize of the source surface in pixels.
destViewportx,y - destination region offset, z, w - destination region size.
Returns
Transform from source to destination.

◆ evalSubregionTexcoordTransformCoefficients() [1/2]

glm::vec4 Framebuffer::evalSubregionTexcoordTransformCoefficients ( const glm::ivec2 &  sourceSurface,
const glm::ivec2 &  destRegionSize,
const glm::ivec2 &  destRegionOffset = glm::ivec2(0) 
)
static

Used to get coefficients for mapping one surface to an area on the other surface.

Parameters
sourceSurfaceSize of the source surface in pixels.
destRegionSizeSize of the destination region in pixels.
destRegionOffsetStart position of the destination region in pixels.
Returns
vec4 where x - x start coefficient, y - y start coefficient, z - width coefficient, w - height coefficient.

◆ evalSubregionTexcoordTransformCoefficients() [2/2]

glm::vec4 Framebuffer::evalSubregionTexcoordTransformCoefficients ( const glm::ivec2 &  sourceSurface,
const glm::ivec4 &  destViewport 
)
static

Used to get coefficients for mapping one surface to an area on the other surface.

Parameters
sourceSurfaceSize of the source surface in pixels.
destViewportx,y - destination region offset, z, w - destination region size.
Returns
vec4 where x - x start coefficient, y - y start coefficient, z - width coefficient, w - height coefficient.

◆ getAspectRatio()

float gpu::Framebuffer::getAspectRatio ( ) const
inline
Returns
Framebuffer width divided by height.

◆ getBufferMask()

Masks gpu::Framebuffer::getBufferMask ( ) const
inline

Buffer mask is used for checking what types of render buffers are populated in the particular framebuffer.

Returns
Buffer mask.

◆ getColorStamps()

const std::vector<Stamp>& gpu::Framebuffer::getColorStamps ( ) const
inline

Stamp is a counter that is incremented on changes and then compared with the stamp on backend-specific object side to determine if backend-specific object needs to be updated.

Returns
Stamps for color buffers.

◆ getDepthStamp()

Stamp gpu::Framebuffer::getDepthStamp ( ) const
inline

Stamp is a counter that is incremented on changes and then compared with the stamp on backend-specific object side to determine if backend-specific object needs to be updated.

Returns
Current stamp for depth render buffer.

◆ getDepthStencilBuffer()

const TexturePointer & Framebuffer::getDepthStencilBuffer ( ) const
Returns
Shared pointer to a depth stencil buffer. It can be nullptr if the render buffer does not exist.

◆ getDepthStencilBufferFormat()

Format Framebuffer::getDepthStencilBufferFormat ( ) const
Returns
Depth stencil buffer format.

◆ getDepthStencilBufferSubresource()

uint32 Framebuffer::getDepthStencilBufferSubresource ( ) const
Returns
Subresource index of the current depth stencil buffer. Multiple subresources on depth buffers are used for shadow cascades.

◆ getHeight()

uint16 Framebuffer::getHeight ( ) const
Returns
Framebuffer height in pixels.

◆ getMaxNumRenderBuffers()

static uint32 gpu::Framebuffer::getMaxNumRenderBuffers ( )
inlinestatic
Returns
Returns maximum number of render buffers. The result is platform-dependent.

◆ getName()

const std::string& gpu::Framebuffer::getName ( ) const
inline
Returns
Framebuffer name.

◆ getNumRenderBuffers()

uint32 Framebuffer::getNumRenderBuffers ( ) const
Returns
Number of render buffers in the framebuffer.

◆ getNumSamples()

uint16 Framebuffer::getNumSamples ( ) const
Returns
Number of samples. It's greater than one for MSAA.

◆ getRenderBuffer()

const TexturePointer & Framebuffer::getRenderBuffer ( uint32  slot) const

Returns render buffer from particular slot.

Parameters
slotSlot index.
Returns
Pointer to the render buffer.

◆ getRenderBuffers()

const TextureViews& gpu::Framebuffer::getRenderBuffers ( ) const
inline
Returns
Render buffers as TextureView objects.

◆ getRenderBufferSubresource()

uint32 Framebuffer::getRenderBufferSubresource ( uint32  slot) const

Get subresource index for a give slot.

Parameters
slotSlot index.
Returns
Subresource index.

◆ getSize()

Vec2u gpu::Framebuffer::getSize ( ) const
inline
Returns
Framebuffer size in pixels.

◆ getWidth()

uint16 Framebuffer::getWidth ( ) const
Returns
Framebuffer width in pixels.

◆ hasColor()

bool gpu::Framebuffer::hasColor ( ) const
inline
Returns
true if the framebuffer has one or more color render buffers.

◆ hasDepth()

bool gpu::Framebuffer::hasDepth ( ) const
inline
Returns
true if render buffer has a depth render buffer.

◆ hasDepthStencil()

bool gpu::Framebuffer::hasDepthStencil ( ) const
inline
Returns
true if render buffer has a depth stencil render buffer.

◆ hasStencil()

bool gpu::Framebuffer::hasStencil ( ) const
inline
Returns
true if render buffer has a stencil render buffer.

◆ isEmpty()

bool gpu::Framebuffer::isEmpty ( ) const
inline
Returns
true if there's no render buffers in the current framebuffer.

◆ setDepthBuffer()

bool Framebuffer::setDepthBuffer ( const TexturePointer &  texture,
const Format &  format,
uint32  subresource = 0 
)

Sets depth render buffer.

Parameters
textureTexture to be set as render buffer.
formatDepth format for the render buffer.
subresourceSubresource index, used when texture has several subresources, for example for shadow cascades.
Returns
true if render buffer was set successfully.

◆ setDepthStencilBuffer()

bool Framebuffer::setDepthStencilBuffer ( const TexturePointer &  texture,
const Format &  format,
uint32  subresource = 0 
)

Sets the combined depth stencil render buffer.

Parameters
textureTexture to be set as render buffer.
formatDepth stencil format for the render buffer.
subresourceSubresource index, used when texture has several subresources.
Returns
true if render buffer was set successfully.

◆ setName()

void gpu::Framebuffer::setName ( const std::string &  name)
inline

Sets the framebuffer name.

Parameters
nameNew name.

◆ setRenderBuffer()

int Framebuffer::setRenderBuffer ( uint32  slot,
const TexturePointer &  texture,
uint32  subresource = 0 
)

Sets a given render buffer slot in the framebuffer.

Parameters
slotIndex of the slot to set.
textureTexture to set it to.
subresourceSubresource index for when texture has several subresources. Used for shadow cascades and SSAO.
Returns

◆ setStencilBuffer()

bool Framebuffer::setStencilBuffer ( const TexturePointer &  texture,
const Format &  format,
uint32  subresource = 0 
)

Sets stencil render buffer.

Parameters
textureTexture to be set as render buffer.
formatStencil format for the render buffer.
subresourceSubresource index, used when texture has several subresources.
Returns
true if render buffer was set successfully.

◆ updateSize()

void Framebuffer::updateSize ( const TexturePointer &  texture)
protected

Copy width, height and sample count from a texture.

If texture is nullptr, then width, height and sample count are set to 0.

Parameters
textureShared pointer to a texture to copy width, height and sample count from. Can be nullptr.

◆ validateTargetCompatibility()

bool Framebuffer::validateTargetCompatibility ( const Texture &  texture,
uint32  subresource = 0 
) const

Checks if a texture is compatible with being a render attachment.

Checks if texture size and number of samples is the same as for the framebuffer.

Parameters
textureTexture to check.
subresourceIndex of the subresource to check. Currently not used.
Returns
true if texture passed the check.

Member Data Documentation

◆ _colorStamps

std::vector<Stamp> gpu::Framebuffer::_colorStamps
protected

Counters that are incremented on changes and then compared with the stamps on backend-specific objects to determine if backend-specific objects for color render buffers needs to be updated.

◆ _depthStamp

Stamp gpu::Framebuffer::_depthStamp { 0 }
protected

A counter that is incremented on changes and then compared with the stamp on backend-specific object to determine if backend-specific object for depth render buffer needs to be updated.

◆ gpuObject

const GPUObjectPointer gpu::Framebuffer::gpuObject {}

Graphics API-specific object representing this framebuffer on the backend side.


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