[plugins/qpa] Runtime depend on OpenGLES instead of compile time
Using QOpenGLContext::openGLModuleType() to determine whether we need a GLES or GL context.
This commit is contained in:
parent
4f64b32aba
commit
2f065b9c6b
1 changed files with 36 additions and 45 deletions
|
@ -26,6 +26,11 @@ namespace KWin
|
|||
namespace QPA
|
||||
{
|
||||
|
||||
static bool isOpenGLES()
|
||||
{
|
||||
return QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGLES;
|
||||
}
|
||||
|
||||
static EGLConfig configFromGLFormat(EGLDisplay dpy, const QSurfaceFormat &format)
|
||||
{
|
||||
#define SIZE( __buffer__ ) format.__buffer__##BufferSize() > 0 ? format.__buffer__##BufferSize() : 0
|
||||
|
@ -38,11 +43,7 @@ static EGLConfig configFromGLFormat(EGLDisplay dpy, const QSurfaceFormat &format
|
|||
EGL_ALPHA_SIZE, SIZE(alpha),
|
||||
EGL_DEPTH_SIZE, SIZE(depth),
|
||||
EGL_STENCIL_SIZE, SIZE(stencil),
|
||||
#ifdef KWIN_HAVE_OPENGLES
|
||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
||||
#else
|
||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
|
||||
#endif
|
||||
EGL_RENDERABLE_TYPE, isOpenGLES() ? EGL_OPENGL_ES2_BIT : EGL_OPENGL_BIT,
|
||||
EGL_NONE,
|
||||
};
|
||||
#undef SIZE
|
||||
|
@ -79,11 +80,7 @@ static QSurfaceFormat formatFromConfig(EGLDisplay dpy, EGLConfig config)
|
|||
#undef BUFFER_HELPER
|
||||
HELPER(SAMPLES, Samples)
|
||||
#undef HELPER
|
||||
#ifdef KWIN_HAVE_OPENGLES
|
||||
format.setRenderableType(QSurfaceFormat::OpenGLES);
|
||||
#else
|
||||
format.setRenderableType(QSurfaceFormat::OpenGL);
|
||||
#endif
|
||||
format.setRenderableType(isOpenGLES() ? QSurfaceFormat::OpenGLES : QSurfaceFormat::OpenGL);
|
||||
format.setStereo(false);
|
||||
|
||||
return format;
|
||||
|
@ -127,55 +124,49 @@ bool AbstractPlatformContext::isValid() const
|
|||
|
||||
bool AbstractPlatformContext::bindApi()
|
||||
{
|
||||
#ifdef KWIN_HAVE_OPENGLES
|
||||
if (eglBindAPI(EGL_OPENGL_ES_API) == EGL_FALSE) {
|
||||
if (eglBindAPI(isOpenGLES() ? EGL_OPENGL_ES_API : EGL_OPENGL_API) == EGL_FALSE) {
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
if (eglBindAPI(EGL_OPENGL_API) == EGL_FALSE) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
void AbstractPlatformContext::createContext(EGLContext shareContext)
|
||||
{
|
||||
EGLContext context = EGL_NO_CONTEXT;
|
||||
#ifdef KWIN_HAVE_OPENGLES
|
||||
const EGLint context_attribs[] = {
|
||||
EGL_CONTEXT_CLIENT_VERSION, 2,
|
||||
EGL_NONE
|
||||
};
|
||||
if (isOpenGLES()) {
|
||||
const EGLint context_attribs[] = {
|
||||
EGL_CONTEXT_CLIENT_VERSION, 2,
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
context = eglCreateContext(eglDisplay(), config(), shareContext, context_attribs);
|
||||
#else
|
||||
const EGLint context_attribs_31_core[] = {
|
||||
EGL_CONTEXT_MAJOR_VERSION_KHR, m_format.majorVersion(),
|
||||
EGL_CONTEXT_MINOR_VERSION_KHR, m_format.minorVersion(),
|
||||
EGL_CONTEXT_FLAGS_KHR, EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR,
|
||||
EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR, m_format.profile() == QSurfaceFormat::CoreProfile ? EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR : EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR,
|
||||
EGL_NONE
|
||||
};
|
||||
context = eglCreateContext(eglDisplay(), config(), shareContext, context_attribs);
|
||||
} else {
|
||||
const EGLint context_attribs_31_core[] = {
|
||||
EGL_CONTEXT_MAJOR_VERSION_KHR, m_format.majorVersion(),
|
||||
EGL_CONTEXT_MINOR_VERSION_KHR, m_format.minorVersion(),
|
||||
EGL_CONTEXT_FLAGS_KHR, EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR,
|
||||
EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR, m_format.profile() == QSurfaceFormat::CoreProfile ? EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR : EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR,
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
const EGLint context_attribs_legacy[] = {
|
||||
EGL_CONTEXT_CLIENT_VERSION, 2,
|
||||
EGL_NONE
|
||||
};
|
||||
const EGLint context_attribs_legacy[] = {
|
||||
EGL_CONTEXT_CLIENT_VERSION, 2,
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
const char* eglExtensionsCString = eglQueryString(eglDisplay(), EGL_EXTENSIONS);
|
||||
const QList<QByteArray> extensions = QByteArray::fromRawData(eglExtensionsCString, qstrlen(eglExtensionsCString)).split(' ');
|
||||
const char* eglExtensionsCString = eglQueryString(eglDisplay(), EGL_EXTENSIONS);
|
||||
const QList<QByteArray> extensions = QByteArray::fromRawData(eglExtensionsCString, qstrlen(eglExtensionsCString)).split(' ');
|
||||
|
||||
// Try to create a 3.1 core context
|
||||
if (m_format.majorVersion() >= 3 && extensions.contains(QByteArrayLiteral("EGL_KHR_create_context"))) {
|
||||
context = eglCreateContext(eglDisplay(), config(), shareContext, context_attribs_31_core);
|
||||
// Try to create a 3.1 core context
|
||||
if (m_format.majorVersion() >= 3 && extensions.contains(QByteArrayLiteral("EGL_KHR_create_context"))) {
|
||||
context = eglCreateContext(eglDisplay(), config(), shareContext, context_attribs_31_core);
|
||||
}
|
||||
|
||||
if (context == EGL_NO_CONTEXT) {
|
||||
context = eglCreateContext(eglDisplay(), config(), shareContext, context_attribs_legacy);
|
||||
}
|
||||
}
|
||||
|
||||
if (context == EGL_NO_CONTEXT) {
|
||||
context = eglCreateContext(eglDisplay(), config(), shareContext, context_attribs_legacy);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (context == EGL_NO_CONTEXT) {
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue