Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:36

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 
0025   //! Constructor.
0026   OpenGl_TextureSetPairIterator (const Handle(OpenGl_TextureSet)& theSet1,
0027                                  const Handle(OpenGl_TextureSet)& theSet2)
0028   : myIter1 (theSet1),
0029     myIter2 (theSet2),
0030     myTexture1 (NULL),
0031     myTexture2 (NULL),
0032     myUnitLower (IntegerLast()),
0033     myUnitUpper (IntegerFirst()),
0034     myUnitCurrent (0)
0035   {
0036     if (!theSet1.IsNull()
0037      && !theSet1->IsEmpty())
0038     {
0039       myUnitLower = Min (myUnitLower, theSet1->FirstUnit());
0040       myUnitUpper = Max (myUnitUpper, theSet1->LastUnit());
0041     }
0042     if (!theSet2.IsNull()
0043      && !theSet2->IsEmpty())
0044     {
0045       myUnitLower = Min (myUnitLower, theSet2->FirstUnit());
0046       myUnitUpper = Max (myUnitUpper, theSet2->LastUnit());
0047     }
0048     myUnitCurrent = myUnitLower;
0049     myTexture1 = (myIter1.More() && myIter1.Unit() == myUnitCurrent)
0050                ? myIter1.ChangeValue().get()
0051                : NULL;
0052     myTexture2 = (myIter2.More() && myIter2.Unit() == myUnitCurrent)
0053                ? myIter2.ChangeValue().get()
0054                : NULL;
0055   }
0056 
0057   //! Return TRUE if there are more texture units to pass through.
0058   bool More() const { return myUnitCurrent <= myUnitUpper; }
0059 
0060   //! Return current texture unit.
0061   Graphic3d_TextureUnit Unit() const { return (Graphic3d_TextureUnit )myUnitCurrent; }
0062 
0063   //! Access texture from first texture set.
0064   const OpenGl_Texture* Texture1() const { return myTexture1; }
0065 
0066   //! Access texture from second texture set.
0067   const OpenGl_Texture* Texture2() const { return myTexture2; }
0068 
0069   //! Move iterator position to the next pair.
0070   void Next()
0071   {
0072     ++myUnitCurrent;
0073     myTexture1 = myTexture2 = NULL;
0074     for (; myIter1.More(); myIter1.Next())
0075     {
0076       if (myIter1.Unit() >= myUnitCurrent)
0077       {
0078         myTexture1 = myIter1.Unit() == myUnitCurrent ? myIter1.ChangeValue().get() : NULL;
0079         break;
0080       }
0081     }
0082     for (; myIter2.More(); myIter2.Next())
0083     {
0084       if (myIter2.Unit() >= myUnitCurrent)
0085       {
0086         myTexture2 = myIter2.Unit() == myUnitCurrent ? myIter2.ChangeValue().get() : NULL;
0087         break;
0088       }
0089     }
0090   }
0091 
0092 private:
0093 
0094   OpenGl_TextureSet::Iterator myIter1;
0095   OpenGl_TextureSet::Iterator myIter2;
0096   OpenGl_Texture*  myTexture1;
0097   OpenGl_Texture*  myTexture2;
0098   Standard_Integer myUnitLower;
0099   Standard_Integer myUnitUpper;
0100   Standard_Integer myUnitCurrent;
0101 
0102 };
0103 
0104 #endif //_OpenGl_TextureSetPairIterator_Header