OsgShader.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_OSGSHADER_H
17 #define SURGSIM_GRAPHICS_OSGSHADER_H
18 
20 
21 #include <osg/Program>
22 #include <osg/StateSet>
23 
24 #include <string>
25 #include <memory>
26 
27 namespace SurgSim
28 {
29 namespace Framework
30 {
31 class ApplicationData;
32 }
33 
34 namespace Graphics
35 {
36 
42 class OsgShader : public Shader
43 {
44 public:
47  OsgShader();
48 
51  virtual void addToStateSet(osg::StateSet* stateSet);
52 
55  virtual void removeFromStateSet(osg::StateSet* stateSet);
56 
58  virtual bool hasVertexShader() const;
59 
61  virtual void clearVertexShader();
62 
66  virtual bool loadVertexShaderSource(const std::string& filePath);
67 
70  virtual void setVertexShaderSource(const std::string& source);
71 
74  virtual bool getVertexShaderSource(std::string* source) const;
75 
77  virtual bool hasGeometryShader() const;
78 
80  virtual void clearGeometryShader();
81 
85  virtual bool loadGeometryShaderSource(const std::string& filePath);
86 
89  virtual void setGeometryShaderSource(const std::string& source);
90 
93  virtual bool getGeometryShaderSource(std::string* source) const;
94 
95 
97  virtual bool hasFragmentShader() const;
98 
100  virtual void clearFragmentShader();
101 
105  virtual bool loadFragmentShaderSource(const std::string& filePath);
106 
109  virtual void setFragmentShaderSource(const std::string& source);
110 
113  virtual bool getFragmentShaderSource(std::string* source) const;
114 
116  osg::ref_ptr<osg::Program> getOsgProgram() const;
117 
120  virtual void setGlobalScope(bool val) override;
121 
124  virtual bool isGlobalScope() const override;
125 
126 
127 private:
129  osg::ref_ptr<osg::Program> m_program;
130 
132  osg::ref_ptr<osg::Shader> m_vertexShader;
134  osg::ref_ptr<osg::Shader> m_geometryShader;
136  osg::ref_ptr<osg::Shader> m_fragmentShader;
137 
140 };
141 
142 std::shared_ptr<SurgSim::Graphics::OsgShader> loadShader(const SurgSim::Framework::ApplicationData& data,
143  const std::string& name);
144 
145 
146 }; // namespace Graphics
147 
148 }; // namespace SurgSim
149 
150 #endif // SURGSIM_GRAPHICS_OSGSHADER_H
Definition: DriveElementFromInputBehavior.cpp:27
OSG-based implementation of a graphics shader.
Definition: OsgShader.h:42
Enable searching for files in a given list of paths, give access to the current directory and wrap bo...
Definition: ApplicationData.h:39
std::shared_ptr< SurgSim::Graphics::OsgShader > loadShader(const SurgSim::Framework::ApplicationData &data, const std::string &name)
Definition: OsgShader.cpp:213
bool m_globalScope
Is the shader supposed to be used globally.
Definition: OsgShader.h:139
osg::ref_ptr< osg::Shader > m_geometryShader
OSG geometry shader.
Definition: OsgShader.h:134
Base class that defines the interface for graphics shaders.
Definition: Shader.h:30
string(TOUPPER ${DEVICE}DEVICE_UPPER_CASE) option(BUILD_DEVICE_ $
Definition: CMakeLists.txt:35
osg::ref_ptr< osg::Program > m_program
OSG program attribute.
Definition: OsgShader.h:129
osg::ref_ptr< osg::Shader > m_vertexShader
OSG vertex shader.
Definition: OsgShader.h:132
osg::ref_ptr< osg::Shader > m_fragmentShader
OSG fragment shader.
Definition: OsgShader.h:136