1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-06 18:26:22 +03:00

0026221: Visualization - use NCollection_IndexedMap instead of NCollection_Sequence in OpenGl_Layer to improve performance

This commit is contained in:
dbp 2015-05-25 09:43:06 +03:00 committed by bugmaster
parent 94f71cad33
commit 9f112210cc
10 changed files with 50 additions and 80 deletions

View File

@ -141,7 +141,6 @@ OpenGl_ShaderManager.hxx
OpenGl_ShaderManager.cxx OpenGl_ShaderManager.cxx
OpenGl_ShaderStates.hxx OpenGl_ShaderStates.hxx
OpenGl_ShaderStates.cxx OpenGl_ShaderStates.cxx
OpenGl_SequenceOfStructure.hxx
Handle_OpenGl_ShaderObject.hxx Handle_OpenGl_ShaderObject.hxx
Handle_OpenGl_ShaderProgram.hxx Handle_OpenGl_ShaderProgram.hxx
Handle_OpenGl_ShaderManager.hxx Handle_OpenGl_ShaderManager.hxx

View File

@ -71,13 +71,13 @@ void OpenGl_BVHClipPrimitiveSet::Swap (const Standard_Integer theIdx1,
// function : Assign // function : Assign
// purpose : // purpose :
// ======================================================================= // =======================================================================
void OpenGl_BVHClipPrimitiveSet::Assign (const OpenGl_ArrayOfStructure& theStructs) void OpenGl_BVHClipPrimitiveSet::Assign (const OpenGl_ArrayOfIndexedMapOfStructure& theStructs)
{ {
myStructs.Clear(); myStructs.Clear();
for (Standard_Integer aPriorityIdx = 0, aNbPriorities = theStructs.Length(); aPriorityIdx < aNbPriorities; ++aPriorityIdx) for (Standard_Integer aPriorityIdx = 0, aNbPriorities = theStructs.Length(); aPriorityIdx < aNbPriorities; ++aPriorityIdx)
{ {
for (OpenGl_SequenceOfStructure::Iterator aStructIter (theStructs (aPriorityIdx)); aStructIter.More(); aStructIter.Next()) for (OpenGl_IndexedMapOfStructure::Iterator aStructIter (theStructs (aPriorityIdx)); aStructIter.More(); aStructIter.Next())
{ {
const OpenGl_Structure* aStruct = aStructIter.Value(); const OpenGl_Structure* aStruct = aStructIter.Value();

View File

@ -21,9 +21,12 @@
#include <NCollection_IndexedMap.hxx> #include <NCollection_IndexedMap.hxx>
#include <OpenGl_Structure.hxx> #include <OpenGl_Structure.hxx>
#include <OpenGl_SequenceOfStructure.hxx>
typedef NCollection_Array1<OpenGl_SequenceOfStructure> OpenGl_ArrayOfStructure; //! Defines index map of OpenGL structures.
typedef NCollection_IndexedMap<const OpenGl_Structure*> OpenGl_IndexedMapOfStructure;
//! Defines array of indexed maps of OpenGL structures.
typedef NCollection_Array1<OpenGl_IndexedMapOfStructure> OpenGl_ArrayOfIndexedMapOfStructure;
//! Set of OpenGl_Structures for building BVH tree. //! Set of OpenGl_Structures for building BVH tree.
class OpenGl_BVHClipPrimitiveSet : public BVH_PrimitiveSet<Standard_ShortReal, 4> class OpenGl_BVHClipPrimitiveSet : public BVH_PrimitiveSet<Standard_ShortReal, 4>
@ -53,7 +56,7 @@ public:
//! Replaces the set by the given array taking into account //! Replaces the set by the given array taking into account
//! if each structure is cullable or not. //! if each structure is cullable or not.
void Assign (const OpenGl_ArrayOfStructure& theStructs); void Assign (const OpenGl_ArrayOfIndexedMapOfStructure& theStructs);
//! Adds structure to the set. //! Adds structure to the set.
void Add (const OpenGl_Structure* theStruct); void Add (const OpenGl_Structure* theStruct);

View File

@ -56,7 +56,7 @@ void OpenGl_Layer::Add (const OpenGl_Structure* theStruct,
return; return;
} }
myArray (anIndex).Append (theStruct); myArray (anIndex).Add (theStruct);
if (theStruct->IsAlwaysRendered()) if (theStruct->IsAlwaysRendered())
{ {
theStruct->MarkAsNotCulled(); theStruct->MarkAsNotCulled();
@ -85,21 +85,22 @@ bool OpenGl_Layer::Remove (const OpenGl_Structure* theStruct,
const Standard_Integer aNbPriorities = myArray.Length(); const Standard_Integer aNbPriorities = myArray.Length();
for (Standard_Integer aPriorityIter = 0; aPriorityIter < aNbPriorities; ++aPriorityIter) for (Standard_Integer aPriorityIter = 0; aPriorityIter < aNbPriorities; ++aPriorityIter)
{ {
OpenGl_SequenceOfStructure& aSeq = myArray (aPriorityIter); OpenGl_IndexedMapOfStructure& aStructures = myArray (aPriorityIter);
for (OpenGl_SequenceOfStructure::Iterator aStructIter (aSeq); aStructIter.More(); aStructIter.Next())
const Standard_Integer anIndex = aStructures.FindIndex (theStruct);
if (anIndex != 0)
{ {
if (aStructIter.Value() == theStruct) aStructures.Swap (anIndex, aStructures.Size());
aStructures.RemoveLast();
if (!theStruct->IsAlwaysRendered()
&& !isForChangePriority)
{ {
aSeq.Remove (aStructIter); myBVHPrimitives.Remove (theStruct);
if (!theStruct->IsAlwaysRendered()
&& !isForChangePriority)
{
myBVHPrimitives.Remove (theStruct);
}
--myNbStructures;
thePriority = aPriorityIter;
return true;
} }
--myNbStructures;
thePriority = aPriorityIter;
return true;
} }
} }
@ -126,9 +127,10 @@ void OpenGl_Layer::renderAll (const Handle(OpenGl_Workspace)& theWorkspace) cons
const Standard_Integer aViewId = theWorkspace->ActiveViewId(); const Standard_Integer aViewId = theWorkspace->ActiveViewId();
for (Standard_Integer aPriorityIter = 0; aPriorityIter < aNbPriorities; ++aPriorityIter) for (Standard_Integer aPriorityIter = 0; aPriorityIter < aNbPriorities; ++aPriorityIter)
{ {
for (OpenGl_SequenceOfStructure::Iterator aStructIter (myArray (aPriorityIter)); aStructIter.More(); aStructIter.Next()) const OpenGl_IndexedMapOfStructure& aStructures = myArray (aPriorityIter);
for (Standard_Integer aStructIdx = 1; aStructIdx <= aStructures.Size(); ++aStructIdx)
{ {
const OpenGl_Structure* aStruct = aStructIter.Value(); const OpenGl_Structure* aStruct = aStructures.FindKey (aStructIdx);
if (!aStruct->IsVisible()) if (!aStruct->IsVisible())
{ {
continue; continue;
@ -163,9 +165,10 @@ void OpenGl_Layer::renderTraverse (const Handle(OpenGl_Workspace)& theWorkspace)
const Standard_Integer aViewId = theWorkspace->ActiveViewId(); const Standard_Integer aViewId = theWorkspace->ActiveViewId();
for (Standard_Integer aPriorityIter = 0; aPriorityIter < aNbPriorities; ++aPriorityIter) for (Standard_Integer aPriorityIter = 0; aPriorityIter < aNbPriorities; ++aPriorityIter)
{ {
for (OpenGl_SequenceOfStructure::Iterator aStructIter (myArray (aPriorityIter)); aStructIter.More(); aStructIter.Next()) const OpenGl_IndexedMapOfStructure& aStructures = myArray (aPriorityIter);
for (Standard_Integer aStructIdx = 1; aStructIdx <= aStructures.Size(); ++aStructIdx)
{ {
const OpenGl_Structure* aStruct = aStructIter.Value(); const OpenGl_Structure* aStruct = aStructures.FindKey (aStructIdx);
if (!aStruct->IsVisible() if (!aStruct->IsVisible()
|| aStruct->IsCulled()) || aStruct->IsCulled())
{ {
@ -267,9 +270,10 @@ Standard_Boolean OpenGl_Layer::Append (const OpenGl_Layer& theOther)
// add all structures to destination priority list // add all structures to destination priority list
for (Standard_Integer aPriorityIter = 0; aPriorityIter < aNbPriorities; ++aPriorityIter) for (Standard_Integer aPriorityIter = 0; aPriorityIter < aNbPriorities; ++aPriorityIter)
{ {
for (OpenGl_SequenceOfStructure::Iterator aStructIter (theOther.myArray (aPriorityIter)); aStructIter.More(); aStructIter.Next()) const OpenGl_IndexedMapOfStructure& aStructures = theOther.myArray (aPriorityIter);
for (Standard_Integer aStructIdx = 1; aStructIdx <= aStructures.Size(); ++aStructIdx)
{ {
Add (aStructIter.Value(), aPriorityIter); Add (aStructures.FindKey (aStructIdx), aPriorityIter);
} }
} }

View File

@ -82,7 +82,7 @@ public:
Standard_Boolean Append (const OpenGl_Layer& theOther); Standard_Boolean Append (const OpenGl_Layer& theOther);
//! Returns array of OpenGL structures. //! Returns array of OpenGL structures.
const OpenGl_ArrayOfStructure& ArrayOfStructures() const { return myArray; } const OpenGl_ArrayOfIndexedMapOfStructure& ArrayOfStructures() const { return myArray; }
//! Marks BVH tree for given priority list as dirty and //! Marks BVH tree for given priority list as dirty and
//! marks primitive set for rebuild. //! marks primitive set for rebuild.
@ -105,12 +105,12 @@ protected:
private: private:
OpenGl_ArrayOfStructure myArray; OpenGl_ArrayOfIndexedMapOfStructure myArray;
Standard_Integer myNbStructures; Standard_Integer myNbStructures;
Graphic3d_ZLayerSettings myLayerSettings; //!< Layer setting flags Graphic3d_ZLayerSettings myLayerSettings; //!< Layer setting flags
mutable OpenGl_BVHClipPrimitiveSet myBVHPrimitives; //<! Set of OpenGl_Structures for building BVH tree mutable OpenGl_BVHClipPrimitiveSet myBVHPrimitives; //!< Set of OpenGl_Structures for building BVH tree
mutable Standard_Boolean myBVHIsLeftChildQueuedFirst; //<! Is needed for implementation of stochastic order of BVH traverse mutable Standard_Boolean myBVHIsLeftChildQueuedFirst; //!< Is needed for implementation of stochastic order of BVH traverse
mutable Standard_Boolean myIsBVHPrimitivesNeedsReset; //<! Defines if the primitive set for BVH is outdated mutable Standard_Boolean myIsBVHPrimitivesNeedsReset; //!< Defines if the primitive set for BVH is outdated
public: public:

View File

@ -1,24 +0,0 @@
// Created on: 2014-12-18
// Created by: Kirill Gavrilov
// 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 _OpenGl_SequenceOfStructure
#define _OpenGl_SequenceOfStructure
#include <NCollection_Sequence.hxx>
class OpenGl_Structure;
typedef NCollection_Sequence<const OpenGl_Structure*> OpenGl_SequenceOfStructure;
#endif // _OpenGl_SequenceOfStructure

View File

@ -201,7 +201,7 @@ class OpenGl_View : public MMgt_TShared
void InvalidateBVHData (const Standard_Integer theLayerId); void InvalidateBVHData (const Standard_Integer theLayerId);
//! Returns list of immediate structures rendered on top of main presentation //! Returns list of immediate structures rendered on top of main presentation
const OpenGl_SequenceOfStructure& ImmediateStructures() const const OpenGl_IndexedMapOfStructure& ImmediateStructures() const
{ {
return myImmediateList; return myImmediateList;
} }
@ -267,8 +267,8 @@ protected:
//View_LABDepthCueing - fixed index used //View_LABDepthCueing - fixed index used
OpenGl_LayerList myZLayers; //!< main list of displayed structure, sorted by layers OpenGl_LayerList myZLayers; //!< main list of displayed structure, sorted by layers
OpenGl_SequenceOfStructure myImmediateList; //!< list of immediate structures rendered on top of main presentation OpenGl_IndexedMapOfStructure myImmediateList; //!< list of immediate structures rendered on top of main presentation
const TEL_TRANSFORM_PERSISTENCE *myTransPers; const TEL_TRANSFORM_PERSISTENCE *myTransPers;
Standard_Boolean myIsTransPers; Standard_Boolean myIsTransPers;

View File

@ -919,16 +919,7 @@ void OpenGl_View::DisplayStructure (const Handle(Graphic3d_Structure)& theStruct
void OpenGl_View::DisplayImmediateStructure (const Handle(Graphic3d_Structure)& theStructure) void OpenGl_View::DisplayImmediateStructure (const Handle(Graphic3d_Structure)& theStructure)
{ {
const OpenGl_Structure* aStruct = reinterpret_cast<const OpenGl_Structure*> (theStructure->CStructure().operator->()); const OpenGl_Structure* aStruct = reinterpret_cast<const OpenGl_Structure*> (theStructure->CStructure().operator->());
for (OpenGl_SequenceOfStructure::Iterator anIter (myImmediateList); myImmediateList.Add (aStruct);
anIter.More(); anIter.Next())
{
if (anIter.Value() == aStruct)
{
return;
}
}
myImmediateList.Append (aStruct);
} }
//======================================================================= //=======================================================================
@ -948,14 +939,12 @@ void OpenGl_View::EraseStructure (const Handle(Graphic3d_Structure)& theStructur
void OpenGl_View::EraseImmediateStructure (const OpenGl_Structure* theStructure) void OpenGl_View::EraseImmediateStructure (const OpenGl_Structure* theStructure)
{ {
for (OpenGl_SequenceOfStructure::Iterator anIter (myImmediateList); const Standard_Integer anIndex = myImmediateList.FindIndex (theStructure);
anIter.More(); anIter.Next())
if (anIndex != 0)
{ {
if (anIter.Value() == theStructure) myImmediateList.Swap (myImmediateList.Size(), anIndex);
{ myImmediateList.RemoveLast();
myImmediateList.Remove (anIter);
return;
}
} }
} }

View File

@ -71,11 +71,11 @@ Standard_Boolean OpenGl_View::updateRaytraceGeometry (const RaytraceUpdateMode
if (aLayer.NbStructures() != 0) if (aLayer.NbStructures() != 0)
{ {
const OpenGl_ArrayOfStructure& aStructArray = aLayer.ArrayOfStructures(); const OpenGl_ArrayOfIndexedMapOfStructure& aStructArray = aLayer.ArrayOfStructures();
for (Standard_Integer anIndex = 0; anIndex < aStructArray.Length(); ++anIndex) for (Standard_Integer anIndex = 0; anIndex < aStructArray.Length(); ++anIndex)
{ {
for (OpenGl_SequenceOfStructure::Iterator aStructIt (aStructArray (anIndex)); aStructIt.More(); aStructIt.Next()) for (OpenGl_IndexedMapOfStructure::Iterator aStructIt (aStructArray (anIndex)); aStructIt.More(); aStructIt.Next())
{ {
const OpenGl_Structure* aStructure = aStructIt.Value(); const OpenGl_Structure* aStructure = aStructIt.Value();

View File

@ -1429,8 +1429,7 @@ bool OpenGl_Workspace::redrawImmediate (const Graphic3d_CView& theCView,
{ {
glDisable (GL_DEPTH_TEST); glDisable (GL_DEPTH_TEST);
} }
for (OpenGl_SequenceOfStructure::Iterator anIter (myView->ImmediateStructures()); for (OpenGl_IndexedMapOfStructure::Iterator anIter (myView->ImmediateStructures()); anIter.More(); anIter.Next())
anIter.More(); anIter.Next())
{ {
const OpenGl_Structure* aStructure = anIter.Value(); const OpenGl_Structure* aStructure = anIter.Value();
if (!aStructure->IsVisible()) if (!aStructure->IsVisible())