Commit d623e384 authored by schultezub's avatar schultezub
Browse files

* added singleton implementation to kisscl::CLRuntime

 * added (de)initialization of KissCL to TumVisApplication

git-svn-id: https://camplinux.in.tum.de/svn/campvis/trunk@243 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent d8d4738a
...@@ -38,6 +38,8 @@ ...@@ -38,6 +38,8 @@
#include "tgt/qt/qtcontextmanager.h" #include "tgt/qt/qtcontextmanager.h"
#include "tbb/include/tbb/compat/thread" #include "tbb/include/tbb/compat/thread"
#include "kisscl/clruntime.h"
#include "application/tumvispainter.h" #include "application/tumvispainter.h"
#include "application/gui/mainwindow.h" #include "application/gui/mainwindow.h"
#include "core/pipeline/abstractpipeline.h" #include "core/pipeline/abstractpipeline.h"
...@@ -48,11 +50,12 @@ namespace TUMVis { ...@@ -48,11 +50,12 @@ namespace TUMVis {
const std::string TumVisApplication::loggerCat_ = "TUMVis.application.TumVisApplication"; const std::string TumVisApplication::loggerCat_ = "TUMVis.application.TumVisApplication";
TumVisApplication::TumVisApplication(int argc, char** argv) TumVisApplication::TumVisApplication(int argc, char** argv, bool useOpenCL)
: QApplication(argc, argv) : QApplication(argc, argv)
, _localContext(0) , _localContext(0)
, _mainWindow(0) , _mainWindow(0)
, _initialized(false) , _initialized(false)
, _useOpenCL(useOpenCL)
, _argc(argc) , _argc(argc)
, _argv(argv) , _argv(argv)
{ {
...@@ -93,6 +96,7 @@ namespace TUMVis { ...@@ -93,6 +96,7 @@ namespace TUMVis {
tgt::GLContextScopedLock lock(_localContext->getContext()); tgt::GLContextScopedLock lock(_localContext->getContext());
tgt::initGL(featureset); tgt::initGL(featureset);
ShdrMgr.setGlobalHeader("#version 130\n");
LGL_ERROR; LGL_ERROR;
// ensure matching OpenGL specs // ensure matching OpenGL specs
...@@ -103,6 +107,10 @@ namespace TUMVis { ...@@ -103,6 +107,10 @@ namespace TUMVis {
LERROR("Your system does not support GLSL Shader Version 1.30, which is mandatory. TUMVis will probably not work as intendet."); LERROR("Your system does not support GLSL Shader Version 1.30, which is mandatory. TUMVis will probably not work as intendet.");
} }
if (_useOpenCL) {
kisscl::CLRuntime::init();
}
if (_argc > 0) { if (_argc > 0) {
// ugly hack // ugly hack
std::string programPath(_argv[0]); std::string programPath(_argv[0]);
...@@ -131,6 +139,10 @@ namespace TUMVis { ...@@ -131,6 +139,10 @@ namespace TUMVis {
// Deinit everything OpenGL related using the local context. // Deinit everything OpenGL related using the local context.
tgt::GLContextScopedLock lock(_localContext->getContext()); tgt::GLContextScopedLock lock(_localContext->getContext());
if (_useOpenCL) {
kisscl::CLRuntime::deinit();
}
// Deinit pipeline first // Deinit pipeline first
for (std::vector<AbstractPipeline*>::iterator it = _pipelines.begin(); it != _pipelines.end(); ++it) { for (std::vector<AbstractPipeline*>::iterator it = _pipelines.begin(); it != _pipelines.end(); ++it) {
(*it)->deinit(); (*it)->deinit();
......
...@@ -63,10 +63,11 @@ namespace TUMVis { ...@@ -63,10 +63,11 @@ namespace TUMVis {
public: public:
/** /**
* Creates a new TumVisApplication. * Creates a new TumVisApplication.
* \param argc number of passed arguments * \param argc number of passed arguments
* \param argv vector of arguments * \param argv vector of arguments
* \param useOpenCL Flag, whether to use OpenCL (inits and deinits KissCL lib at the appropriate time).
*/ */
TumVisApplication(int argc, char** argv); TumVisApplication(int argc, char** argv, bool useOpenCL = true);
/** /**
* Destructor, make sure to call deinit() first. * Destructor, make sure to call deinit() first.
...@@ -131,6 +132,9 @@ namespace TUMVis { ...@@ -131,6 +132,9 @@ namespace TUMVis {
/// Flag, whether TumVisApplication was correctly initialized /// Flag, whether TumVisApplication was correctly initialized
bool _initialized; bool _initialized;
/// Flag, whether to use OpenCL (inits and deinits KissCL lib at the appropriate time).
bool _useOpenCL;
int _argc; int _argc;
char** _argv; char** _argv;
......
...@@ -37,9 +37,13 @@ namespace kisscl { ...@@ -37,9 +37,13 @@ namespace kisscl {
* Singleton class for managing the OpenCL runtime. * Singleton class for managing the OpenCL runtime.
* Gathers all available OpenCL platforms/devices and offers methods to create OpenCL contexts on them. * Gathers all available OpenCL platforms/devices and offers methods to create OpenCL contexts on them.
*/ */
class CLRuntime { class CLRuntime : public tgt::Singleton<CLRuntime> {
friend class tgt::Singleton<CLRuntime>;
public: public:
CLRuntime(); /**
* Destructor, cleaning up all platforms and devices.
*/
~CLRuntime(); ~CLRuntime();
/** /**
...@@ -73,10 +77,16 @@ namespace kisscl { ...@@ -73,10 +77,16 @@ namespace kisscl {
std::vector<Device*> _cpuDevices; ///< List of all OpenCL CPU devices (just a shortcut to the corresponding devices in _platforms) std::vector<Device*> _cpuDevices; ///< List of all OpenCL CPU devices (just a shortcut to the corresponding devices in _platforms)
std::vector<Device*> _gpuDevices; ///< List of all OpenCL GPU devices (just a shortcut to the corresponding devices in _platforms) std::vector<Device*> _gpuDevices; ///< List of all OpenCL GPU devices (just a shortcut to the corresponding devices in _platforms)
/**
* Private constructor for singleton pattern.
*/
CLRuntime();
static const std::string loggerCat_; static const std::string loggerCat_;
}; };
#define CLMgr tgt::Singleton<kisscl::CLRuntime>::getRef()
} }
#endif // KISSCL_CLRUNTIME_H__ #endif // KISSCL_CLRUNTIME_H__
...@@ -67,8 +67,7 @@ namespace TUMVis { ...@@ -67,8 +67,7 @@ namespace TUMVis {
void DVRVis::init() { void DVRVis::init() {
VisualizationPipeline::init(); VisualizationPipeline::init();
kisscl::CLRuntime clr; kisscl::Context* context = CLMgr.createGlSharingContext();
kisscl::Context* context = clr.createGlSharingContext();
delete context; delete context;
_camera.addSharedProperty(&_eepGenerator._camera); _camera.addSharedProperty(&_eepGenerator._camera);
......
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