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