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 ****************************************************************************/
42 #include "qeglplatformcontext_p.h"
44 #include "qeglconvenience_p.h"
46 #include <QtGui/QPlatformWindow>
50 QEGLPlatformContext::QEGLPlatformContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share, EGLDisplay display,
52 : m_eglDisplay(display)
56 EGLConfig config = q_configFromGLFormat(display, format, true);
57 m_format = q_glFormatFromConfig(display, config);
59 m_shareContext = share ? static_cast<QEGLPlatformContext *>(share)->m_eglContext : 0;
61 QVector<EGLint> contextAttrs;
62 contextAttrs.append(EGL_CONTEXT_CLIENT_VERSION);
63 contextAttrs.append(format.majorVersion());
64 contextAttrs.append(EGL_NONE);
67 m_eglContext = eglCreateContext(m_eglDisplay, config, m_shareContext, contextAttrs.constData());
68 if (m_eglContext == EGL_NO_CONTEXT && m_shareContext != EGL_NO_CONTEXT) {
70 m_eglContext = eglCreateContext(m_eglDisplay, config, 0, contextAttrs.constData());
74 bool QEGLPlatformContext::makeCurrent(QPlatformSurface *surface)
76 #ifdef QEGL_EXTRA_DEBUG
77 qWarning("QEglContext::makeCurrent: %p\n",this);
81 EGLSurface eglSurface = eglSurfaceForPlatformSurface(surface);
83 bool ok = eglMakeCurrent(m_eglDisplay, eglSurface, eglSurface, m_eglContext);
85 qWarning("QEGLPlatformContext::makeCurrent: eglError: %x, this: %p \n", eglGetError(), this);
86 #ifdef QEGL_EXTRA_DEBUG
87 static bool showDebug = true;
90 const char *str = (const char*)glGetString(GL_VENDOR);
91 qWarning("Vendor %s\n", str);
92 str = (const char*)glGetString(GL_RENDERER);
93 qWarning("Renderer %s\n", str);
94 str = (const char*)glGetString(GL_VERSION);
95 qWarning("Version %s\n", str);
97 str = (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION);
98 qWarning("Extensions %s\n",str);
100 str = (const char*)glGetString(GL_EXTENSIONS);
101 qWarning("Extensions %s\n", str);
108 QEGLPlatformContext::~QEGLPlatformContext()
110 #ifdef QEGL_EXTRA_DEBUG
111 qWarning("QEglContext::~QEglContext(): %p\n",this);
113 if (m_eglContext != EGL_NO_CONTEXT) {
114 eglDestroyContext(m_eglDisplay, m_eglContext);
115 m_eglContext = EGL_NO_CONTEXT;
119 void QEGLPlatformContext::doneCurrent()
121 #ifdef QEGL_EXTRA_DEBUG
122 qWarning("QEglContext::doneCurrent:%p\n",this);
124 eglBindAPI(m_eglApi);
125 bool ok = eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
127 qWarning("QEGLPlatformContext::doneCurrent(): eglError: %d, this: %p \n", eglGetError(), this);
130 void QEGLPlatformContext::swapBuffers(QPlatformSurface *surface)
132 #ifdef QEGL_EXTRA_DEBUG
133 qWarning("QEglContext::swapBuffers:%p\n",this);
135 eglBindAPI(m_eglApi);
136 EGLSurface eglSurface = eglSurfaceForPlatformSurface(surface);
137 bool ok = eglSwapBuffers(m_eglDisplay, eglSurface);
139 qWarning("QEGLPlatformContext::swapBuffers(): eglError: %d, this: %p \n", eglGetError(), this);
142 void (*QEGLPlatformContext::getProcAddress(const QByteArray &procName)) ()
144 #ifdef QEGL_EXTRA_DEBUG
145 qWarning("QEglContext::getProcAddress%p\n",this);
147 eglBindAPI(m_eglApi);
148 return eglGetProcAddress(procName.constData());
151 QSurfaceFormat QEGLPlatformContext::format() const
156 EGLContext QEGLPlatformContext::eglContext() const