wgpu-odin
wgpu-odin copied to clipboard
Bindings to WGPU Native in the Odin programming language
WGPU Odin Bindings
Bindings to wgpu-native 22.1.0.5 made by hand in the Odin programming language.
See examples here.
Status
Note
The wgpu-API still in the "Working Draft" phase. Until the specification is stabilized, break changes can happen without notice.
Bindings only
You can use the bindings only where the procedures are called directly from the foreign block. There is also the official bindings in case you want a "raw" version with some helper procedures.
Wrapper (๐งWIP)
The wrapper version exposes an API similar to the Rust API, this allows developers to easily translate Rust tutorials and examples into Odin code.
Linking
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/v22.1.0.5
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
โ โ โ ๐wgpu_native.lib
โ โ ๐x86_64
โ โ โ ๐wgpu_native.dll.lib
โ โ โ ๐wgpu_native.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 by default, you need wgpu_native.dll along side your executable. To build statically, set the config WGPU_SHARED to false (this option only affects Windows).
Both Linux and Mac by default are statically linked for ease of use, but you can link against system.
Link against system
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.
Quick Start Guide
-
Clone this repository or download the zip file.
-
Ensure you follow the "Linking" steps outlined above to include the appropriate binaries for your target platform.
-
Create a folder named
libs/wgpuin the root of your project (where you runodin buildfrom). Alternatively, you can use thesharedfolder in your Odin installation to define a collection. -
If you want the wrapper version:
- Copy the
bindings,wrapper, andutilsfolders from this repository to the directory created in step 3.
- Copy the
-
To easily import the package into your project, set up a
collection:// Example of setting up a collection (add this to your build command or script) odin build ./src -collection:libs=./libs -
You can now import the package in your code:
import wgpu "libs:wgpu/wrapper"
Or
import wgpu "libs:wgpu/bindings"
Naming Conventions
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 |
License
MIT license.