1 // Copyright (c) 2018 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <Graphic3d_AttribBuffer.hxx>
16 IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_AttribBuffer, Graphic3d_Buffer)
18 // =======================================================================
19 // function : Graphic3d_AttribBuffer
21 // =======================================================================
22 Graphic3d_AttribBuffer::Graphic3d_AttribBuffer(const Handle(NCollection_BaseAllocator)& theAlloc)
23 : Graphic3d_Buffer (theAlloc),
24 myIsInterleaved (Standard_True),
25 myIsMutable (Standard_False)
29 // =======================================================================
32 // =======================================================================
33 bool Graphic3d_AttribBuffer::Init (const Standard_Integer theNbElems,
34 const Graphic3d_Attribute* theAttribs,
35 const Standard_Integer theNbAttribs)
37 if (!Graphic3d_Buffer::Init (theNbElems, theAttribs, theNbAttribs))
42 if (mySize > (Standard_Size )IntegerLast()
45 throw Standard_OutOfRange ("Graphic3d_AttribBuffer::Init(), Mutable flag cannot be used for buffer exceeding 32-bit address space");
50 // =======================================================================
51 // function : SetMutable
53 // =======================================================================
54 void Graphic3d_AttribBuffer::SetMutable (Standard_Boolean theMutable)
56 if (mySize > (Standard_Size )IntegerLast()
59 throw Standard_OutOfRange ("Graphic3d_AttribBuffer::SetMutable(), Mutable flag cannot be used for buffer exceeding 32-bit address space");
61 myIsMutable = theMutable;
64 // =======================================================================
65 // function : Invalidate
67 // =======================================================================
68 void Graphic3d_AttribBuffer::SetInterleaved (Standard_Boolean theIsInterleaved)
70 if (NbMaxElements() != 0)
72 throw Standard_ProgramError ("Graphic3d_AttribBuffer::SetInterleaved() should not be called for allocated buffer");
74 myIsInterleaved = theIsInterleaved;
77 // =======================================================================
78 // function : invalidate
80 // =======================================================================
81 void Graphic3d_AttribBuffer::invalidate (const Graphic3d_BufferRange& theRange)
83 if (mySize > (Standard_Size )IntegerLast())
85 throw Standard_OutOfRange ("Graphic3d_Buffer::Invalidate() cannot be used for buffer exceeding 32-bit address space");
88 myInvalidatedRange.Unite (theRange);
91 // =======================================================================
92 // function : Invalidate
94 // =======================================================================
95 void Graphic3d_AttribBuffer::Invalidate()
97 if (mySize > (Standard_Size )IntegerLast())
99 throw Standard_OutOfRange ("Graphic3d_AttribBuffer::Invalidate() cannot be used for buffer exceeding 32-bit address space");
102 invalidate (Graphic3d_BufferRange (0, (Standard_Integer )mySize));
105 // =======================================================================
106 // function : Invalidate
108 // =======================================================================
109 void Graphic3d_AttribBuffer::Invalidate (Standard_Integer theAttributeIndex)
111 Standard_OutOfRange_Raise_if (theAttributeIndex < 0
112 || theAttributeIndex >= NbAttributes, "Graphic3d_AttribBuffer::Invalidate()");
119 Graphic3d_BufferRange aRange;
120 const Standard_Integer aNbMaxVerts = NbMaxElements();
121 for (Standard_Integer anAttribIter = 0; anAttribIter < NbAttributes; ++anAttribIter)
123 const Graphic3d_Attribute& anAttrib = Attribute (anAttribIter);
124 const Standard_Integer anAttribStride = Graphic3d_Attribute::Stride (anAttrib.DataType);
125 if (anAttribIter == theAttributeIndex)
127 aRange.Length = anAttribStride * aNbMaxVerts;
132 aRange.Start += anAttribStride * aNbMaxVerts;
136 // =======================================================================
137 // function : Invalidate
139 // =======================================================================
140 void Graphic3d_AttribBuffer::Invalidate (Standard_Integer theAttributeIndex,
141 Standard_Integer theVertexLower,
142 Standard_Integer theVertexUpper)
144 Standard_OutOfRange_Raise_if (theAttributeIndex < 0
145 || theAttributeIndex >= NbAttributes
146 || theVertexLower < 0
147 || theVertexLower > theVertexUpper
148 || theVertexUpper >= NbMaxElements(), "Graphic3d_AttribBuffer::Invalidate()");
151 Invalidate (theVertexLower, theVertexUpper);
155 Graphic3d_BufferRange aRange;
156 const Standard_Integer aNbMaxVerts = NbMaxElements();
157 for (Standard_Integer anAttribIter = 0; anAttribIter < NbAttributes; ++anAttribIter)
159 const Graphic3d_Attribute& anAttrib = Attribute (anAttribIter);
160 const Standard_Integer anAttribStride = Graphic3d_Attribute::Stride (anAttrib.DataType);
161 if (anAttribIter == theAttributeIndex)
163 aRange.Start += anAttribStride * theVertexLower;
164 aRange.Length = anAttribStride * (theVertexUpper - theVertexLower + 1);
169 aRange.Start += anAttribStride * aNbMaxVerts;
173 // =======================================================================
174 // function : Invalidate
176 // =======================================================================
177 void Graphic3d_AttribBuffer::Invalidate (Standard_Integer theVertexLower,
178 Standard_Integer theVertexUpper)
180 Standard_OutOfRange_Raise_if (theVertexLower < 0
181 || theVertexLower > theVertexUpper
182 || theVertexUpper >= NbMaxElements(), "Graphic3d_AttribBuffer::Invalidate()");
185 invalidate (Graphic3d_BufferRange (Stride * theVertexLower,
186 Stride * (theVertexUpper - theVertexLower + 1)));
190 for (Standard_Integer anAttribIter = 0; anAttribIter < NbAttributes; ++anAttribIter)
192 Invalidate (anAttribIter, theVertexLower, theVertexUpper);