Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-15 09:16:46

0001 // Created on: 2013-10-02
0002 // Created by: Denis BOGOLEPOV
0003 // Copyright (c) 2013-2014 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef OpenGl_ShaderStates_HeaderFile
0017 #define OpenGl_ShaderStates_HeaderFile
0018 
0019 #include <Graphic3d_RenderTransparentMethod.hxx>
0020 #include <Graphic3d_LightSet.hxx>
0021 #include <OpenGl_Element.hxx>
0022 #include <OpenGl_Vec.hxx>
0023 
0024 class OpenGl_ShadowMapArray;
0025 
0026 //! Defines interface for OpenGL state.
0027 class OpenGl_StateInterface
0028 {
0029 public:
0030   //! Creates new state.
0031   Standard_EXPORT OpenGl_StateInterface();
0032 
0033   //! Returns current state index.
0034   size_t Index() const { return myIndex; }
0035 
0036   //! Increment current state.
0037   void Update() { ++myIndex; }
0038 
0039 protected:
0040   size_t myIndex; //!< current state index
0041 };
0042 
0043 //! Defines state of OCCT projection transformation.
0044 class OpenGl_ProjectionState : public OpenGl_StateInterface
0045 {
0046 public:
0047   //! Creates uninitialized projection state.
0048   Standard_EXPORT OpenGl_ProjectionState();
0049 
0050   //! Sets new projection matrix.
0051   Standard_EXPORT void Set(const NCollection_Mat4<float>& theProjectionMatrix);
0052 
0053   //! Returns current projection matrix.
0054   const NCollection_Mat4<float>& ProjectionMatrix() const { return myProjectionMatrix; }
0055 
0056   //! Returns inverse of current projection matrix.
0057   Standard_EXPORT const NCollection_Mat4<float>& ProjectionMatrixInverse() const;
0058 
0059 private:
0060   NCollection_Mat4<float>         myProjectionMatrix;        //!< OCCT projection matrix
0061   mutable NCollection_Mat4<float> myProjectionMatrixInverse; //!< Inverse of OCCT projection matrix
0062   mutable bool                    myInverseNeedUpdate;       //!< Is inversed matrix outdated?
0063 };
0064 
0065 //! Defines state of OCCT model-world transformation.
0066 class OpenGl_ModelWorldState : public OpenGl_StateInterface
0067 {
0068 public:
0069   //! Creates uninitialized model-world state.
0070   Standard_EXPORT OpenGl_ModelWorldState();
0071 
0072   //! Sets new model-world matrix.
0073   Standard_EXPORT void Set(const NCollection_Mat4<float>& theModelWorldMatrix);
0074 
0075   //! Returns current model-world matrix.
0076   const NCollection_Mat4<float>& ModelWorldMatrix() const { return myModelWorldMatrix; }
0077 
0078   //! Returns inverse of current model-world matrix.
0079   Standard_EXPORT const NCollection_Mat4<float>& ModelWorldMatrixInverse() const;
0080 
0081 private:
0082   NCollection_Mat4<float>         myModelWorldMatrix;        //!< OCCT model-world matrix
0083   mutable NCollection_Mat4<float> myModelWorldMatrixInverse; //!< Inverse of OCCT model-world matrix
0084   mutable bool                    myInverseNeedUpdate;       //!< Is inversed matrix outdated?
0085 };
0086 
0087 //! Defines state of OCCT world-view transformation.
0088 class OpenGl_WorldViewState : public OpenGl_StateInterface
0089 {
0090 public:
0091   //! Creates uninitialized world-view state.
0092   Standard_EXPORT OpenGl_WorldViewState();
0093 
0094   //! Sets new world-view matrix.
0095   Standard_EXPORT void Set(const NCollection_Mat4<float>& theWorldViewMatrix);
0096 
0097   //! Returns current world-view matrix.
0098   const NCollection_Mat4<float>& WorldViewMatrix() const { return myWorldViewMatrix; }
0099 
0100   //! Returns inverse of current world-view matrix.
0101   Standard_EXPORT const NCollection_Mat4<float>& WorldViewMatrixInverse() const;
0102 
0103 private:
0104   NCollection_Mat4<float>         myWorldViewMatrix;        //!< OCCT world-view matrix
0105   mutable NCollection_Mat4<float> myWorldViewMatrixInverse; //!< Inverse of OCCT world-view matrix
0106   mutable bool                    myInverseNeedUpdate;      //!< Is inversed matrix outdated?
0107 };
0108 
0109 //! Defines state of OCCT light sources.
0110 class OpenGl_LightSourceState : public OpenGl_StateInterface
0111 {
0112 public:
0113   //! Creates uninitialized state of light sources.
0114   OpenGl_LightSourceState()
0115       : mySpecIBLMapLevels(0),
0116         myToCastShadows(true)
0117   {
0118   }
0119 
0120   //! Sets new light sources.
0121   void Set(const occ::handle<Graphic3d_LightSet>& theLightSources)
0122   {
0123     myLightSources = theLightSources;
0124   }
0125 
0126   //! Returns current list of light sources.
0127   const occ::handle<Graphic3d_LightSet>& LightSources() const { return myLightSources; }
0128 
0129   //! Returns number of mipmap levels used in specular IBL map.
0130   //! 0 by default or in case of using non-PBR shading model.
0131   int SpecIBLMapLevels() const { return mySpecIBLMapLevels; }
0132 
0133   //! Sets number of mipmap levels used in specular IBL map.
0134   void SetSpecIBLMapLevels(int theSpecIBLMapLevels) { mySpecIBLMapLevels = theSpecIBLMapLevels; }
0135 
0136   //! Returns TRUE if shadowmap is set.
0137   bool HasShadowMaps() const { return myToCastShadows && !myShadowMaps.IsNull(); }
0138 
0139   //! Returns shadowmap.
0140   const occ::handle<OpenGl_ShadowMapArray>& ShadowMaps() const { return myShadowMaps; }
0141 
0142   //! Sets shadowmap.
0143   void SetShadowMaps(const occ::handle<OpenGl_ShadowMapArray>& theMap) { myShadowMaps = theMap; }
0144 
0145   //! Returns TRUE if shadowmap should be enabled when available; TRUE by default.
0146   bool ToCastShadows() const { return myToCastShadows; }
0147 
0148   //! Set if shadowmap should be enabled when available.
0149   void SetCastShadows(bool theToCast) { myToCastShadows = theToCast; }
0150 
0151 private:
0152   occ::handle<Graphic3d_LightSet> myLightSources;     //!< List of OCCT light sources
0153                                                       // clang-format off
0154   int           mySpecIBLMapLevels; //!< Number of mipmap levels used in specular IBL map (0 by default or in case of using non-PBR shading model)
0155                                                       // clang-format on
0156   occ::handle<OpenGl_ShadowMapArray> myShadowMaps;    //!< active shadowmap
0157   bool                               myToCastShadows; //!< enable/disable shadowmap
0158 };
0159 
0160 //! Defines generic state of OCCT clipping state.
0161 class OpenGl_ClippingState
0162 {
0163 public:
0164   //! Creates new clipping state.
0165   Standard_EXPORT OpenGl_ClippingState();
0166 
0167   //! Returns current state index.
0168   size_t Index() const { return myIndex; }
0169 
0170   //! Updates current state.
0171   Standard_EXPORT void Update();
0172 
0173   //! Reverts current state.
0174   Standard_EXPORT void Revert();
0175 
0176 protected:
0177   size_t                   myIndex;      //!< Current state index
0178   size_t                   myNextIndex;  //!< Next    state index
0179   NCollection_List<size_t> myStateStack; //!< Stack of previous states
0180 };
0181 
0182 //! Defines generic state of order-independent transparency rendering properties.
0183 class OpenGl_OitState : public OpenGl_StateInterface
0184 {
0185 public:
0186   //! Creates new uniform state.
0187   OpenGl_OitState()
0188       : myOitMode(Graphic3d_RTM_BLEND_UNORDERED),
0189         myDepthFactor(0.5f)
0190   {
0191   }
0192 
0193   //! Sets the uniform values.
0194   //! @param[in] theToEnableWrite  flag indicating whether color and coverage
0195   //!  values for OIT processing should be written by shader program.
0196   //! @param[in] theDepthFactor  scalar factor [0-1] defining influence of depth
0197   //!  component of a fragment to its final coverage coefficient.
0198   void Set(Graphic3d_RenderTransparentMethod theMode, const float theDepthFactor)
0199   {
0200     myOitMode     = theMode;
0201     myDepthFactor = static_cast<float>((std::max)(0.f, (std::min)(1.f, theDepthFactor)));
0202   }
0203 
0204   //! Returns flag indicating whether writing of output for OIT processing
0205   //! should be enabled/disabled.
0206   Graphic3d_RenderTransparentMethod ActiveMode() const { return myOitMode; }
0207 
0208   //! Returns factor defining influence of depth component of a fragment
0209   //! to its final coverage coefficient.
0210   float DepthFactor() const { return myDepthFactor; }
0211 
0212 private:
0213   // clang-format off
0214   Graphic3d_RenderTransparentMethod myOitMode;     //!< active OIT method for the main GLSL program
0215   // clang-format on
0216   float myDepthFactor; //!< factor of depth influence to coverage
0217 };
0218 
0219 #endif // _OpenGl_State_HeaderFile