void swapBuffers() { // If there is a xpixmap, we are on the reading side and do not want to swap any buffers. // The buffers are being switched on the writing side, the reading side just reads // whatever texture the XWindow contains. if (m_xPixmap) return; if (!m_surface->isVisible()) return; // Creating and exposing the surface is asynchronous. Therefore we have to wait here // before swapping the buffers. This should only be the case for the very first frame. while (!m_surface->isExposed()) QCoreApplication::processEvents(); QOpenGLContext* glContext = QOpenGLContext::currentContext(); if (m_surface && glContext) { GLint oldFBO; glGetIntegerv(GL_FRAMEBUFFER_BINDING, &oldFBO); pGlBindFramebuffer(GL_FRAMEBUFFER, glContext->defaultFramebufferObject()); glContext->swapBuffers(m_surface.get()); pGlBindFramebuffer(GL_FRAMEBUFFER, oldFBO); } }
void WebView::CreateGLContext() { QOpenGLContext* context = window_->GLContext(); context->makeCurrent(window_); static bool firstClearDone = false; if (!firstClearDone) { QOpenGLFunctions* functions = context->functions(); Q_ASSERT(functions); functions->glClearColor(1.0, 1.0, 1.0, 0.0); functions->glClear(GL_COLOR_BUFFER_BIT); context->swapBuffers(window_); firstClearDone = true; } }
void TestWindow::draw() { if (_aboutToQuit) { return; } // Attempting to draw before we're visible and have a valid size will // produce GL errors. if (!isVisible() || _size.width() <= 0 || _size.height() <= 0) { return; } static std::once_flag once; std::call_once(once, [&] { initGl(); }); if (!_glContext.makeCurrent(this)) { return; } updateSurfaces(); auto size = this->geometry().size(); auto incrementX = size.width() / DIVISIONS_X; auto incrementY = size.height() / DIVISIONS_Y; _glf.glViewport(0, 0, size.width(), size.height()); _glf.glClearColor(1, 0, 0, 1); _glf.glClear(GL_COLOR_BUFFER_BIT); for (uint32_t x = 0; x < DIVISIONS_X; ++x) { for (uint32_t y = 0; y < DIVISIONS_Y; ++y) { auto& qmlInfo = _surfaces[x][y]; if (!qmlInfo.surface || !qmlInfo.texture) { continue; } _glf.glBindFramebuffer(GL_READ_FRAMEBUFFER, _fbo); _glf.glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, qmlInfo.texture, 0); _glf.glBlitFramebuffer( // src coordinates 0, 0, _qmlSize.width() - 1, _qmlSize.height() - 1, // dst coordinates incrementX * x, incrementY * y, incrementX * (x + 1), incrementY * (y + 1), // blit mask and filter GL_COLOR_BUFFER_BIT, GL_NEAREST); } } _glf.glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0); _glf.glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); _glContext.swapBuffers(this); }
void OculusWin32DisplayPlugin::postRender() { _context->swapBuffers(_window); }
void tst_QGuiApplication::focusObject() { int argc = 0; QGuiApplication app(argc, 0); if (qApp->platformName().toLower() == QLatin1String("wayland")) QSKIP("Wayland: This fails. Figure out why."); QObject obj1, obj2, obj3; const QRect screenGeometry = QGuiApplication::primaryScreen()->availableVirtualGeometry(); DummyWindow window1; #if defined(Q_OS_QNX) window1.setSurfaceType(QSurface::OpenGLSurface); #endif window1.resize(windowSize, windowSize); window1.setTitle(QStringLiteral("focusObject:window1")); window1.setFramePosition(QPoint(screenGeometry.left() + spacing, screenGeometry.top() + spacing)); DummyWindow window2; window2.resize(windowSize, windowSize); window2.setFramePosition(QPoint(screenGeometry.left() + 2 * spacing + windowSize, screenGeometry.top() + spacing)); window2.setTitle(QStringLiteral("focusObject:window2")); window1.show(); #if defined(Q_OS_QNX) // We either need to create a eglSurface or a create a backing store // and then post the window in order for screen to show the window QOpenGLContext context; context.create(); context.makeCurrent(&window1); QTest::qWaitForWindowExposed(&window1); // Buffer swap only succeeds with exposed window context.swapBuffers(&window1); #endif QSignalSpy spy(&app, SIGNAL(focusObjectChanged(QObject*))); // verify active window focus propagates to qguiapplication window1.requestActivate(); QVERIFY(QTest::qWaitForWindowActive(&window1)); QCOMPARE(app.focusWindow(), &window1); window1.setFocusObject(&obj1); QCOMPARE(app.focusObject(), &obj1); QCOMPARE(spy.count(), 1); spy.clear(); window1.setFocusObject(&obj2); QCOMPARE(app.focusObject(), &obj2); QCOMPARE(spy.count(), 1); spy.clear(); window2.setFocusObject(&obj3); QCOMPARE(app.focusObject(), &obj2); // not yet changed window2.show(); QVERIFY(QTest::qWaitForWindowExposed(&window2)); QTRY_COMPARE(app.focusWindow(), &window2); QCOMPARE(app.focusObject(), &obj3); QCOMPARE(spy.count(), 1); // focus change on unfocused window does not show spy.clear(); window1.setFocusObject(&obj1); QCOMPARE(spy.count(), 0); QCOMPARE(app.focusObject(), &obj3); }