748ba7da96d560d2d743b66e9c5a514966d36c01
[occt.git] / src / OpenGl / OpenGl_TextureSet.hxx
1 // Copyright (c) 2017 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 #ifndef _OpenGl_TextureSet_Header
15 #define _OpenGl_TextureSet_Header
16
17 #include <Graphic3d_TextureSet.hxx>
18
19 class OpenGl_Texture;
20
21 //! Class holding array of textures to be mapped as a set.
22 class OpenGl_TextureSet : public Standard_Transient
23 {
24   DEFINE_STANDARD_RTTIEXT(OpenGl_TextureSet, Standard_Transient)
25 public:
26
27   //! Class for iterating texture set.
28   class Iterator : public NCollection_Array1<Handle(OpenGl_Texture)>::Iterator
29   {
30   public:
31     //! Empty constructor.
32     Iterator() {}
33
34     //! Constructor.
35     Iterator (const Handle(OpenGl_TextureSet)& theSet)
36     {
37       if (!theSet.IsNull())
38       {
39         NCollection_Array1<Handle(OpenGl_Texture)>::Iterator::Init (theSet->myTextures);
40       }
41     }
42   };
43
44 public:
45
46   //! Empty constructor.
47   OpenGl_TextureSet() {}
48
49   //! Constructor.
50   OpenGl_TextureSet (Standard_Integer theNbTextures)
51   : myTextures (0, theNbTextures - 1) {}
52
53   //! Constructor for a single texture.
54   OpenGl_TextureSet (const Handle(OpenGl_Texture)& theTexture)
55   : myTextures (0, 0)
56   {
57     myTextures.ChangeFirst() = theTexture;
58   }
59
60   //! Return TRUE if texture array is empty.
61   Standard_Boolean IsEmpty() const { return myTextures.IsEmpty(); }
62
63   //! Return number of textures.
64   Standard_Integer Size() const { return myTextures.Size(); }
65
66   //! Return the lower index in texture set.
67   Standard_Integer Lower() const { return myTextures.Lower(); }
68
69   //! Return the upper index in texture set.
70   Standard_Integer Upper() const { return myTextures.Upper(); }
71
72   //! Return the first texture.
73   const Handle(OpenGl_Texture)& First() const { return myTextures.First(); }
74
75   //! Return the first texture.
76   Handle(OpenGl_Texture)& ChangeFirst() { return myTextures.ChangeFirst(); }
77
78   //! Return the last texture.
79   const Handle(OpenGl_Texture)& Last() const { return myTextures.Last(); }
80
81   //! Return the last texture.
82   Handle(OpenGl_Texture)& ChangeLast() { return myTextures.ChangeLast(); }
83
84   //! Return the texture at specified position within [0, Size()) range.
85   const Handle(OpenGl_Texture)& Value (Standard_Integer theIndex) const { return myTextures.Value (theIndex); }
86
87   //! Return the texture at specified position within [0, Size()) range.
88   Handle(OpenGl_Texture)& ChangeValue (Standard_Integer theIndex) { return myTextures.ChangeValue (theIndex); }
89
90   //! Return TRUE if texture color modulation has been enabled for the first texture
91   //! or if texture is not set at all.
92   Standard_EXPORT bool IsModulate() const;
93
94   //! Return TRUE if other than point sprite textures are defined within point set.
95   Standard_EXPORT bool HasNonPointSprite() const;
96
97   //! Return TRUE if last texture is a point sprite.
98   Standard_EXPORT bool HasPointSprite() const;
99
100   //! Nullify all handles.
101   void InitZero()
102   {
103     myTextures.Init (Handle(OpenGl_Texture)());
104   }
105
106 protected:
107
108   NCollection_Array1<Handle(OpenGl_Texture)> myTextures;
109
110 };
111
112 #endif //_OpenGl_TextureSet_Header