#include <renderablemeshcomponent.h>
Public Member Functions | |
RenderableMeshComponentInstance (EntityInstance &entity, Component &component) | |
virtual bool | init (utility::ErrorState &errorState) override |
RenderableMesh | createRenderableMesh (IMesh &mesh, MaterialInstance &materialInstance, utility::ErrorState &errorState) |
RenderableMesh | createRenderableMesh (IMesh &mesh, utility::ErrorState &errorState) |
void | setMesh (const RenderableMesh &mesh) |
MaterialInstance & | getMaterialInstance () |
IMesh & | getMesh () |
MeshInstance & | getMeshInstance () |
const RenderableMesh & | getRenderableMesh () const |
void | setClipRect (const math::Rect &rect) |
void | setLineWidth (float lineWidth) |
const math::Rect & | getClipRect () const |
const TransformComponentInstance & | getTransform () |
MaterialInstance * | getOrCreateMaterial () |
![]() | |
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 RenderLayer * | getLayer () const |
virtual bool | isSupported (nap::CameraComponentInstance &camera) const |
![]() | |
ComponentInstance (EntityInstance &entity, Component &resource) | |
virtual void | update (double deltaTime) |
nap::EntityInstance * | getEntityInstance () const |
nap::Component * | getComponent () const |
template<typename T > | |
T * | getComponent () const |
virtual bool | init (utility::ErrorState &errorState) |
![]() | |
Object () | |
virtual | ~Object () |
virtual void | onDestroy () |
Object (Object &)=delete | |
Object & | operator= (const Object &)=delete |
Object (Object &&)=delete | |
Object & | operator= (Object &&)=delete |
Protected Member Functions | |
virtual void | onDraw (IRenderTarget &renderTarget, VkCommandBuffer commandBuffer, const glm::mat4 &viewMatrix, const glm::mat4 &projectionMatrix) override |
Protected Attributes | |
TransformComponentInstance * | mTransformComponent |
Cached pointer to transform. More... | |
MaterialInstance | mMaterialInstance |
The MaterialInstance as created from the resource. More... | |
math::Rect | mClipRect |
Clipping rectangle for this instance, in pixel coordinates. More... | |
RenderableMesh | mRenderableMesh |
The currently active renderable mesh, either set during init() or set by setMesh. More... | |
UniformMat4Instance * | mModelMatUniform = nullptr |
Pointer to the model matrix uniform. More... | |
UniformMat4Instance * | mViewMatUniform = nullptr |
Pointer to the view matrix uniform. More... | |
UniformMat4Instance * | mProjectMatUniform = nullptr |
Pointer to the projection matrix uniform. More... | |
UniformMat4Instance * | mNormalMatrixUniform = nullptr |
Pointer to the normal matrix uniform. More... | |
UniformVec3Instance * | mCameraWorldPosUniform = nullptr |
Pointer to the camera world position uniform. More... | |
float | mLineWidth = 1.0f |
Line width, clamped to 1.0 if not supported by GPU. More... | |
![]() | |
RenderService * | mRenderService = nullptr |
Additional Inherited Members | |
![]() | |
static bool | isIDProperty (rtti::Instance &object, const rtti::Property &property) |
![]() | |
std::string | mID |
Property: 'mID' unique name of the object. Used as an identifier by the system. More... | |
Instance part of the renderable mesh component. Renders a mesh to screen or any other render target. You can set the mesh at runtime if necessary.
A mesh becomes 'renderable' when it is used in combination with a material. Such a mesh-material combination forms a 'nap::RenderableMesh'. Vertex attributes in both the shader and mesh should match. Otherwise, the RenderableMesh is invalid. The nap::RenderableMesh is created based on the given mesh and the material properties.
It is, however, possible to switch the mesh and / or material from the RenderableMeshComponent to some other mesh and / or material. To do so, other components should create their own nap::RenderableMesh by calling nap::RenderService::createRenderableMesh, and pass the returned object to setMesh(). The object calling nap::RenderService::createRenderableMesh should own the custom mesh and / or material and should validate the result on init().
The model view and projection matrices are automatically updated when the vertex shader exposes a struct with the 'uniform::mvpStruct' name.
A Transform component is required to position the mesh.
RenderableMeshComponentInstance | ( | EntityInstance & | entity, |
Component & | component | ||
) |
RenderableMesh createRenderableMesh | ( | IMesh & | mesh, |
MaterialInstance & | materialInstance, | ||
utility::ErrorState & | errorState | ||
) |
Creates a renderable mesh that can be used to switch to another mesh and/or material at runtime. This function should be called from init() functions on other components, and the result should be validated.
mesh | The mesh that is used in the mesh-material combination. |
materialInstance | The material instance that is used in the mesh-material combination. |
errorState | If this function returns an invalid renderable mesh, the error state contains error information. |
RenderableMesh createRenderableMesh | ( | IMesh & | mesh, |
utility::ErrorState & | errorState | ||
) |
Creates a renderable mesh that can be used to switch to another mesh at runtime. The material remains the same material as the one that was already set on the RenderableMeshComponent.. This function should be called from init() functions on other components, and the result should be validated.
mesh | The mesh that is used in the mesh-material combination. |
errorState | If this function returns an invalid renderable mesh, the error state contains error information. |
const math::Rect& getClipRect | ( | ) | const |
MaterialInstance& getMaterialInstance | ( | ) |
IMesh& getMesh | ( | ) |
MeshInstance& getMeshInstance | ( | ) |
Returns the runtime version of the mesh that is drawn, part of the original mesh.
MaterialInstance* getOrCreateMaterial | ( | ) |
Returns the program used to render the mesh.
TODO: This should be private, but our current RTTI implementation 'mangles' class name-spaces, causing the RTTR_REGISTRATION_FRIEND macro to fail -> needs to be fixed. It is therefore not recommended to use this function at runtime, use 'getMaterialInstance' instead!
const RenderableMesh& getRenderableMesh | ( | ) | const |
Returns the renderable mesh which can be used to extract low-level vertex buffer information
const TransformComponentInstance& getTransform | ( | ) |
|
overridevirtual |
Acquires VAO, copies clipping rectangle, initializes material instance.
Reimplemented from RenderableComponentInstance.
|
overrideprotectedvirtual |
Renders the model from the ModelResource, using the material on the ModelResource.
Implements RenderableComponentInstance.
void setClipRect | ( | const math::Rect & | rect | ) |
Sets clipping rectangle on this instance.
rect | Rectangle in pixel coordinates. |
void setLineWidth | ( | float | lineWidth | ) |
Sets line width
lineWidth | New line width |
void setMesh | ( | const RenderableMesh & | mesh | ) |
Switches the mesh and/or the material that is rendered. The renderable mesh should be created through createRenderableMesh, and must be created from an init() function.
mesh | The mesh that was retrieved through createRenderableMesh. |
|
protected |
Pointer to the camera world position uniform.
|
protected |
Clipping rectangle for this instance, in pixel coordinates.
|
protected |
Line width, clamped to 1.0 if not supported by GPU.
|
protected |
The MaterialInstance as created from the resource.
|
protected |
Pointer to the model matrix uniform.
|
protected |
Pointer to the normal matrix uniform.
|
protected |
Pointer to the projection matrix uniform.
|
protected |
The currently active renderable mesh, either set during init() or set by setMesh.
|
protected |
Cached pointer to transform.
|
protected |
Pointer to the view matrix uniform.