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

#include <rendertarget.h>

Public Member Functions

 RenderTarget (Core &core)
 
 ~RenderTarget ()
 
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
 
bool hasDepthTexture () const
 
RenderTexture2DgetColorTexture ()
 
DepthRenderTexture2DgetDepthTexture ()
 
virtual VkFormat getColorFormat () const override
 
virtual VkFormat getDepthFormat () const override
 
virtual VkSampleCountFlagBits getSampleCount () const override
 
virtual bool getSampleShadingEnabled () const override
 
- 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
 

Public Attributes

bool mSampleShading = true
 Property: 'SampleShading' Reduces texture aliasing when enabled, at higher computational cost. More...
 
RGBAColorFloat mClearColor = { 0.0f, 0.0f, 0.0f, 0.0f }
 Property: 'ClearColor' color selection used for clearing the render target. More...
 
ERasterizationSamples mRequestedSamples = ERasterizationSamples::One
 Property: 'Samples' The number of samples used during Rasterization. For better results turn on 'SampleShading'. More...
 
ResourcePtr< RenderTexture2DmColorTexture
 Property: 'ColorTexture' texture to render to. More...
 
ResourcePtr< DepthRenderTexture2DmDepthTexture
 Property: 'DepthTexture' optional depth 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...
 

Additional Inherited Members

- Static Public Member Functions inherited from Object
static bool isIDProperty (rtti::Instance &object, const rtti::Property &property)
 

Description

A resource that is used to render one or multiple objects to a nap::RenderTexture2D instead of a nap::RenderWindow. This objects requires a link to a nap::RenderTexture2D to store the result of the render pass. Only render to a render target within a headless recording pass, failure to do so will result in undefined behavior. Make sure to call beginRendering() to start the render pass and endRendering() to end the render pass. Always call RenderService::endHeadlessRecording after having recorded all off-screen render operations.

mRenderService->beginFrame();
if (mRenderService->beginHeadlessRecording())
{
...
mTargetOne->beginRendering();
mRenderService->renderObjects(*mTargetOne, ortho_cam, objects_one);
mTargetOne->endRendering();
...
mTargetTwo->beginRendering();
mRenderService->renderObjects(*mTargetTwo, ortho_cam, objects_two);
mTargetTwo->endRendering();
...
mRenderService->endHeadlessRecording();
}
mRenderService->endFrame();

nap::RenderTarget can also be used to hook up a nap::DepthRenderTexture2D as a depth attachment. This lets you use the depth buffer as a shader resource in a subsequent render operation. The property DepthTexture is optional. When empty, an internal depth attachment is created to use during rendering and calls to nap::RenderTarget::getDepthTexture() will fail (always make sure hasDepthTexture() returns true first). When a depth texture is set, nap::RenderTarget::getDepthTexture() return a reference to the resource successfully.

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

Constructor & Destructor Documentation

◆ RenderTarget()

RenderTarget ( Core core)

Every render target requires a reference to core.

Parameters
corelink to a nap core instance

◆ ~RenderTarget()

Destroys allocated render resources

Member Function Documentation

◆ beginRendering()

virtual void beginRendering ( )
overridevirtual

Starts the render pass. Only start the render pass after a successful call to RenderService::beginHeadlessRecording().

mRenderService->beginFrame();
if (mRenderService->beginHeadlessRecording())
{
...
mTarget->beginRendering();
mRenderService->renderObjects(*mTarget, ortho_cam, objects_one);
mTarget->endRendering();
...
mRenderService->endHeadlessRecording();
}
mRenderService->endFrame();

Implements IRenderTarget.

◆ endRendering()

virtual void endRendering ( )
overridevirtual

Ends the render pass. Always call this after beginRendering().

mRenderService->beginFrame();
if (mRenderService->beginHeadlessRecording())
{
...
mTarget->beginRendering();
mTarget->renderObjects(*mTarget, ortho_cam, objects_one);
mTarget->endRendering();
...
mRenderService->endHeadlessRecording();
}
mRenderService->endFrame();

Implements IRenderTarget.

◆ getBufferSize()

virtual const glm::ivec2 getBufferSize ( ) const
overridevirtual
Returns
size in pixels of the render target.

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. This is the format of the linked in color texture.

Implements IRenderTarget.

◆ getColorTexture()

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

◆ getDepthFormat()

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

Implements IRenderTarget.

◆ getDepthTexture()

DepthRenderTexture2D& getDepthTexture ( )

Returns the depth texture resource if available, asserts if this is not the case. Always make sure hasDepthTexture() returns true before calling this function.

Returns
the depth texture that holds the result of the render pass, asserts otherwise.

◆ getRenderPass()

virtual VkRenderPass getRenderPass ( ) const
overridevirtual
Returns
the render pass

Implements IRenderTarget.

◆ getSampleCount()

virtual VkSampleCountFlagBits getSampleCount ( ) const
overridevirtual
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.

◆ getWindingOrder()

virtual ECullWindingOrder getWindingOrder ( ) const
overridevirtual

Geometry winding order, defaults to clockwise.

Implements IRenderTarget.

◆ hasDepthTexture()

bool hasDepthTexture ( ) const
Returns
whether this render target writes to a specified depth texture resource

◆ init()

virtual bool init ( utility::ErrorState errorState)
overridevirtual

Initializes the render target, including all the required resources.

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

Reimplemented from Object.

◆ 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.

◆ mColorTexture

ResourcePtr<RenderTexture2D> mColorTexture

Property: 'ColorTexture' texture to render to.

◆ mDepthTexture

Property: 'DepthTexture' optional depth texture to render to.

◆ mRequestedSamples

Property: 'Samples' The number of samples used during Rasterization. For better results turn on 'SampleShading'.

◆ mSampleShading

bool mSampleShading = true

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

nap::RenderService::renderObjects
void renderObjects(IRenderTarget &renderTarget, CameraComponentInstance &camera, RenderMask renderMask=mask::all)
nap::RenderService::beginHeadlessRecording
bool beginHeadlessRecording()
nap::RenderService::beginFrame
void beginFrame()
nap::RenderService::endHeadlessRecording
void endHeadlessRecording()
nap::RenderService::endFrame
void endFrame()