Radium Engine  1.5.0
RenderTechnique.hpp
1 #pragma once
2 
3 #include <Core/Utils/Index.hpp>
4 #include <Engine/RaEngine.hpp>
5 
6 #include <Engine/Data/ShaderConfiguration.hpp>
7 
8 #include <functional>
9 #include <map>
10 #include <memory>
11 
12 namespace Ra {
13 namespace Engine {
14 namespace Data {
15 class Material;
16 class ShaderProgram;
17 class ShaderParameterProvider;
18 } // namespace Data
19 
20 namespace Rendering {
21 
25 enum DefaultRenderingPasses : int {
32  DEFAULT_PASS = 0,
37  LIGHTING_OPAQUE = DEFAULT_PASS,
42  Z_PREPASS,
48  LIGHTING_TRANSPARENT,
54  LIGHTING_VOLUMETRIC
55 
56 }; // enum DefaultRenderingPasses
57 
63 class RA_ENGINE_API RenderTechnique final
64 {
65  public:
67 
70  ~RenderTechnique();
71 
78  void setConfiguration( const Data::ShaderConfiguration& newConfig,
79  Core::Utils::Index pass = DefaultRenderingPasses::LIGHTING_OPAQUE );
80 
86  inline bool
87  hasConfiguration( Core::Utils::Index pass = DefaultRenderingPasses::LIGHTING_OPAQUE ) const;
88 
93  inline void
94  setConfiguration( Core::Utils::Index pass = DefaultRenderingPasses::LIGHTING_OPAQUE );
95 
100  inline void
101  clearConfiguration( Core::Utils::Index pass = DefaultRenderingPasses::LIGHTING_OPAQUE );
102 
108  inline const Data::ShaderConfiguration&
109  getConfiguration( Core::Utils::Index pass = DefaultRenderingPasses::LIGHTING_OPAQUE ) const;
110 
116  const Data::ShaderProgram*
117  getShader( Core::Utils::Index pass = DefaultRenderingPasses::LIGHTING_OPAQUE ) const;
118 
127  void setParametersProvider( std::shared_ptr<Data::ShaderParameterProvider> provider,
128  Core::Utils::Index pass = Core::Utils::Index( -1 ) );
129 
135  const Data::ShaderParameterProvider* getParametersProvider(
136  Core::Utils::Index pass = DefaultRenderingPasses::LIGHTING_OPAQUE ) const;
137 
141  void updateGL();
142 
148  inline bool isDirty( Core::Utils::Index pass = DefaultRenderingPasses::LIGHTING_OPAQUE ) const;
149 
154  inline void setDirty( Core::Utils::Index pass = DefaultRenderingPasses::LIGHTING_OPAQUE );
155 
160  inline void clearDirty( Core::Utils::Index pass = DefaultRenderingPasses::LIGHTING_OPAQUE );
161 
167  void addPassProperties( const std::list<std::string>& props,
168  Core::Utils::Index pass = Core::Utils::Index {} );
176  static RenderTechnique createDefaultRenderTechnique();
177 
178  private:
180  static constexpr int s_maxNbPasses { 32 };
181 
183  using PassConfiguration = std::pair<Data::ShaderConfiguration, const Data::ShaderProgram*>;
185  using ConfigurationSet = std::array<PassConfiguration, s_maxNbPasses>;
187  using PassesParameters =
188  std::array<std::shared_ptr<Data::ShaderParameterProvider>, s_maxNbPasses>;
189 
191  ConfigurationSet m_activePasses;
193  PassesParameters m_passesParameters;
194 
196  Core::Utils::Index m_numActivePass;
197 
198  // Change this if there is more than 32 configurations
200  unsigned int m_dirtyBits { 0xFFFFFFFF };
202  unsigned int m_setPasses { 0x00000000 };
203 };
204 
208 namespace EngineRenderTechniques {
209 
216 using DefaultTechniqueBuilder = std::function<void( RenderTechnique& rt, bool isTransparent )>;
217 
221 RA_ENGINE_API bool registerDefaultTechnique( const std::string& name,
222  DefaultTechniqueBuilder builder );
223 
227 RA_ENGINE_API bool removeDefaultTechnique( const std::string& name );
228 
234 RA_ENGINE_API std::pair<bool, DefaultTechniqueBuilder>
235 getDefaultTechnique( const std::string& name );
236 
237 RA_ENGINE_API bool cleanup();
238 } // namespace EngineRenderTechniques
239 
245 inline bool RenderTechnique::isDirty( Core::Utils::Index pass ) const {
246  return m_dirtyBits & ( 1 << pass );
247 }
248 
253 inline void RenderTechnique::setDirty( Core::Utils::Index pass ) {
254  m_dirtyBits |= ( 1 << pass );
255 }
256 
257 inline void RenderTechnique::clearDirty( Core::Utils::Index pass ) {
258  m_dirtyBits &= ~( 1 << pass );
259 }
260 
261 inline bool RenderTechnique::hasConfiguration( Core::Utils::Index pass ) const {
262  return m_setPasses & ( 1 << pass );
263 }
264 
265 inline void RenderTechnique::setConfiguration( Core::Utils::Index pass ) {
266  m_setPasses |= ( 1 << pass );
267 }
268 
269 inline void RenderTechnique::clearConfiguration( Core::Utils::Index pass ) {
270  m_setPasses &= ~( 1 << pass );
271 }
272 
273 inline const Data::ShaderConfiguration&
274 RenderTechnique::getConfiguration( Core::Utils::Index pass ) const {
275  return m_activePasses[pass].first;
276 }
277 
278 } // namespace Rendering
279 } // namespace Engine
280 } // namespace Ra
void clearDirty(Core::Utils::Index pass=DefaultRenderingPasses::LIGHTING_OPAQUE)
void clearConfiguration(Core::Utils::Index pass=DefaultRenderingPasses::LIGHTING_OPAQUE)
const Data::ShaderConfiguration & getConfiguration(Core::Utils::Index pass=DefaultRenderingPasses::LIGHTING_OPAQUE) const
void setConfiguration(const Data::ShaderConfiguration &newConfig, Core::Utils::Index pass=DefaultRenderingPasses::LIGHTING_OPAQUE)
bool hasConfiguration(Core::Utils::Index pass=DefaultRenderingPasses::LIGHTING_OPAQUE) const
bool isDirty(Core::Utils::Index pass=DefaultRenderingPasses::LIGHTING_OPAQUE) const
void setDirty(Core::Utils::Index pass=DefaultRenderingPasses::LIGHTING_OPAQUE)
Definition: Cage.cpp:3