0029528: Visualization, TKOpenGl - allow defining sRGB textures
[occt.git] / src / Graphic3d / Graphic3d_TextureRoot.hxx
CommitLineData
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 28class Graphic3d_TextureParams;
42cf5bc1 29
30//! This is the texture root class enable the dialog with the GraphicDriver allows the loading of texture.
d2edda76 31class Graphic3d_TextureRoot : public Standard_Transient
42cf5bc1 32{
d2edda76 33 DEFINE_STANDARD_RTTIEXT(Graphic3d_TextureRoot, Standard_Transient)
34public:
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
40public:
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 //!
cc8cbabe 58 //! Default implementation generates unique ID within constructor;
59 //! inheritors may re-initialize it within their constructor,
60 //! but should never modify it afterwards.
42cf5bc1 61 //!
dc858f4c 62 //! Multiple Graphic3d_TextureRoot instances with same ID
42cf5bc1 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 //!
cc8cbabe 67 //! If this ID is set to empty string by inheritor,
68 //! then independent graphical resource will be created
42cf5bc1 69 //! for each instance of Graphic3d_AspectFillArea3d where texture will be used.
70 //!
71 //! @return texture identifier.
d2edda76 72 const TCollection_AsciiString& GetId() const { return myTexId; }
73
74 //! Return image revision.
75 Standard_Size Revision() const { return myRevision; }
76
77 //! Update image revision.
dc858f4c 78 //! Can be used for signaling changes in the texture source (e.g. file update, pixmap update)
cc8cbabe 79 //! without re-creating texture source itself (since unique id should be never modified).
d2edda76 80 void UpdateRevision() { ++myRevision; }
42cf5bc1 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.
a13f2dc4 89 Standard_EXPORT virtual Handle(Image_PixMap) GetImage() const;
90
42cf5bc1 91 //! @return low-level texture parameters
d2edda76 92 const Handle(Graphic3d_TextureParams)& GetParams() const { return myParams; }
42cf5bc1 93
ba00aab7 94 //! Return flag indicating color nature of values within the texture; TRUE by default.
95 //!
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).
99 //!
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; }
103
104 //! Set flag indicating color nature of values within the texture.
105 void SetColorMap (Standard_Boolean theIsColor) { myIsColorMap = theIsColor; }
106
42cf5bc1 107protected:
108
42cf5bc1 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);
113
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()).
a13f2dc4 117 Standard_EXPORT Graphic3d_TextureRoot(const Handle(Image_PixMap)& thePixmap, const Graphic3d_TypeOfTexture theType);
42cf5bc1 118
cc8cbabe 119 //! Unconditionally generate new texture id. Should be called only within constructor.
d2edda76 120 Standard_EXPORT void generateId();
42cf5bc1 121
d2edda76 122protected:
42cf5bc1 123
ba00aab7 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
42cf5bc1 131
132};
133
d2edda76 134DEFINE_STANDARD_HANDLE(Graphic3d_TextureRoot, Standard_Transient)
42cf5bc1 135
136#endif // _Graphic3d_TextureRoot_HeaderFile