summaryrefslogtreecommitdiffstats
path: root/src/platformsupport
diff options
context:
space:
mode:
Diffstat (limited to 'src/platformsupport')
-rw-r--r--src/platformsupport/eglconvenience/qeglconvenience.cpp115
-rw-r--r--src/platformsupport/eglconvenience/qeglconvenience_p.h35
-rw-r--r--src/platformsupport/eglconvenience/qeglplatformcontext.cpp16
-rw-r--r--src/platformsupport/eglconvenience/qeglplatformcontext_p.h6
4 files changed, 128 insertions, 44 deletions
diff --git a/src/platformsupport/eglconvenience/qeglconvenience.cpp b/src/platformsupport/eglconvenience/qeglconvenience.cpp
index a88025a24d..c9f3e89272 100644
--- a/src/platformsupport/eglconvenience/qeglconvenience.cpp
+++ b/src/platformsupport/eglconvenience/qeglconvenience.cpp
@@ -210,75 +210,106 @@ bool q_reduceConfigAttributes(QVector<EGLint> *configAttributes)
return false;
}
-EGLConfig q_configFromGLFormat(EGLDisplay display, const QSurfaceFormat &format, bool highestPixelFormat, int surfaceType)
+QEglConfigChooser::QEglConfigChooser(EGLDisplay display)
+ : m_display(display)
+ , m_surfaceType(EGL_WINDOW_BIT)
+ , m_ignore(false)
+ , m_confAttrRed(0)
+ , m_confAttrGreen(0)
+ , m_confAttrBlue(0)
+ , m_confAttrAlpha(0)
+{
+}
+
+QEglConfigChooser::~QEglConfigChooser()
{
- EGLConfig cfg = 0;
- QVector<EGLint> configureAttributes = q_createConfigAttributesFromFormat(format);
+}
+
+EGLConfig QEglConfigChooser::chooseConfig()
+{
+ QVector<EGLint> configureAttributes = q_createConfigAttributesFromFormat(m_format);
configureAttributes.append(EGL_SURFACE_TYPE);
- configureAttributes.append(surfaceType);
+ configureAttributes.append(surfaceType());
configureAttributes.append(EGL_RENDERABLE_TYPE);
- if (format.renderableType() == QSurfaceFormat::OpenVG)
+ if (m_format.renderableType() == QSurfaceFormat::OpenVG)
configureAttributes.append(EGL_OPENVG_BIT);
#ifdef EGL_VERSION_1_4
- else if (format.renderableType() == QSurfaceFormat::OpenGL)
+ else if (m_format.renderableType() == QSurfaceFormat::OpenGL)
configureAttributes.append(EGL_OPENGL_BIT);
#endif
- else if (format.majorVersion() == 1)
+ else if (m_format.majorVersion() == 1)
configureAttributes.append(EGL_OPENGL_ES_BIT);
else
configureAttributes.append(EGL_OPENGL_ES2_BIT);
configureAttributes.append(EGL_NONE);
+ EGLConfig cfg;
do {
// Get the number of matching configurations for this set of properties.
EGLint matching = 0;
- if (!eglChooseConfig(display, configureAttributes.constData(), 0, 0, &matching) || !matching)
+ if (!eglChooseConfig(display(), configureAttributes.constData(), 0, 0, &matching) || !matching)
continue;
- // If we want the best pixel format, then return the first
- // matching configuration.
- if (highestPixelFormat) {
- eglChooseConfig(display, configureAttributes.constData(), &cfg, 1, &matching);
- if (matching < 1)
- continue;
- return cfg;
- }
-
// Fetch all of the matching configurations and find the
// first that matches the pixel format we wanted.
int i = configureAttributes.indexOf(EGL_RED_SIZE);
- int confAttrRed = configureAttributes.at(i+1);
+ m_confAttrRed = configureAttributes.at(i+1);
i = configureAttributes.indexOf(EGL_GREEN_SIZE);
- int confAttrGreen = configureAttributes.at(i+1);
+ m_confAttrGreen = configureAttributes.at(i+1);
i = configureAttributes.indexOf(EGL_BLUE_SIZE);
- int confAttrBlue = configureAttributes.at(i+1);
+ m_confAttrBlue = configureAttributes.at(i+1);
i = configureAttributes.indexOf(EGL_ALPHA_SIZE);
- int confAttrAlpha = i == -1 ? 0 : configureAttributes.at(i+1);
-
- EGLint size = matching;
- EGLConfig *configs = new EGLConfig [size];
- eglChooseConfig(display, configureAttributes.constData(), configs, size, &matching);
- for (EGLint index = 0; index < size; ++index) {
- EGLint red, green, blue, alpha;
- eglGetConfigAttrib(display, configs[index], EGL_RED_SIZE, &red);
- eglGetConfigAttrib(display, configs[index], EGL_GREEN_SIZE, &green);
- eglGetConfigAttrib(display, configs[index], EGL_BLUE_SIZE, &blue);
- eglGetConfigAttrib(display, configs[index], EGL_ALPHA_SIZE, &alpha);
- if ((confAttrRed == 0 || red == confAttrRed) &&
- (confAttrGreen == 0 || green == confAttrGreen) &&
- (confAttrBlue == 0 || blue == confAttrBlue) &&
- (confAttrAlpha == 0 || alpha == confAttrAlpha)) {
- cfg = configs[index];
- delete [] configs;
- return cfg;
- }
+ m_confAttrAlpha = i == -1 ? 0 : configureAttributes.at(i+1);
+
+ QVector<EGLConfig> configs(matching);
+ eglChooseConfig(display(), configureAttributes.constData(), configs.data(), configs.size(), &matching);
+ if (!cfg && matching > 0)
+ cfg = configs.first();
+
+ for (int i = 0; i < configs.size(); ++i) {
+ if (filterConfig(configs[i]))
+ return configs.at(i);
}
- delete [] configs;
} while (q_reduceConfigAttributes(&configureAttributes));
- qWarning("Cant find EGLConfig, returning null config");
- return 0;
+
+ if (!cfg)
+ qWarning("Cant find EGLConfig, returning null config");
+ return cfg;
+}
+
+bool QEglConfigChooser::filterConfig(EGLConfig config) const
+{
+ if (m_ignore)
+ return true;
+
+ EGLint red = 0;
+ EGLint green = 0;
+ EGLint blue = 0;
+ EGLint alpha = 0;
+
+ if (m_confAttrRed)
+ eglGetConfigAttrib(display(), config, EGL_RED_SIZE, &red);
+ if (m_confAttrGreen)
+ eglGetConfigAttrib(display(), config, EGL_GREEN_SIZE, &green);
+ if (m_confAttrBlue)
+ eglGetConfigAttrib(display(), config, EGL_BLUE_SIZE, &blue);
+ if (m_confAttrAlpha)
+ eglGetConfigAttrib(display(), config, EGL_ALPHA_SIZE, &alpha);
+
+ return red == m_confAttrRed && green == m_confAttrGreen
+ && blue == m_confAttrBlue && alpha == m_confAttrAlpha;
+}
+
+EGLConfig q_configFromGLFormat(EGLDisplay display, const QSurfaceFormat &format, bool highestPixelFormat, int surfaceType)
+{
+ QEglConfigChooser chooser(display);
+ chooser.setSurfaceFormat(format);
+ chooser.setSurfaceType(surfaceType);
+ chooser.setIgnoreColorChannels(highestPixelFormat);
+
+ return chooser.chooseConfig();
}
QSurfaceFormat q_glFormatFromConfig(EGLDisplay display, const EGLConfig config, const QSurfaceFormat &referenceFormat)
diff --git a/src/platformsupport/eglconvenience/qeglconvenience_p.h b/src/platformsupport/eglconvenience/qeglconvenience_p.h
index 5dd132edd3..3efd3991b9 100644
--- a/src/platformsupport/eglconvenience/qeglconvenience_p.h
+++ b/src/platformsupport/eglconvenience/qeglconvenience_p.h
@@ -56,6 +56,41 @@ QSurfaceFormat q_glFormatFromConfig(EGLDisplay display, const EGLConfig config,
bool q_hasEglExtension(EGLDisplay display,const char* extensionName);
void q_printEglConfig(EGLDisplay display, EGLConfig config);
+class QEglConfigChooser
+{
+public:
+ QEglConfigChooser(EGLDisplay display);
+ virtual ~QEglConfigChooser();
+
+ EGLDisplay display() const { return m_display; }
+
+ void setSurfaceType(EGLint surfaceType) { m_surfaceType = surfaceType; }
+ EGLint surfaceType() const { return m_surfaceType; }
+
+ void setSurfaceFormat(const QSurfaceFormat &format) { m_format = format; }
+ QSurfaceFormat surfaceFormat() const { return m_format; }
+
+ void setIgnoreColorChannels(bool ignore) { m_ignore = ignore; }
+ bool ignoreColorChannels() const { return m_ignore; }
+
+ EGLConfig chooseConfig();
+
+protected:
+ virtual bool filterConfig(EGLConfig config) const;
+
+private:
+ QSurfaceFormat m_format;
+ EGLDisplay m_display;
+ EGLint m_surfaceType;
+ bool m_ignore;
+
+ int m_confAttrRed;
+ int m_confAttrGreen;
+ int m_confAttrBlue;
+ int m_confAttrAlpha;
+};
+
+
QT_END_NAMESPACE
#endif //QEGLCONVENIENCE_H
diff --git a/src/platformsupport/eglconvenience/qeglplatformcontext.cpp b/src/platformsupport/eglconvenience/qeglplatformcontext.cpp
index 78dc1f7e9b..0b11d96e5c 100644
--- a/src/platformsupport/eglconvenience/qeglplatformcontext.cpp
+++ b/src/platformsupport/eglconvenience/qeglplatformcontext.cpp
@@ -64,8 +64,22 @@ QEGLPlatformContext::QEGLPlatformContext(const QSurfaceFormat &format, QPlatform
: m_eglDisplay(display)
, m_eglApi(eglApi)
, m_eglConfig(q_configFromGLFormat(display, format, true))
- , m_format(q_glFormatFromConfig(display, m_eglConfig))
{
+ init(format, share);
+}
+
+QEGLPlatformContext::QEGLPlatformContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share, EGLDisplay display,
+ EGLConfig config, EGLenum eglApi)
+ : m_eglDisplay(display)
+ , m_eglApi(eglApi)
+ , m_eglConfig(config)
+{
+ init(format, share);
+}
+
+void QEGLPlatformContext::init(const QSurfaceFormat &format, QPlatformOpenGLContext *share)
+{
+ m_format = q_glFormatFromConfig(m_eglDisplay, m_eglConfig);
m_shareContext = share ? static_cast<QEGLPlatformContext *>(share)->m_eglContext : 0;
QVector<EGLint> contextAttrs;
diff --git a/src/platformsupport/eglconvenience/qeglplatformcontext_p.h b/src/platformsupport/eglconvenience/qeglplatformcontext_p.h
index 0fcf9d47c6..c7918516db 100644
--- a/src/platformsupport/eglconvenience/qeglplatformcontext_p.h
+++ b/src/platformsupport/eglconvenience/qeglplatformcontext_p.h
@@ -51,6 +51,8 @@ class QEGLPlatformContext : public QPlatformOpenGLContext
public:
QEGLPlatformContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share, EGLDisplay display,
EGLenum eglApi = EGL_OPENGL_ES_API);
+ QEGLPlatformContext(const QSurfaceFormat &format, QPlatformOpenGLContext *share, EGLDisplay display,
+ EGLConfig config, EGLenum eglApi = EGL_OPENGL_ES_API);
~QEGLPlatformContext();
bool makeCurrent(QPlatformSurface *surface);
@@ -70,12 +72,14 @@ protected:
virtual EGLSurface eglSurfaceForPlatformSurface(QPlatformSurface *surface) = 0;
private:
+ void init(const QSurfaceFormat &format, QPlatformOpenGLContext *share);
+
EGLContext m_eglContext;
EGLContext m_shareContext;
EGLDisplay m_eglDisplay;
EGLenum m_eglApi;
EGLConfig m_eglConfig;
- const QSurfaceFormat m_format;
+ QSurfaceFormat m_format;
};
#endif //QEGLPLATFORMCONTEXT_H