Back to home page

EIC code displayed by LXR

 
 

    


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

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 
0034   //! Empty constructor.
0035   OpenGl_ShadowMap();
0036 
0037   //! Releases all OpenGL resources.
0038   Standard_EXPORT virtual void Release (OpenGl_Context* theCtx) Standard_OVERRIDE;
0039 
0040   //! Returns estimated GPU memory usage for holding data without considering overheads and 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 theView   [in] active view
0078   //! @param theOrigin [in] when not-NULL - displace shadow map camera to specified Z-Layer origin
0079   Standard_EXPORT bool UpdateCamera (const Graphic3d_CView& theView,
0080                                      const gp_XYZ* theOrigin = NULL);
0081 
0082 private:
0083 
0084   Handle(OpenGl_FrameBuffer) myShadowMapFbo;  //!< frame buffer for rendering shadow map
0085   Handle(Graphic3d_CLight)   myShadowLight;   //!< light source to render shadow map
0086   Handle(Graphic3d_Camera)   myShadowCamera;  //!< rendering camera
0087   Graphic3d_Mat4             myLightMatrix;   //!< light source matrix
0088   Standard_ShortReal         myShadowMapBias; //!< shadowmap bias
0089 
0090 };
0091 
0092 //! Array of shadow maps.
0093 class OpenGl_ShadowMapArray : public Standard_Transient, public NCollection_Array1<Handle(OpenGl_ShadowMap)>
0094 {
0095 public:
0096   //! Empty constructor.
0097   OpenGl_ShadowMapArray() {}
0098 
0099   //! Releases all OpenGL resources.
0100   Standard_EXPORT void Release (OpenGl_Context* theCtx);
0101 
0102   //! Return TRUE if defined.
0103   bool IsValid() const
0104   {
0105     return !IsEmpty()
0106          && First()->IsValid();
0107   }
0108 
0109   //! Returns estimated GPU memory usage for holding data without considering overheads and allocation alignment rules.
0110   Standard_EXPORT Standard_Size EstimatedDataSize() const;
0111 
0112 public:
0113   DEFINE_STANDARD_ALLOC
0114   DEFINE_NCOLLECTION_ALLOC
0115 
0116 };
0117 
0118 #endif // _OpenGl_ShadowMap_HeaderFile