Radium Engine  1.5.20
Loading...
Searching...
No Matches
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
12namespace Ra {
13namespace Engine {
14namespace Data {
15class Material;
16class ShaderProgram;
17class ShaderParameterProvider;
18} // namespace Data
19
20namespace Rendering {
21
57
63class RA_ENGINE_API RenderTechnique final
64{
65 public:
67
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
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
187 using PassesParameters =
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
208namespace EngineRenderTechniques {
209
216using DefaultTechniqueBuilder = std::function<void( RenderTechnique& rt, bool isTransparent )>;
217
221RA_ENGINE_API bool registerDefaultTechnique( const std::string& name,
222 DefaultTechniqueBuilder builder );
223
227RA_ENGINE_API bool removeDefaultTechnique( const std::string& name );
228
235getDefaultTechnique( const std::string& name );
236
237RA_ENGINE_API bool cleanup();
238} // namespace EngineRenderTechniques
239
245inline bool RenderTechnique::isDirty( Core::Utils::Index pass ) const {
246 return m_dirtyBits & ( 1 << pass );
247}
248
253inline void RenderTechnique::setDirty( Core::Utils::Index pass ) {
254 m_dirtyBits |= ( 1 << pass );
255}
256
257inline void RenderTechnique::clearDirty( Core::Utils::Index pass ) {
258 m_dirtyBits &= ~( 1 << pass );
259}
260
261inline bool RenderTechnique::hasConfiguration( Core::Utils::Index pass ) const {
262 return m_setPasses & ( 1 << pass );
263}
264
265inline void RenderTechnique::setConfiguration( Core::Utils::Index pass ) {
266 m_setPasses |= ( 1 << pass );
267}
268
269inline void RenderTechnique::clearConfiguration( Core::Utils::Index pass ) {
270 m_setPasses &= ~( 1 << pass );
271}
272
273inline const Data::ShaderConfiguration&
274RenderTechnique::getConfiguration( Core::Utils::Index pass ) const {
275 return m_activePasses[pass].first;
276}
277
278} // namespace Rendering
279} // namespace Engine
280} // namespace Ra
Shader program parameter provider.
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)
hepler function to manage enum as underlying types in VariableSet
Definition Cage.cpp:3