1 // Created on: 1997-07-28
2 // Created by: Pierre CHALAMET
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef _Graphic3d_TextureRoot_HeaderFile
18 #define _Graphic3d_TextureRoot_HeaderFile
20 #include <Image_PixMap.hxx>
21 #include <OSD_Path.hxx>
22 #include <Graphic3d_TypeOfTexture.hxx>
23 #include <Standard.hxx>
24 #include <Standard_Transient.hxx>
25 #include <Standard_Type.hxx>
26 #include <TCollection_AsciiString.hxx>
28 class Image_CompressedPixMap;
29 class Image_SupportedFormats;
30 class Graphic3d_TextureParams;
32 //! This is the texture root class enable the dialog with the GraphicDriver allows the loading of texture.
33 class Graphic3d_TextureRoot : public Standard_Transient
35 DEFINE_STANDARD_RTTIEXT(Graphic3d_TextureRoot, Standard_Transient)
38 //! The path to textures determined from CSF_MDTVTexturesDirectory or CASROOT environment variables.
39 //! @return the root folder with default textures.
40 Standard_EXPORT static TCollection_AsciiString TexturesFolder();
45 Standard_EXPORT ~Graphic3d_TextureRoot();
47 //! Checks if a texture class is valid or not.
48 //! @return true if the construction of the class is correct
49 Standard_EXPORT virtual Standard_Boolean IsDone() const;
51 //! Returns the full path of the defined texture.
52 //! It could be empty path if GetImage() is overridden to load image not from file.
53 const OSD_Path& Path() const { return myPath; }
55 //! @return the texture type.
56 Graphic3d_TypeOfTexture Type() const { return myType; }
58 //! This ID will be used to manage resource in graphic driver.
60 //! Default implementation generates unique ID within constructor;
61 //! inheritors may re-initialize it within their constructor,
62 //! but should never modify it afterwards.
64 //! Multiple Graphic3d_TextureRoot instances with same ID
65 //! will be treated as single texture with different parameters
66 //! to optimize memory usage though this will be more natural
67 //! to use same instance of Graphic3d_TextureRoot when possible.
69 //! If this ID is set to empty string by inheritor,
70 //! then independent graphical resource will be created
71 //! for each instance of Graphic3d_AspectFillArea3d where texture will be used.
73 //! @return texture identifier.
74 const TCollection_AsciiString& GetId() const { return myTexId; }
76 //! Return image revision.
77 Standard_Size Revision() const { return myRevision; }
79 //! Update image revision.
80 //! Can be used for signaling changes in the texture source (e.g. file update, pixmap update)
81 //! without re-creating texture source itself (since unique id should be never modified).
82 void UpdateRevision() { ++myRevision; }
84 //! This method will be called by graphic driver each time when texture resource should be created.
85 //! It is called in front of GetImage() for uploading compressed image formats natively supported by GPU.
86 //! @param theSupported [in] the list of supported compressed texture formats;
87 //! returning image in unsupported format will result in texture upload failure
88 //! @return compressed pixmap or NULL if image is not in supported compressed format
89 Standard_EXPORT virtual Handle(Image_CompressedPixMap) GetCompressedImage (const Handle(Image_SupportedFormats)& theSupported);
91 //! This method will be called by graphic driver each time when texture resource should be created.
92 //! Default constructors allow defining the texture source as path to texture image or directly as pixmap.
93 //! If the source is defined as path, then the image will be dynamically loaded when this method is called
94 //! (and no copy will be preserved in this class instance).
95 //! Inheritors may dynamically generate the image.
96 //! Notice, image data should be in Bottom-Up order (see Image_PixMap::IsTopDown())!
97 //! @return the image for texture.
98 Standard_EXPORT virtual Handle(Image_PixMap) GetImage (const Handle(Image_SupportedFormats)& theSupported);
100 //! @return low-level texture parameters
101 const Handle(Graphic3d_TextureParams)& GetParams() const { return myParams; }
103 //! Return flag indicating color nature of values within the texture; TRUE by default.
105 //! This flag will be used to interpret 8-bit per channel RGB(A) images as sRGB(A) textures
106 //! with implicit linearizion of color components.
107 //! Has no effect on images with floating point values (always considered linearized).
109 //! When set to FALSE, such images will be interpreted as textures will be linear component values,
110 //! which is useful for RGB(A) textures defining non-color properties (like Normalmap/Metalness/Roughness).
111 Standard_Boolean IsColorMap() const { return myIsColorMap; }
113 //! Set flag indicating color nature of values within the texture.
114 void SetColorMap (Standard_Boolean theIsColor) { myIsColorMap = theIsColor; }
116 //! Returns whether row's memory layout is top-down.
117 Standard_Boolean IsTopDown() const { return myIsTopDown; }
121 //! Creates a texture from a file
122 //! Warning: Note that if <FileName> is NULL the texture must be realized
123 //! using LoadTexture(image) method.
124 Standard_EXPORT Graphic3d_TextureRoot(const TCollection_AsciiString& theFileName, const Graphic3d_TypeOfTexture theType);
126 //! Creates a texture from pixmap.
127 //! Please note that the implementation expects the image data
128 //! to be in Bottom-Up order (see Image_PixMap::IsTopDown()).
129 Standard_EXPORT Graphic3d_TextureRoot(const Handle(Image_PixMap)& thePixmap, const Graphic3d_TypeOfTexture theType);
131 //! Unconditionally generate new texture id. Should be called only within constructor.
132 Standard_EXPORT void generateId();
134 //! Try converting image to compatible format.
135 Standard_EXPORT static void convertToCompatible (const Handle(Image_SupportedFormats)& theSupported,
136 const Handle(Image_PixMap)& theImage);
138 //! Method for supporting old API; another GetImage() method should be implemented instead.
139 virtual Handle(Image_PixMap) GetImage() const { return Handle(Image_PixMap)(); }
143 Handle(Graphic3d_TextureParams) myParams; //!< associated texture parameters
144 TCollection_AsciiString myTexId; //!< unique identifier of this resource (for sharing graphic resource); should never be modified outside constructor
145 Handle(Image_PixMap) myPixMap; //!< image pixmap - as one of the ways for defining the texture source
146 OSD_Path myPath; //!< image file path - as one of the ways for defining the texture source
147 Standard_Size myRevision; //!< image revision - for signaling changes in the texture source (e.g. file update, pixmap update)
148 Graphic3d_TypeOfTexture myType; //!< texture type
149 Standard_Boolean myIsColorMap; //!< flag indicating color nature of values within the texture
150 Standard_Boolean myIsTopDown; //!< Stores rows's memory layout
155 DEFINE_STANDARD_HANDLE(Graphic3d_TextureRoot, Standard_Transient)
157 #endif // _Graphic3d_TextureRoot_HeaderFile