1 // Created on: 2013-09-19
2 // Created by: Denis BOGOLEPOV
3 // Copyright (c) 2013-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _OpenGl_ShaderProgram_Header
17 #define _OpenGl_ShaderProgram_Header
19 #include <NCollection_DataMap.hxx>
20 #include <NCollection_Sequence.hxx>
21 #include <TCollection_AsciiString.hxx>
23 #include <Graphic3d_ShaderObject.hxx>
24 #include <Graphic3d_ShaderProgram.hxx>
26 #include <OpenGl_Vec.hxx>
27 #include <OpenGl_Matrix.hxx>
28 #include <OpenGl_NamedResource.hxx>
29 #include <OpenGl_ShaderObject.hxx>
31 class OpenGl_ShaderProgram;
32 DEFINE_STANDARD_HANDLE(OpenGl_ShaderProgram, OpenGl_NamedResource)
34 //! The enumeration of OCCT-specific OpenGL/GLSL variables.
35 enum OpenGl_StateVariable
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,
51 // OpenGL clip planes state
52 OpenGl_OCC_CLIP_PLANE_EQUATIONS,
53 OpenGl_OCC_CLIP_PLANE_CHAINS,
54 OpenGl_OCC_CLIP_PLANE_COUNT,
57 OpenGl_OCC_LIGHT_SOURCE_COUNT,
58 OpenGl_OCC_LIGHT_SOURCE_TYPES,
59 OpenGl_OCC_LIGHT_SOURCE_PARAMS,
60 OpenGl_OCC_LIGHT_AMBIENT,
63 OpenGl_OCCT_TEXTURE_ENABLE,
64 OpenGl_OCCT_DISTINGUISH_MODE,
65 OpenGl_OCCT_FRONT_MATERIAL,
66 OpenGl_OCCT_BACK_MATERIAL,
67 OpenGl_OCCT_ALPHA_CUTOFF,
70 // Weighted, Blended Order-Independent Transparency rendering state
71 OpenGl_OCCT_OIT_OUTPUT,
72 OpenGl_OCCT_OIT_DEPTH_FACTOR,
74 // Context-dependent state
75 OpenGl_OCCT_TEXTURE_TRSF2D,
76 OpenGl_OCCT_POINT_SIZE,
80 OpenGl_OCCT_LINE_WIDTH,
81 OpenGl_OCCT_LINE_FEATHER,
82 OpenGl_OCCT_WIREFRAME_COLOR,
83 OpenGl_OCCT_QUAD_MODE_STATE,
85 // Parameters of outline (silhouette) shader
86 OpenGl_OCCT_ORTHO_SCALE,
87 OpenGl_OCCT_SILHOUETTE_THICKNESS,
89 // DON'T MODIFY THIS ITEM (insert new items before it)
90 OpenGl_OCCT_NUMBER_OF_STATE_VARIABLES
93 //! Interface for generic setter of user-defined uniform variables.
94 struct OpenGl_SetterInterface
96 //! Sets user-defined uniform variable to specified program.
97 virtual void Set (const Handle(OpenGl_Context)& theCtx,
98 const Handle(Graphic3d_ShaderVariable)& theVariable,
99 OpenGl_ShaderProgram* theProgram) = 0;
102 virtual ~OpenGl_SetterInterface() {}
105 //! List of OpenGL shader objects.
106 typedef NCollection_Sequence<Handle(OpenGl_ShaderObject)> OpenGl_ShaderList;
108 //! List of shader variable setters.
109 typedef NCollection_DataMap<size_t, OpenGl_SetterInterface*> OpenGl_SetterList;
111 //! Support tool for setting user-defined uniform variables.
112 class OpenGl_VariableSetterSelector
116 //! Creates new setter selector.
117 OpenGl_VariableSetterSelector();
119 //! Releases memory resources of setter selector.
120 ~OpenGl_VariableSetterSelector();
122 //! Sets user-defined uniform variable to specified program.
123 void Set (const Handle(OpenGl_Context)& theCtx,
124 const Handle(Graphic3d_ShaderVariable)& theVariable,
125 OpenGl_ShaderProgram* theProgram) const;
129 //! List of variable setters.
130 OpenGl_SetterList mySetterList;
133 //! Defines types of uniform state variables.
134 enum OpenGl_UniformStateType
136 OpenGl_LIGHT_SOURCES_STATE,
137 OpenGl_CLIP_PLANES_STATE,
138 OpenGl_MODEL_WORLD_STATE,
139 OpenGl_WORLD_VIEW_STATE,
140 OpenGl_PROJECTION_STATE,
141 OpenGl_MATERIAL_STATE,
142 OpenGl_SURF_DETAIL_STATE,
144 OpenGl_UniformStateType_NB
147 //! Simple class represents GLSL program variable location.
148 class OpenGl_ShaderUniformLocation
151 //! Invalid location of uniform/attribute variable.
152 static const GLint INVALID_LOCATION = -1;
155 //! Construct an invalid location.
156 OpenGl_ShaderUniformLocation() : myLocation (INVALID_LOCATION) {}
158 //! Constructor with initialization.
159 explicit OpenGl_ShaderUniformLocation (GLint theLocation) : myLocation (theLocation) {}
161 //! Note you may safely put invalid location in functions like glUniform* - the data passed in will be silently ignored.
162 //! @return true if location is not equal to -1.
163 bool IsValid() const { return myLocation != INVALID_LOCATION; }
165 //! Return TRUE for non-invalid location.
166 operator bool() const { return myLocation != INVALID_LOCATION; }
168 //! Convert operators help silently put object to GL functions like glUniform*.
169 operator GLint() const { return myLocation; }
175 //! Wrapper for OpenGL program object.
176 class OpenGl_ShaderProgram : public OpenGl_NamedResource
178 friend class OpenGl_View;
179 friend class OpenGl_ShaderManager;
180 DEFINE_STANDARD_RTTIEXT(OpenGl_ShaderProgram, OpenGl_NamedResource)
183 //! Non-valid shader name.
184 static const GLuint NO_PROGRAM = 0;
186 //! Invalid location of uniform/attribute variable.
187 static const GLint INVALID_LOCATION = -1;
189 //! List of pre-defined OCCT state uniform variables.
190 static Standard_CString PredefinedKeywords[OpenGl_OCCT_NUMBER_OF_STATE_VARIABLES];
192 //! Wrapper for compiling shader object with verbose printing on error.
193 Standard_EXPORT static bool compileShaderVerbose (const Handle(OpenGl_Context)& theCtx,
194 const Handle(OpenGl_ShaderObject)& theShader,
195 const TCollection_AsciiString& theSource,
196 bool theToPrintSource = true);
198 //! Creates uninitialized shader program.
200 //! WARNING! This constructor is not intended to be called anywhere but from OpenGl_ShaderManager::Create().
201 //! Manager has been designed to synchronize camera position, lights definition and other aspects of the program implicitly,
202 //! as well as sharing same program across rendering groups.
204 //! Program created outside the manager will be left detached from these routines,
205 //! and them should be performed manually by caller.
207 //! This constructor has been made public to provide more flexibility to re-use OCCT OpenGL classes without OCCT Viewer itself.
208 //! If this is not the case - create the program using shared OpenGl_ShaderManager instance instead.
209 Standard_EXPORT OpenGl_ShaderProgram (const Handle(Graphic3d_ShaderProgram)& theProxy = NULL,
210 const TCollection_AsciiString& theId = "");
214 static OpenGl_VariableSetterSelector mySetterSelector;
218 //! Releases resources of shader program.
219 Standard_EXPORT virtual ~OpenGl_ShaderProgram();
221 //! Creates new empty shader program of specified type.
222 Standard_EXPORT Standard_Boolean Create (const Handle(OpenGl_Context)& theCtx);
224 //! Destroys shader program.
225 Standard_EXPORT virtual void Release (OpenGl_Context* theCtx) Standard_OVERRIDE;
227 //! Returns estimated GPU memory usage - cannot be easily estimated.
228 virtual Standard_Size EstimatedDataSize() const Standard_OVERRIDE { return 0; }
230 //! Attaches shader object to the program object.
231 Standard_EXPORT Standard_Boolean AttachShader (const Handle(OpenGl_Context)& theCtx,
232 const Handle(OpenGl_ShaderObject)& theShader);
234 //! Detaches shader object to the program object.
235 Standard_EXPORT Standard_Boolean DetachShader (const Handle(OpenGl_Context)& theCtx,
236 const Handle(OpenGl_ShaderObject)& theShader);
238 //! Initializes program object with the list of shader objects.
239 Standard_EXPORT Standard_Boolean Initialize (const Handle(OpenGl_Context)& theCtx,
240 const Graphic3d_ShaderObjectList& theShaders);
242 //! Links the program object.
243 //! @param theCtx bound OpenGL context
244 //! @param theIsVerbose flag to print log on error
245 Standard_EXPORT Standard_Boolean Link (const Handle(OpenGl_Context)& theCtx,
246 bool theIsVerbose = true);
248 //! Fetches information log of the last link operation.
249 Standard_EXPORT Standard_Boolean FetchInfoLog (const Handle(OpenGl_Context)& theCtx,
250 TCollection_AsciiString& theLog);
252 //! Fetches uniform variables from proxy shader program.
253 Standard_EXPORT Standard_Boolean ApplyVariables (const Handle(OpenGl_Context)& theCtx);
255 //! @return true if current object was initialized
256 inline bool IsValid() const
258 return myProgramID != NO_PROGRAM;
261 //! @return program ID
262 inline GLuint ProgramId() const
269 //! Return TRUE if program defines tessellation stage.
270 Standard_Boolean HasTessellationStage() const { return myHasTessShader; }
272 //! Return the length of array of light sources (THE_MAX_LIGHTS),
273 //! to be used for initialization occLightSources (OpenGl_OCC_LIGHT_SOURCE_PARAMS).
274 Standard_Integer NbLightsMax() const { return myNbLightsMax; }
276 //! Return the length of array of clipping planes (THE_MAX_CLIP_PLANES),
277 //! to be used for initialization occClipPlaneEquations (OpenGl_OCC_CLIP_PLANE_EQUATIONS) and occClipPlaneChains (OpenGl_OCC_CLIP_PLANE_CHAINS).
278 Standard_Integer NbClipPlanesMax() const { return myNbClipPlanesMax; }
280 //! Return the length of array of Fragment Shader outputs (THE_NB_FRAG_OUTPUTS),
281 //! to be used for initialization occFragColorArray/occFragColorN.
282 Standard_Integer NbFragmentOutputs() const { return myNbFragOutputs; }
284 //! Return true if Fragment Shader should perform alpha test; FALSE by default.
285 Standard_Boolean HasAlphaTest() const { return myHasAlphaTest; }
287 //! Return true if Fragment Shader color should output the weighted OIT coverage; FALSE by default.
288 Standard_Boolean HasWeightOitOutput() const { return myHasWeightOitOutput; }
292 //! Returns index of last modification of variables of specified state type.
293 Standard_Size ActiveState (const OpenGl_UniformStateType theType) const
295 return theType < OpenGl_UniformStateType_NB
296 ? myCurrentState[theType]
300 //! Updates index of last modification of variables of specified state type.
301 void UpdateState (const OpenGl_UniformStateType theType,
302 const Standard_Size theIndex)
304 if (theType < OpenGl_UniformStateType_NB)
306 myCurrentState[theType] = theIndex;
312 //! Returns location of the specific uniform variable.
313 Standard_EXPORT OpenGl_ShaderUniformLocation GetUniformLocation (const Handle(OpenGl_Context)& theCtx,
314 const GLchar* theName) const;
316 //! Returns index of the generic vertex attribute by variable name.
317 Standard_EXPORT GLint GetAttributeLocation (const Handle(OpenGl_Context)& theCtx,
318 const GLchar* theName) const;
320 //! Returns location of the OCCT state uniform variable.
321 const OpenGl_ShaderUniformLocation& GetStateLocation (OpenGl_StateVariable theVariable) const { return myStateLocations[theVariable]; }
325 //! Returns the value of the integer uniform variable.
326 Standard_EXPORT Standard_Boolean GetUniform (const Handle(OpenGl_Context)& theCtx,
327 const GLchar* theName,
328 OpenGl_Vec4i& theValue) const;
330 Standard_EXPORT Standard_Boolean GetUniform (const Handle(OpenGl_Context)& theCtx,
332 OpenGl_Vec4i& theValue) const;
334 //! Returns the value of the float uniform variable.
335 Standard_EXPORT Standard_Boolean GetUniform (const Handle(OpenGl_Context)& theCtx,
336 const GLchar* theName,
337 OpenGl_Vec4& theValue) const;
339 //! Returns the value of the float uniform variable.
340 Standard_EXPORT Standard_Boolean GetUniform (const Handle(OpenGl_Context)& theCtx,
342 OpenGl_Vec4& theValue) const;
346 //! Returns the integer vertex attribute.
347 Standard_EXPORT Standard_Boolean GetAttribute (const Handle(OpenGl_Context)& theCtx,
348 const GLchar* theName,
349 OpenGl_Vec4i& theValue) const;
351 //! Returns the integer vertex attribute.
352 Standard_EXPORT Standard_Boolean GetAttribute (const Handle(OpenGl_Context)& theCtx,
354 OpenGl_Vec4i& theValue) const;
356 //! Returns the float vertex attribute.
357 Standard_EXPORT Standard_Boolean GetAttribute (const Handle(OpenGl_Context)& theCtx,
358 const GLchar* theName,
359 OpenGl_Vec4& theValue) const;
361 //! Returns the float vertex attribute.
362 Standard_EXPORT Standard_Boolean GetAttribute (const Handle(OpenGl_Context)& theCtx,
364 OpenGl_Vec4& theValue) const;
368 //! Wrapper for glBindAttribLocation()
369 Standard_EXPORT Standard_Boolean SetAttributeName (const Handle(OpenGl_Context)& theCtx,
371 const GLchar* theName);
373 //! Wrapper for glVertexAttrib1f()
374 Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
375 const GLchar* theName,
378 //! Wrapper for glVertexAttrib1f()
379 Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
383 //! Wrapper for glVertexAttrib2fv()
384 Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
385 const GLchar* theName,
386 const OpenGl_Vec2& theValue);
388 //! Wrapper for glVertexAttrib2fv()
389 Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
391 const OpenGl_Vec2& theValue);
393 //! Wrapper for glVertexAttrib3fv()
394 Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
395 const GLchar* theName,
396 const OpenGl_Vec3& theValue);
398 //! Wrapper for glVertexAttrib3fv()
399 Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
401 const OpenGl_Vec3& theValue);
403 //! Wrapper for glVertexAttrib4fv()
404 Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
405 const GLchar* theName,
406 const OpenGl_Vec4& theValue);
408 //! Wrapper for glVertexAttrib4fv()
409 Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
411 const OpenGl_Vec4& theValue);
415 //! Specifies the value of the integer uniform variable.
416 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
417 const GLchar* theName,
420 //! Specifies the value of the integer uniform variable.
421 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
425 //! Specifies the value of the integer uniform 2D vector.
426 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
427 const GLchar* theName,
428 const OpenGl_Vec2i& theValue);
430 //! Specifies the value of the integer uniform 2D vector.
431 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
433 const OpenGl_Vec2i& theValue);
435 //! Specifies the value of the integer uniform 3D vector.
436 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
437 const GLchar* theName,
438 const OpenGl_Vec3i& theValue);
440 //! Specifies the value of the integer uniform 3D vector.
441 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
443 const OpenGl_Vec3i& theValue);
445 //! Specifies the value of the integer uniform 4D vector.
446 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
447 const GLchar* theName,
448 const OpenGl_Vec4i& theValue);
450 //! Specifies the value of the integer uniform 4D vector.
451 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
453 const OpenGl_Vec4i& theValue);
457 //! Specifies the value of the unsigned integer uniform 2D vector (uvec2).
458 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
459 const GLchar* theName,
460 const OpenGl_Vec2u& theValue);
462 //! Specifies the value of the unsigned integer uniform 2D vector (uvec2).
463 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
465 const OpenGl_Vec2u& theValue);
467 //! Specifies the value of the uvec2 uniform array
468 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
469 const GLchar* theName,
470 const GLsizei theCount,
471 const OpenGl_Vec2u* theValue);
473 //! Specifies the value of the uvec2 uniform array
474 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
476 const GLsizei theCount,
477 const OpenGl_Vec2u* theValue);
481 //! Specifies the value of the float uniform variable.
482 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
483 const GLchar* theName,
486 //! Specifies the value of the float uniform variable.
487 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
491 //! Specifies the value of the float uniform 2D vector.
492 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
493 const GLchar* theName,
494 const OpenGl_Vec2& theValue);
496 //! Specifies the value of the float uniform 2D vector.
497 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
499 const OpenGl_Vec2& theValue);
501 //! Specifies the value of the float uniform 3D vector.
502 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
503 const GLchar* theName,
504 const OpenGl_Vec3& theValue);
506 //! Specifies the value of the float uniform 3D vector.
507 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
509 const OpenGl_Vec3& theValue);
511 //! Specifies the value of the float uniform 4D vector.
512 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
513 const GLchar* theName,
514 const OpenGl_Vec4& theValue);
516 //! Specifies the value of the float uniform 4D vector.
517 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
519 const OpenGl_Vec4& theValue);
523 //! Specifies the value of the float uniform 4x4 matrix.
524 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
525 const GLchar* theName,
526 const OpenGl_Mat4& theValue,
527 GLboolean theTranspose = GL_FALSE);
529 //! Specifies the value of the float uniform 4x4 matrix.
530 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
532 const OpenGl_Mat4& theValue,
533 GLboolean theTranspose = GL_FALSE);
535 //! Specifies the value of the float uniform 4x4 matrix.
536 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
537 const GLchar* theName,
538 const OpenGl_Matrix& theValue,
539 GLboolean theTranspose = GL_FALSE);
541 //! Specifies the value of the float uniform 4x4 matrix.
542 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
544 const OpenGl_Matrix& theValue,
545 GLboolean theTranspose = GL_FALSE);
547 //! Specifies the value of the float uniform array
548 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
551 const Standard_ShortReal* theData);
553 //! Specifies the value of the float2 uniform array
554 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
557 const OpenGl_Vec2* theData);
559 //! Specifies the value of the float3 uniform array
560 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
563 const OpenGl_Vec3* theData);
565 //! Specifies the value of the float4 uniform array
566 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
569 const OpenGl_Vec4* theData);
571 //! Specifies the value of the integer uniform array
572 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
575 const Standard_Integer* theData);
577 //! Specifies the value of the int2 uniform array
578 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
581 const OpenGl_Vec2i* theData);
583 //! Specifies the value of the int3 uniform array
584 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
587 const OpenGl_Vec3i* theData);
589 //! Specifies the value of the int4 uniform array
590 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
593 const OpenGl_Vec4i* theData);
597 //! Specifies the value of the sampler uniform variable.
598 Standard_EXPORT Standard_Boolean SetSampler (const Handle(OpenGl_Context)& theCtx,
599 const GLchar* theName,
600 const Graphic3d_TextureUnit theTextureUnit);
602 //! Specifies the value of the sampler uniform variable.
603 Standard_EXPORT Standard_Boolean SetSampler (const Handle(OpenGl_Context)& theCtx,
605 const Graphic3d_TextureUnit theTextureUnit);
609 //! Update the shader program from external files (per shader stage) in the following way:
610 //! 1) If external file does not exist, then it will be created (current source code will be dumped, no recompilation) and FALSE will be returned.
611 //! 2) If external file exists and it has the same timestamp as myDumpDate, nothing will be done and FALSE will be returned.
612 //! 3) If external file exists and it has newer timestamp than myDumpDate, shader will be recompiled and relinked and TRUE will be returned.
613 //! @param theCtx OpenGL context bound to this working thread
614 //! @param theFolder folder to store files; when unspecified, $CSF_ShadersDirectoryDump or current folder will be used instead
615 //! @param theToBeautify flag improving formatting (add extra newlines)
616 //! @param theToReset when TRUE, existing dumps will be overridden
617 Standard_EXPORT Standard_Boolean UpdateDebugDump (const Handle(OpenGl_Context)& theCtx,
618 const TCollection_AsciiString& theFolder = "",
619 Standard_Boolean theToBeautify = Standard_False,
620 Standard_Boolean theToReset = Standard_False);
624 //! Increments counter of users.
625 //! Used by OpenGl_ShaderManager.
626 //! @return true when resource has been restored from delayed release queue
629 return ++myShareCount == 1;
632 //! Decrements counter of users.
633 //! Used by OpenGl_ShaderManager.
634 //! @return true when there are no more users of this program has been left
637 return --myShareCount == 0;
640 //! Links the program object.
641 Standard_EXPORT Standard_Boolean link (const Handle(OpenGl_Context)& theCtx);
645 GLuint myProgramID; //!< Handle of OpenGL shader program
646 OpenGl_ShaderList myShaderObjects; //!< List of attached shader objects
647 Handle(Graphic3d_ShaderProgram) myProxy; //!< Proxy shader program (from application layer)
648 Standard_Integer myShareCount; //!< program users count, initialized with 1 (already shared by one user)
649 Standard_Integer myNbLightsMax; //!< length of array of light sources (THE_MAX_LIGHTS)
650 Standard_Integer myNbClipPlanesMax; //!< length of array of clipping planes (THE_MAX_CLIP_PLANES)
651 Standard_Integer myNbFragOutputs; //!< length of array of Fragment Shader outputs (THE_NB_FRAG_OUTPUTS)
652 Standard_Boolean myHasAlphaTest; //!< flag indicating that Fragment Shader should perform alpha-test
653 Standard_Boolean myHasWeightOitOutput; //!< flag indicating that Fragment Shader includes weighted OIT coverage
654 Standard_Boolean myHasTessShader; //!< flag indicating that program defines tessellation stage
658 Standard_Size myCurrentState[OpenGl_UniformStateType_NB]; //!< defines last modification for variables of each state type
660 //! Stores locations of OCCT state uniform variables.
661 OpenGl_ShaderUniformLocation myStateLocations[OpenGl_OCCT_NUMBER_OF_STATE_VARIABLES];
666 struct OpenGl_VariableSetter : public OpenGl_SetterInterface
668 virtual void Set (const Handle(OpenGl_Context)& theCtx,
669 const Handle(Graphic3d_ShaderVariable)& theVariable,
670 OpenGl_ShaderProgram* theProgram)
672 theProgram->SetUniform (theCtx,
673 theVariable->Name().ToCString(),
674 theVariable->Value()->As<T>());
678 namespace OpenGl_HashMapInitializer
680 template<class K, class V>
683 NCollection_DataMap<K, V> myDictionary;
685 MapListOfType (K theKey, V theValue)
687 myDictionary.Bind (theKey, theValue);
690 MapListOfType& operator() (K theKey, V theValue)
692 myDictionary.Bind (theKey, theValue);
696 operator const NCollection_DataMap<K, V>& () const
702 template<class K, class V>
703 MapListOfType<K, V> CreateListOf (K theKey, V theValue)
705 return MapListOfType<K, V> (theKey, theValue);
709 #endif // _OpenGl_ShaderProgram_Header