exhibit drawing is now handled by the Renderer
authorJohn Tsiombikas <nuclear@member.fsf.org>
Thu, 18 Jan 2018 06:43:22 +0000 (08:43 +0200)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Thu, 18 Jan 2018 06:43:22 +0000 (08:43 +0200)
src/blob_exhibit.cc
src/exhibit.cc
src/exhibit.h
src/exman.cc

index 35552e4..cd29e96 100644 (file)
@@ -140,6 +140,12 @@ void BlobExhibit::draw() const
        glEnable(GL_TEXTURE_GEN_S);
        glEnable(GL_TEXTURE_GEN_T);
 
+       if(node) {
+               glMatrixMode(GL_MODELVIEW);
+               glPushMatrix();
+               glMultMatrixf(node->get_matrix()[0]);
+       }
+
        glMatrixMode(GL_TEXTURE);
        glLoadIdentity();
        glScalef(1, -1, 1);
@@ -183,6 +189,9 @@ void BlobExhibit::draw() const
 
        glLoadIdentity();
        glMatrixMode(GL_MODELVIEW);
+       if(node) {
+               glPopMatrix();
+       }
 
        glPopAttrib();
 }
index 8403550..2e81854 100644 (file)
@@ -1,8 +1,6 @@
 #include "exhibit.h"
 #include "snode.h"
 #include "scene.h"
-#include "geomdraw.h"
-#include "app.h"
 
 ExSelection ExSelection::null;
 
@@ -70,33 +68,6 @@ void Exhibit::update(float dt)
 {
 }
 
-void Exhibit::pre_draw() const
-{
-       if(node) {
-               glMatrixMode(GL_MODELVIEW);
-               glPushMatrix();
-               glMultMatrixf(node->get_matrix()[0]);
-       }
-}
-
-void Exhibit::draw() const
-{
-}
-
-void Exhibit::post_draw() const
-{
-       if(node) {
-               glMatrixMode(GL_MODELVIEW);
-               glPopMatrix();
-
-               if(exsel_hover.ex == this) {
-                       const AABox &bvol = get_aabox();
-                       draw_geom_object(&bvol);
-               }
-       }
-}
-
-
 const AABox &Exhibit::get_aabox() const
 {
        aabb = node->get_bounds();
index fd1d77b..9b5c753 100644 (file)
@@ -77,10 +77,6 @@ public:
 
        virtual void update(float dt = 0.0f) override;
 
-       virtual void pre_draw() const;
-       virtual void draw() const override;
-       virtual void post_draw() const;
-
        virtual const AABox &get_aabox() const override;
 };
 
index d6cac9c..31ee1ae 100644 (file)
@@ -4,6 +4,8 @@
 #include "exhibit.h"
 #include "blob_exhibit.h"
 #include "treestore.h"
+#include "app.h"
+#include "geomdraw.h"
 
 static Exhibit *create_exhibit(const char *type);
 
@@ -114,13 +116,10 @@ ExhibitManager::~ExhibitManager()
 
 void ExhibitManager::clear()
 {
-       int num = (int)items.size();
-       for(int i=0; i<num; i++) {
-               delete items[i];
-       }
+       // not deleting exhibit objects, as they will be deleted the own_scn destructor
        items.clear();
 
-       num = (int)exslots.size();
+       int num = (int)exslots.size();
        for(int i=0; i<num; i++) {
                delete exslots[i];
        }
@@ -134,6 +133,8 @@ void ExhibitManager::add(Exhibit *ex)
        std::vector<Exhibit*>::iterator it = std::find(items.begin(), items.end(), ex);
        if(it == items.end()) {
                items.push_back(ex);
+               own_scn->add_object(ex);
+               if(ex->node) own_scn->add_node(ex->node);
        }
 }
 
@@ -142,6 +143,8 @@ bool ExhibitManager::remove(Exhibit *ex)
        std::vector<Exhibit*>::iterator it = std::find(items.begin(), items.end(), ex);
        if(it != items.end()) {
                items.erase(it);
+               own_scn->remove_object(ex);
+               if(ex->node) own_scn->remove_node(ex->node);
                return true;
        }
        return false;
@@ -156,8 +159,10 @@ bool ExhibitManager::load(MetaScene *mscn, const char *fname)
                return false;
        }
 
-       // create our own scene to manage all exhibits not already in an existing scene
-       // and add it to the metascene
+       /* create our own scene to manage all exhibits not already in an existing scene
+        * and add it to the metascene.
+        * Also exhibit drawing happens due to the renderer drawing the metascene
+        */
        if(!own_scn) {
                own_scn = new Scene;
                own_scn->name = "ad-hoc exhibits";
@@ -192,13 +197,15 @@ bool ExhibitManager::load(MetaScene *mscn, const char *fname)
                                }
                        }
 
+                       // add everything to our data structures
+                       // equivalent to add_exhibit(ex), but without all the searching
+                       own_scn->add_object(ex);
                        if(!snode) {
                                snode = new SceneNode;
                                snode->set_name(ex->get_name());
                                own_scn->add_node(snode);
                        }
                        ex->set_node(snode);
-
                        items.push_back(ex);
 
                        float *apos = ts_get_attr_vec(node, "pos");
@@ -336,9 +343,10 @@ void ExhibitManager::draw() const
 {
        int num = items.size();
        for(int i=0; i<num; i++) {
-               items[i]->pre_draw();
-               items[i]->draw();
-               items[i]->post_draw();
+               if(exsel_hover.ex == items[i]) {
+                       const AABox &bvol = items[i]->get_aabox();
+                       draw_geom_object(&bvol);
+               }
        }
 }