OsgScreenSpaceQuadRepresentation.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_OSGSCREENSPACEQUADREPRESENTATION_H
17 #define SURGSIM_GRAPHICS_OSGSCREENSPACEQUADREPRESENTATION_H
18 
24 
25 #include <osg/Vec3>
26 
27 #if defined(_MSC_VER)
28 #pragma warning(push)
29 #pragma warning(disable:4250)
30 #endif
31 
32 namespace osg
33 {
34 class Projection;
35 class Geode;
36 class Geometry;
37 }
38 
39 namespace SurgSim
40 {
41 namespace Graphics
42 {
43 
44 class UniformBase;
45 class Texture;
46 class OsgTexture2d;
47 class OsgTextureRectangle;
48 
49 
53 {
54 public:
55 
57  explicit OsgScreenSpaceQuadRepresentation(const std::string& name);
59 
62  virtual void setLocation(double x, double y);
63 
66  virtual void getLocation(double* x, double* y);
67 
71  virtual void setSize(double width, double height) override;
72 
76  virtual void getSize(double* width, double* height) const override;
77 
83  virtual bool setTexture(std::shared_ptr<Texture> texture) override;
84 
90  bool setTexture(std::shared_ptr<OsgTexture2d> texture);
91 
97  bool setTexture(std::shared_ptr<OsgTextureRectangle> texture);
98 
99 protected:
100  virtual void doUpdate(double dt) override;
101 
102  virtual bool doInitialize() override;
103 
104 private:
105 
107  osg::ref_ptr<osg::Geode> m_geode;
108 
110  osg::ref_ptr<osg::Geometry> m_geometry;
111 
113  osg::ref_ptr<osg::Projection> m_projection;
114 
116  osg::Vec3 m_scale;
117 
123 
126  void setTextureCoordinates(float left, float bottom, float right, float top);
127 
132  bool replaceUniform(const std::string& name, std::shared_ptr<SurgSim::Graphics::UniformBase> newUniform);
133 
135  std::shared_ptr<OsgUniform<std::shared_ptr<OsgTexture2d>>> m_textureUniform;
136 
138  std::shared_ptr<OsgUniform<std::shared_ptr<OsgTextureRectangle>>> m_rectangleTextureUniform;
139 
142 
147  std::shared_ptr<OsgMaterial> buildMaterial(
148  const std::string& vertexShaderName,
149  const std::string& fragmentShaderName);
150 };
151 
152 }; // Graphics
153 }; // SurgSim
154 
155 #if defined(_MSC_VER)
156 #pragma warning(pop)
157 #endif
158 
159 #endif
int m_displayHeight
Definition: OsgScreenSpaceQuadRepresentation.h:121
Definition: DriveElementFromInputBehavior.cpp:27
osg::Vec3 m_scale
Size of the quad.
Definition: OsgScreenSpaceQuadRepresentation.h:116
SurgSim::DataStructures::OptionalValue< int > m_texureType
Indicate which type of texture is currently being used.
Definition: OsgScreenSpaceQuadRepresentation.h:141
osg::ref_ptr< osg::Geometry > m_geometry
Local geometry pointer.
Definition: OsgScreenSpaceQuadRepresentation.h:110
int m_displayWidth
Definition: OsgScreenSpaceQuadRepresentation.h:120
std::shared_ptr< OsgUniform< std::shared_ptr< OsgTexture2d > > > m_textureUniform
Uniform to carry the power of two texture, "texture".
Definition: OsgScreenSpaceQuadRepresentation.h:135
osg::ref_ptr< osg::Projection > m_projection
Projection matrix, needs to be updated when the view is changed.
Definition: OsgScreenSpaceQuadRepresentation.h:113
std::shared_ptr< OsgUniform< std::shared_ptr< OsgTextureRectangle > > > m_rectangleTextureUniform
Uniform to carry the rectangle texture "texture".
Definition: OsgScreenSpaceQuadRepresentation.h:138
osg::ref_ptr< osg::Geode > m_geode
Local geode to contain geometry.
Definition: OsgScreenSpaceQuadRepresentation.h:107
string(TOUPPER ${DEVICE}DEVICE_UPPER_CASE) option(BUILD_DEVICE_ $
Definition: CMakeLists.txt:35
A quad to display on the screen in screen space coordinates, use setPose() to set the position but x...
Definition: ScreenSpaceQuadRepresentation.h:31
Definition: OsgLight.h:33
Base OSG implementation of a graphics representation.
Definition: OsgRepresentation.h:42
Implements the ScreenSpaceQuadRepresentation, provides the uniform &#39;texture&#39; for the texture that it ...
Definition: OsgScreenSpaceQuadRepresentation.h:52