Created
March 27, 2014 15:37
-
-
Save torarnv/9810363 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git i/examples/gui/openglwindow/main.cpp w/examples/gui/openglwindow/main.cpp | |
index aa1c6d7..d2a4d4a 100644 | |
--- i/examples/gui/openglwindow/main.cpp | |
+++ w/examples/gui/openglwindow/main.cpp | |
@@ -139,7 +139,7 @@ void TriangleWindow::render() | |
const qreal retinaScale = devicePixelRatio(); | |
glViewport(0, 0, width() * retinaScale, height() * retinaScale); | |
- glClear(GL_COLOR_BUFFER_BIT); | |
+ //glClear(GL_COLOR_BUFFER_BIT); | |
m_program->bind(); | |
diff --git i/examples/gui/openglwindow/openglwindow.cpp w/examples/gui/openglwindow/openglwindow.cpp | |
index afebf52..029cb5c 100644 | |
--- i/examples/gui/openglwindow/openglwindow.cpp | |
+++ w/examples/gui/openglwindow/openglwindow.cpp | |
@@ -52,6 +52,7 @@ OpenGLWindow::OpenGLWindow(QWindow *parent) | |
, m_update_pending(false) | |
, m_animating(false) | |
, m_context(0) | |
+ , m_context2(0) | |
, m_device(0) | |
{ | |
setSurfaceType(QWindow::OpenGLSurface); | |
@@ -77,13 +78,26 @@ void OpenGLWindow::render() | |
if (!m_device) | |
m_device = new QOpenGLPaintDevice; | |
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); | |
+// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); | |
m_device->setSize(size()); | |
QPainter painter(m_device); | |
render(&painter); | |
} | |
+ | |
+void OpenGLWindow::render2() | |
+{ | |
+ if (!m_device) | |
+ m_device = new QOpenGLPaintDevice; | |
+ | |
+// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); | |
+ | |
+ m_device->setSize(size()); | |
+ | |
+ QPainter painter(m_device); | |
+ painter.fillRect(QRect(0, 0, 100, 100), Qt::red); | |
+} | |
//! [2] | |
//! [3] | |
@@ -127,9 +141,23 @@ void OpenGLWindow::renderNow() | |
if (!m_context) { | |
m_context = new QOpenGLContext(this); | |
m_context->setFormat(requestedFormat()); | |
+ | |
+ m_context2 = new QOpenGLContext(this); | |
+ m_context2->setFormat(requestedFormat()); | |
+ m_context2->setShareContext(m_context); | |
+ | |
+ m_context->setShareContext(m_context2); | |
+ | |
m_context->create(); | |
needsInitialize = true; | |
+ | |
+ | |
+ m_context2->create(); | |
+ | |
+ m_context2->makeCurrent(this); | |
+ initializeOpenGLFunctions(); | |
+ initialize(); | |
} | |
m_context->makeCurrent(this); | |
@@ -143,6 +171,10 @@ void OpenGLWindow::renderNow() | |
m_context->swapBuffers(this); | |
+ m_context2->makeCurrent(this); | |
+ render2(); | |
+ m_context2->swapBuffers(this); | |
+ | |
if (m_animating) | |
renderLater(); | |
} | |
@@ -158,3 +190,4 @@ void OpenGLWindow::setAnimating(bool animating) | |
} | |
//! [5] | |
+ | |
diff --git i/examples/gui/openglwindow/openglwindow.h w/examples/gui/openglwindow/openglwindow.h | |
index f6b53e3..20595cb 100644 | |
--- i/examples/gui/openglwindow/openglwindow.h | |
+++ w/examples/gui/openglwindow/openglwindow.h | |
@@ -57,6 +57,7 @@ public: | |
virtual void render(QPainter *painter); | |
virtual void render(); | |
+ virtual void render2(); | |
virtual void initialize(); | |
@@ -76,6 +77,7 @@ private: | |
bool m_animating; | |
QOpenGLContext *m_context; | |
+ QOpenGLContext *m_context2; | |
QOpenGLPaintDevice *m_device; | |
}; | |
//! [1] | |
diff --git i/src/plugins/platforms/ios/qioscontext.h w/src/plugins/platforms/ios/qioscontext.h | |
index 52357a5..93be4cb 100644 | |
--- i/src/plugins/platforms/ios/qioscontext.h | |
+++ w/src/plugins/platforms/ios/qioscontext.h | |
@@ -88,7 +88,7 @@ private: | |
bool isComplete; | |
}; | |
- static void deleteBuffers(const FramebufferObject &framebufferObject); | |
+ void deleteBuffers(const FramebufferObject &framebufferObject); | |
FramebufferObject &backingFramebufferObjectFor(QPlatformSurface *) const; | |
mutable QHash<QIOSWindow *, FramebufferObject> m_framebufferObjects; | |
diff --git i/src/plugins/platforms/ios/qioscontext.mm w/src/plugins/platforms/ios/qioscontext.mm | |
index 1ea0403..ddee521 100644 | |
--- i/src/plugins/platforms/ios/qioscontext.mm | |
+++ w/src/plugins/platforms/ios/qioscontext.mm | |
@@ -140,17 +140,22 @@ void QIOSContext::swapBuffers(QPlatformSurface *surface) | |
if (surface->surface()->surfaceClass() == QSurface::Offscreen) | |
return; // Nothing to do | |
- Q_ASSERT(surface->surface()->surfaceClass() == QSurface::Window); | |
- QIOSWindow *window = static_cast<QIOSWindow *>(surface); | |
- Q_ASSERT(m_framebufferObjects.contains(window)); | |
+ FramebufferObject &framebufferObject = backingFramebufferObjectFor(surface); | |
[EAGLContext setCurrentContext:m_eaglContext]; | |
- glBindRenderbuffer(GL_RENDERBUFFER, m_framebufferObjects[window].colorRenderbuffer); | |
+ glBindRenderbuffer(GL_RENDERBUFFER, framebufferObject.colorRenderbuffer); | |
[m_eaglContext presentRenderbuffer:GL_RENDERBUFFER]; | |
} | |
QIOSContext::FramebufferObject &QIOSContext::backingFramebufferObjectFor(QPlatformSurface *surface) const | |
{ | |
+ // We keep track of default-FBOs in the root context of a share-group. This assumes | |
+ // that the contexts form a tree, where leaf nodes are always destroyed before their | |
+ // parents. If that assumption (based on the current implementation) doesn't hold we | |
+ // should probably use QOpenGLMultiGroupSharedResource to track the shared default-FBOs. | |
+ if (m_sharedContext) | |
+ return m_sharedContext->backingFramebufferObjectFor(surface); | |
+ | |
Q_ASSERT(surface && surface->surface()->surfaceClass() == QSurface::Window); | |
QIOSWindow *window = static_cast<QIOSWindow *>(surface); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment