Skip to content

Commit

Permalink
V10.3 port: Fix map not rendering on emulators when MSAA is enabled (#…
Browse files Browse the repository at this point in the history
…1086)

* Fix map not rendering on emulatores with MSAA enabled

* PR fixes

* Update changelog
  • Loading branch information
kiryldz authored Jan 26, 2022
1 parent d5d74bd commit 7d9ad17
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 18 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 🏁
Expand Down
56 changes: 38 additions & 18 deletions sdk/src/main/java/com/mapbox/maps/renderer/egl/EGLConfigChooser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -71,7 +70,6 @@ internal class EGLConfigChooser constructor(
val possibleConfigurations = getPossibleConfigurations(
egl,
display,
configAttrs,
numConfigs
)
if (!eglChooserSuccess) {
Expand All @@ -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<EGLConfig> {
val configs = arrayOfNulls<EGLConfig>(numConfigs[0])
Expand All @@ -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()
)
)
Expand Down

0 comments on commit 7d9ad17

Please sign in to comment.