MeVisLab Resolution Independence API
Loading...
Searching...
No Matches
SoGLShaderProgram.h
Go to the documentation of this file.
1/*************************************************************************************
2**
3** Copyright 2007, MeVis Medical Solutions AG
4**
5** The user may use this file in accordance with the license agreement provided with
6** the Software or, alternatively, in accordance with the terms contained in a
7** written agreement between the user and MeVis Medical Solutions AG.
8**
9** For further information use the contact form at https://www.mevislab.de/contact
10**
11**************************************************************************************/
12
13#ifndef SO_GLSHADER_PROGRAM_H
14#define SO_GLSHADER_PROGRAM_H
15
16
18
19#include "SoShaderSystem.h"
22#include <Inventor/SbString.h>
23#include <mlGLResources.h>
24#include <list>
25#include <map>
26#include <string>
27#include "SoShaderTypes.h"
28
30
33{
34 typedef SoGLShader inherited;
35
36protected:
38
42
43public:
46
49
51 void reset() override;
52
53 void addShaderObject(SoGLShaderObject* shaderObject);
56
57 void enable();
58 void disable();
59
61
62 void setGeometryInputType(GLint type)
63 {
64 if (_geometryInputType != type) {
65 _geometryInputType = type;
67 }
68 }
69 void setGeometryOutputType(GLint type)
70 {
71 if (_geometryOutputType != type) {
74 }
75 }
76 void setGeometryVerticesOut(GLint number)
77 {
78 if (_geometryVerticesOut != number) {
79 _geometryVerticesOut = number;
81 }
82 }
83
86 virtual void updateUniformsFromState(SoState*) {};
87 virtual void preLinkSetup() {};
88 virtual void postLinkSetup() {};
89
90 virtual SbBool isActiveUniform(const SbString& name);
91
94 {
96 }
97
103 {
105 }
106
108 int addTextureSampler(const SbString& name) override;
109
110 void set1f(const SbString& name, const float value) override;
111 void set2f(const SbString& name, const float* value) override;
112 void set3f(const SbString& name, const float* value) override;
113 void set4f(const SbString& name, const float* value) override;
114 void set2f(const SbString& name, const float value0, const float value1) override;
115 void set3f(const SbString& name, const float value0, const float value1, const float value2) override;
116 void set4f(const SbString& name, const float value0, const float value1, const float value2,
117 const float value3) override;
118
119 void set1fv(const SbString& name, const int num, const float* value) override;
120 void set2fv(const SbString& name, const int num, const float* value) override;
121 void set3fv(const SbString& name, const int num, const float* value) override;
122 void set4fv(const SbString& name, const int num, const float* value) override;
123
124 void set1i(const SbString& name, const int32_t value) override;
125 void set2i(const SbString& name, const int32_t* value) override;
126 void set2i(const SbString& name, const SbVec2s& value) override;
127 void set3i(const SbString& name, const int32_t* value) override;
128 void set3i(const SbString& name, const SbVec3s& value) override;
129 void set4i(const SbString& name, const int32_t* value) override;
130
131 void setMatrix3fv(const SbString& /*name*/, int /*num*/, const float* /*value*/,
132 SbBool /*transpose*/ = FALSE) override;
133 void setMatrix4fv(const SbString& /*name*/, int /*num*/, const float* /*value*/,
134 SbBool /*transpose*/ = FALSE) override;
135
136 void setName(const SbString& name)
137 {
138 _name = name;
139 }
140
141 const SbString& getName() const
142 {
143 return _name;
144 }
145
148
149SoINTERNAL public :
150
156
161
162 GLuint getProgramHandle() const
163 {
164 return _programRes.getHandle();
165 }
166
168 bool isValid();
169
170 SbBool isExecutable() const
171 {
172 return _isExecutable;
173 }
174
175 SbBool shouldLink() const
176 {
177 return _shouldLink;
178 }
179
181
182 void updateUniformInfo(GLint programHandle);
183
184 void setAlwaysReadErrorLog(bool flag)
185 {
186 _alwaysReadErrorLog = flag;
187 }
189 {
190 return _alwaysReadErrorLog;
191 }
192
194 {
195 return _hadError;
196 }
197 const SbString& getErrorLog()
198 {
199 return _errorLog;
200 }
201
202protected:
203 std::list<SoGLShaderObject*> _shaderObjects;
206
207 SbString _name;
208
210
213 {
214 GLint location;
215 GLenum type;
216 GLint size;
218 : location(-1)
219 , type(GL_INT)
220 , size(0)
221 {}
222 UniformInfo(GLint _location, GLenum _type, GLint _size)
223 : location(_location)
224 , type(_type)
225 , size(_size)
226 {}
227 };
228 std::map<std::string, UniformInfo> _uniformInfo;
229
230 GLint getUniform(const SbString& name, GLenum type, int* num = nullptr);
231
234 SbString _errorLog;
235};
236
237#endif // _SO_GL_SHADER_PROGRAM_
#define INVENTOR_SHADER_API
Define class export specifier.
Vertex or fragment shader object class.
void setMatrix3fv(const SbString &, int, const float *, SbBool=FALSE) override
void removeShaderObject(SoGLShaderObject *shaderObject)
SbBool isExecutable() const
void set2i(const SbString &name, const SbVec2s &value) override
void set4fv(const SbString &name, const int num, const float *value) override
int shaderVersion(SoShader::ShaderType type) const
Get the used GLSL version for the given shader type.
void set1fv(const SbString &name, const int num, const float *value) override
void setGeometryInputType(GLint type)
virtual void clearAssignedTextureUnits()
Clears the assigned texture units to 0.
bool isValid()
returns if the shader is valid or needs re-creation
const SbString & getName() const
void reset() override
Free all resources (OpenGL too) and reset instance to initial state.
void set4i(const SbString &name, const int32_t *value) override
int addTextureSampler(const SbString &name) override
Adds a new texture sampler with given name and returns the assigned texture unit.
void setGeometryOutputType(GLint type)
void set4f(const SbString &name, const float *value) override
virtual SbBool isActiveUniform(const SbString &name)
ml::GLSLProgram & getProgramResource()
void setMatrix4fv(const SbString &, int, const float *, SbBool=FALSE) override
void set2i(const SbString &name, const int32_t *value) override
void set3f(const SbString &name, const float *value) override
GLuint getProgramHandle() const
virtual void postLinkSetup()
void set3i(const SbString &name, const SbVec3s &value) override
LinkageResult link()
void set3fv(const SbString &name, const int num, const float *value) override
void set4f(const SbString &name, const float value0, const float value1, const float value2, const float value3) override
void removeAllShaderObjects()
void set1f(const SbString &name, const float value) override
virtual void updateUniformsFromState(SoState *)
void set2f(const SbString &name, const float value0, const float value1) override
ml::GLSLProgram _programRes
void setNumAssignedTextureUnits(int num)
const SbString & getErrorLog()
std::list< SoGLShaderObject * > _shaderObjects
GLint getUniform(const SbString &name, GLenum type, int *num=nullptr)
SbBool shouldLink() const
void setAlwaysReadErrorLog(bool flag)
void set2fv(const SbString &name, const int num, const float *value) override
void setName(const SbString &name)
~SoGLShaderProgram() override
Destructor.
void set1i(const SbString &name, const int32_t value) override
std::map< std::string, UniformInfo > _uniformInfo
void set2f(const SbString &name, const float *value) override
void addShaderObject(SoGLShaderObject *shaderObject)
void set3i(const SbString &name, const int32_t *value) override
void updateUniformInfo(GLint programHandle)
SoGLShaderProgram()
Constructor.
virtual void preLinkSetup()
void setGeometryVerticesOut(GLint number)
void set3f(const SbString &name, const float value0, const float value1, const float value2) override
SoGLShader()
Constructor.
SoUniformParameterBase()
Hidden constructor.
GLSL Program resource.
GLuint getHandle() const
Returns the program's handle (you need to create() the buffer before you get a handle).
UniformInfo(GLint _location, GLenum _type, GLint _size)