fix Raylib RGB565 to RGBA8888 texture conversion and audio streaming

This commit is contained in:
2026-08-14 16:34:23 +02:00
parent d7cca04cd4
commit fb6aa5d46b
+13 -4
View File
@@ -10,6 +10,8 @@ pub const Driver = struct {
height: i32, height: i32,
scale: i32, scale: i32,
rgba_buffer: [256 * 240]u32 = [_]u32{0xFF000000} ** (256 * 240),
event_queue: [16]platform.Event = undefined, event_queue: [16]platform.Event = undefined,
event_head: usize = 0, event_head: usize = 0,
event_tail: usize = 0, event_tail: usize = 0,
@@ -19,7 +21,7 @@ pub const Driver = struct {
c.SetTargetFPS(60); c.SetTargetFPS(60);
c.InitAudioDevice(); c.InitAudioDevice();
c.SetAudioStreamBufferSizeDefault(1024); c.SetAudioStreamBufferSizeDefault(2048);
const stream = c.LoadAudioStream(44100, 16, 1); const stream = c.LoadAudioStream(44100, 16, 1);
c.PlayAudioStream(stream); c.PlayAudioStream(stream);
@@ -87,8 +89,15 @@ pub const Driver = struct {
pub fn renderVideo(self: *Driver, output: usize, frame: contract.VideoFrame) void { pub fn renderVideo(self: *Driver, output: usize, frame: contract.VideoFrame) void {
_ = output; _ = output;
if (frame.data.len > 0) { if (frame.data.len >= 256 * 240 * 2) {
c.UpdateTexture(self.texture, frame.data.ptr); const raw_pixels = std.mem.bytesAsSlice(u16, frame.data);
for (raw_pixels[0..@min(raw_pixels.len, self.rgba_buffer.len)], 0..) |pixel, i| {
const r = @as(u32, (pixel >> 11) & 0x1F) * 255 / 31;
const g = @as(u32, (pixel >> 5) & 0x3F) * 255 / 63;
const b = @as(u32, pixel & 0x1F) * 255 / 31;
self.rgba_buffer[i] = r | (g << 8) | (b << 16) | (0xFF << 24);
}
c.UpdateTexture(self.texture, &self.rgba_buffer);
} }
c.BeginDrawing(); c.BeginDrawing();
@@ -107,7 +116,7 @@ pub const Driver = struct {
pub fn queueAudio(self: *Driver, output: usize, buffer: contract.AudioBuffer) void { pub fn queueAudio(self: *Driver, output: usize, buffer: contract.AudioBuffer) void {
_ = output; _ = output;
if (buffer.frames > 0 and c.IsAudioStreamProcessed(self.audio_stream)) { if (buffer.frames > 0) {
c.UpdateAudioStream(self.audio_stream, buffer.data.ptr, @intCast(buffer.frames)); c.UpdateAudioStream(self.audio_stream, buffer.data.ptr, @intCast(buffer.frames));
} }
} }