1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the plugins of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
45 #include "qxcbwindow.h"
46 #include "qxcbscreen.h"
49 #include <X11/Xutil.h>
52 #include <QtGui/QOpenGLContext>
54 #include "qglxintegration.h"
55 #include <QtPlatformSupport/private/qglxconvenience_p.h>
57 #if defined(Q_OS_LINUX) || defined(Q_OS_BSD4)
61 QGLXContext::QGLXContext(QXcbScreen *screen, const QSurfaceFormat &format, QPlatformOpenGLContext *share)
62 : QPlatformOpenGLContext()
66 GLXContext shareGlxContext = 0;
68 shareGlxContext = static_cast<const QGLXContext*>(share)->glxContext();
70 GLXFBConfig config = qglx_findConfig(DISPLAY_FROM_XCB(screen),screen->screenNumber(),format);
71 m_context = glXCreateNewContext(DISPLAY_FROM_XCB(screen), config, GLX_RGBA_TYPE, shareGlxContext, TRUE);
72 m_format = qglx_surfaceFormatFromGLXFBConfig(DISPLAY_FROM_XCB(screen), config, m_context);
75 QGLXContext::~QGLXContext()
77 glXDestroyContext(DISPLAY_FROM_XCB(m_screen), m_context);
80 bool QGLXContext::makeCurrent(QPlatformSurface *surface)
84 GLXDrawable glxDrawable = static_cast<QXcbWindow *>(surface)->xcb_window();
86 return glXMakeCurrent(DISPLAY_FROM_XCB(m_screen), glxDrawable, m_context);
89 void QGLXContext::doneCurrent()
91 glXMakeCurrent(DISPLAY_FROM_XCB(m_screen), 0, 0);
94 void QGLXContext::swapBuffers(QPlatformSurface *surface)
96 GLXDrawable glxDrawable = static_cast<QXcbWindow *>(surface)->xcb_window();
97 glXSwapBuffers(DISPLAY_FROM_XCB(m_screen), glxDrawable);
100 void (*QGLXContext::getProcAddress(const QByteArray &procName)) ()
102 typedef void *(*qt_glXGetProcAddressARB)(const GLubyte *);
103 static qt_glXGetProcAddressARB glXGetProcAddressARB = 0;
104 static bool resolved = false;
106 if (resolved && !glXGetProcAddressARB)
108 if (!glXGetProcAddressARB) {
109 QList<QByteArray> glxExt = QByteArray(glXGetClientString(DISPLAY_FROM_XCB(m_screen), GLX_EXTENSIONS)).split(' ');
110 if (glxExt.contains("GLX_ARB_get_proc_address")) {
111 #if defined(Q_OS_LINUX) || defined(Q_OS_BSD4)
112 void *handle = dlopen(NULL, RTLD_LAZY);
114 glXGetProcAddressARB = (qt_glXGetProcAddressARB) dlsym(handle, "glXGetProcAddressARB");
117 if (!glXGetProcAddressARB)
120 extern const QString qt_gl_library_name();
121 // QLibrary lib(qt_gl_library_name());
122 QLibrary lib(QLatin1String("GL"));
123 glXGetProcAddressARB = (qt_glXGetProcAddressARB) lib.resolve("glXGetProcAddressARB");
128 if (!glXGetProcAddressARB)
130 return (void (*)())glXGetProcAddressARB(reinterpret_cast<const GLubyte *>(procName.constData()));
133 QSurfaceFormat QGLXContext::format() const