From ad38ff230b00fdd35dd7eaab79c26f160092af23 Mon Sep 17 00:00:00 2001 From: Bruno de Oliveira Abinader Date: Fri, 11 Nov 2016 16:37:44 +0200 Subject: [linux] Ensure EGL uses OpenGL ES 2.0 client API --- platform/linux/src/headless_backend_egl.cpp | 15 ++++++++++----- platform/linux/src/headless_display_egl.cpp | 6 ++++++ test/util/offscreen_texture.test.cpp | 12 ++++++++++++ 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/platform/linux/src/headless_backend_egl.cpp b/platform/linux/src/headless_backend_egl.cpp index 5c68976ada..0fb33ea0e0 100644 --- a/platform/linux/src/headless_backend_egl.cpp +++ b/platform/linux/src/headless_backend_egl.cpp @@ -58,11 +58,16 @@ void HeadlessBackend::createContext() { EGLDisplay display_ = display->attribute(); EGLConfig& config = display->attribute(); - if (!eglBindAPI(EGL_OPENGL_API)) { - throw std::runtime_error("Error setting the EGL rendering API.\n"); - } - - EGLContext glContext = eglCreateContext(display_, config, EGL_NO_CONTEXT, NULL); + // EGL initializes the context client version to 1 by default. We want to + // use OpenGL ES 2.0 which has the ability to create shader and program + // objects and also to write vertex and fragment shaders in the OpenGL ES + // Shading Language. + const EGLint attribs[] = { + EGL_CONTEXT_CLIENT_VERSION, 2, + EGL_NONE + }; + + EGLContext glContext = eglCreateContext(display_, config, EGL_NO_CONTEXT, attribs); if (glContext == EGL_NO_CONTEXT) { mbgl::Log::Error(mbgl::Event::OpenGL, "eglCreateContext() returned error 0x%04x", eglGetError()); diff --git a/platform/linux/src/headless_display_egl.cpp b/platform/linux/src/headless_display_egl.cpp index 2c0481ddd1..4be519cfcd 100644 --- a/platform/linux/src/headless_display_egl.cpp +++ b/platform/linux/src/headless_display_egl.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -25,6 +26,11 @@ HeadlessDisplay::Impl::Impl() { throw std::runtime_error("eglInitialize() failed.\n"); } + if (!eglBindAPI(EGL_OPENGL_ES_API)) { + mbgl::Log::Error(mbgl::Event::OpenGL, "eglBindAPI(EGL_OPENGL_ES_API) returned error %d", eglGetError()); + throw std::runtime_error("eglBindAPI() failed"); + } + // This shouldn't matter as we're rendering to a framebuffer. const EGLint attribs[] = { EGL_NONE }; if (!eglChooseConfig(display, attribs, &config, 1, &numConfigs) || numConfigs != 1) { diff --git a/test/util/offscreen_texture.test.cpp b/test/util/offscreen_texture.test.cpp index 9a07f4f3bf..1d6a6e80e3 100644 --- a/test/util/offscreen_texture.test.cpp +++ b/test/util/offscreen_texture.test.cpp @@ -74,17 +74,26 @@ TEST(OffscreenTexture, RenderToTexture) { MBGL_CHECK_ERROR(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); Shader paintShader(R"MBGL_SHADER( +#ifdef GL_ES +precision mediump float; +#endif attribute vec2 a_pos; void main() { gl_Position = vec4(a_pos, 0, 1); } )MBGL_SHADER", R"MBGL_SHADER( +#ifdef GL_ES +precision mediump float; +#endif void main() { gl_FragColor = vec4(0, 0.8, 0, 0.8); } )MBGL_SHADER"); Shader compositeShader(R"MBGL_SHADER( +#ifdef GL_ES +precision mediump float; +#endif attribute vec2 a_pos; varying vec2 v_texcoord; void main() { @@ -92,6 +101,9 @@ void main() { v_texcoord = (a_pos + 1.0) / 2.0; } )MBGL_SHADER", R"MBGL_SHADER( +#ifdef GL_ES +precision mediump float; +#endif uniform sampler2D u_texture; varying vec2 v_texcoord; void main() { -- cgit v1.2.1