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 
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 private:
64  std::shared_ptr<T> m_texture;
65 
66  osg::ref_ptr<osg::StateSet> m_stateset;
67 
69  ptrdiff_t m_unit;
70 
73 };
74 
76 template <>
77 class OsgUniform<std::shared_ptr<OsgTexture1d>> : public OsgTextureUniform<OsgTexture1d>
78 {
79 public:
82  explicit OsgUniform(const std::string& name) : OsgTextureUniform<OsgTexture1d>(name)
83  {
84  }
85 };
86 
88 template <>
89 class OsgUniform<std::shared_ptr<OsgTexture2d>> : public OsgTextureUniform<OsgTexture2d>
90 {
91 public:
94  explicit OsgUniform(const std::string& name) : OsgTextureUniform<OsgTexture2d>(name)
95  {
96  }
97 };
98 
100 template <>
101 class OsgUniform<std::shared_ptr<OsgTexture3d>> : public OsgTextureUniform<OsgTexture3d>
102 {
103 public:
106  explicit OsgUniform(const std::string& name) : OsgTextureUniform<OsgTexture3d>(name)
107  {
108  }
109 };
110 
112 template <>
113 class OsgUniform<std::shared_ptr<OsgTextureCubeMap>> : public OsgTextureUniform<OsgTextureCubeMap>
114 {
115 public:
118  explicit OsgUniform(const std::string& name) : OsgTextureUniform<OsgTextureCubeMap>(name)
119  {
120  }
121 };
122 
124 template <>
125 class OsgUniform<std::shared_ptr<OsgTextureRectangle>> : public OsgTextureUniform<OsgTextureRectangle>
126 {
127 public:
130  explicit OsgUniform(const std::string& name) : OsgTextureUniform<OsgTextureRectangle>(name)
131  {
132  }
133 };
134 
135 }; // namespace Graphics
136 
137 }; // namespace SurgSim
138 
139 #endif // SURGSIM_GRAPHICS_OSGTEXTUREUNIFORM_H
SurgSim::Graphics::OsgUniformBase
Base OSG implementation of graphics uniforms.
Definition: OsgUniformBase.h:41
SurgSim::Graphics::OsgTextureUniform::OsgTextureUniform
OsgTextureUniform(const std::string &name)
Constructor.
Definition: OsgTextureUniform-inl.h:37
SurgSim::Graphics::OsgTextureRectangle
OSG implementation of a Rectangle Texture.
Definition: OsgTextureRectangle.h:40
SurgSim::Graphics::OsgTextureUniform::addToStateSet
virtual void addToStateSet(osg::StateSet *stateSet)
Adds this uniform to the OSG state set.
Definition: OsgTextureUniform-inl.h:72
SurgSim::Graphics::OsgTextureUniform::m_unit
ptrdiff_t m_unit
Texture unit.
Definition: OsgTextureUniform.h:69
SurgSim::Graphics::OsgTextureUniform::setMinimumTextureUnit
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
SurgSim::Graphics::OsgUniform< std::shared_ptr< OsgTextureRectangle > >::OsgUniform
OsgUniform(const std::string &name)
Constructor.
Definition: OsgTextureUniform.h:130
SurgSim::Graphics::OsgTextureUniform::removeFromStateSet
virtual void removeFromStateSet(osg::StateSet *stateSet)
Removes this uniform from the OSG state set.
Definition: OsgTextureUniform-inl.h:111
SurgSim::Graphics::OsgUniform< std::shared_ptr< OsgTexture3d > >::OsgUniform
OsgUniform(const std::string &name)
Constructor.
Definition: OsgTextureUniform.h:106
SurgSim::Graphics::OsgTextureUniform::m_minimumTextureUnit
size_t m_minimumTextureUnit
The smallest unit to be used.
Definition: OsgTextureUniform.h:72
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Graphics::OsgTexture3d
OSG implementation of a 3D Texture.
Definition: OsgTexture3d.h:38
SurgSim::Graphics::OsgUniform
OSG implementation of graphics uniform with a value of type T.
Definition: OsgCamera.h:46
SurgSim::Graphics::OsgUniform< std::shared_ptr< OsgTextureCubeMap > >::OsgUniform
OsgUniform(const std::string &name)
Constructor.
Definition: OsgTextureUniform.h:118
SurgSim::Graphics::OsgTextureUniform::set
virtual void set(const std::shared_ptr< T > &value)
Sets the value of the uniform.
Definition: OsgTextureUniform-inl.h:50
SurgSim::Graphics::OsgUniform< std::shared_ptr< OsgTexture2d > >::OsgUniform
OsgUniform(const std::string &name)
Constructor.
Definition: OsgTextureUniform.h:94
SurgSim::Graphics::OsgTextureUniform::getMinimumTextureUnit
size_t getMinimumTextureUnit() const
Definition: OsgTextureUniform-inl.h:127
SurgSim::Graphics::OsgTextureUniform::m_texture
std::shared_ptr< T > m_texture
Texture.
Definition: OsgTextureUniform.h:64
SurgSim::Graphics::OsgTextureUniform::get
virtual const std::shared_ptr< T > & get() const
Returns the value of the uniform.
Definition: OsgTextureUniform-inl.h:66
SurgSim::Graphics::OsgTextureUniform::m_stateset
osg::ref_ptr< osg::StateSet > m_stateset
Definition: OsgTextureUniform.h:66
SurgSim::Graphics::OsgTextureCubeMap
OSG implementation of a Cube Map Texture.
Definition: OsgTextureCubeMap.h:38
SurgSim::Graphics::OsgUniform< std::shared_ptr< OsgTexture1d > >::OsgUniform
OsgUniform(const std::string &name)
Constructor.
Definition: OsgTextureUniform.h:82
SurgSim::Graphics::OsgTexture1d
OSG implementation of a 1D Texture.
Definition: OsgTexture1d.h:38
SurgSim::Graphics::OsgTexture2d
OSG implementation of a 2D Texture.
Definition: OsgTexture2d.h:42
SurgSim::Graphics::OsgTextureUniform
OSG implementation of graphics uniform with a texture value.
Definition: OsgTextureUniform.h:30
SurgSim::Graphics::Uniform
Base class for a graphics uniform with a value of type T.
Definition: Uniform.h:32