From 194fb16c219a208a769b261d68af00ab7fdc6a12 Mon Sep 17 00:00:00 2001 From: asl Date: Wed, 29 Aug 2018 13:52:22 +0300 Subject: [PATCH] debug on the OCC automatic test --- src/Graphic3d/Graphic3d_ArrayOfPrimitives.cxx | 3 +- src/Graphic3d/Graphic3d_AttribBuffer.cxx | 5 +-- src/Graphic3d/Graphic3d_AttribBuffer.hxx | 3 +- src/Graphic3d/Graphic3d_Buffer.hxx | 18 ++++++---- src/Graphic3d/Graphic3d_IndexBuffer.hxx | 2 +- src/OpenGl/OpenGl_BackgroundArray.cxx | 2 +- src/OpenGl/OpenGl_CappingPlaneResource.cxx | 2 +- src/OpenGl/OpenGl_PrimitiveArray.cxx | 34 ++++++++++++++++--- src/OpenGl/OpenGl_VertexBuffer.hxx | 2 ++ src/Select3D/Select3D_BVHIndexBuffer.hxx | 2 +- src/ViewerTest/ViewerTest_ObjectCommands.cxx | 30 +++++++++++++++- tests/bugs/vis/bug30076 | 11 ++++++ 12 files changed, 94 insertions(+), 20 deletions(-) create mode 100644 tests/bugs/vis/bug30076 diff --git a/src/Graphic3d/Graphic3d_ArrayOfPrimitives.cxx b/src/Graphic3d/Graphic3d_ArrayOfPrimitives.cxx index 3a676d252f..1cd421ff07 100644 --- a/src/Graphic3d/Graphic3d_ArrayOfPrimitives.cxx +++ b/src/Graphic3d/Graphic3d_ArrayOfPrimitives.cxx @@ -65,12 +65,13 @@ Graphic3d_ArrayOfPrimitives::Graphic3d_ArrayOfPrimitives (const Graphic3d_TypeOf 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); diff --git a/src/Graphic3d/Graphic3d_AttribBuffer.cxx b/src/Graphic3d/Graphic3d_AttribBuffer.cxx index 9df60114a4..e6c4134f51 100644 --- a/src/Graphic3d/Graphic3d_AttribBuffer.cxx +++ b/src/Graphic3d/Graphic3d_AttribBuffer.cxx @@ -14,8 +14,9 @@ #include 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) { } diff --git a/src/Graphic3d/Graphic3d_AttribBuffer.hxx b/src/Graphic3d/Graphic3d_AttribBuffer.hxx index d5a81e2950..8566ed0ed4 100644 --- a/src/Graphic3d/Graphic3d_AttribBuffer.hxx +++ b/src/Graphic3d/Graphic3d_AttribBuffer.hxx @@ -22,7 +22,8 @@ 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_Boolean isInterleaved, Standard_Boolean isMutable, + Standard_Integer theMaxNbElements); Standard_EXPORT Standard_Boolean Invalidate(Standard_Integer theAttributeIndex); Standard_EXPORT Standard_Boolean Invalidate(Standard_Integer theAttributeIndex, diff --git a/src/Graphic3d/Graphic3d_Buffer.hxx b/src/Graphic3d/Graphic3d_Buffer.hxx index 3d68b6a832..8733971855 100644 --- a/src/Graphic3d/Graphic3d_Buffer.hxx +++ b/src/Graphic3d/Graphic3d_Buffer.hxx @@ -82,10 +82,12 @@ public: //! 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) @@ -120,7 +122,7 @@ public: anOffset += Graphic3d_Attribute::Stride (Attribute (anAttribIter).DataType); } if (!bIsInterleaved) - anOffset *= NbElements; + anOffset *= MaxNbElements; return anOffset; } @@ -146,8 +148,9 @@ public: 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; } } @@ -158,8 +161,9 @@ public: 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; } } @@ -205,6 +209,7 @@ public: Stride = aStride; NbElements = theNbElems; + MaxNbElements = theNbElems; NbAttributes = theNbAttribs; if (NbElements != 0) { @@ -261,6 +266,7 @@ 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 + Standard_Integer MaxNbElements; //!< maximum number of the elements private: Standard_Boolean bIsInterleaved; diff --git a/src/Graphic3d/Graphic3d_IndexBuffer.hxx b/src/Graphic3d/Graphic3d_IndexBuffer.hxx index 10d953df3c..ccb2491c65 100644 --- a/src/Graphic3d/Graphic3d_IndexBuffer.hxx +++ b/src/Graphic3d/Graphic3d_IndexBuffer.hxx @@ -23,7 +23,7 @@ public: //! 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 diff --git a/src/OpenGl/OpenGl_BackgroundArray.cxx b/src/OpenGl/OpenGl_BackgroundArray.cxx index e133714c6f..9acb58f2d6 100644 --- a/src/OpenGl/OpenGl_BackgroundArray.cxx +++ b/src/OpenGl/OpenGl_BackgroundArray.cxx @@ -35,7 +35,7 @@ OpenGl_BackgroundArray::OpenGl_BackgroundArray (const Graphic3d_TypeOfBackground 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; diff --git a/src/OpenGl/OpenGl_CappingPlaneResource.cxx b/src/OpenGl/OpenGl_CappingPlaneResource.cxx index 7e4f030f3a..9b52c4adff 100755 --- a/src/OpenGl/OpenGl_CappingPlaneResource.cxx +++ b/src/OpenGl/OpenGl_CappingPlaneResource.cxx @@ -72,7 +72,7 @@ OpenGl_CappingPlaneResource::OpenGl_CappingPlaneResource (const Handle(Graphic3d { // 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 }, diff --git a/src/OpenGl/OpenGl_PrimitiveArray.cxx b/src/OpenGl/OpenGl_PrimitiveArray.cxx index 5a8123211d..ba74da67c6 100644 --- a/src/OpenGl/OpenGl_PrimitiveArray.cxx +++ b/src/OpenGl/OpenGl_PrimitiveArray.cxx @@ -361,13 +361,34 @@ Standard_Boolean OpenGl_PrimitiveArray::buildVBO (const Handle(OpenGl_Context)& Standard_Boolean OpenGl_PrimitiveArray::updateVBO(const Handle(OpenGl_Context)& theCtx) const { - const std::vector& 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& 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; } @@ -756,8 +777,8 @@ void OpenGl_PrimitiveArray::Render (const Handle(OpenGl_Workspace)& theWorkspace 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; @@ -880,6 +901,9 @@ void OpenGl_PrimitiveArray::Render (const Handle(OpenGl_Workspace)& theWorkspace 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); } @@ -1004,7 +1028,7 @@ Standard_Boolean OpenGl_PrimitiveArray::processIndices (const Handle(OpenGl_Cont if (myAttribs->NbElements > std::numeric_limits::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 diff --git a/src/OpenGl/OpenGl_VertexBuffer.hxx b/src/OpenGl/OpenGl_VertexBuffer.hxx index 2558a0c3ae..7a222bc972 100644 --- a/src/OpenGl/OpenGl_VertexBuffer.hxx +++ b/src/OpenGl/OpenGl_VertexBuffer.hxx @@ -48,6 +48,8 @@ public: return myBufferId != NO_BUFFER; } + inline GLuint BufferId() const { return myBufferId; } + //! @return the number of components per generic vertex attribute. inline GLuint GetComponentsNb() const { diff --git a/src/Select3D/Select3D_BVHIndexBuffer.hxx b/src/Select3D/Select3D_BVHIndexBuffer.hxx index ceaf913a9b..67bbe6becc 100644 --- a/src/Select3D/Select3D_BVHIndexBuffer.hxx +++ b/src/Select3D/Select3D_BVHIndexBuffer.hxx @@ -28,7 +28,7 @@ public: //! 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; } diff --git a/src/ViewerTest/ViewerTest_ObjectCommands.cxx b/src/ViewerTest/ViewerTest_ObjectCommands.cxx index f221369710..50bd903401 100644 --- a/src/ViewerTest/ViewerTest_ObjectCommands.cxx +++ b/src/ViewerTest/ViewerTest_ObjectCommands.cxx @@ -3165,6 +3165,20 @@ public: 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, @@ -3276,7 +3290,7 @@ MyPArrayObject::MyPArrayObject (Handle(TColStd_HArray1OfAsciiString) theArrayDes 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, @@ -3448,6 +3462,20 @@ static int VDrawPArray (Draw_Interpretor& di, Standard_Integer argc, const char* 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"; diff --git a/tests/bugs/vis/bug30076 b/tests/bugs/vis/bug30076 new file mode 100644 index 0000000000..3c9d3622a4 --- /dev/null +++ b/tests/bugs/vis/bug30076 @@ -0,0 +1,11 @@ +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 -- 2.39.5