From a9e3df91d56cc63ff2993d90a534422bec953c6a Mon Sep 17 00:00:00 2001 From: Kiryl Dzehtsiarenka Date: Wed, 26 Jan 2022 14:48:33 +0300 Subject: [PATCH] Fix map not rendering on emulators when MSAA is enabled (#1077) * Fix map not rendering on emulatores with MSAA enabled * PR fixes * Update changelog --- CHANGELOG.md | 5 ++ .../maps/renderer/egl/EGLConfigChooser.kt | 56 +++++++++++++------ 2 files changed, 43 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fefa169472..0773e669b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ Mapbox welcomes participation and contributions from everyone. +# 10.3.0-rc.1 January 26, 2022 + +## Bug fixes 🐞 +* Fix map not rendering on emulators when MSAA is enabled. ([#1077](https://github.com/mapbox/mapbox-maps-android/pull/1077)) + # 10.3.0-beta.1 January 12, 2022 ## Features ✨ and improvements 🏁 diff --git a/sdk/src/main/java/com/mapbox/maps/renderer/egl/EGLConfigChooser.kt b/sdk/src/main/java/com/mapbox/maps/renderer/egl/EGLConfigChooser.kt index 1e73bfdd4a..dc0d6a9294 100644 --- a/sdk/src/main/java/com/mapbox/maps/renderer/egl/EGLConfigChooser.kt +++ b/sdk/src/main/java/com/mapbox/maps/renderer/egl/EGLConfigChooser.kt @@ -14,9 +14,9 @@ import javax.microedition.khronos.egl.EGLDisplay internal class EGLConfigChooser constructor( private val translucentSurface: Boolean, - private val antialiasingSampleCount: Int, + private var antialiasingSampleCount: Int, ) { - private val antialiasingEnabled = antialiasingSampleCount > DEFAULT_ANTIALIASING_SAMPLE_COUNT + private val antialiasingEnabled get() = antialiasingSampleCount > DEFAULT_ANTIALIASING_SAMPLE_COUNT // Get all configs at least RGB 565 with 16 depth and 8 stencil private val configAttributes: IntArray @@ -57,9 +57,8 @@ internal class EGLConfigChooser constructor( private var eglChooserSuccess = true fun chooseConfig(egl: EGL10, display: EGLDisplay): EGLConfig? { - val configAttrs = configAttributes // Determine number of possible configurations - val numConfigs = getNumberOfConfigurations(egl, display, configAttrs) + val numConfigs = getNumberOfConfigurations(egl, display) if (!eglChooserSuccess) { return null } @@ -71,7 +70,6 @@ internal class EGLConfigChooser constructor( val possibleConfigurations = getPossibleConfigurations( egl, display, - configAttrs, numConfigs ) if (!eglChooserSuccess) { @@ -88,28 +86,50 @@ internal class EGLConfigChooser constructor( private fun getNumberOfConfigurations( egl: EGL10, - display: EGLDisplay, - configAttributes: IntArray + display: EGLDisplay ): IntArray { val numConfigs = IntArray(1) - if (!egl.eglChooseConfig(display, configAttributes, null, 0, numConfigs)) { - Logger.e( - TAG, - String.format( - MAPBOX_LOCALE, - "eglChooseConfig returned error %d", - egl.eglGetError() + val initialSampleCount = antialiasingSampleCount + var suitableConfigsFound = false + while (!suitableConfigsFound) { + val success = egl.eglChooseConfig(display, configAttributes, null, 0, numConfigs) + if (!success || numConfigs[0] < 1) { + Logger.e( + TAG, + String.format( + MAPBOX_LOCALE, + "eglChooseConfig returned error %d", + egl.eglGetError() + ) ) - ) - eglChooserSuccess = false + if (antialiasingSampleCount > 1) { + Logger.w(TAG, "Reducing sample count in 2 times for MSAA as EGL_SAMPLES=$antialiasingSampleCount is not supported") + antialiasingSampleCount /= 2 + } else { + // we did all we could, return error + Logger.e(TAG, "No suitable EGL configs were found.") + numConfigs[0] = 0 + eglChooserSuccess = false + return numConfigs + } + } else { + suitableConfigsFound = true + } + } + if (initialSampleCount != antialiasingSampleCount) { + if (antialiasingSampleCount == 1) { + Logger.w(TAG, "Found EGL configs only with MSAA disabled.") + } else { + Logger.w(TAG, "Found EGL configs with MSAA enabled, EGL_SAMPLES=$antialiasingSampleCount.") + } } + eglChooserSuccess = true return numConfigs } private fun getPossibleConfigurations( egl: EGL10, display: EGLDisplay, - configAttributes: IntArray, numConfigs: IntArray ): Array { val configs = arrayOfNulls(numConfigs[0]) @@ -118,7 +138,7 @@ internal class EGLConfigChooser constructor( TAG, String.format( MAPBOX_LOCALE, - "eglChooseConfig() returned error %d", + "Weird: eglChooseConfig() returned error %d although ran fine before.", egl.eglGetError() ) )