077a220c |
1 | // Author: Ilya Khramov |
2 | // Copyright (c) 2019 OPEN CASCADE SAS |
3 | // |
4 | // This file is part of Open CASCADE Technology software library. |
5 | // |
6 | // This library is free software; you can redistribute it and/or modify it under |
7 | // the terms of the GNU Lesser General Public License version 2.1 as published |
8 | // by the Free Software Foundation, with special exception defined in the file |
9 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
10 | // distribution for complete text of the license and disclaimer of any warranty. |
11 | // |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
14 | |
15 | #ifndef _Graphic3d_CubeMap_HeaderFile |
16 | #define _Graphic3d_CubeMap_HeaderFile |
17 | |
18 | #include <Graphic3d_CubeMapOrder.hxx> |
19 | #include <Graphic3d_TextureMap.hxx> |
20 | |
21 | //! Base class for cubemaps. |
22 | //! It is iterator over cubemap sides. |
23 | class Graphic3d_CubeMap : public Graphic3d_TextureMap |
24 | { |
25 | DEFINE_STANDARD_RTTIEXT(Graphic3d_CubeMap, Graphic3d_TextureMap) |
26 | public: |
27 | |
28 | //! Constructor defining loading cubemap from file. |
67312b79 |
29 | Graphic3d_CubeMap (const TCollection_AsciiString& theFileName, |
30 | Standard_Boolean theToGenerateMipmaps = Standard_False) : |
077a220c |
31 | Graphic3d_TextureMap (theFileName, Graphic3d_TOT_CUBEMAP), |
32 | myCurrentSide (Graphic3d_CMS_POS_X), |
33 | myEndIsReached (false), |
67312b79 |
34 | myZIsInverted (false), |
35 | myHasMipmaps (theToGenerateMipmaps) |
077a220c |
36 | {} |
37 | |
38 | //! Constructor defining direct cubemap initialization from PixMap. |
67312b79 |
39 | Graphic3d_CubeMap (const Handle(Image_PixMap)& thePixmap = Handle(Image_PixMap)(), |
40 | Standard_Boolean theToGenerateMipmaps = Standard_False) : |
077a220c |
41 | Graphic3d_TextureMap (thePixmap, Graphic3d_TOT_CUBEMAP), |
42 | myCurrentSide (Graphic3d_CMS_POS_X), |
43 | myEndIsReached (false), |
67312b79 |
44 | myZIsInverted (false), |
45 | myHasMipmaps (theToGenerateMipmaps) |
077a220c |
46 | {} |
47 | |
48 | //! Returns whether the iterator has reached the end (true if it hasn't). |
49 | Standard_Boolean More() const { return !myEndIsReached; } |
50 | |
51 | //! Returns current cubemap side (iterator state). |
52 | Graphic3d_CubeMapSide CurrentSide() const { return myCurrentSide; } |
53 | |
54 | //! Moves iterator to the next cubemap side. |
55 | //! Uses OpenGL cubemap sides order +X -> -X -> +Y -> -Y -> +Z -> -Z. |
56 | void Next() |
57 | { |
58 | if (!myEndIsReached && myCurrentSide == Graphic3d_CMS_NEG_Z) |
59 | { |
60 | myEndIsReached = true; |
61 | } |
62 | else |
63 | { |
64 | myCurrentSide = Graphic3d_CubeMapSide (myCurrentSide + 1); |
65 | } |
66 | } |
67 | |
077a220c |
68 | //! Sets Z axis inversion (vertical flipping). |
69 | void SetZInversion (Standard_Boolean theZIsInverted) |
70 | { |
71 | myZIsInverted = theZIsInverted; |
72 | } |
73 | |
74 | //! Returns whether Z axis is inverted. |
75 | Standard_Boolean ZIsInverted() const |
76 | { |
77 | return myZIsInverted; |
78 | } |
79 | |
67312b79 |
80 | //! Returns whether mipmaps of cubemap will be generated or not. |
81 | Standard_Boolean HasMipmaps() const { return myHasMipmaps; } |
82 | |
83 | //! Sets whether to generate mipmaps of cubemap or not. |
84 | void SetMipmapsGeneration (Standard_Boolean theToGenerateMipmaps) { myHasMipmaps = theToGenerateMipmaps; } |
85 | |
faff3767 |
86 | //! Returns current cubemap side as compressed PixMap. |
87 | //! Returns null handle if current side is invalid or if image is not in supported compressed format. |
88 | virtual Handle(Image_CompressedPixMap) CompressedValue (const Handle(Image_SupportedFormats)& theSupported) = 0; |
89 | |
077a220c |
90 | //! Returns PixMap containing current side of cubemap. |
91 | //! Returns null handle if current side is invalid. |
faff3767 |
92 | virtual Handle(Image_PixMap) Value (const Handle(Image_SupportedFormats)& theSupported) = 0; |
077a220c |
93 | |
94 | //! Sets iterator state to +X cubemap side. |
95 | Graphic3d_CubeMap& Reset() |
96 | { |
97 | myCurrentSide = Graphic3d_CMS_POS_X; |
98 | myEndIsReached = false; |
99 | return *this; |
100 | } |
101 | |
102 | //! Empty destructor. |
103 | ~Graphic3d_CubeMap() {} |
104 | |
105 | protected: |
106 | |
107 | Graphic3d_CubeMapSide myCurrentSide; //!< Iterator state |
108 | Standard_Boolean myEndIsReached; //!< Indicates whether end of iteration has been reached or hasn't |
077a220c |
109 | Standard_Boolean myZIsInverted; //!< Indicates whether Z axis is inverted that allows to synchronize vertical flip of cubemap |
67312b79 |
110 | Standard_Boolean myHasMipmaps; //!< Indicates whether mipmaps of cubemap will be generated or not |
077a220c |
111 | |
112 | }; |
113 | |
114 | DEFINE_STANDARD_HANDLE(Graphic3d_CubeMap, Graphic3d_TextureMap) |
115 | |
116 | #endif // _Graphic3d_CubeMap_HeaderFile |