0029304: Draw Harness, DBRep_DrawableShape - fix inappropriate use of unordered map
[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>
cc8cbabe 28#include <OpenGl_NamedResource.hxx>
30f0ad28 29#include <OpenGl_ShaderObject.hxx>
30f0ad28 30
c04c30b3 31class OpenGl_ShaderProgram;
cc8cbabe 32DEFINE_STANDARD_HANDLE(OpenGl_ShaderProgram, OpenGl_NamedResource)
c04c30b3 33
30f0ad28 34//! The enumeration of OCCT-specific OpenGL/GLSL variables.
35enum OpenGl_StateVariable
36{
37 // OpenGL matrix state
38 OpenGl_OCC_MODEL_WORLD_MATRIX,
39 OpenGl_OCC_WORLD_VIEW_MATRIX,
40 OpenGl_OCC_PROJECTION_MATRIX,
41 OpenGl_OCC_MODEL_WORLD_MATRIX_INVERSE,
42 OpenGl_OCC_WORLD_VIEW_MATRIX_INVERSE,
43 OpenGl_OCC_PROJECTION_MATRIX_INVERSE,
44 OpenGl_OCC_MODEL_WORLD_MATRIX_TRANSPOSE,
45 OpenGl_OCC_WORLD_VIEW_MATRIX_TRANSPOSE,
46 OpenGl_OCC_PROJECTION_MATRIX_TRANSPOSE,
47 OpenGl_OCC_MODEL_WORLD_MATRIX_INVERSE_TRANSPOSE,
48 OpenGl_OCC_WORLD_VIEW_MATRIX_INVERSE_TRANSPOSE,
49 OpenGl_OCC_PROJECTION_MATRIX_INVERSE_TRANSPOSE,
50
51 // OpenGL clip planes state
12381341 52 OpenGl_OCC_CLIP_PLANE_EQUATIONS,
5495fa7e 53 OpenGl_OCC_CLIP_PLANE_COUNT,
30f0ad28 54
55 // OpenGL light state
12381341 56 OpenGl_OCC_LIGHT_SOURCE_COUNT,
57 OpenGl_OCC_LIGHT_SOURCE_TYPES,
58 OpenGl_OCC_LIGHT_SOURCE_PARAMS,
59 OpenGl_OCC_LIGHT_AMBIENT,
30f0ad28 60
61 // Material state
30f0ad28 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
30f0ad28 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,
8613985b 128 OpenGl_MATERIAL_STATE,
129 OpenGl_SURF_DETAIL_STATE,
a1073ae2 130 OpenGL_OIT_STATE,
8613985b 131 OpenGl_UniformStateType_NB
30f0ad28 132};
133
30f0ad28 134//! Wrapper for OpenGL program object.
cc8cbabe 135class OpenGl_ShaderProgram : public OpenGl_NamedResource
30f0ad28 136{
91c60b57 137 friend class OpenGl_View;
cc8cbabe 138 friend class OpenGl_ShaderManager;
139 DEFINE_STANDARD_RTTIEXT(OpenGl_ShaderProgram, OpenGl_NamedResource)
30f0ad28 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.
79104795 177 Standard_EXPORT virtual void Release (OpenGl_Context* theCtx) Standard_OVERRIDE;
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
8e0a2b19 213 //! Return TRUE if program defines tessellation stage.
214 Standard_Boolean HasTessellationStage() const { return myHasTessShader; }
215
30f0ad28 216private:
217
218 //! Returns index of last modification of variables of specified state type.
8613985b 219 Standard_Size ActiveState (const OpenGl_UniformStateType theType) const
220 {
221 return theType < OpenGl_UniformStateType_NB
222 ? myCurrentState[theType]
223 : 0;
224 }
30f0ad28 225
226 //! Updates index of last modification of variables of specified state type.
8613985b 227 void UpdateState (const OpenGl_UniformStateType theType,
228 const Standard_Size theIndex)
229 {
230 if (theType < OpenGl_UniformStateType_NB)
231 {
232 myCurrentState[theType] = theIndex;
233 }
234 }
30f0ad28 235
236public:
237
238 //! Returns location of the specific uniform variable.
239 Standard_EXPORT GLint GetUniformLocation (const Handle(OpenGl_Context)& theCtx,
240 const GLchar* theName) const;
241
242 //! Returns index of the generic vertex attribute by variable name.
243 Standard_EXPORT GLint GetAttributeLocation (const Handle(OpenGl_Context)& theCtx,
244 const GLchar* theName) const;
245
246 //! Returns location of the OCCT state uniform variable.
247 Standard_EXPORT GLint GetStateLocation (const GLuint theVariable) const;
248
249public:
250
251 //! Returns the value of the integer uniform variable.
252 Standard_EXPORT Standard_Boolean GetUniform (const Handle(OpenGl_Context)& theCtx,
253 const GLchar* theName,
254 OpenGl_Vec4i& theValue) const;
255
256 Standard_EXPORT Standard_Boolean GetUniform (const Handle(OpenGl_Context)& theCtx,
257 GLint theLocation,
258 OpenGl_Vec4i& theValue) const;
259
260 //! Returns the value of the float uniform variable.
261 Standard_EXPORT Standard_Boolean GetUniform (const Handle(OpenGl_Context)& theCtx,
262 const GLchar* theName,
263 OpenGl_Vec4& theValue) const;
264
265 //! Returns the value of the float uniform variable.
266 Standard_EXPORT Standard_Boolean GetUniform (const Handle(OpenGl_Context)& theCtx,
267 GLint theLocation,
268 OpenGl_Vec4& theValue) const;
269
270public:
271
272 //! Returns the integer vertex attribute.
273 Standard_EXPORT Standard_Boolean GetAttribute (const Handle(OpenGl_Context)& theCtx,
274 const GLchar* theName,
275 OpenGl_Vec4i& theValue) const;
276
277 //! Returns the integer vertex attribute.
278 Standard_EXPORT Standard_Boolean GetAttribute (const Handle(OpenGl_Context)& theCtx,
279 GLint theIndex,
280 OpenGl_Vec4i& theValue) const;
281
282 //! Returns the float vertex attribute.
283 Standard_EXPORT Standard_Boolean GetAttribute (const Handle(OpenGl_Context)& theCtx,
284 const GLchar* theName,
285 OpenGl_Vec4& theValue) const;
286
287 //! Returns the float vertex attribute.
288 Standard_EXPORT Standard_Boolean GetAttribute (const Handle(OpenGl_Context)& theCtx,
289 GLint theIndex,
290 OpenGl_Vec4& theValue) const;
291
292public:
293
fc73a202 294 //! Wrapper for glBindAttribLocation()
295 Standard_EXPORT Standard_Boolean SetAttributeName (const Handle(OpenGl_Context)& theCtx,
296 GLint theIndex,
297 const GLchar* theName);
298
299 //! Wrapper for glVertexAttrib1f()
300 Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
301 const GLchar* theName,
302 GLfloat theValue);
303
304 //! Wrapper for glVertexAttrib1f()
305 Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
306 GLint theIndex,
307 GLfloat theValue);
308
309 //! Wrapper for glVertexAttrib2fv()
310 Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
311 const GLchar* theName,
312 const OpenGl_Vec2& theValue);
313
314 //! Wrapper for glVertexAttrib2fv()
315 Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
316 GLint theIndex,
317 const OpenGl_Vec2& theValue);
318
319 //! Wrapper for glVertexAttrib3fv()
320 Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
321 const GLchar* theName,
322 const OpenGl_Vec3& theValue);
323
324 //! Wrapper for glVertexAttrib3fv()
325 Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
326 GLint theIndex,
327 const OpenGl_Vec3& theValue);
328
329 //! Wrapper for glVertexAttrib4fv()
330 Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
331 const GLchar* theName,
332 const OpenGl_Vec4& theValue);
333
334 //! Wrapper for glVertexAttrib4fv()
335 Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
336 GLint theIndex,
337 const OpenGl_Vec4& theValue);
338
339public:
340
30f0ad28 341 //! Specifies the value of the integer uniform variable.
342 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
343 const GLchar* theName,
344 GLint theValue);
345
346 //! Specifies the value of the integer uniform variable.
347 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
348 GLint theLocation,
349 GLint theValue);
350
351 //! Specifies the value of the integer uniform 2D vector.
352 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
353 const GLchar* theName,
354 const OpenGl_Vec2i& theValue);
355
356 //! Specifies the value of the integer uniform 2D vector.
357 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
358 GLint theLocation,
359 const OpenGl_Vec2i& theValue);
360
361 //! Specifies the value of the integer uniform 3D vector.
362 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
363 const GLchar* theName,
364 const OpenGl_Vec3i& theValue);
365
366 //! Specifies the value of the integer uniform 3D vector.
367 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
368 GLint theLocation,
369 const OpenGl_Vec3i& theValue);
370
371 //! Specifies the value of the integer uniform 4D vector.
372 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
373 const GLchar* theName,
374 const OpenGl_Vec4i& theValue);
375
376 //! Specifies the value of the integer uniform 4D vector.
377 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
378 GLint theLocation,
379 const OpenGl_Vec4i& theValue);
380
381public:
382
47e9c178 383 //! Specifies the value of the unsigned integer uniform 2D vector (uvec2).
25ef750e 384 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
385 const GLchar* theName,
47e9c178 386 const OpenGl_Vec2u& theValue);
25ef750e 387
47e9c178 388 //! Specifies the value of the unsigned integer uniform 2D vector (uvec2).
25ef750e 389 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
390 GLint theLocation,
47e9c178 391 const OpenGl_Vec2u& theValue);
25ef750e 392
47e9c178 393 //! Specifies the value of the uvec2 uniform array
25ef750e 394 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
395 const GLchar* theName,
396 const GLsizei theCount,
47e9c178 397 const OpenGl_Vec2u* theValue);
25ef750e 398
47e9c178 399 //! Specifies the value of the uvec2 uniform array
25ef750e 400 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
401 GLint theLocation,
402 const GLsizei theCount,
47e9c178 403 const OpenGl_Vec2u* theValue);
25ef750e 404
405public:
406
30f0ad28 407 //! Specifies the value of the float uniform variable.
408 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
409 const GLchar* theName,
410 GLfloat theValue);
411
412 //! Specifies the value of the float uniform variable.
413 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
414 GLint theLocation,
415 GLfloat theValue);
416
417 //! Specifies the value of the float uniform 2D vector.
418 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
419 const GLchar* theName,
420 const OpenGl_Vec2& theValue);
421
422 //! Specifies the value of the float uniform 2D vector.
423 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
424 GLint theLocation,
425 const OpenGl_Vec2& theValue);
426
427 //! Specifies the value of the float uniform 3D vector.
428 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
429 const GLchar* theName,
430 const OpenGl_Vec3& theValue);
431
432 //! Specifies the value of the float uniform 3D vector.
433 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
434 GLint theLocation,
435 const OpenGl_Vec3& theValue);
436
437 //! Specifies the value of the float uniform 4D vector.
438 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
439 const GLchar* theName,
440 const OpenGl_Vec4& theValue);
441
442 //! Specifies the value of the float uniform 4D vector.
443 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
444 GLint theLocation,
445 const OpenGl_Vec4& theValue);
446
447public:
448
449 //! Specifies the value of the float uniform 4x4 matrix.
450 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
451 const GLchar* theName,
25ef750e 452 const OpenGl_Mat4& theValue,
453 GLboolean theTranspose = GL_FALSE);
454
455 //! Specifies the value of the float uniform 4x4 matrix.
456 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
457 GLint theLocation,
458 const OpenGl_Mat4& theValue,
459 GLboolean theTranspose = GL_FALSE);
460
461 //! Specifies the value of the float uniform 4x4 matrix.
462 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
463 const GLchar* theName,
30f0ad28 464 const OpenGl_Matrix& theValue,
465 GLboolean theTranspose = GL_FALSE);
466
467 //! Specifies the value of the float uniform 4x4 matrix.
468 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
469 GLint theLocation,
470 const OpenGl_Matrix& theValue,
471 GLboolean theTranspose = GL_FALSE);
472
4fe9ad57 473 //! Specifies the value of the float uniform array
474 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
475 GLint theLocation,
476 GLuint theCount,
477 const Standard_ShortReal* theData);
478
479 //! Specifies the value of the float2 uniform array
480 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
481 GLint theLocation,
482 GLuint theCount,
483 const OpenGl_Vec2* theData);
484
485 //! Specifies the value of the float3 uniform array
486 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
487 GLint theLocation,
488 GLuint theCount,
489 const OpenGl_Vec3* theData);
490
491 //! Specifies the value of the float4 uniform array
492 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
493 GLint theLocation,
494 GLuint theCount,
495 const OpenGl_Vec4* theData);
496
497 //! Specifies the value of the integer uniform array
498 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
499 GLint theLocation,
500 GLuint theCount,
501 const Standard_Integer* theData);
502
503 //! Specifies the value of the int2 uniform array
504 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
505 GLint theLocation,
506 GLuint theCount,
507 const OpenGl_Vec2i* theData);
508
509 //! Specifies the value of the int3 uniform array
510 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
511 GLint theLocation,
512 GLuint theCount,
513 const OpenGl_Vec3i* theData);
514
515 //! Specifies the value of the int4 uniform array
516 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
517 GLint theLocation,
518 GLuint theCount,
519 const OpenGl_Vec4i* theData);
520
30f0ad28 521public:
522
523 //! Specifies the value of the sampler uniform variable.
524 Standard_EXPORT Standard_Boolean SetSampler (const Handle(OpenGl_Context)& theCtx,
525 const GLchar* theName,
cc8cbabe 526 const Graphic3d_TextureUnit theTextureUnit);
30f0ad28 527
528 //! Specifies the value of the sampler uniform variable.
529 Standard_EXPORT Standard_Boolean SetSampler (const Handle(OpenGl_Context)& theCtx,
530 GLint theLocation,
cc8cbabe 531 const Graphic3d_TextureUnit theTextureUnit);
30f0ad28 532
533protected:
534
392ac980 535 //! Increments counter of users.
536 //! Used by OpenGl_ShaderManager.
05dd08ce 537 //! @return true when resource has been restored from delayed release queue
538 bool Share()
392ac980 539 {
05dd08ce 540 return ++myShareCount == 1;
392ac980 541 }
542
543 //! Decrements counter of users.
544 //! Used by OpenGl_ShaderManager.
545 //! @return true when there are no more users of this program has been left
546 bool UnShare()
547 {
548 return --myShareCount == 0;
549 }
550
551protected:
552
553 GLuint myProgramID; //!< Handle of OpenGL shader program
554 OpenGl_ShaderList myShaderObjects; //!< List of attached shader objects
555 Handle(Graphic3d_ShaderProgram) myProxy; //!< Proxy shader program (from application layer)
556 Standard_Integer myShareCount; //!< program users count, initialized with 1 (already shared by one user)
8e0a2b19 557 Standard_Boolean myHasTessShader; //!< flag indicating that program defines tessellation stage
30f0ad28 558
559protected:
560
8613985b 561 Standard_Size myCurrentState[OpenGl_UniformStateType_NB]; //!< defines last modification for variables of each state type
30f0ad28 562
563 //! Stores locations of OCCT state uniform variables.
564 GLint myStateLocations[OpenGl_OCCT_NUMBER_OF_STATE_VARIABLES];
565
30f0ad28 566};
567
568template<class T>
569struct OpenGl_VariableSetter : public OpenGl_SetterInterface
570{
571 virtual void Set (const Handle(OpenGl_Context)& theCtx,
572 const Handle(Graphic3d_ShaderVariable)& theVariable,
573 OpenGl_ShaderProgram* theProgram)
574 {
575 theProgram->SetUniform (theCtx,
576 theVariable->Name().ToCString(),
577 theVariable->Value()->As<T>());
578 }
579};
580
581namespace OpenGl_HashMapInitializer
582{
583 template<class K, class V>
584 struct MapListOfType
585 {
586 NCollection_DataMap<K, V> myDictionary;
587
588 MapListOfType (K theKey, V theValue)
589 {
590 myDictionary.Bind (theKey, theValue);
591 }
592
593 MapListOfType& operator() (K theKey, V theValue)
594 {
595 myDictionary.Bind (theKey, theValue);
596 return *this;
597 }
598
599 operator const NCollection_DataMap<K, V>& () const
600 {
601 return myDictionary;
602 }
603 };
604
605 template<class K, class V>
606 MapListOfType<K, V> CreateListOf (K theKey, V theValue)
607 {
608 return MapListOfType<K, V> (theKey, theValue);
609 }
610}
611
612#endif // _OpenGl_ShaderProgram_Header