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, theHasVertColor, theEnableEnvMap, false, theCustomProgram);
96 //! Bind program for filled primitives rendering
97 Standard_Boolean BindFaceProgram (const Handle(OpenGl_TextureSet)& theTextures,
98 Graphic3d_TypeOfShadingModel theShadingModel,
99 Graphic3d_AlphaMode theAlphaMode,
100 Aspect_InteriorStyle theInteriorStyle,
101 Standard_Boolean theHasVertColor,
102 Standard_Boolean theEnableEnvMap,
103 Standard_Boolean theEnableMeshEdges,
104 const Handle(OpenGl_ShaderProgram)& theCustomProgram)
106 if (!theCustomProgram.IsNull()
107 || myContext->caps->ffpEnable)
109 return bindProgramWithState (theCustomProgram);
112 const Graphic3d_TypeOfShadingModel aShadeModelOnFace = theShadingModel != Graphic3d_TOSM_UNLIT
113 && (theTextures.IsNull() || theTextures->IsModulate())
115 : Graphic3d_TOSM_UNLIT;
116 const Standard_Integer aBits = getProgramBits (theTextures, theAlphaMode, theInteriorStyle, theHasVertColor, theEnableEnvMap, theEnableMeshEdges);
117 Handle(OpenGl_ShaderProgram)& aProgram = getStdProgram (aShadeModelOnFace, aBits);
118 return bindProgramWithState (aProgram);
121 //! Bind program for line rendering
122 Standard_Boolean BindLineProgram (const Handle(OpenGl_TextureSet)& theTextures,
123 const Aspect_TypeOfLine theLineType,
124 const Graphic3d_TypeOfShadingModel theShadingModel,
125 const Graphic3d_AlphaMode theAlphaMode,
126 const Standard_Boolean theHasVertColor,
127 const Handle(OpenGl_ShaderProgram)& theCustomProgram)
129 if (!theCustomProgram.IsNull()
130 || myContext->caps->ffpEnable)
132 return bindProgramWithState (theCustomProgram);
135 Standard_Integer aBits = getProgramBits (theTextures, theAlphaMode, Aspect_IS_SOLID, theHasVertColor, false, false);
136 if (theLineType != Aspect_TOL_SOLID)
138 aBits |= OpenGl_PO_StippleLine;
141 Handle(OpenGl_ShaderProgram)& aProgram = getStdProgram (theShadingModel, aBits);
142 return bindProgramWithState (aProgram);
145 //! Bind program for point rendering
146 Standard_Boolean BindMarkerProgram (const Handle(OpenGl_TextureSet)& theTextures,
147 const Graphic3d_TypeOfShadingModel theShadingModel,
148 const Graphic3d_AlphaMode theAlphaMode,
149 const Standard_Boolean theHasVertColor,
150 const Handle(OpenGl_ShaderProgram)& theCustomProgram)
152 if (!theCustomProgram.IsNull()
153 || myContext->caps->ffpEnable)
155 return bindProgramWithState (theCustomProgram);
158 const Standard_Integer aBits = getProgramBits (theTextures, theAlphaMode, Aspect_IS_SOLID, theHasVertColor, false, false) | OpenGl_PO_Point;
159 Handle(OpenGl_ShaderProgram)& aProgram = getStdProgram (theShadingModel, aBits);
160 return bindProgramWithState (aProgram);
163 //! Bind program for rendering alpha-textured font.
164 Standard_Boolean BindFontProgram (const Handle(OpenGl_ShaderProgram)& theCustomProgram)
166 if (!theCustomProgram.IsNull()
167 || myContext->caps->ffpEnable)
169 return bindProgramWithState (theCustomProgram);
172 if (myFontProgram.IsNull())
174 prepareStdProgramFont();
177 return bindProgramWithState (myFontProgram);
180 //! Bind program for FBO blit operation.
181 Standard_Boolean BindFboBlitProgram()
183 if (myBlitProgram.IsNull())
185 prepareStdProgramFboBlit();
187 return !myBlitProgram.IsNull()
188 && myContext->BindProgram (myBlitProgram);
191 //! Bind program for blended order-independent transparency buffers compositing.
192 Standard_Boolean BindOitCompositingProgram (const Standard_Boolean theIsMSAAEnabled)
194 const Standard_Integer aProgramIdx = theIsMSAAEnabled ? 1 : 0;
195 if (myOitCompositingProgram[aProgramIdx].IsNull())
197 prepareStdProgramOitCompositing (theIsMSAAEnabled);
200 const Handle(OpenGl_ShaderProgram)& aProgram = myOitCompositingProgram [aProgramIdx];
201 return !aProgram.IsNull() && myContext->BindProgram (aProgram);
204 //! Bind program for rendering stereoscopic image.
205 Standard_Boolean BindStereoProgram (const Graphic3d_StereoMode theStereoMode)
207 if (theStereoMode < 0 || theStereoMode >= Graphic3d_StereoMode_NB)
209 return Standard_False;
212 if (myStereoPrograms[theStereoMode].IsNull())
214 prepareStdProgramStereo (myStereoPrograms[theStereoMode], theStereoMode);
216 const Handle(OpenGl_ShaderProgram)& aProgram = myStereoPrograms[theStereoMode];
217 return !aProgram.IsNull()
218 && myContext->BindProgram (aProgram);
221 //! Bind program for rendering bounding box.
222 Standard_Boolean BindBoundBoxProgram()
224 if (myBoundBoxProgram.IsNull())
226 prepareStdProgramBoundBox();
228 return bindProgramWithState (myBoundBoxProgram);
231 //! Returns bounding box vertex buffer.
232 const Handle(OpenGl_VertexBuffer)& BoundBoxVertBuffer() const { return myBoundBoxVertBuffer; }
236 //! Returns current state of OCCT light sources.
237 const OpenGl_LightSourceState& LightSourceState() const { return myLightSourceState; }
239 //! Updates state of OCCT light sources.
240 Standard_EXPORT void UpdateLightSourceStateTo (const Handle(Graphic3d_LightSet)& theLights);
242 //! Invalidate state of OCCT light sources.
243 Standard_EXPORT void UpdateLightSourceState();
245 //! Pushes current state of OCCT light sources to specified program.
246 Standard_EXPORT void PushLightSourceState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
250 //! Returns current state of OCCT projection transform.
251 const OpenGl_ProjectionState& ProjectionState() const { return myProjectionState; }
253 //! Updates state of OCCT projection transform.
254 Standard_EXPORT void UpdateProjectionStateTo (const OpenGl_Mat4& theProjectionMatrix);
256 //! Pushes current state of OCCT projection transform to specified program.
257 Standard_EXPORT void PushProjectionState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
261 //! Returns current state of OCCT model-world transform.
262 const OpenGl_ModelWorldState& ModelWorldState() const { return myModelWorldState; }
264 //! Updates state of OCCT model-world transform.
265 Standard_EXPORT void UpdateModelWorldStateTo (const OpenGl_Mat4& theModelWorldMatrix);
267 //! Pushes current state of OCCT model-world transform to specified program.
268 Standard_EXPORT void PushModelWorldState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
272 //! Returns current state of OCCT world-view transform.
273 const OpenGl_WorldViewState& WorldViewState() const { return myWorldViewState; }
275 //! Updates state of OCCT world-view transform.
276 Standard_EXPORT void UpdateWorldViewStateTo (const OpenGl_Mat4& theWorldViewMatrix);
278 //! Pushes current state of OCCT world-view transform to specified program.
279 Standard_EXPORT void PushWorldViewState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
283 //! Updates state of OCCT clipping planes.
284 Standard_EXPORT void UpdateClippingState();
286 //! Reverts state of OCCT clipping planes.
287 Standard_EXPORT void RevertClippingState();
289 //! Pushes current state of OCCT clipping planes to specified program.
290 Standard_EXPORT void PushClippingState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
294 //! Returns current state of material.
295 const OpenGl_MaterialState& MaterialState() const { return myMaterialState; }
297 //! Updates state of material.
298 void UpdateMaterialStateTo (const OpenGl_Material& theFrontMat,
299 const OpenGl_Material& theBackMat,
300 const float theAlphaCutoff,
301 const bool theToDistinguish,
302 const bool theToMapTexture)
304 myMaterialState.Set (theFrontMat, theBackMat, theAlphaCutoff, theToDistinguish, theToMapTexture);
305 myMaterialState.Update();
308 //! Updates state of material.
309 void UpdateMaterialState()
311 myMaterialState.Update();
314 //! Pushes current state of material to specified program.
315 void PushMaterialState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
319 //! Setup interior style line edges variables.
320 Standard_EXPORT void PushInteriorState (const Handle(OpenGl_ShaderProgram)& theProgram,
321 const Handle(Graphic3d_AspectFillArea3d)& theAspect) const;
325 //! Returns state of OIT uniforms.
326 const OpenGl_OitState& OitState() const { return myOitState; }
328 //! Set the state of OIT rendering pass.
329 //! @param theToEnableOitWrite [in] flag indicating whether the special output should be written for OIT algorithm.
330 //! @param theDepthFactor [in] the scalar factor of depth influence to the fragment's coverage.
331 void SetOitState (const bool theToEnableOitWrite, const float theDepthFactor)
333 myOitState.Set (theToEnableOitWrite, theDepthFactor);
337 //! Pushes state of OIT uniforms to the specified program.
338 Standard_EXPORT void PushOitState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
342 //! Pushes current state of OCCT graphics parameters to specified program.
343 Standard_EXPORT void PushState (const Handle(OpenGl_ShaderProgram)& theProgram) const;
347 //! Overwrites context
348 void SetContext (OpenGl_Context* theCtx)
353 //! Returns true when provided context is the same as used one by shader manager.
354 bool IsSameContext (OpenGl_Context* theCtx) const
356 return myContext == theCtx;
359 //! Choose Shading Model for filled primitives.
360 //! Fallbacks to FACET model if there are no normal attributes.
361 Graphic3d_TypeOfShadingModel ChooseFaceShadingModel (Graphic3d_TypeOfShadingModel theCustomModel,
362 bool theHasNodalNormals) const
364 if (!myContext->ColorMask())
366 return Graphic3d_TOSM_UNLIT;
368 Graphic3d_TypeOfShadingModel aModel = theCustomModel != Graphic3d_TOSM_DEFAULT ? theCustomModel : myShadingModel;
371 case Graphic3d_TOSM_DEFAULT:
372 case Graphic3d_TOSM_UNLIT:
373 case Graphic3d_TOSM_FACET:
375 case Graphic3d_TOSM_VERTEX:
376 case Graphic3d_TOSM_FRAGMENT:
377 return theHasNodalNormals ? aModel : Graphic3d_TOSM_FACET;
379 return Graphic3d_TOSM_UNLIT;
382 //! Choose Shading Model for line primitives.
383 //! Fallbacks to UNLIT model if there are no normal attributes.
384 Graphic3d_TypeOfShadingModel ChooseLineShadingModel (Graphic3d_TypeOfShadingModel theCustomModel,
385 bool theHasNodalNormals) const
387 if (!myContext->ColorMask())
389 return Graphic3d_TOSM_UNLIT;
391 Graphic3d_TypeOfShadingModel aModel = theCustomModel != Graphic3d_TOSM_DEFAULT ? theCustomModel : myShadingModel;
394 case Graphic3d_TOSM_DEFAULT:
395 case Graphic3d_TOSM_UNLIT:
396 case Graphic3d_TOSM_FACET:
397 return Graphic3d_TOSM_UNLIT;
398 case Graphic3d_TOSM_VERTEX:
399 case Graphic3d_TOSM_FRAGMENT:
400 return theHasNodalNormals ? aModel : Graphic3d_TOSM_UNLIT;
402 return Graphic3d_TOSM_UNLIT;
405 //! Choose Shading Model for Marker primitives.
406 Graphic3d_TypeOfShadingModel ChooseMarkerShadingModel (Graphic3d_TypeOfShadingModel theCustomModel,
407 bool theHasNodalNormals) const
409 return ChooseLineShadingModel (theCustomModel, theHasNodalNormals);
412 //! Returns default Shading Model.
413 Graphic3d_TypeOfShadingModel ShadingModel() const { return myShadingModel; }
415 //! Sets shading model.
416 Standard_EXPORT void SetShadingModel (const Graphic3d_TypeOfShadingModel theModel);
418 //! Sets last view manger used with.
419 //! Helps to handle matrix states in multi-view configurations.
420 void SetLastView (const OpenGl_View* theLastView)
422 myLastView = theLastView;
425 //! Returns true when provided view is the same as cached one.
426 bool IsSameView (const OpenGl_View* theView) const
428 return myLastView == theView;
433 //! Define clipping planes program bits.
434 Standard_Integer getClipPlaneBits() const
436 const Standard_Integer aNbPlanes = myContext->Clipping().NbClippingOrCappingOn();
442 Standard_Integer aBits = 0;
443 if (myContext->Clipping().HasClippingChains())
445 aBits |= OpenGl_PO_ClipChains;
450 aBits |= OpenGl_PO_ClipPlanes1;
452 else if (aNbPlanes == 2)
454 aBits |= OpenGl_PO_ClipPlanes2;
458 aBits |= OpenGl_PO_ClipPlanesN;
463 //! Define program bits.
464 Standard_Integer getProgramBits (const Handle(OpenGl_TextureSet)& theTextures,
465 Graphic3d_AlphaMode theAlphaMode,
466 Aspect_InteriorStyle theInteriorStyle,
467 Standard_Boolean theHasVertColor,
468 Standard_Boolean theEnableEnvMap,
469 Standard_Boolean theEnableMeshEdges) const
471 Standard_Integer aBits = 0;
472 if (theAlphaMode == Graphic3d_AlphaMode_Mask)
474 aBits |= OpenGl_PO_AlphaTest;
477 aBits |= getClipPlaneBits();
478 if (theEnableMeshEdges
479 && myContext->hasGeometryStage != OpenGl_FeatureNotAvailable)
481 aBits |= OpenGl_PO_MeshEdges;
482 if (theInteriorStyle == Aspect_IS_HOLLOW)
484 aBits |= OpenGl_PO_AlphaTest;
490 // Environment map overwrites material texture
491 aBits |= OpenGl_PO_TextureEnv;
493 else if (!theTextures.IsNull()
494 && !theTextures->IsEmpty()
495 && !theTextures->First().IsNull())
497 aBits |= theTextures->First()->IsAlpha() ? OpenGl_PO_TextureA : OpenGl_PO_TextureRGB;
500 && theInteriorStyle != Aspect_IS_HIDDENLINE)
502 aBits |= OpenGl_PO_VertColor;
505 if (myOitState.ToEnableWrite())
507 aBits |= OpenGl_PO_WriteOit;
512 //! Prepare standard GLSL program.
513 Handle(OpenGl_ShaderProgram)& getStdProgram (Graphic3d_TypeOfShadingModel theShadingModel,
514 Standard_Integer theBits)
516 if (theShadingModel == Graphic3d_TOSM_UNLIT
517 || (theBits & OpenGl_PO_TextureEnv) != 0)
519 // If environment map is enabled lighting calculations are
520 // not needed (in accordance with default OCCT behavior)
521 Handle(OpenGl_ShaderProgram)& aProgram = myUnlitPrograms->ChangeValue (Graphic3d_TOSM_UNLIT, theBits);
522 if (aProgram.IsNull())
524 prepareStdProgramUnlit (aProgram, theBits);
529 Handle(OpenGl_ShaderProgram)& aProgram = myLightPrograms->ChangeValue (theShadingModel, theBits);
530 if (aProgram.IsNull())
532 prepareStdProgramLight (aProgram, theShadingModel, theBits);
537 //! Prepare standard GLSL program for accessing point sprite alpha.
538 Standard_EXPORT TCollection_AsciiString pointSpriteAlphaSrc (const Standard_Integer theBits);
540 //! Prepare standard GLSL program for computing point sprite shading.
541 Standard_EXPORT TCollection_AsciiString pointSpriteShadingSrc (const TCollection_AsciiString theBaseColorSrc, const Standard_Integer theBits);
543 //! Prepare standard GLSL program for textured font.
544 Standard_EXPORT Standard_Boolean prepareStdProgramFont();
546 //! Prepare standard GLSL program for FBO blit operation.
547 Standard_EXPORT Standard_Boolean prepareStdProgramFboBlit();
549 //! Prepare standard GLSL programs for OIT compositing operation.
550 Standard_EXPORT Standard_Boolean prepareStdProgramOitCompositing (const Standard_Boolean theMsaa);
552 //! Prepare standard GLSL program without lighting.
553 Standard_EXPORT Standard_Boolean prepareStdProgramUnlit (Handle(OpenGl_ShaderProgram)& theProgram,
554 const Standard_Integer theBits);
556 //! Prepare standard GLSL program with lighting.
557 Standard_Boolean prepareStdProgramLight (Handle(OpenGl_ShaderProgram)& theProgram,
558 Graphic3d_TypeOfShadingModel theShadingModel,
559 Standard_Integer theBits)
561 switch (theShadingModel)
563 case Graphic3d_TOSM_UNLIT: return prepareStdProgramUnlit (theProgram, theBits);
564 case Graphic3d_TOSM_FACET: return prepareStdProgramPhong (theProgram, theBits, true);
565 case Graphic3d_TOSM_VERTEX: return prepareStdProgramGouraud(theProgram, theBits);
566 case Graphic3d_TOSM_DEFAULT:
567 case Graphic3d_TOSM_FRAGMENT: return prepareStdProgramPhong (theProgram, theBits, false);
572 //! Prepare standard GLSL program with per-vertex lighting.
573 Standard_EXPORT Standard_Boolean prepareStdProgramGouraud (Handle(OpenGl_ShaderProgram)& theProgram,
574 const Standard_Integer theBits);
576 //! Prepare standard GLSL program with per-pixel lighting.
577 //! @param theIsFlatNormal when TRUE, the Vertex normals will be ignored and Face normal will be computed instead
578 Standard_EXPORT Standard_Boolean prepareStdProgramPhong (Handle(OpenGl_ShaderProgram)& theProgram,
579 const Standard_Integer theBits,
580 const Standard_Boolean theIsFlatNormal = false);
582 //! Define computeLighting GLSL function depending on current lights configuration
583 //! @param theNbLights [out] number of defined light sources
584 //! @param theHasVertColor [in] flag to use getVertColor() instead of Ambient and Diffuse components of active material
585 Standard_EXPORT TCollection_AsciiString stdComputeLighting (Standard_Integer& theNbLights,
586 Standard_Boolean theHasVertColor);
588 //! Bind specified program to current context and apply state.
589 Standard_EXPORT Standard_Boolean bindProgramWithState (const Handle(OpenGl_ShaderProgram)& theProgram);
591 //! Set pointer myLightPrograms to active lighting programs set from myMapOfLightPrograms
592 Standard_EXPORT void switchLightPrograms();
594 //! Prepare standard GLSL program for stereoscopic image.
595 Standard_EXPORT Standard_Boolean prepareStdProgramStereo (Handle(OpenGl_ShaderProgram)& theProgram,
596 const Graphic3d_StereoMode theStereoMode);
598 //! Prepare standard GLSL program for bounding box.
599 Standard_EXPORT Standard_Boolean prepareStdProgramBoundBox();
601 //! Prepare GLSL version header.
602 Standard_EXPORT Standard_Integer defaultGlslVersion (const Handle(Graphic3d_ShaderProgram)& theProgram,
603 Standard_Integer theBits,
604 bool theUsesDerivates = false) const;
606 //! Prepare GLSL source for geometry shader according to parameters.
607 Standard_EXPORT TCollection_AsciiString prepareGeomMainSrc (OpenGl_ShaderObject::ShaderVariableList& theUnifoms,
608 OpenGl_ShaderObject::ShaderVariableList& theStageInOuts,
609 Standard_Integer theBits);
613 //! Packed properties of light source
614 struct OpenGl_ShaderLightParameters
617 OpenGl_Vec4 Position;
618 OpenGl_Vec4 Direction;
619 OpenGl_Vec4 Parameters;
621 //! Returns packed (serialized) representation of light source properties
622 const OpenGl_Vec4* Packed() const { return reinterpret_cast<const OpenGl_Vec4*> (this); }
623 static Standard_Integer NbOfVec4() { return 4; }
626 //! Packed light source type information
627 struct OpenGl_ShaderLightType
629 Standard_Integer Type;
630 Standard_Integer IsHeadlight;
632 //! Returns packed (serialized) representation of light source type
633 const OpenGl_Vec2i* Packed() const { return reinterpret_cast<const OpenGl_Vec2i*> (this); }
634 static Standard_Integer NbOfVec2i() { return 1; }
637 //! Fake OpenGL program for tracking FFP state in the way consistent to programmable pipeline.
638 class OpenGl_ShaderProgramFFP : public OpenGl_ShaderProgram
640 DEFINE_STANDARD_RTTI_INLINE(OpenGl_ShaderProgramFFP, OpenGl_ShaderProgram)
641 friend class OpenGl_ShaderManager;
643 OpenGl_ShaderProgramFFP() {}
648 //! Append clipping plane definition to temporary buffers.
649 void addClippingPlane (Standard_Integer& thePlaneId,
650 const Graphic3d_ClipPlane& thePlane,
651 const Graphic3d_Vec4d& theEq,
652 const Standard_Integer theChainFwd) const
654 myClipChainArray.SetValue (thePlaneId, theChainFwd);
655 OpenGl_Vec4& aPlaneEq = myClipPlaneArray.ChangeValue (thePlaneId);
656 aPlaneEq.x() = float(theEq.x());
657 aPlaneEq.y() = float(theEq.y());
658 aPlaneEq.z() = float(theEq.z());
659 aPlaneEq.w() = float(theEq.w());
660 if (myHasLocalOrigin)
662 const gp_XYZ aPos = thePlane.ToPlane().Position().Location().XYZ() - myLocalOrigin;
663 const Standard_Real aD = -(theEq.x() * aPos.X() + theEq.y() * aPos.Y() + theEq.z() * aPos.Z());
664 aPlaneEq.w() = float(aD);
671 Handle(OpenGl_ShaderProgramFFP) myFfpProgram;
673 Graphic3d_TypeOfShadingModel myShadingModel; //!< lighting shading model
674 OpenGl_ShaderProgramList myProgramList; //!< The list of shader programs
675 Handle(OpenGl_SetOfShaderPrograms) myLightPrograms; //!< pointer to active lighting programs matrix
676 Handle(OpenGl_SetOfShaderPrograms) myUnlitPrograms; //!< programs matrix without lighting
677 Handle(OpenGl_ShaderProgram) myFontProgram; //!< standard program for textured text
678 Handle(OpenGl_ShaderProgram) myBlitProgram; //!< standard program for FBO blit emulation
679 Handle(OpenGl_ShaderProgram) myBoundBoxProgram; //!< standard program for bounding box
680 Handle(OpenGl_ShaderProgram) myOitCompositingProgram[2]; //!< standard program for OIT compositing (default and MSAA).
681 OpenGl_MapOfShaderPrograms myMapOfLightPrograms; //!< map of lighting programs depending on lights configuration
683 Handle(OpenGl_ShaderProgram) myStereoPrograms[Graphic3d_StereoMode_NB]; //!< standard stereo programs
685 Handle(OpenGl_VertexBuffer) myBoundBoxVertBuffer; //!< bounding box vertex buffer
687 OpenGl_Context* myContext; //!< OpenGL context
691 OpenGl_ProjectionState myProjectionState; //!< State of OCCT projection transformation
692 OpenGl_ModelWorldState myModelWorldState; //!< State of OCCT model-world transformation
693 OpenGl_WorldViewState myWorldViewState; //!< State of OCCT world-view transformation
694 OpenGl_ClippingState myClippingState; //!< State of OCCT clipping planes
695 OpenGl_LightSourceState myLightSourceState; //!< State of OCCT light sources
696 OpenGl_MaterialState myMaterialState; //!< State of Front and Back materials
697 OpenGl_OitState myOitState; //!< State of OIT uniforms
699 gp_XYZ myLocalOrigin; //!< local camera transformation
700 Standard_Boolean myHasLocalOrigin; //!< flag indicating that local camera transformation has been set
702 mutable NCollection_Array1<OpenGl_ShaderLightType> myLightTypeArray;
703 mutable NCollection_Array1<OpenGl_ShaderLightParameters> myLightParamsArray;
704 mutable NCollection_Array1<OpenGl_Vec4> myClipPlaneArray;
705 mutable NCollection_Array1<OpenGl_Vec4d> myClipPlaneArrayFfp;
706 mutable NCollection_Array1<Standard_Integer> myClipChainArray;
710 const OpenGl_View* myLastView; //!< Pointer to the last view shader manager used with
714 DEFINE_STANDARD_HANDLE(OpenGl_ShaderManager, Standard_Transient)
716 #endif // _OpenGl_ShaderManager_HeaderFile