From 008b070aab3687d022a1b68ac4deb5cc82c8dd65 Mon Sep 17 00:00:00 2001 From: vlj Date: Fri, 28 Mar 2014 01:43:59 +0100 Subject: [PATCH] Properly clean GL buffers in instancing node. --- src/graphics/stkinstancedscenenode.cpp | 30 ++++++++++++++++++++++++++ src/graphics/stkinstancedscenenode.hpp | 2 ++ 2 files changed, 32 insertions(+) diff --git a/src/graphics/stkinstancedscenenode.cpp b/src/graphics/stkinstancedscenenode.cpp index 47968679a..3004ea092 100644 --- a/src/graphics/stkinstancedscenenode.cpp +++ b/src/graphics/stkinstancedscenenode.cpp @@ -11,6 +11,36 @@ STKInstancedSceneNode::STKInstancedSceneNode(irr::scene::IMesh* mesh, ISceneNode setAutomaticCulling(0); } +void STKInstancedSceneNode::cleanGL() +{ + for (u32 i = 0; i < GLmeshes.size(); ++i) + { + GLMesh mesh = GLmeshes[i]; + if (!mesh.vertex_buffer) + continue; + if (mesh.vao_first_pass) + glDeleteVertexArrays(1, &(mesh.vao_first_pass)); + if (mesh.vao_second_pass) + glDeleteVertexArrays(1, &(mesh.vao_second_pass)); + if (mesh.vao_glow_pass) + glDeleteVertexArrays(1, &(mesh.vao_glow_pass)); + if (mesh.vao_displace_pass) + glDeleteVertexArrays(1, &(mesh.vao_displace_pass)); + if (mesh.vao_displace_mask_pass) + glDeleteVertexArrays(1, &(mesh.vao_displace_mask_pass)); + if (mesh.vao_shadow_pass) + glDeleteVertexArrays(1, &(mesh.vao_shadow_pass)); + glDeleteBuffers(1, &(mesh.vertex_buffer)); + glDeleteBuffers(1, &(mesh.index_buffer)); + } + glDeleteBuffers(1, &instances_vbo); +} + +STKInstancedSceneNode::~STKInstancedSceneNode() +{ + cleanGL(); +} + void STKInstancedSceneNode::createGLMeshes() { for (u32 i = 0; igetMeshBufferCount(); ++i) diff --git a/src/graphics/stkinstancedscenenode.hpp b/src/graphics/stkinstancedscenenode.hpp index 9293d860a..a2ca06fed 100644 --- a/src/graphics/stkinstancedscenenode.hpp +++ b/src/graphics/stkinstancedscenenode.hpp @@ -16,12 +16,14 @@ protected: bool isMaterialInitialized; void setFirstTimeMaterial(); void initinstancedvaostate(GLMesh &mesh, GeometricMaterial GeoMat, ShadedMaterial ShadedMat); + void cleanGL(); core::vector3df windDir; public: STKInstancedSceneNode(irr::scene::IMesh* mesh, ISceneNode* parent, irr::scene::ISceneManager* mgr, irr::s32 id, const irr::core::vector3df& position = irr::core::vector3df(0, 0, 0), const irr::core::vector3df& rotation = irr::core::vector3df(0, 0, 0), const irr::core::vector3df& scale = irr::core::vector3df(1.0f, 1.0f, 1.0f)); + ~STKInstancedSceneNode(); virtual void render(); void addInstance(const core::vector3df &origin, const core::vector3df &orientation); };