1 // Created on: 2013-09-26
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_ShaderManager_HeaderFile
17 #define _OpenGl_ShaderManager_HeaderFile
19 #include <Graphic3d_ShaderProgram.hxx>
20 #include <Graphic3d_StereoMode.hxx>
22 #include <NCollection_DataMap.hxx>
23 #include <NCollection_Sequence.hxx>
25 #include <OpenGl_SetOfShaderPrograms.hxx>
26 #include <OpenGl_ShaderStates.hxx>
27 #include <OpenGl_AspectFace.hxx>
28 #include <OpenGl_AspectLine.hxx>
29 #include <OpenGl_AspectText.hxx>
30 #include <OpenGl_AspectMarker.hxx>
31 #include <OpenGl_MaterialState.hxx>
32 #include <OpenGl_Texture.hxx>
35 class OpenGl_VertexBuffer;
37 //! List of shader programs.
38 typedef NCollection_Sequence<Handle(OpenGl_ShaderProgram)> OpenGl_ShaderProgramList;
40 //! This class is responsible for managing shader programs.
41 class OpenGl_ShaderManager : public Standard_Transient
43 DEFINE_STANDARD_RTTIEXT(OpenGl_ShaderManager, Standard_Transient)
44 friend class OpenGl_ShaderProgram;
47 //! Creates new empty shader manager.
48 Standard_EXPORT OpenGl_ShaderManager (OpenGl_Context* theContext);
50 //! Releases resources of shader manager.
51 Standard_EXPORT virtual ~OpenGl_ShaderManager();
53 //! Release all resources.
54 Standard_EXPORT void clear();
56 //! Return local camera transformation.
57 const gp_XYZ& LocalOrigin() const { return myLocalOrigin; }
59 //! Setup local camera transformation for compensating float precision issues.
60 void SetLocalOrigin (const gp_XYZ& theOrigin)
62 myLocalOrigin = theOrigin;
63 myHasLocalOrigin = !theOrigin.IsEqual (gp_XYZ(0.0, 0.0, 0.0), gp::Resolution());
66 //! Creates new shader program or re-use shared instance.
67 //! @param theProxy [IN] program definition
68 //! @param theShareKey [OUT] sharing key
69 //! @param theProgram [OUT] OpenGL program
70 //! @return true on success
71 Standard_EXPORT Standard_Boolean Create (const Handle(Graphic3d_ShaderProgram)& theProxy,
72 TCollection_AsciiString& theShareKey,
73 Handle(OpenGl_ShaderProgram)& theProgram);
75 //! Unregisters specified shader program.
76 Standard_EXPORT void Unregister (TCollection_AsciiString& theShareKey,
77 Handle(OpenGl_ShaderProgram)& theProgram);
79 //! Returns list of registered shader programs.
80 Standard_EXPORT const OpenGl_ShaderProgramList& ShaderPrograms() const;
82 //! Returns true if no program objects are registered in the manager.
83 Standard_EXPORT Standard_Boolean IsEmpty() const;
85 //! Bind program for filled primitives rendering
86 Standard_Boolean BindFaceProgram (const Handle(OpenGl_TextureSet)& theTextures,
87 Graphic3d_TypeOfShadingModel theShadingModel,
88 Graphic3d_AlphaMode theAlphaMode,
89 Standard_Boolean theHasVertColor,
90 Standard_Boolean theEnableEnvMap,
91 const Handle(OpenGl_ShaderProgram)& theCustomProgram)
93 return BindFaceProgram (theTextures, theShadingModel, theAlphaMode, Aspect_IS_SOLID,
94 theHasVertColor, theEnableEnvMap, false, theCustomProgram);
97 //! Bind program for filled primitives rendering
98 Standard_Boolean BindFaceProgram (const Handle(OpenGl_TextureSet)& theTextures,
99 Graphic3d_TypeOfShadingModel theShadingModel,
100 Graphic3d_AlphaMode theAlphaMode,
101 Aspect_InteriorStyle theInteriorStyle,
102 Standard_Boolean theHasVertColor,
103 Standard_Boolean theEnableEnvMap,
104 Standard_Boolean theEnableMeshEdges,
105 const Handle(OpenGl_ShaderProgram)& theCustomProgram)
107 if (!theCustomProgram.IsNull()
108 || myContext->caps->ffpEnable)
110 return bindProgramWithState (theCustomProgram);
113 const Graphic3d_TypeOfShadingModel aShadeModelOnFace = theShadingModel != Graphic3d_TOSM_UNLIT
114 && (theTextures.IsNull() || theTextures->IsModulate())
116 : Graphic3d_TOSM_UNLIT;
117 const Standard_Integer aBits = getProgramBits (theTextures, theAlphaMode, theInteriorStyle, theHasVertColor, theEnableEnvMap, theEnableMeshEdges);
118 Handle(OpenGl_ShaderProgram)& aProgram = getStdProgram (aShadeModelOnFace, aBits);
119 return bindProgramWithState (aProgram);
122 //! Bind program for line rendering
123 Standard_Boolean BindLineProgram (const Handle(OpenGl_TextureSet)& theTextures,
124 const Aspect_TypeOfLine theLineType,
125 const Graphic3d_TypeOfShadingModel theShadingModel,
126 const Graphic3d_AlphaMode theAlphaMode,
127 const Standard_Boolean theHasVertColor,
128 const Handle(OpenGl_ShaderProgram)& theCustomProgram)
130 if (!theCustomProgram.IsNull()
131 || myContext->caps->ffpEnable)
133 return bindProgramWithState (theCustomProgram);
136 Standard_Integer aBits = getProgramBits (theTextures, theAlphaMode, Aspect_IS_SOLID, theHasVertColor, false, false);
137 if (theLineType != Aspect_TOL_SOLID)
139 aBits |= OpenGl_PO_StippleLine;
142 Handle(OpenGl_ShaderProgram)& aProgram = getStdProgram (theShadingModel, aBits);
143 return bindProgramWithState (aProgram);
146 //! Bind program for point rendering
147 Standard_Boolean BindMarkerProgram (const Handle(OpenGl_TextureSet)& theTextures,
148 const Graphic3d_TypeOfShadingModel theShadingModel,
149 const Graphic3d_AlphaMode theAlphaMode,
150 const Standard_Boolean theHasVertColor,
151 const Handle(OpenGl_ShaderProgram)& theCustomProgram)
153 if (!theCustomProgram.IsNull()
154 || myContext->caps->ffpEnable)
156 return bindProgramWithState (theCustomProgram);
159 const Standard_Integer aBits = getProgramBits (theTextures, theAlphaMode, Aspect_IS_SOLID, theHasVertColor, false, false) | OpenGl_PO_Point;
160 Handle(OpenGl_ShaderProgram)& aProgram = getStdProgram (theShadingModel, aBits);
161 return bindProgramWithState (aProgram);
164 //! Bind program for rendering alpha-textured font.
165 Standard_Boolean BindFontProgram (const Handle(OpenGl_ShaderProgram)& theCustomProgram)
167 if (!theCustomProgram.IsNull()
168 || myContext->caps->ffpEnable)
170 return bindProgramWithState (theCustomProgram);
173 if (myFontProgram.IsNull())
175 prepareStdProgramFont();
178 return bindProgramWithState (myFontProgram);
181 //! Bind program for outline rendering
182 Standard_Boolean BindOutlineProgram()
184 if (myContext->caps->ffpEnable)
189 const Standard_Integer aBits = getProgramBits (Handle(OpenGl_TextureSet)(), Graphic3d_AlphaMode_Opaque, Aspect_IS_SOLID, false, false, false);
190 if (myOutlinePrograms.IsNull())
192 myOutlinePrograms = new OpenGl_SetOfPrograms();
194 Handle(OpenGl_ShaderProgram)& aProgram = myOutlinePrograms->ChangeValue (aBits);
195 if (aProgram.IsNull())
197 prepareStdProgramUnlit (aProgram, aBits, true);
199 return bindProgramWithState (aProgram);
202 //! Bind program for FBO blit operation.
203 Standard_Boolean BindFboBlitProgram()
205 if (myBlitProgram.IsNull())
207 prepareStdProgramFboBlit();
209 return !myBlitProgram.IsNull()
210 && myContext->BindProgram (myBlitProgram);
213 //! Bind program for blended order-independent transparency buffers compositing.
214 Standard_Boolean BindOitCompositingProgram (const Standard_Boolean theIsMSAAEnabled)
216 const Standard_Integer aProgramIdx = theIsMSAAEnabled ? 1 : 0;
217 if (myOitCompositingProgram[aProgramIdx].IsNull())
219 prepareStdProgramOitCompositing (theIsMSAAEnabled);
222 const Handle(OpenGl_ShaderProgram)& aProgram = myOitCompositingProgram [aProgramIdx];
223 return !aProgram.IsNull() && myContext->BindProgram (aProgram);
226 //! Bind program for rendering stereoscopic image.
227 Standard_Boolean BindStereoProgram (const Graphic3d_StereoMode theStereoMode)
229 if (theStereoMode < 0 || theStereoMode >= Graphic3d_StereoMode_NB)
231 return Standard_False;
234 if (myStereoPrograms[theStereoMode].IsNull())
236 prepareStdProgramStereo (myStereoPrograms[theStereoMode], theStereoMode);
238 const Handle(OpenGl_ShaderProgram)& aProgram = myStereoPrograms[theStereoMode];
239 return !aProgram.IsNull()
240 && myContext->BindProgram (aProgram);
243 //! Bind program for rendering bounding box.
244 Standard_Boolean BindBoundBoxProgram()
246 if (myBoundBoxProgram.IsNull())
248 prepareStdProgramBoundBox();
250 return bindProgramWithState (myBoundBoxProgram);
253 //! Returns bounding box vertex buffer.
254 const Handle(OpenGl_VertexBuffer)& BoundBoxVertBuffer() const { return myBoundBoxVertBuffer; }
258 //! Returns current state of OCCT light sources.
259 const OpenGl_LightSourceState& LightSourceState() const { return myLightSourceState; }
261 //! Updates state of OCCT light sources.
262 Standard_EXPORT void UpdateLightSourceStateTo (const Handle(Graphic3d_LightSet)& theLights);
264 //! Invalidate state of OCCT light sources.
265 Standard_EXPORT void UpdateLightSourceState();
267 //! Pushes current state of OCCT light sources to specified program.
268 Standard_EXPORT void PushLightSourceState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
272 //! Returns current state of OCCT projection transform.
273 const OpenGl_ProjectionState& ProjectionState() const { return myProjectionState; }
275 //! Updates state of OCCT projection transform.
276 Standard_EXPORT void UpdateProjectionStateTo (const OpenGl_Mat4& theProjectionMatrix);
278 //! Pushes current state of OCCT projection transform to specified program.
279 Standard_EXPORT void PushProjectionState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
283 //! Returns current state of OCCT model-world transform.
284 const OpenGl_ModelWorldState& ModelWorldState() const { return myModelWorldState; }
286 //! Updates state of OCCT model-world transform.
287 Standard_EXPORT void UpdateModelWorldStateTo (const OpenGl_Mat4& theModelWorldMatrix);
289 //! Pushes current state of OCCT model-world transform to specified program.
290 Standard_EXPORT void PushModelWorldState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
294 //! Returns current state of OCCT world-view transform.
295 const OpenGl_WorldViewState& WorldViewState() const { return myWorldViewState; }
297 //! Updates state of OCCT world-view transform.
298 Standard_EXPORT void UpdateWorldViewStateTo (const OpenGl_Mat4& theWorldViewMatrix);
300 //! Pushes current state of OCCT world-view transform to specified program.
301 Standard_EXPORT void PushWorldViewState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
305 //! Updates state of OCCT clipping planes.
306 Standard_EXPORT void UpdateClippingState();
308 //! Reverts state of OCCT clipping planes.
309 Standard_EXPORT void RevertClippingState();
311 //! Pushes current state of OCCT clipping planes to specified program.
312 Standard_EXPORT void PushClippingState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
316 //! Returns current state of material.
317 const OpenGl_MaterialState& MaterialState() const { return myMaterialState; }
319 //! Updates state of material.
320 void UpdateMaterialStateTo (const OpenGl_Material& theFrontMat,
321 const OpenGl_Material& theBackMat,
322 const float theAlphaCutoff,
323 const bool theToDistinguish,
324 const bool theToMapTexture)
326 myMaterialState.Set (theFrontMat, theBackMat, theAlphaCutoff, theToDistinguish, theToMapTexture);
327 myMaterialState.Update();
330 //! Updates state of material.
331 void UpdateMaterialState()
333 myMaterialState.Update();
336 //! Pushes current state of material to specified program.
337 void PushMaterialState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
341 //! Setup interior style line edges variables.
342 Standard_EXPORT void PushInteriorState (const Handle(OpenGl_ShaderProgram)& theProgram,
343 const Handle(Graphic3d_AspectFillArea3d)& theAspect) const;
347 //! Returns state of OIT uniforms.
348 const OpenGl_OitState& OitState() const { return myOitState; }
350 //! Set the state of OIT rendering pass.
351 //! @param theToEnableOitWrite [in] flag indicating whether the special output should be written for OIT algorithm.
352 //! @param theDepthFactor [in] the scalar factor of depth influence to the fragment's coverage.
353 void SetOitState (const bool theToEnableOitWrite, const float theDepthFactor)
355 myOitState.Set (theToEnableOitWrite, theDepthFactor);
359 //! Pushes state of OIT uniforms to the specified program.
360 Standard_EXPORT void PushOitState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
364 //! Pushes current state of OCCT graphics parameters to specified program.
365 Standard_EXPORT void PushState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
369 //! Overwrites context
370 void SetContext (OpenGl_Context* theCtx)
375 //! Returns true when provided context is the same as used one by shader manager.
376 bool IsSameContext (OpenGl_Context* theCtx) const
378 return myContext == theCtx;
381 //! Choose Shading Model for filled primitives.
382 //! Fallbacks to FACET model if there are no normal attributes.
383 Graphic3d_TypeOfShadingModel ChooseFaceShadingModel (Graphic3d_TypeOfShadingModel theCustomModel,
384 bool theHasNodalNormals) const
386 if (!myContext->ColorMask())
388 return Graphic3d_TOSM_UNLIT;
390 Graphic3d_TypeOfShadingModel aModel = theCustomModel != Graphic3d_TOSM_DEFAULT ? theCustomModel : myShadingModel;
393 case Graphic3d_TOSM_DEFAULT:
394 case Graphic3d_TOSM_UNLIT:
395 case Graphic3d_TOSM_FACET:
397 case Graphic3d_TOSM_VERTEX:
398 case Graphic3d_TOSM_FRAGMENT:
399 return theHasNodalNormals ? aModel : Graphic3d_TOSM_FACET;
401 return Graphic3d_TOSM_UNLIT;
404 //! Choose Shading Model for line primitives.
405 //! Fallbacks to UNLIT model if there are no normal attributes.
406 Graphic3d_TypeOfShadingModel ChooseLineShadingModel (Graphic3d_TypeOfShadingModel theCustomModel,
407 bool theHasNodalNormals) const
409 if (!myContext->ColorMask())
411 return Graphic3d_TOSM_UNLIT;
413 Graphic3d_TypeOfShadingModel aModel = theCustomModel != Graphic3d_TOSM_DEFAULT ? theCustomModel : myShadingModel;
416 case Graphic3d_TOSM_DEFAULT:
417 case Graphic3d_TOSM_UNLIT:
418 case Graphic3d_TOSM_FACET:
419 return Graphic3d_TOSM_UNLIT;
420 case Graphic3d_TOSM_VERTEX:
421 case Graphic3d_TOSM_FRAGMENT:
422 return theHasNodalNormals ? aModel : Graphic3d_TOSM_UNLIT;
424 return Graphic3d_TOSM_UNLIT;
427 //! Choose Shading Model for Marker primitives.
428 Graphic3d_TypeOfShadingModel ChooseMarkerShadingModel (Graphic3d_TypeOfShadingModel theCustomModel,
429 bool theHasNodalNormals) const
431 return ChooseLineShadingModel (theCustomModel, theHasNodalNormals);
434 //! Returns default Shading Model.
435 Graphic3d_TypeOfShadingModel ShadingModel() const { return myShadingModel; }
437 //! Sets shading model.
438 Standard_EXPORT void SetShadingModel (const Graphic3d_TypeOfShadingModel theModel);
440 //! Sets last view manger used with.
441 //! Helps to handle matrix states in multi-view configurations.
442 void SetLastView (const OpenGl_View* theLastView)
444 myLastView = theLastView;
447 //! Returns true when provided view is the same as cached one.
448 bool IsSameView (const OpenGl_View* theView) const
450 return myLastView == theView;
455 //! Define clipping planes program bits.
456 Standard_Integer getClipPlaneBits() const
458 const Standard_Integer aNbPlanes = myContext->Clipping().NbClippingOrCappingOn();
464 Standard_Integer aBits = 0;
465 if (myContext->Clipping().HasClippingChains())
467 aBits |= OpenGl_PO_ClipChains;
472 aBits |= OpenGl_PO_ClipPlanes1;
474 else if (aNbPlanes == 2)
476 aBits |= OpenGl_PO_ClipPlanes2;
480 aBits |= OpenGl_PO_ClipPlanesN;
485 //! Define program bits.
486 Standard_Integer getProgramBits (const Handle(OpenGl_TextureSet)& theTextures,
487 Graphic3d_AlphaMode theAlphaMode,
488 Aspect_InteriorStyle theInteriorStyle,
489 Standard_Boolean theHasVertColor,
490 Standard_Boolean theEnableEnvMap,
491 Standard_Boolean theEnableMeshEdges) const
493 Standard_Integer aBits = 0;
494 if (theAlphaMode == Graphic3d_AlphaMode_Mask)
496 aBits |= OpenGl_PO_AlphaTest;
499 aBits |= getClipPlaneBits();
500 if (theEnableMeshEdges
501 && myContext->hasGeometryStage != OpenGl_FeatureNotAvailable)
503 aBits |= OpenGl_PO_MeshEdges;
504 if (theInteriorStyle == Aspect_IS_HOLLOW)
506 aBits |= OpenGl_PO_AlphaTest;
512 // Environment map overwrites material texture
513 aBits |= OpenGl_PO_TextureEnv;
515 else if (!theTextures.IsNull()
516 && !theTextures->IsEmpty()
517 && !theTextures->First().IsNull())
519 aBits |= theTextures->First()->IsAlpha() ? OpenGl_PO_TextureA : OpenGl_PO_TextureRGB;
522 && theInteriorStyle != Aspect_IS_HIDDENLINE)
524 aBits |= OpenGl_PO_VertColor;
527 if (myOitState.ToEnableWrite())
529 aBits |= OpenGl_PO_WriteOit;
534 //! Prepare standard GLSL program.
535 Handle(OpenGl_ShaderProgram)& getStdProgram (Graphic3d_TypeOfShadingModel theShadingModel,
536 Standard_Integer theBits)
538 if (theShadingModel == Graphic3d_TOSM_UNLIT
539 || (theBits & OpenGl_PO_TextureEnv) != 0)
541 // If environment map is enabled lighting calculations are
542 // not needed (in accordance with default OCCT behavior)
543 Handle(OpenGl_ShaderProgram)& aProgram = myUnlitPrograms->ChangeValue (theBits);
544 if (aProgram.IsNull())
546 prepareStdProgramUnlit (aProgram, theBits, false);
551 Handle(OpenGl_ShaderProgram)& aProgram = myLightPrograms->ChangeValue (theShadingModel, theBits);
552 if (aProgram.IsNull())
554 prepareStdProgramLight (aProgram, theShadingModel, theBits);
559 //! Prepare standard GLSL program for accessing point sprite alpha.
560 Standard_EXPORT TCollection_AsciiString pointSpriteAlphaSrc (const Standard_Integer theBits);
562 //! Prepare standard GLSL program for computing point sprite shading.
563 Standard_EXPORT TCollection_AsciiString pointSpriteShadingSrc (const TCollection_AsciiString theBaseColorSrc, const Standard_Integer theBits);
565 //! Prepare standard GLSL program for textured font.
566 Standard_EXPORT Standard_Boolean prepareStdProgramFont();
568 //! Prepare standard GLSL program for FBO blit operation.
569 Standard_EXPORT Standard_Boolean prepareStdProgramFboBlit();
571 //! Prepare standard GLSL programs for OIT compositing operation.
572 Standard_EXPORT Standard_Boolean prepareStdProgramOitCompositing (const Standard_Boolean theMsaa);
574 //! Prepare standard GLSL program without lighting.
575 Standard_EXPORT Standard_Boolean prepareStdProgramUnlit (Handle(OpenGl_ShaderProgram)& theProgram,
576 Standard_Integer theBits,
577 Standard_Boolean theIsOutline = false);
579 //! Prepare standard GLSL program with lighting.
580 Standard_Boolean prepareStdProgramLight (Handle(OpenGl_ShaderProgram)& theProgram,
581 Graphic3d_TypeOfShadingModel theShadingModel,
582 Standard_Integer theBits)
584 switch (theShadingModel)
586 case Graphic3d_TOSM_UNLIT: return prepareStdProgramUnlit (theProgram, theBits, false);
587 case Graphic3d_TOSM_FACET: return prepareStdProgramPhong (theProgram, theBits, true);
588 case Graphic3d_TOSM_VERTEX: return prepareStdProgramGouraud(theProgram, theBits);
589 case Graphic3d_TOSM_DEFAULT:
590 case Graphic3d_TOSM_FRAGMENT: return prepareStdProgramPhong (theProgram, theBits, false);
595 //! Prepare standard GLSL program with per-vertex lighting.
596 Standard_EXPORT Standard_Boolean prepareStdProgramGouraud (Handle(OpenGl_ShaderProgram)& theProgram,
597 const Standard_Integer theBits);
599 //! Prepare standard GLSL program with per-pixel lighting.
600 //! @param theIsFlatNormal when TRUE, the Vertex normals will be ignored and Face normal will be computed instead
601 Standard_EXPORT Standard_Boolean prepareStdProgramPhong (Handle(OpenGl_ShaderProgram)& theProgram,
602 const Standard_Integer theBits,
603 const Standard_Boolean theIsFlatNormal = false);
605 //! Define computeLighting GLSL function depending on current lights configuration
606 //! @param theNbLights [out] number of defined light sources
607 //! @param theHasVertColor [in] flag to use getVertColor() instead of Ambient and Diffuse components of active material
608 Standard_EXPORT TCollection_AsciiString stdComputeLighting (Standard_Integer& theNbLights,
609 Standard_Boolean theHasVertColor);
611 //! Bind specified program to current context and apply state.
612 Standard_EXPORT Standard_Boolean bindProgramWithState (const Handle(OpenGl_ShaderProgram)& theProgram);
614 //! Set pointer myLightPrograms to active lighting programs set from myMapOfLightPrograms
615 Standard_EXPORT void switchLightPrograms();
617 //! Prepare standard GLSL program for stereoscopic image.
618 Standard_EXPORT Standard_Boolean prepareStdProgramStereo (Handle(OpenGl_ShaderProgram)& theProgram,
619 const Graphic3d_StereoMode theStereoMode);
621 //! Prepare standard GLSL program for bounding box.
622 Standard_EXPORT Standard_Boolean prepareStdProgramBoundBox();
624 //! Prepare GLSL version header.
625 Standard_EXPORT Standard_Integer defaultGlslVersion (const Handle(Graphic3d_ShaderProgram)& theProgram,
626 const TCollection_AsciiString& theName,
627 Standard_Integer theBits,
628 bool theUsesDerivates = false) const;
630 //! Prepare GLSL source for geometry shader according to parameters.
631 Standard_EXPORT TCollection_AsciiString prepareGeomMainSrc (OpenGl_ShaderObject::ShaderVariableList& theUnifoms,
632 OpenGl_ShaderObject::ShaderVariableList& theStageInOuts,
633 Standard_Integer theBits);
637 //! Packed properties of light source
638 struct OpenGl_ShaderLightParameters
641 OpenGl_Vec4 Position;
642 OpenGl_Vec4 Direction;
643 OpenGl_Vec4 Parameters;
645 //! Returns packed (serialized) representation of light source properties
646 const OpenGl_Vec4* Packed() const { return reinterpret_cast<const OpenGl_Vec4*> (this); }
647 static Standard_Integer NbOfVec4() { return 4; }
650 //! Packed light source type information
651 struct OpenGl_ShaderLightType
653 Standard_Integer Type;
654 Standard_Integer IsHeadlight;
656 //! Returns packed (serialized) representation of light source type
657 const OpenGl_Vec2i* Packed() const { return reinterpret_cast<const OpenGl_Vec2i*> (this); }
658 static Standard_Integer NbOfVec2i() { return 1; }
661 //! Fake OpenGL program for tracking FFP state in the way consistent to programmable pipeline.
662 class OpenGl_ShaderProgramFFP : public OpenGl_ShaderProgram
664 DEFINE_STANDARD_RTTI_INLINE(OpenGl_ShaderProgramFFP, OpenGl_ShaderProgram)
665 friend class OpenGl_ShaderManager;
667 OpenGl_ShaderProgramFFP() {}
672 //! Append clipping plane definition to temporary buffers.
673 void addClippingPlane (Standard_Integer& thePlaneId,
674 const Graphic3d_ClipPlane& thePlane,
675 const Graphic3d_Vec4d& theEq,
676 const Standard_Integer theChainFwd) const
678 myClipChainArray.SetValue (thePlaneId, theChainFwd);
679 OpenGl_Vec4& aPlaneEq = myClipPlaneArray.ChangeValue (thePlaneId);
680 aPlaneEq.x() = float(theEq.x());
681 aPlaneEq.y() = float(theEq.y());
682 aPlaneEq.z() = float(theEq.z());
683 aPlaneEq.w() = float(theEq.w());
684 if (myHasLocalOrigin)
686 const gp_XYZ aPos = thePlane.ToPlane().Position().Location().XYZ() - myLocalOrigin;
687 const Standard_Real aD = -(theEq.x() * aPos.X() + theEq.y() * aPos.Y() + theEq.z() * aPos.Z());
688 aPlaneEq.w() = float(aD);
695 Handle(OpenGl_ShaderProgramFFP) myFfpProgram;
697 Graphic3d_TypeOfShadingModel myShadingModel; //!< lighting shading model
698 OpenGl_ShaderProgramList myProgramList; //!< The list of shader programs
699 Handle(OpenGl_SetOfShaderPrograms) myLightPrograms; //!< pointer to active lighting programs matrix
700 Handle(OpenGl_SetOfPrograms) myUnlitPrograms; //!< programs matrix without lighting
701 Handle(OpenGl_SetOfPrograms) myOutlinePrograms; //!< programs matrix without lighting for outline presentation
702 Handle(OpenGl_ShaderProgram) myFontProgram; //!< standard program for textured text
703 Handle(OpenGl_ShaderProgram) myBlitProgram; //!< standard program for FBO blit emulation
704 Handle(OpenGl_ShaderProgram) myBoundBoxProgram; //!< standard program for bounding box
705 Handle(OpenGl_ShaderProgram) myOitCompositingProgram[2]; //!< standard program for OIT compositing (default and MSAA).
706 OpenGl_MapOfShaderPrograms myMapOfLightPrograms; //!< map of lighting programs depending on lights configuration
708 Handle(OpenGl_ShaderProgram) myStereoPrograms[Graphic3d_StereoMode_NB]; //!< standard stereo programs
710 Handle(OpenGl_VertexBuffer) myBoundBoxVertBuffer; //!< bounding box vertex buffer
712 OpenGl_Context* myContext; //!< OpenGL context
716 OpenGl_ProjectionState myProjectionState; //!< State of OCCT projection transformation
717 OpenGl_ModelWorldState myModelWorldState; //!< State of OCCT model-world transformation
718 OpenGl_WorldViewState myWorldViewState; //!< State of OCCT world-view transformation
719 OpenGl_ClippingState myClippingState; //!< State of OCCT clipping planes
720 OpenGl_LightSourceState myLightSourceState; //!< State of OCCT light sources
721 OpenGl_MaterialState myMaterialState; //!< State of Front and Back materials
722 OpenGl_OitState myOitState; //!< State of OIT uniforms
724 gp_XYZ myLocalOrigin; //!< local camera transformation
725 Standard_Boolean myHasLocalOrigin; //!< flag indicating that local camera transformation has been set
727 mutable NCollection_Array1<OpenGl_ShaderLightType> myLightTypeArray;
728 mutable NCollection_Array1<OpenGl_ShaderLightParameters> myLightParamsArray;
729 mutable NCollection_Array1<OpenGl_Vec4> myClipPlaneArray;
730 mutable NCollection_Array1<OpenGl_Vec4d> myClipPlaneArrayFfp;
731 mutable NCollection_Array1<Standard_Integer> myClipChainArray;
735 const OpenGl_View* myLastView; //!< Pointer to the last view shader manager used with
739 DEFINE_STANDARD_HANDLE(OpenGl_ShaderManager, Standard_Transient)
741 #endif // _OpenGl_ShaderManager_HeaderFile