All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OsgTextureUniform.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_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 
50  virtual const std::shared_ptr<T>& get() const;
51 
54  virtual void addToStateSet(osg::StateSet* stateSet);
55 
58  virtual void removeFromStateSet(osg::StateSet* stateSet);
59 
60 private:
62  std::shared_ptr<T> m_texture;
63 
64  osg::ref_ptr<osg::StateSet> m_stateset;
65 
67  ptrdiff_t m_unit;
68 
71 };
72 
74 template <>
75 class OsgUniform<std::shared_ptr<OsgTexture1d>> : public OsgTextureUniform<OsgTexture1d>
76 {
77 public:
80  explicit OsgUniform(const std::string& name) : OsgTextureUniform<OsgTexture1d>(name)
81  {
82  }
83 };
84 
86 template <>
87 class OsgUniform<std::shared_ptr<OsgTexture2d>> : public OsgTextureUniform<OsgTexture2d>
88 {
89 public:
92  explicit OsgUniform(const std::string& name) : OsgTextureUniform<OsgTexture2d>(name)
93  {
94  }
95 };
96 
98 template <>
99 class OsgUniform<std::shared_ptr<OsgTexture3d>> : public OsgTextureUniform<OsgTexture3d>
100 {
101 public:
104  explicit OsgUniform(const std::string& name) : OsgTextureUniform<OsgTexture3d>(name)
105  {
106  }
107 };
108 
110 template <>
111 class OsgUniform<std::shared_ptr<OsgTextureCubeMap>> : public OsgTextureUniform<OsgTextureCubeMap>
112 {
113 public:
116  explicit OsgUniform(const std::string& name) : OsgTextureUniform<OsgTextureCubeMap>(name)
117  {
118  }
119 };
120 
122 template <>
123 class OsgUniform<std::shared_ptr<OsgTextureRectangle>> : public OsgTextureUniform<OsgTextureRectangle>
124 {
125 public:
128  explicit OsgUniform(const std::string& name) : OsgTextureUniform<OsgTextureRectangle>(name)
129  {
130  }
131 };
132 
133 }; // namespace Graphics
134 
135 }; // namespace SurgSim
136 
137 #endif // SURGSIM_GRAPHICS_OSGTEXTUREUNIFORM_H
osg::ref_ptr< osg::StateSet > m_stateset
Definition: OsgTextureUniform.h:64
OsgUniform(const std::string &name)
Constructor.
Definition: OsgTextureUniform.h:104
OSG implementation of a Cube Map Texture.
Definition: OsgTextureCubeMap.h:37
virtual void set(const std::shared_ptr< T > &value)
Sets the value of the uniform.
Definition: OsgTextureUniform-inl.h:48
OSG implementation of graphics uniform with a value of type T.
Definition: OsgCamera.h:46
std::shared_ptr< T > m_texture
Texture.
Definition: OsgTextureUniform.h:62
OsgUniform(const std::string &name)
Constructor.
Definition: OsgTextureUniform.h:92
OSG implementation of a 3D Texture.
Definition: OsgTexture3d.h:38
Base OSG implementation of graphics uniforms.
Definition: OsgUniformBase.h:36
OsgUniform(const std::string &name)
Constructor.
Definition: OsgTextureUniform.h:128
virtual void removeFromStateSet(osg::StateSet *stateSet)
Removes this uniform from the OSG state set.
Definition: OsgTextureUniform-inl.h:97
OsgTextureUniform(const std::string &name)
Constructor.
Definition: OsgTextureUniform-inl.h:35
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:106
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:64
ptrdiff_t m_unit
Texture unit.
Definition: OsgTextureUniform.h:67
OsgUniform(const std::string &name)
Constructor.
Definition: OsgTextureUniform.h:80
OSG implementation of a 1D Texture.
Definition: OsgTexture1d.h:38
OsgUniform(const std::string &name)
Constructor.
Definition: OsgTextureUniform.h:116
OSG implementation of a 2D Texture.
Definition: OsgTexture2d.h:42
size_t m_minimumTextureUnit
The smallest unit to be used.
Definition: OsgTextureUniform.h:70
size_t getMinimumTextureUnit() const
Definition: OsgTextureUniform-inl.h:113