From 5bf9e9f2ec0c88cb38ca0aed014a89ad4447eac1 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 12 Oct 2009 15:00:46 +0000 Subject: [PATCH] moved Object contructor/destructor into .cc file, keeping track of number of references to OpenGL display list and deleting it when the last reference goes away git-svn-id: svn://anubis/anaglym/trunk@66 99a6e188-d820-4881-8870-2d33a10e2619 --- anaglym.cc | 24 +++++++++++++++++++++++- anaglym.h | 12 +++--------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/anaglym.cc b/anaglym.cc index b103436..a1063c5 100644 --- a/anaglym.cc +++ b/anaglym.cc @@ -343,10 +343,32 @@ void Engine::drawObjects() } } +Engine::Object::Object(bool is_static, OdeWorld & world, GLuint dl) +{ + m_ode_object = world.createObject(is_static); + m_display_list = dl; + m_display_list_refcnt = new int; + *m_display_list_refcnt = 1; +} + Engine::Object::Object(const Engine::Object & orig) { - m_display_list = orig.m_display_list; m_ode_object = new OdeWorld::Object(*orig.m_ode_object); + m_display_list = orig.m_display_list; + m_display_list_refcnt = orig.m_display_list_refcnt; + (*m_display_list_refcnt)++; +} + +Engine::Object::~Object() +{ + delete m_ode_object; + (*m_display_list_refcnt)--; + if (*m_display_list_refcnt < 1) + { + /* we hold the last reference to the OpenGL display list */ + delete m_display_list_refcnt; + glDeleteLists(m_display_list, 1); + } } void Engine::Object::draw() diff --git a/anaglym.h b/anaglym.h index cdcad74..9dc2173 100644 --- a/anaglym.h +++ b/anaglym.h @@ -17,16 +17,9 @@ class Engine class Object { public: - Object(bool is_static, OdeWorld & world, GLuint dl) - { - m_ode_object = world.createObject(is_static); - m_display_list = dl; - } + Object(bool is_static, OdeWorld & world, GLuint dl); Object(const Object & orig); - ~Object() - { - delete m_ode_object; - } + ~Object(); void setPosition(double x, double y, double z) { @@ -46,6 +39,7 @@ class Engine protected: OdeWorld::Object * m_ode_object; GLuint m_display_list; + int * m_display_list_refcnt; }; Engine();