summaryrefslogtreecommitdiff
path: root/src/screen/main.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/screen/main.zig')
-rw-r--r--src/screen/main.zig50
1 files changed, 21 insertions, 29 deletions
diff --git a/src/screen/main.zig b/src/screen/main.zig
index 673be0e..0514210 100644
--- a/src/screen/main.zig
+++ b/src/screen/main.zig
@@ -14,30 +14,17 @@ pub fn main() !void {
var connector = try card.connector(resources.connector_ids[0]);
defer connector.deinit();
- std.debug.print("connector = {}\n", .{ connector.id });
-
const mode = connector.modes[0];
- std.debug.print("mode = {s}@{d}Hz\n", .{ mode.name, mode.frame_rate() });
-
var crtc = try card.crtc(resources.crtc_ids[
connector.compatible_crtc() orelse @panic("no crtc found")
]);
defer crtc.detach();
- std.debug.print("crtc = {}\n", .{ crtc.id });
-
- var double_buffer = try card.create_double_buffer(mode.horizontal.size, mode.vertical.size, 32);
- defer double_buffer.deinit();
+ var buffer = try card.create_buffer(mode.horizontal.size, mode.vertical.size);
+ defer buffer.deinit();
- std.debug.print("buffer = {}, {}x{}, stride = {}\n", .{
- double_buffer.current.id,
- double_buffer.current.width,
- double_buffer.current.height,
- double_buffer.current.stride,
- });
-
- try crtc.attach(&double_buffer, &connector, mode);
+ try crtc.attach(&buffer, &connector, mode);
const Pos = struct { x: f32, y: f32 };
@@ -46,13 +33,20 @@ pub fn main() !void {
var delta: f32 = 0;
const size = 100;
- const width: f32 = @floatFromInt(double_buffer.current.width);
- const height: f32 = @floatFromInt(double_buffer.current.height);
+ const width: f32 = @floatFromInt(buffer.current.width);
+ const height: f32 = @floatFromInt(buffer.current.height);
while (true) {
const start = try std.time.Instant.now();
- double_buffer.current.fill(.{ .red = 0x25, .green = 0x25, .blue = 0x25 });
+ @memset(
+ buffer.current.pixels,
+ .{
+ .red = 0x25,
+ .green = 0x25,
+ .blue = 0x25
+ }
+ );
pos.x += vec.x * delta;
pos.y += vec.y * delta;
@@ -75,23 +69,21 @@ pub fn main() !void {
for (0..size) |w| {
for (0..size) |h| {
- double_buffer.current.set(
- @as(u32, @intFromFloat(pos.x)) + @as(u32, @intCast(w)),
- @as(u32, @intFromFloat(pos.y)) + @as(u32, @intCast(h)),
- .{
- .red = 0xff,
- .green = 0,
- .blue = 0,
- });
+ const x = @as(usize, @intFromFloat(pos.x)) + w;
+ const y = @as(usize, @intFromFloat(pos.y)) + h;
+ buffer.current.pixels[x + buffer.current.width * y] = .{
+ .red = 0xff,
+ .green = 0,
+ .blue = 0,
+ };
}
}
const end = try std.time.Instant.now();
const elapsed = (@as(f32, @floatFromInt(end.since(start))) / std.time.ns_per_s);
- std.debug.print("FPS: {d:.2}\r", .{ 1 / elapsed });
delta = elapsed * 60;
- try crtc.page_flip(&double_buffer);
+ try crtc.page_flip(&buffer);
while (true) {
var event: ?drm.Event = null;