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 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> 27 28 class Graphic3d_TextureParams; 29 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 32 { 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(); 39 40 public: 41 42 //! Destructor. 43 Standard_EXPORT ~Graphic3d_TextureRoot(); 44 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; 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. Path() const51 const OSD_Path& Path() const { return myPath; } 52 53 //! @return the texture type. Type() const54 Graphic3d_TypeOfTexture Type() const { return myType; } 55 56 //! This ID will be used to manage resource in graphic driver. 57 //! 58 //! Default implementation generates unique ID within constructor; 59 //! inheritors may re-initialize it within their constructor, 60 //! but should never modify it afterwards. 61 //! 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. 66 //! 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. 70 //! 71 //! @return texture identifier. GetId() const72 const TCollection_AsciiString& GetId() const { return myTexId; } 73 74 //! Return image revision. Revision() const75 Standard_Size Revision() const { return myRevision; } 76 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). UpdateRevision()80 void UpdateRevision() { ++myRevision; } 81 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; 90 91 //! @return low-level texture parameters Handle(Graphic3d_TextureParams)92 const Handle(Graphic3d_TextureParams)& GetParams() const { return myParams; } 93 94 protected: 95 96 //! Creates a texture from a file 97 //! Warning: Note that if <FileName> is NULL the texture must be realized 98 //! using LoadTexture(image) method. 99 Standard_EXPORT Graphic3d_TextureRoot(const TCollection_AsciiString& theFileName, const Graphic3d_TypeOfTexture theType); 100 101 //! Creates a texture from pixmap. 102 //! Please note that the implementation expects the image data 103 //! to be in Bottom-Up order (see Image_PixMap::IsTopDown()). 104 Standard_EXPORT Graphic3d_TextureRoot(const Handle(Image_PixMap)& thePixmap, const Graphic3d_TypeOfTexture theType); 105 106 //! Unconditionally generate new texture id. Should be called only within constructor. 107 Standard_EXPORT void generateId(); 108 109 protected: 110 111 Handle(Graphic3d_TextureParams) myParams; //!< associated texture parameters 112 TCollection_AsciiString myTexId; //!< unique identifier of this resource (for sharing graphic resource); should never be modified outside constructor 113 Handle(Image_PixMap) myPixMap; //!< image pixmap - as one of the ways for defining the texture source 114 OSD_Path myPath; //!< image file path - as one of the ways for defining the texture source 115 Standard_Size myRevision; //!< image revision - for signaling changes in the texture source (e.g. file update, pixmap update) 116 Graphic3d_TypeOfTexture myType; //!< texture type 117 118 }; 119 120 DEFINE_STANDARD_HANDLE(Graphic3d_TextureRoot, Standard_Transient) 121 122 #endif // _Graphic3d_TextureRoot_HeaderFile 123