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); } }
/*! \fn bool QOpenGLFramebufferObject::bindDefault() Switches rendering back to the default, windowing system provided framebuffer. Returns \c true upon success, false otherwise. \sa bind(), release() */ bool QOpenGLFramebufferObject::bindDefault() { QOpenGLContext *ctx = const_cast<QOpenGLContext *>(QOpenGLContext::currentContext()); QOpenGLFunctions functions(ctx); if (ctx) { ctx->d_func()->current_fbo = ctx->defaultFramebufferObject(); functions.glBindFramebuffer(GL_FRAMEBUFFER, ctx->d_func()->current_fbo); #ifdef QT_DEBUG } else { qWarning("QOpenGLFramebufferObject::bindDefault() called without current context."); #endif } return ctx != 0; }
/*! \fn bool QOpenGLFramebufferObject::release() Switches rendering back to the default, windowing system provided framebuffer. Returns \c true upon success, false otherwise. \sa bind() */ bool QOpenGLFramebufferObject::release() { if (!isValid()) return false; QOpenGLContext *current = QOpenGLContext::currentContext(); if (!current) return false; Q_D(QOpenGLFramebufferObject); #ifdef QT_DEBUG if (current->shareGroup() != d->fbo_guard->group()) qWarning("QOpenGLFramebufferObject::release() called from incompatible context"); #endif if (current) { current->d_func()->current_fbo = current->defaultFramebufferObject(); d->funcs.glBindFramebuffer(GL_FRAMEBUFFER, current->d_func()->current_fbo); } return true; }