Java bindings for wgpu-native using Panama FFI with some experimental approach. The goal is to make the API similar to what it looks like in JavaScript.
Requires JDK 23 and wgpu-native v22.1.0.5
In general wgpu API can be used "raw" with static methods located under wgpu.WGPU.*
. These use raw long
for WGPU object references and MemorySegment
for data. The other way is to use object wrappers, such as GPUInstance
, etc.
All callback stubs are allocated with Arena.ofAuto()
and cached by a weak map. You can safely inline short lasting callbacks, but for "long lasting" callbacks (such as device lost callback) you should keep their instance around to avoid GC cleaning the stub up.
There's a triangle rendering example (without geometry) here: TriangleExample.java
At current stage it's a bit messy and is mostly untested. The code is generated with custom script (not in the repo yet).
If you want to test it, you can download artifacts from the experimental CI build. You will also need wgpu-native binaries in your library path.