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