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