1 // Created on: 2013-09-19
2 // Created by: Denis BOGOLEPOV
3 // Copyright (c) 2013 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
20 #ifndef _OpenGl_ShaderProgram_Header
21 #define _OpenGl_ShaderProgram_Header
23 #include <NCollection_DataMap.hxx>
24 #include <NCollection_Sequence.hxx>
25 #include <TCollection_AsciiString.hxx>
27 #include <Graphic3d_ShaderObject.hxx>
28 #include <Graphic3d_ShaderProgram.hxx>
30 #include <InterfaceGraphic_tgl_all.hxx>
32 #include <OpenGl_Vec.hxx>
33 #include <OpenGl_Matrix.hxx>
34 #include <OpenGl_ShaderObject.hxx>
35 #include <Handle_OpenGl_ShaderProgram.hxx>
37 //! The enumeration of OCCT-specific OpenGL/GLSL variables.
38 enum OpenGl_StateVariable
40 // OpenGL matrix state
41 OpenGl_OCC_MODEL_WORLD_MATRIX,
42 OpenGl_OCC_WORLD_VIEW_MATRIX,
43 OpenGl_OCC_PROJECTION_MATRIX,
44 OpenGl_OCC_MODEL_WORLD_MATRIX_INVERSE,
45 OpenGl_OCC_WORLD_VIEW_MATRIX_INVERSE,
46 OpenGl_OCC_PROJECTION_MATRIX_INVERSE,
47 OpenGl_OCC_MODEL_WORLD_MATRIX_TRANSPOSE,
48 OpenGl_OCC_WORLD_VIEW_MATRIX_TRANSPOSE,
49 OpenGl_OCC_PROJECTION_MATRIX_TRANSPOSE,
50 OpenGl_OCC_MODEL_WORLD_MATRIX_INVERSE_TRANSPOSE,
51 OpenGl_OCC_WORLD_VIEW_MATRIX_INVERSE_TRANSPOSE,
52 OpenGl_OCC_PROJECTION_MATRIX_INVERSE_TRANSPOSE,
54 // OpenGL clip planes state
55 OpenGl_OCC_CLIP_PLANE_0_EQUATION,
56 OpenGl_OCC_CLIP_PLANE_1_EQUATION,
57 OpenGl_OCC_CLIP_PLANE_2_EQUATION,
58 OpenGl_OCC_CLIP_PLANE_3_EQUATION,
59 OpenGl_OCC_CLIP_PLANE_4_EQUATION,
60 OpenGl_OCC_CLIP_PLANE_5_EQUATION,
61 OpenGl_OCC_CLIP_PLANE_6_EQUATION,
62 OpenGl_OCC_CLIP_PLANE_7_EQUATION,
63 OpenGl_OCC_CLIP_PLANE_0_SPACE,
64 OpenGl_OCC_CLIP_PLANE_1_SPACE,
65 OpenGl_OCC_CLIP_PLANE_2_SPACE,
66 OpenGl_OCC_CLIP_PLANE_3_SPACE,
67 OpenGl_OCC_CLIP_PLANE_4_SPACE,
68 OpenGl_OCC_CLIP_PLANE_5_SPACE,
69 OpenGl_OCC_CLIP_PLANE_6_SPACE,
70 OpenGl_OCC_CLIP_PLANE_7_SPACE,
72 OpenGl_OCC_LIGHT_SOURCE_COUNT,
75 OpenGl_OCC_LIGHT_SOURCE_0_TYPE,
76 OpenGl_OCC_LIGHT_SOURCE_1_TYPE,
77 OpenGl_OCC_LIGHT_SOURCE_2_TYPE,
78 OpenGl_OCC_LIGHT_SOURCE_3_TYPE,
79 OpenGl_OCC_LIGHT_SOURCE_4_TYPE,
80 OpenGl_OCC_LIGHT_SOURCE_5_TYPE,
81 OpenGl_OCC_LIGHT_SOURCE_6_TYPE,
82 OpenGl_OCC_LIGHT_SOURCE_7_TYPE,
83 OpenGl_OCC_LIGHT_SOURCE_0_HEAD,
84 OpenGl_OCC_LIGHT_SOURCE_1_HEAD,
85 OpenGl_OCC_LIGHT_SOURCE_2_HEAD,
86 OpenGl_OCC_LIGHT_SOURCE_3_HEAD,
87 OpenGl_OCC_LIGHT_SOURCE_4_HEAD,
88 OpenGl_OCC_LIGHT_SOURCE_5_HEAD,
89 OpenGl_OCC_LIGHT_SOURCE_6_HEAD,
90 OpenGl_OCC_LIGHT_SOURCE_7_HEAD,
91 OpenGl_OCC_LIGHT_SOURCE_0_AMBIENT,
92 OpenGl_OCC_LIGHT_SOURCE_1_AMBIENT,
93 OpenGl_OCC_LIGHT_SOURCE_2_AMBIENT,
94 OpenGl_OCC_LIGHT_SOURCE_3_AMBIENT,
95 OpenGl_OCC_LIGHT_SOURCE_4_AMBIENT,
96 OpenGl_OCC_LIGHT_SOURCE_5_AMBIENT,
97 OpenGl_OCC_LIGHT_SOURCE_6_AMBIENT,
98 OpenGl_OCC_LIGHT_SOURCE_7_AMBIENT,
99 OpenGl_OCC_LIGHT_SOURCE_0_DIFFUSE,
100 OpenGl_OCC_LIGHT_SOURCE_1_DIFFUSE,
101 OpenGl_OCC_LIGHT_SOURCE_2_DIFFUSE,
102 OpenGl_OCC_LIGHT_SOURCE_3_DIFFUSE,
103 OpenGl_OCC_LIGHT_SOURCE_4_DIFFUSE,
104 OpenGl_OCC_LIGHT_SOURCE_5_DIFFUSE,
105 OpenGl_OCC_LIGHT_SOURCE_6_DIFFUSE,
106 OpenGl_OCC_LIGHT_SOURCE_7_DIFFUSE,
107 OpenGl_OCC_LIGHT_SOURCE_0_SPECULAR,
108 OpenGl_OCC_LIGHT_SOURCE_1_SPECULAR,
109 OpenGl_OCC_LIGHT_SOURCE_2_SPECULAR,
110 OpenGl_OCC_LIGHT_SOURCE_3_SPECULAR,
111 OpenGl_OCC_LIGHT_SOURCE_4_SPECULAR,
112 OpenGl_OCC_LIGHT_SOURCE_5_SPECULAR,
113 OpenGl_OCC_LIGHT_SOURCE_6_SPECULAR,
114 OpenGl_OCC_LIGHT_SOURCE_7_SPECULAR,
115 OpenGl_OCC_LIGHT_SOURCE_0_POSITION,
116 OpenGl_OCC_LIGHT_SOURCE_1_POSITION,
117 OpenGl_OCC_LIGHT_SOURCE_2_POSITION,
118 OpenGl_OCC_LIGHT_SOURCE_3_POSITION,
119 OpenGl_OCC_LIGHT_SOURCE_4_POSITION,
120 OpenGl_OCC_LIGHT_SOURCE_5_POSITION,
121 OpenGl_OCC_LIGHT_SOURCE_6_POSITION,
122 OpenGl_OCC_LIGHT_SOURCE_7_POSITION,
123 OpenGl_OCC_LIGHT_SOURCE_0_SPOT_CUTOFF,
124 OpenGl_OCC_LIGHT_SOURCE_1_SPOT_CUTOFF,
125 OpenGl_OCC_LIGHT_SOURCE_2_SPOT_CUTOFF,
126 OpenGl_OCC_LIGHT_SOURCE_3_SPOT_CUTOFF,
127 OpenGl_OCC_LIGHT_SOURCE_4_SPOT_CUTOFF,
128 OpenGl_OCC_LIGHT_SOURCE_5_SPOT_CUTOFF,
129 OpenGl_OCC_LIGHT_SOURCE_6_SPOT_CUTOFF,
130 OpenGl_OCC_LIGHT_SOURCE_7_SPOT_CUTOFF,
131 OpenGl_OCC_LIGHT_SOURCE_0_SPOT_EXPONENT,
132 OpenGl_OCC_LIGHT_SOURCE_1_SPOT_EXPONENT,
133 OpenGl_OCC_LIGHT_SOURCE_2_SPOT_EXPONENT,
134 OpenGl_OCC_LIGHT_SOURCE_3_SPOT_EXPONENT,
135 OpenGl_OCC_LIGHT_SOURCE_4_SPOT_EXPONENT,
136 OpenGl_OCC_LIGHT_SOURCE_5_SPOT_EXPONENT,
137 OpenGl_OCC_LIGHT_SOURCE_6_SPOT_EXPONENT,
138 OpenGl_OCC_LIGHT_SOURCE_7_SPOT_EXPONENT,
139 OpenGl_OCC_LIGHT_SOURCE_0_SPOT_DIRECTION,
140 OpenGl_OCC_LIGHT_SOURCE_1_SPOT_DIRECTION,
141 OpenGl_OCC_LIGHT_SOURCE_2_SPOT_DIRECTION,
142 OpenGl_OCC_LIGHT_SOURCE_3_SPOT_DIRECTION,
143 OpenGl_OCC_LIGHT_SOURCE_4_SPOT_DIRECTION,
144 OpenGl_OCC_LIGHT_SOURCE_5_SPOT_DIRECTION,
145 OpenGl_OCC_LIGHT_SOURCE_6_SPOT_DIRECTION,
146 OpenGl_OCC_LIGHT_SOURCE_7_SPOT_DIRECTION,
147 OpenGl_OCC_LIGHT_SOURCE_0_CONST_ATTENUATION,
148 OpenGl_OCC_LIGHT_SOURCE_1_CONST_ATTENUATION,
149 OpenGl_OCC_LIGHT_SOURCE_2_CONST_ATTENUATION,
150 OpenGl_OCC_LIGHT_SOURCE_3_CONST_ATTENUATION,
151 OpenGl_OCC_LIGHT_SOURCE_4_CONST_ATTENUATION,
152 OpenGl_OCC_LIGHT_SOURCE_5_CONST_ATTENUATION,
153 OpenGl_OCC_LIGHT_SOURCE_6_CONST_ATTENUATION,
154 OpenGl_OCC_LIGHT_SOURCE_7_CONST_ATTENUATION,
155 OpenGl_OCC_LIGHT_SOURCE_0_LINEAR_ATTENUATION,
156 OpenGl_OCC_LIGHT_SOURCE_1_LINEAR_ATTENUATION,
157 OpenGl_OCC_LIGHT_SOURCE_2_LINEAR_ATTENUATION,
158 OpenGl_OCC_LIGHT_SOURCE_3_LINEAR_ATTENUATION,
159 OpenGl_OCC_LIGHT_SOURCE_4_LINEAR_ATTENUATION,
160 OpenGl_OCC_LIGHT_SOURCE_5_LINEAR_ATTENUATION,
161 OpenGl_OCC_LIGHT_SOURCE_6_LINEAR_ATTENUATION,
162 OpenGl_OCC_LIGHT_SOURCE_7_LINEAR_ATTENUATION,
165 OpenGl_OCCT_ACTIVE_SAMPLER,
166 OpenGl_OCCT_TEXTURE_ENABLE,
167 OpenGl_OCCT_DISTINGUISH_MODE,
168 OpenGl_OCCT_FRONT_MATERIAL_AMBIENT,
169 OpenGl_OCCT_BACK_MATERIAL_AMBIENT,
170 OpenGl_OCCT_FRONT_MATERIAL_DIFFUSE,
171 OpenGl_OCCT_BACK_MATERIAL_DIFFUSE,
172 OpenGl_OCCT_FRONT_MATERIAL_SPECULAR,
173 OpenGl_OCCT_BACK_MATERIAL_SPECULAR,
174 OpenGl_OCCT_FRONT_MATERIAL_EMISSION,
175 OpenGl_OCCT_BACK_MATERIAL_EMISSION,
176 OpenGl_OCCT_FRONT_MATERIAL_SHININESS,
177 OpenGl_OCCT_BACK_MATERIAL_SHININESS,
178 OpenGl_OCCT_FRONT_MATERIAL_TRANSPARENCY,
179 OpenGl_OCCT_BACK_MATERIAL_TRANSPARENCY,
181 // DON'T MODIFY THIS ITEM (insert new items before it)
182 OpenGl_OCCT_NUMBER_OF_STATE_VARIABLES
185 class OpenGl_ShaderProgram;
187 //! Interface for generic setter of user-defined uniform variables.
188 struct OpenGl_SetterInterface
190 //! Sets user-defined uniform variable to specified program.
191 virtual void Set (const Handle(OpenGl_Context)& theCtx,
192 const Handle(Graphic3d_ShaderVariable)& theVariable,
193 OpenGl_ShaderProgram* theProgram) = 0;
196 virtual ~OpenGl_SetterInterface() {}
199 //! List of OpenGL shader objects.
200 typedef NCollection_Sequence<Handle(OpenGl_ShaderObject)> OpenGl_ShaderList;
202 //! List of shader variable setters.
203 typedef NCollection_DataMap<size_t, OpenGl_SetterInterface*> OpenGl_SetterList;
205 //! Support tool for setting user-defined uniform variables.
206 class OpenGl_VariableSetterSelector
210 //! Creates new setter selector.
211 OpenGl_VariableSetterSelector();
213 //! Releases memory resources of setter selector.
214 ~OpenGl_VariableSetterSelector();
216 //! Sets user-defined uniform variable to specified program.
217 void Set (const Handle(OpenGl_Context)& theCtx,
218 const Handle(Graphic3d_ShaderVariable)& theVariable,
219 OpenGl_ShaderProgram* theProgram) const;
223 //! List of variable setters.
224 OpenGl_SetterList mySetterList;
227 //! Defines types of uniform state variables.
228 enum OpenGl_UniformStateType
230 OpenGl_LIGHT_SOURCES_STATE,
231 OpenGl_CLIP_PLANES_STATE,
232 OpenGl_MODEL_WORLD_STATE,
233 OpenGl_WORLD_VIEW_STATE,
234 OpenGl_PROJECTION_STATE,
235 OpenGl_MATERIALS_STATE
238 //! Total number of state types.
239 const int MaxStateTypes = 6;
241 //! Wrapper for OpenGL program object.
242 class OpenGl_ShaderProgram : public OpenGl_Resource
247 //! Non-valid shader name.
248 static const GLuint NO_PROGRAM = 0;
250 //! Invalid location of uniform/attribute variable.
251 static const GLint INVALID_LOCATION = -1;
253 //! List of pre-defined OCCT state uniform variables.
254 static Standard_CString PredefinedKeywords[OpenGl_OCCT_NUMBER_OF_STATE_VARIABLES];
258 //! Creates uninitialized shader program.
259 Standard_EXPORT OpenGl_ShaderProgram (const Handle(Graphic3d_ShaderProgram)& theProxy = NULL);
261 static OpenGl_VariableSetterSelector mySetterSelector;
265 //! Releases resources of shader program.
266 Standard_EXPORT virtual ~OpenGl_ShaderProgram();
268 //! Creates new empty shader program of specified type.
269 Standard_EXPORT Standard_Boolean Create (const Handle(OpenGl_Context)& theCtx);
271 //! Destroys shader program.
272 Standard_EXPORT virtual void Release (const OpenGl_Context* theCtx);
274 //! Attaches shader object to the program object.
275 Standard_EXPORT Standard_Boolean AttachShader (const Handle(OpenGl_Context)& theCtx,
276 const Handle(OpenGl_ShaderObject)& theShader);
278 //! Detaches shader object to the program object.
279 Standard_EXPORT Standard_Boolean DetachShader (const Handle(OpenGl_Context)& theCtx,
280 const Handle(OpenGl_ShaderObject)& theShader);
282 //! Initializes program object with the list of shader objects.
283 Standard_EXPORT Standard_Boolean Initialize (const Handle(OpenGl_Context)& theCtx,
284 const Graphic3d_ShaderObjectList& theShaders);
286 //! Links the program object.
287 Standard_EXPORT Standard_Boolean Link (const Handle(OpenGl_Context)& theCtx);
289 //! Fetches information log of the last link operation.
290 Standard_EXPORT Standard_Boolean FetchInfoLog (const Handle(OpenGl_Context)& theCtx,
291 TCollection_AsciiString& theLog);
293 //! Fetches uniform variables from proxy shader program.
294 Standard_EXPORT Standard_Boolean ApplyVariables (const Handle(OpenGl_Context)& theCtx);
296 //! Sets the program object as part of current rendering state.
297 Standard_EXPORT void Bind (const Handle(OpenGl_Context)& theCtx) const;
299 //! Binds the program object and applies variables from proxy shader program.
300 Standard_EXPORT Standard_Boolean BindWithVariables (const Handle(OpenGl_Context)& theCtx);
302 //! Reverts to fixed-function graphics pipeline (FFP).
303 Standard_EXPORT static void Unbind (const Handle(OpenGl_Context)& theCtx);
307 //! Returns index of last modification of variables of specified state type.
308 Standard_EXPORT Standard_Size ActiveState (const OpenGl_UniformStateType theType) const;
310 //! Updates index of last modification of variables of specified state type.
311 Standard_EXPORT void UpdateState (const OpenGl_UniformStateType theType,
312 const Standard_Size theIndex);
316 //! Returns location of the specific uniform variable.
317 Standard_EXPORT GLint GetUniformLocation (const Handle(OpenGl_Context)& theCtx,
318 const GLchar* theName) const;
320 //! Returns index of the generic vertex attribute by variable name.
321 Standard_EXPORT GLint GetAttributeLocation (const Handle(OpenGl_Context)& theCtx,
322 const GLchar* theName) const;
324 //! Returns location of the OCCT state uniform variable.
325 Standard_EXPORT GLint GetStateLocation (const GLuint theVariable) const;
329 //! Returns the value of the integer uniform variable.
330 Standard_EXPORT Standard_Boolean GetUniform (const Handle(OpenGl_Context)& theCtx,
331 const GLchar* theName,
332 OpenGl_Vec4i& theValue) const;
334 Standard_EXPORT Standard_Boolean GetUniform (const Handle(OpenGl_Context)& theCtx,
336 OpenGl_Vec4i& theValue) const;
338 //! Returns the value of the float uniform variable.
339 Standard_EXPORT Standard_Boolean GetUniform (const Handle(OpenGl_Context)& theCtx,
340 const GLchar* theName,
341 OpenGl_Vec4& theValue) const;
343 //! Returns the value of the float uniform variable.
344 Standard_EXPORT Standard_Boolean GetUniform (const Handle(OpenGl_Context)& theCtx,
346 OpenGl_Vec4& theValue) const;
350 //! Returns the integer vertex attribute.
351 Standard_EXPORT Standard_Boolean GetAttribute (const Handle(OpenGl_Context)& theCtx,
352 const GLchar* theName,
353 OpenGl_Vec4i& theValue) const;
355 //! Returns the integer vertex attribute.
356 Standard_EXPORT Standard_Boolean GetAttribute (const Handle(OpenGl_Context)& theCtx,
358 OpenGl_Vec4i& theValue) const;
360 //! Returns the float vertex attribute.
361 Standard_EXPORT Standard_Boolean GetAttribute (const Handle(OpenGl_Context)& theCtx,
362 const GLchar* theName,
363 OpenGl_Vec4& theValue) const;
365 //! Returns the float vertex attribute.
366 Standard_EXPORT Standard_Boolean GetAttribute (const Handle(OpenGl_Context)& theCtx,
368 OpenGl_Vec4& theValue) const;
372 //! Specifies the value of the integer uniform variable.
373 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
374 const GLchar* theName,
377 //! Specifies the value of the integer uniform variable.
378 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
382 //! Specifies the value of the integer uniform 2D vector.
383 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
384 const GLchar* theName,
385 const OpenGl_Vec2i& theValue);
387 //! Specifies the value of the integer uniform 2D vector.
388 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
390 const OpenGl_Vec2i& theValue);
392 //! Specifies the value of the integer uniform 3D vector.
393 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
394 const GLchar* theName,
395 const OpenGl_Vec3i& theValue);
397 //! Specifies the value of the integer uniform 3D vector.
398 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
400 const OpenGl_Vec3i& theValue);
402 //! Specifies the value of the integer uniform 4D vector.
403 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
404 const GLchar* theName,
405 const OpenGl_Vec4i& theValue);
407 //! Specifies the value of the integer uniform 4D vector.
408 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
410 const OpenGl_Vec4i& theValue);
414 //! Specifies the value of the float uniform variable.
415 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
416 const GLchar* theName,
419 //! Specifies the value of the float uniform variable.
420 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
424 //! Specifies the value of the float uniform 2D vector.
425 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
426 const GLchar* theName,
427 const OpenGl_Vec2& theValue);
429 //! Specifies the value of the float uniform 2D vector.
430 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
432 const OpenGl_Vec2& theValue);
434 //! Specifies the value of the float uniform 3D vector.
435 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
436 const GLchar* theName,
437 const OpenGl_Vec3& theValue);
439 //! Specifies the value of the float uniform 3D vector.
440 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
442 const OpenGl_Vec3& theValue);
444 //! Specifies the value of the float uniform 4D vector.
445 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
446 const GLchar* theName,
447 const OpenGl_Vec4& theValue);
449 //! Specifies the value of the float uniform 4D vector.
450 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
452 const OpenGl_Vec4& theValue);
456 //! Specifies the value of the float uniform 4x4 matrix.
457 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
458 const GLchar* theName,
459 const OpenGl_Matrix& theValue,
460 GLboolean theTranspose = GL_FALSE);
462 //! Specifies the value of the float uniform 4x4 matrix.
463 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
465 const OpenGl_Matrix& theValue,
466 GLboolean theTranspose = GL_FALSE);
468 //! Specifies the value of the float uniform 4x4 matrix.
469 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
470 const GLchar* theName,
471 const Tmatrix3& theValue,
472 GLboolean theTranspose = GL_FALSE);
474 //! Specifies the value of the float uniform 4x4 matrix.
475 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
477 const Tmatrix3& theValue,
478 GLboolean theTranspose = GL_FALSE);
482 //! Specifies the value of the sampler uniform variable.
483 Standard_EXPORT Standard_Boolean SetSampler (const Handle(OpenGl_Context)& theCtx,
484 const GLchar* theName,
485 const GLenum theTextureUnit);
487 //! Specifies the value of the sampler uniform variable.
488 Standard_EXPORT Standard_Boolean SetSampler (const Handle(OpenGl_Context)& theCtx,
490 const GLenum theTextureUnit);
494 //! Increments counter of users.
495 //! Used by OpenGl_ShaderManager.
496 //! @return true when resource has been restored from delayed release queue
499 return ++myShareCount == 1;
502 //! Decrements counter of users.
503 //! Used by OpenGl_ShaderManager.
504 //! @return true when there are no more users of this program has been left
507 return --myShareCount == 0;
512 GLuint myProgramID; //!< Handle of OpenGL shader program
513 OpenGl_ShaderList myShaderObjects; //!< List of attached shader objects
514 Handle(Graphic3d_ShaderProgram) myProxy; //!< Proxy shader program (from application layer)
515 Standard_Integer myShareCount; //!< program users count, initialized with 1 (already shared by one user)
519 //! Defines last modification for variables of each state type.
520 Standard_Size myCurrentState[MaxStateTypes];
522 //! Stores locations of OCCT state uniform variables.
523 GLint myStateLocations[OpenGl_OCCT_NUMBER_OF_STATE_VARIABLES];
527 DEFINE_STANDARD_RTTI (OpenGl_ShaderProgram)
528 friend class OpenGl_ShaderManager;
533 struct OpenGl_VariableSetter : public OpenGl_SetterInterface
535 virtual void Set (const Handle(OpenGl_Context)& theCtx,
536 const Handle(Graphic3d_ShaderVariable)& theVariable,
537 OpenGl_ShaderProgram* theProgram)
539 theProgram->SetUniform (theCtx,
540 theVariable->Name().ToCString(),
541 theVariable->Value()->As<T>());
545 namespace OpenGl_HashMapInitializer
547 template<class K, class V>
550 NCollection_DataMap<K, V> myDictionary;
552 MapListOfType (K theKey, V theValue)
554 myDictionary.Bind (theKey, theValue);
557 MapListOfType& operator() (K theKey, V theValue)
559 myDictionary.Bind (theKey, theValue);
563 operator const NCollection_DataMap<K, V>& () const
569 template<class K, class V>
570 MapListOfType<K, V> CreateListOf (K theKey, V theValue)
572 return MapListOfType<K, V> (theKey, theValue);
576 #endif // _OpenGl_ShaderProgram_Header