Commit 2247936f authored by Christian Schulte zu Berge's avatar Christian Schulte zu Berge
Browse files

Merge branch 'issue-641' into 'development'

See merge request !116

closes #640
refs #641
parents b8fec63c 927262c4
......@@ -64,6 +64,8 @@ namespace campvis {
}
void AbstractPipeline::init() {
_data->s_dataAdded.connect(this, &AbstractPipeline::onDataContainerDataAdded);
initAllProperties();
// initialize all processors:
......@@ -81,6 +83,8 @@ namespace campvis {
}
void AbstractPipeline::deinit() {
_data->s_dataAdded.disconnect(this);
// use trigger signal to enforce blocking call
s_deinit.triggerSignal();
......@@ -276,6 +280,10 @@ namespace campvis {
return _processors[index];
}
void AbstractPipeline::onDataContainerDataAdded(std::string name, DataHandle dh) {
if (name == _renderTargetID.getValue())
setPipelineDirty();
}
void AbstractPipeline::forceExecuteProcessor(AbstractProcessor* processor) {
bool enabledState = processor->getEnabled();
......@@ -287,5 +295,4 @@ namespace campvis {
}
}
......@@ -231,6 +231,14 @@ namespace campvis {
*/
void executeProcessorAndCheckOpenGLState(AbstractProcessor* processor);
/**
* Gets called when the data collection of this pipeline has changed and thus has notified its observers.
* If \a name equals the name of the renderTarget, setPipelineDirty will be called.
* \param name Name of the added data.
* \param dh DataHandle to the newly added data.
*/
virtual void onDataContainerDataAdded(std::string name, DataHandle dh);
/**
* Slot getting called when one of the observed properties changed and notifies its observers.
* The default behaviour is just to set the invalidation level to invalid.
......
// ================================================================================================
//
//
// This file is part of the CAMPVis Software Framework.
//
//
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitaet Muenchen
// Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
//
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
//
// Unless required by applicable law or agreed to in writing, software distributed under the
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
//
//
// ================================================================================================
#include "autoevaluationpipeline.h"
......@@ -34,7 +34,7 @@
namespace campvis {
const std::string AutoEvaluationPipeline::loggerCat_ = "CAMPVis.core.datastructures.AutoEvaluationPipeline";
AutoEvaluationPipeline::AutoEvaluationPipeline(DataContainer* dc)
AutoEvaluationPipeline::AutoEvaluationPipeline(DataContainer* dc)
: AbstractPipeline(dc)
{
}
......@@ -44,16 +44,13 @@ namespace campvis {
void AutoEvaluationPipeline::init() {
AbstractPipeline::init();
_data->s_dataAdded.connect(this, &AutoEvaluationPipeline::onDataContainerDataAdded);
}
void AutoEvaluationPipeline::deinit() {
_data->s_dataAdded.disconnect(this);
for (std::vector<AbstractProcessor*>::iterator it = _processors.begin(); it != _processors.end(); ++it) {
(*it)->s_invalidated.disconnect(this);
}
AbstractPipeline::deinit();
}
......@@ -73,7 +70,7 @@ namespace campvis {
}
void AutoEvaluationPipeline::executePipeline() {
// execute each processor once
// execute each processor once
// (AbstractProcessor::process() takes care of executing only invalid processors)
for (size_t i = 0; i < _processors.size(); ++i) {
executeProcessorAndCheckOpenGLState(_processors[i]);
......@@ -129,6 +126,8 @@ namespace campvis {
void AutoEvaluationPipeline::onDataContainerDataAdded(std::string name, DataHandle dh) {
{
AbstractPipeline::onDataContainerDataAdded(name, dh);
// acquire read lock
tbb::spin_rw_mutex::scoped_lock lock(_pmMutex, false);
......
......@@ -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,8 @@
#include "cgt/framebufferobject.h"
#include "cgt/logmanager.h"
#include "cgt/openglgarbagecollector.h"
#include <string.h> // memset
namespace cgt {
......@@ -44,7 +45,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_);
}
......
......@@ -51,6 +51,8 @@ TextureUnit::TextureUnit(bool keep)
TextureUnit::~TextureUnit() {
if (assigned_ && !keep_) {
tbb::spin_mutex::scoped_lock lock(mutex_);
busyUnits_.at(number_) = false;
totalActive_--;
}
......
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