myVCol (0)
{
Handle(NCollection_AlignedAllocator) anAlloc = new NCollection_AlignedAllocator (16);
- myAttribs = new Graphic3d_AttribBuffer(anAlloc, theIsInterleaved, theIsMutable);
if (theMaxVertexs < 1)
{
return;
}
+ myAttribs = new Graphic3d_AttribBuffer(anAlloc, theIsInterleaved, theIsMutable, theMaxVertexs);
+
if (theMaxEdges > 0)
{
myIndices = new Graphic3d_IndexBuffer (anAlloc);
#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 isInterleaved, Standard_Boolean isMutable,
+ Standard_Integer theMaxNbElements)
+ : Graphic3d_Buffer(theAlloc, isInterleaved, isMutable, theMaxNbElements)
{
}
public:
//! Empty constructor.
Standard_EXPORT Graphic3d_AttribBuffer(const Handle(NCollection_BaseAllocator)& theAlloc,
- Standard_Boolean isInterleaved, Standard_Boolean isMutable);
+ Standard_Boolean isInterleaved, Standard_Boolean isMutable,
+ Standard_Integer theMaxNbElements);
Standard_EXPORT Standard_Boolean Invalidate(Standard_Integer theAttributeIndex);
Standard_EXPORT Standard_Boolean Invalidate(Standard_Integer theAttributeIndex,
//! Empty constructor.
Graphic3d_Buffer (const Handle(NCollection_BaseAllocator)& theAlloc,
- Standard_Boolean isInterleaved, Standard_Boolean isMutable)
+ Standard_Boolean isInterleaved, Standard_Boolean isMutable,
+ Standard_Integer theMaxNbElements)
: NCollection_Buffer (theAlloc),
Stride (0),
NbElements (0),
+ MaxNbElements(theMaxNbElements),
NbAttributes (0),
bIsInterleaved(isInterleaved),
bIsMutable(isMutable)
anOffset += Graphic3d_Attribute::Stride (Attribute (anAttribIter).DataType);
}
if (!bIsInterleaved)
- anOffset *= NbElements;
+ anOffset *= MaxNbElements;
return anOffset;
}
return myData + Stride * size_t(theElem);
else
{
- int aStrideI = AttributesArray()[theAttribIndex].Stride(); //TODO: correct attribute index
- return myData + aStrideI * theElem;
+ int anOffset = AttributeOffset(theAttribIndex);
+ int aStrideI = AttributesArray()[theAttribIndex].Stride();
+ return myData + anOffset + aStrideI * theElem;
}
}
return myData + Stride * size_t(theElem);
else
{
- int aStrideI = AttributesArray()[theAttribIndex].Stride(); //TODO: correct attribute index
- return myData + aStrideI * theElem;
+ int anOffset = AttributeOffset(theAttribIndex);
+ int aStrideI = AttributesArray()[theAttribIndex].Stride();
+ return myData + anOffset + aStrideI * theElem;
}
}
Stride = aStride;
NbElements = theNbElems;
+ MaxNbElements = theNbElems;
NbAttributes = theNbAttribs;
if (NbElements != 0)
{
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
+ Standard_Integer MaxNbElements; //!< maximum number of the elements
private:
Standard_Boolean bIsInterleaved;
//! Empty constructor.
Graphic3d_IndexBuffer (const Handle(NCollection_BaseAllocator)& theAlloc)
- : Graphic3d_Buffer (theAlloc, true, false) {}
+ : Graphic3d_Buffer (theAlloc, true, false, 0) {}
//! Allocates new empty index array
template<typename IndexType_t>
myToUpdate (Standard_False)
{
Handle(NCollection_AlignedAllocator) anAlloc = new NCollection_AlignedAllocator (16);
- myAttribs = new Graphic3d_Buffer (anAlloc, true, false);
+ myAttribs = new Graphic3d_Buffer (anAlloc, true, false, 0);
myDrawMode = GL_TRIANGLE_STRIP;
{
// Fill primitive array
Handle(NCollection_AlignedAllocator) anAlloc = new NCollection_AlignedAllocator (16);
- Handle(Graphic3d_Buffer) anAttribs = new Graphic3d_Buffer (anAlloc, true, false);
+ Handle(Graphic3d_Buffer) anAttribs = new Graphic3d_Buffer (anAlloc, true, false, 0);
Graphic3d_Attribute anAttribInfo[] =
{
{ Graphic3d_TOA_POS, Graphic3d_TOD_VEC4 },
Standard_Boolean OpenGl_PrimitiveArray::updateVBO(const Handle(OpenGl_Context)& theCtx) const
{
- const std::vector<Graphic3d_Range>& ranges = myAttribs->InvalidatedRanges();
+ int aStride = myAttribs->IsInterleaved() ? myAttribs->Stride : myAttribs->AttributeOffset(myAttribs->NbAttributes) / myAttribs->NbElements;
+ int aSize = myAttribs->AttributeOffset(myAttribs->NbAttributes);
+ myVboAttribs->init(theCtx, aStride, myAttribs->NbElements, myAttribs->Data(), GL_UNSIGNED_BYTE, aStride);
+
+ /*GLint a, b, c;
+ theCtx->core15fwd->glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &a);
+ theCtx->core15fwd->glGetIntegerv(GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &b);
+ theCtx->core15fwd->glGetIntegerv(GL_ELEMENT_ARRAY_BUFFER_BINDING, &c);
+
+ myVboAttribs->BindAllAttributes(theCtx);
+
+ printf("array buffer: %i\n", (int)a);
+ printf("vertex attrib: %i\n", (int)b);
+ printf("element array: %i\n", (int)c);
+ printf("my buffer: %i\n", (int)myVboAttribs->BufferId());
+ theCtx->core15fwd->glBufferData(myVboAttribs->GetTarget(), aSize, myAttribs->Data(), GL_STATIC_DRAW);
+
+ myVboAttribs->UnbindAllAttributes(theCtx);
+
+ /*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);
- }
+ }*/
+ //myVboAttribs->Unbind(theCtx);
+
myAttribs->Validate();
return Standard_True;
}
myIsVboInit = Standard_True;
}
- if (!myAttribs.IsNull() && myAttribs->IsMutable() && myAttribs->InvalidatedRanges().size() > 0)
- updateVBO(aCtx);
+ //if (!myAttribs.IsNull() && myAttribs->IsMutable() && myAttribs->InvalidatedRanges().size() > 0)
+ // updateVBO(aCtx);
// Temporarily disable environment mapping
Handle(OpenGl_TextureSet) aTextureBack;
const Graphic3d_Vec4* aFaceColors = !myBounds.IsNull() && !toHilight && anAspectFace->Aspect()->InteriorStyle() != Aspect_IS_HIDDENLINE
? myBounds->Colors
: NULL;
+ if (!myAttribs.IsNull() && myAttribs->IsMutable() && myAttribs->InvalidatedRanges().size() > 0)
+ updateVBO(aCtx);
+
drawArray (theWorkspace, aFaceColors, hasColorAttrib);
}
if (myAttribs->NbElements > std::numeric_limits<GLushort>::max())
{
- Handle(Graphic3d_Buffer) anAttribs = new Graphic3d_Buffer (new NCollection_AlignedAllocator (16), true, false);
+ Handle(Graphic3d_Buffer) anAttribs = new Graphic3d_Buffer (new NCollection_AlignedAllocator (16), true, false, 0);
if (!anAttribs->Init (myIndices->NbElements, myAttribs->AttributesArray(), myAttribs->NbAttributes))
{
return Standard_False; // failed to initialize attribute array
return myBufferId != NO_BUFFER;
}
+ inline GLuint BufferId() const { return myBufferId; }
+
//! @return the number of components per generic vertex attribute.
inline GLuint GetComponentsNb() const
{
//! Empty constructor.
Select3D_BVHIndexBuffer (const Handle(NCollection_BaseAllocator)& theAlloc)
- : Graphic3d_Buffer (theAlloc, true, false), myHasPatches (false) {}
+ : Graphic3d_Buffer (theAlloc, true, false, 0), myHasPatches (false) {}
bool HasPatches() const { return myHasPatches; }
virtual Standard_Boolean AcceptDisplayMode (const Standard_Integer theMode) const Standard_OVERRIDE { return theMode == 0; }
+ void SetRandomColors()
+ {
+ for (int i = 0, n = myPArray->VertexNumber(); i < n; i++)
+ {
+ Graphic3d_Vec4ub color;
+ color.r() = rand() % 255;
+ color.g() = rand() % 255;
+ color.b() = rand() % 255;
+ color.a() = 255;
+ myPArray->SetVertexColor(i + 1, color);
+ }
+ myPArray->Attributes()->Invalidate(1);
+ }
+
private:
void Compute (const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
hasVColors, hasBColors);
else if (anArrayType == "triangles")
anArray = new Graphic3d_ArrayOfTriangles (aVertexNum, aEdgeNum, hasNormals,
- hasVColors, hasTexels);
+ hasVColors, hasTexels, false, true);
else if (anArrayType == "trianglefans")
anArray = new Graphic3d_ArrayOfTriangleFans (aVertexNum, aBoundNum,
hasNormals, hasVColors,
std::cout << "Error: no active Viewer\n";
return 1;
}
+
+ if (argc == 3 && strcmp(argv[2], "randomcolors") == 0)
+ {
+ Handle(MyPArrayObject) aPObject = Handle(MyPArrayObject)::DownCast(GetMapOfAIS().Find2(argv[1]));
+ if (!aPObject.IsNull())
+ {
+ printf("Set random colors\n");
+ aPObject->SetRandomColors();
+ return 0;
+ }
+ else
+ return 1;
+ }
+
else if (argc < 3)
{
std::cout << "Syntax error: wrong number of arguments\n";
--- /dev/null
+puts "============="
+puts "0030076: Visualization, TKV3d - API to update certain vertex attribute(s) without recomputing a presentation"
+puts "============="
+
+pload ALL
+
+vinit
+vdrawparray a triangles v 0 0 0 c 1 0 0 v 1 0 0 c 1 0 0 v 1 1 0 c 1 0 0 v 1 1 0 c 0 0 1 v 0 1 0 c 0 0 1 v 0 0 0 c 0 0 1
+vdrawparray a randomcolors
+
+vfit