Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:35

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 
0031   //! Creates new state.
0032   Standard_EXPORT OpenGl_StateInterface();
0033 
0034   //! Returns current state index.
0035   Standard_Size Index() const { return myIndex; }
0036 
0037   //! Increment current state.
0038   void Update() { ++myIndex; }
0039 
0040 protected:
0041 
0042   Standard_Size myIndex; //!< current state index
0043 
0044 };
0045 
0046 //! Defines state of OCCT projection transformation.
0047 class OpenGl_ProjectionState : public OpenGl_StateInterface
0048 {
0049 public:
0050 
0051   //! Creates uninitialized projection state.
0052   Standard_EXPORT OpenGl_ProjectionState();
0053 
0054   //! Sets new projection matrix.
0055   Standard_EXPORT void Set (const OpenGl_Mat4& theProjectionMatrix);
0056 
0057   //! Returns current projection matrix.
0058   const OpenGl_Mat4& ProjectionMatrix() const { return myProjectionMatrix; }
0059 
0060   //! Returns inverse of current projection matrix.
0061   Standard_EXPORT const OpenGl_Mat4& ProjectionMatrixInverse() const;
0062 
0063 private:
0064 
0065   OpenGl_Mat4         myProjectionMatrix;        //!< OCCT projection matrix
0066   mutable OpenGl_Mat4 myProjectionMatrixInverse; //!< Inverse of OCCT projection matrix
0067   mutable bool        myInverseNeedUpdate;       //!< Is inversed matrix outdated?
0068 
0069 };
0070 
0071 //! Defines state of OCCT model-world transformation.
0072 class OpenGl_ModelWorldState : public OpenGl_StateInterface
0073 {
0074 public:
0075 
0076   //! Creates uninitialized model-world state.
0077   Standard_EXPORT OpenGl_ModelWorldState();
0078 
0079   //! Sets new model-world matrix.
0080   Standard_EXPORT void Set (const OpenGl_Mat4& theModelWorldMatrix);
0081 
0082   //! Returns current model-world matrix.
0083   const OpenGl_Mat4& ModelWorldMatrix() const { return myModelWorldMatrix; }
0084 
0085   //! Returns inverse of current model-world matrix.
0086   Standard_EXPORT const OpenGl_Mat4& ModelWorldMatrixInverse() const;
0087 
0088 private:
0089 
0090   OpenGl_Mat4         myModelWorldMatrix;        //!< OCCT model-world matrix
0091   mutable OpenGl_Mat4 myModelWorldMatrixInverse; //!< Inverse of OCCT model-world matrix
0092   mutable bool        myInverseNeedUpdate;       //!< Is inversed matrix outdated?
0093   
0094 };
0095 
0096 //! Defines state of OCCT world-view transformation.
0097 class OpenGl_WorldViewState : public OpenGl_StateInterface
0098 {
0099 public:
0100 
0101   //! Creates uninitialized world-view state.
0102   Standard_EXPORT OpenGl_WorldViewState();
0103 
0104   //! Sets new world-view matrix.
0105   Standard_EXPORT void Set (const OpenGl_Mat4& theWorldViewMatrix);
0106 
0107   //! Returns current world-view matrix.
0108   const OpenGl_Mat4& WorldViewMatrix() const { return myWorldViewMatrix; }
0109 
0110   //! Returns inverse of current world-view matrix.
0111   Standard_EXPORT const OpenGl_Mat4& WorldViewMatrixInverse() const;
0112 
0113 private:
0114 
0115   OpenGl_Mat4         myWorldViewMatrix;        //!< OCCT world-view matrix
0116   mutable OpenGl_Mat4 myWorldViewMatrixInverse; //!< Inverse of OCCT world-view matrix
0117   mutable bool        myInverseNeedUpdate;      //!< Is inversed matrix outdated?
0118 
0119 };
0120 
0121 //! Defines state of OCCT light sources.
0122 class OpenGl_LightSourceState : public OpenGl_StateInterface
0123 {
0124 public:
0125 
0126   //! Creates uninitialized state of light sources.
0127   OpenGl_LightSourceState() : mySpecIBLMapLevels (0), myToCastShadows (Standard_True) {}
0128 
0129   //! Sets new light sources.
0130   void Set (const Handle(Graphic3d_LightSet)& theLightSources) { myLightSources = theLightSources; }
0131 
0132   //! Returns current list of light sources.
0133   const Handle(Graphic3d_LightSet)& LightSources() const { return myLightSources; }
0134 
0135   //! Returns number of mipmap levels used in specular IBL map.
0136   //! 0 by default or in case of using non-PBR shading model.
0137   Standard_Integer SpecIBLMapLevels() const { return mySpecIBLMapLevels; }
0138 
0139   //! Sets number of mipmap levels used in specular IBL map.
0140   void SetSpecIBLMapLevels(Standard_Integer theSpecIBLMapLevels) { mySpecIBLMapLevels = theSpecIBLMapLevels; }
0141 
0142   //! Returns TRUE if shadowmap is set.
0143   bool HasShadowMaps() const { return myToCastShadows && !myShadowMaps.IsNull(); }
0144 
0145   //! Returns shadowmap.
0146   const Handle(OpenGl_ShadowMapArray)& ShadowMaps() const { return myShadowMaps; }
0147 
0148   //! Sets shadowmap.
0149   void SetShadowMaps (const Handle(OpenGl_ShadowMapArray)& theMap) { myShadowMaps = theMap; }
0150 
0151   //! Returns TRUE if shadowmap should be enabled when available; TRUE by default.
0152   bool ToCastShadows() const { return myToCastShadows; }
0153 
0154   //! Set if shadowmap should be enabled when available.
0155   void SetCastShadows (bool theToCast) { myToCastShadows = theToCast; }
0156 
0157 private:
0158 
0159   Handle(Graphic3d_LightSet) myLightSources;     //!< List of OCCT light sources
0160   Standard_Integer           mySpecIBLMapLevels; //!< Number of mipmap levels used in specular IBL map (0 by default or in case of using non-PBR shading model)
0161   Handle(OpenGl_ShadowMapArray) myShadowMaps;    //!< active shadowmap
0162   Standard_Boolean           myToCastShadows;    //!< enable/disable shadowmap
0163 
0164 };
0165 
0166 //! Defines generic state of OCCT clipping state.
0167 class OpenGl_ClippingState
0168 {
0169 public:
0170 
0171   //! Creates new clipping state.
0172   Standard_EXPORT OpenGl_ClippingState();
0173 
0174   //! Returns current state index.
0175   Standard_Size Index() const { return myIndex; }
0176 
0177   //! Updates current state.
0178   Standard_EXPORT void Update();
0179 
0180   //! Reverts current state.
0181   Standard_EXPORT void Revert();
0182 
0183 protected:
0184 
0185   Standard_Size                   myIndex;      //!< Current state index
0186   Standard_Size                   myNextIndex;  //!< Next    state index
0187   NCollection_List<Standard_Size> myStateStack; //!< Stack of previous states
0188 
0189 };
0190 
0191 //! Defines generic state of order-independent transparency rendering properties.
0192 class OpenGl_OitState : public OpenGl_StateInterface
0193 {
0194 public:
0195 
0196   //! Creates new uniform state.
0197   OpenGl_OitState() : myOitMode (Graphic3d_RTM_BLEND_UNORDERED), myDepthFactor (0.5f) {}
0198 
0199   //! Sets the uniform values.
0200   //! @param theToEnableWrite [in] flag indicating whether color and coverage
0201   //!  values for OIT processing should be written by shader program.
0202   //! @param theDepthFactor [in] scalar factor [0-1] defining influence of depth
0203   //!  component of a fragment to its final coverage coefficient.
0204   void Set (Graphic3d_RenderTransparentMethod theMode,
0205             const float theDepthFactor)
0206   {
0207     myOitMode = theMode;
0208     myDepthFactor = static_cast<float> (Max (0.f, Min (1.f, theDepthFactor)));
0209   }
0210 
0211   //! Returns flag indicating whether writing of output for OIT processing
0212   //! should be enabled/disabled.
0213   Graphic3d_RenderTransparentMethod ActiveMode() const { return myOitMode; }
0214 
0215   //! Returns factor defining influence of depth component of a fragment
0216   //! to its final coverage coefficient.
0217   float DepthFactor() const { return myDepthFactor; }
0218 
0219 private:
0220 
0221   Graphic3d_RenderTransparentMethod myOitMode;     //!< active OIT method for the main GLSL program
0222   float                             myDepthFactor; //!< factor of depth influence to coverage
0223 };
0224 
0225 #endif // _OpenGl_State_HeaderFile