opensurgsim
OsgUniformBase.h
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_OSGUNIFORMBASE_H
17 #define SURGSIM_GRAPHICS_OSGUNIFORMBASE_H
18 
19 #include "SurgSim/Graphics/Uniform.h"
20 
21 #include <osg/StateSet>
22 #include <osg/Uniform>
23 
24 namespace YAML
25 {
26 class Node;
27 }
28 
29 namespace SurgSim
30 {
31 
32 namespace Graphics
33 {
34 
41 class OsgUniformBase : public virtual UniformBase
42 {
43 public:
45  const std::string& getName() const
46  {
47  return m_uniform->getName();
48  }
49 
53  virtual void set(const YAML::Node& node) = 0;
54 
57  virtual void addToStateSet(osg::StateSet* stateSet);
58 
61  virtual void removeFromStateSet(osg::StateSet* stateSet);
62 
64  osg::ref_ptr<osg::Uniform> getOsgUniform() const
65  {
66  return m_uniform;
67  }
68 
69 
70  virtual const std::string getGlslType() const = 0;
71 
72 protected:
75  explicit OsgUniformBase(const std::string& name);
76 
78  osg::ref_ptr<osg::Uniform> m_uniform;
79 };
80 
81 }; // namespace Graphics
82 
83 }; // namespace SurgSim
84 
85 namespace YAML
86 {
87 template<>
88 struct convert<std::shared_ptr<SurgSim::Graphics::OsgUniformBase>>
89 {
90  static Node encode(const std::shared_ptr<SurgSim::Graphics::OsgUniformBase> rhs);
91  static bool decode(const Node& node, std::shared_ptr<SurgSim::Graphics::OsgUniformBase>& rhs); //NOLINT
92 };
93 
94 };
95 
96 
97 #endif // SURGSIM_GRAPHICS_OSGUNIFORMBASE_H
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
osg::ref_ptr< osg::Uniform > m_uniform
OSG uniform node.
Definition: OsgUniformBase.h:78
Definition: MockObjects.h:47
Base OSG implementation of graphics uniforms.
Definition: OsgUniformBase.h:41
osg::ref_ptr< osg::Uniform > getOsgUniform() const
Returns the OSG uniform node.
Definition: OsgUniformBase.h:64
Definition: DataStructuresConvert.h:28
const std::string & getName() const
Returns the name used in shader code to access this uniform.
Definition: OsgUniformBase.h:45
Common base class for all graphics uniforms.
Definition: UniformBase.h:33
const std::string getGlslType()
Returns the OSG uniform type enum value for the template parameter type.
Definition: OsgUniformGlslTypes.h:45