feat(android): Vulkan graphics backend support for Android custom layers (#4348)
Co-authored-by: Vladyslav Odobesku <VladyslavOdobesku@intellias.com> Co-authored-by: Claude Opus 4 <noreply@anthropic.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
9f6f8e3f1b
commit
aa90185d42
@@ -13,8 +13,10 @@ import org.maplibre.android.maps.MapView
|
||||
import org.maplibre.android.maps.MapLibreMap
|
||||
import org.maplibre.android.maps.Style
|
||||
import org.maplibre.android.style.layers.CustomLayer
|
||||
import org.maplibre.android.testapp.BuildConfig
|
||||
import org.maplibre.android.testapp.R
|
||||
import org.maplibre.android.testapp.model.customlayer.ExampleCustomLayer
|
||||
import org.maplibre.android.testapp.model.customlayer.ExampleVulkanCustomLayer
|
||||
import org.maplibre.android.testapp.styles.TestStyles
|
||||
|
||||
/**
|
||||
@@ -29,6 +31,9 @@ class CustomLayerActivity : AppCompatActivity() {
|
||||
private lateinit var mapView: MapView
|
||||
private var customLayer: CustomLayer? = null
|
||||
private lateinit var fab: FloatingActionButton
|
||||
|
||||
private var isVulkan = BuildConfig.FLAVOR.contains("vulkan")
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_custom_layer)
|
||||
@@ -65,7 +70,7 @@ class CustomLayerActivity : AppCompatActivity() {
|
||||
} else {
|
||||
customLayer = CustomLayer(
|
||||
"custom",
|
||||
ExampleCustomLayer.createContext()
|
||||
if (!isVulkan) ExampleCustomLayer.createContext() else ExampleVulkanCustomLayer.createContext()
|
||||
)
|
||||
style!!.addLayerBelow(customLayer!!, "building")
|
||||
fab.setImageResource(R.drawable.ic_layers_clear)
|
||||
@@ -124,18 +129,34 @@ class CustomLayerActivity : AppCompatActivity() {
|
||||
updateLayer()
|
||||
true
|
||||
}
|
||||
|
||||
R.id.action_set_color_red -> {
|
||||
ExampleCustomLayer.setColor(1f, 0f, 0f, 1f)
|
||||
if (!isVulkan) {
|
||||
ExampleCustomLayer.setColor(1f, 0f, 0f, 1f)
|
||||
} else {
|
||||
ExampleVulkanCustomLayer.setColor(1f, 0f, 0f, 1f)
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
R.id.action_set_color_green -> {
|
||||
ExampleCustomLayer.setColor(0f, 1f, 0f, 1f)
|
||||
if (!isVulkan) {
|
||||
ExampleCustomLayer.setColor(0f, 1f, 0f, 1f)
|
||||
} else {
|
||||
ExampleVulkanCustomLayer.setColor(0f, 1f, 0f, 1f)
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
R.id.action_set_color_blue -> {
|
||||
ExampleCustomLayer.setColor(0f, 0f, 1f, 1f)
|
||||
if (!isVulkan) {
|
||||
ExampleCustomLayer.setColor(0f, 0f, 1f, 1f)
|
||||
} else {
|
||||
ExampleVulkanCustomLayer.setColor(0f, 0f, 1f, 1f)
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
else -> super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.maplibre.android.testapp.model.customlayer
|
||||
|
||||
import androidx.annotation.Keep
|
||||
|
||||
@Keep
|
||||
object ExampleVulkanCustomLayer {
|
||||
init {
|
||||
System.loadLibrary("example-vulkan-custom-layer")
|
||||
}
|
||||
|
||||
external fun createContext(): Long
|
||||
external fun setColor(red: Float, green: Float, blue: Float, alpha: Float)
|
||||
var InitializeFunction: Long = 0
|
||||
var RenderFunction: Long = 0
|
||||
var ContextLostFunction: Long = 0
|
||||
var DeinitializeFunction: Long = 0
|
||||
}
|
||||
Reference in New Issue
Block a user