Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[linux] Ensure EGL uses OpenGL ES 2.0 client API
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoabinader committed Nov 17, 2016
1 parent 0ef52d7 commit ad38ff2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
15 changes: 10 additions & 5 deletions platform/linux/src/headless_backend_egl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,16 @@ void HeadlessBackend::createContext() {
EGLDisplay display_ = display->attribute<EGLDisplay>();
EGLConfig& config = display->attribute<EGLConfig&>();

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());
Expand Down
6 changes: 6 additions & 0 deletions platform/linux/src/headless_display_egl.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <mbgl/platform/default/headless_display.hpp>
#include <mbgl/platform/log.hpp>
#include <mbgl/util/string.hpp>

#include <EGL/egl.h>
Expand All @@ -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) {
Expand Down
12 changes: 12 additions & 0 deletions test/util/offscreen_texture.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,36 @@ 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() {
gl_Position = vec4(a_pos, 0, 1);
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() {
Expand Down

0 comments on commit ad38ff2

Please sign in to comment.