Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-19 09:28:07

0001 // Created on: 1997-07-28
0002 // Created by: Pierre CHALAMET
0003 // Copyright (c) 1997-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016 
0017 #ifndef _Graphic3d_TextureRoot_HeaderFile
0018 #define _Graphic3d_TextureRoot_HeaderFile
0019 
0020 #include <Image_PixMap.hxx>
0021 #include <OSD_Path.hxx>
0022 #include <Graphic3d_TypeOfTexture.hxx>
0023 #include <Standard.hxx>
0024 #include <Standard_Transient.hxx>
0025 #include <Standard_Type.hxx>
0026 #include <TCollection_AsciiString.hxx>
0027 
0028 class Image_CompressedPixMap;
0029 class Image_SupportedFormats;
0030 class Graphic3d_TextureParams;
0031 
0032 //! This is the texture root class enable the dialog with the GraphicDriver allows the loading of
0033 //! texture.
0034 class Graphic3d_TextureRoot : public Standard_Transient
0035 {
0036   DEFINE_STANDARD_RTTIEXT(Graphic3d_TextureRoot, Standard_Transient)
0037 public:
0038   //! The path to textures determined from CSF_MDTVTexturesDirectory or CASROOT environment
0039   //! variables.
0040   //! @return the root folder with default textures.
0041   Standard_EXPORT static TCollection_AsciiString TexturesFolder();
0042 
0043 public:
0044   //! Destructor.
0045   Standard_EXPORT ~Graphic3d_TextureRoot() override;
0046 
0047   //! Checks if a texture class is valid or not.
0048   //! @return true if the construction of the class is correct
0049   Standard_EXPORT virtual bool IsDone() const;
0050 
0051   //! Returns the full path of the defined texture.
0052   //! It could be empty path if GetImage() is overridden to load image not from file.
0053   const OSD_Path& Path() const { return myPath; }
0054 
0055   //! @return the texture type.
0056   Graphic3d_TypeOfTexture Type() const { return myType; }
0057 
0058   //! This ID will be used to manage resource in graphic driver.
0059   //!
0060   //! Default implementation generates unique ID within constructor;
0061   //! inheritors may re-initialize it within their constructor,
0062   //! but should never modify it afterwards.
0063   //!
0064   //! Multiple Graphic3d_TextureRoot instances with same ID
0065   //! will be treated as single texture with different parameters
0066   //! to optimize memory usage though this will be more natural
0067   //! to use same instance of Graphic3d_TextureRoot when possible.
0068   //!
0069   //! If this ID is set to empty string by inheritor,
0070   //! then independent graphical resource will be created
0071   //! for each instance of Graphic3d_AspectFillArea3d where texture will be used.
0072   //!
0073   //! @return texture identifier.
0074   const TCollection_AsciiString& GetId() const { return myTexId; }
0075 
0076   //! Return image revision.
0077   size_t Revision() const { return myRevision; }
0078 
0079   //! Update image revision.
0080   //! Can be used for signaling changes in the texture source (e.g. file update, pixmap update)
0081   //! without re-creating texture source itself (since unique id should be never modified).
0082   void UpdateRevision() { ++myRevision; }
0083 
0084   //! This method will be called by graphic driver each time when texture resource should be
0085   //! created. It is called in front of GetImage() for uploading compressed image formats natively
0086   //! supported by GPU.
0087   //! @param[in] theSupported  the list of supported compressed texture formats;
0088   //!                          returning image in unsupported format will result in texture upload
0089   //!                          failure
0090   //! @return compressed pixmap or NULL if image is not in supported compressed format
0091   Standard_EXPORT virtual occ::handle<Image_CompressedPixMap> GetCompressedImage(
0092     const occ::handle<Image_SupportedFormats>& theSupported);
0093 
0094   //! This method will be called by graphic driver each time when texture resource should be
0095   //! created. Default constructors allow defining the texture source as path to texture image or
0096   //! directly as pixmap. If the source is defined as path, then the image will be dynamically
0097   //! loaded when this method is called (and no copy will be preserved in this class instance).
0098   //! Inheritors may dynamically generate the image.
0099   //! Notice, image data should be in Bottom-Up order (see Image_PixMap::IsTopDown())!
0100   //! @return the image for texture.
0101   Standard_EXPORT virtual occ::handle<Image_PixMap> GetImage(
0102     const occ::handle<Image_SupportedFormats>& theSupported);
0103 
0104   //! @return low-level texture parameters
0105   const occ::handle<Graphic3d_TextureParams>& GetParams() const { return myParams; }
0106 
0107   //! Return flag indicating color nature of values within the texture; TRUE by default.
0108   //!
0109   //! This flag will be used to interpret 8-bit per channel RGB(A) images as sRGB(A) textures
0110   //! with implicit linearizion of color components.
0111   //! Has no effect on images with floating point values (always considered linearized).
0112   //!
0113   //! When set to FALSE, such images will be interpreted as textures will be linear component
0114   //! values, which is useful for RGB(A) textures defining non-color properties (like
0115   //! Normalmap/Metalness/Roughness).
0116   bool IsColorMap() const { return myIsColorMap; }
0117 
0118   //! Set flag indicating color nature of values within the texture.
0119   void SetColorMap(bool theIsColor) { myIsColorMap = theIsColor; }
0120 
0121   //! Returns whether mipmaps should be generated or not.
0122   bool HasMipmaps() const { return myHasMipmaps; }
0123 
0124   //! Sets whether to generate mipmaps or not.
0125   void SetMipmapsGeneration(bool theToGenerateMipmaps) { myHasMipmaps = theToGenerateMipmaps; }
0126 
0127   //! Returns whether row's memory layout is top-down.
0128   bool IsTopDown() const { return myIsTopDown; }
0129 
0130 protected:
0131   //! Creates a texture from a file
0132   //! Warning: Note that if <FileName> is NULL the texture must be realized
0133   //! using LoadTexture(image) method.
0134   Standard_EXPORT Graphic3d_TextureRoot(const TCollection_AsciiString& theFileName,
0135                                         const Graphic3d_TypeOfTexture  theType);
0136 
0137   //! Creates a texture from pixmap.
0138   //! Please note that the implementation expects the image data
0139   //! to be in Bottom-Up order (see Image_PixMap::IsTopDown()).
0140   Standard_EXPORT Graphic3d_TextureRoot(const occ::handle<Image_PixMap>& thePixmap,
0141                                         const Graphic3d_TypeOfTexture    theType);
0142 
0143   //! Unconditionally generate new texture id. Should be called only within constructor.
0144   Standard_EXPORT void generateId();
0145 
0146   //! Try converting image to compatible format.
0147   Standard_EXPORT static void convertToCompatible(
0148     const occ::handle<Image_SupportedFormats>& theSupported,
0149     const occ::handle<Image_PixMap>&           theImage);
0150 
0151   //! Method for supporting old API; another GetImage() method should be implemented instead.
0152   virtual occ::handle<Image_PixMap> GetImage() const { return occ::handle<Image_PixMap>(); }
0153 
0154 protected:
0155   occ::handle<Graphic3d_TextureParams> myParams; //!< associated texture parameters
0156   // clang-format off
0157   TCollection_AsciiString         myTexId;      //!< unique identifier of this resource (for sharing graphic resource); should never be modified outside constructor
0158   occ::handle<Image_PixMap>            myPixMap;     //!< image pixmap - as one of the ways for defining the texture source
0159   OSD_Path                        myPath;       //!< image file path - as one of the ways for defining the texture source
0160   size_t                   myRevision;   //!< image revision - for signaling changes in the texture source (e.g. file update, pixmap update)
0161   Graphic3d_TypeOfTexture         myType;       //!< texture type
0162   bool                myIsColorMap; //!< flag indicating color nature of values within the texture
0163   bool                myIsTopDown;  //!< Stores rows's memory layout
0164   bool                myHasMipmaps; //!< Indicates whether mipmaps should be generated or not
0165   // clang-format on
0166 };
0167 
0168 #endif // _Graphic3d_TextureRoot_HeaderFile