The expiration time for new job artifacts in CI/CD pipelines is now 30 days (GitLab default). Previously generated artifacts in already completed jobs will not be affected by the change. The latest artifacts for all jobs in the latest successful pipelines will be kept. More information: https://gitlab.lrz.de/help/user/admin_area/settings/continuous_integration.html#default-artifacts-expiration

Commit d4266712 authored by schultezub's avatar schultezub
Browse files

Introducing tgt::OpenGLGarbagecollector to centralize deletion of heavy OpenGL...

Introducing tgt::OpenGLGarbagecollector to centralize deletion of heavy OpenGL objects (textures, FBOs, buffers)

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@490 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent 8abced32
......@@ -46,6 +46,7 @@ SET(TGT_SOURCES
light.cpp
logmanager.cpp
naturalcubicspline.cpp
openglgarbagecollector.cpp
painter.cpp
shadermanager.cpp
spline.cpp
......
#include "buffer.h"
#include "tgt/openglgarbagecollector.h"
namespace tgt {
......@@ -21,8 +22,7 @@ namespace tgt {
tgtAssert(_assignedAttributes.empty(), "Destructing a BufferObject, that is still bound to a VertexAttribute.");
if (_id != 0) {
glDeleteBuffers(1, &_id);
LGL_ERROR;
GLGC.addGarbageBufferObject(_id);
}
}
......
......@@ -74,6 +74,12 @@ namespace tgt {
*/
size_t getBufferSize() const;
/**
* Gets the OpenGL id of this buffer object;
* \return _id
*/
GLuint getId() const { return _id; };
/**
* Binds the buffer object to the current OpenGL context.
* \param target Target type of buffer object
......
......@@ -24,6 +24,7 @@
#include "tgt/framebufferobject.h"
#include "tgt/logmanager.h"
#include "tgt/openglgarbagecollector.h"
namespace tgt {
......@@ -37,7 +38,7 @@ FramebufferObject::FramebufferObject()
FramebufferObject::~FramebufferObject()
{
glDeleteFramebuffersEXT(1, &id_);
GLGC.addGarbageFramebufferObject(id_);
}
void FramebufferObject::activate()
......
......@@ -58,6 +58,8 @@ public:
static GLuint getActiveObject();
GLuint getId() const { return id_; };
protected:
GLuint generateId();
......
......@@ -27,6 +27,7 @@
#include "tgt/tgt_gl.h"
#include "tgt/assert.h"
#include "tgt/openglgarbagecollector.h"
#include "tgt/singleton.h"
#include "tgt/gpucapabilities.h"
#ifdef _MSC_VER
......@@ -112,9 +113,13 @@ void initGL(InitFeature::Features featureset) {
// starting shadermanager
ShaderManager::init();
OpenGLGarbageCollector::init();
}
void deinitGL() {
if (OpenGLGarbageCollector::isInited())
OpenGLGarbageCollector::deinit();
if (GpuCapabilities::isInited())
GpuCapabilities::deinit();
#ifdef _MSC_VER
......
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitt Mnchen
// Boltzmannstr. 3, 85748 Garching b. Mnchen, Germany
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// The licensing of this softare is not yet resolved. Until then, redistribution in source or
// binary forms outside the CAMP chair is not permitted, unless explicitly stated in legal form.
// However, the names of the original authors and the above copyright notice must retain in its
// original state in any case.
//
// Legal disclaimer provided by the BSD license:
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ================================================================================================
#include "openglgarbagecollector.h"
#include "tgt/assert.h"
#include "tgt/logmanager.h"
namespace tgt {
OpenGLGarbageCollector::OpenGLGarbageCollector() {
_currentFrontindex = 0;
}
OpenGLGarbageCollector::~OpenGLGarbageCollector() {
deleteGarbage();
deleteGarbage();
}
void OpenGLGarbageCollector::deleteGarbage() {
tbb::spin_mutex::scoped_lock lock(_mutex);
size_t backIndex = _currentFrontindex;
_currentFrontindex = (_currentFrontindex+1) % 2;
// delete textures
if (! _texturesToDelete[backIndex].empty()) {
glDeleteTextures(_texturesToDelete[backIndex].size(), &(_texturesToDelete[backIndex].front()));
//LDEBUGC("tgt.OpenGLGarbageCollector", "Deleted " << _texturesToDelete[backIndex].size() << " Textures.");
_texturesToDelete[backIndex].clear();
}
// delete FBOs
if (! _fbosToDelete[backIndex].empty()) {
glDeleteFramebuffers(_fbosToDelete[backIndex].size(), &(_fbosToDelete[backIndex].front()));
//LDEBUGC("tgt.OpenGLGarbageCollector", "Deleted " << _fbosToDelete[backIndex].size() << " FBOs.");
_fbosToDelete[backIndex].clear();
}
// delete buffers
if (! _buffersToDelete[backIndex].empty()) {
glDeleteBuffers(_buffersToDelete[backIndex].size(), &(_buffersToDelete[backIndex].front()));
// LDEBUGC("tgt.OpenGLGarbageCollector", "Deleted " << _buffersToDelete[backIndex].size() << " Buffers.");
_buffersToDelete[backIndex].clear();
}
LGL_ERROR;
}
}
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitt Mnchen
// Boltzmannstr. 3, 85748 Garching b. Mnchen, Germany
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// The licensing of this softare is not yet resolved. Until then, redistribution in source or
// binary forms outside the CAMP chair is not permitted, unless explicitly stated in legal form.
// However, the names of the original authors and the above copyright notice must retain in its
// original state in any case.
//
// Legal disclaimer provided by the BSD license:
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// ================================================================================================
#ifndef OPENGLGARBAGECOLLECTOR_H__
#define OPENGLGARBAGECOLLECTOR_H_
#include "tgt/tgt_gl.h"
#include "tgt/singleton.h"
#include "tbb/atomic.h"
#include "tbb/concurrent_vector.h"
#include "tbb/spin_mutex.h"
#include <vector>
namespace tgt {
/**
* Singleton class for collecting OpenGL stuff that is to be deleted.
*
* This class is to be considered as thread-safe.
*/
class OpenGLGarbageCollector : public Singleton<OpenGLGarbageCollector> {
friend class Singleton<OpenGLGarbageCollector>;
public:
/**
* Destructor, deletes all unfinished jobs.
*/
~OpenGLGarbageCollector();
void addGarbageTexture(GLuint id) {
tbb::spin_mutex::scoped_lock lock(_addMutex);
_texturesToDelete[_currentFrontindex].push_back(id);
};
void addGarbageFramebufferObject(GLuint id) {
tbb::spin_mutex::scoped_lock lock(_addMutex);
_fbosToDelete[_currentFrontindex].push_back(id);
};
void addGarbageBufferObject(GLuint id) {
tbb::spin_mutex::scoped_lock lock(_addMutex);
_buffersToDelete[_currentFrontindex].push_back(id);
};
void deleteGarbage();
protected:
OpenGLGarbageCollector();
std::vector<GLuint> _texturesToDelete[2];
std::vector<GLuint> _fbosToDelete[2];
std::vector<GLuint> _buffersToDelete[2];
tbb::atomic<size_t> _currentFrontindex;
tbb::spin_mutex _mutex;
tbb::spin_mutex _addMutex;
};
}
#define GLGC tgt::Singleton<tgt::OpenGLGarbageCollector>::getRef()
#endif // OPENGLGARBAGECOLLECTOR_H__
......@@ -27,6 +27,7 @@
#include "tgt/gpucapabilities.h"
#include "tgt/filesystem.h"
#include "tgt/openglgarbagecollector.h"
namespace tgt {
......@@ -92,6 +93,15 @@ Texture::Texture(GLubyte* data, const tgt::ivec3& dimensions, GLint format,
arraySize_ = hmul(dimensions_) * bpp_;
}
Texture::~Texture() {
if (id_)
GLGC.addGarbageTexture(id_);
if (pixels_)
delete[] pixels_;
}
void Texture::init(bool allocData) {
#ifndef GL_TEXTURE_RECTANGLE_ARB
textureRectangle = false;
......
......@@ -94,14 +94,7 @@ public:
* The destructor deletes the Texture in OpenGL.
* Handled by the texturemanager!
*/
virtual ~Texture()
{
if (id_)
glDeleteTextures(1, &id_);
if (pixels_)
delete[] pixels_;
}
virtual ~Texture();
/// allocates an appropriate buffer for the texture
void alloc() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment