diff options
author | Charles Yin <charles.yin@nokia.com> | 2012-05-18 09:58:09 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-05-31 02:23:02 +0200 |
commit | fdbb1f1b4f43a961d66998a1125f5e11618ed025 (patch) | |
tree | 1f8db88458bd6f837492bc9ddc26fbc9278c3c48 /src/quick/items/context2d/qquickcontext2dtexture.cpp | |
parent | 447e5acb880ebda498891623dc4009984cb73bc6 (diff) |
Enable threaded/immediate rendering for FBO(step 1)
1. Create a new gl context if the scenegraph render thread is different with context2d render thread
2. Expose the gl context and window surface from context2d
3. Get the right current gl context before painting
Change-Id: I5e252a8142d760442f9dfb53ed8a8ce289379af9
Reviewed-by: Glenn Watson <glenn.watson@nokia.com>
Diffstat (limited to 'src/quick/items/context2d/qquickcontext2dtexture.cpp')
-rw-r--r-- | src/quick/items/context2d/qquickcontext2dtexture.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/quick/items/context2d/qquickcontext2dtexture.cpp b/src/quick/items/context2d/qquickcontext2dtexture.cpp index 1beee8c7d1..52f3161a8b 100644 --- a/src/quick/items/context2d/qquickcontext2dtexture.cpp +++ b/src/quick/items/context2d/qquickcontext2dtexture.cpp @@ -68,6 +68,25 @@ static inline int qt_next_power_of_two(int v) return v; } +struct GLAcquireContext { + GLAcquireContext(QOpenGLContext *c, QSurface *s):ctx(c) { + if (ctx) { + Q_ASSERT(s); + if (!ctx->isValid()) + ctx->create(); + + if (!ctx->isValid()) + qWarning() << "Unable to create GL context"; + else if (!ctx->makeCurrent(s)) + qWarning() << "Can't make current GL context"; + } + } + ~GLAcquireContext() { + if (ctx) + ctx->doneCurrent(); + } + QOpenGLContext *ctx; +}; Q_GLOBAL_STATIC(QThread, globalCanvasThreadRenderInstance) @@ -241,6 +260,8 @@ void QQuickContext2DTexture::paint() if (canvasDestroyed()) return; + GLAcquireContext currentContext(m_context->glContext(), m_context->surface()); + if (m_threadRendering && QThread::currentThread() != globalCanvasThreadRenderInstance()) { Q_ASSERT(thread() == globalCanvasThreadRenderInstance()); QMetaObject::invokeMethod(this, "paint", Qt::QueuedConnection); |