NAP
renderfadercomponent.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 // External Includes
8 #include <rendercomponent.h>
9 #include <renderablemesh.h>
10 #include <materialinstance.h>
11 #include <nap/resourceptr.h>
12 #include <nap/signalslot.h>
13 #include <rect.h>
14 #include <componentptr.h>
15 #include <emptymesh.h>
16 #include <nap/timer.h>
17 
18 namespace nap
19 {
20  class RenderFaderComponentInstance;
21 
34  {
35  RTTI_ENABLE(RenderableComponent)
37  public:
38  float mFadeDuration = 2.0f;
39  RGBColorFloat mFadeColor = { 0.0f, 0.0f, 0.0f };
40  bool mFadeIn = true;
41  };
42 
43 
56  {
57  RTTI_ENABLE(RenderableComponentInstance)
58 
59  public:
60  // Fade state
61  enum class EFadeState: nap::uint8
62  {
63  FadingIn = 0,
64  FadedIn = 1,
65  FadingOut = 2,
66  FadedOut = 3
67  };
68 
69  // Constructor
71 
75  virtual bool init(utility::ErrorState& errorState) override;
76 
82  virtual void update(double deltaTime) override;
83 
87  EFadeState getState() const { return mFadeState; }
88 
92  void fadeIn() { mFadeState = EFadeState::FadingIn; mTimer.reset(); }
93 
97  void fadeOut() { mFadeState = EFadeState::FadingOut; mTimer.reset(); }
98 
101 
102  protected:
106  virtual void onDraw(IRenderTarget& renderTarget, VkCommandBuffer commandBuffer, const glm::mat4& viewMatrix, const glm::mat4& projectionMatrix) override;
107 
108  private:
109  MaterialInstance mMaterialInstance;
110  EmptyMesh mEmptyMesh;
111  MaterialInstanceResource mMaterialInstanceResource;
112 
113  RenderFaderComponent* mResource = nullptr;
114  RenderService* mRenderService = nullptr;
115 
116  nap::SteadyTimer mTimer;
117  UniformFloatInstance* mAlphaUniform = nullptr;
118 
119  EFadeState mFadeState = EFadeState::FadedIn;
120  };
121 }
nap::RenderableComponentInstance
Definition: rendercomponent.h:46
nap::RenderFaderComponent
Definition: renderfadercomponent.h:33
nap::IRenderTarget
Definition: irendertarget.h:21
nap::RenderFaderComponentInstance::getState
EFadeState getState() const
Definition: renderfadercomponent.h:87
nap::RGBColor< float >
nap::RenderFaderComponentInstance::fadeOut
void fadeOut()
Definition: renderfadercomponent.h:97
nap::uint8
uint8_t uint8
Definition: numeric.h:16
nap::utility::ErrorState
Definition: errorstate.h:19
nap::Timer< SteadyClock >
nap::Signal
Definition: signalslot.h:28
nap::RenderService
Definition: renderservice.h:275
nap::EntityInstance
Definition: entity.h:34
nap::RenderFaderComponentInstance::EFadeState
EFadeState
Definition: renderfadercomponent.h:61
nap::RenderableComponent
Definition: rendercomponent.h:29
nap::RenderFaderComponentInstance
Definition: renderfadercomponent.h:55
nap::Component
Definition: component.h:151
nap::MaterialInstance
Definition: materialinstance.h:297
nap
Definition: templateapp.h:17
nap::EmptyMesh
Definition: emptymesh.h:27
nap::TypedUniformValueInstance
Definition: uniforminstance.h:243
nap::RenderFaderComponentInstance::mFadedOut
nap::Signal mFadedOut
Triggered when a fade transition finished fading to 'FadeColor'.
Definition: renderfadercomponent.h:100
nap::RenderFaderComponentInstance::mFadedIn
nap::Signal mFadedIn
Triggered when a fade transition finished fading from 'FadeColor'.
Definition: renderfadercomponent.h:99
nap::RenderFaderComponentInstance::fadeIn
void fadeIn()
Definition: renderfadercomponent.h:92
nap::MaterialInstanceResource
Definition: materialinstance.h:68