Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-22 08:59:04

0001 // Copyright (c) 2017 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_TextureSet_Header
0015 #define _OpenGl_TextureSet_Header
0016 
0017 #include <Graphic3d_TextureSet.hxx>
0018 #include <Graphic3d_TextureSetBits.hxx>
0019 
0020 class OpenGl_Texture;
0021 
0022 //! Class holding array of textures to be mapped as a set.
0023 //! Textures should be defined in ascending order of texture units within the set.
0024 class OpenGl_TextureSet : public Standard_Transient
0025 {
0026   DEFINE_STANDARD_RTTIEXT(OpenGl_TextureSet, Standard_Transient)
0027 public:
0028   //! Texture slot - combination of Texture and binding Unit.
0029   struct TextureSlot
0030   {
0031     occ::handle<OpenGl_Texture> Texture;
0032     Graphic3d_TextureUnit       Unit;
0033 
0034     operator const occ::handle<OpenGl_Texture>&() const { return Texture; }
0035 
0036     operator occ::handle<OpenGl_Texture>&() { return Texture; }
0037 
0038     TextureSlot()
0039         : Unit(Graphic3d_TextureUnit_0)
0040     {
0041     }
0042   };
0043 
0044   //! Class for iterating texture set.
0045   class Iterator : public NCollection_Array1<TextureSlot>::Iterator
0046   {
0047   public:
0048     //! Empty constructor.
0049     Iterator() = default;
0050 
0051     //! Constructor.
0052     Iterator(const occ::handle<OpenGl_TextureSet>& theSet)
0053     {
0054       if (!theSet.IsNull())
0055       {
0056         NCollection_Array1<TextureSlot>::Iterator::Init(theSet->myTextures);
0057       }
0058     }
0059 
0060     //! Access texture.
0061     const occ::handle<OpenGl_Texture>& Value() const
0062     {
0063       return NCollection_Array1<TextureSlot>::Iterator::Value().Texture;
0064     }
0065 
0066     occ::handle<OpenGl_Texture>& ChangeValue()
0067     {
0068       return NCollection_Array1<TextureSlot>::Iterator::ChangeValue().Texture;
0069     }
0070 
0071     //! Access texture unit.
0072     Graphic3d_TextureUnit Unit() const
0073     {
0074       return NCollection_Array1<TextureSlot>::Iterator::Value().Unit;
0075     }
0076 
0077     Graphic3d_TextureUnit& ChangeUnit()
0078     {
0079       return NCollection_Array1<TextureSlot>::Iterator::ChangeValue().Unit;
0080     }
0081   };
0082 
0083 public:
0084   //! Empty constructor.
0085   OpenGl_TextureSet()
0086       : myTextureSetBits(Graphic3d_TextureSetBits_NONE)
0087   {
0088   }
0089 
0090   //! Constructor.
0091   OpenGl_TextureSet(int theNbTextures)
0092       : myTextures(0, theNbTextures - 1),
0093         myTextureSetBits(Graphic3d_TextureSetBits_NONE)
0094   {
0095   }
0096 
0097   //! Constructor for a single texture.
0098   Standard_EXPORT OpenGl_TextureSet(const occ::handle<OpenGl_Texture>& theTexture);
0099 
0100   //! Return texture units declared within the program, @sa Graphic3d_TextureSetBits.
0101   int TextureSetBits() const { return myTextureSetBits; }
0102 
0103   //! Return texture units declared within the program, @sa Graphic3d_TextureSetBits.
0104   int& ChangeTextureSetBits() { return myTextureSetBits; }
0105 
0106   //! Return TRUE if texture array is empty.
0107   bool IsEmpty() const { return myTextures.IsEmpty(); }
0108 
0109   //! Return number of textures.
0110   int Size() const { return myTextures.Length(); }
0111 
0112   //! Return the lower index in texture set.
0113   int Lower() const { return myTextures.Lower(); }
0114 
0115   //! Return the upper index in texture set.
0116   int Upper() const { return myTextures.Upper(); }
0117 
0118   //! Return the first texture.
0119   const occ::handle<OpenGl_Texture>& First() const { return myTextures.First().Texture; }
0120 
0121   //! Return the first texture.
0122   occ::handle<OpenGl_Texture>& ChangeFirst() { return myTextures.ChangeFirst().Texture; }
0123 
0124   //! Return the first texture unit.
0125   Graphic3d_TextureUnit FirstUnit() const { return myTextures.First().Unit; }
0126 
0127   //! Return the last texture.
0128   const occ::handle<OpenGl_Texture>& Last() const { return myTextures.Last().Texture; }
0129 
0130   //! Return the last texture.
0131   occ::handle<OpenGl_Texture>& ChangeLast() { return myTextures.ChangeLast().Texture; }
0132 
0133   //! Return the last texture unit.
0134   Graphic3d_TextureUnit LastUnit() const { return myTextures.Last().Unit; }
0135 
0136   //! Return the last texture unit.
0137   Graphic3d_TextureUnit& ChangeLastUnit() { return myTextures.ChangeLast().Unit; }
0138 
0139   //! Return the texture at specified position within [0, Size()) range.
0140   const occ::handle<OpenGl_Texture>& Value(int theIndex) const
0141   {
0142     return myTextures.Value(theIndex).Texture;
0143   }
0144 
0145   //! Return the texture at specified position within [0, Size()) range.
0146   occ::handle<OpenGl_Texture>& ChangeValue(int theIndex)
0147   {
0148     return myTextures.ChangeValue(theIndex).Texture;
0149   }
0150 
0151   //! Return TRUE if texture color modulation has been enabled for the first texture
0152   //! or if texture is not set at all.
0153   Standard_EXPORT bool IsModulate() const;
0154 
0155   //! Return TRUE if other than point sprite textures are defined within point set.
0156   Standard_EXPORT bool HasNonPointSprite() const;
0157 
0158   //! Return TRUE if last texture is a point sprite.
0159   Standard_EXPORT bool HasPointSprite() const;
0160 
0161   //! Nullify all handles.
0162   void InitZero()
0163   {
0164     myTextures.Init(TextureSlot());
0165     myTextureSetBits = Graphic3d_TextureSetBits_NONE;
0166   }
0167 
0168 protected:
0169   NCollection_Array1<TextureSlot> myTextures;
0170   int                             myTextureSetBits;
0171 };
0172 
0173 #endif //_OpenGl_TextureSet_Header