42cf5bc1 |
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 |
5 | // |
6 | // This file is part of Open CASCADE Technology software library. |
7 | // |
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. |
13 | // |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
16 | |
17 | #ifndef _Graphic3d_TextureRoot_HeaderFile |
18 | #define _Graphic3d_TextureRoot_HeaderFile |
19 | |
a13f2dc4 |
20 | #include <Image_PixMap.hxx> |
42cf5bc1 |
21 | #include <OSD_Path.hxx> |
22 | #include <Graphic3d_TypeOfTexture.hxx> |
d2edda76 |
23 | #include <Standard.hxx> |
24 | #include <Standard_Transient.hxx> |
25 | #include <Standard_Type.hxx> |
26 | #include <TCollection_AsciiString.hxx> |
42cf5bc1 |
27 | |
d2edda76 |
28 | class Graphic3d_TextureParams; |
42cf5bc1 |
29 | |
30 | //! This is the texture root class enable the dialog with the GraphicDriver allows the loading of texture. |
d2edda76 |
31 | class Graphic3d_TextureRoot : public Standard_Transient |
42cf5bc1 |
32 | { |
d2edda76 |
33 | DEFINE_STANDARD_RTTIEXT(Graphic3d_TextureRoot, Standard_Transient) |
34 | public: |
35 | |
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(); |
42cf5bc1 |
39 | |
40 | public: |
41 | |
d2edda76 |
42 | //! Destructor. |
43 | Standard_EXPORT ~Graphic3d_TextureRoot(); |
44 | |
42cf5bc1 |
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; |
42cf5bc1 |
48 | |
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. |
d2edda76 |
51 | const OSD_Path& Path() const { return myPath; } |
52 | |
42cf5bc1 |
53 | //! @return the texture type. |
d2edda76 |
54 | Graphic3d_TypeOfTexture Type() const { return myType; } |
42cf5bc1 |
55 | |
56 | //! This ID will be used to manage resource in graphic driver. |
57 | //! |
58 | //! Default implementation generates unique ID although inheritors may re-initialize it. |
59 | //! |
dc858f4c |
60 | //! Multiple Graphic3d_TextureRoot instances with same ID |
42cf5bc1 |
61 | //! will be treated as single texture with different parameters |
62 | //! to optimize memory usage though this will be more natural |
63 | //! to use same instance of Graphic3d_TextureRoot when possible. |
64 | //! |
65 | //! Notice that inheritor may set this ID to empty string. |
66 | //! In this case independent graphical resource will be created |
67 | //! for each instance of Graphic3d_AspectFillArea3d where texture will be used. |
68 | //! |
69 | //! @return texture identifier. |
d2edda76 |
70 | const TCollection_AsciiString& GetId() const { return myTexId; } |
71 | |
72 | //! Return image revision. |
73 | Standard_Size Revision() const { return myRevision; } |
74 | |
75 | //! Update image revision. |
dc858f4c |
76 | //! Can be used for signaling changes in the texture source (e.g. file update, pixmap update) |
d2edda76 |
77 | //! without re-creating texture source itself (e.g. preserving the unique id). |
78 | void UpdateRevision() { ++myRevision; } |
42cf5bc1 |
79 | |
80 | //! This method will be called by graphic driver each time when texture resource should be created. |
81 | //! Default constructors allow defining the texture source as path to texture image or directly as pixmap. |
82 | //! If the source is defined as path, then the image will be dynamically loaded when this method is called |
83 | //! (and no copy will be preserved in this class instance). |
84 | //! Inheritors may dynamically generate the image. |
85 | //! Notice, image data should be in Bottom-Up order (see Image_PixMap::IsTopDown())! |
86 | //! @return the image for texture. |
a13f2dc4 |
87 | Standard_EXPORT virtual Handle(Image_PixMap) GetImage() const; |
88 | |
42cf5bc1 |
89 | //! @return low-level texture parameters |
d2edda76 |
90 | const Handle(Graphic3d_TextureParams)& GetParams() const { return myParams; } |
42cf5bc1 |
91 | |
92 | protected: |
93 | |
42cf5bc1 |
94 | //! Creates a texture from a file |
95 | //! Warning: Note that if <FileName> is NULL the texture must be realized |
96 | //! using LoadTexture(image) method. |
97 | Standard_EXPORT Graphic3d_TextureRoot(const TCollection_AsciiString& theFileName, const Graphic3d_TypeOfTexture theType); |
98 | |
99 | //! Creates a texture from pixmap. |
100 | //! Please note that the implementation expects the image data |
101 | //! to be in Bottom-Up order (see Image_PixMap::IsTopDown()). |
a13f2dc4 |
102 | Standard_EXPORT Graphic3d_TextureRoot(const Handle(Image_PixMap)& thePixmap, const Graphic3d_TypeOfTexture theType); |
42cf5bc1 |
103 | |
d2edda76 |
104 | //! Unconditionally generate new texture id. |
105 | Standard_EXPORT void generateId(); |
42cf5bc1 |
106 | |
d2edda76 |
107 | protected: |
42cf5bc1 |
108 | |
d2edda76 |
109 | Handle(Graphic3d_TextureParams) myParams; //!< associated texture parameters |
110 | TCollection_AsciiString myTexId; //!< unique identifier of this resource (for sharing) |
111 | Handle(Image_PixMap) myPixMap; //!< image pixmap - as one of the ways for defining the texture source |
112 | OSD_Path myPath; //!< image file path - as one of the ways for defining the texture source |
dc858f4c |
113 | Standard_Size myRevision; //!< image revision - for signaling changes in the texture source (e.g. file update, pixmap update) |
d2edda76 |
114 | Graphic3d_TypeOfTexture myType; //!< texture type |
42cf5bc1 |
115 | |
116 | }; |
117 | |
d2edda76 |
118 | DEFINE_STANDARD_HANDLE(Graphic3d_TextureRoot, Standard_Transient) |
42cf5bc1 |
119 | |
120 | #endif // _Graphic3d_TextureRoot_HeaderFile |