cc8cbabe |
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> |
72f6dc61 |
18 | #include <Graphic3d_TextureSetBits.hxx> |
cc8cbabe |
19 | |
20 | class OpenGl_Texture; |
21 | |
22 | //! Class holding array of textures to be mapped as a set. |
d850414a |
23 | //! Textures should be defined in ascending order of texture units within the set. |
cc8cbabe |
24 | class OpenGl_TextureSet : public Standard_Transient |
25 | { |
26 | DEFINE_STANDARD_RTTIEXT(OpenGl_TextureSet, Standard_Transient) |
27 | public: |
28 | |
72f6dc61 |
29 | //! Texture slot - combination of Texture and binding Unit. |
30 | struct TextureSlot |
31 | { |
32 | Handle(OpenGl_Texture) Texture; |
33 | Graphic3d_TextureUnit Unit; |
34 | |
35 | operator const Handle(OpenGl_Texture)& () const { return Texture; } |
36 | operator Handle(OpenGl_Texture)& () { return Texture; } |
37 | |
38 | TextureSlot() : Unit (Graphic3d_TextureUnit_0) {} |
39 | }; |
40 | |
cc8cbabe |
41 | //! Class for iterating texture set. |
72f6dc61 |
42 | class Iterator : public NCollection_Array1<TextureSlot>::Iterator |
cc8cbabe |
43 | { |
44 | public: |
45 | //! Empty constructor. |
46 | Iterator() {} |
47 | |
48 | //! Constructor. |
49 | Iterator (const Handle(OpenGl_TextureSet)& theSet) |
50 | { |
51 | if (!theSet.IsNull()) |
52 | { |
72f6dc61 |
53 | NCollection_Array1<TextureSlot>::Iterator::Init (theSet->myTextures); |
cc8cbabe |
54 | } |
55 | } |
72f6dc61 |
56 | |
57 | //! Access texture. |
58 | const Handle(OpenGl_Texture)& Value() const { return NCollection_Array1<TextureSlot>::Iterator::Value().Texture; } |
59 | Handle(OpenGl_Texture)& ChangeValue() { return NCollection_Array1<TextureSlot>::Iterator::ChangeValue().Texture; } |
60 | |
61 | //! Access texture unit. |
62 | Graphic3d_TextureUnit Unit() const { return NCollection_Array1<TextureSlot>::Iterator::Value().Unit; } |
63 | Graphic3d_TextureUnit& ChangeUnit() { return NCollection_Array1<TextureSlot>::Iterator::ChangeValue().Unit; } |
cc8cbabe |
64 | }; |
65 | |
66 | public: |
67 | |
68 | //! Empty constructor. |
72f6dc61 |
69 | OpenGl_TextureSet() : myTextureSetBits (Graphic3d_TextureSetBits_NONE) {} |
cc8cbabe |
70 | |
71 | //! Constructor. |
72 | OpenGl_TextureSet (Standard_Integer theNbTextures) |
72f6dc61 |
73 | : myTextures (0, theNbTextures - 1), |
74 | myTextureSetBits (Graphic3d_TextureSetBits_NONE) {} |
cc8cbabe |
75 | |
76 | //! Constructor for a single texture. |
72f6dc61 |
77 | Standard_EXPORT OpenGl_TextureSet (const Handle(OpenGl_Texture)& theTexture); |
78 | |
79 | //! Return texture units declared within the program, @sa Graphic3d_TextureSetBits. |
80 | Standard_Integer TextureSetBits() const { return myTextureSetBits; } |
81 | |
82 | //! Return texture units declared within the program, @sa Graphic3d_TextureSetBits. |
83 | Standard_Integer& ChangeTextureSetBits() { return myTextureSetBits; } |
cc8cbabe |
84 | |
85 | //! Return TRUE if texture array is empty. |
86 | Standard_Boolean IsEmpty() const { return myTextures.IsEmpty(); } |
87 | |
88 | //! Return number of textures. |
89 | Standard_Integer Size() const { return myTextures.Size(); } |
90 | |
91 | //! Return the lower index in texture set. |
92 | Standard_Integer Lower() const { return myTextures.Lower(); } |
93 | |
94 | //! Return the upper index in texture set. |
95 | Standard_Integer Upper() const { return myTextures.Upper(); } |
96 | |
97 | //! Return the first texture. |
72f6dc61 |
98 | const Handle(OpenGl_Texture)& First() const { return myTextures.First().Texture; } |
cc8cbabe |
99 | |
100 | //! Return the first texture. |
72f6dc61 |
101 | Handle(OpenGl_Texture)& ChangeFirst() { return myTextures.ChangeFirst().Texture; } |
cc8cbabe |
102 | |
d850414a |
103 | //! Return the first texture unit. |
104 | Graphic3d_TextureUnit FirstUnit() const { return myTextures.First().Unit; } |
105 | |
737e9a8d |
106 | //! Return the last texture. |
72f6dc61 |
107 | const Handle(OpenGl_Texture)& Last() const { return myTextures.Last().Texture; } |
737e9a8d |
108 | |
109 | //! Return the last texture. |
72f6dc61 |
110 | Handle(OpenGl_Texture)& ChangeLast() { return myTextures.ChangeLast().Texture; } |
111 | |
d850414a |
112 | //! Return the last texture unit. |
113 | Graphic3d_TextureUnit LastUnit() const { return myTextures.Last().Unit; } |
114 | |
72f6dc61 |
115 | //! Return the last texture unit. |
116 | Graphic3d_TextureUnit& ChangeLastUnit() { return myTextures.ChangeLast().Unit; } |
737e9a8d |
117 | |
cc8cbabe |
118 | //! Return the texture at specified position within [0, Size()) range. |
72f6dc61 |
119 | const Handle(OpenGl_Texture)& Value (Standard_Integer theIndex) const { return myTextures.Value (theIndex).Texture; } |
cc8cbabe |
120 | |
121 | //! Return the texture at specified position within [0, Size()) range. |
72f6dc61 |
122 | Handle(OpenGl_Texture)& ChangeValue (Standard_Integer theIndex) { return myTextures.ChangeValue (theIndex).Texture; } |
cc8cbabe |
123 | |
dc89236f |
124 | //! Return TRUE if texture color modulation has been enabled for the first texture |
125 | //! or if texture is not set at all. |
126 | Standard_EXPORT bool IsModulate() const; |
127 | |
737e9a8d |
128 | //! Return TRUE if other than point sprite textures are defined within point set. |
129 | Standard_EXPORT bool HasNonPointSprite() const; |
130 | |
131 | //! Return TRUE if last texture is a point sprite. |
132 | Standard_EXPORT bool HasPointSprite() const; |
133 | |
134 | //! Nullify all handles. |
135 | void InitZero() |
136 | { |
72f6dc61 |
137 | myTextures.Init (TextureSlot()); |
138 | myTextureSetBits = Graphic3d_TextureSetBits_NONE; |
737e9a8d |
139 | } |
140 | |
cc8cbabe |
141 | protected: |
142 | |
72f6dc61 |
143 | NCollection_Array1<TextureSlot> myTextures; |
144 | Standard_Integer myTextureSetBits; |
cc8cbabe |
145 | |
146 | }; |
147 | |
148 | #endif //_OpenGl_TextureSet_Header |