Updated examples to be compatible with self-hosted
- Uses the new
asRangecalling convention from https://github.com/floooh/sokol/pull/710 - Change
Mat4/Vec2/Vec3toextern structas arrays in packed structs are no longer supported, and a guaranteed memory layout is needed for passing these to the GPU
All the examples (except for instancing.zig) run for me on self-hosted (Windows, x86_64) in both opengl and directx. I did notice the point size seems different between dx and gl for sgl-points, but this seems true with -fstage1 as well.
The instancing.zig example crashes on self-hosted with a stack overflow, at the start of frame(). Debugging this, it seems that it tries to pass ~40M to ___chkstk_ms, which comes from lib/compiler_rt/stack_probe.zig. I recall seeing some activity about this so this may just be a self-hosted bug. I only have access to Windows, so it may not affect other platforms. This may also be related to the issue with structs being copied on to the stack (https://github.com/ziglang/zig/issues/12638) but I'm not familiar with how the stack probe is supposed to work, so I can't say without more investigating.
My own zig implementation of the sokol instancing example is is actually what triggered this issue: https://github.com/ziglang/zig/issues/12568
If you do a similar workaround to the one I posted there you can probably get the instancing to work on stage2 too.
For reference, this is what my update loop looks like now on my side (I don't have the data wrapped in a state struct and just use the sokol c code directly, so maybe it won't work here):
{
var i: u32 = 0;
// update particle positions
while (i < cur_num_particles) : (i += 1) {
const particle_pos = &pos[i];
const particle_vel = &vel[i];
particle_vel.y -= frame_time;
particle_pos.* = particle_pos.add(particle_vel.scl(frame_time));
// bounce back from 'ground'
if (particle_pos.y < -2.0) {
particle_vel.y = -1.8;
particle_vel.y = -particle_vel.y;
particle_vel.x *= 0.8;
particle_vel.y *= 0.8;
particle_vel.z *= 0.8;
}
}
}
Ah, thanks! Indeed that workaround works here as well, just added the change. Cheers!
Ok, I have merged this PR manually into a new sokol-zig branch 0.10.0:
https://github.com/floooh/sokol-zig/tree/zig-0.10.0
...once Zig 0.10.0 is officially released, I'll merge that back into master, and (hopefully), this PR should then automatically resolve too.
PS: ...and I have converted this PR to a draft so that I don't accidentally press the merge button ...
PPS: many thanks for the PR :)
...and it's in master now.
awesome!