Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-13 09:16:36

0001 // Copyright (c) 2014 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 _Graphic3d_IndexBuffer_HeaderFile
0015 #define _Graphic3d_IndexBuffer_HeaderFile
0016 
0017 #include <Graphic3d_Buffer.hxx>
0018 
0019 //! Index buffer.
0020 class Graphic3d_IndexBuffer : public Graphic3d_Buffer
0021 {
0022   DEFINE_STANDARD_RTTIEXT(Graphic3d_IndexBuffer, Graphic3d_Buffer)
0023 public:
0024   //! Empty constructor.
0025   Graphic3d_IndexBuffer(const occ::handle<NCollection_BaseAllocator>& theAlloc)
0026       : Graphic3d_Buffer(theAlloc)
0027   {
0028   }
0029 
0030   //! Allocates new empty index array
0031   template <typename IndexType_t>
0032   bool Init(const int theNbElems)
0033   {
0034     release();
0035     Stride = sizeof(IndexType_t);
0036     if (Stride != sizeof(unsigned short) && Stride != sizeof(unsigned int))
0037     {
0038       return false;
0039     }
0040 
0041     NbElements   = theNbElems;
0042     NbAttributes = 0;
0043     if (NbElements != 0 && !Allocate(size_t(Stride) * size_t(NbElements)))
0044     {
0045       release();
0046       return false;
0047     }
0048     return true;
0049   }
0050 
0051   //! Allocates new empty index array
0052   bool InitInt32(const int theNbElems) { return Init<int>(theNbElems); }
0053 
0054   //! Access index at specified position
0055   int Index(const int theIndex) const
0056   {
0057     return Stride == sizeof(unsigned short) ? int(Value<unsigned short>(theIndex))
0058                                             : int(Value<unsigned int>(theIndex));
0059   }
0060 
0061   //! Change index at specified position
0062   void SetIndex(const int theIndex, const int theValue)
0063   {
0064     if (Stride == sizeof(unsigned short))
0065     {
0066       ChangeValue<unsigned short>(theIndex) = (unsigned short)theValue;
0067     }
0068     else
0069     {
0070       ChangeValue<unsigned int>(theIndex) = (unsigned int)theValue;
0071     }
0072   }
0073 
0074   //! Dumps the content of me into the stream
0075   void DumpJson(Standard_OStream& theOStream, int theDepth = -1) const override
0076   {
0077     OCCT_DUMP_TRANSIENT_CLASS_BEGIN(theOStream)
0078     OCCT_DUMP_BASE_CLASS(theOStream, theDepth, Graphic3d_Buffer)
0079   }
0080 };
0081 
0082 #endif // _Graphic3d_IndexBuffer_HeaderFile