Public Member Functions | Protected Member Functions | List of all members
RenderToTextureComponentInstance Class Reference

#include <rendertotexturecomponent.h>

Public Member Functions

 RenderToTextureComponentInstance (EntityInstance &entity, Component &resource)
virtual bool init (utility::ErrorState &errorState) override
IRenderTargetgetTarget ()
Texture2DgetOutputTexture ()
void draw ()
virtual bool isSupported (nap::CameraComponentInstance &camera) const override
MaterialInstancegetMaterialInstance ()
void setPreserveAspect (bool preserveAspect)
- Public Member Functions inherited from RenderableComponentInstance
 RenderableComponentInstance (EntityInstance &entity, Component &resource)
void draw (IRenderTarget &renderTarget, VkCommandBuffer commandBuffer, const glm::mat4 &viewMatrix, const glm::mat4 &projectionMatrix)
void setVisible (bool visible)
bool isVisible () const
- Public Member Functions inherited from ComponentInstance
 ComponentInstance (EntityInstance &entity, Component &resource)
virtual void update (double deltaTime)
nap::EntityInstancegetEntityInstance () const
nap::ComponentgetComponent () const
template<typename T >
T * getComponent () const
- 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

Protected Member Functions

virtual void onDraw (IRenderTarget &renderTarget, VkCommandBuffer commandBuffer, const glm::mat4 &viewMatrix, const glm::mat4 &projectionMatrix) override

Additional Inherited Members

- Static Public Member Functions inherited from Object
static bool isIDProperty (rtti::Instance &object, const rtti::Property &property)
- Public Attributes inherited from Object
std::string mID
 Property: 'mID' unique name of the object. Used as an identifier by the system. More...


Renders an effect directly to a texture using a custom material without having to define a render target or mesh. Use this component as a post process render step. This component manages its own render target and plane to render to. The plane is automatically scaled to fit the bounds of the render target.

Simply declare the component in json and call RenderToTextureComponentInstance::draw() in the render part of your application, in between nap::RenderService::beginHeadlessRecording() and nap::RenderService::endHeadlessRecording(). It is still possible to render this component through the render service, although only orthographic cameras are supported.

This component expects a material with a shader that contains both a model and projection matrix uniform. The view matrix uniform is optional. It will be set if found, otherwise bypassed. If you don't care about view space (camera) transformation, don't declare it in the shader. for example:

uniform nap
uniform mat4 projectionMatrix;
uniform mat4 modelMatrix;
} mvp;
void main(void)
gl_Position = mvp.projectionMatrix * mvp.modelMatrix;
Inheritance diagram for RenderToTextureComponentInstance:
Collaboration diagram for RenderToTextureComponentInstance:

Constructor & Destructor Documentation

◆ RenderToTextureComponentInstance()

Member Function Documentation

◆ draw()

void draw ( )

Renders the effect directly to texture using a custom material, without having to define a render target or mesh. Call this in your application render() call, in between nap::RenderService::beginHeadlessRecording() and nap::RenderService::endHeadlessRecording(). Do not call this function outside of a headless recording pass, ie: when rendering to a window. The result is rendered into the given output texture. Alternatively, you can use the render service to render this component, see onDraw()

◆ getMaterialInstance()

MaterialInstance& getMaterialInstance ( )
current material used when drawing the mesh.

◆ getOutputTexture()

Texture2D& getOutputTexture ( )
the output texture

◆ getTarget()

IRenderTarget& getTarget ( )
the render target that is used to perform the render step

◆ init()

virtual bool init ( utility::ErrorState errorState)

Initialize RenderToTextureComponentInstance based on the RenderToTextureComponent resource

errorStateshould hold the error message when initialization fails
if the rendertotexturecomponentInstance initialized successfully

Reimplemented from RenderableComponentInstance.

◆ isSupported()

virtual bool isSupported ( nap::CameraComponentInstance camera) const

Called by the Render Service. Only orthographic cameras are supported.

true if camera is orthographic

Reimplemented from RenderableComponentInstance.

◆ onDraw()

virtual void onDraw ( IRenderTarget renderTarget,
VkCommandBuffer  commandBuffer,
const glm::mat4 &  viewMatrix,
const glm::mat4 &  projectionMatrix 

Draws the effect full screen to the currently active render target, when the view matrix = identity.

renderTargetthe target to render to.
commandBufferthe currently active command buffer.
viewMatrixoften the camera world space location
projectionMatrixoften the camera projection matrix

Implements RenderableComponentInstance.

◆ setPreserveAspect()

void setPreserveAspect ( bool  preserveAspect)

Sets whether to preserve the texture aspect ratio when rendering to the target

constexpr const char * main
Definition: renderglobals.h:19
constexpr const char * modelMatrix
uniform model matrix name
Definition: renderglobals.h:46
Definition: assert.h:10
constexpr const char * projectionMatrix
uniform projection matrix name
Definition: renderglobals.h:48