示例#1
0
    GraphicsSurfacePrivate(const PlatformGraphicsContext3D shareContext = 0)
        : m_display(0)
        , m_xPixmap(0)
        , m_glxPixmap(0)
        , m_glContext(0)
        , m_detachedContext(0)
        , m_detachedSurface(0)
        , m_textureIsYInverted(false)
        , m_hasAlpha(false)
    {
        GLXContext shareContextObject = 0;
        m_display = XOpenDisplay(0);

#if PLATFORM(QT)
        if (shareContext) {
#if 0
            // This code path requires QXcbNativeInterface::nativeResourceForContext() which is not availble in Qt5 on the build bots yet.
            QPlatformNativeInterface* nativeInterface = QGuiApplication::platformNativeInterface();
            shareContextObject = static_cast<GLXContext>(nativeInterface->nativeResourceForContext(QByteArrayLiteral("glxcontext"), shareContext));
            if (!shareContextObject)
                return;
#else
            // This code path should be removed as soon as QXcbNativeInterface::nativeResourceForContext() can provide the GLXContext.
            QOpenGLContext* previousContext = QOpenGLContext::currentContext();
            QSurface* previousSurface = previousContext->surface();
            QSurface* currentSurface = shareContext->surface();
            shareContext->makeCurrent(currentSurface);

            shareContextObject = glXGetCurrentContext();

            previousContext->makeCurrent(previousSurface);
#endif
        }
#endif

        m_display = m_offScreenWindow.display();
        int attributes[] = {
            GLX_LEVEL, 0,
            GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
            GLX_RENDER_TYPE,   GLX_RGBA_BIT,
            GLX_RED_SIZE,      1,
            GLX_GREEN_SIZE,    1,
            GLX_BLUE_SIZE,     1,
            GLX_DOUBLEBUFFER,  True,
            None
        };

        int numReturned;
        m_fbConfigs = glXChooseFBConfig(m_display, DefaultScreen(m_display), attributes, &numReturned);
        // Create a GLX context for OpenGL rendering
        m_glContext = glXCreateNewContext(m_display, m_fbConfigs[0], GLX_RGBA_TYPE, shareContextObject, true);
    }
bool GraphicsContext3DPrivate::makeCurrentIfNeeded() const
{
    const QOpenGLContext* currentContext = QOpenGLContext::currentContext();
    if (currentContext == m_platformContext)
        return true;
    return m_platformContext->makeCurrent(m_surface);
}
示例#3
0
bool GraphicsContext3DPrivate::isOpenGLES() const
{
    if (m_platformContext)
        return m_platformContext->isOpenGLES();
#if USE(OPENGL_ES_2)
    return true;
#else
    return false;
#endif
}
示例#4
0
void GraphicsContext3DPrivate::blitMultisampleFramebufferAndRestoreContext()
{
    const QOpenGLContext* currentContext = QOpenGLContext::currentContext();
    QSurface* currentSurface = 0;
    if (currentContext && currentContext != m_platformContext) {
        currentSurface = currentContext->surface();
        m_platformContext->makeCurrent(m_surface);
    }

    if (m_context->m_attrs.antialias)
        blitMultisampleFramebuffer();

    // While the context is still bound, make sure all the Framebuffer content is in finished state.
    // This is necessary as we are doing our own double buffering instead of using a drawable that provides swapBuffers.
    glFinish();

    if (currentContext && currentContext != m_platformContext)
        const_cast<QOpenGLContext*>(currentContext)->makeCurrent(currentSurface);
}
示例#5
0
bool GraphicsContext3DPrivate::isValid() const
{
    if (!m_platformContext || !m_platformContext->isValid())
        return false;
    return m_platformContext->isOpenGLES() || m_platformContext->format().majorVersion() >= 2;
}