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), |
34 | myIsTopDown (true), |
67312b79 |
35 | myZIsInverted (false), |
36 | myHasMipmaps (theToGenerateMipmaps) |
077a220c |
37 | {} |
38 | |
39 | //! Constructor defining direct cubemap initialization from PixMap. |
67312b79 |
40 | Graphic3d_CubeMap (const Handle(Image_PixMap)& thePixmap = Handle(Image_PixMap)(), |
41 | Standard_Boolean theToGenerateMipmaps = Standard_False) : |
077a220c |
42 | Graphic3d_TextureMap (thePixmap, Graphic3d_TOT_CUBEMAP), |
43 | myCurrentSide (Graphic3d_CMS_POS_X), |
44 | myEndIsReached (false), |
45 | myIsTopDown (true), |
67312b79 |
46 | myZIsInverted (false), |
47 | myHasMipmaps (theToGenerateMipmaps) |
077a220c |
48 | {} |
49 | |
50 | //! Returns whether the iterator has reached the end (true if it hasn't). |
51 | Standard_Boolean More() const { return !myEndIsReached; } |
52 | |
53 | //! Returns current cubemap side (iterator state). |
54 | Graphic3d_CubeMapSide CurrentSide() const { return myCurrentSide; } |
55 | |
56 | //! Moves iterator to the next cubemap side. |
57 | //! Uses OpenGL cubemap sides order +X -> -X -> +Y -> -Y -> +Z -> -Z. |
58 | void Next() |
59 | { |
60 | if (!myEndIsReached && myCurrentSide == Graphic3d_CMS_NEG_Z) |
61 | { |
62 | myEndIsReached = true; |
63 | } |
64 | else |
65 | { |
66 | myCurrentSide = Graphic3d_CubeMapSide (myCurrentSide + 1); |
67 | } |
68 | } |
69 | |
70 | //! Returns whether row's memory layout is top-down. |
71 | Standard_Boolean IsTopDown() const |
72 | { |
73 | return myIsTopDown; |
74 | } |
75 | |
76 | //! Sets Z axis inversion (vertical flipping). |
77 | void SetZInversion (Standard_Boolean theZIsInverted) |
78 | { |
79 | myZIsInverted = theZIsInverted; |
80 | } |
81 | |
82 | //! Returns whether Z axis is inverted. |
83 | Standard_Boolean ZIsInverted() const |
84 | { |
85 | return myZIsInverted; |
86 | } |
87 | |
67312b79 |
88 | //! Returns whether mipmaps of cubemap will be generated or not. |
89 | Standard_Boolean HasMipmaps() const { return myHasMipmaps; } |
90 | |
91 | //! Sets whether to generate mipmaps of cubemap or not. |
92 | void SetMipmapsGeneration (Standard_Boolean theToGenerateMipmaps) { myHasMipmaps = theToGenerateMipmaps; } |
93 | |
077a220c |
94 | //! Returns PixMap containing current side of cubemap. |
95 | //! Returns null handle if current side is invalid. |
96 | virtual Handle(Image_PixMap) Value() = 0; |
97 | |
98 | //! Sets iterator state to +X cubemap side. |
99 | Graphic3d_CubeMap& Reset() |
100 | { |
101 | myCurrentSide = Graphic3d_CMS_POS_X; |
102 | myEndIsReached = false; |
103 | return *this; |
104 | } |
105 | |
106 | //! Empty destructor. |
107 | ~Graphic3d_CubeMap() {} |
108 | |
109 | protected: |
110 | |
111 | Graphic3d_CubeMapSide myCurrentSide; //!< Iterator state |
112 | Standard_Boolean myEndIsReached; //!< Indicates whether end of iteration has been reached or hasn't |
113 | Standard_Boolean myIsTopDown; //!< Stores rows's memory layout |
114 | Standard_Boolean myZIsInverted; //!< Indicates whether Z axis is inverted that allows to synchronize vertical flip of cubemap |
67312b79 |
115 | Standard_Boolean myHasMipmaps; //!< Indicates whether mipmaps of cubemap will be generated or not |
077a220c |
116 | |
117 | }; |
118 | |
119 | DEFINE_STANDARD_HANDLE(Graphic3d_CubeMap, Graphic3d_TextureMap) |
120 | |
121 | #endif // _Graphic3d_CubeMap_HeaderFile |