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>
25 #include <Graphic3d_TextureSetBits.hxx>
27 #include <OpenGl_Vec.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,
61 OpenGl_OCC_LIGHT_SHADOWMAP_SIZE_BIAS,// occShadowMapSizeBias
62 OpenGl_OCC_LIGHT_SHADOWMAP_SAMPLERS, // occShadowMapSamplers
63 OpenGl_OCC_LIGHT_SHADOWMAP_MATRICES, // occShadowMapMatrices
66 OpenGl_OCCT_TEXTURE_ENABLE,
67 OpenGl_OCCT_DISTINGUISH_MODE,
68 OpenGl_OCCT_PBR_MATERIAL,
69 OpenGl_OCCT_COMMON_MATERIAL,
70 OpenGl_OCCT_ALPHA_CUTOFF,
73 // Weighted, Blended Order-Independent Transparency rendering state
74 OpenGl_OCCT_OIT_OUTPUT,
75 OpenGl_OCCT_OIT_DEPTH_FACTOR,
77 // Context-dependent state
78 OpenGl_OCCT_TEXTURE_TRSF2D,
79 OpenGl_OCCT_POINT_SIZE,
83 OpenGl_OCCT_LINE_WIDTH,
84 OpenGl_OCCT_LINE_FEATHER,
85 OpenGl_OCCT_LINE_STIPPLE_PATTERN, // occStipplePattern
86 OpenGl_OCCT_LINE_STIPPLE_FACTOR, // occStippleFactor
87 OpenGl_OCCT_WIREFRAME_COLOR,
88 OpenGl_OCCT_QUAD_MODE_STATE,
90 // Parameters of outline (silhouette) shader
91 OpenGl_OCCT_ORTHO_SCALE,
92 OpenGl_OCCT_SILHOUETTE_THICKNESS,
95 OpenGl_OCCT_NB_SPEC_IBL_LEVELS,
97 // DON'T MODIFY THIS ITEM (insert new items before it)
98 OpenGl_OCCT_NUMBER_OF_STATE_VARIABLES
101 //! Interface for generic setter of user-defined uniform variables.
102 struct OpenGl_SetterInterface
104 //! Sets user-defined uniform variable to specified program.
105 virtual void Set (const Handle(OpenGl_Context)& theCtx,
106 const Handle(Graphic3d_ShaderVariable)& theVariable,
107 OpenGl_ShaderProgram* theProgram) = 0;
110 virtual ~OpenGl_SetterInterface() {}
113 //! List of OpenGL shader objects.
114 typedef NCollection_Sequence<Handle(OpenGl_ShaderObject)> OpenGl_ShaderList;
116 //! List of shader variable setters.
117 typedef NCollection_DataMap<size_t, OpenGl_SetterInterface*> OpenGl_SetterList;
119 //! Support tool for setting user-defined uniform variables.
120 class OpenGl_VariableSetterSelector
124 //! Creates new setter selector.
125 OpenGl_VariableSetterSelector();
127 //! Releases memory resources of setter selector.
128 ~OpenGl_VariableSetterSelector();
130 //! Sets user-defined uniform variable to specified program.
131 void Set (const Handle(OpenGl_Context)& theCtx,
132 const Handle(Graphic3d_ShaderVariable)& theVariable,
133 OpenGl_ShaderProgram* theProgram) const;
137 //! List of variable setters.
138 OpenGl_SetterList mySetterList;
141 //! Defines types of uniform state variables.
142 enum OpenGl_UniformStateType
144 OpenGl_LIGHT_SOURCES_STATE,
145 OpenGl_CLIP_PLANES_STATE,
146 OpenGl_MODEL_WORLD_STATE,
147 OpenGl_WORLD_VIEW_STATE,
148 OpenGl_PROJECTION_STATE,
149 OpenGl_MATERIAL_STATE,
150 OpenGl_SURF_DETAIL_STATE,
152 OpenGl_UniformStateType_NB
155 //! Simple class represents GLSL program variable location.
156 class OpenGl_ShaderUniformLocation
159 //! Invalid location of uniform/attribute variable.
160 static const GLint INVALID_LOCATION = -1;
163 //! Construct an invalid location.
164 OpenGl_ShaderUniformLocation() : myLocation (INVALID_LOCATION) {}
166 //! Constructor with initialization.
167 explicit OpenGl_ShaderUniformLocation (GLint theLocation) : myLocation (theLocation) {}
169 //! Note you may safely put invalid location in functions like glUniform* - the data passed in will be silently ignored.
170 //! @return true if location is not equal to -1.
171 bool IsValid() const { return myLocation != INVALID_LOCATION; }
173 //! Return TRUE for non-invalid location.
174 operator bool() const { return myLocation != INVALID_LOCATION; }
176 //! Convert operators help silently put object to GL functions like glUniform*.
177 operator GLint() const { return myLocation; }
183 //! Wrapper for OpenGL program object.
184 class OpenGl_ShaderProgram : public OpenGl_NamedResource
186 friend class OpenGl_View;
187 friend class OpenGl_ShaderManager;
188 DEFINE_STANDARD_RTTIEXT(OpenGl_ShaderProgram, OpenGl_NamedResource)
191 //! Non-valid shader name.
192 static const GLuint NO_PROGRAM = 0;
194 //! Invalid location of uniform/attribute variable.
195 static const GLint INVALID_LOCATION = -1;
197 //! List of pre-defined OCCT state uniform variables.
198 static Standard_CString PredefinedKeywords[OpenGl_OCCT_NUMBER_OF_STATE_VARIABLES];
200 //! Wrapper for compiling shader object with verbose printing on error.
201 Standard_EXPORT static bool compileShaderVerbose (const Handle(OpenGl_Context)& theCtx,
202 const Handle(OpenGl_ShaderObject)& theShader,
203 const TCollection_AsciiString& theSource,
204 bool theToPrintSource = true);
206 //! Creates uninitialized shader program.
208 //! WARNING! This constructor is not intended to be called anywhere but from OpenGl_ShaderManager::Create().
209 //! Manager has been designed to synchronize camera position, lights definition and other aspects of the program implicitly,
210 //! as well as sharing same program across rendering groups.
212 //! Program created outside the manager will be left detached from these routines,
213 //! and them should be performed manually by caller.
215 //! This constructor has been made public to provide more flexibility to re-use OCCT OpenGL classes without OCCT Viewer itself.
216 //! If this is not the case - create the program using shared OpenGl_ShaderManager instance instead.
217 Standard_EXPORT OpenGl_ShaderProgram (const Handle(Graphic3d_ShaderProgram)& theProxy = NULL,
218 const TCollection_AsciiString& theId = "");
222 static OpenGl_VariableSetterSelector mySetterSelector;
226 //! Releases resources of shader program.
227 Standard_EXPORT virtual ~OpenGl_ShaderProgram();
229 //! Creates new empty shader program of specified type.
230 Standard_EXPORT Standard_Boolean Create (const Handle(OpenGl_Context)& theCtx);
232 //! Destroys shader program.
233 Standard_EXPORT virtual void Release (OpenGl_Context* theCtx) Standard_OVERRIDE;
235 //! Returns estimated GPU memory usage - cannot be easily estimated.
236 virtual Standard_Size EstimatedDataSize() const Standard_OVERRIDE { return 0; }
238 //! Attaches shader object to the program object.
239 Standard_EXPORT Standard_Boolean AttachShader (const Handle(OpenGl_Context)& theCtx,
240 const Handle(OpenGl_ShaderObject)& theShader);
242 //! Detaches shader object to the program object.
243 Standard_EXPORT Standard_Boolean DetachShader (const Handle(OpenGl_Context)& theCtx,
244 const Handle(OpenGl_ShaderObject)& theShader);
246 //! Initializes program object with the list of shader objects.
247 Standard_EXPORT Standard_Boolean Initialize (const Handle(OpenGl_Context)& theCtx,
248 const Graphic3d_ShaderObjectList& theShaders);
250 //! Links the program object.
251 //! @param theCtx bound OpenGL context
252 //! @param theIsVerbose flag to print log on error
253 Standard_EXPORT Standard_Boolean Link (const Handle(OpenGl_Context)& theCtx,
254 bool theIsVerbose = true);
256 //! Fetches information log of the last link operation.
257 Standard_EXPORT Standard_Boolean FetchInfoLog (const Handle(OpenGl_Context)& theCtx,
258 TCollection_AsciiString& theLog);
260 //! Fetches uniform variables from proxy shader program.
261 Standard_EXPORT Standard_Boolean ApplyVariables (const Handle(OpenGl_Context)& theCtx);
263 //! @return proxy shader program.
264 const Handle(Graphic3d_ShaderProgram)& Proxy() const { return myProxy; }
266 //! @return true if current object was initialized
267 inline bool IsValid() const
269 return myProgramID != NO_PROGRAM;
272 //! @return program ID
273 inline GLuint ProgramId() const
280 //! Return TRUE if program defines tessellation stage.
281 Standard_Boolean HasTessellationStage() const { return myHasTessShader; }
283 //! Return the length of array of light sources (THE_MAX_LIGHTS),
284 //! to be used for initialization occLightSources (OpenGl_OCC_LIGHT_SOURCE_PARAMS).
285 Standard_Integer NbLightsMax() const { return myNbLightsMax; }
287 //! Return the length of array of shadow maps (THE_NB_SHADOWMAPS); 0 by default.
288 Standard_Integer NbShadowMaps() const { return myNbShadowMaps; }
290 //! Return the length of array of clipping planes (THE_MAX_CLIP_PLANES),
291 //! to be used for initialization occClipPlaneEquations (OpenGl_OCC_CLIP_PLANE_EQUATIONS) and occClipPlaneChains (OpenGl_OCC_CLIP_PLANE_CHAINS).
292 Standard_Integer NbClipPlanesMax() const { return myNbClipPlanesMax; }
294 //! Return the length of array of Fragment Shader outputs (THE_NB_FRAG_OUTPUTS),
295 //! to be used for initialization occFragColorArray/occFragColorN.
296 Standard_Integer NbFragmentOutputs() const { return myNbFragOutputs; }
298 //! Return true if Fragment Shader should perform alpha test; FALSE by default.
299 Standard_Boolean HasAlphaTest() const { return myHasAlphaTest; }
301 //! Return if Fragment Shader color should output the OIT values; OFF by default.
302 Graphic3d_RenderTransparentMethod OitOutput() const { return myOitOutput; }
304 //! Return texture units declared within the program, @sa Graphic3d_TextureSetBits.
305 Standard_Integer TextureSetBits() const { return myTextureSetBits; }
309 //! Returns index of last modification of variables of specified state type.
310 Standard_Size ActiveState (const OpenGl_UniformStateType theType) const
312 return theType < OpenGl_UniformStateType_NB
313 ? myCurrentState[theType]
317 //! Updates index of last modification of variables of specified state type.
318 void UpdateState (const OpenGl_UniformStateType theType,
319 const Standard_Size theIndex)
321 if (theType < OpenGl_UniformStateType_NB)
323 myCurrentState[theType] = theIndex;
329 //! Returns location of the specific uniform variable.
330 Standard_EXPORT OpenGl_ShaderUniformLocation GetUniformLocation (const Handle(OpenGl_Context)& theCtx,
331 const GLchar* theName) const;
333 //! Returns index of the generic vertex attribute by variable name.
334 Standard_EXPORT GLint GetAttributeLocation (const Handle(OpenGl_Context)& theCtx,
335 const GLchar* theName) const;
337 //! Returns location of the OCCT state uniform variable.
338 const OpenGl_ShaderUniformLocation& GetStateLocation (OpenGl_StateVariable theVariable) const { return myStateLocations[theVariable]; }
342 //! Returns the value of the uniform variable from given name.
343 template<typename ValueType>
344 bool GetUniform (const Handle(OpenGl_Context)& theCtx,
345 const GLchar* theName,
346 ValueType& theValue) const
348 return GetUniform (theCtx, GetUniformLocation (theCtx, theName), theValue);
351 //! Returns the value of the integer uniform variable.
352 //! Wrapper for glGetUniformiv()
353 Standard_EXPORT Standard_Boolean GetUniform (const Handle(OpenGl_Context)& theCtx,
355 OpenGl_Vec4i& theValue) const;
357 //! Returns the value of the float uniform variable.
358 //! Wrapper for glGetUniformfv()
359 Standard_EXPORT Standard_Boolean GetUniform (const Handle(OpenGl_Context)& theCtx,
361 OpenGl_Vec4& theValue) const;
365 //! Returns the vertex attribute from given name.
366 template<typename ValueType>
367 bool GetAttribute (const Handle(OpenGl_Context)& theCtx,
368 const GLchar* theName,
369 ValueType& theValue) const
371 return GetAttribute (theCtx, GetAttributeLocation (theCtx, theName), theValue);
374 //! Returns the integer vertex attribute.
375 //! Wrapper for glGetVertexAttribiv()
376 Standard_EXPORT Standard_Boolean GetAttribute (const Handle(OpenGl_Context)& theCtx,
378 OpenGl_Vec4i& theValue) const;
380 //! Returns the float vertex attribute.
381 //! Wrapper for glGetVertexAttribfv()
382 Standard_EXPORT Standard_Boolean GetAttribute (const Handle(OpenGl_Context)& theCtx,
384 OpenGl_Vec4& theValue) const;
388 //! Wrapper for glBindAttribLocation()
389 Standard_EXPORT Standard_Boolean SetAttributeName (const Handle(OpenGl_Context)& theCtx,
391 const GLchar* theName);
393 //! Wrapper for glVertexAttrib*() for attribute with the given name.
394 template<typename ValueType>
395 bool SetAttribute (const Handle(OpenGl_Context)& theCtx,
396 const GLchar* theName,
397 const ValueType& theValue)
399 return SetAttribute (theCtx, GetAttributeLocation (theCtx, theName), theValue);
402 //! Wrapper for glVertexAttrib1f()
403 Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
407 //! Wrapper for glVertexAttrib2fv()
408 Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
410 const OpenGl_Vec2& theValue);
412 //! Wrapper for glVertexAttrib3fv()
413 Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
415 const OpenGl_Vec3& theValue);
417 //! Wrapper for glVertexAttrib4fv()
418 Standard_EXPORT Standard_Boolean SetAttribute (const Handle(OpenGl_Context)& theCtx,
420 const OpenGl_Vec4& theValue);
424 //! Specifies the value of the uniform variable with given name.
425 template<typename ValueType>
426 bool SetUniform (const Handle(OpenGl_Context)& theCtx,
427 const GLchar* theName,
428 const ValueType& theValue)
430 return SetUniform (theCtx, GetUniformLocation (theCtx, theName), theValue);
433 //! Specifies the value of the integer uniform variable.
434 //! Wrapper for glUniform1i()
435 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
439 //! Specifies the value of the integer uniform 2D vector.
440 //! Wrapper for glUniform2iv()
441 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
443 const OpenGl_Vec2i& theValue);
445 //! Specifies the value of the integer uniform 3D vector.
446 //! Wrapper for glUniform3iv()
447 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
449 const OpenGl_Vec3i& theValue);
451 //! Specifies the value of the integer uniform 4D vector.
452 //! Wrapper for glUniform4iv()
453 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
455 const OpenGl_Vec4i& theValue);
459 //! Specifies the value of the unsigned integer uniform 2D vector (uvec2).
460 //! Wrapper for glUniform2uiv()
461 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
463 const OpenGl_Vec2u& theValue);
465 //! Specifies the value of the uvec2 uniform array
466 //! Wrapper for glUniform2uiv()
467 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
468 const GLchar* theName,
469 const GLsizei theCount,
470 const OpenGl_Vec2u* theValue);
472 //! Specifies the value of the uvec2 uniform array
473 //! Wrapper for glUniform2uiv()
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 //! Wrapper for glUniform1f()
483 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
487 //! Specifies the value of the float uniform 2D vector.
488 //! Wrapper for glUniform2fv()
489 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
491 const OpenGl_Vec2& theValue);
493 //! Specifies the value of the float uniform 3D vector.
494 //! Wrapper for glUniform3fv()
495 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
497 const OpenGl_Vec3& theValue);
499 //! Specifies the value of the float uniform 4D vector.
500 //! Wrapper for glUniform4fv()
501 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
503 const OpenGl_Vec4& theValue);
507 //! Specifies the value of the array of float uniform 3x3 matrices.
508 //! Wrapper over glUniformMatrix3fv().
509 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
512 const NCollection_Mat3<float>* theData);
514 //! Specifies the value of the float uniform 4x4 matrix.
515 //! Wrapper for glUniformMatrix4fv()
516 bool SetUniform (const Handle(OpenGl_Context)& theCtx,
517 const GLchar* theName,
518 const OpenGl_Mat4& theValue,
519 GLboolean theTranspose = GL_FALSE)
521 return SetUniform (theCtx, GetUniformLocation (theCtx, theName), theValue, theTranspose);
524 //! Specifies the value of the float uniform 4x4 matrix.
525 //! Wrapper for glUniformMatrix4fv()
526 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
528 const OpenGl_Mat4& theValue,
529 GLboolean theTranspose = GL_FALSE);
531 //! Specifies the value of the array of float uniform 4x4 matrices.
532 //! Wrapper over glUniformMatrix4fv().
533 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
536 const OpenGl_Mat4* theData);
538 //! Specifies the value of the float uniform array
539 //! Wrapper over glUniform1fv()
540 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
543 const Standard_ShortReal* theData);
545 //! Specifies the value of the float2 uniform array
546 //! Wrapper over glUniform2fv()
547 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
550 const OpenGl_Vec2* theData);
552 //! Specifies the value of the float3 uniform array
553 //! Wrapper over glUniform3fv()
554 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
557 const OpenGl_Vec3* theData);
559 //! Specifies the value of the float4 uniform array
560 //! Wrapper over glUniform4fv()
561 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
564 const OpenGl_Vec4* theData);
566 //! Specifies the value of the integer uniform array
567 //! Wrapper over glUniform1iv()
568 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
571 const Standard_Integer* theData);
573 //! Specifies the value of the int2 uniform array
574 //! Wrapper over glUniform2iv()
575 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
578 const OpenGl_Vec2i* theData);
580 //! Specifies the value of the int3 uniform array
581 //! Wrapper over glUniform3iv()
582 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
585 const OpenGl_Vec3i* theData);
587 //! Specifies the value of the int4 uniform array
588 //! Wrapper over glUniform4iv()
589 Standard_EXPORT Standard_Boolean SetUniform (const Handle(OpenGl_Context)& theCtx,
592 const OpenGl_Vec4i* theData);
596 //! Specifies the value of the sampler uniform variable.
597 bool SetSampler (const Handle(OpenGl_Context)& theCtx,
598 const GLchar* theName,
599 const Graphic3d_TextureUnit theTextureUnit)
601 return SetSampler (theCtx, GetUniformLocation (theCtx, theName), theTextureUnit);
604 //! Specifies the value of the sampler uniform variable.
605 Standard_EXPORT Standard_Boolean SetSampler (const Handle(OpenGl_Context)& theCtx,
607 const Graphic3d_TextureUnit theTextureUnit);
611 //! Update the shader program from external files (per shader stage) in the following way:
612 //! 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.
613 //! 2) If external file exists and it has the same timestamp as myDumpDate, nothing will be done and FALSE will be returned.
614 //! 3) If external file exists and it has newer timestamp than myDumpDate, shader will be recompiled and relinked and TRUE will be returned.
615 //! @param theCtx OpenGL context bound to this working thread
616 //! @param theFolder folder to store files; when unspecified, $CSF_ShadersDirectoryDump or current folder will be used instead
617 //! @param theToBeautify flag improving formatting (add extra newlines)
618 //! @param theToReset when TRUE, existing dumps will be overridden
619 Standard_EXPORT Standard_Boolean UpdateDebugDump (const Handle(OpenGl_Context)& theCtx,
620 const TCollection_AsciiString& theFolder = "",
621 Standard_Boolean theToBeautify = Standard_False,
622 Standard_Boolean theToReset = Standard_False);
626 //! Increments counter of users.
627 //! Used by OpenGl_ShaderManager.
628 //! @return true when resource has been restored from delayed release queue
631 return ++myShareCount == 1;
634 //! Decrements counter of users.
635 //! Used by OpenGl_ShaderManager.
636 //! @return true when there are no more users of this program has been left
639 return --myShareCount == 0;
642 //! Links the program object.
643 Standard_EXPORT Standard_Boolean link (const Handle(OpenGl_Context)& theCtx);
647 GLuint myProgramID; //!< Handle of OpenGL shader program
648 OpenGl_ShaderList myShaderObjects; //!< List of attached shader objects
649 Handle(Graphic3d_ShaderProgram) myProxy; //!< Proxy shader program (from application layer)
650 Standard_Integer myShareCount; //!< program users count, initialized with 1 (already shared by one user)
651 Standard_Integer myNbLightsMax; //!< length of array of light sources (THE_MAX_LIGHTS)
652 Standard_Integer myNbShadowMaps; //!< length of array of shadow maps (THE_NB_SHADOWMAPS)
653 Standard_Integer myNbClipPlanesMax; //!< length of array of clipping planes (THE_MAX_CLIP_PLANES)
654 Standard_Integer myNbFragOutputs; //!< length of array of Fragment Shader outputs (THE_NB_FRAG_OUTPUTS)
655 Standard_Integer myTextureSetBits;//!< texture units declared within the program, @sa Graphic3d_TextureSetBits
656 Graphic3d_RenderTransparentMethod myOitOutput; //!< flag indicating that Fragment Shader includes OIT outputs
657 Standard_Boolean myHasAlphaTest; //!< flag indicating that Fragment Shader should perform alpha-test
658 Standard_Boolean myHasTessShader; //!< flag indicating that program defines tessellation stage
662 Standard_Size myCurrentState[OpenGl_UniformStateType_NB]; //!< defines last modification for variables of each state type
664 //! Stores locations of OCCT state uniform variables.
665 OpenGl_ShaderUniformLocation myStateLocations[OpenGl_OCCT_NUMBER_OF_STATE_VARIABLES];
670 struct OpenGl_VariableSetter : public OpenGl_SetterInterface
672 virtual void Set (const Handle(OpenGl_Context)& theCtx,
673 const Handle(Graphic3d_ShaderVariable)& theVariable,
674 OpenGl_ShaderProgram* theProgram)
676 theProgram->SetUniform (theCtx,
677 theVariable->Name().ToCString(),
678 theVariable->Value()->As<T>());
682 namespace OpenGl_HashMapInitializer
684 template<class K, class V>
687 NCollection_DataMap<K, V> myDictionary;
689 MapListOfType (K theKey, V theValue)
691 myDictionary.Bind (theKey, theValue);
694 MapListOfType& operator() (K theKey, V theValue)
696 myDictionary.Bind (theKey, theValue);
700 operator const NCollection_DataMap<K, V>& () const
706 template<class K, class V>
707 MapListOfType<K, V> CreateListOf (K theKey, V theValue)
709 return MapListOfType<K, V> (theKey, theValue);
713 #endif // _OpenGl_ShaderProgram_Header