0032862: Visualization, Graphic3d_TextureMap - add 3D texture definition
[occt.git] / src / Graphic3d / Graphic3d_CubeMap.hxx
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.
29   Standard_EXPORT Graphic3d_CubeMap (const TCollection_AsciiString& theFileName,
30                                      Standard_Boolean               theToGenerateMipmaps = Standard_False);
31
32   //! Constructor defining direct cubemap initialization from PixMap.
33   Standard_EXPORT Graphic3d_CubeMap (const Handle(Image_PixMap)& thePixmap = Handle(Image_PixMap)(),
34                                      Standard_Boolean            theToGenerateMipmaps = Standard_False);
35
36   //! Returns whether the iterator has reached the end (true if it hasn't). 
37   Standard_Boolean More() const { return !myEndIsReached; }
38
39   //! Returns current cubemap side (iterator state).
40   Graphic3d_CubeMapSide CurrentSide() const { return myCurrentSide; }
41
42   //! Moves iterator to the next cubemap side.
43   //! Uses OpenGL cubemap sides order +X -> -X -> +Y -> -Y -> +Z -> -Z.
44   void Next()
45   {
46     if (!myEndIsReached && myCurrentSide == Graphic3d_CMS_NEG_Z)
47     {
48       myEndIsReached = true;
49     }
50     else
51     {
52       myCurrentSide = Graphic3d_CubeMapSide (myCurrentSide + 1);
53     }
54   }
55
56   //! Sets Z axis inversion (vertical flipping).
57   void SetZInversion (Standard_Boolean theZIsInverted)
58   {
59     myZIsInverted = theZIsInverted;
60   }
61
62   //! Returns whether Z axis is inverted.
63   Standard_Boolean ZIsInverted() const
64   {
65     return myZIsInverted;
66   }
67
68   //! Returns whether mipmaps of cubemap will be generated or not.
69   Standard_Boolean HasMipmaps() const { return myHasMipmaps; }
70
71   //! Sets whether to generate mipmaps of cubemap or not.
72   void SetMipmapsGeneration (Standard_Boolean theToGenerateMipmaps) { myHasMipmaps = theToGenerateMipmaps; }
73
74   //! Returns current cubemap side as compressed PixMap.
75   //! Returns null handle if current side is invalid or if image is not in supported compressed format.
76   virtual Handle(Image_CompressedPixMap) CompressedValue (const Handle(Image_SupportedFormats)& theSupported) = 0;
77
78   //! Returns PixMap containing current side of cubemap.
79   //! Returns null handle if current side is invalid.
80   virtual Handle(Image_PixMap) Value (const Handle(Image_SupportedFormats)& theSupported) = 0;
81
82   //! Sets iterator state to +X cubemap side.
83   Graphic3d_CubeMap& Reset()
84   { 
85     myCurrentSide = Graphic3d_CMS_POS_X;
86     myEndIsReached = false;
87     return *this;
88   }
89
90   //! Empty destructor.
91   Standard_EXPORT virtual ~Graphic3d_CubeMap();
92
93 protected:
94
95   Graphic3d_CubeMapSide myCurrentSide;  //!< Iterator state
96   Standard_Boolean      myEndIsReached; //!< Indicates whether end of iteration has been reached or hasn't
97   Standard_Boolean      myZIsInverted;  //!< Indicates whether Z axis is inverted that allows to synchronize vertical flip of cubemap
98
99 };
100
101 DEFINE_STANDARD_HANDLE(Graphic3d_CubeMap, Graphic3d_TextureMap)
102
103 #endif // _Graphic3d_CubeMap_HeaderFile