Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-10 09:17:47

0001 // Copyright (c) 2021 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _OpenGl_ShadowMap_HeaderFile
0015 #define _OpenGl_ShadowMap_HeaderFile
0016 
0017 #include <Graphic3d_Mat4.hxx>
0018 #include <NCollection_Array1.hxx>
0019 #include <OpenGl_NamedResource.hxx>
0020 
0021 class gp_XYZ;
0022 class Graphic3d_Camera;
0023 class Graphic3d_CLight;
0024 class Graphic3d_CView;
0025 class OpenGl_FrameBuffer;
0026 class OpenGl_Texture;
0027 
0028 //! This class contains shadow mapping resources.
0029 class OpenGl_ShadowMap : public OpenGl_NamedResource
0030 {
0031   DEFINE_STANDARD_RTTIEXT(OpenGl_ShadowMap, OpenGl_NamedResource)
0032 public:
0033   //! Empty constructor.
0034   OpenGl_ShadowMap();
0035 
0036   //! Releases all OpenGL resources.
0037   Standard_EXPORT virtual void Release(OpenGl_Context* theCtx) Standard_OVERRIDE;
0038 
0039   //! Returns estimated GPU memory usage for holding data without considering overheads and
0040   //! allocation alignment rules.
0041   Standard_EXPORT virtual Standard_Size EstimatedDataSize() const Standard_OVERRIDE;
0042 
0043   //! Destructor.
0044   Standard_EXPORT virtual ~OpenGl_ShadowMap();
0045 
0046   //! Return TRUE if defined.
0047   Standard_EXPORT bool IsValid() const;
0048 
0049   //! Return framebuffer.
0050   const Handle(OpenGl_FrameBuffer)& FrameBuffer() const { return myShadowMapFbo; }
0051 
0052   //! Return depth texture.
0053   Standard_EXPORT const Handle(OpenGl_Texture)& Texture() const;
0054 
0055   //! Return light source casting the shadow or NULL if undefined.
0056   const Handle(Graphic3d_CLight)& LightSource() const { return myShadowLight; }
0057 
0058   //! Set light source casting the shadow.
0059   void SetLightSource(const Handle(Graphic3d_CLight)& theLight) { myShadowLight = theLight; }
0060 
0061   //! Return rendering camera.
0062   const Handle(Graphic3d_Camera)& Camera() const { return myShadowCamera; }
0063 
0064   //! Return light source mapping matrix.
0065   const Graphic3d_Mat4& LightSourceMatrix() const { return myLightMatrix; }
0066 
0067   //! Set light source mapping matrix.
0068   void SetLightSourceMatrix(const Graphic3d_Mat4& theMat) { myLightMatrix = theMat; }
0069 
0070   //! Returns shadowmap bias.
0071   Standard_ShortReal ShadowMapBias() const { return myShadowMapBias; }
0072 
0073   //! Sets shadowmap bias.
0074   void SetShadowMapBias(Standard_ShortReal theBias) { myShadowMapBias = theBias; }
0075 
0076   //! Compute camera.
0077   //! @param[in] theView    active view
0078   //! @param[in] theOrigin  when not-NULL - displace shadow map camera to specified Z-Layer origin
0079   Standard_EXPORT bool UpdateCamera(const Graphic3d_CView& theView, const gp_XYZ* theOrigin = NULL);
0080 
0081 private:
0082   Handle(OpenGl_FrameBuffer) myShadowMapFbo;  //!< frame buffer for rendering shadow map
0083   Handle(Graphic3d_CLight)   myShadowLight;   //!< light source to render shadow map
0084   Handle(Graphic3d_Camera)   myShadowCamera;  //!< rendering camera
0085   Graphic3d_Mat4             myLightMatrix;   //!< light source matrix
0086   Standard_ShortReal         myShadowMapBias; //!< shadowmap bias
0087 };
0088 
0089 //! Array of shadow maps.
0090 class OpenGl_ShadowMapArray : public Standard_Transient,
0091                               public NCollection_Array1<Handle(OpenGl_ShadowMap)>
0092 {
0093 public:
0094   //! Empty constructor.
0095   OpenGl_ShadowMapArray() {}
0096 
0097   //! Releases all OpenGL resources.
0098   Standard_EXPORT void Release(OpenGl_Context* theCtx);
0099 
0100   //! Return TRUE if defined.
0101   bool IsValid() const { return !IsEmpty() && First()->IsValid(); }
0102 
0103   //! Returns estimated GPU memory usage for holding data without considering overheads and
0104   //! allocation alignment rules.
0105   Standard_EXPORT Standard_Size EstimatedDataSize() const;
0106 
0107 public:
0108   DEFINE_STANDARD_ALLOC
0109   DEFINE_NCOLLECTION_ALLOC
0110 };
0111 
0112 #endif // _OpenGl_ShadowMap_HeaderFile