MeVisLab Resolution Independence API
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
36 protected:
37
39
43
44 public:
45
48
51
53 void reset() override;
54
55 void addShaderObject(SoGLShaderObject *shaderObject);
58
59 void enable();
60 void disable();
61
63
64 void setGeometryInputType(GLint type) {
65 if (_geometryInputType != type) { _geometryInputType = type; scheduleLinking(); }
66 }
67 void setGeometryOutputType(GLint type) {
68 if (_geometryOutputType != type) { _geometryOutputType = type; scheduleLinking(); }
69 }
70 void setGeometryVerticesOut(GLint number) {
71 if (_geometryVerticesOut != number) { _geometryVerticesOut = number; scheduleLinking(); }
72 }
73
76 virtual void updateUniformsFromState(SoState*) {};
77 virtual void preLinkSetup() {};
78 virtual void postLinkSetup() {};
79
80 virtual SbBool isActiveUniform(const SbString &name);
81
83 virtual void clearAssignedTextureUnits() { _assignedTextureUnits = 0; }
84
85 int getNumAssignedTextureUnits() { return _assignedTextureUnits; }
86 void setNumAssignedTextureUnits(int num) { _assignedTextureUnits = num; }
87
89 int addTextureSampler(const SbString &name) override;
90
91 void set1f(const SbString &name, const float value) override;
92 void set2f(const SbString &name, const float *value) override;
93 void set3f(const SbString &name, const float *value) override;
94 void set4f(const SbString &name, const float *value) override;
95 void set2f(const SbString &name, const float value0, const float value1) override;
96 void set3f(const SbString &name, const float value0, const float value1, const float value2) override;
97 void set4f(const SbString &name, const float value0, const float value1, const float value2, const float value3) override;
98
99 void set1fv(const SbString &name, const int num, const float *value) override;
100 void set2fv(const SbString &name, const int num, const float *value) override;
101 void set3fv(const SbString &name, const int num, const float *value) override;
102 void set4fv(const SbString &name, const int num, const float *value) override;
103
104 void set1i(const SbString &name, const int32_t value) override;
105 void set2i(const SbString &name, const int32_t *value) override;
106 void set2i(const SbString &name, const SbVec2s &value) override;
107 void set3i(const SbString &name, const int32_t *value) override;
108 void set3i(const SbString &name, const SbVec3s &value) override;
109 void set4i(const SbString &name, const int32_t *value) override;
110
111 void setMatrix3fv(const SbString & /*name*/, int /*num*/, const float * /*value*/, SbBool /*transpose*/ = FALSE) override;
112 void setMatrix4fv(const SbString & /*name*/, int /*num*/, const float * /*value*/, SbBool /*transpose*/ = FALSE) override;
113
114 void setName(const SbString& name) { _name = name; }
115
116 const SbString& getName() const { return _name; }
117
120
121 SoINTERNAL public:
122
124 LR_FAILURE = 0,
125 LR_SUCCESS = 1,
126 LR_SKIPPED = 2
127 };
128
130 return _programRes;
131 }
132
133 GLuint getProgramHandle() const {
134 return _programRes.getHandle();
135 }
136
138 bool isValid();
139
140 SbBool isExecutable() const {
141 return _isExecutable;
142 }
143
144 SbBool shouldLink() const {
145 return _shouldLink;
146 }
147
149
150 void updateUniformInfo(GLint programHandle);
151
152 void setAlwaysReadErrorLog(bool flag) { _alwaysReadErrorLog = flag; }
153 bool alwaysReadErrorLog() { return _alwaysReadErrorLog; }
154
155 bool hadLinkError() { return _hadError; }
156 const SbString& getErrorLog() { return _errorLog; }
157
158 protected:
159
160 std::list<SoGLShaderObject *> _shaderObjects;
163
164 SbString _name;
165
167
169 struct UniformInfo {
170 GLint location;
171 GLenum type;
172 GLint size;
173 UniformInfo() : location(-1), type(GL_INT), size(0) {}
174 UniformInfo(GLint _location, GLenum _type, GLint _size) : location(_location), type(_type), size(_size) {}
175 };
176 std::map<std::string, UniformInfo> _uniformInfo;
177
178 GLint getUniform(const SbString &name, GLenum type, int *num = nullptr);
179
182 SbString _errorLog;
183};
184
185#endif // _SO_GL_SHADER_PROGRAM_
#define INVENTOR_SHADER_API
Define class export specifier.
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()
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
std::list< SoGLShaderObject * > _shaderObjects
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.
GLSL Program resource.
GLuint getHandle() const
get the program's handle (you need to create() the buffer before you get a handle)
Information structure for SoGLShaderObject containing location, type, and size.
UniformInfo(GLint _location, GLenum _type, GLint _size)