MeVisLab Resolution Independence API
Loading...
Searching...
No Matches
SoShaderProgram.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_SHADER_PROGRAM_H
14#define SO_SHADER_PROGRAM_H
15
16
18
19#include "SoShaderSystem.h"
23#include <Inventor/fields/SoSFEnum.h>
24#include <Inventor/fields/SoSFInt32.h>
25#include <Inventor/nodes/SoSubNode.h>
26#include <Inventor/SbPList.h>
28
29class SoState;
30class SoSensor;
31class SoGLRenderAction;
33
37{
38public:
40
42 void preLinkSetup() override;
43
45 void postLinkSetup() override;
46
48 void updateUniformsFromState(SoState*) override;
49
50private:
51 enum BindingPoint {
52 LightBindingPoint,
53 ClipPlaneBindingPoint,
54 MaterialBindingPoint
55 };
56 GLint _modelViewProjLoc;
57 GLint _modelViewLoc;
58 GLint _modelLoc;
59 GLint _modelNormalMatrixLoc;
60 GLint _viewLoc;
61 GLint _projLoc;
62 GLint _modelViewNormalMatrixLoc;
63
64 GLint _projInverseLoc;
65 GLint _modelInverseLoc;
66 GLint _viewInverseLoc;
67 GLint _modelViewInverseLoc;
68 GLint _modelViewProjInverseLoc;
69
70 GLint _lightModelAmbientLoc;
71
72 unsigned int _lastProjMatrixId;
73 unsigned int _lastModelViewMatrixId;
74
75 GLint _lightBlockIndex;
76 GLint _clipPlaneBlockIndex;
77 GLint _materialBlockIndex;
78
79 struct UniformBuffer
80 {
81
82 void prepare(size_t size, int bindingPoint);
83 void upload(unsigned int dataId, void* data);
84
85 unsigned int _dataId;
86 size_t _size;
87 ml::GLVertexBuffer _buffer;
88 };
89
90 static UniformBuffer* _clipPlaneBuffer;
91 static UniformBuffer* _materialBuffer;
92 static UniformBuffer* _lightBuffer;
93
94 static void calculateInverseTransposed3x3(float* in, float* out);
95};
96
99{
100 typedef SoNode inherited;
101
102 SO_NODE_HEADER(SoShaderProgram);
103
104public:
117
120
123
126
129
132
135
136SoEXTENDER public :
137
139 void GLRender(SoGLRenderAction* action) override;
140
145
146SoINTERNAL public :
147
149 static void initClass();
150
151protected:
153
156
159
161 void setup();
162
164 SbBool isValidShaderObjects() const;
165
166 void adaptParametersList(const SbPList& nextParameters);
167 void adaptShadersList(SbPList& prevShaders, const SbPList& nextShaders);
170
176
177private:
178 SbPList _prevGraphShaders;
179 SbPList _prevFieldShaders;
180
181 // Active shaders containing the main function
182 SoShaderObject* _shaderWithMainFuncForType[SoShader::NUM_SHADER_TYPES];
183 // List of active shaders with snippets
184 SbPList _snippetShadersForType[SoShader::NUM_SHADER_TYPES];
185
186 void shaderObjectChanged(SoField* field = nullptr);
187 void geometryInputTypeChanged(SoField* field = nullptr);
188 void geometryOutputTypeChanged(SoField* field = nullptr);
189 void maxEmittedGeometryVerticesChanged(SoField* field = nullptr);
190};
191
192#endif // _SO_SHADER_PROGRAM_
#define INVENTOR_SHADER_API
Define class export specifier.
void postLinkSetup() override
Store information about uniforms locations.
void preLinkSetup() override
Bind locations before linking the shader program.
void updateUniformsFromState(SoState *) override
Update the shader uniforms according to the current Inventor state.
Class managing an OpenGL shader program.
SoGLShaderProgram()
Constructor.
Open Inventor multiple field managing a list of shader objects.
Open Inventor multiple field managing a list of shader parameters.
Abstract Open Inventor node for vertex or fragment shader nodes.
SoSFEnum geometryInputType
Kind of primitives the geometry shader will accept as input.
SoGLInventorShaderProgram * _glShaderProgram
void adaptShadersList(SbPList &prevShaders, const SbPList &nextShaders)
SoSFInt32 maxEmittedGeometryVertices
Maximum number of points the geometry shader will emit.
SoGLShaderProgram * getGLShaderProgram()
SbPList _usedShaderParameters
Shader parameters known via element.
SoSFEnum geometryOutputType
Kind of primitives the geometry shader will output.
~SoShaderProgram() override
Destructor.
void updateOIVStateDependentParameters(SoState *state)
static void initClass()
Initialize class with runtime type system.
void scheduleShaderObjectRebuild()
SoMFUniformShaderParameter parameter
Collects all shader parameters.
SoMFShaderObject shaderObject
Collects all vertex and fragment shaders.
void injectSnippets()
SoShaderProgram()
Constructor.
SbBool isValidShaderObjects() const
Returns 'TRUE' if all shader objects are valid.
void adaptParametersList(const SbPList &nextParameters)
void GLRender(SoGLRenderAction *action) override
Implements rendering.
void setup()
Initial setup of shader program.