Bindings to wgpu-native 0.19.4.1 in the Odin programming language.
See examples here.
Note
The wgpu-API still in the "Working Draft" phase. Until the specification is stabilized, break changes can happen without notice.
You can use the bindings only where the procedures are called directly from the foreign
block.
The wrapper version exposes an API similar to the WebGPU spec. Most of the inner procedures are boilerplate code that create an convenient way to work with idiomatic Odin and wgpu data.
To make this repository easy to maintain and light to download, I decided to not include all binaries files (that can exceed 130MB). You can build the library yourself, but all those files are autogenerated and you can download on wgpu-native releases page:
https://github.com/gfx-rs/wgpu-native/releases/tag/v0.19.4.1
Make sure to match the version tag is the same from upstream, just place the corresponding files according to the bindings tree in bindings/lib/
:
📦lib
┣ 📂linux
┃ ┣ 📂arch64
┃ ┃ ┗ 📜libwgpu_native.a
┃ ┗ 📂x86_64
┃ ┃ ┗ 📜libwgpu_native.a
┣ 📂mac_os
┃ ┣ 📂arch64
┃ ┃ ┗ 📜libwgpu_native.a
┃ ┗ 📂x86_64
┃ ┃ ┗ 📜libwgpu_native.a
┣ 📂windows
┃ ┣ 📂i686
┃ ┃ ┗ 📜wgpu_native.dll.lib
┃ ┗ 📂x86_64
┃ ┃ ┗ 📜wgpu_native.dll.lib
Check the foreign import in the file bindings.odin for more details. For example, download wgpu-windows-x86_64-release.zip
and copy wgpu_native.dll.lib
to the folder bindings/lib/windows/x86_64/
.
On Windows the linking is dynamic, you need wgpu_native.dll
along side your executable. Both Linux and Mac are statically linked for ease of use.
On Linux or Mac, you can tell the library to link against system libwgpu_native
instead of one provided in the directory by defining the Odin config value WGPU_USE_SYSTEM_LIBRARIES
as true
.
- Clone this repository.
- Make sure you follow the Linking steps above to include the binaries for your target.
- Create a folder
libs/wgpu
in the root of your project (from where you runodin build
). - If you want the wrapper version, copy the folders
bindings
,wrapper
andutils
from this repository to the directory created in the previous step. - To easily import the package to your project, you can set a
collection
:
odin build ./src -collection:libs=./libs
- Import the package:
import wgpu "libs:wgpu/wrapper"
Or
import wgpu "libs:wgpu/bindings"
Types and values follow the Odin Naming Convention. In general, Ada_Case
for types and snake_case
for values
Case | |
---|---|
Import Name | snake_case (but prefer single word) |
Types | Ada_Case |
Enum Values | Ada_Case |
Procedures | snake_case |
Local Variables | snake_case |
Constant Variables | SCREAMING_SNAKE_CASE |
MIT license.