1 // File: OpenGl_ResourceCleaner.hxx
2 // Created: 18.03.11 9:30:00
3 // Author: Anton POLETAEV
5 #ifndef _OPENGL_RESOURCECLEANER_H
6 #define _OPENGL_RESOURCECLEANER_H
8 #include <OpenGl_tgl_all.hxx>
9 #include <NCollection_Queue.hxx>
10 #include <NCollection_List.hxx>
11 #include <NCollection_Map.hxx>
12 #include <NCollection_DataMap.hxx>
13 #include <OpenGl_Resource.hxx>
15 class OpenGl_Resource;
16 class Handle_OpenGl_Resource;
18 typedef NCollection_Queue<Handle_OpenGl_Resource> QueueOfResources;
19 typedef NCollection_DataMap<GLCONTEXT, QueueOfResources> DataMapOfContextsResources;
20 typedef NCollection_Map<GLCONTEXT> MapOfContexts;
22 //! OpenGl_ResourceCleaner should be used to clean OpenGl memory resources;
23 //! The reason is that the resources might be shared between the contexts and
24 //! should be cleaned up only while suitable context is active;
25 class OpenGl_ResourceCleaner
31 OpenGl_ResourceCleaner();
34 virtual ~OpenGl_ResourceCleaner() { }
36 //! Append OpenGl context to the OpenGl_ResourceCleaner
38 void AppendContext(GLCONTEXT theContext, Standard_Boolean isShared);
40 //! Tell the OpenGl_ResourceCleaner to clean up the OpenGl memory resource
41 //! which has been created by the specified OpenGl context;
42 //! The context should be in the OpenGl_ResourceCleaner control list.
43 Standard_Boolean AddResource(GLCONTEXT theContext, Handle_OpenGl_Resource theResource);
45 //! Cancel clean procedure for all the resources added to the OpenGl_ResourceCleaner.
48 //! Cancel clean procedure for all the resources of the specific OpenGl context
49 //! which were added to the OpenGl_ResourceCleaner.
50 Standard_Boolean Clear(GLCONTEXT theContext);
52 //! Cancel clean procedure for all of the shared resources.
55 //! Clear the unused resources for active OpenGl context;
56 //! You should add the cleaner resources by AddResources method;
57 //! It is suggested to call this method right before the OpenGl
58 //! new frame drawing procedure starts.
61 //! Remove the OpenGl context from the OpenGl_ResourceCleaner control list.
62 void RemoveContext(GLCONTEXT theContext);
64 //! Get any of shared contexts from the OpenGl_ResourceCleaner list
65 //! to share resources with a new one
66 GLCONTEXT GetSharedContext() const;
68 //! Get the global instance of OpenGl_ResourceCleaner
69 static OpenGl_ResourceCleaner* GetInstance();
73 DataMapOfContextsResources myInstanceQueue; // map for queues of non-shared context's resources
74 QueueOfResources mySharedQueue; // queue of shared context's resources
75 MapOfContexts mySharedContexts; // the control list of shared contexts