Radium Engine  1.5.0
SimpleMaterial.cpp
1 #include <Engine/Data/SimpleMaterial.hpp>
2 #include <Engine/Data/TextureManager.hpp>
3 #include <Engine/RadiumEngine.hpp>
4 
5 #include <fstream>
6 
7 namespace Ra {
8 namespace Engine {
9 namespace Data {
10 SimpleMaterial::SimpleMaterial( const std::string& instanceName,
11  const std::string& materialName,
12  MaterialAspect aspect ) :
13  Material( instanceName, materialName, aspect ) {}
14 
16  m_textures.clear();
17 }
18 
19 void SimpleMaterial::updateRenderingParameters() {
20  auto& renderParameters = getParameters();
21  // update the rendering paramaters
22  renderParameters.addParameter( "material.color", m_color );
23  renderParameters.addParameter( "material.perVertexColor", m_perVertexColor );
24  Texture* tex = getTexture( SimpleMaterial::TextureSemantic::TEX_COLOR );
25  if ( tex != nullptr ) { renderParameters.addParameter( "material.tex.color", tex ); }
26  renderParameters.addParameter( "material.tex.hasColor", tex != nullptr );
27  tex = getTexture( SimpleMaterial::TextureSemantic::TEX_MASK );
28  if ( tex != nullptr ) { renderParameters.addParameter( "material.tex.mask", tex ); }
29  renderParameters.addParameter( "material.tex.hasMask", tex != nullptr );
30 }
31 
33  if ( !m_isDirty ) { return; }
34  // Load textures
35  Data::TextureManager* texManager = RadiumEngine::getInstance()->getTextureManager();
36  for ( const auto& tex : m_pendingTextures ) {
37  // ask to convert color textures from sRGB to Linear RGB
38  bool tolinear = ( tex.first == TextureSemantic::TEX_COLOR );
39  auto texture = texManager->getOrLoadTexture( tex.second, tolinear );
40  m_textures[tex.first] = texture;
41  }
42  // as all the pending textures where initialized, clear the pending textures list
43  m_pendingTextures.clear();
44  m_isDirty = false;
45  updateRenderingParameters();
46 }
47 
48 void SimpleMaterial::loadMetaData( nlohmann::json& destination ) {
49  ParameterSetEditingInterface::loadMetaData( "Simple", destination );
50 }
51 } // namespace Data
52 } // namespace Engine
53 } // namespace Ra
static void loadMetaData(const std::string &basename, nlohmann::json &destination)
Load the ParameterSet description.
void updateGL() override final
static void loadMetaData(nlohmann::json &destination)
Load the material parameter description.
Core::Utils::Color m_color
The base color of the material.
SimpleMaterial(const std::string &instanceName, const std::string &materialName, MaterialAspect aspect=MaterialAspect::MAT_OPAQUE)
Texture * getTexture(const TextureSemantic &semantic) const
Texture * getOrLoadTexture(const TextureParameters &texParameters, bool linearize=false)
Definition: Cage.cpp:3