0025885: Visualization, ray tracing - Improve layer processing
[occt.git] / src / OpenGl / OpenGl_ShaderProgram.hxx
1 // Created on: 2013-09-19
2 // Created by: Denis BOGOLEPOV
3 // Copyright (c) 2013-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _OpenGl_ShaderProgram_Header
17 #define _OpenGl_ShaderProgram_Header
18
19 #include <NCollection_DataMap.hxx>
20 #include <NCollection_Sequence.hxx>
21 #include <TCollection_AsciiString.hxx>
22
23 #include <Graphic3d_ShaderObject.hxx>
24 #include <Graphic3d_ShaderProgram.hxx>
25
26 #include <InterfaceGraphic_tgl_all.hxx>
27
28 #include <OpenGl_Vec.hxx>
29 #include <OpenGl_Matrix.hxx>
30 #include <OpenGl_ShaderObject.hxx>
31 #include <Handle_OpenGl_ShaderProgram.hxx>
32
33 //! The enumeration of OCCT-specific OpenGL/GLSL variables.
34 enum OpenGl_StateVariable
35 {
36   // OpenGL matrix state
37   OpenGl_OCC_MODEL_WORLD_MATRIX,
38   OpenGl_OCC_WORLD_VIEW_MATRIX,
39   OpenGl_OCC_PROJECTION_MATRIX,
40   OpenGl_OCC_MODEL_WORLD_MATRIX_INVERSE,
41   OpenGl_OCC_WORLD_VIEW_MATRIX_INVERSE,
42   OpenGl_OCC_PROJECTION_MATRIX_INVERSE,
43   OpenGl_OCC_MODEL_WORLD_MATRIX_TRANSPOSE,
44   OpenGl_OCC_WORLD_VIEW_MATRIX_TRANSPOSE,
45   OpenGl_OCC_PROJECTION_MATRIX_TRANSPOSE,
46   OpenGl_OCC_MODEL_WORLD_MATRIX_INVERSE_TRANSPOSE,
47   OpenGl_OCC_WORLD_VIEW_MATRIX_INVERSE_TRANSPOSE,
48   OpenGl_OCC_PROJECTION_MATRIX_INVERSE_TRANSPOSE,
49
50   // OpenGL clip planes state
51   OpenGl_OCC_CLIP_PLANE_EQUATIONS,
52   OpenGl_OCC_CLIP_PLANE_SPACES,
53   OpenGl_OCC_CLIP_PLANE_COUNT,
54
55   // OpenGL light state
56   OpenGl_OCC_LIGHT_SOURCE_COUNT,
57   OpenGl_OCC_LIGHT_SOURCE_TYPES,
58   OpenGl_OCC_LIGHT_SOURCE_PARAMS,
59   OpenGl_OCC_LIGHT_AMBIENT,
60
61   // Material state
62   OpenGl_OCCT_ACTIVE_SAMPLER,
63   OpenGl_OCCT_TEXTURE_ENABLE,
64   OpenGl_OCCT_DISTINGUISH_MODE,
65   OpenGl_OCCT_FRONT_MATERIAL,
66   OpenGl_OCCT_BACK_MATERIAL,
67   OpenGl_OCCT_COLOR,
68
69   OpenGl_OCCT_POINT_SIZE,
70
71   // DON'T MODIFY THIS ITEM (insert new items before it)
72   OpenGl_OCCT_NUMBER_OF_STATE_VARIABLES
73 };
74
75 class OpenGl_ShaderProgram;
76
77 //! Interface for generic setter of user-defined uniform variables.
78 struct OpenGl_SetterInterface
79 {
80   //! Sets user-defined uniform variable to specified program.
81   virtual void Set (const Handle(OpenGl_Context)&           theCtx,
82                     const Handle(Graphic3d_ShaderVariable)& theVariable,
83                     OpenGl_ShaderProgram*                   theProgram) = 0;
84
85   //! Destructor
86   virtual ~OpenGl_SetterInterface() {}
87 };
88
89 //! List of OpenGL shader objects.
90 typedef NCollection_Sequence<Handle(OpenGl_ShaderObject)>    OpenGl_ShaderList;
91
92 //! List of shader variable setters.
93 typedef NCollection_DataMap<size_t, OpenGl_SetterInterface*> OpenGl_SetterList;
94
95 //! Support tool for setting user-defined uniform variables.
96 class OpenGl_VariableSetterSelector
97 {
98 public:
99
100   //! Creates new setter selector.
101   OpenGl_VariableSetterSelector();
102
103   //! Releases memory resources of setter selector.
104   ~OpenGl_VariableSetterSelector();
105
106   //! Sets user-defined uniform variable to specified program.
107   void Set (const Handle(OpenGl_Context)&           theCtx,
108             const Handle(Graphic3d_ShaderVariable)& theVariable,
109             OpenGl_ShaderProgram*                   theProgram) const;
110
111 private:
112
113   //! List of variable setters.
114   OpenGl_SetterList mySetterList;
115 };
116
117 //! Defines types of uniform state variables.
118 enum OpenGl_UniformStateType
119 {
120   OpenGl_LIGHT_SOURCES_STATE,
121   OpenGl_CLIP_PLANES_STATE,
122   OpenGl_MODEL_WORLD_STATE,
123   OpenGl_WORLD_VIEW_STATE,
124   OpenGl_PROJECTION_STATE,
125   OpenGl_MATERIALS_STATE,
126   OpenGl_SURF_DETAIL_STATE
127 };
128
129 //! Total number of state types.
130 const int MaxStateTypes = 6;
131
132 //! Wrapper for OpenGL program object.
133 class OpenGl_ShaderProgram : public OpenGl_Resource
134 {
135   friend class OpenGl_View;
136
137 public:
138
139   //! Non-valid shader name.
140   static const GLuint NO_PROGRAM = 0;
141
142   //! Invalid location of uniform/attribute variable.
143   static const GLint INVALID_LOCATION = -1;
144
145   //! List of pre-defined OCCT state uniform variables.
146   static Standard_CString PredefinedKeywords[OpenGl_OCCT_NUMBER_OF_STATE_VARIABLES];
147
148 protected:
149
150   //! Creates uninitialized shader program.
151   Standard_EXPORT OpenGl_ShaderProgram (const Handle(Graphic3d_ShaderProgram)& theProxy = NULL);
152
153   static OpenGl_VariableSetterSelector mySetterSelector;
154
155 public:
156
157   //! Releases resources of shader program.
158   Standard_EXPORT virtual ~OpenGl_ShaderProgram();
159
160   //! Creates new empty shader program of specified type.
161   Standard_EXPORT Standard_Boolean Create (const Handle(OpenGl_Context)& theCtx);
162
163   //! Destroys shader program.
164   Standard_EXPORT virtual void Release (OpenGl_Context* theCtx);
165
166   //! Attaches shader object to the program object.
167   Standard_EXPORT Standard_Boolean AttachShader (const Handle(OpenGl_Context)&      theCtx,
168                                                  const Handle(OpenGl_ShaderObject)& theShader);
169
170   //! Detaches shader object to the program object.
171   Standard_EXPORT Standard_Boolean DetachShader (const Handle(OpenGl_Context)&      theCtx,
172                                                  const Handle(OpenGl_ShaderObject)& theShader);
173
174   //! Initializes program object with the list of shader objects.
175   Standard_EXPORT Standard_Boolean Initialize (const Handle(OpenGl_Context)&     theCtx,
176                                                const Graphic3d_ShaderObjectList& theShaders);
177
178   //! Links the program object.
179   Standard_EXPORT Standard_Boolean Link (const Handle(OpenGl_Context)& theCtx);
180
181   //! Fetches information log of the last link operation.
182   Standard_EXPORT Standard_Boolean FetchInfoLog (const Handle(OpenGl_Context)& theCtx,
183                                                  TCollection_AsciiString&      theLog);
184
185   //! Fetches uniform variables from proxy shader program.
186   Standard_EXPORT Standard_Boolean ApplyVariables (const Handle(OpenGl_Context)& theCtx);
187
188   //! @return true if current object was initialized
189   inline bool IsValid() const
190   {
191     return myProgramID != NO_PROGRAM;
192   }
193
194   //! @return program ID
195   inline GLuint ProgramId() const
196   {
197     return myProgramID;
198   }
199
200 private:
201
202   //! Returns index of last modification of variables of specified state type.
203   Standard_EXPORT Standard_Size ActiveState (const OpenGl_UniformStateType theType) const;
204
205   //! Updates index of last modification of variables of specified state type.
206   Standard_EXPORT void UpdateState (const OpenGl_UniformStateType theType,
207                                     const Standard_Size           theIndex);
208
209 public:
210
211   //! Returns location of the specific uniform variable.
212   Standard_EXPORT GLint GetUniformLocation (const Handle(OpenGl_Context)& theCtx,
213                                             const GLchar*                 theName) const;
214
215   //! Returns index of the generic vertex attribute by variable name.
216   Standard_EXPORT GLint GetAttributeLocation (const Handle(OpenGl_Context)& theCtx,
217                                               const GLchar*                 theName) const;
218
219   //! Returns location of the OCCT state uniform variable.
220   Standard_EXPORT GLint GetStateLocation (const GLuint theVariable) const;
221
222 public:
223
224   //! Returns the value of the integer uniform variable.
225   Standard_EXPORT Standard_Boolean GetUniform (const Handle(OpenGl_Context)& theCtx,
226                                                const GLchar*                 theName,
227                                                OpenGl_Vec4i&                 theValue) const;
228
229   Standard_EXPORT Standard_Boolean GetUniform (const Handle(OpenGl_Context)& theCtx,
230                                                GLint                         theLocation,
231                                                OpenGl_Vec4i&                 theValue) const;
232
233   //! Returns the value of the float uniform variable.
234   Standard_EXPORT Standard_Boolean GetUniform (const Handle(OpenGl_Context)& theCtx,
235                                                const GLchar*                 theName,
236                                                OpenGl_Vec4&                  theValue) const;
237
238   //! Returns the value of the float uniform variable.
239   Standard_EXPORT Standard_Boolean GetUniform (const Handle(OpenGl_Context)& theCtx,
240                                                GLint                         theLocation,
241                                                OpenGl_Vec4&                  theValue) const;
242
243 public:
244
245   //! Returns the integer vertex attribute.
246   Standard_EXPORT Standard_Boolean GetAttribute (const Handle(OpenGl_Context)& theCtx,
247                                                  const GLchar*                 theName,
248                                                  OpenGl_Vec4i&                 theValue) const;
249
250   //! Returns the integer vertex attribute.
251   Standard_EXPORT Standard_Boolean GetAttribute (const Handle(OpenGl_Context)& theCtx,
252                                                  GLint                         theIndex,
253                                                  OpenGl_Vec4i&                 theValue) const;
254
255   //! Returns the float vertex attribute.
256   Standard_EXPORT Standard_Boolean GetAttribute (const Handle(OpenGl_Context)& theCtx,
257                                                  const GLchar*                 theName,
258                                                  OpenGl_Vec4&                  theValue) const;
259
260   //! Returns the float vertex attribute.
261   Standard_EXPORT Standard_Boolean GetAttribute (const Handle(OpenGl_Context)& theCtx,
262                                                  GLint                         theIndex,
263                                                  OpenGl_Vec4&                  theValue) const;
264
265 public:
266
267   //! Wrapper for glBindAttribLocation()
268   Standard_EXPORT Standard_Boolean SetAttributeName (const Handle(OpenGl_Context)& theCtx,
269                                                      GLint                         theIndex,
270                                                      const GLchar*                 theName);
271
272   //! Wrapper for glVertexAttrib1f()
273   Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
274                                                  const GLchar*                 theName,
275                                                  GLfloat                       theValue);
276
277   //! Wrapper for glVertexAttrib1f()
278   Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
279                                                  GLint                         theIndex,
280                                                  GLfloat                       theValue);
281
282   //! Wrapper for glVertexAttrib2fv()
283   Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
284                                                  const GLchar*                 theName,
285                                                  const OpenGl_Vec2&            theValue);
286
287   //! Wrapper for glVertexAttrib2fv()
288   Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
289                                                  GLint                         theIndex,
290                                                  const OpenGl_Vec2&            theValue);
291
292   //! Wrapper for glVertexAttrib3fv()
293   Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
294                                                  const GLchar*                 theName,
295                                                  const OpenGl_Vec3&            theValue);
296
297   //! Wrapper for glVertexAttrib3fv()
298   Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
299                                                  GLint                         theIndex,
300                                                  const OpenGl_Vec3&            theValue);
301
302   //! Wrapper for glVertexAttrib4fv()
303   Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
304                                                  const GLchar*                 theName,
305                                                  const OpenGl_Vec4&            theValue);
306
307   //! Wrapper for glVertexAttrib4fv()
308   Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
309                                                  GLint                         theIndex,
310                                                  const OpenGl_Vec4&            theValue);
311
312 public:
313
314   //! Specifies the value of the integer uniform variable.
315   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
316                                                const GLchar*                 theName,
317                                                GLint                         theValue);
318
319   //! Specifies the value of the integer uniform variable.
320   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
321                                                GLint                         theLocation,
322                                                GLint                         theValue);
323
324   //! Specifies the value of the integer uniform 2D vector.
325   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
326                                                const GLchar*                 theName,
327                                                const OpenGl_Vec2i&           theValue);
328
329   //! Specifies the value of the integer uniform 2D vector.
330   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
331                                                GLint                         theLocation,
332                                                const OpenGl_Vec2i&           theValue);
333
334   //! Specifies the value of the integer uniform 3D vector.
335   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
336                                                const GLchar*                 theName,
337                                                const OpenGl_Vec3i&           theValue);
338
339   //! Specifies the value of the integer uniform 3D vector.
340   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
341                                                GLint                         theLocation,
342                                                const OpenGl_Vec3i&           theValue);
343
344   //! Specifies the value of the integer uniform 4D vector.
345   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
346                                                const GLchar*                 theName,
347                                                const OpenGl_Vec4i&           theValue);
348
349   //! Specifies the value of the integer uniform 4D vector.
350   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
351                                                GLint                         theLocation,
352                                                const OpenGl_Vec4i&           theValue);
353
354 public:
355
356   //! Specifies the value of the 64-bit unsigned integer uniform variable.
357   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
358                                                const GLchar*                 theName,
359                                                GLuint64                      theValue);
360
361   //! Specifies the value of the 64-bit unsigned integer uniform variable.
362   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
363                                                GLint                         theLocation,
364                                                GLuint64                      theValue);
365
366   //! Specifies the value of the 64-bit unsigned integer uniform array.
367   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
368                                                const GLchar*                 theName,
369                                                const GLsizei                 theCount,
370                                                const GLuint64*               theValue);
371
372   //! Specifies the value of the 64-bit unsigned integer uniform array.
373   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
374                                                GLint                         theLocation,
375                                                const GLsizei                 theCount,
376                                                const GLuint64*               theValue);
377
378 public:
379
380   //! Specifies the value of the float uniform variable.
381   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
382                                                const GLchar*                 theName,
383                                                GLfloat                       theValue);
384
385   //! Specifies the value of the float uniform variable.
386   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
387                                                GLint                         theLocation,
388                                                GLfloat                       theValue);
389
390   //! Specifies the value of the float uniform 2D vector.
391   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
392                                                const GLchar*                 theName,
393                                                const OpenGl_Vec2&            theValue);
394
395   //! Specifies the value of the float uniform 2D vector.
396   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
397                                                GLint                         theLocation,
398                                                const OpenGl_Vec2&            theValue);
399
400   //! Specifies the value of the float uniform 3D vector.
401   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
402                                                const GLchar*                 theName,
403                                                const OpenGl_Vec3&            theValue);
404
405   //! Specifies the value of the float uniform 3D vector.
406   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
407                                                GLint                         theLocation,
408                                                const OpenGl_Vec3&            theValue);
409
410   //! Specifies the value of the float uniform 4D vector.
411   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
412                                                const GLchar*                 theName,
413                                                const OpenGl_Vec4&            theValue);
414
415   //! Specifies the value of the float uniform 4D vector.
416   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
417                                                GLint                         theLocation,
418                                                const OpenGl_Vec4&            theValue);
419
420 public:
421
422   //! Specifies the value of the float uniform 4x4 matrix.
423   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
424                                                const GLchar*                 theName,
425                                                const OpenGl_Mat4&            theValue,
426                                                GLboolean                     theTranspose = GL_FALSE);
427
428   //! Specifies the value of the float uniform 4x4 matrix.
429   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
430                                                GLint                         theLocation,
431                                                const OpenGl_Mat4&            theValue,
432                                                GLboolean                     theTranspose = GL_FALSE);
433
434   //! Specifies the value of the float uniform 4x4 matrix.
435   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
436                                                const GLchar*                 theName,
437                                                const OpenGl_Matrix&          theValue,
438                                                GLboolean                     theTranspose = GL_FALSE);
439
440   //! Specifies the value of the float uniform 4x4 matrix.
441   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
442                                                GLint                         theLocation,
443                                                const OpenGl_Matrix&          theValue,
444                                                GLboolean                     theTranspose = GL_FALSE);
445
446   //! Specifies the value of the float uniform array
447   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
448                                                GLint                         theLocation,
449                                                GLuint                        theCount,
450                                                const Standard_ShortReal*     theData);
451
452   //! Specifies the value of the float2 uniform array
453   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
454                                                GLint                         theLocation,
455                                                GLuint                        theCount,
456                                                const OpenGl_Vec2*            theData);
457
458   //! Specifies the value of the float3 uniform array
459   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
460                                                GLint                         theLocation,
461                                                GLuint                        theCount,
462                                                const OpenGl_Vec3*            theData);
463
464   //! Specifies the value of the float4 uniform array
465   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
466                                                GLint                         theLocation,
467                                                GLuint                        theCount,
468                                                const OpenGl_Vec4*            theData);
469
470   //! Specifies the value of the integer uniform array
471   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
472                                                GLint                         theLocation,
473                                                GLuint                        theCount,
474                                                const Standard_Integer*       theData);
475
476   //! Specifies the value of the int2 uniform array
477   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
478                                                GLint                         theLocation,
479                                                GLuint                        theCount,
480                                                const OpenGl_Vec2i*           theData);
481
482   //! Specifies the value of the int3 uniform array
483   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
484                                                GLint                         theLocation,
485                                                GLuint                        theCount,
486                                                const OpenGl_Vec3i*           theData);
487
488   //! Specifies the value of the int4 uniform array
489   Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
490                                                GLint                         theLocation,
491                                                GLuint                        theCount,
492                                                const OpenGl_Vec4i*           theData);
493
494 public:
495
496   //! Specifies the value of the sampler uniform variable.
497   Standard_EXPORT Standard_Boolean SetSampler (const Handle(OpenGl_Context)& theCtx,
498                                                const GLchar*                 theName,
499                                                const GLenum                  theTextureUnit);
500
501   //! Specifies the value of the sampler uniform variable.
502   Standard_EXPORT Standard_Boolean SetSampler (const Handle(OpenGl_Context)& theCtx,
503                                                GLint                         theLocation,
504                                                const GLenum                  theTextureUnit);
505
506 protected:
507
508   //! Increments counter of users.
509   //! Used by OpenGl_ShaderManager.
510   //! @return true when resource has been restored from delayed release queue
511   bool Share()
512   {
513     return ++myShareCount == 1;
514   }
515
516   //! Decrements counter of users.
517   //! Used by OpenGl_ShaderManager.
518   //! @return true when there are no more users of this program has been left
519   bool UnShare()
520   {
521     return --myShareCount == 0;
522   }
523
524 protected:
525
526   GLuint                          myProgramID;     //!< Handle of OpenGL shader program
527   OpenGl_ShaderList               myShaderObjects; //!< List of attached shader objects
528   Handle(Graphic3d_ShaderProgram) myProxy;         //!< Proxy shader program (from application layer)
529   Standard_Integer                myShareCount;    //!< program users count, initialized with 1 (already shared by one user)
530
531 protected:
532
533   Standard_Size myCurrentState[MaxStateTypes];  //!< defines last modification for variables of each state type
534
535   //! Stores locations of OCCT state uniform variables.
536   GLint myStateLocations[OpenGl_OCCT_NUMBER_OF_STATE_VARIABLES];
537
538 public:
539
540   DEFINE_STANDARD_RTTI (OpenGl_ShaderProgram)
541   friend class OpenGl_ShaderManager;
542
543 };
544
545 template<class T>
546 struct OpenGl_VariableSetter : public OpenGl_SetterInterface
547 {
548   virtual void Set (const Handle(OpenGl_Context)&           theCtx,
549                     const Handle(Graphic3d_ShaderVariable)& theVariable,
550                     OpenGl_ShaderProgram*                   theProgram)
551   {
552     theProgram->SetUniform (theCtx,
553                             theVariable->Name().ToCString(),
554                             theVariable->Value()->As<T>());
555   }
556 };
557
558 namespace OpenGl_HashMapInitializer
559 {
560   template<class K, class V>
561   struct MapListOfType
562   {
563     NCollection_DataMap<K, V> myDictionary;
564
565     MapListOfType (K theKey, V theValue)
566     {
567       myDictionary.Bind (theKey, theValue);
568     }
569
570     MapListOfType& operator() (K theKey, V theValue)
571     {
572       myDictionary.Bind (theKey, theValue);
573       return *this;
574     }
575
576     operator const NCollection_DataMap<K, V>& () const
577     {
578       return myDictionary;
579     }
580   };
581
582   template<class K, class V>
583   MapListOfType<K, V> CreateListOf (K theKey, V theValue)
584   {
585     return MapListOfType<K, V> (theKey, theValue);
586   }
587 }
588
589 #endif // _OpenGl_ShaderProgram_Header