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
This commit is contained in:
parent
bd2d3d8b25
commit
5bf9e9f2ec
24
anaglym.cc
24
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)
|
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_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()
|
void Engine::Object::draw()
|
||||||
|
12
anaglym.h
12
anaglym.h
@ -17,16 +17,9 @@ class Engine
|
|||||||
class Object
|
class Object
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Object(bool is_static, OdeWorld & world, GLuint dl)
|
Object(bool is_static, OdeWorld & world, GLuint dl);
|
||||||
{
|
|
||||||
m_ode_object = world.createObject(is_static);
|
|
||||||
m_display_list = dl;
|
|
||||||
}
|
|
||||||
Object(const Object & orig);
|
Object(const Object & orig);
|
||||||
~Object()
|
~Object();
|
||||||
{
|
|
||||||
delete m_ode_object;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setPosition(double x, double y, double z)
|
void setPosition(double x, double y, double z)
|
||||||
{
|
{
|
||||||
@ -46,6 +39,7 @@ class Engine
|
|||||||
protected:
|
protected:
|
||||||
OdeWorld::Object * m_ode_object;
|
OdeWorld::Object * m_ode_object;
|
||||||
GLuint m_display_list;
|
GLuint m_display_list;
|
||||||
|
int * m_display_list_refcnt;
|
||||||
};
|
};
|
||||||
|
|
||||||
Engine();
|
Engine();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user