Radium Engine  1.5.0
RenderParameters.cpp
1 #include <Core/Utils/Log.hpp>
2 
3 #include <Engine/Data/RenderParameters.hpp>
4 #include <Engine/RadiumEngine.hpp>
5 
6 #include <fstream>
7 namespace Ra {
8 namespace Engine {
9 namespace Data {
10 
11 RenderParameters::StaticParameterBinder RenderParameters::s_binder;
12 
13 void RenderParameters::bind( const Data::ShaderProgram* shader ) const {
14  m_parameterSets.visit( s_binder, shader );
15 }
16 
17 void RenderParameters::addParameter( const std::string& name, const std::string& value ) {
18  auto converterFunc = m_parameterSets.existsVariable<
19  std::function<void( Core::VariableSet&, const std::string&, const std::string& )>>( name );
20  if ( converterFunc ) { ( *converterFunc )->second( m_parameterSets, name, value ); }
21  else {
22  LOG( Core::Utils::logWARNING )
23  << "RenderParameters, try to set enum value from string without converter. Adding "
24  "non-bindable TParameter<string> "
25  << name << " " << value;
26  m_parameterSets.insertOrAssignVariable( name, value );
27  }
28 }
29 
30 void RenderParameters::addParameter( const std::string& name, const char* value ) {
31  addParameter( name, std::string( value ) );
32 }
33 
35  m_parameterSets.mergeKeepVariables( params.getStorage() );
36 }
37 
39  m_parameterSets.mergeReplaceVariables( params.getStorage() );
40 }
41 
42 void ParameterSetEditingInterface::loadMetaData( const std::string& basename,
43  nlohmann::json& destination ) {
44  auto resourcesRootDir { RadiumEngine::getInstance()->getResourcesDir() };
45  std::string metadataFileName = "Metadata/" + basename + ".json";
46  std::ifstream metadata( resourcesRootDir + metadataFileName );
47  if ( metadata ) { metadata >> destination; }
48  else {
49  LOG( Core::Utils::logERROR )
50  << "RenderParameters : failed to load metadata file " << metadataFileName;
51  }
52 }
53 } // namespace Data
54 } // namespace Engine
55 } // namespace Ra
Heterogeneous container storing "Variables", that maps a name (std::string) to a value (of any type T...
Definition: VariableSet.hpp:72
auto insertOrAssignVariable(const std::string &name, const T &value) -> std::pair< VariableHandle< T >, bool >
reset (or set if the variable does not exist yet) the value of the variable.
auto existsVariable(const std::string &name) const -> Utils::optional< VariableHandle< T >>
test the existence of the given variable
void mergeKeepVariables(const VariableSet &from)
Merge the VariableSet from into this.
Definition: VariableSet.cpp:37
void mergeReplaceVariables(const VariableSet &from)
Merge the VariableSet from into this.
Definition: VariableSet.cpp:44
void visit(F &&visitor) const
Visit the container using a user defined visitor.
static void loadMetaData(const std::string &basename, nlohmann::json &destination)
Load the ParameterSet description.
void addParameter(const std::string &name, T value, typename std::enable_if<!std::is_class< T > {}, bool >::type=true)
Add a parameter by value.
void bind(const Data::ShaderProgram *shader) const
const Core::VariableSet & getStorage() const
Get access to the parameter storage.
void mergeReplaceParameters(const RenderParameters &params)
void mergeKeepParameters(const RenderParameters &params)
Definition: Cage.cpp:3