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_Aspects.hxx>
28 #include <OpenGl_MaterialState.hxx>
29 #include <OpenGl_Texture.hxx>
32 class OpenGl_VertexBuffer;
34 //! List of shader programs.
35 typedef NCollection_Sequence<Handle(OpenGl_ShaderProgram)> OpenGl_ShaderProgramList;
37 //! This class is responsible for managing shader programs.
38 class OpenGl_ShaderManager : public Standard_Transient
40 DEFINE_STANDARD_RTTIEXT(OpenGl_ShaderManager, Standard_Transient)
41 friend class OpenGl_ShaderProgram;
44 //! Creates new empty shader manager.
45 Standard_EXPORT OpenGl_ShaderManager (OpenGl_Context* theContext);
47 //! Releases resources of shader manager.
48 Standard_EXPORT virtual ~OpenGl_ShaderManager();
50 //! Release all resources.
51 Standard_EXPORT void clear();
53 //! Return local camera transformation.
54 const gp_XYZ& LocalOrigin() const { return myLocalOrigin; }
56 //! Setup local camera transformation for compensating float precision issues.
57 void SetLocalOrigin (const gp_XYZ& theOrigin)
59 myLocalOrigin = theOrigin;
60 myHasLocalOrigin = !theOrigin.IsEqual (gp_XYZ(0.0, 0.0, 0.0), gp::Resolution());
63 //! Creates new shader program or re-use shared instance.
64 //! @param theProxy [IN] program definition
65 //! @param theShareKey [OUT] sharing key
66 //! @param theProgram [OUT] OpenGL program
67 //! @return true on success
68 Standard_EXPORT Standard_Boolean Create (const Handle(Graphic3d_ShaderProgram)& theProxy,
69 TCollection_AsciiString& theShareKey,
70 Handle(OpenGl_ShaderProgram)& theProgram);
72 //! Unregisters specified shader program.
73 Standard_EXPORT void Unregister (TCollection_AsciiString& theShareKey,
74 Handle(OpenGl_ShaderProgram)& theProgram);
76 //! Returns list of registered shader programs.
77 Standard_EXPORT const OpenGl_ShaderProgramList& ShaderPrograms() const;
79 //! Returns true if no program objects are registered in the manager.
80 Standard_EXPORT Standard_Boolean IsEmpty() const;
82 //! Bind program for filled primitives rendering
83 Standard_Boolean BindFaceProgram (const Handle(OpenGl_TextureSet)& theTextures,
84 Graphic3d_TypeOfShadingModel theShadingModel,
85 Graphic3d_AlphaMode theAlphaMode,
86 Standard_Boolean theHasVertColor,
87 Standard_Boolean theEnableEnvMap,
88 const Handle(OpenGl_ShaderProgram)& theCustomProgram)
90 return BindFaceProgram (theTextures, theShadingModel, theAlphaMode, Aspect_IS_SOLID,
91 theHasVertColor, theEnableEnvMap, false, theCustomProgram);
94 //! Bind program for filled primitives rendering
95 Standard_Boolean BindFaceProgram (const Handle(OpenGl_TextureSet)& theTextures,
96 Graphic3d_TypeOfShadingModel theShadingModel,
97 Graphic3d_AlphaMode theAlphaMode,
98 Aspect_InteriorStyle theInteriorStyle,
99 Standard_Boolean theHasVertColor,
100 Standard_Boolean theEnableEnvMap,
101 Standard_Boolean theEnableMeshEdges,
102 const Handle(OpenGl_ShaderProgram)& theCustomProgram)
104 if (!theCustomProgram.IsNull()
105 || myContext->caps->ffpEnable)
107 return bindProgramWithState (theCustomProgram);
110 const Graphic3d_TypeOfShadingModel aShadeModelOnFace = theShadingModel != Graphic3d_TOSM_UNLIT
111 && (theTextures.IsNull() || theTextures->IsModulate())
113 : Graphic3d_TOSM_UNLIT;
114 const Standard_Integer aBits = getProgramBits (theTextures, theAlphaMode, theInteriorStyle, theHasVertColor, theEnableEnvMap, theEnableMeshEdges);
115 Handle(OpenGl_ShaderProgram)& aProgram = getStdProgram (aShadeModelOnFace, aBits);
116 return bindProgramWithState (aProgram);
119 //! Bind program for line rendering
120 Standard_Boolean BindLineProgram (const Handle(OpenGl_TextureSet)& theTextures,
121 const Aspect_TypeOfLine theLineType,
122 const Graphic3d_TypeOfShadingModel theShadingModel,
123 const Graphic3d_AlphaMode theAlphaMode,
124 const Standard_Boolean theHasVertColor,
125 const Handle(OpenGl_ShaderProgram)& theCustomProgram)
127 if (!theCustomProgram.IsNull()
128 || myContext->caps->ffpEnable)
130 return bindProgramWithState (theCustomProgram);
133 Standard_Integer aBits = getProgramBits (theTextures, theAlphaMode, Aspect_IS_SOLID, theHasVertColor, false, false);
134 if (theLineType != Aspect_TOL_SOLID)
136 aBits |= OpenGl_PO_StippleLine;
139 Handle(OpenGl_ShaderProgram)& aProgram = getStdProgram (theShadingModel, aBits);
140 return bindProgramWithState (aProgram);
143 //! Bind program for point rendering
144 Standard_Boolean BindMarkerProgram (const Handle(OpenGl_TextureSet)& theTextures,
145 const Graphic3d_TypeOfShadingModel theShadingModel,
146 const Graphic3d_AlphaMode theAlphaMode,
147 const Standard_Boolean theHasVertColor,
148 const Handle(OpenGl_ShaderProgram)& theCustomProgram)
150 if (!theCustomProgram.IsNull()
151 || myContext->caps->ffpEnable)
153 return bindProgramWithState (theCustomProgram);
156 const Standard_Integer aBits = getProgramBits (theTextures, theAlphaMode, Aspect_IS_SOLID, theHasVertColor, false, false) | OpenGl_PO_Point;
157 Handle(OpenGl_ShaderProgram)& aProgram = getStdProgram (theShadingModel, aBits);
158 return bindProgramWithState (aProgram);
161 //! Bind program for rendering alpha-textured font.
162 Standard_Boolean BindFontProgram (const Handle(OpenGl_ShaderProgram)& theCustomProgram)
164 if (!theCustomProgram.IsNull()
165 || myContext->caps->ffpEnable)
167 return bindProgramWithState (theCustomProgram);
170 if (myFontProgram.IsNull())
172 prepareStdProgramFont();
175 return bindProgramWithState (myFontProgram);
178 //! Bind program for outline rendering
179 Standard_Boolean BindOutlineProgram()
181 if (myContext->caps->ffpEnable)
186 const Standard_Integer aBits = getProgramBits (Handle(OpenGl_TextureSet)(), Graphic3d_AlphaMode_Opaque, Aspect_IS_SOLID, false, false, false);
187 if (myOutlinePrograms.IsNull())
189 myOutlinePrograms = new OpenGl_SetOfPrograms();
191 Handle(OpenGl_ShaderProgram)& aProgram = myOutlinePrograms->ChangeValue (aBits);
192 if (aProgram.IsNull())
194 prepareStdProgramUnlit (aProgram, aBits, true);
196 return bindProgramWithState (aProgram);
199 //! Bind program for FBO blit operation.
200 Standard_Boolean BindFboBlitProgram()
202 if (myBlitProgram.IsNull())
204 prepareStdProgramFboBlit();
206 return !myBlitProgram.IsNull()
207 && myContext->BindProgram (myBlitProgram);
210 //! Bind program for blended order-independent transparency buffers compositing.
211 Standard_Boolean BindOitCompositingProgram (const Standard_Boolean theIsMSAAEnabled)
213 const Standard_Integer aProgramIdx = theIsMSAAEnabled ? 1 : 0;
214 if (myOitCompositingProgram[aProgramIdx].IsNull())
216 prepareStdProgramOitCompositing (theIsMSAAEnabled);
219 const Handle(OpenGl_ShaderProgram)& aProgram = myOitCompositingProgram [aProgramIdx];
220 return !aProgram.IsNull() && myContext->BindProgram (aProgram);
223 //! Bind program for rendering stereoscopic image.
224 Standard_Boolean BindStereoProgram (const Graphic3d_StereoMode theStereoMode)
226 if (theStereoMode < 0 || theStereoMode >= Graphic3d_StereoMode_NB)
228 return Standard_False;
231 if (myStereoPrograms[theStereoMode].IsNull())
233 prepareStdProgramStereo (myStereoPrograms[theStereoMode], theStereoMode);
235 const Handle(OpenGl_ShaderProgram)& aProgram = myStereoPrograms[theStereoMode];
236 return !aProgram.IsNull()
237 && myContext->BindProgram (aProgram);
240 //! Bind program for rendering bounding box.
241 Standard_Boolean BindBoundBoxProgram()
243 if (myBoundBoxProgram.IsNull())
245 prepareStdProgramBoundBox();
247 return bindProgramWithState (myBoundBoxProgram);
250 //! Returns bounding box vertex buffer.
251 const Handle(OpenGl_VertexBuffer)& BoundBoxVertBuffer() const { return myBoundBoxVertBuffer; }
255 //! Returns current state of OCCT light sources.
256 const OpenGl_LightSourceState& LightSourceState() const { return myLightSourceState; }
258 //! Updates state of OCCT light sources.
259 Standard_EXPORT void UpdateLightSourceStateTo (const Handle(Graphic3d_LightSet)& theLights);
261 //! Invalidate state of OCCT light sources.
262 Standard_EXPORT void UpdateLightSourceState();
264 //! Pushes current state of OCCT light sources to specified program.
265 Standard_EXPORT void PushLightSourceState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
269 //! Returns current state of OCCT projection transform.
270 const OpenGl_ProjectionState& ProjectionState() const { return myProjectionState; }
272 //! Updates state of OCCT projection transform.
273 Standard_EXPORT void UpdateProjectionStateTo (const OpenGl_Mat4& theProjectionMatrix);
275 //! Pushes current state of OCCT projection transform to specified program.
276 Standard_EXPORT void PushProjectionState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
280 //! Returns current state of OCCT model-world transform.
281 const OpenGl_ModelWorldState& ModelWorldState() const { return myModelWorldState; }
283 //! Updates state of OCCT model-world transform.
284 Standard_EXPORT void UpdateModelWorldStateTo (const OpenGl_Mat4& theModelWorldMatrix);
286 //! Pushes current state of OCCT model-world transform to specified program.
287 Standard_EXPORT void PushModelWorldState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
291 //! Returns current state of OCCT world-view transform.
292 const OpenGl_WorldViewState& WorldViewState() const { return myWorldViewState; }
294 //! Updates state of OCCT world-view transform.
295 Standard_EXPORT void UpdateWorldViewStateTo (const OpenGl_Mat4& theWorldViewMatrix);
297 //! Pushes current state of OCCT world-view transform to specified program.
298 Standard_EXPORT void PushWorldViewState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
302 //! Updates state of OCCT clipping planes.
303 Standard_EXPORT void UpdateClippingState();
305 //! Reverts state of OCCT clipping planes.
306 Standard_EXPORT void RevertClippingState();
308 //! Pushes current state of OCCT clipping planes to specified program.
309 Standard_EXPORT void PushClippingState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
313 //! Returns current state of material.
314 const OpenGl_MaterialState& MaterialState() const { return myMaterialState; }
316 //! Updates state of material.
317 void UpdateMaterialStateTo (const OpenGl_Material& theFrontMat,
318 const OpenGl_Material& theBackMat,
319 const float theAlphaCutoff,
320 const bool theToDistinguish,
321 const bool theToMapTexture)
323 myMaterialState.Set (theFrontMat, theBackMat, theAlphaCutoff, theToDistinguish, theToMapTexture);
324 myMaterialState.Update();
327 //! Updates state of material.
328 void UpdateMaterialState()
330 myMaterialState.Update();
333 //! Pushes current state of material to specified program.
334 void PushMaterialState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
338 //! Setup interior style line edges variables.
339 Standard_EXPORT void PushInteriorState (const Handle(OpenGl_ShaderProgram)& theProgram,
340 const Handle(Graphic3d_Aspects)& theAspect) const;
344 //! Returns state of OIT uniforms.
345 const OpenGl_OitState& OitState() const { return myOitState; }
347 //! Set the state of OIT rendering pass.
348 //! @param theToEnableOitWrite [in] flag indicating whether the special output should be written for OIT algorithm.
349 //! @param theDepthFactor [in] the scalar factor of depth influence to the fragment's coverage.
350 void SetOitState (const bool theToEnableOitWrite, const float theDepthFactor)
352 myOitState.Set (theToEnableOitWrite, theDepthFactor);
356 //! Pushes state of OIT uniforms to the specified program.
357 Standard_EXPORT void PushOitState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
361 //! Pushes current state of OCCT graphics parameters to specified program.
362 Standard_EXPORT void PushState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
366 //! Overwrites context
367 void SetContext (OpenGl_Context* theCtx)
372 //! Returns true when provided context is the same as used one by shader manager.
373 bool IsSameContext (OpenGl_Context* theCtx) const
375 return myContext == theCtx;
378 //! Choose Shading Model for filled primitives.
379 //! Fallbacks to FACET model if there are no normal attributes.
380 Graphic3d_TypeOfShadingModel ChooseFaceShadingModel (Graphic3d_TypeOfShadingModel theCustomModel,
381 bool theHasNodalNormals) const
383 if (!myContext->ColorMask())
385 return Graphic3d_TOSM_UNLIT;
387 Graphic3d_TypeOfShadingModel aModel = theCustomModel != Graphic3d_TOSM_DEFAULT ? theCustomModel : myShadingModel;
390 case Graphic3d_TOSM_DEFAULT:
391 case Graphic3d_TOSM_UNLIT:
392 case Graphic3d_TOSM_FACET:
394 case Graphic3d_TOSM_VERTEX:
395 case Graphic3d_TOSM_FRAGMENT:
396 return theHasNodalNormals ? aModel : Graphic3d_TOSM_FACET;
398 return Graphic3d_TOSM_UNLIT;
401 //! Choose Shading Model for line primitives.
402 //! Fallbacks to UNLIT model if there are no normal attributes.
403 Graphic3d_TypeOfShadingModel ChooseLineShadingModel (Graphic3d_TypeOfShadingModel theCustomModel,
404 bool theHasNodalNormals) const
406 if (!myContext->ColorMask())
408 return Graphic3d_TOSM_UNLIT;
410 Graphic3d_TypeOfShadingModel aModel = theCustomModel != Graphic3d_TOSM_DEFAULT ? theCustomModel : myShadingModel;
413 case Graphic3d_TOSM_DEFAULT:
414 case Graphic3d_TOSM_UNLIT:
415 case Graphic3d_TOSM_FACET:
416 return Graphic3d_TOSM_UNLIT;
417 case Graphic3d_TOSM_VERTEX:
418 case Graphic3d_TOSM_FRAGMENT:
419 return theHasNodalNormals ? aModel : Graphic3d_TOSM_UNLIT;
421 return Graphic3d_TOSM_UNLIT;
424 //! Choose Shading Model for Marker primitives.
425 Graphic3d_TypeOfShadingModel ChooseMarkerShadingModel (Graphic3d_TypeOfShadingModel theCustomModel,
426 bool theHasNodalNormals) const
428 return ChooseLineShadingModel (theCustomModel, theHasNodalNormals);
431 //! Returns default Shading Model.
432 Graphic3d_TypeOfShadingModel ShadingModel() const { return myShadingModel; }
434 //! Sets shading model.
435 Standard_EXPORT void SetShadingModel (const Graphic3d_TypeOfShadingModel theModel);
437 //! Sets last view manger used with.
438 //! Helps to handle matrix states in multi-view configurations.
439 void SetLastView (const OpenGl_View* theLastView)
441 myLastView = theLastView;
444 //! Returns true when provided view is the same as cached one.
445 bool IsSameView (const OpenGl_View* theView) const
447 return myLastView == theView;
452 //! Define clipping planes program bits.
453 Standard_Integer getClipPlaneBits() const
455 const Standard_Integer aNbPlanes = myContext->Clipping().NbClippingOrCappingOn();
461 Standard_Integer aBits = 0;
462 if (myContext->Clipping().HasClippingChains())
464 aBits |= OpenGl_PO_ClipChains;
469 aBits |= OpenGl_PO_ClipPlanes1;
471 else if (aNbPlanes == 2)
473 aBits |= OpenGl_PO_ClipPlanes2;
477 aBits |= OpenGl_PO_ClipPlanesN;
482 //! Define program bits.
483 Standard_Integer getProgramBits (const Handle(OpenGl_TextureSet)& theTextures,
484 Graphic3d_AlphaMode theAlphaMode,
485 Aspect_InteriorStyle theInteriorStyle,
486 Standard_Boolean theHasVertColor,
487 Standard_Boolean theEnableEnvMap,
488 Standard_Boolean theEnableMeshEdges) const
490 Standard_Integer aBits = 0;
491 if (theAlphaMode == Graphic3d_AlphaMode_Mask)
493 aBits |= OpenGl_PO_AlphaTest;
496 aBits |= getClipPlaneBits();
497 if (theEnableMeshEdges
498 && myContext->hasGeometryStage != OpenGl_FeatureNotAvailable)
500 aBits |= OpenGl_PO_MeshEdges;
501 if (theInteriorStyle == Aspect_IS_HOLLOW)
503 aBits |= OpenGl_PO_AlphaTest;
509 // Environment map overwrites material texture
510 aBits |= OpenGl_PO_TextureEnv;
512 else if (!theTextures.IsNull()
513 && !theTextures->IsEmpty()
514 && !theTextures->First().IsNull())
516 aBits |= theTextures->First()->IsAlpha() ? OpenGl_PO_TextureA : OpenGl_PO_TextureRGB;
519 && theInteriorStyle != Aspect_IS_HIDDENLINE)
521 aBits |= OpenGl_PO_VertColor;
524 if (myOitState.ToEnableWrite())
526 aBits |= OpenGl_PO_WriteOit;
531 //! Prepare standard GLSL program.
532 Handle(OpenGl_ShaderProgram)& getStdProgram (Graphic3d_TypeOfShadingModel theShadingModel,
533 Standard_Integer theBits)
535 if (theShadingModel == Graphic3d_TOSM_UNLIT
536 || (theBits & OpenGl_PO_TextureEnv) != 0)
538 // If environment map is enabled lighting calculations are
539 // not needed (in accordance with default OCCT behavior)
540 Handle(OpenGl_ShaderProgram)& aProgram = myUnlitPrograms->ChangeValue (theBits);
541 if (aProgram.IsNull())
543 prepareStdProgramUnlit (aProgram, theBits, false);
548 Handle(OpenGl_ShaderProgram)& aProgram = myLightPrograms->ChangeValue (theShadingModel, theBits);
549 if (aProgram.IsNull())
551 prepareStdProgramLight (aProgram, theShadingModel, theBits);
556 //! Prepare standard GLSL program for accessing point sprite alpha.
557 Standard_EXPORT TCollection_AsciiString pointSpriteAlphaSrc (const Standard_Integer theBits);
559 //! Prepare standard GLSL program for computing point sprite shading.
560 Standard_EXPORT TCollection_AsciiString pointSpriteShadingSrc (const TCollection_AsciiString theBaseColorSrc, const Standard_Integer theBits);
562 //! Prepare standard GLSL program for textured font.
563 Standard_EXPORT Standard_Boolean prepareStdProgramFont();
565 //! Prepare standard GLSL program for FBO blit operation.
566 Standard_EXPORT Standard_Boolean prepareStdProgramFboBlit();
568 //! Prepare standard GLSL programs for OIT compositing operation.
569 Standard_EXPORT Standard_Boolean prepareStdProgramOitCompositing (const Standard_Boolean theMsaa);
571 //! Prepare standard GLSL program without lighting.
572 Standard_EXPORT Standard_Boolean prepareStdProgramUnlit (Handle(OpenGl_ShaderProgram)& theProgram,
573 Standard_Integer theBits,
574 Standard_Boolean theIsOutline = false);
576 //! Prepare standard GLSL program with lighting.
577 Standard_Boolean prepareStdProgramLight (Handle(OpenGl_ShaderProgram)& theProgram,
578 Graphic3d_TypeOfShadingModel theShadingModel,
579 Standard_Integer theBits)
581 switch (theShadingModel)
583 case Graphic3d_TOSM_UNLIT: return prepareStdProgramUnlit (theProgram, theBits, false);
584 case Graphic3d_TOSM_FACET: return prepareStdProgramPhong (theProgram, theBits, true);
585 case Graphic3d_TOSM_VERTEX: return prepareStdProgramGouraud(theProgram, theBits);
586 case Graphic3d_TOSM_DEFAULT:
587 case Graphic3d_TOSM_FRAGMENT: return prepareStdProgramPhong (theProgram, theBits, false);
592 //! Prepare standard GLSL program with per-vertex lighting.
593 Standard_EXPORT Standard_Boolean prepareStdProgramGouraud (Handle(OpenGl_ShaderProgram)& theProgram,
594 const Standard_Integer theBits);
596 //! Prepare standard GLSL program with per-pixel lighting.
597 //! @param theIsFlatNormal when TRUE, the Vertex normals will be ignored and Face normal will be computed instead
598 Standard_EXPORT Standard_Boolean prepareStdProgramPhong (Handle(OpenGl_ShaderProgram)& theProgram,
599 const Standard_Integer theBits,
600 const Standard_Boolean theIsFlatNormal = false);
602 //! Define computeLighting GLSL function depending on current lights configuration
603 //! @param theNbLights [out] number of defined light sources
604 //! @param theHasVertColor [in] flag to use getVertColor() instead of Ambient and Diffuse components of active material
605 Standard_EXPORT TCollection_AsciiString stdComputeLighting (Standard_Integer& theNbLights,
606 Standard_Boolean theHasVertColor);
608 //! Bind specified program to current context and apply state.
609 Standard_EXPORT Standard_Boolean bindProgramWithState (const Handle(OpenGl_ShaderProgram)& theProgram);
611 //! Set pointer myLightPrograms to active lighting programs set from myMapOfLightPrograms
612 Standard_EXPORT void switchLightPrograms();
614 //! Prepare standard GLSL program for stereoscopic image.
615 Standard_EXPORT Standard_Boolean prepareStdProgramStereo (Handle(OpenGl_ShaderProgram)& theProgram,
616 const Graphic3d_StereoMode theStereoMode);
618 //! Prepare standard GLSL program for bounding box.
619 Standard_EXPORT Standard_Boolean prepareStdProgramBoundBox();
621 //! Prepare GLSL version header.
622 Standard_EXPORT Standard_Integer defaultGlslVersion (const Handle(Graphic3d_ShaderProgram)& theProgram,
623 const TCollection_AsciiString& theName,
624 Standard_Integer theBits,
625 bool theUsesDerivates = false) const;
627 //! Prepare GLSL source for geometry shader according to parameters.
628 Standard_EXPORT TCollection_AsciiString prepareGeomMainSrc (OpenGl_ShaderObject::ShaderVariableList& theUnifoms,
629 OpenGl_ShaderObject::ShaderVariableList& theStageInOuts,
630 Standard_Integer theBits);
634 //! Packed properties of light source
635 struct OpenGl_ShaderLightParameters
638 OpenGl_Vec4 Position;
639 OpenGl_Vec4 Direction;
640 OpenGl_Vec4 Parameters;
642 //! Returns packed (serialized) representation of light source properties
643 const OpenGl_Vec4* Packed() const { return reinterpret_cast<const OpenGl_Vec4*> (this); }
644 static Standard_Integer NbOfVec4() { return 4; }
647 //! Packed light source type information
648 struct OpenGl_ShaderLightType
650 Standard_Integer Type;
651 Standard_Integer IsHeadlight;
653 //! Returns packed (serialized) representation of light source type
654 const OpenGl_Vec2i* Packed() const { return reinterpret_cast<const OpenGl_Vec2i*> (this); }
655 static Standard_Integer NbOfVec2i() { return 1; }
658 //! Fake OpenGL program for tracking FFP state in the way consistent to programmable pipeline.
659 class OpenGl_ShaderProgramFFP : public OpenGl_ShaderProgram
661 DEFINE_STANDARD_RTTI_INLINE(OpenGl_ShaderProgramFFP, OpenGl_ShaderProgram)
662 friend class OpenGl_ShaderManager;
664 OpenGl_ShaderProgramFFP() {}
669 //! Append clipping plane definition to temporary buffers.
670 void addClippingPlane (Standard_Integer& thePlaneId,
671 const Graphic3d_ClipPlane& thePlane,
672 const Graphic3d_Vec4d& theEq,
673 const Standard_Integer theChainFwd) const
675 myClipChainArray.SetValue (thePlaneId, theChainFwd);
676 OpenGl_Vec4& aPlaneEq = myClipPlaneArray.ChangeValue (thePlaneId);
677 aPlaneEq.x() = float(theEq.x());
678 aPlaneEq.y() = float(theEq.y());
679 aPlaneEq.z() = float(theEq.z());
680 aPlaneEq.w() = float(theEq.w());
681 if (myHasLocalOrigin)
683 const gp_XYZ aPos = thePlane.ToPlane().Position().Location().XYZ() - myLocalOrigin;
684 const Standard_Real aD = -(theEq.x() * aPos.X() + theEq.y() * aPos.Y() + theEq.z() * aPos.Z());
685 aPlaneEq.w() = float(aD);
692 Handle(OpenGl_ShaderProgramFFP) myFfpProgram;
694 Graphic3d_TypeOfShadingModel myShadingModel; //!< lighting shading model
695 OpenGl_ShaderProgramList myProgramList; //!< The list of shader programs
696 Handle(OpenGl_SetOfShaderPrograms) myLightPrograms; //!< pointer to active lighting programs matrix
697 Handle(OpenGl_SetOfPrograms) myUnlitPrograms; //!< programs matrix without lighting
698 Handle(OpenGl_SetOfPrograms) myOutlinePrograms; //!< programs matrix without lighting for outline presentation
699 Handle(OpenGl_ShaderProgram) myFontProgram; //!< standard program for textured text
700 Handle(OpenGl_ShaderProgram) myBlitProgram; //!< standard program for FBO blit emulation
701 Handle(OpenGl_ShaderProgram) myBoundBoxProgram; //!< standard program for bounding box
702 Handle(OpenGl_ShaderProgram) myOitCompositingProgram[2]; //!< standard program for OIT compositing (default and MSAA).
703 OpenGl_MapOfShaderPrograms myMapOfLightPrograms; //!< map of lighting programs depending on lights configuration
705 Handle(OpenGl_ShaderProgram) myStereoPrograms[Graphic3d_StereoMode_NB]; //!< standard stereo programs
707 Handle(OpenGl_VertexBuffer) myBoundBoxVertBuffer; //!< bounding box vertex buffer
709 OpenGl_Context* myContext; //!< OpenGL context
713 OpenGl_ProjectionState myProjectionState; //!< State of OCCT projection transformation
714 OpenGl_ModelWorldState myModelWorldState; //!< State of OCCT model-world transformation
715 OpenGl_WorldViewState myWorldViewState; //!< State of OCCT world-view transformation
716 OpenGl_ClippingState myClippingState; //!< State of OCCT clipping planes
717 OpenGl_LightSourceState myLightSourceState; //!< State of OCCT light sources
718 OpenGl_MaterialState myMaterialState; //!< State of Front and Back materials
719 OpenGl_OitState myOitState; //!< State of OIT uniforms
721 gp_XYZ myLocalOrigin; //!< local camera transformation
722 Standard_Boolean myHasLocalOrigin; //!< flag indicating that local camera transformation has been set
724 mutable NCollection_Array1<OpenGl_ShaderLightType> myLightTypeArray;
725 mutable NCollection_Array1<OpenGl_ShaderLightParameters> myLightParamsArray;
726 mutable NCollection_Array1<OpenGl_Vec4> myClipPlaneArray;
727 mutable NCollection_Array1<OpenGl_Vec4d> myClipPlaneArrayFfp;
728 mutable NCollection_Array1<Standard_Integer> myClipChainArray;
732 const OpenGl_View* myLastView; //!< Pointer to the last view shader manager used with
736 DEFINE_STANDARD_HANDLE(OpenGl_ShaderManager, Standard_Transient)
738 #endif // _OpenGl_ShaderManager_HeaderFile