NAP
Public Member Functions | Protected Member Functions | List of all members
RenderToWindowComponentInstance Class Reference

#include <rendertowindowcomponent.h>

Public Member Functions

 RenderToWindowComponentInstance (EntityInstance &entity, Component &resource)
 
bool init (utility::ErrorState &errorState) override
 
MaterialInstancegetMaterialInstance ()
 
const MaterialInstancegetMaterialInstance () const
 
void draw ()
 
bool isSupported (nap::CameraComponentInstance &camera) const override
 
RenderToWindowComponent::EScaleMode getMode () const
 
void setMode (RenderToWindowComponent::EScaleMode mode)
 
glm::vec2 getRatio () const
 
void setRatio (const glm::vec2 &ratio)
 
- 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
 
const std::vector< ResourcePtr< RenderTag > > & getTags () const
 
RenderMask getMask () const
 
bool includesMask (RenderMask otherMask)
 
int getRank () const
 
const RenderLayergetLayer () 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
 
virtual bool init (utility::ErrorState &errorState)
 
- 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

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...
 
- Protected Attributes inherited from RenderableComponentInstance
RenderServicemRenderService = nullptr
 

Description

Renders a plane directly to a window using a custom material, centering and scaling it based on the selected mode. Use this component to, for example, present the output of a render-pass to screen.

Simply declare the component in json and call RenderToWindowComponent::draw() in the render part of your application. This component manages its own nap::PlaneMesh to render with, you only have to provide it with a material.

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.

uniform nap
{
uniform mat4 projectionMatrix;
uniform mat4 modelMatrix;
} mvp;
...
void main(void)
{
gl_Position = mvp.projectionMatrix * mvp.modelMatrix;
}
Inheritance diagram for RenderToWindowComponentInstance:
[legend]
Collaboration diagram for RenderToWindowComponentInstance:
[legend]

Constructor & Destructor Documentation

◆ RenderToWindowComponentInstance()

Member Function Documentation

◆ draw()

void draw ( )

Renders directly to the window using a custom material, without having to define a mesh. Call this in your application render() call -> the result is rendered into the given window. This call starts and stops the render operation, you can't render anything else to the window after it's done. Alternatively, you can use the render service to render this component, see onDraw()

◆ getMaterialInstance() [1/2]

MaterialInstance& getMaterialInstance ( )
Returns
current material used when drawing the canvas to window.

◆ getMaterialInstance() [2/2]

const MaterialInstance& getMaterialInstance ( ) const
Returns
current material used when drawing the canvas to window.

◆ getMode()

Returns
current canvas scaling mode

◆ getRatio()

glm::vec2 getRatio ( ) const

Returns current canvas scaling ratio.

Returns
canvas source ratio

◆ init()

bool init ( utility::ErrorState errorState)
overridevirtual

Initialize the component

Parameters
errorStateholds the error message when initialization fails
Returns
if the component initialized successfully

Reimplemented from RenderableComponentInstance.

◆ isSupported()

bool isSupported ( nap::CameraComponentInstance camera) const
overridevirtual

Only orthographic cameras are supported.

Returns
true if camera is orthographic

Reimplemented from RenderableComponentInstance.

◆ onDraw()

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

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

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

Implements RenderableComponentInstance.

◆ setMode()

void setMode ( RenderToWindowComponent::EScaleMode  mode)

Set current canvas scaling mode

Parameters
modecanvas scaling mode

◆ setRatio()

void setRatio ( const glm::vec2 &  ratio)

Set and use custom canvas scaling ratio.

Parameters
rationew canvas scaling ratio
nap::shader::main
constexpr const char * main
Definition: renderglobals.h:29
nap::uniform::modelMatrix
constexpr const char * modelMatrix
uniform model matrix name
Definition: renderglobals.h:56
nap
Definition: templateapp.h:17
nap::uniform::projectionMatrix
constexpr const char * projectionMatrix
uniform projection matrix name
Definition: renderglobals.h:58