SPARK  0.1.0
A general purpose game engine written in C++.
Loading...
Searching...
No Matches
spark::render::RenderTarget Class Referencefinal

Implements a IRenderTarget. More...

#include <RenderTarget.h>

Inheritance diagram for spark::render::RenderTarget:
spark::render::IRenderTarget

Classes

struct  Impl
 

Public Member Functions

 RenderTarget () noexcept
 Initializes a default RenderTarget.
 
 RenderTarget (unsigned int location, RenderTargetType type, Format format, bool clear_buffer, const math::Vector4< float > &clear_values={0.f, 0.f, 0.f, 0.f}, bool clear_stencil=true, bool is_volatile=false, const BlendState &blend_state={})
 Initializes the RenderTarget.
 
 RenderTarget (const std::string &name, unsigned int location, RenderTargetType type, Format format, bool clear_buffer, const math::Vector4< float > &clear_values={0.f, 0.f, 0.f, 0.f}, bool clear_stencil=true, bool is_volatile=false, const BlendState &blend_state={})
 Initializes the RenderTarget.
 
 RenderTarget (const RenderTarget &other)
 
 RenderTarget (RenderTarget &&other) noexcept
 
RenderTargetoperator= (const RenderTarget &other)
 
RenderTargetoperator= (RenderTarget &&other) noexcept
 
std::string name () const noexcept override
 Gets the name of the render target.
 
unsigned location () const noexcept override
 Gets the location of the render target output attachment within the fragment shader.
 
RenderTargetType type () const noexcept override
 Gets the type of the render target.
 
Format format () const noexcept override
 Gets the internal format of the render target.
 
bool clearBuffer () const noexcept override
 Checks if the render target should be cleared when the render pass is started.
 
bool clearStencil () const noexcept override
 Checks if the render target stencil should be cleared when the render pass is started.
 
math::Vector4< float > clearValues () const noexcept override
 Gets the value the render target is cleared with, if clearBuffer() or clearStencil() returns true.
 
bool isVolatile () const noexcept override
 Checks if the target should not be persistent for access after the render pass has finished.
 
BlendState blendState () const noexcept override
 Gets the render target blend state.
 

Detailed Description

Implements a IRenderTarget.

Constructor & Destructor Documentation

◆ RenderTarget() [1/2]

spark::render::RenderTarget::RenderTarget ( unsigned int location,
RenderTargetType type,
Format format,
bool clear_buffer,
const math::Vector4< float > & clear_values = {0.f, 0.f, 0.f, 0.f},
bool clear_stencil = true,
bool is_volatile = false,
const BlendState & blend_state = {} )
explicit

Initializes the RenderTarget.

Parameters
locationThe location of the render target output attachment.
typeThe type of the render target.
formatThe format of the render target.
clear_buffertrue, if the render target should be cleared when the render pass is started, false otherwise.
clear_valuesThe values with which the render target gets cleared.
clear_stenciltrue, if the render target stencil should be cleared when the render pass is started, false otherwise.
is_volatiletrue, if the target should not be persistent for access after the render pass has finished, false otherwise.
blend_stateThe blend state of the render target.

◆ RenderTarget() [2/2]

spark::render::RenderTarget::RenderTarget ( const std::string & name,
unsigned int location,
RenderTargetType type,
Format format,
bool clear_buffer,
const math::Vector4< float > & clear_values = {0.f, 0.f, 0.f, 0.f},
bool clear_stencil = true,
bool is_volatile = false,
const BlendState & blend_state = {} )
explicit

Initializes the RenderTarget.

Parameters
nameThe name of the render target.
locationThe location of the render target output attachment.
typeThe type of the render target.
formatThe format of the render target.
clear_buffertrue, if the render target should be cleared when the render pass is started, false otherwise.
clear_valuesThe values with which the render target gets cleared.
clear_stenciltrue, if the render target stencil should be cleared when the render pass is started, false otherwise.
is_volatiletrue, if the target should not be persistent for access after the render pass has finished, false otherwise.
blend_stateThe blend state of the render target.

Member Function Documentation

◆ blendState()

IRenderTarget::BlendState spark::render::RenderTarget::blendState ( ) const
nodiscardoverridevirtualnoexcept

Gets the render target blend state.

Returns
A BlendState value describing the blend state of the render target.

Implements spark::render::IRenderTarget.

◆ clearBuffer()

bool spark::render::RenderTarget::clearBuffer ( ) const
overridevirtualnoexcept

Checks if the render target should be cleared when the render pass is started.

Returns
true, if the render target should be cleared when the render pass is started, false otherwise.
Note
If the format() is a depth format, the depth buffer will be cleared. Otherwise, the color buffer will be cleared.

Implements spark::render::IRenderTarget.

◆ clearStencil()

bool spark::render::RenderTarget::clearStencil ( ) const
overridevirtualnoexcept

Checks if the render target stencil should be cleared when the render pass is started.

Returns
true, if the render target stencil should be cleared when the render pass is started, false otherwise.
Note
If the format() is does not contain a stencil channel, this has no effect.

Implements spark::render::IRenderTarget.

◆ clearValues()

math::Vector4< float > spark::render::RenderTarget::clearValues ( ) const
nodiscardoverridevirtualnoexcept

Gets the value the render target is cleared with, if clearBuffer() or clearStencil() returns true.

Returns
The value the render target is cleared with.

If the format() is a color format and clearBuffer() is specified, this contains the clear color. However, if the format is a depth/stencil format, the R and G channels contain the depth and stencil value to clear the buffer with. Note that the stencil buffer is only cleared, if clearStencil() is specified and vice versa.

Implements spark::render::IRenderTarget.

◆ format()

Format spark::render::RenderTarget::format ( ) const
nodiscardoverridevirtualnoexcept

Gets the internal format of the render target.

Returns
A Format value describing the internal format of the render target.

Implements spark::render::IRenderTarget.

◆ isVolatile()

bool spark::render::RenderTarget::isVolatile ( ) const
nodiscardoverridevirtualnoexcept

Checks if the target should not be persistent for access after the render pass has finished.

Returns
true, if the target should not be persistent for access after the render pass has finished, false otherwise.

A render target can be marked as volatile if it does not need to be accessed after the render pass has finished. This can be used to optimize away unnecessary GPU/CPU memory round-trips. For example a depth buffer may only be used as an input for the lighting stage of a deferred renderer, but is not required after this. So instead of reading it from the GPU after the lighting pass has finished and then discarding it anyway, it can be marked as volatile in order to prevent it from being read from the GPU memory again in the first place.

Implements spark::render::IRenderTarget.

◆ location()

unsigned spark::render::RenderTarget::location ( ) const
nodiscardoverridevirtualnoexcept

Gets the location of the render target output attachment within the fragment shader.

Returns
The location of the render target output attachment within the fragment shader.

The locations of all render targets of a frame buffer must be within a continuous domain, starting at 0. A frame buffer validates the render target locations when it is initialized and will raise an exception, if a location is either not mapped or assigned multiple times.

Implements spark::render::IRenderTarget.

◆ name()

std::string spark::render::RenderTarget::name ( ) const
nodiscardoverridevirtualnoexcept

Gets the name of the render target.

Returns
A std::string containing the name of the render target.

Implements spark::render::IRenderTarget.

◆ type()

RenderTargetType spark::render::RenderTarget::type ( ) const
nodiscardoverridevirtualnoexcept

Gets the type of the render target.

Returns
A RenderTargetType value describing the type of the render target.

Implements spark::render::IRenderTarget.