diff --git a/src/platform/raylib.zig b/src/platform/raylib.zig index 4eced7c..b455629 100644 --- a/src/platform/raylib.zig +++ b/src/platform/raylib.zig @@ -10,6 +10,8 @@ pub const Driver = struct { height: i32, scale: i32, + rgba_buffer: [256 * 240]u32 = [_]u32{0xFF000000} ** (256 * 240), + event_queue: [16]platform.Event = undefined, event_head: usize = 0, event_tail: usize = 0, @@ -19,7 +21,7 @@ pub const Driver = struct { c.SetTargetFPS(60); c.InitAudioDevice(); - c.SetAudioStreamBufferSizeDefault(1024); + c.SetAudioStreamBufferSizeDefault(2048); const stream = c.LoadAudioStream(44100, 16, 1); c.PlayAudioStream(stream); @@ -87,8 +89,15 @@ pub const Driver = struct { pub fn renderVideo(self: *Driver, output: usize, frame: contract.VideoFrame) void { _ = output; - if (frame.data.len > 0) { - c.UpdateTexture(self.texture, frame.data.ptr); + if (frame.data.len >= 256 * 240 * 2) { + 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(); @@ -107,7 +116,7 @@ pub const Driver = struct { pub fn queueAudio(self: *Driver, output: usize, buffer: contract.AudioBuffer) void { _ = 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)); } }