1#include <Engine/Rendering/RenderTechnique.hpp>
3#include <Engine/Data/BlinnPhongMaterial.hpp>
4#include <Engine/Data/ShaderProgramManager.hpp>
5#include <Engine/RadiumEngine.hpp>
7#include <Core/Utils/Log.hpp>
13using namespace Core::Utils;
17RenderTechnique::RenderTechnique() : m_numActivePass { 0 } {
18 for (
auto p = Index( 0 ); p < s_maxNbPasses; ++p ) {
19 m_activePasses[p] = PassConfiguration( Data::ShaderConfiguration(),
nullptr );
20 m_passesParameters[p] =
nullptr;
25 m_numActivePass { o.m_numActivePass },
26 m_dirtyBits { o.m_dirtyBits },
27 m_setPasses { o.m_setPasses } {
28 for (
auto p = Index( 0 ); p < m_numActivePass; ++p ) {
30 m_activePasses[p] = o.m_activePasses[p];
31 m_passesParameters[p] = o.m_passesParameters[p];
36RenderTechnique::~RenderTechnique() =
default;
39 Core::Utils::Index pass ) {
40 m_numActivePass =
std::max( m_numActivePass, pass + 1 );
53 Core::Utils::Index pass ) {
54 if ( m_numActivePass == 0 ) {
56 <<
"Unable to set pass parameters : is passes configured using setConfiguration ? ";
59 if ( pass.isValid() ) {
63 for (
int i = 0; i < m_numActivePass; ++i ) {
72 Core::Utils::Index pass ) {
73 if ( m_numActivePass == 0 ) {
75 <<
"Unable to set pass properties : is passes configured using setConfiguration ? ";
79 m_activePasses[pass].first.addProperties( props );
83 for (
int i = 0; i < m_numActivePass; ++i ) {
85 m_activePasses[i].first.addProperties( props );
99 auto shaderProgramManager = RadiumEngine::getInstance()->getShaderProgramManager();
101 for (
auto p = Index( 0 ); p < m_numActivePass; ++p ) {
103 ( (
nullptr == m_activePasses[p].second ) ||
isDirty( p ) ) ) {
104 m_activePasses[p].second =
105 shaderProgramManager->getShaderProgram( m_activePasses[p].first );
109 for (
auto p = Index( 0 ); p < m_numActivePass; ++p ) {
110 if ( m_passesParameters[p] ) { m_passesParameters[p]->updateGL(); }
116 if ( RadiumDefaultRenderTechnique !=
nullptr ) {
117 return *( RadiumDefaultRenderTechnique.
get() );
121 auto builder = EngineRenderTechniques::getDefaultTechnique(
"BlinnPhong" );
122 if ( !builder.first ) {
123 LOG( logERROR ) <<
"Unable to create the default technique : is the Engine initialized ? ";
125 builder.second( *rt,
false );
126 rt->setParametersProvider( mat );
127 RadiumDefaultRenderTechnique.
reset( rt );
128 return *( RadiumDefaultRenderTechnique.
get() );
134namespace EngineRenderTechniques {
142bool registerDefaultTechnique(
const std::string& name, DefaultTechniqueBuilder builder ) {
143 auto result = EngineTechniqueRegistry.insert( { name, builder } );
144 return result.second;
150bool removeDefaultTechnique(
const std::string& name ) {
151 std::size_t removed = EngineTechniqueRegistry.erase( name );
152 return ( removed == 1 );
161 auto search = EngineTechniqueRegistry.find( name );
162 if ( search != EngineTechniqueRegistry.end() ) {
return {
true, search->second }; }
163 auto result =
std::make_pair(
false, [name]( RenderTechnique&,
bool ) ->
void {
164 LOG( logERROR ) <<
"Undefined default technique for " << name <<
" !";
170 EngineTechniqueRegistry.clear();
Shader program parameter provider.
void setParametersProvider(std::shared_ptr< Data::ShaderParameterProvider > provider, Core::Utils::Index pass=Core::Utils::Index(-1))
void clearDirty(Core::Utils::Index pass=DefaultRenderingPasses::LIGHTING_OPAQUE)
void setConfiguration(const Data::ShaderConfiguration &newConfig, Core::Utils::Index pass=DefaultRenderingPasses::LIGHTING_OPAQUE)
const Data::ShaderParameterProvider * getParametersProvider(Core::Utils::Index pass=DefaultRenderingPasses::LIGHTING_OPAQUE) const
void addPassProperties(const std::list< std::string > &props, Core::Utils::Index pass=Core::Utils::Index {})
static RenderTechnique createDefaultRenderTechnique()
const Data::ShaderProgram * getShader(Core::Utils::Index pass=DefaultRenderingPasses::LIGHTING_OPAQUE) const
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