add Release() method to handle resource/mem freeing instead of doing it only in the destructor (the destructor in these classes just calls Release() now)

This commit is contained in:
Gered 2013-04-01 17:37:56 -04:00
parent d8c19411ec
commit 9f42c16c93
8 changed files with 70 additions and 25 deletions

View file

@ -14,11 +14,19 @@ BufferObject::BufferObject()
m_sizeInBytes = 0; m_sizeInBytes = 0;
} }
BufferObject::~BufferObject() void BufferObject::Release()
{ {
STACK_TRACE; STACK_TRACE;
if (!IsClientSideBuffer()) if (!IsClientSideBuffer())
FreeBufferObject(); FreeBufferObject();
m_type = BUFFEROBJECT_TYPE_VERTEX;
m_usage = BUFFEROBJECT_USAGE_STATIC;
m_bufferId = 0;
m_isDirty = FALSE;
m_sizeInBytes = 0;
GraphicsContextResource::Release();
} }
BOOL BufferObject::Initialize(GraphicsDevice *graphicsDevice, BUFFEROBJECT_TYPE type, BUFFEROBJECT_USAGE usage) BOOL BufferObject::Initialize(GraphicsDevice *graphicsDevice, BUFFEROBJECT_TYPE type, BUFFEROBJECT_USAGE usage)

View file

@ -27,7 +27,9 @@ class BufferObject : public GraphicsContextResource
{ {
public: public:
BufferObject(); BufferObject();
virtual ~BufferObject(); virtual ~BufferObject() { Release(); }
virtual void Release();
/** /**
* @return TRUE if this buffer object is holding client side data only * @return TRUE if this buffer object is holding client side data only

View file

@ -9,11 +9,13 @@ GraphicsContextResource::GraphicsContextResource()
m_graphicsDevice = NULL; m_graphicsDevice = NULL;
} }
GraphicsContextResource::~GraphicsContextResource() void GraphicsContextResource::Release()
{ {
STACK_TRACE; STACK_TRACE;
if (m_graphicsDevice != NULL) if (m_graphicsDevice != NULL)
m_graphicsDevice->UnregisterManagedResource(this); m_graphicsDevice->UnregisterManagedResource(this);
m_graphicsDevice = NULL;
} }
BOOL GraphicsContextResource::Initialize() BOOL GraphicsContextResource::Initialize()

View file

@ -14,7 +14,9 @@ class GraphicsContextResource
{ {
public: public:
GraphicsContextResource(); GraphicsContextResource();
virtual ~GraphicsContextResource(); virtual ~GraphicsContextResource() { Release(); }
virtual void Release();
/** /**
* New OpenGL graphics context creation callback. * New OpenGL graphics context creation callback.

View file

@ -10,9 +10,13 @@ IndexBuffer::IndexBuffer()
m_currentIndex = 0; m_currentIndex = 0;
} }
IndexBuffer::~IndexBuffer() void IndexBuffer::Release()
{ {
STACK_TRACE; m_buffer.clear();
stl::vector<uint16_t>().swap(m_buffer);
m_currentIndex = 0;
BufferObject::Release();
} }
BOOL IndexBuffer::Initialize(uint32_t numIndices, BUFFEROBJECT_USAGE usage) BOOL IndexBuffer::Initialize(uint32_t numIndices, BUFFEROBJECT_USAGE usage)

View file

@ -17,7 +17,12 @@ class IndexBuffer : public BufferObject
{ {
public: public:
IndexBuffer(); IndexBuffer();
virtual ~IndexBuffer(); virtual ~IndexBuffer() { Release(); }
/**
* Releases all resources associated with this index buffer.
*/
virtual void Release();
/** /**
* Initializes the index buffer. * Initializes the index buffer.

View file

@ -24,9 +24,26 @@ VertexBuffer::VertexBuffer()
m_numGPUAttributeSlotsUsed = 0; m_numGPUAttributeSlotsUsed = 0;
} }
VertexBuffer::~VertexBuffer() void VertexBuffer::Release()
{ {
STACK_TRACE; STACK_TRACE;
m_buffer.clear();
stl::vector<float>().swap(m_buffer);
m_numVertices = 0;
m_currentVertex = 0;
m_standardTypeAttribs = 0;
m_elementWidth = 0;
m_colorOffset = 0;
m_position2Offset = 0;
m_position3Offset = 0;
m_normalOffset = 0;
m_texCoordOffset = 0;
m_numAttributes = 0;
m_attribs = NULL;
m_numGPUAttributeSlotsUsed = 0;
BufferObject::Release();
} }
BOOL VertexBuffer::Initialize(const VERTEX_ATTRIBS *attributes, uint32_t numAttributes, uint32_t numVertices, BUFFEROBJECT_USAGE usage) BOOL VertexBuffer::Initialize(const VERTEX_ATTRIBS *attributes, uint32_t numAttributes, uint32_t numVertices, BUFFEROBJECT_USAGE usage)

View file

@ -26,7 +26,12 @@ class VertexBuffer : public BufferObject
{ {
public: public:
VertexBuffer(); VertexBuffer();
virtual ~VertexBuffer(); virtual ~VertexBuffer() { Release(); }
/**
* Releases all resources associated with this vertex buffer.
*/
virtual void Release();
/** /**
* Initializes the vertex buffer. * Initializes the vertex buffer.