summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/eglconvenience
diff options
context:
space:
mode:
authorSamuel Rødal <samuel.rodal@nokia.com>2011-06-07 17:25:22 +0200
committerSamuel Rødal <samuel.rodal@nokia.com>2011-06-10 09:24:56 +0200
commit4a189c188ccd2fb5f8d1d5ddadf06cbd6bc0916f (patch)
tree99bff9f015e869b5521836ea5667590939b22a53 /src/plugins/platforms/eglconvenience
parent4d10e64f2a78e32418a98e1c80c6579ae0779dfc (diff)
QWindowContext / QWindowFormat refactor.
To enable having a single GL context used for multiple drawables we need to de-couple the context class a bit more from the window class in the plugin API. Now contexts are created stand-alone based on a GL format and a share context, and when calling makeCurrent() a desired surface is specified. This maps well to GLX, EGL, Cocoa, AGL, and WGL, which all support this use case. QWindowContext is renamed to QGuiGLContext, and QWindowFormat is renamed to QGuiGLFormat. We have the ability to introduce a pbuffer or similar other offscreen GL drawable abstraction in the future.
Diffstat (limited to 'src/plugins/platforms/eglconvenience')
-rw-r--r--src/plugins/platforms/eglconvenience/qeglconvenience.cpp12
-rw-r--r--src/plugins/platforms/eglconvenience/qeglconvenience.h8
-rw-r--r--src/plugins/platforms/eglconvenience/qeglplatformcontext.cpp79
-rw-r--r--src/plugins/platforms/eglconvenience/qeglplatformcontext.h32
4 files changed, 78 insertions, 53 deletions
diff --git a/src/plugins/platforms/eglconvenience/qeglconvenience.cpp b/src/plugins/platforms/eglconvenience/qeglconvenience.cpp
index 333425632c..2f686d6f76 100644
--- a/src/plugins/platforms/eglconvenience/qeglconvenience.cpp
+++ b/src/plugins/platforms/eglconvenience/qeglconvenience.cpp
@@ -39,11 +39,13 @@
**
****************************************************************************/
+#include <QByteArray>
+
#include "qeglconvenience.h"
QT_BEGIN_NAMESPACE
-QVector<EGLint> q_createConfigAttributesFromFormat(const QWindowFormat &format)
+QVector<EGLint> q_createConfigAttributesFromFormat(const QGuiGLFormat &format)
{
int redSize = format.redBufferSize();
int greenSize = format.greenBufferSize();
@@ -68,7 +70,7 @@ QVector<EGLint> q_createConfigAttributesFromFormat(const QWindowFormat &format)
// "AtLeast" for EGL_BUFFER_SIZE, it's sort order is "smaller" meaning 16-bit configs are
// put in the list before 32-bit configs. So, to make sure 16-bit is preffered over 32-bit,
// we must set the red/green/blue sizes to zero. This has an unfortunate consequence that
- // if the application sets the red/green/blue size to 5/6/5 on the QPlatformWindowFormat,
+ // if the application sets the red/green/blue size to 5/6/5 on the QGuiGLFormat,
// they will probably get a 32-bit config, even when there's an RGB565 config available.
// // Now normalize the values so -1 becomes 0
@@ -195,7 +197,7 @@ bool q_reduceConfigAttributes(QVector<EGLint> *configAttributes)
return false;
}
-EGLConfig q_configFromQWindowFormat(EGLDisplay display, const QWindowFormat &format, bool highestPixelFormat, int surfaceType)
+EGLConfig q_configFromGLFormat(EGLDisplay display, const QGuiGLFormat &format, bool highestPixelFormat, int surfaceType)
{
EGLConfig cfg = 0;
QVector<EGLint> configureAttributes = q_createConfigAttributesFromFormat(format);
@@ -257,9 +259,9 @@ EGLConfig q_configFromQWindowFormat(EGLDisplay display, const QWindowFormat &for
return 0;
}
-QWindowFormat q_windowFormatFromConfig(EGLDisplay display, const EGLConfig config)
+QGuiGLFormat q_glFormatFromConfig(EGLDisplay display, const EGLConfig config)
{
- QWindowFormat format;
+ QGuiGLFormat format;
EGLint redSize = 0;
EGLint greenSize = 0;
EGLint blueSize = 0;
diff --git a/src/plugins/platforms/eglconvenience/qeglconvenience.h b/src/plugins/platforms/eglconvenience/qeglconvenience.h
index 978cab4925..302aba318f 100644
--- a/src/plugins/platforms/eglconvenience/qeglconvenience.h
+++ b/src/plugins/platforms/eglconvenience/qeglconvenience.h
@@ -43,16 +43,16 @@
#define QEGLCONVENIENCE_H
-#include <QtGui/QWindowFormat>
+#include <QtGui/QGuiGLFormat>
#include <QtCore/QVector>
#include <EGL/egl.h>
QT_BEGIN_NAMESPACE
-QVector<EGLint> q_createConfigAttributesFromFormat(const QWindowFormat &format);
+QVector<EGLint> q_createConfigAttributesFromFormat(const QGuiGLFormat &format);
bool q_reduceConfigAttributes(QVector<EGLint> *configAttributes);
-EGLConfig q_configFromQWindowFormat(EGLDisplay display, const QWindowFormat &format, bool highestPixelFormat = false, int surfaceType = EGL_WINDOW_BIT);
-QWindowFormat q_windowFormatFromConfig(EGLDisplay display, const EGLConfig config);
+EGLConfig q_configFromGLFormat(EGLDisplay display, const QGuiGLFormat &format, bool highestPixelFormat = false, int surfaceType = EGL_WINDOW_BIT);
+QGuiGLFormat q_glFormatFromConfig(EGLDisplay display, const EGLConfig config);
bool q_hasEglExtension(EGLDisplay display,const char* extensionName);
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/eglconvenience/qeglplatformcontext.cpp b/src/plugins/platforms/eglconvenience/qeglplatformcontext.cpp
index db3666bb3e..c96e8ed67a 100644
--- a/src/plugins/platforms/eglconvenience/qeglplatformcontext.cpp
+++ b/src/plugins/platforms/eglconvenience/qeglplatformcontext.cpp
@@ -48,51 +48,47 @@
#include <EGL/egl.h>
-QEGLPlatformContext::QEGLPlatformContext(EGLDisplay display, EGLConfig config, EGLint contextAttrs[], EGLSurface surface, EGLenum eglApi)
- : QPlatformGLContext()
- , m_eglDisplay(display)
+QEGLSurface::QEGLSurface(EGLSurface surface, const QGuiGLFormat &format)
+ : QPlatformGLSurface(format)
, m_eglSurface(surface)
+{
+}
+
+QEGLPlatformContext::QEGLPlatformContext(const QGuiGLFormat &format, QPlatformGLContext *share, EGLDisplay display,
+ EGLint eglClientVersion, EGLenum eglApi)
+ : m_eglDisplay(display)
, m_eglApi(eglApi)
+ , m_format(format)
{
- if (m_eglSurface == EGL_NO_SURFACE) {
- qWarning("Createing QEGLPlatformContext with no surface");
- }
+ EGLConfig config = q_configFromGLFormat(display, format, true);
+ m_format = q_glFormatFromConfig(display, config);
+
+ EGLContext shareContext = share ? static_cast<QEGLPlatformContext *>(share)->m_eglContext : 0;
+
+ QVector<EGLint> contextAttrs;
+ contextAttrs.append(EGL_CONTEXT_CLIENT_VERSION);
+ contextAttrs.append(eglClientVersion);
+ contextAttrs.append(EGL_NONE);
eglBindAPI(m_eglApi);
- m_eglContext = eglCreateContext(m_eglDisplay,config, 0,contextAttrs);
+ m_eglContext = eglCreateContext(m_eglDisplay, config, shareContext, contextAttrs.constData());
if (m_eglContext == EGL_NO_CONTEXT) {
qWarning("Could not create the egl context\n");
eglTerminate(m_eglDisplay);
qFatal("EGL error");
}
-
- m_windowFormat = q_windowFormatFromConfig(display,config);
-}
-
-QEGLPlatformContext::~QEGLPlatformContext()
-{
-#ifdef QEGL_EXTRA_DEBUG
- qWarning("QEglContext::~QEglContext(): %p\n",this);
-#endif
- if (m_eglSurface != EGL_NO_SURFACE) {
- doneCurrent();
- eglDestroySurface(m_eglDisplay, m_eglSurface);
- m_eglSurface = EGL_NO_SURFACE;
- }
-
- if (m_eglContext != EGL_NO_CONTEXT) {
- eglDestroyContext(m_eglDisplay, m_eglContext);
- m_eglContext = EGL_NO_CONTEXT;
- }
}
-void QEGLPlatformContext::makeCurrent()
+bool QEGLPlatformContext::makeCurrent(const QPlatformGLSurface &surface)
{
#ifdef QEGL_EXTRA_DEBUG
qWarning("QEglContext::makeCurrent: %p\n",this);
#endif
eglBindAPI(m_eglApi);
- bool ok = eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext);
+
+ EGLSurface eglSurface = static_cast<const QEGLSurface &>(surface).eglSurface();
+
+ bool ok = eglMakeCurrent(m_eglDisplay, eglSurface, eglSurface, m_eglContext);
if (!ok)
qWarning("QEGLPlatformContext::makeCurrent: eglError: %d, this: %p \n", eglGetError(), this);
#ifdef QEGL_EXTRA_DEBUG
@@ -114,7 +110,20 @@ void QEGLPlatformContext::makeCurrent()
}
#endif
+ return ok;
+}
+
+QEGLPlatformContext::~QEGLPlatformContext()
+{
+#ifdef QEGL_EXTRA_DEBUG
+ qWarning("QEglContext::~QEglContext(): %p\n",this);
+#endif
+ if (m_eglContext != EGL_NO_CONTEXT) {
+ eglDestroyContext(m_eglDisplay, m_eglContext);
+ m_eglContext = EGL_NO_CONTEXT;
+ }
}
+
void QEGLPlatformContext::doneCurrent()
{
#ifdef QEGL_EXTRA_DEBUG
@@ -125,28 +134,30 @@ void QEGLPlatformContext::doneCurrent()
if (!ok)
qWarning("QEGLPlatformContext::doneCurrent(): eglError: %d, this: %p \n", eglGetError(), this);
}
-void QEGLPlatformContext::swapBuffers()
+
+void QEGLPlatformContext::swapBuffers(const QPlatformGLSurface &surface)
{
#ifdef QEGL_EXTRA_DEBUG
qWarning("QEglContext::swapBuffers:%p\n",this);
#endif
eglBindAPI(m_eglApi);
- bool ok = eglSwapBuffers(m_eglDisplay, m_eglSurface);
+ bool ok = eglSwapBuffers(m_eglDisplay, static_cast<const QEGLSurface &>(surface).eglSurface());
if (!ok)
qWarning("QEGLPlatformContext::swapBuffers(): eglError: %d, this: %p \n", eglGetError(), this);
}
-void* QEGLPlatformContext::getProcAddress(const QString& procName)
+
+void (*QEGLPlatformContext::getProcAddress(const QByteArray &procName)) ()
{
#ifdef QEGL_EXTRA_DEBUG
qWarning("QEglContext::getProcAddress%p\n",this);
#endif
eglBindAPI(m_eglApi);
- return (void *)eglGetProcAddress(qPrintable(procName));
+ return eglGetProcAddress(procName.constData());
}
-QWindowFormat QEGLPlatformContext::windowFormat() const
+QGuiGLFormat QEGLPlatformContext::format() const
{
- return m_windowFormat;
+ return m_format;
}
EGLContext QEGLPlatformContext::eglContext() const
diff --git a/src/plugins/platforms/eglconvenience/qeglplatformcontext.h b/src/plugins/platforms/eglconvenience/qeglplatformcontext.h
index 531f553f3b..9877b77e4e 100644
--- a/src/plugins/platforms/eglconvenience/qeglplatformcontext.h
+++ b/src/plugins/platforms/eglconvenience/qeglplatformcontext.h
@@ -39,33 +39,45 @@
**
****************************************************************************/
-#ifndef QOPENKODEGLINTEGRATION_H
-#define QOPENKODEGLINTEGRATION_H
+#ifndef QEGLPLATFORMCONTEXT_H
+#define QEGLPLATFORMCONTEXT_H
#include <QtGui/QPlatformGLContext>
#include <EGL/egl.h>
+class QEGLSurface : public QPlatformGLSurface
+{
+public:
+ QEGLSurface(EGLSurface surface, const QGuiGLFormat &format);
+
+ virtual EGLSurface eglSurface() const { return m_eglSurface; }
+
+private:
+ EGLSurface m_eglSurface;
+};
+
class QEGLPlatformContext : public QPlatformGLContext
{
public:
- QEGLPlatformContext(EGLDisplay display, EGLConfig config, EGLint contextAttrs[], EGLSurface surface, EGLenum eglApi);
+ QEGLPlatformContext(const QGuiGLFormat &format, QPlatformGLContext *share, EGLDisplay display,
+ EGLint eglClientVersion = 2, EGLenum eglApi = EGL_OPENGL_ES_API);
~QEGLPlatformContext();
- void makeCurrent();
+ bool makeCurrent(const QPlatformGLSurface &surface);
void doneCurrent();
- void swapBuffers();
- void* getProcAddress(const QString& procName);
+ void swapBuffers(const QPlatformGLSurface &surface);
+ void (*getProcAddress(const QByteArray &procName)) ();
- QWindowFormat windowFormat() const;
+ QGuiGLFormat format() const;
EGLContext eglContext() const;
+
private:
EGLContext m_eglContext;
EGLDisplay m_eglDisplay;
- EGLSurface m_eglSurface;
EGLenum m_eglApi;
- QWindowFormat m_windowFormat;
+ QGuiGLFormat m_format;
};
-#endif //QOPENKODEGLINTEGRATION_H
+#endif //QEGLPLATFORMCONTEXT_H