Graphic3d_Buffer and classes for arrays of primitives support now the non-interleaved mode for the attributes storage
Graphic3d_AspectText3d.cxx
Graphic3d_AspectText3d.hxx
Graphic3d_AspectTextDefinitionError.hxx
+Graphic3d_AttribBuffer.cxx
+Graphic3d_AttribBuffer.hxx
Graphic3d_BndBox3d.hxx
Graphic3d_BndBox4d.hxx
Graphic3d_BndBox4f.hxx
//! @param theHasVNormals when TRUE, AddVertex(Point,Normal) should be used for specifying vertex normal
Graphic3d_ArrayOfPoints (const Standard_Integer theMaxVertexs,
const Standard_Boolean theHasVColors = Standard_False,
- const Standard_Boolean theHasVNormals = Standard_False)
- : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_POINTS, theMaxVertexs, 0, 0, theHasVNormals, theHasVColors, Standard_False, Standard_False) {}
+ const Standard_Boolean theHasVNormals = Standard_False,
+ const Standard_Boolean theIsInterleaved = Standard_True,
+ const Standard_Boolean theIsMutable = Standard_False)
+ : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_POINTS, theMaxVertexs, 0, 0, theHasVNormals, theHasVColors, Standard_False, Standard_False, theIsInterleaved, theIsMutable) {}
};
const Standard_Boolean theHasVNormals = Standard_False,
const Standard_Boolean theHasVColors = Standard_False,
const Standard_Boolean theHasBColors = Standard_False,
- const Standard_Boolean theHasVTexels = Standard_False)
- : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_POLYGONS, theMaxVertexs, theMaxBounds, theMaxEdges, theHasVNormals, theHasVColors, theHasBColors, theHasVTexels) {}
+ const Standard_Boolean theHasVTexels = Standard_False,
+ const Standard_Boolean theIsInterleaved = Standard_True,
+ const Standard_Boolean theIsMutable = Standard_False)
+ : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_POLYGONS, theMaxVertexs, theMaxBounds, theMaxEdges, theHasVNormals, theHasVColors, theHasBColors, theHasVTexels, theIsInterleaved, theIsMutable) {}
};
const Standard_Integer theMaxBounds = 0,
const Standard_Integer theMaxEdges = 0,
const Standard_Boolean theHasVColors = Standard_False,
- const Standard_Boolean theHasBColors = Standard_False)
- : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_POLYLINES, theMaxVertexs, theMaxBounds, theMaxEdges, Standard_False, theHasVColors, theHasBColors, Standard_False) {}
+ const Standard_Boolean theHasBColors = Standard_False,
+ const Standard_Boolean theIsInterleaved = Standard_True,
+ const Standard_Boolean theIsMutable = Standard_False)
+ : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_POLYLINES, theMaxVertexs, theMaxBounds, theMaxEdges, Standard_False, theHasVColors, theHasBColors, Standard_False, theIsInterleaved, theIsMutable) {}
};
const Standard_Boolean theHasVNormals,
const Standard_Boolean theHasVColors,
const Standard_Boolean theHasFColors,
- const Standard_Boolean theHasVTexels)
+ const Standard_Boolean theHasVTexels,
+ const Standard_Boolean theIsInterleaved,
+ const Standard_Boolean theIsMutable)
: myType (theType),
myMaxBounds (0),
myMaxVertexs (0),
myVCol (0)
{
Handle(NCollection_AlignedAllocator) anAlloc = new NCollection_AlignedAllocator (16);
- myAttribs = new Graphic3d_Buffer (anAlloc);
+ myAttribs = new Graphic3d_AttribBuffer(anAlloc, theIsInterleaved, theIsMutable);
if (theMaxVertexs < 1)
{
return;
break;
case Graphic3d_TOA_NORM:
{
- myVNor = static_cast<Standard_Byte>(myAttribs->AttributeOffset (anAttribIter));
+ if(theIsInterleaved)
+ myVNor = static_cast<Standard_Byte>(myAttribs->AttributeOffset (anAttribIter));
+ myINor = anAttribIter;
break;
}
case Graphic3d_TOA_UV:
{
- myVTex = static_cast<Standard_Byte>(myAttribs->AttributeOffset (anAttribIter));
+ if (theIsInterleaved)
+ myVTex = static_cast<Standard_Byte>(myAttribs->AttributeOffset (anAttribIter));
+ myITex = anAttribIter;
break;
}
case Graphic3d_TOA_COLOR:
{
- myVCol = static_cast<Standard_Byte>(myAttribs->AttributeOffset (anAttribIter));
+ if (theIsInterleaved)
+ myVCol = static_cast<Standard_Byte>(myAttribs->AttributeOffset (anAttribIter));
+ myICol = anAttribIter;
break;
}
}
#define _Graphic3d_ArrayOfPrimitives_HeaderFile
#include <Graphic3d_BoundBuffer.hxx>
-#include <Graphic3d_Buffer.hxx>
+#include <Graphic3d_AttribBuffer.hxx>
#include <Graphic3d_IndexBuffer.hxx>
#include <Graphic3d_TypeOfPrimitiveArray.hxx>
#include <gp_Dir.hxx>
Standard_EXPORT virtual ~Graphic3d_ArrayOfPrimitives();
//! Returns vertex attributes buffer (colors, normals, texture coordinates).
- const Handle(Graphic3d_Buffer)& Attributes() const { return myAttribs; }
+ const Handle(Graphic3d_AttribBuffer)& Attributes() const { return myAttribs; }
//! Returns the type of this primitive
Graphic3d_TypeOfPrimitiveArray Type() const { return myType; }
Standard_EXPORT Standard_CString StringType() const;
//! Returns TRUE when vertex normals array is defined.
- Standard_Boolean HasVertexNormals() const { return myVNor != 0; }
+ Standard_Boolean HasVertexNormals() const { return myINor != 0; }
//! Returns TRUE when vertex colors array is defined.
- Standard_Boolean HasVertexColors() const { return myVCol != 0; }
+ Standard_Boolean HasVertexColors() const { return myICol != 0; }
//! Returns TRUE when vertex texels array is defined.
- Standard_Boolean HasVertexTexels() const { return myVTex != 0; }
+ Standard_Boolean HasVertexTexels() const { return myITex != 0; }
//! Returns the number of defined vertex
Standard_Integer VertexNumber() const { return !myAttribs.IsNull() ? myAttribs->NbElements : -1; }
throw Standard_OutOfRange ("BAD VERTEX index");
}
- if (myVCol != 0)
+ if (myICol != 0)
{
Graphic3d_Vec4ub *aColorPtr =
- reinterpret_cast<Graphic3d_Vec4ub* >(myAttribs->changeValue (theIndex - 1) + size_t(myVCol));
+ reinterpret_cast<Graphic3d_Vec4ub* >(myAttribs->changeValue (theIndex - 1, myICol) + size_t(myVCol));
aColorPtr->SetValues (Standard_Byte(theR * 255.0),
Standard_Byte(theG * 255.0),
Standard_Byte(theB * 255.0), 255);
throw Standard_OutOfRange ("BAD VERTEX index");
}
- if (myVCol != 0)
+ if (myICol != 0)
{
Graphic3d_Vec4ub *aColorPtr =
- reinterpret_cast<Graphic3d_Vec4ub* >(myAttribs->changeValue (theIndex - 1) + size_t(myVCol));
+ reinterpret_cast<Graphic3d_Vec4ub* >(myAttribs->changeValue (theIndex - 1, myICol) + size_t(myVCol));
(*aColorPtr) = theColor;
}
myAttribs->NbElements = Max (theIndex, myAttribs->NbElements);
throw Standard_OutOfRange ("BAD VERTEX index");
}
- if (myVCol != 0)
+ if (myICol != 0)
{
- *reinterpret_cast<Standard_Integer* >(myAttribs->changeValue (theIndex - 1) + size_t(myVCol)) = theColor32;
+ *reinterpret_cast<Standard_Integer* >(myAttribs->changeValue (theIndex - 1, myICol) + size_t(myVCol)) = theColor32;
}
}
throw Standard_OutOfRange("BAD VERTEX index");
}
- if (myVNor != 0)
+ if (myINor != 0)
{
- Graphic3d_Vec3& aVec = *reinterpret_cast<Graphic3d_Vec3* >(myAttribs->changeValue (theIndex - 1) + size_t(myVNor));
+ Graphic3d_Vec3& aVec = *reinterpret_cast<Graphic3d_Vec3* >(myAttribs->changeValue (theIndex - 1, myINor) + size_t(myVNor));
aVec.x() = Standard_ShortReal (theNX);
aVec.y() = Standard_ShortReal (theNY);
aVec.z() = Standard_ShortReal (theNZ);
throw Standard_OutOfRange("BAD VERTEX index");
}
- if (myVTex != 0)
+ if (myITex != 0)
{
- Graphic3d_Vec2& aVec = *reinterpret_cast<Graphic3d_Vec2* >(myAttribs->changeValue (theIndex - 1) + size_t(myVTex));
+ Graphic3d_Vec2& aVec = *reinterpret_cast<Graphic3d_Vec2* >(myAttribs->changeValue (theIndex - 1, myITex) + size_t(myVTex));
aVec.x() = Standard_ShortReal (theTX);
aVec.y() = Standard_ShortReal (theTY);
}
throw Standard_OutOfRange ("BAD VERTEX index");
}
- const Graphic3d_Vec3& aVec = myAttribs->Value<Graphic3d_Vec3> (theRank - 1);
+ const Graphic3d_Vec3& aVec = myAttribs->Value<Graphic3d_Vec3> (theRank - 1, 0);
theX = Standard_Real(aVec.x());
theY = Standard_Real(aVec.y());
theZ = Standard_Real(aVec.z());
Graphic3d_Vec4ub& theColor) const
{
if (myAttribs.IsNull()
- || myVCol == 0)
+ || myICol == 0)
{
throw Standard_OutOfRange ("Primitive array does not define color attribute");
}
{
theR = theG = theB = 0.0;
if (myAttribs.IsNull()
- || myVCol == 0)
+ || myICol == 0)
{
return;
}
//! Returns the vertex color values at rank theRank from the vertex table if defined.
void VertexColor (const Standard_Integer theRank, Standard_Integer& theColor) const
{
- if (myVCol != 0)
+ if (myICol != 0)
{
theColor = *reinterpret_cast<const Standard_Integer* >(myAttribs->value (theRank - 1) + size_t(myVCol));
}
throw Standard_OutOfRange ("BAD VERTEX index");
}
- if (myVNor != 0)
+ if (myINor != 0)
{
const Graphic3d_Vec3& aVec = *reinterpret_cast<const Graphic3d_Vec3* >(myAttribs->value (theRank - 1) + size_t(myVNor));
theNX = Standard_Real(aVec.x());
throw Standard_OutOfRange ("BAD VERTEX index");
}
- if (myVTex != 0)
+ if (myITex != 0)
{
const Graphic3d_Vec2& aVec = *reinterpret_cast<const Graphic3d_Vec2* >(myAttribs->value (theRank - 1) + size_t(myVTex));
theTX = Standard_Real(aVec.x());
const Standard_Boolean theHasVNormals,
const Standard_Boolean theHasVColors,
const Standard_Boolean theHasBColors,
- const Standard_Boolean theHasVTexels);
+ const Standard_Boolean theHasVTexels,
+ const Standard_Boolean theIsInterleaved,
+ const Standard_Boolean theIsMutable);
private: //! @name private fields
Handle(Graphic3d_IndexBuffer) myIndices;
- Handle(Graphic3d_Buffer) myAttribs;
+ Handle(Graphic3d_AttribBuffer) myAttribs;
Handle(Graphic3d_BoundBuffer) myBounds;
Graphic3d_TypeOfPrimitiveArray myType;
Standard_Integer myMaxBounds;
Standard_Integer myMaxVertexs;
Standard_Integer myMaxEdges;
+
Standard_Byte myVNor;
Standard_Byte myVTex;
Standard_Byte myVCol;
-
+ Standard_Integer myINor;
+ Standard_Integer myITex;
+ Standard_Integer myICol;
};
#endif // _Graphic3d_ArrayOfPrimitives_HeaderFile
const Standard_Boolean theHasVNormals = Standard_False,
const Standard_Boolean theHasVColors = Standard_False,
const Standard_Boolean theHasSColors = Standard_False,
- const Standard_Boolean theHasVTexels = Standard_False)
- : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_QUADRANGLESTRIPS, theMaxVertexs, theMaxStrips, 0, theHasVNormals, theHasVColors, theHasSColors, theHasVTexels) {}
+ const Standard_Boolean theHasVTexels = Standard_False,
+ const Standard_Boolean theIsInterleaved = Standard_True,
+ const Standard_Boolean theIsMutable = Standard_False)
+ : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_QUADRANGLESTRIPS, theMaxVertexs, theMaxStrips, 0, theHasVNormals, theHasVColors, theHasSColors, theHasVTexels, theIsInterleaved, theIsMutable) {}
};
const Standard_Integer theMaxEdges = 0,
const Standard_Boolean theHasVNormals = Standard_False,
const Standard_Boolean theHasVColors = Standard_False,
- const Standard_Boolean theHasVTexels = Standard_False)
- : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_QUADRANGLES, theMaxVertexs, 0, theMaxEdges, theHasVNormals, theHasVColors, Standard_False, theHasVTexels) {}
+ const Standard_Boolean theHasVTexels = Standard_False,
+ const Standard_Boolean theIsInterleaved = Standard_True,
+ const Standard_Boolean theIsMutable = Standard_False)
+ : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_QUADRANGLES, theMaxVertexs, 0, theMaxEdges, theHasVNormals, theHasVColors, Standard_False, theHasVTexels, theIsInterleaved, theIsMutable) {}
};
//! @param theHasVColors when TRUE, AddVertex(Point,Color) should be used for specifying vertex color
Graphic3d_ArrayOfSegments (const Standard_Integer theMaxVertexs,
const Standard_Integer theMaxEdges = 0,
- const Standard_Boolean theHasVColors = Standard_False)
- : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_SEGMENTS, theMaxVertexs, 0, theMaxEdges, Standard_False, theHasVColors, Standard_False, Standard_False) {}
+ const Standard_Boolean theHasVColors = Standard_False,
+ const Standard_Boolean theIsInterleaved = Standard_True,
+ const Standard_Boolean theIsMutable = Standard_False)
+ : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_SEGMENTS, theMaxVertexs, 0, theMaxEdges, Standard_False, theHasVColors, Standard_False, Standard_False, theIsInterleaved, theIsMutable) {}
};
const Standard_Boolean theHasVNormals = Standard_False,
const Standard_Boolean theHasVColors = Standard_False,
const Standard_Boolean theHasBColors = Standard_False,
- const Standard_Boolean theHasVTexels = Standard_False)
- : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_TRIANGLEFANS, theMaxVertexs, theMaxFans, 0, theHasVNormals, theHasVColors, theHasBColors, theHasVTexels) {}
+ const Standard_Boolean theHasVTexels = Standard_False,
+ const Standard_Boolean theIsInterleaved = Standard_True,
+ const Standard_Boolean theIsMutable = Standard_False)
+ : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_TRIANGLEFANS, theMaxVertexs, theMaxFans, 0, theHasVNormals, theHasVColors, theHasBColors, theHasVTexels, theIsInterleaved, theIsMutable) {}
};
const Standard_Boolean theHasVNormals = Standard_False,
const Standard_Boolean theHasVColors = Standard_False,
const Standard_Boolean theHasBColors = Standard_False,
- const Standard_Boolean theHasVTexels = Standard_False)
- : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_TRIANGLESTRIPS, theMaxVertexs, theMaxStrips, 0, theHasVNormals, theHasVColors, theHasBColors, theHasVTexels) {}
+ const Standard_Boolean theHasVTexels = Standard_False,
+ const Standard_Boolean theIsInterleaved = Standard_True,
+ const Standard_Boolean theIsMutable = Standard_False)
+ : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_TRIANGLESTRIPS, theMaxVertexs, theMaxStrips, 0, theHasVNormals, theHasVColors, theHasBColors, theHasVTexels, theIsInterleaved, theIsMutable) {}
};
const Standard_Integer theMaxEdges = 0,
const Standard_Boolean theHasVNormals = Standard_False,
const Standard_Boolean theHasVColors = Standard_False,
- const Standard_Boolean theHasVTexels = Standard_False)
- : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_TRIANGLES, theMaxVertexs, 0, theMaxEdges, theHasVNormals, theHasVColors, Standard_False, theHasVTexels) {}
+ const Standard_Boolean theHasVTexels = Standard_False,
+ const Standard_Boolean theIsInterleaved = Standard_True,
+ const Standard_Boolean theIsMutable = Standard_False)
+ : Graphic3d_ArrayOfPrimitives (Graphic3d_TOPA_TRIANGLES, theMaxVertexs, 0, theMaxEdges, theHasVNormals, theHasVColors, Standard_False, theHasVTexels, theIsInterleaved, theIsMutable) {}
};
--- /dev/null
+// Copyright (c) 2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#include <Graphic3d_AttribBuffer.hxx>
+
+Graphic3d_AttribBuffer::Graphic3d_AttribBuffer(const Handle(NCollection_BaseAllocator)& theAlloc,
+ Standard_Boolean isInterleaved, Standard_Boolean isMutable)
+ : Graphic3d_Buffer(theAlloc, isInterleaved, isMutable)
+{
+}
+
+Standard_Boolean Graphic3d_AttribBuffer::Invalidate(int theAttributeIndex)
+{
+ if (!IsMutable() || IsInterleaved())
+ return false;
+
+ Graphic3d_Range aRange;
+ aRange.Start = AttributeOffset(theAttributeIndex);
+ aRange.Length = AttributeOffset(theAttributeIndex + 1) - aRange.Start;
+ Graphic3d_Buffer::Invalidate(aRange);
+
+ return true;
+}
+
+Standard_Boolean Graphic3d_AttribBuffer::Invalidate(int theAttributeIndex, int theStartVertexIndex, int theEndVertexIndex)
+{
+ if (!IsMutable() || IsInterleaved())
+ return false;
+
+ Graphic3d_Range aRange;
+ Standard_Integer anAttrOffset = AttributeOffset(theAttributeIndex);
+ Standard_Integer aStride = AttributesArray()[theAttributeIndex].Stride();
+ aRange.Start = anAttrOffset + aStride * theStartVertexIndex;
+ aRange.Length = aStride * ( theEndVertexIndex - theStartVertexIndex + 1 );
+ Graphic3d_Buffer::Invalidate(aRange);
+
+ return true;
+}
+
+Standard_Boolean Graphic3d_AttribBuffer::Invalidate(int theStartVertexIndex, int theEndVertexIndex)
+{
+ if (!IsMutable())
+ return false;
+
+ if (IsInterleaved())
+ {
+ Graphic3d_Range aRange;
+ aRange.Start = Stride * theStartVertexIndex;
+ aRange.Length = Stride * (theEndVertexIndex - theStartVertexIndex + 1);
+ Graphic3d_Buffer::Invalidate(aRange);
+ return true;
+ }
+ else
+ {
+ Standard_Boolean isOK = true;
+ for (Standard_Integer i = 0, n = NbAttributes; i < n; i++)
+ {
+ bool isLocalOK = Invalidate(i, theStartVertexIndex, theEndVertexIndex);
+ isOK = isOK && isLocalOK;
+ }
+ return isOK;
+ }
+}
+
+
--- /dev/null
+// Copyright (c) 2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#ifndef _Graphic3d_AttribBuffer_HeaderFile
+#define _Graphic3d_AttribBuffer_HeaderFile
+
+#include <Graphic3d_Buffer.hxx>
+
+//! Buffer of vertex attributes.
+class Graphic3d_AttribBuffer : public Graphic3d_Buffer
+{
+public:
+ //! Empty constructor.
+ Standard_EXPORT Graphic3d_AttribBuffer(const Handle(NCollection_BaseAllocator)& theAlloc,
+ Standard_Boolean isInterleaved, Standard_Boolean isMutable);
+
+ Standard_EXPORT Standard_Boolean Invalidate(Standard_Integer theAttributeIndex);
+ Standard_EXPORT Standard_Boolean Invalidate(Standard_Integer theAttributeIndex,
+ Standard_Integer theStartVertexIndex,
+ Standard_Integer theEndVertexIndex);
+ Standard_EXPORT Standard_Boolean Invalidate(Standard_Integer theStartVertexIndex,
+ Standard_Integer theEndVertexIndex);
+
+public:
+ DEFINE_STANDARD_RTTI_INLINE(Graphic3d_AttribBuffer, Graphic3d_Buffer) // Type definition
+};
+
+DEFINE_STANDARD_HANDLE(Graphic3d_AttribBuffer, Graphic3d_Buffer)
+
+#endif // _Graphic3d_AttribBuffer_HeaderFile
#include <Graphic3d_Vec.hxx>
#include <NCollection_Array1.hxx>
#include <NCollection_Buffer.hxx>
+#include <vector>
//! Type of attribute in Vertex Buffer
enum Graphic3d_TypeOfAttribute
typedef NCollection_Array1<Graphic3d_Attribute> Graphic3d_Array1OfAttribute;
+struct Graphic3d_Range
+{
+ Standard_Integer Start;
+ Standard_Integer Length;
+};
+
//! Buffer of vertex attributes.
class Graphic3d_Buffer : public NCollection_Buffer
{
public:
//! Empty constructor.
- Graphic3d_Buffer (const Handle(NCollection_BaseAllocator)& theAlloc)
+ Graphic3d_Buffer (const Handle(NCollection_BaseAllocator)& theAlloc,
+ Standard_Boolean isInterleaved, Standard_Boolean isMutable)
: NCollection_Buffer (theAlloc),
Stride (0),
NbElements (0),
- NbAttributes (0)
+ NbAttributes (0),
+ bIsInterleaved(isInterleaved),
+ bIsMutable(isMutable)
{
//
}
{
anOffset += Graphic3d_Attribute::Stride (Attribute (anAttribIter).DataType);
}
+ if (!bIsInterleaved)
+ anOffset *= NbElements;
return anOffset;
}
}
//! Access specified element.
- inline const Standard_Byte* value (const Standard_Integer theElem) const
+ inline const Standard_Byte* value (const Standard_Integer theElem, const Standard_Integer theAttribIndex = 0) const
{
- return myData + Stride * size_t(theElem);
+ if (bIsInterleaved)
+ return myData + Stride * size_t(theElem);
+ else
+ {
+ int aStrideI = AttributesArray()[theAttribIndex].Stride(); //TODO: correct attribute index
+ return myData + aStrideI * theElem;
+ }
}
//! Access specified element.
- inline Standard_Byte* changeValue (const Standard_Integer theElem)
+ inline Standard_Byte* changeValue (const Standard_Integer theElem, const Standard_Integer theAttribIndex = 0)
{
- return myData + Stride * size_t(theElem);
+ if (bIsInterleaved)
+ return myData + Stride * size_t(theElem);
+ else
+ {
+ int aStrideI = AttributesArray()[theAttribIndex].Stride(); //TODO: correct attribute index
+ return myData + aStrideI * theElem;
+ }
}
//! Access element with specified position and type.
template <typename Type_t>
- inline const Type_t& Value (const Standard_Integer theElem) const
+ inline const Type_t& Value (const Standard_Integer theElem, const Standard_Integer theAttribIndex = 0) const
{
- return *reinterpret_cast<const Type_t*>(value (theElem));
+ return *reinterpret_cast<const Type_t*>(value (theElem, theAttribIndex));
}
//! Access element with specified position and type.
}
//! Allocates new empty array
- bool Init (const Standard_Integer theNbElems,
+ Standard_Boolean Init (const Standard_Integer theNbElems,
const Graphic3d_Attribute* theAttribs,
const Standard_Integer theNbAttribs)
{
ChangeAttribute (anAttribIter) = theAttribs[anAttribIter];
}
}
+
+ if (!bIsInterleaved)
+ {
+ Stride = 0;
+ }
+
return true;
}
//! Allocates new empty array
- bool Init (const Standard_Integer theNbElems,
+ Standard_Boolean Init (const Standard_Integer theNbElems,
const Graphic3d_Array1OfAttribute& theAttribs)
{
return Init (theNbElems, &theAttribs.First(), theAttribs.Size());
}
+ inline Standard_Boolean IsInterleaved() const { return bIsInterleaved; }
+ inline Standard_Boolean IsMutable() const { return bIsMutable; }
+
+ std::vector<Graphic3d_Range> InvalidatedRanges() const
+ {
+ return Ranges;
+ }
+
+ void Validate()
+ {
+ Ranges.clear();
+ }
+
+protected:
+ void Invalidate(const Graphic3d_Range& theRange)
+ {
+ Ranges.push_back(theRange);
+ }
+
public:
Standard_Integer Stride; //!< the distance to the attributes of the next vertex
Standard_Integer NbElements; //!< number of the elements
Standard_Integer NbAttributes; //!< number of vertex attributes
+private:
+ Standard_Boolean bIsInterleaved;
+ Standard_Boolean bIsMutable;
+ std::vector<Graphic3d_Range> Ranges;
+
public:
DEFINE_STANDARD_RTTI_INLINE(Graphic3d_Buffer,NCollection_Buffer) // Type definition
//! Empty constructor.
Graphic3d_IndexBuffer (const Handle(NCollection_BaseAllocator)& theAlloc)
- : Graphic3d_Buffer (theAlloc) {}
+ : Graphic3d_Buffer (theAlloc, true, false) {}
//! Allocates new empty index array
template<typename IndexType_t>
}
}
+ //! Invalidate the given indices
+ Standard_Boolean Invalidate(Standard_Integer theStartIndex, Standard_Integer theEndIndex)
+ {
+ Graphic3d_Range aRange;
+ aRange.Start = Stride * theStartIndex;
+ aRange.Length = Stride * (theEndIndex - theStartIndex + 1);
+ }
+
public:
DEFINE_STANDARD_RTTI_INLINE(Graphic3d_IndexBuffer,Graphic3d_Buffer) // Type definition
myToUpdate (Standard_False)
{
Handle(NCollection_AlignedAllocator) anAlloc = new NCollection_AlignedAllocator (16);
- myAttribs = new Graphic3d_Buffer (anAlloc);
+ myAttribs = new Graphic3d_Buffer (anAlloc, true, false);
myDrawMode = GL_TRIANGLE_STRIP;
{
// Fill primitive array
Handle(NCollection_AlignedAllocator) anAlloc = new NCollection_AlignedAllocator (16);
- Handle(Graphic3d_Buffer) anAttribs = new Graphic3d_Buffer (anAlloc);
+ Handle(Graphic3d_Buffer) anAttribs = new Graphic3d_Buffer (anAlloc, true, false);
Graphic3d_Attribute anAttribInfo[] =
{
{ Graphic3d_TOA_POS, Graphic3d_TOD_VEC4 },
//! Create uninitialized VBO.
OpenGl_VertexBufferT (const Graphic3d_Attribute* theAttribs,
const Standard_Integer theStride)
- : Stride (theStride)
+ : Stride (theStride),
+ NbElements(1)
{
memcpy (Attribs, theAttribs, sizeof(Graphic3d_Attribute) * NbAttributes);
}
//! Create uninitialized VBO.
OpenGl_VertexBufferT (const Graphic3d_Buffer& theAttribs)
- : Stride (theAttribs.Stride)
+ : Stride (theAttribs.IsInterleaved() ? theAttribs.Stride : 0),
+ NbElements(theAttribs.IsInterleaved() ? 1 : theAttribs.NbElements)
{
memcpy (Attribs, theAttribs.AttributesArray(), sizeof(Graphic3d_Attribute) * NbAttributes);
}
}
TheBaseClass::bindAttribute (theGlCtx, anAttrib.Id, aNbComp, aDataType, Stride, anOffset);
- anOffset += Graphic3d_Attribute::Stride (anAttrib.DataType);
+ anOffset += Graphic3d_Attribute::Stride (anAttrib.DataType) * NbElements;
}
}
Graphic3d_Attribute Attribs[NbAttributes];
Standard_Integer Stride;
-
+ Standard_Integer NbElements;
};
// =======================================================================
}
// specify data type as Byte and NbComponents as Stride, so that OpenGl_VertexBuffer::EstimatedDataSize() will return correct value
- if (!myVboAttribs->init (theCtx, myAttribs->Stride, myAttribs->NbElements, myAttribs->Data(), GL_UNSIGNED_BYTE, myAttribs->Stride))
+ int aStride = myAttribs->IsInterleaved() ? myAttribs->Stride : myAttribs->AttributeOffset(myAttribs->NbAttributes) / myAttribs->NbElements;
+ if (!myVboAttribs->init (theCtx, aStride, myAttribs->NbElements, myAttribs->Data(), GL_UNSIGNED_BYTE, aStride))
{
TCollection_ExtendedString aMsg;
aMsg += "VBO creation for Primitive Array has failed for ";
&& initNormalVbo (theCtx))
{
if (!theCtx->caps->keepArrayData
- && !theToKeepData)
+ && !theToKeepData
+ && !myAttribs->IsMutable())
{
myIndices.Nullify();
myAttribs.Nullify();
}
myVboAttribs = aVboAttribs;
if (!theCtx->caps->keepArrayData
- && !theToKeepData)
+ && !theToKeepData
+ && !myAttribs->IsMutable())
{
// does not make sense for compatibility mode
//myIndices.Nullify();
return Standard_True;
}
+Standard_Boolean OpenGl_PrimitiveArray::updateVBO(const Handle(OpenGl_Context)& theCtx) const
+{
+ const std::vector<Graphic3d_Range>& ranges = myAttribs->InvalidatedRanges();
+ for (size_t i = 0, n = ranges.size(); i < n; i++)
+ {
+ Graphic3d_Range aRange = ranges[i];
+ theCtx->core15fwd->glBufferSubData(myVboAttribs->GetTarget(),
+ aRange.Start, aRange.Length, myAttribs->Data() + aRange.Start);
+ }
+ myAttribs->Validate();
+ return Standard_True;
+}
+
// =======================================================================
// function : drawArray
// purpose :
myIsVboInit = Standard_True;
}
+ if (!myAttribs.IsNull() && myAttribs->IsMutable() && myAttribs->InvalidatedRanges().size() > 0)
+ updateVBO(aCtx);
+
// Temporarily disable environment mapping
Handle(OpenGl_TextureSet) aTextureBack;
bool toDrawArray = true;
if (myAttribs->NbElements > std::numeric_limits<GLushort>::max())
{
- Handle(Graphic3d_Buffer) anAttribs = new Graphic3d_Buffer (new NCollection_AlignedAllocator (16));
+ Handle(Graphic3d_Buffer) anAttribs = new Graphic3d_Buffer (new NCollection_AlignedAllocator (16), true, false);
if (!anAttribs->Init (myIndices->NbElements, myAttribs->AttributesArray(), myAttribs->NbAttributes))
{
return Standard_False; // failed to initialize attribute array
Standard_EXPORT Standard_Boolean buildVBO (const Handle(OpenGl_Context)& theCtx,
const Standard_Boolean theToKeepData) const;
+ Standard_EXPORT Standard_Boolean updateVBO(const Handle(OpenGl_Context)& theCtx) const;
+
Standard_EXPORT void clearMemoryGL (const Handle(OpenGl_Context)& theGlCtx) const;
private:
//! Empty constructor.
Select3D_BVHIndexBuffer (const Handle(NCollection_BaseAllocator)& theAlloc)
- : Graphic3d_Buffer (theAlloc), myHasPatches (false) {}
+ : Graphic3d_Buffer (theAlloc, true, false), myHasPatches (false) {}
bool HasPatches() const { return myHasPatches; }