1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the plugins of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "qeglplatformcontext_p.h"
44 #include "qeglconvenience_p.h"
46 #include <qpa/qplatformwindow.h>
50 static inline void bindApi(const QSurfaceFormat &format)
52 if (format.renderableType() == QSurfaceFormat::OpenVG)
53 eglBindAPI(EGL_OPENVG_API);
54 #ifdef EGL_VERSION_1_4
55 else if (format.renderableType() == QSurfaceFormat::OpenGL)
56 eglBindAPI(EGL_OPENGL_API);
59 eglBindAPI(EGL_OPENGL_ES_API);
62 QEGLPlatformContext::QEGLPlatformContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share, EGLDisplay display,
64 : m_eglDisplay(display)
66 , m_eglConfig(q_configFromGLFormat(display, format, true))
67 , m_format(q_glFormatFromConfig(display, m_eglConfig))
69 m_shareContext = share ? static_cast<QEGLPlatformContext *>(share)->m_eglContext : 0;
71 QVector<EGLint> contextAttrs;
72 contextAttrs.append(EGL_CONTEXT_CLIENT_VERSION);
73 contextAttrs.append(format.majorVersion());
74 contextAttrs.append(EGL_NONE);
77 m_eglContext = eglCreateContext(m_eglDisplay, m_eglConfig, m_shareContext, contextAttrs.constData());
78 if (m_eglContext == EGL_NO_CONTEXT && m_shareContext != EGL_NO_CONTEXT) {
80 m_eglContext = eglCreateContext(m_eglDisplay, m_eglConfig, 0, contextAttrs.constData());
84 bool QEGLPlatformContext::makeCurrent(QPlatformSurface *surface)
86 Q_ASSERT(surface->surface()->surfaceType() == QSurface::OpenGLSurface);
88 #ifdef QEGL_EXTRA_DEBUG
89 qWarning("QEglContext::makeCurrent: %p\n",this);
93 EGLSurface eglSurface = eglSurfaceForPlatformSurface(surface);
95 bool ok = eglMakeCurrent(m_eglDisplay, eglSurface, eglSurface, m_eglContext);
97 qWarning("QEGLPlatformContext::makeCurrent: eglError: %x, this: %p \n", eglGetError(), this);
98 #ifdef QEGL_EXTRA_DEBUG
99 static bool showDebug = true;
102 const char *str = (const char*)glGetString(GL_VENDOR);
103 qWarning("Vendor %s\n", str);
104 str = (const char*)glGetString(GL_RENDERER);
105 qWarning("Renderer %s\n", str);
106 str = (const char*)glGetString(GL_VERSION);
107 qWarning("Version %s\n", str);
109 str = (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION);
110 qWarning("Extensions %s\n",str);
112 str = (const char*)glGetString(GL_EXTENSIONS);
113 qWarning("Extensions %s\n", str);
120 QEGLPlatformContext::~QEGLPlatformContext()
122 #ifdef QEGL_EXTRA_DEBUG
123 qWarning("QEglContext::~QEglContext(): %p\n",this);
125 if (m_eglContext != EGL_NO_CONTEXT) {
126 eglDestroyContext(m_eglDisplay, m_eglContext);
127 m_eglContext = EGL_NO_CONTEXT;
131 void QEGLPlatformContext::doneCurrent()
133 #ifdef QEGL_EXTRA_DEBUG
134 qWarning("QEglContext::doneCurrent:%p\n",this);
137 bool ok = eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
139 qWarning("QEGLPlatformContext::doneCurrent(): eglError: %d, this: %p \n", eglGetError(), this);
142 void QEGLPlatformContext::swapBuffers(QPlatformSurface *surface)
144 #ifdef QEGL_EXTRA_DEBUG
145 qWarning("QEglContext::swapBuffers:%p\n",this);
148 EGLSurface eglSurface = eglSurfaceForPlatformSurface(surface);
149 bool ok = eglSwapBuffers(m_eglDisplay, eglSurface);
151 qWarning("QEGLPlatformContext::swapBuffers(): eglError: %d, this: %p \n", eglGetError(), this);
154 void (*QEGLPlatformContext::getProcAddress(const QByteArray &procName)) ()
156 #ifdef QEGL_EXTRA_DEBUG
157 qWarning("QEglContext::getProcAddress%p\n",this);
160 return eglGetProcAddress(procName.constData());
163 QSurfaceFormat QEGLPlatformContext::format() const
168 EGLContext QEGLPlatformContext::eglContext() const
173 EGLDisplay QEGLPlatformContext::eglDisplay() const
178 EGLConfig QEGLPlatformContext::eglConfig() const