| 1 | // Copyright (c) 2014 OPEN CASCADE SAS |
| 2 | // |
| 3 | // This file is part of Open CASCADE Technology software library. |
| 4 | // |
| 5 | // This library is free software; you can redistribute it and/or modify it under |
| 6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
| 7 | // by the Free Software Foundation, with special exception defined in the file |
| 8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
| 9 | // distribution for complete text of the license and disclaimer of any warranty. |
| 10 | // |
| 11 | // Alternatively, this file may be used under the terms of Open CASCADE |
| 12 | // commercial license or contractual agreement. |
| 13 | |
| 14 | #ifndef _Graphic3d_IndexBuffer_HeaderFile |
| 15 | #define _Graphic3d_IndexBuffer_HeaderFile |
| 16 | |
| 17 | #include <Graphic3d_Buffer.hxx> |
| 18 | |
| 19 | //! Index buffer. |
| 20 | class Graphic3d_IndexBuffer : public Graphic3d_Buffer |
| 21 | { |
| 22 | public: |
| 23 | |
| 24 | //! Empty constructor. |
| 25 | Graphic3d_IndexBuffer (const Handle(NCollection_BaseAllocator)& theAlloc) |
| 26 | : Graphic3d_Buffer (theAlloc) {} |
| 27 | |
| 28 | //! Allocates new empty index array |
| 29 | template<typename IndexType_t> |
| 30 | bool Init (const Standard_Integer theNbElems) |
| 31 | { |
| 32 | release(); |
| 33 | Stride = sizeof(IndexType_t); |
| 34 | if (Stride != sizeof(unsigned short) |
| 35 | && Stride != sizeof(unsigned int)) |
| 36 | { |
| 37 | return false; |
| 38 | } |
| 39 | |
| 40 | NbElements = theNbElems; |
| 41 | NbAttributes = 0; |
| 42 | if (NbElements != 0 |
| 43 | && !Allocate (size_t(Stride) * size_t(NbElements))) |
| 44 | { |
| 45 | release(); |
| 46 | return false; |
| 47 | } |
| 48 | return true; |
| 49 | } |
| 50 | |
| 51 | //! Allocates new empty index array |
| 52 | bool InitInt32 (const Standard_Integer theNbElems) |
| 53 | { |
| 54 | return Init<int> (theNbElems); |
| 55 | } |
| 56 | |
| 57 | //! Access index at specified position |
| 58 | Standard_Integer Index (const Standard_Integer theIndex) const |
| 59 | { |
| 60 | return Stride == sizeof(unsigned short) |
| 61 | ? Standard_Integer(Value<unsigned short> (theIndex)) |
| 62 | : Standard_Integer(Value<unsigned int> (theIndex)); |
| 63 | } |
| 64 | |
| 65 | //! Change index at specified position |
| 66 | void SetIndex (const Standard_Integer theIndex, |
| 67 | const Standard_Integer theValue) |
| 68 | { |
| 69 | if (Stride == sizeof(unsigned short)) |
| 70 | { |
| 71 | ChangeValue<unsigned short> (theIndex) = (unsigned short )theValue; |
| 72 | } |
| 73 | else |
| 74 | { |
| 75 | ChangeValue<unsigned int> (theIndex) = (unsigned int )theValue; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | public: |
| 80 | |
| 81 | DEFINE_STANDARD_RTTI_INLINE(Graphic3d_IndexBuffer,Graphic3d_Buffer) // Type definition |
| 82 | |
| 83 | }; |
| 84 | |
| 85 | DEFINE_STANDARD_HANDLE(Graphic3d_IndexBuffer, Graphic3d_Buffer) |
| 86 | |
| 87 | #endif // _Graphic3d_IndexBuffer_HeaderFile |