0029502: Improve performance of the ShapeUpgrade_UnifySameDomain::UnifyEdges() method
[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
15669413 179 //! Returns estimated GPU memory usage - cannot be easily estimated.
180 virtual Standard_Size EstimatedDataSize() const Standard_OVERRIDE { return 0; }
181
30f0ad28 182 //! Attaches shader object to the program object.
183 Standard_EXPORT Standard_Boolean AttachShader (const Handle(OpenGl_Context)& theCtx,
184 const Handle(OpenGl_ShaderObject)& theShader);
185
186 //! Detaches shader object to the program object.
187 Standard_EXPORT Standard_Boolean DetachShader (const Handle(OpenGl_Context)& theCtx,
188 const Handle(OpenGl_ShaderObject)& theShader);
189
190 //! Initializes program object with the list of shader objects.
191 Standard_EXPORT Standard_Boolean Initialize (const Handle(OpenGl_Context)& theCtx,
192 const Graphic3d_ShaderObjectList& theShaders);
193
194 //! Links the program object.
195 Standard_EXPORT Standard_Boolean Link (const Handle(OpenGl_Context)& theCtx);
196
197 //! Fetches information log of the last link operation.
198 Standard_EXPORT Standard_Boolean FetchInfoLog (const Handle(OpenGl_Context)& theCtx,
199 TCollection_AsciiString& theLog);
200
201 //! Fetches uniform variables from proxy shader program.
202 Standard_EXPORT Standard_Boolean ApplyVariables (const Handle(OpenGl_Context)& theCtx);
203
12381341 204 //! @return true if current object was initialized
205 inline bool IsValid() const
206 {
207 return myProgramID != NO_PROGRAM;
208 }
209
7d3e64ef 210 //! @return program ID
211 inline GLuint ProgramId() const
212 {
213 return myProgramID;
214 }
215
daf73ab7 216public:
217
8e0a2b19 218 //! Return TRUE if program defines tessellation stage.
219 Standard_Boolean HasTessellationStage() const { return myHasTessShader; }
220
daf73ab7 221 //! Return the length of array of light sources (THE_MAX_LIGHTS),
222 //! to be used for initialization occLightSources (OpenGl_OCC_LIGHT_SOURCE_PARAMS).
223 Standard_Integer NbLightsMax() const { return myNbLightsMax; }
224
225 //! Return the length of array of clipping planes (THE_MAX_CLIP_PLANES),
226 //! to be used for initialization occClipPlaneEquations (OpenGl_OCC_CLIP_PLANE_EQUATIONS).
227 Standard_Integer NbClipPlanesMax() const { return myNbClipPlanesMax; }
228
30f0ad28 229private:
230
231 //! Returns index of last modification of variables of specified state type.
8613985b 232 Standard_Size ActiveState (const OpenGl_UniformStateType theType) const
233 {
234 return theType < OpenGl_UniformStateType_NB
235 ? myCurrentState[theType]
236 : 0;
237 }
30f0ad28 238
239 //! Updates index of last modification of variables of specified state type.
8613985b 240 void UpdateState (const OpenGl_UniformStateType theType,
241 const Standard_Size theIndex)
242 {
243 if (theType < OpenGl_UniformStateType_NB)
244 {
245 myCurrentState[theType] = theIndex;
246 }
247 }
30f0ad28 248
249public:
250
251 //! Returns location of the specific uniform variable.
252 Standard_EXPORT GLint GetUniformLocation (const Handle(OpenGl_Context)& theCtx,
253 const GLchar* theName) const;
254
255 //! Returns index of the generic vertex attribute by variable name.
256 Standard_EXPORT GLint GetAttributeLocation (const Handle(OpenGl_Context)& theCtx,
257 const GLchar* theName) const;
258
259 //! Returns location of the OCCT state uniform variable.
260 Standard_EXPORT GLint GetStateLocation (const GLuint theVariable) const;
261
262public:
263
264 //! Returns the value of the integer uniform variable.
265 Standard_EXPORT Standard_Boolean GetUniform (const Handle(OpenGl_Context)& theCtx,
266 const GLchar* theName,
267 OpenGl_Vec4i& theValue) const;
268
269 Standard_EXPORT Standard_Boolean GetUniform (const Handle(OpenGl_Context)& theCtx,
270 GLint theLocation,
271 OpenGl_Vec4i& theValue) const;
272
273 //! Returns the value of the float uniform variable.
274 Standard_EXPORT Standard_Boolean GetUniform (const Handle(OpenGl_Context)& theCtx,
275 const GLchar* theName,
276 OpenGl_Vec4& theValue) const;
277
278 //! Returns the value of the float uniform variable.
279 Standard_EXPORT Standard_Boolean GetUniform (const Handle(OpenGl_Context)& theCtx,
280 GLint theLocation,
281 OpenGl_Vec4& theValue) const;
282
283public:
284
285 //! Returns the integer vertex attribute.
286 Standard_EXPORT Standard_Boolean GetAttribute (const Handle(OpenGl_Context)& theCtx,
287 const GLchar* theName,
288 OpenGl_Vec4i& theValue) const;
289
290 //! Returns the integer vertex attribute.
291 Standard_EXPORT Standard_Boolean GetAttribute (const Handle(OpenGl_Context)& theCtx,
292 GLint theIndex,
293 OpenGl_Vec4i& theValue) const;
294
295 //! Returns the float vertex attribute.
296 Standard_EXPORT Standard_Boolean GetAttribute (const Handle(OpenGl_Context)& theCtx,
297 const GLchar* theName,
298 OpenGl_Vec4& theValue) const;
299
300 //! Returns the float vertex attribute.
301 Standard_EXPORT Standard_Boolean GetAttribute (const Handle(OpenGl_Context)& theCtx,
302 GLint theIndex,
303 OpenGl_Vec4& theValue) const;
304
fc73a202 305public:
306
307 //! Wrapper for glBindAttribLocation()
308 Standard_EXPORT Standard_Boolean SetAttributeName (const Handle(OpenGl_Context)& theCtx,
309 GLint theIndex,
310 const GLchar* theName);
311
312 //! Wrapper for glVertexAttrib1f()
313 Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
314 const GLchar* theName,
315 GLfloat theValue);
316
317 //! Wrapper for glVertexAttrib1f()
318 Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
319 GLint theIndex,
320 GLfloat theValue);
321
322 //! Wrapper for glVertexAttrib2fv()
323 Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
324 const GLchar* theName,
325 const OpenGl_Vec2& theValue);
326
327 //! Wrapper for glVertexAttrib2fv()
328 Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
329 GLint theIndex,
330 const OpenGl_Vec2& theValue);
331
332 //! Wrapper for glVertexAttrib3fv()
333 Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
334 const GLchar* theName,
335 const OpenGl_Vec3& theValue);
336
337 //! Wrapper for glVertexAttrib3fv()
338 Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
339 GLint theIndex,
340 const OpenGl_Vec3& theValue);
341
342 //! Wrapper for glVertexAttrib4fv()
343 Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
344 const GLchar* theName,
345 const OpenGl_Vec4& theValue);
346
347 //! Wrapper for glVertexAttrib4fv()
348 Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
349 GLint theIndex,
350 const OpenGl_Vec4& theValue);
351
30f0ad28 352public:
353
354 //! Specifies the value of the integer uniform variable.
355 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
356 const GLchar* theName,
357 GLint theValue);
358
359 //! Specifies the value of the integer uniform variable.
360 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
361 GLint theLocation,
362 GLint theValue);
363
364 //! Specifies the value of the integer uniform 2D vector.
365 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
366 const GLchar* theName,
367 const OpenGl_Vec2i& theValue);
368
369 //! Specifies the value of the integer uniform 2D vector.
370 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
371 GLint theLocation,
372 const OpenGl_Vec2i& theValue);
373
374 //! Specifies the value of the integer uniform 3D vector.
375 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
376 const GLchar* theName,
377 const OpenGl_Vec3i& theValue);
378
379 //! Specifies the value of the integer uniform 3D vector.
380 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
381 GLint theLocation,
382 const OpenGl_Vec3i& theValue);
383
384 //! Specifies the value of the integer uniform 4D vector.
385 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
386 const GLchar* theName,
387 const OpenGl_Vec4i& theValue);
388
389 //! Specifies the value of the integer uniform 4D vector.
390 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
391 GLint theLocation,
392 const OpenGl_Vec4i& theValue);
393
25ef750e 394public:
395
47e9c178 396 //! Specifies the value of the unsigned integer uniform 2D vector (uvec2).
25ef750e 397 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
398 const GLchar* theName,
47e9c178 399 const OpenGl_Vec2u& theValue);
25ef750e 400
47e9c178 401 //! Specifies the value of the unsigned integer uniform 2D vector (uvec2).
25ef750e 402 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
403 GLint theLocation,
47e9c178 404 const OpenGl_Vec2u& theValue);
25ef750e 405
47e9c178 406 //! Specifies the value of the uvec2 uniform array
25ef750e 407 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
408 const GLchar* theName,
409 const GLsizei theCount,
47e9c178 410 const OpenGl_Vec2u* theValue);
25ef750e 411
47e9c178 412 //! Specifies the value of the uvec2 uniform array
25ef750e 413 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
414 GLint theLocation,
415 const GLsizei theCount,
47e9c178 416 const OpenGl_Vec2u* theValue);
25ef750e 417
30f0ad28 418public:
419
420 //! Specifies the value of the float uniform variable.
421 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
422 const GLchar* theName,
423 GLfloat theValue);
424
425 //! Specifies the value of the float uniform variable.
426 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
427 GLint theLocation,
428 GLfloat theValue);
429
430 //! Specifies the value of the float uniform 2D vector.
431 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
432 const GLchar* theName,
433 const OpenGl_Vec2& theValue);
434
435 //! Specifies the value of the float uniform 2D vector.
436 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
437 GLint theLocation,
438 const OpenGl_Vec2& theValue);
439
440 //! Specifies the value of the float uniform 3D vector.
441 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
442 const GLchar* theName,
443 const OpenGl_Vec3& theValue);
444
445 //! Specifies the value of the float uniform 3D vector.
446 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
447 GLint theLocation,
448 const OpenGl_Vec3& theValue);
449
450 //! Specifies the value of the float uniform 4D vector.
451 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
452 const GLchar* theName,
453 const OpenGl_Vec4& theValue);
454
455 //! Specifies the value of the float uniform 4D vector.
456 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
457 GLint theLocation,
458 const OpenGl_Vec4& theValue);
459
460public:
461
25ef750e 462 //! Specifies the value of the float uniform 4x4 matrix.
463 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
464 const GLchar* theName,
465 const OpenGl_Mat4& theValue,
466 GLboolean theTranspose = GL_FALSE);
467
468 //! Specifies the value of the float uniform 4x4 matrix.
469 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
470 GLint theLocation,
471 const OpenGl_Mat4& theValue,
472 GLboolean theTranspose = GL_FALSE);
473
30f0ad28 474 //! Specifies the value of the float uniform 4x4 matrix.
475 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
476 const GLchar* theName,
477 const OpenGl_Matrix& theValue,
478 GLboolean theTranspose = GL_FALSE);
479
480 //! Specifies the value of the float uniform 4x4 matrix.
481 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
482 GLint theLocation,
483 const OpenGl_Matrix& theValue,
484 GLboolean theTranspose = GL_FALSE);
485
4fe9ad57 486 //! Specifies the value of the float uniform array
487 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
488 GLint theLocation,
489 GLuint theCount,
490 const Standard_ShortReal* theData);
491
492 //! Specifies the value of the float2 uniform array
493 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
494 GLint theLocation,
495 GLuint theCount,
496 const OpenGl_Vec2* theData);
497
498 //! Specifies the value of the float3 uniform array
499 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
500 GLint theLocation,
501 GLuint theCount,
502 const OpenGl_Vec3* theData);
503
504 //! Specifies the value of the float4 uniform array
505 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
506 GLint theLocation,
507 GLuint theCount,
508 const OpenGl_Vec4* theData);
509
510 //! Specifies the value of the integer uniform array
511 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
512 GLint theLocation,
513 GLuint theCount,
514 const Standard_Integer* theData);
515
516 //! Specifies the value of the int2 uniform array
517 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
518 GLint theLocation,
519 GLuint theCount,
520 const OpenGl_Vec2i* theData);
521
522 //! Specifies the value of the int3 uniform array
523 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
524 GLint theLocation,
525 GLuint theCount,
526 const OpenGl_Vec3i* theData);
527
528 //! Specifies the value of the int4 uniform array
529 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
530 GLint theLocation,
531 GLuint theCount,
532 const OpenGl_Vec4i* theData);
533
30f0ad28 534public:
535
536 //! Specifies the value of the sampler uniform variable.
537 Standard_EXPORT Standard_Boolean SetSampler (const Handle(OpenGl_Context)& theCtx,
538 const GLchar* theName,
cc8cbabe 539 const Graphic3d_TextureUnit theTextureUnit);
30f0ad28 540
541 //! Specifies the value of the sampler uniform variable.
542 Standard_EXPORT Standard_Boolean SetSampler (const Handle(OpenGl_Context)& theCtx,
543 GLint theLocation,
cc8cbabe 544 const Graphic3d_TextureUnit theTextureUnit);
30f0ad28 545
546protected:
547
392ac980 548 //! Increments counter of users.
549 //! Used by OpenGl_ShaderManager.
05dd08ce 550 //! @return true when resource has been restored from delayed release queue
551 bool Share()
392ac980 552 {
05dd08ce 553 return ++myShareCount == 1;
392ac980 554 }
555
556 //! Decrements counter of users.
557 //! Used by OpenGl_ShaderManager.
558 //! @return true when there are no more users of this program has been left
559 bool UnShare()
560 {
561 return --myShareCount == 0;
562 }
563
564protected:
565
566 GLuint myProgramID; //!< Handle of OpenGL shader program
567 OpenGl_ShaderList myShaderObjects; //!< List of attached shader objects
568 Handle(Graphic3d_ShaderProgram) myProxy; //!< Proxy shader program (from application layer)
569 Standard_Integer myShareCount; //!< program users count, initialized with 1 (already shared by one user)
daf73ab7 570 Standard_Integer myNbLightsMax; //!< length of array of light sources (THE_MAX_LIGHTS)
571 Standard_Integer myNbClipPlanesMax; //!< length of array of clipping planes (THE_MAX_CLIP_PLANES)
8e0a2b19 572 Standard_Boolean myHasTessShader; //!< flag indicating that program defines tessellation stage
30f0ad28 573
574protected:
575
8613985b 576 Standard_Size myCurrentState[OpenGl_UniformStateType_NB]; //!< defines last modification for variables of each state type
30f0ad28 577
578 //! Stores locations of OCCT state uniform variables.
579 GLint myStateLocations[OpenGl_OCCT_NUMBER_OF_STATE_VARIABLES];
580
30f0ad28 581};
582
583template<class T>
584struct OpenGl_VariableSetter : public OpenGl_SetterInterface
585{
586 virtual void Set (const Handle(OpenGl_Context)& theCtx,
587 const Handle(Graphic3d_ShaderVariable)& theVariable,
588 OpenGl_ShaderProgram* theProgram)
589 {
590 theProgram->SetUniform (theCtx,
591 theVariable->Name().ToCString(),
592 theVariable->Value()->As<T>());
593 }
594};
595
596namespace OpenGl_HashMapInitializer
597{
598 template<class K, class V>
599 struct MapListOfType
600 {
601 NCollection_DataMap<K, V> myDictionary;
602
603 MapListOfType (K theKey, V theValue)
604 {
605 myDictionary.Bind (theKey, theValue);
606 }
607
608 MapListOfType& operator() (K theKey, V theValue)
609 {
610 myDictionary.Bind (theKey, theValue);
611 return *this;
612 }
613
614 operator const NCollection_DataMap<K, V>& () const
615 {
616 return myDictionary;
617 }
618 };
619
620 template<class K, class V>
621 MapListOfType<K, V> CreateListOf (K theKey, V theValue)
622 {
623 return MapListOfType<K, V> (theKey, theValue);
624 }
625}
626
627#endif // _OpenGl_ShaderProgram_Header