From 17e48554d8f123c9a888245093a0f12b5c5af6fe Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 9 Jan 2015 15:06:11 -0800 Subject: [PATCH] implement support for proper cleanup in BatchItemDetails --- libraries/render-utils/src/GeometryCache.cpp | 44 ++++++++++++++++++++ libraries/render-utils/src/GeometryCache.h | 20 +++------ 2 files changed, 49 insertions(+), 15 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 4d09ab0163..0207b47fa1 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -40,6 +40,10 @@ GeometryCache::~GeometryCache() { glDeleteBuffers(1, &vbo.first); glDeleteBuffers(1, &vbo.second); } + qDebug() << "GeometryCache::~GeometryCache()... "; + qDebug() << " _registeredLine3DVBOs.size():" << _registeredLine3DVBOs.size(); + qDebug() << " _line3DVBOs.size():" << _line3DVBOs.size(); + qDebug() << " BatchItemDetails... population:" << GeometryCache::BatchItemDetails::population; } void GeometryCache::renderHemisphere(int slices, int stacks) { @@ -1400,11 +1404,51 @@ void GeometryCache::renderDashedLine(const glm::vec3& start, const glm::vec3& en details.buffer.release(); } +int GeometryCache::BatchItemDetails::population = 0; +GeometryCache::BatchItemDetails::BatchItemDetails() : + verticesBuffer(NULL), + colorBuffer(NULL), + streamFormat(NULL), + stream(NULL), + vertices(0), + vertexSize(0), + isCreated(false) +{ + population++; +} + +GeometryCache::BatchItemDetails::BatchItemDetails(const GeometryCache::BatchItemDetails& other) : + verticesBuffer(other.verticesBuffer), + colorBuffer(other.colorBuffer), + streamFormat(other.streamFormat), + stream(other.stream), + vertices(other.vertices), + vertexSize(other.vertexSize), + isCreated(other.isCreated) +{ + population++; +} + +GeometryCache::BatchItemDetails::~BatchItemDetails() { + population--; + clear(); + qDebug() << "~BatchItemDetails()... population:" << population << "**********************************"; +} + +void GeometryCache::BatchItemDetails::clear() { + isCreated = false; + verticesBuffer.clear(); + colorBuffer.clear(); + streamFormat.clear(); + stream.clear(); +} + void GeometryCache::renderLine(const glm::vec3& p1, const glm::vec3& p2, const glm::vec4& color1, const glm::vec4& color2, int id) { bool registered = (id != UNKNOWN_ID); Vec3Pair key(p1, p2); + BatchItemDetails& details = registered ? _registeredLine3DVBOs[id] : _line3DVBOs[key]; int compactColor1 = ((int(color1.x * 255.0f) & 0xFF)) | diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index 96e3f4c398..0e216a5bc1 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -156,6 +156,7 @@ private: class BatchItemDetails { public: + static int population; gpu::BufferPointer verticesBuffer; gpu::BufferPointer colorBuffer; gpu::Stream::FormatPointer streamFormat; @@ -165,21 +166,10 @@ private: int vertexSize; bool isCreated; - BatchItemDetails() : - verticesBuffer(NULL), - colorBuffer(NULL), - streamFormat(NULL), - stream(NULL), - vertices(0), - vertexSize(0), - isCreated(false) - { - } - - void clear() { - // TODO: add the proper de-allocation of the gpu items - isCreated = false; - } + BatchItemDetails(); + BatchItemDetails(const GeometryCache::BatchItemDetails& other); + ~BatchItemDetails(); + void clear(); }; QHash _hemisphereVBOs;