0031279: Visualization, TKOpenGl - environment background is misplaced within Ray...
[occt.git] / src / OpenGl / OpenGl_TextureSetPairIterator.hxx
1 // Copyright (c) 2020 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_TextureSetPairIterator_Header
15 #define _OpenGl_TextureSetPairIterator_Header
16
17 #include <OpenGl_TextureSet.hxx>
18
19 //! Class for iterating pair of texture sets through each defined texture slot.
20 //! Note that iterator considers texture slots being in ascending order within OpenGl_TextureSet.
21 class OpenGl_TextureSetPairIterator
22 {
23 public:
24
25   //! Constructor.
26   OpenGl_TextureSetPairIterator (const Handle(OpenGl_TextureSet)& theSet1,
27                                  const Handle(OpenGl_TextureSet)& theSet2)
28   : myIter1 (theSet1),
29     myIter2 (theSet2),
30     myTexture1 (NULL),
31     myTexture2 (NULL),
32     myUnitLower (IntegerLast()),
33     myUnitUpper (IntegerFirst()),
34     myUnitCurrent (0)
35   {
36     if (!theSet1.IsNull()
37      && !theSet1->IsEmpty())
38     {
39       myUnitLower = Min (myUnitLower, theSet1->FirstUnit());
40       myUnitUpper = Max (myUnitUpper, theSet1->LastUnit());
41     }
42     if (!theSet2.IsNull()
43      && !theSet2->IsEmpty())
44     {
45       myUnitLower = Min (myUnitLower, theSet2->FirstUnit());
46       myUnitUpper = Max (myUnitUpper, theSet2->LastUnit());
47     }
48     myUnitCurrent = myUnitLower;
49     myTexture1 = (myIter1.More() && myIter1.Unit() == myUnitCurrent)
50                ? myIter1.ChangeValue().get()
51                : NULL;
52     myTexture2 = (myIter2.More() && myIter2.Unit() == myUnitCurrent)
53                ? myIter2.ChangeValue().get()
54                : NULL;
55   }
56
57   //! Return TRUE if there are more texture units to pass through.
58   bool More() const { return myUnitCurrent <= myUnitUpper; }
59
60   //! Return current texture unit.
61   Graphic3d_TextureUnit Unit() const { return (Graphic3d_TextureUnit )myUnitCurrent; }
62
63   //! Access texture from first texture set.
64   const OpenGl_Texture* Texture1() const { return myTexture1; }
65
66   //! Access texture from second texture set.
67   const OpenGl_Texture* Texture2() const { return myTexture2; }
68
69   //! Move iterator position to the next pair.
70   void Next()
71   {
72     ++myUnitCurrent;
73     myTexture1 = myTexture2 = NULL;
74     for (; myIter1.More(); myIter1.Next())
75     {
76       if (myIter1.Unit() >= myUnitCurrent)
77       {
78         myTexture1 = myIter1.Unit() == myUnitCurrent ? myIter1.ChangeValue().get() : NULL;
79         break;
80       }
81     }
82     for (; myIter2.More(); myIter2.Next())
83     {
84       if (myIter2.Unit() >= myUnitCurrent)
85       {
86         myTexture2 = myIter2.Unit() == myUnitCurrent ? myIter2.ChangeValue().get() : NULL;
87         break;
88       }
89     }
90   }
91
92 private:
93
94   OpenGl_TextureSet::Iterator myIter1;
95   OpenGl_TextureSet::Iterator myIter2;
96   OpenGl_Texture*  myTexture1;
97   OpenGl_Texture*  myTexture2;
98   Standard_Integer myUnitLower;
99   Standard_Integer myUnitUpper;
100   Standard_Integer myUnitCurrent;
101
102 };
103
104 #endif //_OpenGl_TextureSetPairIterator_Header