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