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

Commit

Permalink
[android] Update GLSL + ensure binding to OpenGL ES 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoabinader committed Nov 14, 2016
1 parent 52da0e6 commit 1c79147
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"ejs": "^2.4.1",
"express": "^4.11.1",
"lodash": "^4.16.4",
"mapbox-gl-shaders": "mapbox/mapbox-gl-shaders#7f1c3bef3692f1d044035a22e65c8758b7630333",
"mapbox-gl-shaders": "mapbox/mapbox-gl-shaders#ec891ce5360e488d81f60991f95d2038b83c4e3c",
"mapbox-gl-style-spec": "mapbox/mapbox-gl-style-spec#7f62a4fc9f21e619824d68abbc4b03cbc1685572",
"mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#af9ee275f19e81f839a2733e6906c3fac272620e",
"mkdirp": "^0.5.1",
Expand Down
46 changes: 28 additions & 18 deletions platform/android/src/native_map_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,6 @@ mbgl::Map &NativeMapView::getMap() { return *map; }

mbgl::DefaultFileSource &NativeMapView::getFileSource() { return *fileSource; }

bool NativeMapView::inEmulator() {
// Detect if we are in emulator
char prop[PROP_VALUE_MAX];
__system_property_get("ro.kernel.qemu", prop);
return strtol(prop, nullptr, 0) == 1;
}

void NativeMapView::initializeDisplay() {
mbgl::Log::Debug(mbgl::Event::Android, "NativeMapView::initializeDisplay");

Expand Down Expand Up @@ -258,22 +251,39 @@ void NativeMapView::initializeDisplay() {
log_egl_string(display, EGL_CLIENT_APIS, "Client APIs");
log_egl_string(display, EGL_EXTENSIONS, "Client Extensions");

// Detect if we are in emulator
if (inEmulator()) {
// Detect if we are in emulator.
const bool inEmulator = []() {
char prop[PROP_VALUE_MAX];
__system_property_get("ro.kernel.qemu", prop);
return strtol(prop, nullptr, 0) == 1;
}();

if (inEmulator) {
// XXX https://code.google.com/p/android/issues/detail?id=78977
mbgl::Log::Warning(mbgl::Event::Android, "In emulator! Enabling hacks :-(");
}

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");
}

// Get all configs at least RGB 565 with 16 depth and 8 stencil
EGLint configAttribs[] = {
EGL_CONFIG_CAVEAT, EGL_NONE, EGL_RENDERABLE_TYPE,
EGL_OPENGL_ES2_BIT, EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_BUFFER_SIZE, 16, EGL_RED_SIZE,
5, EGL_GREEN_SIZE, 6,
EGL_BLUE_SIZE, 5, EGL_DEPTH_SIZE,
16, EGL_STENCIL_SIZE, 8,
(inEmulator() ? EGL_NONE : EGL_CONFORMANT), EGL_OPENGL_ES2_BIT, // Ugly hack
(inEmulator() ? EGL_NONE : EGL_COLOR_BUFFER_TYPE), EGL_RGB_BUFFER, // Ugly hack
EGL_NONE};
EGL_CONFIG_CAVEAT, EGL_NONE,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_BUFFER_SIZE, 16,
EGL_RED_SIZE, 5,
EGL_GREEN_SIZE, 6,
EGL_BLUE_SIZE, 5,
EGL_DEPTH_SIZE, 16,
EGL_STENCIL_SIZE, 8,
(inEmulator ? EGL_NONE : EGL_CONFORMANT), EGL_OPENGL_ES2_BIT,
(inEmulator ? EGL_NONE : EGL_COLOR_BUFFER_TYPE), EGL_RGB_BUFFER,
EGL_NONE
};

EGLint numConfigs;
if (!eglChooseConfig(display, configAttribs, nullptr, 0, &numConfigs)) {
mbgl::Log::Error(mbgl::Event::OpenGL, "eglChooseConfig(NULL) returned error %d",
Expand Down
2 changes: 0 additions & 2 deletions platform/android/src/native_map_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ class NativeMapView : public mbgl::View, public mbgl::Backend {
private:
EGLConfig chooseConfig(const EGLConfig configs[], EGLint numConfigs);

bool inEmulator();

private:
JavaVM *vm = nullptr;
JNIEnv *env = nullptr;
Expand Down

0 comments on commit 1c79147

Please sign in to comment.