qtcontextmanager.h 2.46 KB
Newer Older
1
2
3
4
#ifndef QTGLCONTEXTMANAGER_H__
#define QTGLCONTEXTMANAGER_H__

#include "tgt/singleton.h"
5
#include "tgt/glcontextmanager.h"
6
#include "tgt/qt/qtthreadedcanvas.h"
7
#include "tgt/types.h"
8
#include <tbb/mutex.h>  // TODO: TBB dependency in TGT is not that beautiful...
9
10
11
12
#include <map>
#include <string>

namespace tgt {
schultezub's avatar
schultezub committed
13
14
    class QtGLContext;
    class QtThreadedCanvas;
15
16
17
18
19

    /**
     * Manages multiple shared OpenGL contexts and offers methods to ensure that only one context is active at a time.
     * 
     */
20
    class TGT_API QtContextManager : public GlContextManager {
21
22
23
24
25
26
27
28
29
30
31
32
    public:
        /**
         * Creates a new QtGLContext for the OpenGL context of \a canvas.
         * \param   canvas  QtCanvas with the OpenGL context to manage
         */
        QtContextManager();

        /**
         * Destructor
         */
        ~QtContextManager();

33
34
35
36
37
38
39
40
41
42
43
        /**
         * Init the actual singleton.
         * Must be called BEFORE the class is used, like this:
         */
        static void init();

        /**
         * Deinit the actual singleton.
         * Must be done at last.
         */
        static void deinit();
44
45

        /**
46
47
         * Creates a new OpenGL context in a QtThreadedCanvas with the given arguments.
         * Parameters are the same as in QtThreadedCanvas() but context sharing is enables per default.
48
49
         * 
         * \note    Must be called with the OpenGL mutex acquired!
50
51
52
53
54
55
56
         * 
         * \note    The created canvas/context is owned by this ContextManager. Hence, you may not
         *          delete it yourself!
         * 
         * \param   key     Key of the context to create, must be unique.
         * \param   title   Window title
         * \param   size    Window size
57
         * \return  The newly created QtThreadedCanvas.
58
         */
59
        virtual GLCanvas* createContext(
60
61
62
63
            const std::string& key,
            const std::string& title = "",
            const ivec2& size = ivec2(GLCanvas::DEFAULT_WINDOW_WIDTH, GLCanvas::DEFAULT_WINDOW_HEIGHT),
            const GLCanvas::Buffers buffers = GLCanvas::RGBADD,
64
            bool shared = true);
65
66
67
68
69
70
71
72

        
    protected:
        /**
         * Sets the given context \a context as the current context for the OpenGL device.
         * If \a context is already the current context, nothing will happen.
         * \param   context     Context to set as current.
         */
73
        virtual void setCurrent(GLCanvas* context);
74
75
76
77
78
79
80
81

    };

} // namespace tgt


#endif // QTGLCONTEXTMANAGER_H__