OsgMaterial.h
Go to the documentation of this file.
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013-2016, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SURGSIM_GRAPHICS_OSGMATERIAL_H
17 #define SURGSIM_GRAPHICS_OSGMATERIAL_H
18 
19 #include <boost/any.hpp>
20 #include <osg/Material>
21 #include <osg/StateSet>
22 #include <set>
23 
25 
26 
27 namespace SurgSim
28 {
29 
30 namespace Graphics
31 {
32 
33 class MaterialFace;
34 class OsgProgram;
35 class OsgUniformBase;
36 
45 class OsgMaterial : public Material
46 {
47 public:
50  explicit OsgMaterial(const std::string& name);
51 
53 
57  void addUniform(std::shared_ptr<UniformBase> uniform) override;
58 
59  void addUniform(const std::string& type, const std::string& name) override;
60 
65  void addUniform(const std::string& type, const std::string& name, const boost::any& value);
66 
71  bool removeUniform(std::shared_ptr<UniformBase> uniform) override;
72 
73  bool removeUniform(const std::string& name) override;
74 
75  size_t getNumUniforms() const override;
76 
77  std::shared_ptr<UniformBase> getUniform(size_t index) const override;
78 
79  std::shared_ptr<UniformBase> getUniform(const std::string& name) const override;
80 
81  bool hasUniform(const std::string& name) const override;
82 
87  bool setProgram(std::shared_ptr<Program> program) override;
88 
89  std::shared_ptr<Program> getProgram() const override;
90 
91  void clearProgram() override;
92 
94  osg::ref_ptr<osg::StateSet> getOsgStateSet() const;
95 
96  bool doInitialize() override;
97 
98  bool doWakeUp() override;
99 
100 private:
102  osg::ref_ptr<osg::StateSet> m_stateSet;
103 
105  std::vector<std::shared_ptr<OsgUniformBase>> m_uniforms;
106 
108  std::shared_ptr<OsgProgram> m_program;
109 };
110 
115 std::shared_ptr<OsgMaterial> buildMaterial(
116  const std::string& vertexShaderName,
117  const std::string& fragmentShaderName);
118 
119 }; // namespace Graphics
120 
121 }; // namespace SurgSim
122 
123 #endif // SURGSIM_GRAPHICS_OSGMATERIAL_H
SurgSim::Graphics::OsgMaterial::getUniform
std::shared_ptr< UniformBase > getUniform(size_t index) const override
Gets a uniform in this material.
Definition: OsgMaterial.cpp:116
SurgSim::Graphics::OsgMaterial::m_uniforms
std::vector< std::shared_ptr< OsgUniformBase > > m_uniforms
Uniforms used by this material.
Definition: OsgMaterial.h:105
SurgSim::Graphics::OsgMaterial::m_stateSet
osg::ref_ptr< osg::StateSet > m_stateSet
OSG state set which provides material properties in the scenegraph.
Definition: OsgMaterial.h:102
SurgSim::Graphics::OsgMaterial::doWakeUp
bool doWakeUp() override
Interface to be implemented by derived classes.
Definition: OsgMaterial.cpp:205
SurgSim::Graphics::OsgMaterial::addUniform
void addUniform(std::shared_ptr< UniformBase > uniform) override
Adds a uniform to this material.
Definition: OsgMaterial.cpp:46
SurgSim::Graphics::Material
Base class that defines the interface for graphics materials.
Definition: Material.h:40
SurgSim
Definition: CompoundShapeToGraphics.cpp:30
SurgSim::Graphics::OsgMaterial::doInitialize
bool doInitialize() override
Interface to be implemented by derived classes.
Definition: OsgMaterial.cpp:196
SurgSim::Graphics::OsgMaterial
OSG-based implementation of a graphics material.
Definition: OsgMaterial.h:46
SurgSim::Graphics::OsgMaterial::removeUniform
bool removeUniform(std::shared_ptr< UniformBase > uniform) override
Removes a uniform from this material.
Definition: OsgMaterial.cpp:84
SurgSim::Graphics::OsgMaterial::clearProgram
void clearProgram() override
Removes the shader from the material, falling back to fixed-function pipeline.
Definition: OsgMaterial.cpp:187
SurgSim::Graphics::OsgMaterial::hasUniform
bool hasUniform(const std::string &name) const override
Checks if this material has a uniform with the given name.
Definition: OsgMaterial.cpp:158
SurgSim::Graphics::buildMaterial
std::shared_ptr< OsgMaterial > buildMaterial(const std::string &vertexShaderName, const std::string &fragmentShaderName)
Utility function to build the material.
Definition: OsgMaterial.cpp:215
SurgSim::Graphics::OsgMaterial::getNumUniforms
size_t getNumUniforms() const override
Returns the number of uniforms in this material.
Definition: OsgMaterial.cpp:111
SurgSim::Graphics::OsgMaterial::getProgram
std::shared_ptr< Program > getProgram() const override
Gets the program used by this material.
Definition: OsgMaterial.cpp:182
SurgSim::Graphics::OsgMaterial::OsgMaterial
OsgMaterial(const std::string &name)
Constructor.
Definition: OsgMaterial.cpp:39
SurgSim::Graphics::OsgMaterial::m_program
std::shared_ptr< OsgProgram > m_program
Shader used by this material.
Definition: OsgMaterial.h:108
SurgSim::Graphics::OsgMaterial::SURGSIM_CLASSNAME
SURGSIM_CLASSNAME(SurgSim::Graphics::OsgMaterial)
string
string(TOUPPER ${DEVICE} DEVICE_UPPER_CASE) option(BUILD_DEVICE_$
Definition: CMakeLists.txt:38
SurgSim::Graphics::OsgMaterial::setProgram
bool setProgram(std::shared_ptr< Program > program) override
Sets the shader used by this material.
Definition: OsgMaterial.cpp:163
SurgSim::Graphics::OsgMaterial::getOsgStateSet
osg::ref_ptr< osg::StateSet > getOsgStateSet() const
Definition: OsgMaterial.cpp:210
Material.h