0030537: Visualization - wrapping text in font text formatter
[occt.git] / src / Graphic3d / Graphic3d_IndexBuffer.hxx
CommitLineData
871fa103 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.
20class Graphic3d_IndexBuffer : public Graphic3d_Buffer
21{
34253146 22 DEFINE_STANDARD_RTTIEXT(Graphic3d_IndexBuffer, Graphic3d_Buffer)
871fa103 23public:
24
25 //! Empty constructor.
26 Graphic3d_IndexBuffer (const Handle(NCollection_BaseAllocator)& theAlloc)
27 : Graphic3d_Buffer (theAlloc) {}
28
29 //! Allocates new empty index array
30 template<typename IndexType_t>
31 bool Init (const Standard_Integer theNbElems)
32 {
33 release();
34 Stride = sizeof(IndexType_t);
35 if (Stride != sizeof(unsigned short)
36 && Stride != sizeof(unsigned int))
37 {
38 return false;
39 }
40
41 NbElements = theNbElems;
42 NbAttributes = 0;
43 if (NbElements != 0
44 && !Allocate (size_t(Stride) * size_t(NbElements)))
45 {
46 release();
47 return false;
48 }
49 return true;
50 }
51
4a535d3f 52 //! Allocates new empty index array
53 bool InitInt32 (const Standard_Integer theNbElems)
54 {
55 return Init<int> (theNbElems);
56 }
57
871fa103 58 //! Access index at specified position
59 Standard_Integer Index (const Standard_Integer theIndex) const
60 {
61 return Stride == sizeof(unsigned short)
62 ? Standard_Integer(Value<unsigned short> (theIndex))
63 : Standard_Integer(Value<unsigned int> (theIndex));
64 }
65
66 //! Change index at specified position
67 void SetIndex (const Standard_Integer theIndex,
68 const Standard_Integer theValue)
69 {
70 if (Stride == sizeof(unsigned short))
71 {
72 ChangeValue<unsigned short> (theIndex) = (unsigned short )theValue;
73 }
74 else
75 {
76 ChangeValue<unsigned int> (theIndex) = (unsigned int )theValue;
77 }
78 }
79
bc73b006 80 //! Dumps the content of me into the stream
81 virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE
82 {
83 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
84 OCCT_DUMP_BASE_CLASS (theOStream, theDepth, Graphic3d_Buffer)
85 }
7d3e64ef 86
871fa103 87};
88
7d3e64ef 89DEFINE_STANDARD_HANDLE(Graphic3d_IndexBuffer, Graphic3d_Buffer)
871fa103 90
91#endif // _Graphic3d_IndexBuffer_HeaderFile