opensurgsim
OsgTextureUniform.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_OSGTEXTUREUNIFORM_H
17 #define SURGSIM_GRAPHICS_OSGTEXTUREUNIFORM_H
18 
20 
21 namespace SurgSim
22 {
23 
24 namespace Graphics
25 {
26 
29 template <class T>
30 class OsgTextureUniform : public Uniform<std::shared_ptr<T>>, public OsgUniformBase
31 {
32 public:
35  explicit OsgTextureUniform(const std::string& name);
36 
39  void setMinimumTextureUnit(size_t unit);
40 
42  size_t getMinimumTextureUnit() const;
43 
47  virtual void set(const std::shared_ptr<T>& value);
48 
49  virtual void set(const YAML::Node& node);
50 
52  virtual const std::shared_ptr<T>& get() const;
53 
56  virtual void addToStateSet(osg::StateSet* stateSet);
57 
60  virtual void removeFromStateSet(osg::StateSet* stateSet);
61 
62  virtual const std::string getGlslType() const;
63 
64 private:
66  std::shared_ptr<T> m_texture;
67 
68  osg::ref_ptr<osg::StateSet> m_stateset;
69 
71  ptrdiff_t m_unit;
72 
74  size_t m_minimumTextureUnit;
75 };
76 
78 template <>
79 class OsgUniform<std::shared_ptr<OsgTexture1d>> : public OsgTextureUniform<OsgTexture1d>
80 {
81 public:
84  explicit OsgUniform(const std::string& name) : OsgTextureUniform<OsgTexture1d>(name)
85  {
86  }
87 };
88 
90 template <>
91 class OsgUniform<std::shared_ptr<OsgTexture2d>> : public OsgTextureUniform<OsgTexture2d>
92 {
93 public:
96  explicit OsgUniform(const std::string& name) : OsgTextureUniform<OsgTexture2d>(name)
97  {
98  }
99 };
100 
102 template <>
103 class OsgUniform<std::shared_ptr<OsgTexture3d>> : public OsgTextureUniform<OsgTexture3d>
104 {
105 public:
108  explicit OsgUniform(const std::string& name) : OsgTextureUniform<OsgTexture3d>(name)
109  {
110  }
111 };
112 
114 template <>
115 class OsgUniform<std::shared_ptr<OsgTextureCubeMap>> : public OsgTextureUniform<OsgTextureCubeMap>
116 {
117 public:
120  explicit OsgUniform(const std::string& name) : OsgTextureUniform<OsgTextureCubeMap>(name)
121  {
122  }
123 };
124 
126 template <>
127 class OsgUniform<std::shared_ptr<OsgTextureRectangle>> : public OsgTextureUniform<OsgTextureRectangle>
128 {
129 public:
132  explicit OsgUniform(const std::string& name) : OsgTextureUniform<OsgTextureRectangle>(name)
133  {
134  }
135 };
136 
137 }; // namespace Graphics
138 
139 }; // namespace SurgSim
140 
141 #endif // SURGSIM_GRAPHICS_OSGTEXTUREUNIFORM_H
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
size_t getMinimumTextureUnit() const
Definition: OsgTextureUniform-inl.h:127
Definition: MockObjects.h:47
OsgUniform(const std::string &name)
Constructor.
Definition: OsgTextureUniform.h:108
OSG implementation of a Cube Map Texture.
Definition: OsgTextureCubeMap.h:38
OSG implementation of graphics uniform with a value of type T.
Definition: OsgCamera.h:46
OsgUniform(const std::string &name)
Constructor.
Definition: OsgTextureUniform.h:96
OSG implementation of a 3D Texture.
Definition: OsgTexture3d.h:38
Base OSG implementation of graphics uniforms.
Definition: OsgUniformBase.h:41
OsgUniform(const std::string &name)
Constructor.
Definition: OsgTextureUniform.h:132
virtual void removeFromStateSet(osg::StateSet *stateSet)
Removes this uniform from the OSG state set.
Definition: OsgTextureUniform-inl.h:111
OsgTextureUniform(const std::string &name)
Constructor.
Definition: OsgTextureUniform-inl.h:37
void setMinimumTextureUnit(size_t unit)
This is the texture unit from where the search for a free texture unit will start.
Definition: OsgTextureUniform-inl.h:120
Base class for a graphics uniform with a value of type T.
Definition: Uniform.h:32
OSG implementation of graphics uniform with a texture value.
Definition: OsgTextureUniform.h:30
OSG implementation of a Rectangle Texture.
Definition: OsgTextureRectangle.h:40
virtual void addToStateSet(osg::StateSet *stateSet)
Adds this uniform to the OSG state set.
Definition: OsgTextureUniform-inl.h:72
OsgUniform(const std::string &name)
Constructor.
Definition: OsgTextureUniform.h:84
OSG implementation of a 1D Texture.
Definition: OsgTexture1d.h:38
OsgUniform(const std::string &name)
Constructor.
Definition: OsgTextureUniform.h:120
OSG implementation of a 2D Texture.
Definition: OsgTexture2d.h:42