Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03:48

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 
0025   //! Empty constructor.
0026   Graphic3d_IndexBuffer (const Handle(NCollection_BaseAllocator)& theAlloc)
0027   : Graphic3d_Buffer (theAlloc) {}
0028 
0029   //! Allocates new empty index array
0030   template<typename IndexType_t>
0031   bool Init (const Standard_Integer theNbElems)
0032   {
0033     release();
0034     Stride = sizeof(IndexType_t);
0035     if (Stride != sizeof(unsigned short)
0036      && Stride != sizeof(unsigned int))
0037     {
0038       return false;
0039     }
0040 
0041     NbElements   = theNbElems;
0042     NbAttributes = 0;
0043     if (NbElements != 0
0044     && !Allocate (size_t(Stride) * size_t(NbElements)))
0045     {
0046       release();
0047       return false;
0048     }
0049     return true;
0050   }
0051 
0052   //! Allocates new empty index array
0053   bool InitInt32 (const Standard_Integer theNbElems)
0054   {
0055     return Init<int> (theNbElems);
0056   }
0057 
0058   //! Access index at specified position
0059   Standard_Integer Index (const Standard_Integer theIndex) const
0060   {
0061     return Stride == sizeof(unsigned short)
0062          ? Standard_Integer(Value<unsigned short> (theIndex))
0063          : Standard_Integer(Value<unsigned int>   (theIndex));
0064   }
0065 
0066   //! Change index at specified position
0067   void SetIndex (const Standard_Integer theIndex,
0068                  const Standard_Integer theValue)
0069   {
0070     if (Stride == sizeof(unsigned short))
0071     {
0072       ChangeValue<unsigned short> (theIndex) = (unsigned short )theValue;
0073     }
0074     else
0075     {
0076       ChangeValue<unsigned int>   (theIndex) = (unsigned int   )theValue;
0077     }
0078   }
0079 
0080   //! Dumps the content of me into the stream
0081   virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE
0082   {
0083     OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
0084     OCCT_DUMP_BASE_CLASS (theOStream, theDepth, Graphic3d_Buffer)
0085   }
0086 
0087 };
0088 
0089 DEFINE_STANDARD_HANDLE(Graphic3d_IndexBuffer, Graphic3d_Buffer)
0090 
0091 #endif // _Graphic3d_IndexBuffer_HeaderFile