Qt 4.8
qeglplatformcontext.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qeglplatformcontext.h"
43 
44 
45 #include <QtGui/QPlatformWindow>
46 
47 #include "qeglconvenience.h"
48 
49 #include <EGL/egl.h>
50 
51 QEGLPlatformContext::QEGLPlatformContext(EGLDisplay display, EGLConfig config, EGLint contextAttrs[], EGLSurface surface, EGLenum eglApi, QEGLPlatformContext *shareContext)
53  , m_eglDisplay(display)
54  , m_eglSurface(surface)
55  , m_eglApi(eglApi)
56 {
57  if (m_eglSurface == EGL_NO_SURFACE) {
58  qWarning("Createing QEGLPlatformContext with no surface");
59  }
60 
61  eglBindAPI(m_eglApi);
62  EGLContext shareEglContext = shareContext ? shareContext->eglContext() : 0;
63  m_eglContext = eglCreateContext(m_eglDisplay,config, shareEglContext, contextAttrs);
64  if (m_eglContext == EGL_NO_CONTEXT) {
65  qWarning("Could not create the egl context\n");
66  eglTerminate(m_eglDisplay);
67  qFatal("EGL error");
68  }
69 
71 }
72 
74 {
75 #ifdef QEGL_EXTRA_DEBUG
76  qWarning("QEglContext::~QEglContext(): %p\n",this);
77 #endif
78  if (m_eglSurface != EGL_NO_SURFACE) {
79  doneCurrent();
80  eglDestroySurface(m_eglDisplay, m_eglSurface);
81  m_eglSurface = EGL_NO_SURFACE;
82  }
83 
84  if (m_eglContext != EGL_NO_CONTEXT) {
85  eglDestroyContext(m_eglDisplay, m_eglContext);
86  m_eglContext = EGL_NO_CONTEXT;
87  }
88 }
89 
91 {
93 #ifdef QEGL_EXTRA_DEBUG
94  qWarning("QEglContext::makeCurrent: %p\n",this);
95 #endif
96  eglBindAPI(m_eglApi);
97  bool ok = eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext);
98  if (!ok)
99  qWarning("QEGLPlatformContext::makeCurrent: eglError: %d, this: %p \n", eglGetError(), this);
100 #ifdef QEGL_EXTRA_DEBUG
101  static bool showDebug = true;
102  if (showDebug) {
103  showDebug = false;
104  const char *str = (const char*)glGetString(GL_VENDOR);
105  qWarning("Vendor %s\n", str);
106  str = (const char*)glGetString(GL_RENDERER);
107  qWarning("Renderer %s\n", str);
108  str = (const char*)glGetString(GL_VERSION);
109  qWarning("Version %s\n", str);
110 
111  str = (const char*)glGetString(GL_SHADING_LANGUAGE_VERSION);
112  qWarning("Extensions %s\n",str);
113 
114  str = (const char*)glGetString(GL_EXTENSIONS);
115  qWarning("Extensions %s\n", str);
116 
117  }
118 #endif
119 }
121 {
123 #ifdef QEGL_EXTRA_DEBUG
124  qWarning("QEglContext::doneCurrent:%p\n",this);
125 #endif
126  eglBindAPI(m_eglApi);
127  bool ok = eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
128  if (!ok)
129  qWarning("QEGLPlatformContext::doneCurrent(): eglError: %d, this: %p \n", eglGetError(), this);
130 }
132 {
133 #ifdef QEGL_EXTRA_DEBUG
134  qWarning("QEglContext::swapBuffers:%p\n",this);
135 #endif
136  eglBindAPI(m_eglApi);
137  bool ok = eglSwapBuffers(m_eglDisplay, m_eglSurface);
138  if (!ok)
139  qWarning("QEGLPlatformContext::swapBuffers(): eglError: %d, this: %p \n", eglGetError(), this);
140 }
142 {
143 #ifdef QEGL_EXTRA_DEBUG
144  qWarning("QEglContext::getProcAddress%p\n",this);
145 #endif
146  eglBindAPI(m_eglApi);
147  return (void *)eglGetProcAddress(qPrintable(procName));
148 }
149 
151 {
152  return m_windowFormat;
153 }
154 
156 {
157  return m_eglContext;
158 }
void makeCurrent()
Reimplement in subclass to do makeCurrent on native GL context.
void * getProcAddress(const QString &procName)
Reimplement in subclass to native getProcAddr calls.
QPlatformWindowFormat m_windowFormat
virtual void doneCurrent()
Reimplement in subclass to release current context.
EGLContext eglContext() const
The QPlatformWindowFormat class specifies the display format of an OpenGL rendering context and if po...
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define GL_VERSION
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
QEGLPlatformContext(EGLDisplay display, EGLConfig config, EGLint contextAttrs[], EGLSurface surface, EGLenum eglApi, QEGLPlatformContext *shareContext=0)
Q_CORE_EXPORT void qWarning(const char *,...)
unsigned int EGLenum
Definition: qegl_p.h:69
virtual void makeCurrent()
Reimplement in subclass to do makeCurrent on native GL context.
void swapBuffers()
Reimplement in subclass to native swap buffers calls.
#define GL_EXTENSIONS
Q_CORE_EXPORT void qFatal(const char *,...)
QPlatformWindowFormat platformWindowFormat() const
QWidget has the function qplatformWindowFormat().
The QPlatformGLContext class provides an abstraction for native GL contexts.
QPlatformWindowFormat qt_qPlatformWindowFormatFromConfig(EGLDisplay display, const EGLConfig config)
#define GL_VENDOR
#define GL_RENDERER
#define showDebug(f, iface)
#define qPrintable(string)
Definition: qglobal.h:1750
#define GL_SHADING_LANGUAGE_VERSION
void doneCurrent()
Reimplement in subclass to release current context.