0032153: Visualization, Graphic3d_ArrayOfPrimitives - share common allocator
authorkgv <kgv@opencascade.com>
Sun, 21 Feb 2021 17:55:35 +0000 (20:55 +0300)
committerbugmaster <bugmaster@opencascade.com>
Thu, 25 Feb 2021 15:55:28 +0000 (18:55 +0300)
Added method Graphic3d_Buffer::DefaultAllocator(), which is now used across code.

src/Graphic3d/Graphic3d_ArrayOfPrimitives.cxx
src/Graphic3d/Graphic3d_Buffer.cxx
src/Graphic3d/Graphic3d_Buffer.hxx
src/Graphic3d/Graphic3d_HatchStyle.cxx
src/OpenGl/OpenGl_BackgroundArray.cxx
src/OpenGl/OpenGl_CappingPlaneResource.cxx
src/OpenGl/OpenGl_FrameBuffer.cxx
src/OpenGl/OpenGl_PrimitiveArray.cxx
src/OpenGl/OpenGl_VertexBufferCompat.cxx
src/OpenGl/OpenGl_Workspace.cxx
src/Select3D/Select3D_SensitivePrimitiveArray.cxx

index 5e81142..c2497c9 100644 (file)
@@ -26,7 +26,6 @@
 #include <Graphic3d_AttribBuffer.hxx>
 #include <Graphic3d_MutableIndexBuffer.hxx>
 
-#include <NCollection_AlignedAllocator.hxx>
 #include <TCollection_AsciiString.hxx>
 
 #include <stdio.h>
@@ -103,7 +102,7 @@ void Graphic3d_ArrayOfPrimitives::init (Graphic3d_TypeOfPrimitiveArray theType,
   myIndices.Nullify();
   myBounds.Nullify();
 
-  Handle(NCollection_AlignedAllocator) anAlloc = new NCollection_AlignedAllocator (16);
+  const Handle(NCollection_BaseAllocator)& anAlloc = Graphic3d_Buffer::DefaultAllocator();
   if ((theArrayOptions & Graphic3d_ArrayFlags_AttribsMutable) != 0
    || (theArrayOptions & Graphic3d_ArrayFlags_AttribsDeinterleaved) != 0)
   {
index 47a0114..5eb0125 100644 (file)
 // commercial license or contractual agreement.
 
 #include <Graphic3d_Buffer.hxx>
+
 #include <Graphic3d_BoundBuffer.hxx>
 #include <Graphic3d_MutableIndexBuffer.hxx>
+#include <NCollection_AlignedAllocator.hxx>
 
 IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_Buffer,      NCollection_Buffer)
 IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_IndexBuffer, Graphic3d_Buffer)
 IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_BoundBuffer, NCollection_Buffer)
 IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_MutableIndexBuffer, Graphic3d_IndexBuffer)
 
+// =======================================================================
+// function : DefaultAllocator
+// purpose  :
+// =======================================================================
+const Handle(NCollection_BaseAllocator)& Graphic3d_Buffer::DefaultAllocator()
+{
+  static const Handle(NCollection_BaseAllocator) THE_ALLOC = new NCollection_AlignedAllocator (16);
+  return THE_ALLOC;
+}
+
 // =======================================================================
 // function : DumpJson
 // purpose  :
index 02f1631..8b84192 100644 (file)
@@ -74,6 +74,11 @@ typedef NCollection_Array1<Graphic3d_Attribute> Graphic3d_Array1OfAttribute;
 class Graphic3d_Buffer : public NCollection_Buffer
 {
   DEFINE_STANDARD_RTTIEXT(Graphic3d_Buffer, NCollection_Buffer)
+public:
+
+  //! Return default vertex data allocator.
+  Standard_EXPORT static const Handle(NCollection_BaseAllocator)& DefaultAllocator();
+
 public:
 
   //! Empty constructor.
index 6cb6476..2d09850 100644 (file)
@@ -14,7 +14,7 @@
 // commercial license or contractual agreement.
 
 #include <Graphic3d_HatchStyle.hxx>
-#include <NCollection_AlignedAllocator.hxx>
+
 #include <Standard_Atomic.hxx>
 #include <Standard_ProgramError.hxx>
 
@@ -496,7 +496,7 @@ Graphic3d_HatchStyle::Graphic3d_HatchStyle (const Handle(Image_PixMap)& thePatte
     "Hatch pattern must be a 32*32 bitmap (Image_Format_Gray format)");
 
   const Standard_Size aByteSize = thePattern->SizeBytes();
-  Handle(NCollection_AlignedAllocator) anAllocator = new NCollection_AlignedAllocator (16);
+  const Handle(NCollection_BaseAllocator)& anAllocator = Image_PixMap::DefaultAllocator();
   myPattern = new NCollection_Buffer (anAllocator);
   myPattern->Allocate (aByteSize);
   std::memcpy (myPattern->ChangeData(), thePattern->Data(), aByteSize);
index 866514d..6bd9193 100644 (file)
@@ -16,7 +16,6 @@
 #include <OpenGl_BackgroundArray.hxx>
 
 #include <Aspect_FillMethod.hxx>
-#include <NCollection_AlignedAllocator.hxx>
 #include <OpenGl_Texture.hxx>
 #include <OpenGl_View.hxx>
 #include <Graphic3d_TextureParams.hxx>
@@ -198,8 +197,7 @@ Standard_Boolean OpenGl_BackgroundArray::createGradientArray (const Handle(OpenG
 
   if (myAttribs.IsNull())
   {
-    Handle(NCollection_AlignedAllocator) anAlloc = new NCollection_AlignedAllocator (16);
-    myAttribs = new Graphic3d_Buffer (anAlloc);
+    myAttribs = new Graphic3d_Buffer (Graphic3d_Buffer::DefaultAllocator());
   }
   if (!myAttribs->Init (4, aGragientAttribInfo, 2))
   {
@@ -332,8 +330,7 @@ Standard_Boolean OpenGl_BackgroundArray::createTextureArray (const Handle(OpenGl
 
   if (myAttribs.IsNull())
   {
-    Handle(NCollection_AlignedAllocator) anAlloc = new NCollection_AlignedAllocator (16);
-    myAttribs = new Graphic3d_Buffer (anAlloc);
+    myAttribs = new Graphic3d_Buffer (Graphic3d_Buffer::DefaultAllocator());
   }
   if (!myAttribs->Init (4, aTextureAttribInfo, 2))
   {
@@ -405,9 +402,8 @@ Standard_Boolean OpenGl_BackgroundArray::createCubeMapArray() const
 
   if (myAttribs.IsNull())
   {
-    Handle(NCollection_AlignedAllocator) anAlloc = new NCollection_AlignedAllocator (16);
-    myAttribs = new Graphic3d_Buffer (anAlloc);
-    myIndices = new Graphic3d_IndexBuffer (anAlloc);
+    myAttribs = new Graphic3d_Buffer (Graphic3d_Buffer::DefaultAllocator());
+    myIndices = new Graphic3d_IndexBuffer (Graphic3d_Buffer::DefaultAllocator());
   }
   if (!myAttribs->Init (8, aCubeMapAttribInfo, 1)
    || !myIndices->Init<unsigned short> (14))
index 6825aef..6b1ce90 100755 (executable)
@@ -13,8 +13,8 @@
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
-#include <NCollection_AlignedAllocator.hxx>
 #include <OpenGl_CappingPlaneResource.hxx>
+
 #include <OpenGl_Context.hxx>
 #include <OpenGl_Vec.hxx>
 #include <OpenGl_ShaderManager.hxx>
@@ -71,9 +71,7 @@ OpenGl_CappingPlaneResource::OpenGl_CappingPlaneResource (const Handle(Graphic3d
   myEquationMod ((unsigned int )-1),
   myAspectMod   ((unsigned int )-1)
 {
-  // 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 (Graphic3d_Buffer::DefaultAllocator());
   Graphic3d_Attribute anAttribInfo[] =
   {
     { Graphic3d_TOA_POS,  Graphic3d_TOD_VEC4 },
index 50d47ef..44b94e0 100644 (file)
@@ -15,7 +15,6 @@
 #include <OpenGl_FrameBuffer.hxx>
 #include <OpenGl_ArbFBO.hxx>
 
-#include <NCollection_AlignedAllocator.hxx>
 #include <Standard_Assert.hxx>
 #include <TCollection_ExtendedString.hxx>
 
@@ -993,9 +992,8 @@ Standard_Boolean OpenGl_FrameBuffer::BufferDump (const Handle(OpenGl_Context)& t
 
   if (toConvRgba2Rgb)
   {
-    Handle(NCollection_BaseAllocator) anAlloc = new NCollection_AlignedAllocator (16);
     const Standard_Size aRowSize = theImage.SizeX() * 4;
-    NCollection_Buffer aRowBuffer (anAlloc);
+    NCollection_Buffer aRowBuffer (Image_PixMap::DefaultAllocator());
     if (!aRowBuffer.Allocate (aRowSize))
     {
       return Standard_False;
index 88c2519..9a1a255 100644 (file)
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
+#include <OpenGl_PrimitiveArray.hxx>
+
 #include <OpenGl_Aspects.hxx>
 #include <OpenGl_Context.hxx>
 #include <OpenGl_GraphicDriver.hxx>
 #include <OpenGl_IndexBuffer.hxx>
 #include <OpenGl_PointSprite.hxx>
-#include <OpenGl_PrimitiveArray.hxx>
 #include <OpenGl_Sampler.hxx>
 #include <OpenGl_ShaderManager.hxx>
 #include <OpenGl_ShaderProgram.hxx>
@@ -27,7 +28,6 @@
 #include <OpenGl_View.hxx>
 #include <OpenGl_Workspace.hxx>
 #include <Graphic3d_TextureParams.hxx>
-#include <NCollection_AlignedAllocator.hxx>
 
 namespace
 {
@@ -1165,7 +1165,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 (Graphic3d_Buffer::DefaultAllocator());
     if (!anAttribs->Init (myIndices->NbElements, myAttribs->AttributesArray(), myAttribs->NbAttributes))
     {
       return Standard_False; // failed to initialize attribute array
index 2ba9a1d..2add516 100644 (file)
@@ -14,9 +14,6 @@
 
 #include <OpenGl_VertexBufferCompat.hxx>
 
-#include <NCollection_AlignedAllocator.hxx>
-
-
 IMPLEMENT_STANDARD_RTTIEXT(OpenGl_VertexBufferCompat,OpenGl_VertexBuffer)
 
 // =======================================================================
@@ -46,8 +43,7 @@ bool OpenGl_VertexBufferCompat::Create (const Handle(OpenGl_Context)& )
   if (myBufferId == NO_BUFFER)
   {
     myBufferId = (GLuint )-1; // dummy identifier...
-    Handle(NCollection_AlignedAllocator) anAlloc = new NCollection_AlignedAllocator (16);
-    myData = new NCollection_Buffer (anAlloc);
+    myData = new NCollection_Buffer (Graphic3d_Buffer::DefaultAllocator());
   }
   return myBufferId != NO_BUFFER;
 }
index bfe72a4..8ef92f8 100644 (file)
@@ -31,7 +31,6 @@
 
 #include <Graphic3d_TextureParams.hxx>
 #include <Graphic3d_TransformUtils.hxx>
-#include <NCollection_AlignedAllocator.hxx>
 
 IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Workspace,Standard_Transient)
 
index 96e9922..00939c5 100644 (file)
@@ -15,7 +15,6 @@
 
 #include <Select3D_SensitivePrimitiveArray.hxx>
 
-#include <NCollection_AlignedAllocator.hxx>
 #include <OSD_Parallel.hxx>
 #include <Standard_Atomic.hxx>
 
@@ -165,7 +164,7 @@ Select3D_SensitivePrimitiveArray::Select3D_SensitivePrimitiveArray (const Handle
   myPatchSizeMax (1),
   myPatchDistance (ShortRealLast()),
   myIs3d (false),
-  myBvhIndices (new NCollection_AlignedAllocator(16)),
+  myBvhIndices (Graphic3d_Buffer::DefaultAllocator()),
   myMinDepthElem (RealLast()),
   myMinDepthNode (RealLast()),
   myMinDepthEdge (RealLast()),