MeVisLab Toolbox Reference
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 
29 class SoState;
30 class SoSensor;
31 class SoGLRenderAction;
32 class SoGLShaderProgram;
33 
36 class INVENTOR_SHADER_API SoGLInventorShaderProgram : public SoGLShaderProgram
37 {
38 public:
40 
42  void preLinkSetup() override;
43 
45  void postLinkSetup() override;
46 
48  void updateUniformsFromState(SoState*) override;
49 
50 private:
51 
52  enum BindingPoint {
53  LightBindingPoint,
54  ClipPlaneBindingPoint,
55  MaterialBindingPoint
56  };
57  GLint _modelViewProjLoc;
58  GLint _modelViewLoc;
59  GLint _modelLoc;
60  GLint _modelNormalMatrixLoc;
61  GLint _viewLoc;
62  GLint _projLoc;
63  GLint _modelViewNormalMatrixLoc;
64 
65  GLint _projInverseLoc;
66  GLint _modelInverseLoc;
67  GLint _viewInverseLoc;
68  GLint _modelViewInverseLoc;
69  GLint _modelViewProjInverseLoc;
70 
71  GLint _lightModelAmbientLoc;
72 
73  unsigned int _lastProjMatrixId;
74  unsigned int _lastModelViewMatrixId;
75 
76  GLint _lightBlockIndex;
77  GLint _clipPlaneBlockIndex;
78  GLint _materialBlockIndex;
79 
80  struct UniformBuffer {
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 
98 class INVENTOR_SHADER_API SoShaderProgram : public SoNode
99 {
100  typedef SoNode inherited;
101 
102  SO_NODE_HEADER(SoShaderProgram);
103 
104  public:
105 
111  TRIANGLES_ADJACENCY_INPUT
112  };
116  TRIANGLE_STRIP_OUTPUT
117  };
118 
121 
124 
127 
130 
133 
136 
137  SoEXTENDER public:
138 
140  void GLRender(SoGLRenderAction *action) override;
141 
142  SoGLShaderProgram * getGLShaderProgram() { return _glShaderProgram; }
143 
144  SoINTERNAL public:
145 
147  static void initClass();
148 
149  protected:
150 
152 
155 
157  ~SoShaderProgram() override;
158 
160  void setup();
161 
163  SbBool isValidShaderObjects() const;
164 
165  void adaptParametersList(const SbPList &nextParameters);
166  void adaptShadersList(SbPList &prevShaders, const SbPList &nextShaders);
169 
174  void updateOIVStateDependentParameters(SoState *state);
175 
176  private:
177 
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 
193 #endif // _SO_SHADER_PROGRAM_
Derived class which supports OpenGL legacy emulation and updating of uniforms when rendering Inventor...
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.
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.
Open Inventor shader program node.
SoGLShaderProgram * getGLShaderProgram()
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.
SbPList _usedShaderParameters
Shader parameters known via element.
SoSFEnum geometryOutputType
Kind of primitives the geometry shader will output.
~SoShaderProgram() override
Destructor.
void updateOIVStateDependentParameters(SoState *state)
Assigns Open Inventor state to some predefined uniform parameters.
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.
@ NUM_SHADER_TYPES
Definition: SoShaderTypes.h:30