Back to home page

EIC code displayed by LXR

 
 

    


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

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 
0029   //! Texture slot - combination of Texture and binding Unit.
0030   struct TextureSlot
0031   {
0032     Handle(OpenGl_Texture) Texture;
0033     Graphic3d_TextureUnit  Unit;
0034 
0035     operator const Handle(OpenGl_Texture)& () const { return Texture; }
0036     operator       Handle(OpenGl_Texture)& ()       { return Texture; }
0037 
0038     TextureSlot() : Unit (Graphic3d_TextureUnit_0) {}
0039   };
0040 
0041   //! Class for iterating texture set.
0042   class Iterator : public NCollection_Array1<TextureSlot>::Iterator
0043   {
0044   public:
0045     //! Empty constructor.
0046     Iterator() {}
0047 
0048     //! Constructor.
0049     Iterator (const Handle(OpenGl_TextureSet)& theSet)
0050     {
0051       if (!theSet.IsNull())
0052       {
0053         NCollection_Array1<TextureSlot>::Iterator::Init (theSet->myTextures);
0054       }
0055     }
0056 
0057     //! Access texture.
0058     const Handle(OpenGl_Texture)& Value() const { return NCollection_Array1<TextureSlot>::Iterator::Value().Texture; }
0059     Handle(OpenGl_Texture)& ChangeValue()       { return NCollection_Array1<TextureSlot>::Iterator::ChangeValue().Texture; }
0060 
0061     //! Access texture unit.
0062     Graphic3d_TextureUnit  Unit() const { return NCollection_Array1<TextureSlot>::Iterator::Value().Unit; }
0063     Graphic3d_TextureUnit& ChangeUnit() { return NCollection_Array1<TextureSlot>::Iterator::ChangeValue().Unit; }
0064   };
0065 
0066 public:
0067 
0068   //! Empty constructor.
0069   OpenGl_TextureSet() : myTextureSetBits (Graphic3d_TextureSetBits_NONE) {}
0070 
0071   //! Constructor.
0072   OpenGl_TextureSet (Standard_Integer theNbTextures)
0073   : myTextures (0, theNbTextures - 1),
0074     myTextureSetBits (Graphic3d_TextureSetBits_NONE) {}
0075 
0076   //! Constructor for a single texture.
0077   Standard_EXPORT OpenGl_TextureSet (const Handle(OpenGl_Texture)& theTexture);
0078 
0079   //! Return texture units declared within the program, @sa Graphic3d_TextureSetBits.
0080   Standard_Integer TextureSetBits() const { return myTextureSetBits; }
0081 
0082   //! Return texture units declared within the program, @sa Graphic3d_TextureSetBits.
0083   Standard_Integer& ChangeTextureSetBits() { return myTextureSetBits; }
0084 
0085   //! Return TRUE if texture array is empty.
0086   Standard_Boolean IsEmpty() const { return myTextures.IsEmpty(); }
0087 
0088   //! Return number of textures.
0089   Standard_Integer Size() const { return myTextures.Size(); }
0090 
0091   //! Return the lower index in texture set.
0092   Standard_Integer Lower() const { return myTextures.Lower(); }
0093 
0094   //! Return the upper index in texture set.
0095   Standard_Integer Upper() const { return myTextures.Upper(); }
0096 
0097   //! Return the first texture.
0098   const Handle(OpenGl_Texture)& First() const { return myTextures.First().Texture; }
0099 
0100   //! Return the first texture.
0101   Handle(OpenGl_Texture)& ChangeFirst() { return myTextures.ChangeFirst().Texture; }
0102 
0103   //! Return the first texture unit.
0104   Graphic3d_TextureUnit FirstUnit() const { return myTextures.First().Unit; }
0105 
0106   //! Return the last texture.
0107   const Handle(OpenGl_Texture)& Last() const { return myTextures.Last().Texture; }
0108 
0109   //! Return the last texture.
0110   Handle(OpenGl_Texture)& ChangeLast() { return myTextures.ChangeLast().Texture; }
0111 
0112   //! Return the last texture unit.
0113   Graphic3d_TextureUnit LastUnit() const { return myTextures.Last().Unit; }
0114 
0115   //! Return the last texture unit.
0116   Graphic3d_TextureUnit& ChangeLastUnit() { return myTextures.ChangeLast().Unit; }
0117 
0118   //! Return the texture at specified position within [0, Size()) range.
0119   const Handle(OpenGl_Texture)& Value (Standard_Integer theIndex) const { return myTextures.Value (theIndex).Texture; }
0120 
0121   //! Return the texture at specified position within [0, Size()) range.
0122   Handle(OpenGl_Texture)& ChangeValue (Standard_Integer theIndex) { return myTextures.ChangeValue (theIndex).Texture; }
0123 
0124   //! Return TRUE if texture color modulation has been enabled for the first texture
0125   //! or if texture is not set at all.
0126   Standard_EXPORT bool IsModulate() const;
0127 
0128   //! Return TRUE if other than point sprite textures are defined within point set.
0129   Standard_EXPORT bool HasNonPointSprite() const;
0130 
0131   //! Return TRUE if last texture is a point sprite.
0132   Standard_EXPORT bool HasPointSprite() const;
0133 
0134   //! Nullify all handles.
0135   void InitZero()
0136   {
0137     myTextures.Init (TextureSlot());
0138     myTextureSetBits = Graphic3d_TextureSetBits_NONE;
0139   }
0140 
0141 protected:
0142 
0143   NCollection_Array1<TextureSlot> myTextures;
0144   Standard_Integer myTextureSetBits;
0145 
0146 };
0147 
0148 #endif //_OpenGl_TextureSet_Header