OsgMaterial.h
Go to the documentation of this file.
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, 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 
20 
21 #include <osg/Material>
22 #include <osg/StateSet>
23 
24 #include <set>
25 
26 namespace SurgSim
27 {
28 
29 namespace Graphics
30 {
31 
32 class MaterialFace;
33 class OsgShader;
34 class OsgUniformBase;
35 
44 class OsgMaterial : public Material
45 {
46 public:
49  explicit OsgMaterial(const std::string& name);
50 
55  virtual bool addUniform(std::shared_ptr<UniformBase> uniform) override;
56 
57  virtual bool addUniform(const std::string& type, const std::string& name) override;
58 
63  virtual bool removeUniform(std::shared_ptr<UniformBase> uniform) override;
64 
65  virtual bool removeUniform(const std::string& name) override;
66 
67  virtual size_t getNumUniforms() const override;
68 
69  virtual std::shared_ptr<UniformBase> getUniform(size_t index) const override;
70 
71  virtual std::shared_ptr<UniformBase> getUniform(const std::string& name) const override;
72 
73  virtual bool hasUniform(const std::string& name) const override;
74 
79  virtual bool setShader(std::shared_ptr<Shader> shader) override;
80 
81  virtual std::shared_ptr<Shader> getShader() const override;
82 
83  virtual void clearShader() override;
84 
86  osg::ref_ptr<osg::StateSet> getOsgStateSet() const;
87 
88  virtual bool doInitialize() override;
89 
90  virtual bool doWakeUp() override;
91 
92 private:
94  osg::ref_ptr<osg::StateSet> m_stateSet;
95 
97  std::vector<std::shared_ptr<OsgUniformBase>> m_uniforms;
98 
100  std::shared_ptr<OsgShader> m_shader;
101 };
102 
103 }; // namespace Graphics
104 
105 }; // namespace SurgSim
106 
107 #endif // SURGSIM_GRAPHICS_OSGMATERIAL_H
virtual size_t getNumUniforms() const override
Returns the number of uniforms in this material.
Definition: OsgMaterial.cpp:112
osg::ref_ptr< osg::StateSet > m_stateSet
OSG state set which provides material properties in the scenegraph.
Definition: OsgMaterial.h:94
Definition: DriveElementFromInputBehavior.cpp:27
virtual std::shared_ptr< Shader > getShader() const override
Gets the shader used by this material.
Definition: OsgMaterial.cpp:183
virtual bool removeUniform(std::shared_ptr< UniformBase > uniform) override
Removes a uniform from this material.
Definition: OsgMaterial.cpp:85
std::vector< std::shared_ptr< OsgUniformBase > > m_uniforms
Uniforms used by this material.
Definition: OsgMaterial.h:97
virtual bool setShader(std::shared_ptr< Shader > shader) override
Sets the shader used by this material.
Definition: OsgMaterial.cpp:164
virtual bool addUniform(std::shared_ptr< UniformBase > uniform) override
Adds a uniform to this material.
Definition: OsgMaterial.cpp:45
Base class that defines the interface for graphics materials.
Definition: Material.h:39
virtual bool doWakeUp() override
Interface to be implemented by derived classes.
Definition: OsgMaterial.cpp:206
virtual std::shared_ptr< UniformBase > getUniform(size_t index) const override
Gets a uniform in this material.
Definition: OsgMaterial.cpp:117
virtual bool hasUniform(const std::string &name) const override
Checks if this material has a uniform with the given name.
Definition: OsgMaterial.cpp:159
std::shared_ptr< OsgShader > m_shader
Shader used by this material.
Definition: OsgMaterial.h:100
virtual void clearShader() override
Removes the shader from the material, falling back to fixed-function pipeline.
Definition: OsgMaterial.cpp:188
osg::ref_ptr< osg::StateSet > getOsgStateSet() const
Definition: OsgMaterial.cpp:211
OsgMaterial(const std::string &name)
Constructor.
Definition: OsgMaterial.cpp:38
OSG-based implementation of a graphics material.
Definition: OsgMaterial.h:44
virtual bool doInitialize() override
Interface to be implemented by derived classes.
Definition: OsgMaterial.cpp:197