m3g/m3gcore11/src/m3g_interface.c
branchRCL_3
changeset 26 15986eb6c500
parent 0 5d03bc08d59c
child 163 bbf46f59e123
--- a/m3g/m3gcore11/src/m3g_interface.c	Mon Mar 15 12:45:41 2010 +0200
+++ b/m3g/m3gcore11/src/m3g_interface.c	Wed Mar 31 23:34:07 2010 +0300
@@ -68,8 +68,6 @@
         /*@shared@*/ m3gReleaseTargetFunc *releaseTarget;
     } func;
     
-    /*Object *objects;*/
-
     /*! \internal \brief Latest error code for this interface */
     M3Genum error;
 
@@ -90,6 +88,8 @@
     M3Gint glRefCount;
 #   endif
 
+    /* \internal \brief List of live objects */
+    PointerArray objects;     
     /*! \internal \brief Number of objects registered for this interface */
     M3Gint objCount;
 
@@ -946,20 +946,26 @@
  * \internal
  * \brief
  */
-static void m3gAddChildObject(Interface *m3g)
+static void m3gAddChildObject(Interface *m3g, Object *obj)
 {
     M3G_ASSERT(!m3g->shutdown);
     M3G_ASSERT(m3gInRange(m3g->objCount, 0, 0x7FFFFFFF));
     ++m3g->objCount;
+
+    /* Add the object to the list of live objects */
+    m3gArrayAppend(&m3g->objects, obj, m3g);
 }
 
 /*!
  * \internal
  * \brief
  */
-static void m3gDelChildObject(Interface *m3g)
+static void m3gDelChildObject(Interface *m3g, Object *obj)
 {
     M3G_ASSERT(m3g->objCount > 0);
+
+    /* Remove the object from the list of live objects */
+    m3gArrayDelete(&m3g->objects, m3gArrayFind(&m3g->objects, obj));
     if (--m3g->objCount == 0 && m3g->shutdown) {
         m3gDeleteInterface(m3g);
     }
@@ -968,6 +974,19 @@
 #if !defined(M3G_NGL_TEXTURE_API)
 /*!
  * \internal
+ * \brief Get a list of live objects with matching class ID
+ */
+static void m3gGetObjectsWithClassID(Interface *m3g, M3GClass classID, PointerArray* objects)
+{
+    M3Gsizei i = m3gArraySize(&m3g->objects);
+    while (i > 0) {
+        M3GObject obj = (M3GObject)m3gGetArrayElement(&m3g->objects, --i);
+        if (m3gGetClass(obj) == classID)
+            m3gArrayAppend(objects, obj, m3g);
+    }
+}
+/*!
+ * \internal
  * \brief Queue OpenGL texture objects for deletion
  *
  * The objects will be deleted when a GL context is next made current.
@@ -1661,6 +1680,7 @@
         /* All done! Now we can allocate the more trival stuff */
 
         m3g->tcache = m3gCreateTransformCache(m3g);
+        m3gInitArray(&m3g->objects);
         
         M3G_LOG1(M3G_LOG_INTERFACE,
                  "Interface 0x%08X initialized\n", (unsigned) m3g);
@@ -1690,6 +1710,7 @@
         return;
     }
 
+    m3gDestroyArray(&m3g->objects, m3g);
 #   if !defined(M3G_NGL_TEXTURE_API)
     /* Free the list of dead GL objects (those will have been deleted
      * along with the owning contexts by now) */