qtthreadedpainter.cpp 1.47 KB
Newer Older
1
2
3
#include "qtthreadedpainter.h"
#include "tgt/qt/qtcanvas.h"
#include "tgt/qt/qtthreadedcanvas.h"
4
#include "tgt/qt/qtcontextmanager.h"
5
6
7
8
9
10
11
12
13
14

namespace tgt {

    QtThreadedPainter::QtThreadedPainter(QtCanvas* canvas) 
        : QThread()
        , tgt::Painter(canvas)
    {
        _evaluateRenderingLoop = true;
    }

15
    void QtThreadedPainter::stop() {
16
        _evaluateRenderingLoop = false;
17
        _renderCondition.wakeAll();
18
19
    }

20
    void QtThreadedPainter::run() {
21
22
23
24
25
26
        QtGLContext* qtContext = static_cast<QtCanvas*>(getCanvas())->getContext();
        GLContextScopedLock lock(qtContext);

        LGL_ERROR;
        while (_evaluateRenderingLoop) {
            paint();
27
28
29
30
31
32
33
34
35
            glFlush();
            qtContext->getCanvas()->swap();

            /*if (qtContext->getCanvas()->doubleBuffer()) {
                if (d->autoSwap)
                    swapBuffers();
            } else {
                glFlush();
            }*/
36

37
            
38
            // suspend rendering thread until there is again sth. to render.
39
            _renderCondition.wait(&CtxtMgr.getGlMutex());
40
41
            qtContext->acquire();
        }
42
43
44

        // release OpenGL context, so that other threads can access it
        CtxtMgr.releaseCurrentContext();
45
46
47
48
49
50
51
52
    }

    void QtThreadedPainter::setCanvas(GLCanvas* canvas) {
        tgtAssert(dynamic_cast<QtCanvas*>(canvas) != 0, "Context must be of type QtGLContext!");
        Painter::setCanvas(canvas);
    }

}