From 02a2beaad9b38e75a2717c8efe711fe89fab08a3 Mon Sep 17 00:00:00 2001 From: kgv Date: Sun, 21 Feb 2021 20:55:35 +0300 Subject: [PATCH] 0032153: Visualization, Graphic3d_ArrayOfPrimitives - share common allocator Added method Graphic3d_Buffer::DefaultAllocator(), which is now used across code. --- src/Graphic3d/Graphic3d_ArrayOfPrimitives.cxx | 3 +-- src/Graphic3d/Graphic3d_Buffer.cxx | 12 ++++++++++++ src/Graphic3d/Graphic3d_Buffer.hxx | 5 +++++ src/Graphic3d/Graphic3d_HatchStyle.cxx | 4 ++-- src/OpenGl/OpenGl_BackgroundArray.cxx | 12 ++++-------- src/OpenGl/OpenGl_CappingPlaneResource.cxx | 6 ++---- src/OpenGl/OpenGl_FrameBuffer.cxx | 4 +--- src/OpenGl/OpenGl_PrimitiveArray.cxx | 6 +++--- src/OpenGl/OpenGl_VertexBufferCompat.cxx | 6 +----- src/OpenGl/OpenGl_Workspace.cxx | 1 - src/Select3D/Select3D_SensitivePrimitiveArray.cxx | 3 +-- 11 files changed, 32 insertions(+), 30 deletions(-) diff --git a/src/Graphic3d/Graphic3d_ArrayOfPrimitives.cxx b/src/Graphic3d/Graphic3d_ArrayOfPrimitives.cxx index 5e81142fb6..c2497c98ad 100644 --- a/src/Graphic3d/Graphic3d_ArrayOfPrimitives.cxx +++ b/src/Graphic3d/Graphic3d_ArrayOfPrimitives.cxx @@ -26,7 +26,6 @@ #include #include -#include #include #include @@ -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) { diff --git a/src/Graphic3d/Graphic3d_Buffer.cxx b/src/Graphic3d/Graphic3d_Buffer.cxx index 47a0114e02..5eb0125df1 100644 --- a/src/Graphic3d/Graphic3d_Buffer.cxx +++ b/src/Graphic3d/Graphic3d_Buffer.cxx @@ -12,14 +12,26 @@ // commercial license or contractual agreement. #include + #include #include +#include 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 : diff --git a/src/Graphic3d/Graphic3d_Buffer.hxx b/src/Graphic3d/Graphic3d_Buffer.hxx index 02f16313ba..8b84192038 100644 --- a/src/Graphic3d/Graphic3d_Buffer.hxx +++ b/src/Graphic3d/Graphic3d_Buffer.hxx @@ -74,6 +74,11 @@ typedef NCollection_Array1 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. diff --git a/src/Graphic3d/Graphic3d_HatchStyle.cxx b/src/Graphic3d/Graphic3d_HatchStyle.cxx index 6cb6476084..2d0985038a 100644 --- a/src/Graphic3d/Graphic3d_HatchStyle.cxx +++ b/src/Graphic3d/Graphic3d_HatchStyle.cxx @@ -14,7 +14,7 @@ // commercial license or contractual agreement. #include -#include + #include #include @@ -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); diff --git a/src/OpenGl/OpenGl_BackgroundArray.cxx b/src/OpenGl/OpenGl_BackgroundArray.cxx index 866514d456..6bd9193068 100644 --- a/src/OpenGl/OpenGl_BackgroundArray.cxx +++ b/src/OpenGl/OpenGl_BackgroundArray.cxx @@ -16,7 +16,6 @@ #include #include -#include #include #include #include @@ -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 (14)) diff --git a/src/OpenGl/OpenGl_CappingPlaneResource.cxx b/src/OpenGl/OpenGl_CappingPlaneResource.cxx index 6825aefea1..6b1ce90734 100755 --- a/src/OpenGl/OpenGl_CappingPlaneResource.cxx +++ b/src/OpenGl/OpenGl_CappingPlaneResource.cxx @@ -13,8 +13,8 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#include #include + #include #include #include @@ -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 }, diff --git a/src/OpenGl/OpenGl_FrameBuffer.cxx b/src/OpenGl/OpenGl_FrameBuffer.cxx index 50d47ef364..44b94e0903 100644 --- a/src/OpenGl/OpenGl_FrameBuffer.cxx +++ b/src/OpenGl/OpenGl_FrameBuffer.cxx @@ -15,7 +15,6 @@ #include #include -#include #include #include @@ -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; diff --git a/src/OpenGl/OpenGl_PrimitiveArray.cxx b/src/OpenGl/OpenGl_PrimitiveArray.cxx index 88c2519390..9a1a25559c 100644 --- a/src/OpenGl/OpenGl_PrimitiveArray.cxx +++ b/src/OpenGl/OpenGl_PrimitiveArray.cxx @@ -13,12 +13,13 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. +#include + #include #include #include #include #include -#include #include #include #include @@ -27,7 +28,6 @@ #include #include #include -#include namespace { @@ -1165,7 +1165,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)); + 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 diff --git a/src/OpenGl/OpenGl_VertexBufferCompat.cxx b/src/OpenGl/OpenGl_VertexBufferCompat.cxx index 2ba9a1d1b4..2add516459 100644 --- a/src/OpenGl/OpenGl_VertexBufferCompat.cxx +++ b/src/OpenGl/OpenGl_VertexBufferCompat.cxx @@ -14,9 +14,6 @@ #include -#include - - 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; } diff --git a/src/OpenGl/OpenGl_Workspace.cxx b/src/OpenGl/OpenGl_Workspace.cxx index bfe72a4278..8ef92f85b1 100644 --- a/src/OpenGl/OpenGl_Workspace.cxx +++ b/src/OpenGl/OpenGl_Workspace.cxx @@ -31,7 +31,6 @@ #include #include -#include IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Workspace,Standard_Transient) diff --git a/src/Select3D/Select3D_SensitivePrimitiveArray.cxx b/src/Select3D/Select3D_SensitivePrimitiveArray.cxx index 96e9922087..00939c5c07 100644 --- a/src/Select3D/Select3D_SensitivePrimitiveArray.cxx +++ b/src/Select3D/Select3D_SensitivePrimitiveArray.cxx @@ -15,7 +15,6 @@ #include -#include #include #include @@ -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()),