NAP
rendertotexturecomponent.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 
7 // Local Includes
8 #include "rendercomponent.h"
9 #include "rendertexture2d.h"
10 #include "planemesh.h"
11 #include "rendertarget.h"
12 #include "materialinstance.h"
13 #include "renderablemesh.h"
14 #include "color.h"
15 
16 // External Includes
17 #include <nap/resourceptr.h>
18 #include <entity.h>
19 
20 namespace nap
21 {
22  // Forward Declares
23  class RenderToTextureComponentInstance;
24 
52  {
53  RTTI_ENABLE(RenderableComponent)
55  public:
56  ResourcePtr<RenderTexture2D> mOutputTexture = nullptr;
59  RGBAColor8 mClearColor = { 255, 255, 255, 255 };
60  bool mSampleShading = true;
61  bool mPreserveAspect = false;
62  };
63 
64 
95  {
96  RTTI_ENABLE(RenderableComponentInstance)
97  public:
99 
105  virtual bool init(utility::ErrorState& errorState) override;
106 
110  IRenderTarget& getTarget();
111 
115  Texture2D& getOutputTexture();
116 
125  void draw();
126 
131  virtual bool isSupported(nap::CameraComponentInstance& camera) const override;
132 
136  MaterialInstance& getMaterialInstance();
137 
141  void setPreserveAspect(bool preserveAspect);
142 
143  protected:
152  virtual void onDraw(IRenderTarget& renderTarget, VkCommandBuffer commandBuffer, const glm::mat4& viewMatrix, const glm::mat4& projectionMatrix) override;
153 
154  private:
155  nap::RenderTarget mTarget;
156  nap::PlaneMesh mPlane;
157  MaterialInstance mMaterialInstance;
158  RenderableMesh mRenderableMesh;
159  RenderService* mService = nullptr;
160  glm::mat4x4 mModelMatrix;
161  bool mDirty = true;
162  bool mPreserveAspect = false;
163  UniformMat4Instance* mModelMatrixUniform = nullptr;
164  UniformMat4Instance* mProjectMatrixUniform = nullptr;
165  UniformMat4Instance* mViewMatrixUniform = nullptr;
166  UniformStructInstance* mMVPStruct = nullptr;
167 
172  UniformMat4Instance* ensureUniform(const std::string& uniformName, nap::UniformStructInstance& mvpStruct, utility::ErrorState& error);
173  };
174 }
nap::RenderableComponentInstance
Definition: rendercomponent.h:46
nap::IRenderTarget
Definition: irendertarget.h:21
nap::ERasterizationSamples::One
@ One
nap::ERasterizationSamples
ERasterizationSamples
Definition: renderutils.h:25
nap::RenderToTextureComponent
Definition: rendertotexturecomponent.h:51
nap::RGBAColor< uint8 >
nap::CameraComponentInstance
Definition: cameracomponent.h:38
nap::rtti::ObjectPtr
Definition: objectptr.h:154
nap::utility::ErrorState
Definition: errorstate.h:19
nap::RenderToTextureComponent::mMaterialInstanceResource
MaterialInstanceResource mMaterialInstanceResource
Property: 'MaterialInstance' instance of the material, used to override uniforms for this instance.
Definition: rendertotexturecomponent.h:57
nap::RenderToTextureComponentInstance
Definition: rendertotexturecomponent.h:94
nap::Texture2D
Definition: texture.h:128
nap::RenderService
Definition: renderservice.h:275
nap::EntityInstance
Definition: entity.h:34
nap::RenderableComponent
Definition: rendercomponent.h:29
nap::Component
Definition: component.h:151
nap::RenderableMesh
Definition: renderablemesh.h:22
nap::MaterialInstance
Definition: materialinstance.h:297
nap::RenderTarget
Definition: rendertarget.h:53
nap
Definition: templateapp.h:17
nap::UniformStructInstance
Definition: uniforminstance.h:53
nap::TypedUniformValueInstance
Definition: uniforminstance.h:243
nap::PlaneMesh
Definition: planemesh.h:26
nap::MaterialInstanceResource
Definition: materialinstance.h:68