1 // Author: Ilya Khramov
2 // Copyright (c) 2019 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #ifndef _Graphic3d_CubeMap_HeaderFile
16 #define _Graphic3d_CubeMap_HeaderFile
18 #include <Graphic3d_CubeMapOrder.hxx>
19 #include <Graphic3d_TextureMap.hxx>
21 //! Base class for cubemaps.
22 //! It is iterator over cubemap sides.
23 class Graphic3d_CubeMap : public Graphic3d_TextureMap
25 DEFINE_STANDARD_RTTIEXT(Graphic3d_CubeMap, Graphic3d_TextureMap)
28 //! Constructor defining loading cubemap from file.
29 Graphic3d_CubeMap (const TCollection_AsciiString& theFileName,
30 Standard_Boolean theToGenerateMipmaps = Standard_False) :
31 Graphic3d_TextureMap (theFileName, Graphic3d_TOT_CUBEMAP),
32 myCurrentSide (Graphic3d_CMS_POS_X),
33 myEndIsReached (false),
35 myZIsInverted (false),
36 myHasMipmaps (theToGenerateMipmaps)
39 //! Constructor defining direct cubemap initialization from PixMap.
40 Graphic3d_CubeMap (const Handle(Image_PixMap)& thePixmap = Handle(Image_PixMap)(),
41 Standard_Boolean theToGenerateMipmaps = Standard_False) :
42 Graphic3d_TextureMap (thePixmap, Graphic3d_TOT_CUBEMAP),
43 myCurrentSide (Graphic3d_CMS_POS_X),
44 myEndIsReached (false),
46 myZIsInverted (false),
47 myHasMipmaps (theToGenerateMipmaps)
50 //! Returns whether the iterator has reached the end (true if it hasn't).
51 Standard_Boolean More() const { return !myEndIsReached; }
53 //! Returns current cubemap side (iterator state).
54 Graphic3d_CubeMapSide CurrentSide() const { return myCurrentSide; }
56 //! Moves iterator to the next cubemap side.
57 //! Uses OpenGL cubemap sides order +X -> -X -> +Y -> -Y -> +Z -> -Z.
60 if (!myEndIsReached && myCurrentSide == Graphic3d_CMS_NEG_Z)
62 myEndIsReached = true;
66 myCurrentSide = Graphic3d_CubeMapSide (myCurrentSide + 1);
70 //! Returns whether row's memory layout is top-down.
71 Standard_Boolean IsTopDown() const
76 //! Sets Z axis inversion (vertical flipping).
77 void SetZInversion (Standard_Boolean theZIsInverted)
79 myZIsInverted = theZIsInverted;
82 //! Returns whether Z axis is inverted.
83 Standard_Boolean ZIsInverted() const
88 //! Returns whether mipmaps of cubemap will be generated or not.
89 Standard_Boolean HasMipmaps() const { return myHasMipmaps; }
91 //! Sets whether to generate mipmaps of cubemap or not.
92 void SetMipmapsGeneration (Standard_Boolean theToGenerateMipmaps) { myHasMipmaps = theToGenerateMipmaps; }
94 //! Returns PixMap containing current side of cubemap.
95 //! Returns null handle if current side is invalid.
96 virtual Handle(Image_PixMap) Value() = 0;
98 //! Sets iterator state to +X cubemap side.
99 Graphic3d_CubeMap& Reset()
101 myCurrentSide = Graphic3d_CMS_POS_X;
102 myEndIsReached = false;
106 //! Empty destructor.
107 ~Graphic3d_CubeMap() {}
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
115 Standard_Boolean myHasMipmaps; //!< Indicates whether mipmaps of cubemap will be generated or not
119 DEFINE_STANDARD_HANDLE(Graphic3d_CubeMap, Graphic3d_TextureMap)
121 #endif // _Graphic3d_CubeMap_HeaderFile