|
||||
File indexing completed on 2025-01-18 10:03:49
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 texture. 0033 class Graphic3d_TextureRoot : public Standard_Transient 0034 { 0035 DEFINE_STANDARD_RTTIEXT(Graphic3d_TextureRoot, Standard_Transient) 0036 public: 0037 0038 //! The path to textures determined from CSF_MDTVTexturesDirectory or CASROOT environment variables. 0039 //! @return the root folder with default textures. 0040 Standard_EXPORT static TCollection_AsciiString TexturesFolder(); 0041 0042 public: 0043 0044 //! Destructor. 0045 Standard_EXPORT ~Graphic3d_TextureRoot(); 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 Standard_Boolean 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 Standard_Size 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 created. 0085 //! It is called in front of GetImage() for uploading compressed image formats natively supported by GPU. 0086 //! @param theSupported [in] the list of supported compressed texture formats; 0087 //! returning image in unsupported format will result in texture upload failure 0088 //! @return compressed pixmap or NULL if image is not in supported compressed format 0089 Standard_EXPORT virtual Handle(Image_CompressedPixMap) GetCompressedImage (const Handle(Image_SupportedFormats)& theSupported); 0090 0091 //! This method will be called by graphic driver each time when texture resource should be created. 0092 //! Default constructors allow defining the texture source as path to texture image or directly as pixmap. 0093 //! If the source is defined as path, then the image will be dynamically loaded when this method is called 0094 //! (and no copy will be preserved in this class instance). 0095 //! Inheritors may dynamically generate the image. 0096 //! Notice, image data should be in Bottom-Up order (see Image_PixMap::IsTopDown())! 0097 //! @return the image for texture. 0098 Standard_EXPORT virtual Handle(Image_PixMap) GetImage (const Handle(Image_SupportedFormats)& theSupported); 0099 0100 //! @return low-level texture parameters 0101 const Handle(Graphic3d_TextureParams)& GetParams() const { return myParams; } 0102 0103 //! Return flag indicating color nature of values within the texture; TRUE by default. 0104 //! 0105 //! This flag will be used to interpret 8-bit per channel RGB(A) images as sRGB(A) textures 0106 //! with implicit linearizion of color components. 0107 //! Has no effect on images with floating point values (always considered linearized). 0108 //! 0109 //! When set to FALSE, such images will be interpreted as textures will be linear component values, 0110 //! which is useful for RGB(A) textures defining non-color properties (like Normalmap/Metalness/Roughness). 0111 Standard_Boolean IsColorMap() const { return myIsColorMap; } 0112 0113 //! Set flag indicating color nature of values within the texture. 0114 void SetColorMap (Standard_Boolean theIsColor) { myIsColorMap = theIsColor; } 0115 0116 //! Returns whether mipmaps should be generated or not. 0117 Standard_Boolean HasMipmaps() const { return myHasMipmaps; } 0118 0119 //! Sets whether to generate mipmaps or not. 0120 void SetMipmapsGeneration (Standard_Boolean theToGenerateMipmaps) { myHasMipmaps = theToGenerateMipmaps; } 0121 0122 //! Returns whether row's memory layout is top-down. 0123 Standard_Boolean IsTopDown() const { return myIsTopDown; } 0124 0125 protected: 0126 0127 //! Creates a texture from a file 0128 //! Warning: Note that if <FileName> is NULL the texture must be realized 0129 //! using LoadTexture(image) method. 0130 Standard_EXPORT Graphic3d_TextureRoot(const TCollection_AsciiString& theFileName, const Graphic3d_TypeOfTexture theType); 0131 0132 //! Creates a texture from pixmap. 0133 //! Please note that the implementation expects the image data 0134 //! to be in Bottom-Up order (see Image_PixMap::IsTopDown()). 0135 Standard_EXPORT Graphic3d_TextureRoot(const Handle(Image_PixMap)& thePixmap, const Graphic3d_TypeOfTexture theType); 0136 0137 //! Unconditionally generate new texture id. Should be called only within constructor. 0138 Standard_EXPORT void generateId(); 0139 0140 //! Try converting image to compatible format. 0141 Standard_EXPORT static void convertToCompatible (const Handle(Image_SupportedFormats)& theSupported, 0142 const Handle(Image_PixMap)& theImage); 0143 0144 //! Method for supporting old API; another GetImage() method should be implemented instead. 0145 virtual Handle(Image_PixMap) GetImage() const { return Handle(Image_PixMap)(); } 0146 0147 protected: 0148 0149 Handle(Graphic3d_TextureParams) myParams; //!< associated texture parameters 0150 TCollection_AsciiString myTexId; //!< unique identifier of this resource (for sharing graphic resource); should never be modified outside constructor 0151 Handle(Image_PixMap) myPixMap; //!< image pixmap - as one of the ways for defining the texture source 0152 OSD_Path myPath; //!< image file path - as one of the ways for defining the texture source 0153 Standard_Size myRevision; //!< image revision - for signaling changes in the texture source (e.g. file update, pixmap update) 0154 Graphic3d_TypeOfTexture myType; //!< texture type 0155 Standard_Boolean myIsColorMap; //!< flag indicating color nature of values within the texture 0156 Standard_Boolean myIsTopDown; //!< Stores rows's memory layout 0157 Standard_Boolean myHasMipmaps; //!< Indicates whether mipmaps should be generated or not 0158 0159 }; 0160 0161 DEFINE_STANDARD_HANDLE(Graphic3d_TextureRoot, Standard_Transient) 0162 0163 #endif // _Graphic3d_TextureRoot_HeaderFile
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |