mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Add sdl2glue to vendor:wgpu package + triangle example
This commit is contained in:
Vendored
+60
@@ -0,0 +1,60 @@
|
||||
package vendor_wgpu_example_triangle
|
||||
|
||||
import "vendor:wgpu"
|
||||
import "vendor:wasm/js"
|
||||
|
||||
OS :: struct {
|
||||
initialized: bool,
|
||||
}
|
||||
|
||||
@(private="file")
|
||||
g_os: ^OS
|
||||
|
||||
os_init :: proc(os: ^OS) {
|
||||
g_os = os
|
||||
assert(js.add_window_event_listener(.Resize, nil, size_callback))
|
||||
}
|
||||
|
||||
// NOTE: frame loop is done by the runtime.js repeatedly calling `step`.
|
||||
os_run :: proc(os: ^OS) {
|
||||
os.initialized = true
|
||||
}
|
||||
|
||||
os_get_render_bounds :: proc(os: ^OS) -> (width, height: u32) {
|
||||
rect := js.get_bounding_client_rect("body")
|
||||
return u32(rect.width), u32(rect.height)
|
||||
}
|
||||
|
||||
os_get_surface :: proc(os: ^OS, instance: wgpu.Instance) -> wgpu.Surface {
|
||||
return wgpu.InstanceCreateSurface(
|
||||
instance,
|
||||
&wgpu.SurfaceDescriptor{
|
||||
nextInChain = &wgpu.SurfaceDescriptorFromCanvasHTMLSelector{
|
||||
sType = .SurfaceDescriptorFromCanvasHTMLSelector,
|
||||
selector = "#wgpu-canvas",
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@(private="file", export)
|
||||
step :: proc(dt: f32) -> bool {
|
||||
if !g_os.initialized {
|
||||
return true
|
||||
}
|
||||
|
||||
frame(dt)
|
||||
return true
|
||||
}
|
||||
|
||||
@(private="file", fini)
|
||||
os_fini :: proc() {
|
||||
js.remove_window_event_listener(.Resize, nil, size_callback)
|
||||
|
||||
finish()
|
||||
}
|
||||
|
||||
@(private="file")
|
||||
size_callback :: proc(e: js.Event) {
|
||||
resize()
|
||||
}
|
||||
Reference in New Issue
Block a user