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 Graphic3d_TextureParams;
30 //! This is the texture root class enable the dialog with the GraphicDriver allows the loading of texture.
31 class Graphic3d_TextureRoot : public Standard_Transient
33 DEFINE_STANDARD_RTTIEXT(Graphic3d_TextureRoot, Standard_Transient)
36 //! The path to textures determined from CSF_MDTVTexturesDirectory or CASROOT environment variables.
37 //! @return the root folder with default textures.
38 Standard_EXPORT static TCollection_AsciiString TexturesFolder();
43 Standard_EXPORT ~Graphic3d_TextureRoot();
45 //! Checks if a texture class is valid or not.
46 //! @return true if the construction of the class is correct
47 Standard_EXPORT virtual Standard_Boolean IsDone() const;
49 //! Returns the full path of the defined texture.
50 //! It could be empty path if GetImage() is overridden to load image not from file.
51 const OSD_Path& Path() const { return myPath; }
53 //! @return the texture type.
54 Graphic3d_TypeOfTexture Type() const { return myType; }
56 //! This ID will be used to manage resource in graphic driver.
58 //! Default implementation generates unique ID within constructor;
59 //! inheritors may re-initialize it within their constructor,
60 //! but should never modify it afterwards.
62 //! Multiple Graphic3d_TextureRoot instances with same ID
63 //! will be treated as single texture with different parameters
64 //! to optimize memory usage though this will be more natural
65 //! to use same instance of Graphic3d_TextureRoot when possible.
67 //! If this ID is set to empty string by inheritor,
68 //! then independent graphical resource will be created
69 //! for each instance of Graphic3d_AspectFillArea3d where texture will be used.
71 //! @return texture identifier.
72 const TCollection_AsciiString& GetId() const { return myTexId; }
74 //! Return image revision.
75 Standard_Size Revision() const { return myRevision; }
77 //! Update image revision.
78 //! Can be used for signaling changes in the texture source (e.g. file update, pixmap update)
79 //! without re-creating texture source itself (since unique id should be never modified).
80 void UpdateRevision() { ++myRevision; }
82 //! This method will be called by graphic driver each time when texture resource should be created.
83 //! Default constructors allow defining the texture source as path to texture image or directly as pixmap.
84 //! If the source is defined as path, then the image will be dynamically loaded when this method is called
85 //! (and no copy will be preserved in this class instance).
86 //! Inheritors may dynamically generate the image.
87 //! Notice, image data should be in Bottom-Up order (see Image_PixMap::IsTopDown())!
88 //! @return the image for texture.
89 Standard_EXPORT virtual Handle(Image_PixMap) GetImage() const;
91 //! @return low-level texture parameters
92 const Handle(Graphic3d_TextureParams)& GetParams() const { return myParams; }
94 //! Return flag indicating color nature of values within the texture; TRUE by default.
96 //! This flag will be used to interpret 8-bit per channel RGB(A) images as sRGB(A) textures
97 //! with implicit linearizion of color components.
98 //! Has no effect on images with floating point values (always considered linearized).
100 //! When set to FALSE, such images will be interpreted as textures will be linear component values,
101 //! which is useful for RGB(A) textures defining non-color properties (like Normalmap/Metalness/Roughness).
102 Standard_Boolean IsColorMap() const { return myIsColorMap; }
104 //! Set flag indicating color nature of values within the texture.
105 void SetColorMap (Standard_Boolean theIsColor) { myIsColorMap = theIsColor; }
109 //! Creates a texture from a file
110 //! Warning: Note that if <FileName> is NULL the texture must be realized
111 //! using LoadTexture(image) method.
112 Standard_EXPORT Graphic3d_TextureRoot(const TCollection_AsciiString& theFileName, const Graphic3d_TypeOfTexture theType);
114 //! Creates a texture from pixmap.
115 //! Please note that the implementation expects the image data
116 //! to be in Bottom-Up order (see Image_PixMap::IsTopDown()).
117 Standard_EXPORT Graphic3d_TextureRoot(const Handle(Image_PixMap)& thePixmap, const Graphic3d_TypeOfTexture theType);
119 //! Unconditionally generate new texture id. Should be called only within constructor.
120 Standard_EXPORT void generateId();
124 Handle(Graphic3d_TextureParams) myParams; //!< associated texture parameters
125 TCollection_AsciiString myTexId; //!< unique identifier of this resource (for sharing graphic resource); should never be modified outside constructor
126 Handle(Image_PixMap) myPixMap; //!< image pixmap - as one of the ways for defining the texture source
127 OSD_Path myPath; //!< image file path - as one of the ways for defining the texture source
128 Standard_Size myRevision; //!< image revision - for signaling changes in the texture source (e.g. file update, pixmap update)
129 Graphic3d_TypeOfTexture myType; //!< texture type
130 Standard_Boolean myIsColorMap; //!< flag indicating color nature of values within the texture
134 DEFINE_STANDARD_HANDLE(Graphic3d_TextureRoot, Standard_Transient)
136 #endif // _Graphic3d_TextureRoot_HeaderFile