]> OCCT Git - occt-copy.git/commitdiff
0030076: Visualization, TKV3d - API to update certain vertex attribute(s) without...
authorasl <asl@opencascade.com>
Thu, 23 Aug 2018 05:42:40 +0000 (08:42 +0300)
committerasl <asl@opencascade.com>
Thu, 23 Aug 2018 12:31:48 +0000 (15:31 +0300)
Graphic3d_Buffer and classes for arrays of primitives support now the non-interleaved mode for the attributes storage

21 files changed:
src/Graphic3d/FILES
src/Graphic3d/Graphic3d_ArrayOfPoints.hxx
src/Graphic3d/Graphic3d_ArrayOfPolygons.hxx
src/Graphic3d/Graphic3d_ArrayOfPolylines.hxx
src/Graphic3d/Graphic3d_ArrayOfPrimitives.cxx
src/Graphic3d/Graphic3d_ArrayOfPrimitives.hxx
src/Graphic3d/Graphic3d_ArrayOfQuadrangleStrips.hxx
src/Graphic3d/Graphic3d_ArrayOfQuadrangles.hxx
src/Graphic3d/Graphic3d_ArrayOfSegments.hxx
src/Graphic3d/Graphic3d_ArrayOfTriangleFans.hxx
src/Graphic3d/Graphic3d_ArrayOfTriangleStrips.hxx
src/Graphic3d/Graphic3d_ArrayOfTriangles.hxx
src/Graphic3d/Graphic3d_AttribBuffer.cxx [new file with mode: 0644]
src/Graphic3d/Graphic3d_AttribBuffer.hxx [new file with mode: 0644]
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_PrimitiveArray.hxx
src/Select3D/Select3D_BVHIndexBuffer.hxx

index 2c15a0d70f11ec735989cb9d020313277216141f..51e4b71c7554cf429966f5b0e812e4fda0e99e55 100755 (executable)
@@ -19,6 +19,8 @@ Graphic3d_AspectMarker3d.hxx
 Graphic3d_AspectText3d.cxx
 Graphic3d_AspectText3d.hxx
 Graphic3d_AspectTextDefinitionError.hxx
+Graphic3d_AttribBuffer.cxx
+Graphic3d_AttribBuffer.hxx
 Graphic3d_BndBox3d.hxx
 Graphic3d_BndBox4d.hxx
 Graphic3d_BndBox4f.hxx
index 99c5ae0b88bffe8dc68c8eb6718fae6108b72753..89f8e8d8ceeb8f2aa758082ea7658ae702e1678f 100644 (file)
@@ -29,8 +29,10 @@ public:
   //! @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) {}
 
 };
 
index 7459670e84a05c397899f402887583002e8e1a5a..d7f93ad45d6098c4ad4a5fd31c54d302fed0492c 100644 (file)
@@ -95,8 +95,10 @@ public:
                              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) {}
 
 };
 
index e7aed229031ad218e4ae0ae1f364b2a074c8be72..28fc7a871724f68355b27d0d172bec908ce62bb9 100644 (file)
@@ -93,8 +93,10 @@ public:
                               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) {}
 
 };
 
index 2e9ccce9e2780990e8cc55b0c12d3710c5131a56..3a676d252fd816a82a0e1ae6a38d8c2056458a66 100644 (file)
@@ -53,7 +53,9 @@ Graphic3d_ArrayOfPrimitives::Graphic3d_ArrayOfPrimitives (const Graphic3d_TypeOf
                                                           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),
@@ -63,7 +65,7 @@ Graphic3d_ArrayOfPrimitives::Graphic3d_ArrayOfPrimitives (const Graphic3d_TypeOf
   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;
@@ -146,17 +148,23 @@ Graphic3d_ArrayOfPrimitives::Graphic3d_ArrayOfPrimitives (const Graphic3d_TypeOf
         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;
       }
     }
index 490574872a0f147253ed3d7c4d2cda35ae049681..7115359f1ff1f0d30dee7d3bcad457d9d5b5af16 100644 (file)
@@ -16,7 +16,7 @@
 #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>
@@ -68,7 +68,7 @@ public:
   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; }
@@ -77,13 +77,13 @@ public:
   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; }
@@ -345,10 +345,10 @@ public:
       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);
@@ -370,10 +370,10 @@ public:
       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);
@@ -395,9 +395,9 @@ public:
       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;
     }
   }
 
@@ -420,9 +420,9 @@ public:
       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);
@@ -449,9 +449,9 @@ public:
       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);
     }
@@ -480,7 +480,7 @@ public:
       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());
@@ -499,7 +499,7 @@ public:
                     Graphic3d_Vec4ub&      theColor) const
   {
     if (myAttribs.IsNull()
-     || myVCol == 0)
+     || myICol == 0)
     {
       throw Standard_OutOfRange ("Primitive array does not define color attribute");
     }
@@ -518,7 +518,7 @@ public:
   {
     theR = theG = theB = 0.0;
     if (myAttribs.IsNull()
-     || myVCol == 0)
+     || myICol == 0)
     {
       return;
     }
@@ -537,7 +537,7 @@ public:
   //! 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));
     }
@@ -565,7 +565,7 @@ public:
       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());
@@ -596,7 +596,7 @@ public:
       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());
@@ -773,21 +773,26 @@ protected: //! @name protected constructors
                                                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
index 8f6fbac071f25d5f3f6a014e913f9a6969518f3b..b0b4b58a33677877275e6d6055067b455744fec1 100644 (file)
@@ -53,8 +53,10 @@ public:
                                      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) {}
 
 };
 
index eb6671b4542fad41d11487e838c251234307fb43..131ade83d43de0cc3bffc13e6e96dd9d51740f87 100644 (file)
@@ -54,8 +54,10 @@ public:
                                 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) {}
 
 };
 
index 07750ff7fb55ecfbc3acd87f3cf2796547d6bf8e..3507611740968a85f65adaff6594d04ea64eb237 100644 (file)
@@ -51,8 +51,10 @@ public:
   //! @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) {}
 
 };
 
index 366d781133fabdd29f3e246f30aa888806bf6be1..f27c88b4d0b1c5de6b5f87d8a2c15a89b5718a9e 100644 (file)
@@ -51,8 +51,10 @@ public:
                                  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) {}
 
 };
 
index e1a05e470a03972cab978ecd241953d32296581b..a738ad44bf4f529a7cf06a281105a8b6e01abf65 100644 (file)
@@ -56,8 +56,10 @@ public:
                                    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) {}
 
 };
 
index e4035a7450847bbb3eaddd64a61c2ddb3d1f3449..c33a5382bfd085e54d851482adc9761a24d6710d 100644 (file)
@@ -54,8 +54,10 @@ public:
                               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) {}
 
 };
 
diff --git a/src/Graphic3d/Graphic3d_AttribBuffer.cxx b/src/Graphic3d/Graphic3d_AttribBuffer.cxx
new file mode 100644 (file)
index 0000000..9df6011
--- /dev/null
@@ -0,0 +1,75 @@
+// 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;
+  }
+}
+
+
diff --git a/src/Graphic3d/Graphic3d_AttribBuffer.hxx b/src/Graphic3d/Graphic3d_AttribBuffer.hxx
new file mode 100644 (file)
index 0000000..d5a81e2
--- /dev/null
@@ -0,0 +1,40 @@
+// 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
index 6aaa671a37461200468a23b78f745e29bff5276d..3d68b6a8327a9a3278333fe5d7ca194f297ef97a 100644 (file)
@@ -17,6 +17,7 @@
 #include <Graphic3d_Vec.hxx>
 #include <NCollection_Array1.hxx>
 #include <NCollection_Buffer.hxx>
+#include <vector>
 
 //! Type of attribute in Vertex Buffer
 enum Graphic3d_TypeOfAttribute
@@ -68,17 +69,26 @@ struct Graphic3d_Attribute
 
 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)
   {
     //
   }
@@ -109,6 +119,8 @@ public:
     {
       anOffset += Graphic3d_Attribute::Stride (Attribute (anAttribIter).DataType);
     }
+    if (!bIsInterleaved)
+      anOffset *= NbElements;
     return anOffset;
   }
 
@@ -128,22 +140,34 @@ public:
   }
 
   //! 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.
@@ -163,7 +187,7 @@ public:
   }
 
   //! 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)
   {
@@ -197,22 +221,52 @@ public:
         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
index 6b6bc9ebbce4f1012d7ab56dc79fada64cdf44e9..10d953df3c005f8c604a5fb633f9cc62311a8e90 100644 (file)
@@ -23,7 +23,7 @@ public:
 
   //! 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>
@@ -76,6 +76,14 @@ public:
     }
   }
 
+  //! 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
index f760dcfc9820b102d204d6118db1cb7c11e2d609..e133714c6f86505803de3f98b3a0c5be0dd1fe09 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);
+  myAttribs = new Graphic3d_Buffer (anAlloc, true, false);
 
   myDrawMode = GL_TRIANGLE_STRIP;
 
index d551231791c59aa9231043da54b46b4019da80d9..7e4f030f3a806d2a20ef2404da844ecbc5a24c6a 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);
+  Handle(Graphic3d_Buffer) anAttribs = new Graphic3d_Buffer (anAlloc, true, false);
   Graphic3d_Attribute anAttribInfo[] =
   {
     { Graphic3d_TOA_POS,  Graphic3d_TOD_VEC4 },
index 71c96fe539d5d0be027b2562397d9e658099a37e..5a8123211d9cc98d1cbeb1402046d86633b720a6 100644 (file)
@@ -74,14 +74,16 @@ public:
   //! 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);
   }
@@ -160,7 +162,7 @@ public:
       }
 
       TheBaseClass::bindAttribute (theGlCtx, anAttrib.Id, aNbComp, aDataType, Stride, anOffset);
-      anOffset += Graphic3d_Attribute::Stride (anAttrib.DataType);
+      anOffset += Graphic3d_Attribute::Stride (anAttrib.DataType) * NbElements;
     }
   }
 
@@ -183,7 +185,7 @@ public:
 
   Graphic3d_Attribute Attribs[NbAttributes];
   Standard_Integer    Stride;
-
+  Standard_Integer    NbElements;
 };
 
 // =======================================================================
@@ -225,7 +227,8 @@ Standard_Boolean OpenGl_PrimitiveArray::initNormalVbo (const Handle(OpenGl_Conte
   }
 
   // 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 ";
@@ -297,7 +300,8 @@ Standard_Boolean OpenGl_PrimitiveArray::buildVBO (const Handle(OpenGl_Context)&
    && initNormalVbo (theCtx))
   {
     if (!theCtx->caps->keepArrayData
-     && !theToKeepData)
+     && !theToKeepData
+     && !myAttribs->IsMutable())
     {
       myIndices.Nullify();
       myAttribs.Nullify();
@@ -344,7 +348,8 @@ Standard_Boolean OpenGl_PrimitiveArray::buildVBO (const Handle(OpenGl_Context)&
   }
   myVboAttribs = aVboAttribs;
   if (!theCtx->caps->keepArrayData
-   && !theToKeepData)
+   && !theToKeepData
+   && !myAttribs->IsMutable())
   {
     // does not make sense for compatibility mode
     //myIndices.Nullify();
@@ -354,6 +359,19 @@ Standard_Boolean OpenGl_PrimitiveArray::buildVBO (const Handle(OpenGl_Context)&
   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  :
@@ -738,6 +756,9 @@ void OpenGl_PrimitiveArray::Render (const Handle(OpenGl_Workspace)& theWorkspace
     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;
@@ -983,7 +1004,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));
+    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
index 258497db75a7edea44969ca4bea28e9a8bf7e262..a7185b06fb700b8d0d5557ff72cd20a964ee98a8 100644 (file)
@@ -107,6 +107,8 @@ protected:
   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:
index 85d8240c0e9ab191be4c109265c4657e759aff0a..ceaf913a9b2ea363326190c097239b4c70e0f7e8 100644 (file)
@@ -28,7 +28,7 @@ public:
 
   //! 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; }