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