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 ****************************************************************************/
46 #include "qxcbwindow.h"
47 #include "qxcbscreen.h"
50 #include <X11/Xutil.h>
53 #include <QtGui/QOpenGLContext>
55 #include "qglxintegration.h"
56 #include <QtPlatformSupport/private/qglxconvenience_p.h>
58 #if defined(Q_OS_LINUX) || defined(Q_OS_BSD4)
62 QGLXContext::QGLXContext(QXcbScreen *screen, const QSurfaceFormat &format, QPlatformOpenGLContext *share)
63 : QPlatformOpenGLContext()
67 GLXContext shareGlxContext = 0;
69 shareGlxContext = static_cast<const QGLXContext*>(share)->glxContext();
71 GLXFBConfig config = qglx_findConfig(DISPLAY_FROM_XCB(screen),screen->screenNumber(),format);
72 m_context = glXCreateNewContext(DISPLAY_FROM_XCB(screen), config, GLX_RGBA_TYPE, shareGlxContext, TRUE);
73 m_format = qglx_surfaceFormatFromGLXFBConfig(DISPLAY_FROM_XCB(screen), config, m_context);
76 QGLXContext::~QGLXContext()
78 glXDestroyContext(DISPLAY_FROM_XCB(m_screen), m_context);
81 bool QGLXContext::makeCurrent(QPlatformSurface *surface)
85 GLXDrawable glxDrawable = static_cast<QXcbWindow *>(surface)->xcb_window();
87 return glXMakeCurrent(DISPLAY_FROM_XCB(m_screen), glxDrawable, m_context);
90 void QGLXContext::doneCurrent()
92 glXMakeCurrent(DISPLAY_FROM_XCB(m_screen), 0, 0);
95 void QGLXContext::swapBuffers(QPlatformSurface *surface)
97 GLXDrawable glxDrawable = static_cast<QXcbWindow *>(surface)->xcb_window();
98 glXSwapBuffers(DISPLAY_FROM_XCB(m_screen), glxDrawable);
101 void (*QGLXContext::getProcAddress(const QByteArray &procName)) ()
103 typedef void *(*qt_glXGetProcAddressARB)(const GLubyte *);
104 static qt_glXGetProcAddressARB glXGetProcAddressARB = 0;
105 static bool resolved = false;
107 if (resolved && !glXGetProcAddressARB)
109 if (!glXGetProcAddressARB) {
110 QList<QByteArray> glxExt = QByteArray(glXGetClientString(DISPLAY_FROM_XCB(m_screen), GLX_EXTENSIONS)).split(' ');
111 if (glxExt.contains("GLX_ARB_get_proc_address")) {
112 #if defined(Q_OS_LINUX) || defined(Q_OS_BSD4)
113 void *handle = dlopen(NULL, RTLD_LAZY);
115 glXGetProcAddressARB = (qt_glXGetProcAddressARB) dlsym(handle, "glXGetProcAddressARB");
118 if (!glXGetProcAddressARB)
121 extern const QString qt_gl_library_name();
122 // QLibrary lib(qt_gl_library_name());
123 QLibrary lib(QLatin1String("GL"));
124 glXGetProcAddressARB = (qt_glXGetProcAddressARB) lib.resolve("glXGetProcAddressARB");
129 if (!glXGetProcAddressARB)
131 return (void (*)())glXGetProcAddressARB(reinterpret_cast<const GLubyte *>(procName.constData()));
134 QSurfaceFormat QGLXContext::format() const