NAP
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
CubeRenderTarget Class Reference

#include <cuberendertarget.h>

Public Member Functions

 CubeRenderTarget (Core &core)
 
 ~CubeRenderTarget ()
 
virtual bool init (utility::ErrorState &errorState) override
 
virtual void beginRendering () override
 
virtual void endRendering () override
 
virtual const glm::ivec2 getBufferSize () const override
 
virtual void setClearColor (const RGBAColorFloat &color) override
 
virtual const RGBAColorFloatgetClearColor () const override
 
virtual ECullWindingOrder getWindingOrder () const override
 
virtual VkRenderPass getRenderPass () const override
 
TextureCubegetColorTexture ()
 
virtual VkFormat getColorFormat () const override
 
virtual VkFormat getDepthFormat () const override
 
virtual VkSampleCountFlagBits getSampleCount () const override
 
virtual bool getSampleShadingEnabled () const override
 
glm::ivec2 getSize () const
 
void render (CubeRenderTargetCallback renderCallback)
 
void render (PerspCameraComponentInstance &camera, CubeRenderTargetCallback renderCallback)
 
uint getLayerIndex () const
 
- Public Member Functions inherited from Resource
 Resource ()
 
- Public Member Functions inherited from Object
 Object ()
 
virtual ~Object ()
 
virtual void onDestroy ()
 
 Object (Object &)=delete
 
Objectoperator= (const Object &)=delete
 
 Object (Object &&)=delete
 
Objectoperator= (Object &&)=delete
 

Static Public Member Functions

static const std::vector< glm::mat4 > & getCubeMapViewMatrices ()
 
static const std::vector< glm::mat4 > & getCubeMapInverseViewMatrices ()
 
- Static Public Member Functions inherited from Object
static bool isIDProperty (rtti::Instance &object, const rtti::Property &property)
 

Public Attributes

bool mSampleShading = true
 Property: 'SampleShading' Reduces texture aliasing when enabled, at higher computational cost. More...
 
bool mUpdateLODs = false
 Property: 'UpdateLODs0' Updates mip-maps using blit operations after rendering when the texture has LODs enabled. More...
 
RGBAColorFloat mClearColor = { 0.0f, 0.0f, 0.0f, 0.0f }
 Property: 'ClearColor' color selection used for clearing the render target. More...
 
RenderTextureCube::EFormat mColorFormat = RenderTextureCube::EFormat::RGBA8
 Property: 'ColorFormat' the cube texture color format. More...
 
DepthRenderTextureCube::EDepthFormat mDepthFormat = DepthRenderTextureCube::EDepthFormat::D16
 Property: 'DepthFormat' the cube texture depth format. More...
 
ResourcePtr< TextureCubemCubeTexture
 Property: 'CubeTexture' cube texture to render to. More...
 
- Public Attributes inherited from Object
std::string mID
 Property: 'mID' unique name of the object. Used as an identifier by the system. More...
 

Description

CubeRenderTarget

A specialized version of nap::RenderTarget that renders a cube texture. As a cube texture comprises six views of the scene, the render function carries out six render passes, each from a different point of view by means of particular view and projection transformations. The result of these render passes is stored in a multi-layer Vulkan image, each layer representing one view through the side of a unit cube.

Cube textures also support LODs. Enabling the UpdateLODs will automatically perform a blit operation to all mip-map levels after the cube texture was updated in the render function.

Inheritance diagram for CubeRenderTarget:
[legend]
Collaboration diagram for CubeRenderTarget:
[legend]

Constructor & Destructor Documentation

◆ CubeRenderTarget()

CubeRenderTarget ( Core core)

Every cube render target requires a reference to core.

Parameters
corelink to a nap core instance

◆ ~CubeRenderTarget()

Destroys allocated render resources

Member Function Documentation

◆ beginRendering()

virtual void beginRendering ( )
overridevirtual

Starts a render pass for the current layer index. Called by CubeRenderTarget::renderInternal.

Implements IRenderTarget.

◆ endRendering()

virtual void endRendering ( )
overridevirtual

Ends a render pass for the current layer index. Called by CubeRenderTarget::renderInternal.

Implements IRenderTarget.

◆ getBufferSize()

virtual const glm::ivec2 getBufferSize ( ) const
overridevirtual
Returns
the size of the buffer in pixels

Implements IRenderTarget.

◆ getClearColor()

virtual const RGBAColorFloat& getClearColor ( ) const
overridevirtual
Returns
the currently used render target clear color.

Implements IRenderTarget.

◆ getColorFormat()

virtual VkFormat getColorFormat ( ) const
overridevirtual
Returns
render target color format.

Implements IRenderTarget.

◆ getColorTexture()

TextureCube& getColorTexture ( )
Returns
the cube texture that holds the result of the render pass.

◆ getCubeMapInverseViewMatrices()

static const std::vector<glm::mat4>& getCubeMapInverseViewMatrices ( )
static
Returns
a list of inverse view matrices that correspond to each cube texture layer index.

◆ getCubeMapViewMatrices()

static const std::vector<glm::mat4>& getCubeMapViewMatrices ( )
static
Returns
a list of view matrices that correspond to each cube texture layer index.

◆ getDepthFormat()

virtual VkFormat getDepthFormat ( ) const
overridevirtual
Returns
render target depth format

Implements IRenderTarget.

◆ getLayerIndex()

uint getLayerIndex ( ) const

Returns the current texture layer index. This value only changes when the individual render layer commands are being recorded to the command buffer. Generally only useful when building highly custom rendering operations.

Returns
the current texture layer index.

◆ getRenderPass()

virtual VkRenderPass getRenderPass ( ) const
overridevirtual
Returns
the render pass

Implements IRenderTarget.

◆ getSampleCount()

virtual VkSampleCountFlagBits getSampleCount ( ) const
overridevirtual

Cube textures currently only support single sample render pass. Therefore, this function always returns VK_SAMPLE_COUNT_1_BIT.

Returns
used number of samples when rendering to the target.

Implements IRenderTarget.

◆ getSampleShadingEnabled()

virtual bool getSampleShadingEnabled ( ) const
overridevirtual
Returns
if sample based shading is enabled when rendering to the target.

Implements IRenderTarget.

◆ getSize()

glm::ivec2 getSize ( ) const
Returns
the absolute size of a single cube face in pixels.

◆ getWindingOrder()

virtual ECullWindingOrder getWindingOrder ( ) const
overridevirtual

Geometry winding order, defaults to clockwise.

Implements IRenderTarget.

◆ init()

virtual bool init ( utility::ErrorState errorState)
overridevirtual

Initializes the cube render target, including all the required resources.

Parameters
errorStatecontains the error if initialization failed.
Returns
if initialization succeeded.

Reimplemented from Object.

◆ render() [1/2]

void render ( CubeRenderTargetCallback  renderCallback)

Renders objects to nap::RenderTextureCube using the specified nap::CubeRenderTarget. Use 'renderCallback' to group the rendering work of a single render pass. This pass is repeated six times to create the resulting cube texture. The view and projection transformations are computed by nap::CubeRenderTarget and passed as arguments to a callback function. The following example demonstrates this using a lambda function:

if (mRenderService->beginHeadlessRecording())
{
cube_target->render([rs = mRenderService, comps = render_comps](CubeRenderTarget& target, const glm::mat4& projection, const glm::mat4& view)
{
rs->renderObjects(target, projection, view, comps, std::bind(&sorter::sortObjectsByDepth, std::placeholders::_1, std::placeholders::_2));
});
mRenderService->endHeadlessRecording();
}

◆ render() [2/2]

void render ( PerspCameraComponentInstance camera,
CubeRenderTargetCallback  renderCallback 
)

Renders objects to nap::RenderTextureCube using the specified nap::CubeRenderTarget. Use 'renderCallback' to group the rendering work of a single render pass. This pass is repeated six times to create the resulting cube texture. The view and projection transformations are computed by nap::CubeRenderTarget and passed as arguments to a callback function. The following example demonstrates this using a lambda function:

if (mRenderService->beginHeadlessRecording())
{
cube_target->render(*persp_camera, [rs = mRenderService, comps = render_comps](CubeRenderTarget& target, const glm::mat4& projection, const glm::mat4& view)
{
rs->renderObjects(target, projection, view, comps, std::bind(&sorter::sortObjectsByDepth, std::placeholders::_1, std::placeholders::_2));
});
mRenderService->endHeadlessRecording();
}

◆ setClearColor()

virtual void setClearColor ( const RGBAColorFloat color)
overridevirtual

Updates the render target clear color.

Parameters
colorthe new clear color to use.

Implements IRenderTarget.

Member Data Documentation

◆ mClearColor

RGBAColorFloat mClearColor = { 0.0f, 0.0f, 0.0f, 0.0f }

Property: 'ClearColor' color selection used for clearing the render target.

◆ mColorFormat

Property: 'ColorFormat' the cube texture color format.

◆ mCubeTexture

ResourcePtr<TextureCube> mCubeTexture

Property: 'CubeTexture' cube texture to render to.

◆ mDepthFormat

Property: 'DepthFormat' the cube texture depth format.

◆ mSampleShading

bool mSampleShading = true

Property: 'SampleShading' Reduces texture aliasing when enabled, at higher computational cost.

◆ mUpdateLODs

bool mUpdateLODs = false

Property: 'UpdateLODs0' Updates mip-maps using blit operations after rendering when the texture has LODs enabled.

nap::RenderService::beginHeadlessRecording
bool beginHeadlessRecording()
nap::RenderService::endHeadlessRecording
void endHeadlessRecording()
nap::sorter::sortObjectsByDepth
void NAPAPI sortObjectsByDepth(std::vector< RenderableComponentInstance * > &comps, const glm::mat4 &viewMatrix)
nap::CubeRenderTarget::CubeRenderTarget
CubeRenderTarget(Core &core)