Commit 9185b628 authored by Christian Schulte zu Berge's avatar Christian Schulte zu Berge
Browse files

Removed OpenGLGarbageCollector interface. All textures, buffers and FBOs are...

Removed OpenGLGarbageCollector interface. All textures, buffers and FBOs are now deleted right away. This seems to improve the flickering issues, however they are still present.

refs #640
refs #641
parent b0004a42
......@@ -35,7 +35,6 @@ SET(CGT_SOURCES
init.cpp
logmanager.cpp
job.cpp
openglgarbagecollector.cpp
opengljobprocessor.cpp
painter.cpp
runnable.cpp
......
......@@ -27,8 +27,6 @@
**********************************************************************/
#include "buffer.h"
#include "cgt/openglgarbagecollector.h"
namespace cgt {
BufferObject::BufferObject(TargetType target, UsageType usage) throw (cgt::Exception)
......@@ -47,7 +45,7 @@ namespace cgt {
}
BufferObject::~BufferObject() {
glDeleteBuffers(1, &_id);
glDeleteBuffers(1, &_id);
}
void BufferObject::bind() {
......
......@@ -28,7 +28,6 @@
#include "cgt/framebufferobject.h"
#include "cgt/logmanager.h"
#include "cgt/openglgarbagecollector.h"
namespace cgt {
......@@ -44,7 +43,7 @@ FramebufferObject::FramebufferObject()
FramebufferObject::~FramebufferObject()
{
GLGC.addGarbageFramebufferObject(id_);
glDeleteFramebuffersEXT(1, &id_);
}
void FramebufferObject::activate()
......
......@@ -31,7 +31,6 @@
#include "cgt/cgt_gl.h"
#include "cgt/assert.h"
#include "cgt/openglgarbagecollector.h"
#include "cgt/singleton.h"
#include "cgt/gpucapabilities.h"
#ifdef _MSC_VER
......@@ -113,13 +112,9 @@ 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
......
/**********************************************************************
* *
* cgt - CAMP Graphics Toolbox, Copyright (C) 2012-2014 *
* Chair for Computer Aided Medical Procedures *
* Technische Universitaet Muenchen, Germany. *
* <http://campar.in.tum.de/> *
* *
* forked from tgt - Tiny Graphics Toolbox, Copyright (C) 2006-2011 *
* Visualization and Computer Graphics Group, Department of *
* Computer Science, University of Muenster, Germany. *
* <http://viscg.uni-muenster.de> *
* *
* This file is part of the cgt library. This library is free *
* software; you can redistribute it and/or modify it under the terms *
* of the GNU Lesser General Public License version 2.1 as published *
* by the Free Software Foundation. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License in the file "LICENSE.txt" along with this library. *
* If not, see <http://www.gnu.org/licenses/>. *
* *
**********************************************************************/
// ================================================================================================
//
// 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 Universität München
// Boltzmannstr. 3, 85748 Garching b. München, 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 "cgt/assert.h"
#include "cgt/logmanager.h"
namespace cgt {
OpenGLGarbageCollector::OpenGLGarbageCollector() {
_currentFrontindex = 0;
}
OpenGLGarbageCollector::~OpenGLGarbageCollector() {
deleteGarbage();
deleteGarbage();
}
void OpenGLGarbageCollector::deleteGarbage() {
tbb::spin_mutex::scoped_lock lock(_mutex);
size_t backIndex;
{
backIndex = _currentFrontindex;
tbb::spin_mutex::scoped_lock lock(_addMutex);
_currentFrontindex = (_currentFrontindex+1) % 2;
}
// delete textures
if (! _texturesToDelete[backIndex].empty()) {
glDeleteTextures(static_cast<GLsizei>(_texturesToDelete[backIndex].size()), &(_texturesToDelete[backIndex].front()));
_texturesToDelete[backIndex].clear();
}
// delete FBOs
if (! _fbosToDelete[backIndex].empty()) {
glDeleteFramebuffersEXT(static_cast<GLsizei>(_fbosToDelete[backIndex].size()), &(_fbosToDelete[backIndex].front()));
_fbosToDelete[backIndex].clear();
}
// delete buffers
if (! _buffersToDelete[backIndex].empty()) {
glDeleteBuffers(static_cast<GLsizei>(_buffersToDelete[backIndex].size()), &(_buffersToDelete[backIndex].front()));
_buffersToDelete[backIndex].clear();
}
LGL_ERROR;
}
}
/**********************************************************************
* *
* cgt - CAMP Graphics Toolbox, Copyright (C) 2012-2014 *
* Chair for Computer Aided Medical Procedures *
* Technische Universitaet Muenchen, Germany. *
* <http://campar.in.tum.de/> *
* *
* forked from tgt - Tiny Graphics Toolbox, Copyright (C) 2006-2011 *
* Visualization and Computer Graphics Group, Department of *
* Computer Science, University of Muenster, Germany. *
* <http://viscg.uni-muenster.de> *
* *
* This file is part of the cgt library. This library is free *
* software; you can redistribute it and/or modify it under the terms *
* of the GNU Lesser General Public License version 2.1 as published *
* by the Free Software Foundation. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License in the file "LICENSE.txt" along with this library. *
* If not, see <http://www.gnu.org/licenses/>. *
* *
**********************************************************************/
// ================================================================================================
//
// 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 Universität München
// Boltzmannstr. 3, 85748 Garching b. München, 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 "cgt/cgt_gl.h"
#include "cgt/opengljobprocessor.h"
#include "cgt/singleton.h"
#include "cgt/types.h"
#include <tbb/atomic.h>
#include <tbb/concurrent_vector.h>
#include <tbb/spin_mutex.h>
#include <vector>
namespace cgt {
/**
* Singleton class for collecting OpenGL stuff that is to be deleted.
*
* This class is to be considered as thread-safe.
*/
class CGT_API 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);
GLJobProc.enqueueGarbageCollection();
};
void addGarbageFramebufferObject(GLuint id) {
tbb::spin_mutex::scoped_lock lock(_addMutex);
_fbosToDelete[_currentFrontindex].push_back(id);
GLJobProc.enqueueGarbageCollection();
};
void addGarbageBufferObject(GLuint id) {
tbb::spin_mutex::scoped_lock lock(_addMutex);
_buffersToDelete[_currentFrontindex].push_back(id);
GLJobProc.enqueueGarbageCollection();
};
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 cgt::Singleton<cgt::OpenGLGarbageCollector>::getRef()
#endif // OPENGLGARBAGECOLLECTOR_H__
......@@ -32,7 +32,6 @@
#include "cgt/assert.h"
#include "cgt/logmanager.h"
#include "cgt/openglgarbagecollector.h"
#include "cgt/glcontextmanager.h"
namespace cgt {
......@@ -59,7 +58,6 @@ namespace cgt {
{
_pause = 0;
_context= nullptr;
_performGarbageCollection = false;
}
OpenGLJobProcessor::~OpenGLJobProcessor() {
......@@ -88,12 +86,9 @@ namespace cgt {
// execute and delete the job
jobToDo->execute();
delete jobToDo;
performGarbageCollectionIfNecessary();
}
while (_pause > 0 && !_stopExecution) {
performGarbageCollectionIfNecessary();
cgt::GlContextManager::getRef().releaseContext(_context, false);
_evaluationCondition.wait(lock);
cgt::GlContextManager::getRef().acquireContext(_context, false);
......@@ -101,7 +96,6 @@ namespace cgt {
}
if (! hadWork && !_stopExecution) {
performGarbageCollectionIfNecessary();
cgt::GlContextManager::getRef().releaseContext(_context, false);
_evaluationCondition.wait(lock);
cgt::GlContextManager::getRef().acquireContext(_context, false);
......@@ -141,18 +135,5 @@ namespace cgt {
return _context;
}
void OpenGLJobProcessor::enqueueGarbageCollection() {
_performGarbageCollection = true;
_evaluationCondition.notify_all();
}
void OpenGLJobProcessor::performGarbageCollectionIfNecessary() {
if (_performGarbageCollection && cgt::OpenGLGarbageCollector::isInited()) {
_performGarbageCollection = false;
GLGC.deleteGarbage();
}
}
}
......@@ -119,24 +119,12 @@ namespace cgt {
*/
void enqueueJob(AbstractJob* job);
/**
* Enqueue OpenGL Garbage collection job
*/
void enqueueGarbageCollection();
protected:
/**
* Performs a OpenGL Garbage Collection if necessary.
*/
void performGarbageCollectionIfNecessary();
// Protected constructor since it's a singleton
OpenGLJobProcessor();
cgt::GLCanvas* _context; ///< The OpenGL context to use
tbb::concurrent_queue<AbstractJob*> _jobQueue; ///< The OpenGL job queue
tbb::atomic<bool> _performGarbageCollection; ///< Flag whether to perform garbage cxollection
tbb::atomic<int> _pause; ///< Counter of pause requests
......
......@@ -31,7 +31,6 @@
#include "cgt/gpucapabilities.h"
#include "cgt/filesystem.h"
#include "cgt/openglgarbagecollector.h"
namespace cgt {
......@@ -64,7 +63,7 @@ Texture::Texture(GLenum type, const cgt::ivec3& dimensions, GLint internalFormat
Texture::~Texture() {
if (id_)
GLGC.addGarbageTexture(id_);
glDeleteTextures(1, &id_);
}
......
Supports Markdown
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