Skip to content

Commit 39cd3af

Browse files
feat: getting started on compositor example
1 parent 8a693d6 commit 39cd3af

File tree

4 files changed

+74
-20
lines changed

4 files changed

+74
-20
lines changed

build.zig

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,34 @@ const Phantom = @import("phantom");
44
pub fn build(b: *std.Build) void {
55
const target = b.standardTargetOptions(.{});
66
const optimize = b.standardOptimizeOption(.{});
7-
const backend = b.option(Phantom.BackendType, "backend", "The backend to use for the example") orelse .headless;
7+
const display_backend = b.option(Phantom.DisplayBackendType, "display-backend", "The display backend to use for the example") orelse .headless;
8+
const scene_backend = b.option(Phantom.SceneBackendType, "scene-backend", "The scene backend to use for the example") orelse .headless;
89

910
const phantom = b.dependency("phantom", .{
1011
.target = target,
1112
.optimize = optimize,
1213
});
1314

14-
_ = b.addModule("phantom", .{
15-
.source_file = .{
16-
.path = phantom.builder.pathFromRoot(phantom.module("phantom").source_file.path),
17-
},
15+
const vizops = b.dependency("vizops", .{
16+
.target = target,
17+
.optimize = optimize,
1818
});
1919

2020
const options = b.addOptions();
21-
options.addOption(Phantom.BackendType, "backend", backend);
21+
options.addOption(Phantom.DisplayBackendType, "display_backend", display_backend);
22+
options.addOption(Phantom.SceneBackendType, "scene_backend", scene_backend);
2223

23-
const exe = b.addExecutable(.{
24-
.name = "example",
24+
const exe_compositor = b.addExecutable(.{
25+
.name = "compositor",
2526
.root_source_file = .{
26-
.path = b.pathFromRoot("src/example.zig"),
27+
.path = b.pathFromRoot("src/compositor.zig"),
2728
},
2829
.target = target,
2930
.optimize = optimize,
3031
});
3132

32-
exe.addModule("phantom", phantom.module("phantom"));
33-
exe.addOptions("options", options);
34-
b.installArtifact(exe);
33+
exe_compositor.addModule("phantom", phantom.module("phantom"));
34+
exe_compositor.addModule("vizops", vizops.module("vizops"));
35+
exe_compositor.addOptions("options", options);
36+
b.installArtifact(exe_compositor);
3537
}

build.zig.zon

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,17 @@
77
.url = "https://github.com/PhantomUIx/i18n/archive/941945e730a50520dfbc44825612b71b86e9a6f7.tar.gz",
88
.hash = "12202590d5272332603b3f472931f1c2a3e2a25ed5e3981f8f3e00271fa545634be3",
99
},
10+
.@"phantom.display.uefi" = .{
11+
.url = "https://github.com/PhantomUIx/display-uefi/archive/01c93ae609c6764fdd2eda1db0fbe6ebc8d7349d.tar.gz",
12+
.hash = "12204a36b9c591f605575b456bb979721b004fb4834cb2a4841a012ec31bb8c7f8eb",
13+
},
1014
.phantom = .{
11-
.url = "https://github.com/PhantomUIx/core/archive/c96b5b99475ce0c5ba0d2cb337ed93b70ba65373.tar.gz",
12-
.hash = "1220807d0a350b9ad6be23b53888b8a3c920a96072be1251b319f68aee555972022d",
15+
.url = "https://github.com/PhantomUIx/core/archive/a7cdd480decac2812e66301b7494137f6a3d5d03.tar.gz",
16+
.hash = "12206e7a39b76d73547275140e0df9e27191a27f237685955c404471cbf3c79e1cdb",
17+
},
18+
.vizops = .{
19+
.url = "https://github.com/MidstallSoftware/vizops/archive/7a1b49fea05d75cabc920c247eba0274e91bf967.tar.gz",
20+
.hash = "12208e6d1334b77b2ac9351867da74dbce8f8470ea0367ffa1531fcf42e22b631371",
1321
},
1422
},
1523
}

src/compositor.zig

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
const std = @import("std");
2+
const options = @import("options");
3+
const phantom = @import("phantom");
4+
const vizops = @import("vizops");
5+
6+
pub fn main() !void {
7+
const alloc = std.heap.page_allocator;
8+
9+
const displayBackendType = comptime std.meta.stringToEnum(phantom.display.BackendType, @tagName(options.display_backend)).?;
10+
const displayBackend = phantom.display.Backend(displayBackendType);
11+
12+
const sceneBackendType = comptime std.meta.stringToEnum(phantom.scene.BackendType, @tagName(options.scene_backend)).?;
13+
14+
var display = displayBackend.Display.init(alloc, .compositor);
15+
defer display.deinit();
16+
17+
if (displayBackendType == .headless) {
18+
_ = try display.addOutput(.{
19+
.enable = true,
20+
.size = .{
21+
.phys = vizops.vector.Float32Vector2.init([_]f32{ 306, 229.5 }),
22+
.res = vizops.vector.UsizeVector2.init([_]usize{ 1024, 768 }),
23+
},
24+
.scale = vizops.vector.Float32Vector2.init(1.0),
25+
.name = "display-0",
26+
.manufacturer = "PhantomUI",
27+
.format = try vizops.color.fourcc.Value.decode(vizops.color.fourcc.formats.argb16161616),
28+
});
29+
}
30+
31+
const outputs = try @constCast(&display.display()).outputs();
32+
defer outputs.deinit();
33+
34+
if (outputs.items.len == 0) {
35+
return error.NoOutputs;
36+
}
37+
38+
const output = outputs.items[0];
39+
const surface = try output.createSurface(.output, .{
40+
.size = (try output.info()).size.res,
41+
});
42+
defer {
43+
surface.destroy() catch {};
44+
surface.deinit();
45+
}
46+
47+
const scene = try surface.createScene(sceneBackendType);
48+
_ = scene;
49+
// TODO: render something to the scene
50+
}

src/example.zig

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)