MeVisLab Toolbox Reference
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:
37 ml::GLSLProgram _programRes;
38
42
43public:
46
49
51 void reset() override;
52
53 void addShaderObject(SoGLShaderObject* shaderObject);
56
57 void enable();
58 void disable();
59
61
63 {
64 if (_geometryInputType != type) {
65 _geometryInputType = type;
66 scheduleLinking();
67 }
68 }
70 {
71 if (_geometryOutputType != type) {
72 _geometryOutputType = type;
73 scheduleLinking();
74 }
75 }
77 {
78 if (_geometryVerticesOut != number) {
79 _geometryVerticesOut = number;
80 scheduleLinking();
81 }
82 }
83
87 virtual void preLinkSetup() {};
88 virtual void postLinkSetup() {};
89
90 virtual SbBool isActiveUniform(const SbString& name);
91
94 {
95 _assignedTextureUnits = 0;
96 }
97
99 {
100 return _assignedTextureUnits;
101 }
103 {
104 _assignedTextureUnits = num;
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
150
152 LR_FAILURE = 0,
153 LR_SUCCESS = 1,
154 LR_SKIPPED = 2
155 };
156
157 ml::GLSLProgram& getProgramResource()
158 {
159 return _programRes;
160 }
161
163 {
164 return _programRes.getHandle();
165 }
166
168 bool isValid();
169
171 {
172 return _isExecutable;
173 }
174
176 {
177 return _shouldLink;
178 }
179
181
183
185 {
186 _alwaysReadErrorLog = flag;
187 }
189 {
190 return _alwaysReadErrorLog;
191 }
192
194 {
195 return _hadError;
196 }
198 {
199 return _errorLog;
200 }
201
202protected:
203 std::list<SoGLShaderObject*> _shaderObjects;
206
208
210
213 {
218 : location(-1)
219 , type(GL_INT)
220 , size(0)
221 {}
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
235};
236
237#endif // _SO_GL_SHADER_PROGRAM_
Vertex or fragment shader object class.
Class managing an OpenGL shader program.
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 *)
Update the shader uniforms according to the current Inventor state.
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
Abstract base class for shader objects.
Definition SoGLShader.h:28
Base class for uniform shader parameters.
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
Information structure for SoGLShaderObject containing location, type, and size.
UniformInfo(GLint _location, GLenum _type, GLint _size)