mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +03:00
OCC22144 NIS performance and memory usage update
This commit is contained in:
@@ -28,21 +28,91 @@ class NIS_View;
|
||||
template <class A> class NCollection_Vector;
|
||||
|
||||
/**
|
||||
* Abstract Drawer type
|
||||
* Abstract Drawer type.
|
||||
* Drawer provides the immediate OpenGL drawing for every NIS_InteractiveObject
|
||||
* maneged by the given Drawer instance. Each Drawer instance has reciprocal
|
||||
* link with a number of NIS_InteractiveObject instances of the same
|
||||
* (corresponding to Drawer) type. The idea is to group the drawing for all
|
||||
* referred interactive objects using the same pre- and post-treatment like
|
||||
* color setting, matrix, polygon offset, line thickness and what not.
|
||||
*
|
||||
* @section nis_drawer_visualprop Visual properties of Drawer
|
||||
* Normally visual properties of any NIS_InteractiveObject are stored in its
|
||||
* Drawer instance, but not in an object. For example, if an interactive object
|
||||
* has method SetColor() then the color is stored in the corresponding Drawer
|
||||
* rather than in the interactive object itself. This scheme avoid useless
|
||||
* duplication when a lot of objects have similar properties like color. Please
|
||||
* see @see nis_interactiveobject_drawer to learn how this mechanism
|
||||
* works from the side of NIS_InteractiveObject.
|
||||
*
|
||||
* @section nis_drawer_drawing Drawing
|
||||
* There are 3 virtual methods to implement OpenGL drawing in this API. They
|
||||
* define the drawing cycle that consists of filling the internal OpenGL draw
|
||||
* list with commands. This drawing cycle is triggered when the corresponding
|
||||
* internal instance of NIS_DrawList has 'IsUpdated' flag (you can set this
|
||||
* flag by means of public methods NIS_Drawer::SetUpdated()).
|
||||
* <ul>
|
||||
* <li><b>BeforeDraw()</b> : contains all OpenGL commands that define the
|
||||
* common set of visual properties for all managed interactive objects.
|
||||
* This method is called once in the beginning of drawing cycle for the
|
||||
* Drawer instance</li>
|
||||
* <li><b>Draw()</b> : all OpenGL commands that are specific to a given
|
||||
* interactive object, usually definition of vertices, triangles, lines,
|
||||
* or their arrays.</li>
|
||||
* <li><b>AfterDraw()</b> : commands that revert the status of OpenGL context
|
||||
* to the state before execution of BeforeDraw(). This method is called
|
||||
* once in the end of drawing cycle.</li>
|
||||
* </ul>
|
||||
* Each of these methods receives NIS_DrawList and DrawType, both identify the
|
||||
* OpenGL draw list that should be filled with commands. Based on DrawType
|
||||
* you will be able to define different presentation - the most important case
|
||||
* is how hilighted (selected) interactive object is presented.
|
||||
* <p>
|
||||
* For advanced purposes you also can redefine the virtual method redraw(), it
|
||||
* is dedicated to higher-level management of draw lists and ordering of
|
||||
* their update when necessary.
|
||||
*
|
||||
* @section nis_drawer_distinction Distinction of Drawer instances
|
||||
* Every Drawer should define which interactive objects it may manage and
|
||||
* which - may not. The same idea could be shaped alternatively: every
|
||||
* interactive object should understand to what Drawer it can attach itself.
|
||||
* This question is answerd by special virtual method IsEqual() that compares
|
||||
* two Drawers of the same type. <b>Two instances of Drawer are equal if they
|
||||
* have the same set of visual properties that are implemented in BeforeDraw().
|
||||
* </b> The method IsEqual() is the core of Drawer architecture and it must
|
||||
* be implemented very carefully for any new type. Particularly, for any
|
||||
* derived class the method IsEqual() should first call the same method of
|
||||
* its superclass.
|
||||
* <p>
|
||||
* For the optimal efficiency of OpenGL drawing it is better to keep the size
|
||||
* of draw list (i.e., the number of interactive objects in a Drawer instance)
|
||||
* not too small and not too big. The latter limitation is entered by the
|
||||
* protected field myObjPerDrawer. It is used in method IsEqual() of the base
|
||||
* Drawer class: two Drawers are not equal if they are initialized on objects
|
||||
* that have too different IDs -- even if all visual properties of these two
|
||||
* Drawer instances coincide.
|
||||
* <p>
|
||||
* @section nis_drawer_cloning Cloning Drawer instances
|
||||
* It is possible to clone a Drawer instance with the viryual method Assign().
|
||||
* This method copies all visual properties and other important data from the
|
||||
* Drawer provided as parameter. Method Clone() also should be very carefully
|
||||
* implemented for any new Drawer type, to make sure that all necessary data
|
||||
* fields and structures are properly copied.
|
||||
*/
|
||||
|
||||
class NIS_Drawer : public Standard_Transient
|
||||
{
|
||||
public:
|
||||
#if (_MSC_VER < 1400)
|
||||
enum DrawType {
|
||||
#if defined(WNT) && (_MSC_VER >= 1400)
|
||||
enum DrawType : unsigned int {
|
||||
#else
|
||||
enum DrawType : unsigned int {
|
||||
enum DrawType {
|
||||
#endif
|
||||
Draw_Normal = 0,
|
||||
Draw_Transparent = 1,
|
||||
Draw_Hilighted = 2,
|
||||
Draw_DynHilighted = 3
|
||||
Draw_Top = 1,
|
||||
Draw_Transparent = 2,
|
||||
Draw_Hilighted = 3,
|
||||
Draw_DynHilighted = 4
|
||||
};
|
||||
|
||||
public:
|
||||
@@ -52,7 +122,12 @@ class NIS_Drawer : public Standard_Transient
|
||||
/**
|
||||
* Empty constructor.
|
||||
*/
|
||||
inline NIS_Drawer () : myCtx (0L) {}
|
||||
inline NIS_Drawer ()
|
||||
: myTransparency (0.f),
|
||||
myIniId (0),
|
||||
myObjPerDrawer (1024),
|
||||
myCtx (0L)
|
||||
{}
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
@@ -91,6 +166,11 @@ class NIS_Drawer : public Standard_Transient
|
||||
const DrawType theType2,
|
||||
const DrawType theType3) const;
|
||||
|
||||
Standard_EXPORT void SetUpdated (const DrawType theType1,
|
||||
const DrawType theType2,
|
||||
const DrawType theType3,
|
||||
const DrawType theType4) const;
|
||||
|
||||
/**
|
||||
* Switch on/off the dynamic hilight of the given object in the
|
||||
* given view.
|
||||
@@ -126,7 +206,20 @@ class NIS_Drawer : public Standard_Transient
|
||||
ObjectIterator () const
|
||||
{ return TColStd_MapIteratorOfPackedMapOfInteger (myMapID); }
|
||||
|
||||
/**
|
||||
* Query associated draw lists.
|
||||
*/
|
||||
inline NCollection_List<NIS_DrawList *>
|
||||
GetLists() const
|
||||
{ return myLists; }
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Called to add draw list IDs to ex-list Ids of view. These draw lists are
|
||||
* eventually released in the callback function, before anything is displayed
|
||||
*/
|
||||
Standard_EXPORT void UpdateExListId (const Handle_NIS_View& theView) const;
|
||||
|
||||
// ---------- PROTECTED METHODS ----------
|
||||
|
||||
/**
|
||||
@@ -154,7 +247,8 @@ protected:
|
||||
const Handle_NIS_View& theView);
|
||||
|
||||
Standard_EXPORT void addObject (const NIS_InteractiveObject * theObj,
|
||||
const Standard_Boolean isUpVws);
|
||||
const Standard_Boolean isShareList,
|
||||
const Standard_Boolean isUpVws);
|
||||
|
||||
Standard_EXPORT void removeObject (const NIS_InteractiveObject * theObj,
|
||||
const Standard_Boolean isUpVws);
|
||||
@@ -162,6 +256,11 @@ protected:
|
||||
Standard_EXPORT virtual NIS_DrawList*
|
||||
createDefaultList (const Handle_NIS_View&) const;
|
||||
|
||||
protected:
|
||||
//! Get the number of interactive objects in this drawer
|
||||
inline Standard_Integer NObjects() const
|
||||
{ return myMapID.Extent(); }
|
||||
|
||||
private:
|
||||
// ---------- PRIVATE (PROHIBITED) METHODS ----------
|
||||
|
||||
@@ -169,12 +268,21 @@ protected:
|
||||
NIS_Drawer& operator = (const NIS_Drawer& theOther);
|
||||
|
||||
// ---------- PRIVATE METHODS ----------
|
||||
void prepareList (const NIS_Drawer::DrawType theType,
|
||||
const NIS_DrawList& theDrawLst);
|
||||
void prepareList (const NIS_Drawer::DrawType theType,
|
||||
const NIS_DrawList& theDrawLst,
|
||||
const TColStd_PackedMapOfInteger& mapObj);
|
||||
|
||||
protected:
|
||||
// ---------- PROTECTED FIELDS ----------
|
||||
NCollection_List<NIS_DrawList*> myLists;
|
||||
Standard_ShortReal myTransparency;
|
||||
//! ID of the initializing InteractiveObject. It is never changed, can be
|
||||
//! used to compute hash code of the Drawer instance.
|
||||
Standard_Integer myIniId;
|
||||
//! Maximal range of IDs of objects in one drawer. Limits the size of
|
||||
//! draw lists. Can be initialized only in constructor (default 1024). It is
|
||||
//! strictly prohibited to change this value outside the constructor.
|
||||
Standard_Integer myObjPerDrawer;
|
||||
|
||||
private:
|
||||
// ---------- PRIVATE FIELDS ----------
|
||||
@@ -185,6 +293,7 @@ protected:
|
||||
|
||||
friend class NIS_InteractiveContext;
|
||||
friend class NIS_InteractiveObject;
|
||||
friend class NIS_View;
|
||||
|
||||
public:
|
||||
// Declaration of CASCADE RTTI
|
||||
|
Reference in New Issue
Block a user