Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-16 08:22:17

0001 // Copyright (c) 2020 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _OpenGl_TextureSetPairIterator_Header
0015 #define _OpenGl_TextureSetPairIterator_Header
0016 
0017 #include <OpenGl_TextureSet.hxx>
0018 
0019 //! Class for iterating pair of texture sets through each defined texture slot.
0020 //! Note that iterator considers texture slots being in ascending order within OpenGl_TextureSet.
0021 class OpenGl_TextureSetPairIterator
0022 {
0023 public:
0024   //! Constructor.
0025   OpenGl_TextureSetPairIterator(const Handle(OpenGl_TextureSet)& theSet1,
0026                                 const Handle(OpenGl_TextureSet)& theSet2)
0027       : myIter1(theSet1),
0028         myIter2(theSet2),
0029         myTexture1(NULL),
0030         myTexture2(NULL),
0031         myUnitLower(IntegerLast()),
0032         myUnitUpper(IntegerFirst()),
0033         myUnitCurrent(0)
0034   {
0035     if (!theSet1.IsNull() && !theSet1->IsEmpty())
0036     {
0037       myUnitLower = Min(myUnitLower, theSet1->FirstUnit());
0038       myUnitUpper = Max(myUnitUpper, theSet1->LastUnit());
0039     }
0040     if (!theSet2.IsNull() && !theSet2->IsEmpty())
0041     {
0042       myUnitLower = Min(myUnitLower, theSet2->FirstUnit());
0043       myUnitUpper = Max(myUnitUpper, theSet2->LastUnit());
0044     }
0045     myUnitCurrent = myUnitLower;
0046     myTexture1 =
0047       (myIter1.More() && myIter1.Unit() == myUnitCurrent) ? myIter1.ChangeValue().get() : NULL;
0048     myTexture2 =
0049       (myIter2.More() && myIter2.Unit() == myUnitCurrent) ? myIter2.ChangeValue().get() : NULL;
0050   }
0051 
0052   //! Return TRUE if there are more texture units to pass through.
0053   bool More() const { return myUnitCurrent <= myUnitUpper; }
0054 
0055   //! Return current texture unit.
0056   Graphic3d_TextureUnit Unit() const { return (Graphic3d_TextureUnit)myUnitCurrent; }
0057 
0058   //! Access texture from first texture set.
0059   const OpenGl_Texture* Texture1() const { return myTexture1; }
0060 
0061   //! Access texture from second texture set.
0062   const OpenGl_Texture* Texture2() const { return myTexture2; }
0063 
0064   //! Move iterator position to the next pair.
0065   void Next()
0066   {
0067     ++myUnitCurrent;
0068     myTexture1 = myTexture2 = NULL;
0069     for (; myIter1.More(); myIter1.Next())
0070     {
0071       if (myIter1.Unit() >= myUnitCurrent)
0072       {
0073         myTexture1 = myIter1.Unit() == myUnitCurrent ? myIter1.ChangeValue().get() : NULL;
0074         break;
0075       }
0076     }
0077     for (; myIter2.More(); myIter2.Next())
0078     {
0079       if (myIter2.Unit() >= myUnitCurrent)
0080       {
0081         myTexture2 = myIter2.Unit() == myUnitCurrent ? myIter2.ChangeValue().get() : NULL;
0082         break;
0083       }
0084     }
0085   }
0086 
0087 private:
0088   OpenGl_TextureSet::Iterator myIter1;
0089   OpenGl_TextureSet::Iterator myIter2;
0090   OpenGl_Texture*             myTexture1;
0091   OpenGl_Texture*             myTexture2;
0092   Standard_Integer            myUnitLower;
0093   Standard_Integer            myUnitUpper;
0094   Standard_Integer            myUnitCurrent;
0095 };
0096 
0097 #endif //_OpenGl_TextureSetPairIterator_Header