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

* Tied tgt::OpenGLJobProcessor and tgt::OpenGLGarbageCollector closer together...

* Tied tgt::OpenGLJobProcessor and tgt::OpenGLGarbageCollector closer together regarding OpenGL garbage collection
* AutoEvaluationPipeline checks for valid OpenGL state after each processor call (only in debug)
parent 25e14d19
......@@ -194,7 +194,10 @@ namespace campvis {
void CampVisApplication::deinit() {
tgtAssert(_initialized, "Tried to deinitialize uninitialized CampVisApplication.");
GLJobProc.stop();
// Stop all pipeline threads.
for (std::vector<PipelineRecord>::iterator it = _pipelines.begin(); it != _pipelines.end(); ++it) {
it->_pipeline->stop();
}
{
// Deinit everything OpenGL related using the local context.
......@@ -215,19 +218,20 @@ namespace campvis {
tgt::deinitGL();
}
tgt::GlContextManager::deinit();
tgt::deinit();
// MainWindow dtor needs a valid CampVisApplication, so we need to call it here instead of during destruction.
delete _mainWindow;
GLJobProc.stop();
OpenGLJobProcessor::deinit();
SimpleJobProcessor::deinit();
tgt::GlContextManager::deinit();
tgt::deinit();
PropertyWidgetFactory::deinit();
ImageRepresentationConverter::deinit();
PipelineFactory::deinit();
// MainWindow dtor needs a valid CampVisApplication, so we need to call it here instead of during destruction.
delete _mainWindow;
_initialized = false;
}
......
......@@ -80,8 +80,6 @@ namespace campvis {
}
void AbstractPipeline::deinit() {
stop();
deinitAllProperties();
// deinitialize all processors:
......@@ -117,7 +115,7 @@ namespace campvis {
_canvas->getPainter()->paint();
}
if (!_enabled || !_pipelineDirty) {
if (!_stopExecution && (!_enabled || !_pipelineDirty)) {
tgt::GlContextManager::getRef().releaseContext(_canvas, false);
_evaluationCondition.wait(lock);
tgt::GlContextManager::getRef().acquireContext(_canvas, false);
......
......@@ -81,7 +81,7 @@ namespace campvis {
// execute each processor once
// (AbstractProcessor::process() takes care of executing only invalid processors)
for (size_t i = 0; i < _processors.size(); ++i) {
_processors[i]->process(getDataContainer());
executeProcessorAndCheckOpenGLState(_processors[i]);
}
}
......
......@@ -37,8 +37,6 @@ namespace tgt {
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glPixelStorei(GL_PACK_ALIGNMENT, 1);
// LDEBUG("Initialized context '" << title << "'");
}
void GlContextManager::removeContext(GLCanvas* context) {
......@@ -77,8 +75,6 @@ namespace tgt {
ci._acquired = true;
ci._threadId = std::this_thread::get_id();
context->acquireAsCurrentContext();
// LDEBUG("Acquired context '" << a->second._title << "' from thread " << a->second._threadId);
}
else {
tgtAssert(false, "Could not find the context in map, this should not happen!");
......@@ -102,7 +98,6 @@ namespace tgt {
if (unlockGlMutex)
ci._glMutex->unlock();
// LDEBUG("Released context '" << a->second._title << "'");
}
else {
tgtAssert(false, "Could not find the context in map, this should not happen!");
......
......@@ -61,19 +61,19 @@ namespace tgt {
void addGarbageTexture(GLuint id) {
tbb::spin_mutex::scoped_lock lock(_addMutex);
_texturesToDelete[_currentFrontindex].push_back(id);
GLJobProc.enqueueJob(makeJobOnHeap(this, &OpenGLGarbageCollector::deleteGarbage));
GLJobProc.enqueueGarbageCollection();
};
void addGarbageFramebufferObject(GLuint id) {
tbb::spin_mutex::scoped_lock lock(_addMutex);
_fbosToDelete[_currentFrontindex].push_back(id);
GLJobProc.enqueueJob(makeJobOnHeap(this, &OpenGLGarbageCollector::deleteGarbage));
GLJobProc.enqueueGarbageCollection();
};
void addGarbageBufferObject(GLuint id) {
tbb::spin_mutex::scoped_lock lock(_addMutex);
_buffersToDelete[_currentFrontindex].push_back(id);
GLJobProc.enqueueJob(makeJobOnHeap(this, &OpenGLGarbageCollector::deleteGarbage));
GLJobProc.enqueueGarbageCollection();
};
void deleteGarbage();
......
......@@ -55,6 +55,7 @@ namespace tgt {
{
_pause = 0;
_context= nullptr;
_performGarbageCollection = false;
}
OpenGLJobProcessor::~OpenGLJobProcessor() {
......@@ -90,16 +91,20 @@ namespace tgt {
// execute and delete the job
jobToDo->execute();
delete jobToDo;
performGarbageCollectionIfNecessary();
}
while (_pause > 0) {
while (_pause > 0 && !_stopExecution) {
performGarbageCollectionIfNecessary();
tgt::GlContextManager::getRef().releaseContext(_context, false);
_evaluationCondition.wait(lock);
tgt::GlContextManager::getRef().acquireContext(_context, false);
hadWork = true;
}
if (! hadWork) {
if (! hadWork && !_stopExecution) {
performGarbageCollectionIfNecessary();
tgt::GlContextManager::getRef().releaseContext(_context, false);
_evaluationCondition.wait(lock);
tgt::GlContextManager::getRef().acquireContext(_context, false);
......@@ -139,6 +144,18 @@ namespace tgt {
return _context;
}
void OpenGLJobProcessor::enqueueGarbageCollection() {
_performGarbageCollection = true;
_evaluationCondition.notify_all();
}
void OpenGLJobProcessor::performGarbageCollectionIfNecessary() {
if (_performGarbageCollection && tgt::OpenGLGarbageCollector::isInited()) {
_performGarbageCollection = false;
GLGC.deleteGarbage();
}
}
}
......@@ -119,13 +119,24 @@ namespace tgt {
*/
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();
tgt::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
std::condition_variable _evaluationCondition; ///< conditional wait to be used when there are currently no jobs to process
......
......@@ -67,6 +67,7 @@ namespace campvis {
}
void AdvOptimizedRaycaster::processImpl(DataContainer& data, ImageRepresentationGL::ScopedRepresentation& image) {
_shader->deactivate();
if (getInvalidationLevel() & INVALID_BBV){
_vhm->createHierarchy(image, p_transferFunction.getTF());
......
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