opensurgsim
OsgMaterial.h
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 
24 #include "SurgSim/Graphics/Material.h"
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 
52  SURGSIM_CLASSNAME(SurgSim::Graphics::OsgMaterial);
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 
83  void loadProgram(const std::string& nameTuple) override;
84 
89  bool setProgram(std::shared_ptr<Program> program) override;
90 
91  std::shared_ptr<Program> getProgram() const override;
92 
93  void clearProgram() override;
94 
96  osg::ref_ptr<osg::StateSet> getOsgStateSet() const;
97 
98  bool doInitialize() override;
99 
100  bool doWakeUp() override;
101 
102 
103 private:
105  osg::ref_ptr<osg::StateSet> m_stateSet;
106 
108  std::vector<std::shared_ptr<OsgUniformBase>> m_uniforms;
109 
111  std::shared_ptr<OsgProgram> m_program;
112 };
113 
118 std::shared_ptr<OsgMaterial> buildMaterial(
119  const std::string& vertexShaderName,
120  const std::string& fragmentShaderName);
121 
122 }; // namespace Graphics
123 
124 }; // namespace SurgSim
125 
126 #endif // SURGSIM_GRAPHICS_OSGMATERIAL_H
size_t getNumUniforms() const override
Returns the number of uniforms in this material.
Definition: OsgMaterial.cpp:111
std::shared_ptr< Program > getProgram() const override
Gets the program used by this material.
Definition: OsgMaterial.cpp:182
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
bool removeUniform(std::shared_ptr< UniformBase > uniform) override
Removes a uniform from this material.
Definition: OsgMaterial.cpp:84
Base class that defines the interface for graphics materials.
Definition: Material.h:39
bool setProgram(std::shared_ptr< Program > program) override
Sets the shader used by this material.
Definition: OsgMaterial.cpp:163
bool doWakeUp() override
Interface to be implemented by derived classes.
Definition: OsgMaterial.cpp:205
void addUniform(std::shared_ptr< UniformBase > uniform) override
Adds a uniform to this material.
Definition: OsgMaterial.cpp:46
std::shared_ptr< UniformBase > getUniform(size_t index) const override
Gets a uniform in this material.
Definition: OsgMaterial.cpp:116
bool hasUniform(const std::string &name) const override
Checks if this material has a uniform with the given name.
Definition: OsgMaterial.cpp:158
osg::ref_ptr< osg::StateSet > getOsgStateSet() const
Definition: OsgMaterial.cpp:217
void clearProgram() override
Removes the shader from the material, falling back to fixed-function pipeline.
Definition: OsgMaterial.cpp:187
OsgMaterial(const std::string &name)
Constructor.
Definition: OsgMaterial.cpp:39
OSG-based implementation of a graphics material.
Definition: OsgMaterial.h:45
bool doInitialize() override
Interface to be implemented by derived classes.
Definition: OsgMaterial.cpp:196