Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix android running issue #31

Merged
merged 2 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ jobs:
steps:
- name: install dependencies
if: matrix.os == 'ubuntu-latest'
run: sudo apt install -y libglfw3-dev
run: |
sudo apt update
sudo apt install -y libglfw3-dev
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
Expand Down
2 changes: 1 addition & 1 deletion demo/android/src/androidMain/kotlin/WGPUSurfaceView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class WGPUSurfaceView : SurfaceView, SurfaceHolder.Callback2 {
override fun surfaceCreated(surfaceHolder: SurfaceHolder): Unit = memoryScope { scope ->
val instance = wgpuCreateInstance(null) ?: error("fail to create instance")
val surface = getSurface(instance, holder)
val adapter = getAdapter(surface, instance, WGPUBackendType_Vulkan)
val adapter = getAdapter(surface, instance)
val device = getDevice(adapter)
val surfaceCapabilities = surfaceCapabilities(surface, adapter)
configureSurface(device, width, height, surface, surfaceCapabilities.formats.first(), surfaceCapabilities.alphaModes.first(), listOf(surfaceCapabilities.formats.first()))
Expand Down
34 changes: 8 additions & 26 deletions demo/common/src/commonMain/kotlin/ext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,10 @@ fun configureSurface(
fun getDevice(adapter: WGPUAdapter): WGPUDevice = memoryScope { scope ->
var fetchedDevice: WGPUDevice? = null

val callback = WGPURequestDeviceCallback.allocate(scope, object : WGPURequestDeviceCallback {
override fun invoke(
status: WGPURequestDeviceStatus,
device: WGPUDevice?,
message: WGPUStringView?,
userdata1: NativeAddress?,
userdata2: NativeAddress?
) {
if (status != WGPURequestDeviceStatus_Success && device == null) error("fail to get device")
fetchedDevice = device
}

})
val callback = WGPURequestDeviceCallback.allocate(scope) { status, device, _, _, _ ->
if (status != WGPURequestDeviceStatus_Success && device == null) error("fail to get device")
fetchedDevice = device
}

val callbackInfo = WGPURequestDeviceCallbackInfo.allocate(scope).apply {
this.callback = callback
Expand All @@ -90,19 +81,10 @@ fun getAdapter(surface: WGPUSurface, instance: WGPUInstance, backendType: UInt =

var fetchedAdapter: WGPUAdapter? = null

val callback = WGPURequestAdapterCallback.allocate(scope, object : WGPURequestAdapterCallback {
override fun invoke(
status: WGPURequestAdapterStatus,
adapter: WGPUAdapter?,
message: WGPUStringView?,
userdata1: NativeAddress?,
userdata2: NativeAddress?
) {
if (status != WGPURequestAdapterStatus_Success || adapter == null) error("fail to get adapter")
fetchedAdapter = adapter
}

})
val callback = WGPURequestAdapterCallback.allocate(scope) { status, adapter, _, _, _ ->
if (status != WGPURequestAdapterStatus_Success || adapter == null) error("fail to get adapter")
fetchedAdapter = adapter
}

callbackInfo.callback = callback
callbackInfo.userdata2 = scope.bufferOfAddress(callback.handler).handler
Expand Down
7 changes: 3 additions & 4 deletions demo/desktop-and-ios/src/desktopMain/kotlin/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ fun main() {
val surface = getSurface(instance, windowHandler)
val adapter = getAdapter(surface, instance)
val device = getDevice(adapter)
val compatibleFormat = compatibleFormat(surface, adapter)
val alphaMode = compatibleAlphaMode(surface, adapter)
configureSurface(device, width, height, surface, compatibleFormat, alphaMode)
val surfaceCapabilities = surfaceCapabilities(surface, adapter)
configureSurface(device, width, height, surface, surfaceCapabilities.formats.first(), surfaceCapabilities.alphaModes.first(), listOf(surfaceCapabilities.formats.first()))

val scene = HelloTriangleScene(device, compatibleFormat, surface)
val scene = HelloTriangleScene(device, surfaceCapabilities.formats.first(), surface)
scene.initialize()

glfwShowWindow(windowHandler)
Expand Down
7 changes: 3 additions & 4 deletions demo/desktop-and-ios/src/jvmMain/kotlin/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,10 @@ fun main() {
}

val device = getDevice(adapter)
val compatibleFormat = compatibleFormat(surface, adapter)
val alphaMode = compatibleAlphaMode(surface, adapter)
configureSurface(device, width, height, surface, compatibleFormat, alphaMode)
val surfaceCapabilities = surfaceCapabilities(surface, adapter)
configureSurface(device, width, height, surface, surfaceCapabilities.formats.first(), surfaceCapabilities.alphaModes.first(), listOf(surfaceCapabilities.formats.first()))

val scene = HelloTriangleScene(device, compatibleFormat, surface)
val scene = HelloTriangleScene(device, surfaceCapabilities.formats.first(), surface)
scene.initialize()

glfwShowWindow(windowHandler)
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
kaml = "0.67.0"
kotlin = "2.1.0"
wgpu = "v24.0.0.2"
wgpu = "v24.0.0.0"
download = "5.6.0"
jreleaser = "1.13.1"
agp = "8.7.3"
Expand Down
7 changes: 1 addition & 6 deletions wgpu4k-native/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,7 @@ java {
}
}

fun jniBasePath() = buildNativeResourcesDirectory.resolve("libsDebug")

/*if (Platform.os == Os.MacOs) {
tasks.findByName("linkDebugTestMingwX64")?.apply { enabled = false }
tasks.findByName("mingwX64Test")?.apply { enabled = false }
}*/
fun jniBasePath() = buildNativeResourcesDirectory.resolve("libs")

tasks.named<Test>("jvmTest") {
useJUnitPlatform()
Expand Down
Loading