]> OCCT Git - occt-copy.git/commitdiff
debug on the OCC automatic test
authorasl <asl@opencascade.com>
Wed, 29 Aug 2018 10:52:22 +0000 (13:52 +0300)
committerasl <asl@opencascade.com>
Wed, 29 Aug 2018 10:52:22 +0000 (13:52 +0300)
12 files changed:
src/Graphic3d/Graphic3d_ArrayOfPrimitives.cxx
src/Graphic3d/Graphic3d_AttribBuffer.cxx
src/Graphic3d/Graphic3d_AttribBuffer.hxx
src/Graphic3d/Graphic3d_Buffer.hxx
src/Graphic3d/Graphic3d_IndexBuffer.hxx
src/OpenGl/OpenGl_BackgroundArray.cxx
src/OpenGl/OpenGl_CappingPlaneResource.cxx
src/OpenGl/OpenGl_PrimitiveArray.cxx
src/OpenGl/OpenGl_VertexBuffer.hxx
src/Select3D/Select3D_BVHIndexBuffer.hxx
src/ViewerTest/ViewerTest_ObjectCommands.cxx
tests/bugs/vis/bug30076 [new file with mode: 0644]

index 3a676d252fd816a82a0e1ae6a38d8c2056458a66..1cd421ff072836df34c564315b79540dbc21cbf0 100644 (file)
@@ -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);
index 9df60114a429e168e091763d3870fc7de5bfc7b2..e6c4134f5169b5e082b4c65898a3d09e9f10439d 100644 (file)
@@ -14,8 +14,9 @@
 #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)
 {
 }
 
index d5a81e29509fa419611c67d9dddd957132cb7ef2..8566ed0ed4bdac2e85f1e5a939496a4cc0a0de40 100644 (file)
@@ -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,
index 3d68b6a8327a9a3278333fe5d7ca194f297ef97a..8733971855f91a8357724c9bf3944dbe5ecfe5e4 100644 (file)
@@ -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;
index 10d953df3c005f8c604a5fb633f9cc62311a8e90..ccb2491c65aa1eab7c3d0791880f15f7fe539fb2 100644 (file)
@@ -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<typename IndexType_t>
index e133714c6f86505803de3f98b3a0c5be0dd1fe09..9acb58f2d699a2329f9375b5374e62321002876e 100644 (file)
@@ -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;
 
index 7e4f030f3a806d2a20ef2404da844ecbc5a24c6a..9b52c4adffdb051eeaa06ccb80c61f0a134c7196 100755 (executable)
@@ -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 },
index 5a8123211d9cc98d1cbeb1402046d86633b720a6..ba74da67c69533bb145b722a7710561ce4bbb3a3 100644 (file)
@@ -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<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;
 }
@@ -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<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
index 2558a0c3ae56dbb3555007c56751285533a42f6f..7a222bc9727a535fa4c9de72d512b93156dc6bd1 100644 (file)
@@ -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
   {
index ceaf913a9b2ea363326190c097239b4c70e0f7e8..67bbe6becc0536c77e1db96f94e42314145165b9 100644 (file)
@@ -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; }
 
index f221369710a6b06d1cb1eb823e4363ca6f9299a6..50bd903401a65eb682db1675be4c478a2acc6658 100644 (file)
@@ -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 (file)
index 0000000..3c9d362
--- /dev/null
@@ -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