From f7cfdb3795aab9abf9dd2bac4b27c05c14c1a827 Mon Sep 17 00:00:00 2001 From: omigamedev Date: Fri, 31 May 2019 10:06:20 +0200 Subject: [PATCH] restore screen density check on android, separate EGL attributes from Quest --- android/android/CMakeLists.txt | 1 + android/src/cpp/main.cpp | 52 ++++++++++++++++++++++++---------- 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/android/android/CMakeLists.txt b/android/android/CMakeLists.txt index 2a5755c..1dfd68b 100644 --- a/android/android/CMakeLists.txt +++ b/android/android/CMakeLists.txt @@ -111,6 +111,7 @@ add_library( ) target_include_directories(native-lib PRIVATE + src/main/cpp ../src/cpp ../../src ../../libs/glm diff --git a/android/src/cpp/main.cpp b/android/src/cpp/main.cpp index 1d0bae6..48cc9d9 100644 --- a/android/src/cpp/main.cpp +++ b/android/src/cpp/main.cpp @@ -327,6 +327,9 @@ static int engine_init_display(struct engine* engine) { * Below, we select an EGLConfig with at least 8 bits per color * component compatible with on-screen windows */ +#ifdef __QUEST__ + EGLint egl_depth = 0; + EGLint egl_alpha = 8; const EGLint attribs[] = { EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT_KHR, EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT, @@ -339,18 +342,32 @@ static int engine_init_display(struct engine* engine) { EGL_SAMPLES, 0, EGL_NONE }; - EGLint w, h, dummy, format; +#else + EGLint egl_depth = 24; + EGLint egl_alpha = 0; + const EGLint attribs[] = { + EGL_SURFACE_TYPE, EGL_WINDOW_BIT, + EGL_BLUE_SIZE, 8, + EGL_GREEN_SIZE, 8, + EGL_RED_SIZE, 8, + EGL_DEPTH_SIZE, 24, + EGL_STENCIL_SIZE, 0, + EGL_SAMPLES, 0, + EGL_NONE + }; +#endif + EGLint w, h, format; EGLint numConfigs; - EGLConfig config; - EGLSurface surface; - EGLContext context; + EGLConfig config = nullptr; + EGLSurface surface = nullptr; + EGLContext context = nullptr; EGLDisplay display = g_display; if (g_display == EGL_NO_DISPLAY) { LOG("DYSPLAY CREATE"); display = eglGetDisplay(EGL_DEFAULT_DISPLAY); - eglInitialize(display, 0, 0); + eglInitialize(display, nullptr, nullptr); } else LOG("DISPLAY RESUME"); @@ -371,7 +388,7 @@ static int engine_init_display(struct engine* engine) { eglGetConfigAttrib(display, cfg, EGL_BLUE_SIZE, &b) && eglGetConfigAttrib(display, cfg, EGL_ALPHA_SIZE, &a) && eglGetConfigAttrib(display, cfg, EGL_DEPTH_SIZE, &d) && - r == 8 && g == 8 && b == 8 && a == 8 && d == 0 ) { + r == 8 && g == 8 && b == 8 && a == egl_alpha && d == egl_depth ) { config = supportedConfigs[i]; break; @@ -386,10 +403,16 @@ static int engine_init_display(struct engine* engine) { * As soon as we picked a EGLConfig, we can safely reconfigure the * ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */ eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format); - surface = eglCreateWindowSurface(display, config, engine->app->window, NULL); + surface = eglCreateWindowSurface(display, config, engine->app->window, nullptr); + +#ifdef __QUEST__ + const int gles_version = 3; +#else + const int gles_version = 2; +#endif const EGLint attribs_test[] = { - EGL_CONTEXT_CLIENT_VERSION, 3, + EGL_CONTEXT_CLIENT_VERSION, gles_version, EGL_CONTEXT_FLAGS_KHR, EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR | EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR, EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR, EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR, EGL_NONE @@ -409,7 +432,7 @@ static int engine_init_display(struct engine* engine) { { LOG("EGL: debug and forward context failed"); const EGLint attribs_test[] = { - EGL_CONTEXT_CLIENT_VERSION, 3, + EGL_CONTEXT_CLIENT_VERSION, gles_version, EGL_CONTEXT_FLAGS_KHR, EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR, EGL_NONE }; @@ -418,7 +441,7 @@ static int engine_init_display(struct engine* engine) { { LOG("EGL: only forward context failed"); const EGLint attribs_test[] = { - EGL_CONTEXT_CLIENT_VERSION, 3, + EGL_CONTEXT_CLIENT_VERSION, gles_version, EGL_CONTEXT_FLAGS_KHR, EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR, //EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR, EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR, EGL_NONE @@ -428,7 +451,7 @@ static int engine_init_display(struct engine* engine) { { LOG("EGL: only debug context failed"); const EGLint attribs_test[] = { - EGL_CONTEXT_CLIENT_VERSION, 3, + EGL_CONTEXT_CLIENT_VERSION, gles_version, EGL_NONE }; context = eglCreateContext(display, config, EGL_NO_CONTEXT, attribs_test); @@ -471,9 +494,9 @@ static int engine_init_display(struct engine* engine) { engine->height = h; engine->state.angle = 0; - //float density = get_display_density(engine->app); - //LOG("density %f", density); - //App::I.zoom = density / 1.5; + float density = get_display_density(engine->app); + LOG("density %f", density); + App::I.zoom = density;// / 1.5; g_display = display; g_context = context; @@ -543,7 +566,6 @@ static int engine_init_display(struct engine* engine) { } - int ret = -1; FILE* file = popen("getprop", "r"); std::map os_props; if (file)