Core: store framebuffer information as components
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
656b0202f2
commit
03a089610b
5 changed files with 25 additions and 5 deletions
|
|
@ -23,7 +23,7 @@ fn init(game: *Mod, core: *mach.Core.Mod) !void {
|
||||||
|
|
||||||
// Color target describes e.g. the pixel format of the window we are rendering to.
|
// Color target describes e.g. the pixel format of the window we are rendering to.
|
||||||
const color_target = gpu.ColorTargetState{
|
const color_target = gpu.ColorTargetState{
|
||||||
.format = mach.core.descriptor.format,
|
.format = core.get(core.state().main_window, .framebuffer_format).?,
|
||||||
.blend = &blend,
|
.blend = &blend,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ fn init(
|
||||||
// Fragment state
|
// Fragment state
|
||||||
const blend = gpu.BlendState{};
|
const blend = gpu.BlendState{};
|
||||||
const color_target = gpu.ColorTargetState{
|
const color_target = gpu.ColorTargetState{
|
||||||
.format = mach.core.descriptor.format,
|
.format = core.get(core.state().main_window, .framebuffer_format).?,
|
||||||
.blend = &blend,
|
.blend = &blend,
|
||||||
.write_mask = gpu.ColorWriteMaskFlags.all,
|
.write_mask = gpu.ColorWriteMaskFlags.all,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
22
src/Core.zig
22
src/Core.zig
|
|
@ -1,5 +1,7 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const mach = @import("main.zig");
|
const mach = @import("main.zig");
|
||||||
|
const gpu = mach.gpu;
|
||||||
|
|
||||||
// TODO(important): mach.core has a lot of standard Zig APIs, and some global variables, which are
|
// TODO(important): mach.core has a lot of standard Zig APIs, and some global variables, which are
|
||||||
// part of its old API design. We should elevate them into this module instead.
|
// part of its old API design. We should elevate them into this module instead.
|
||||||
|
|
@ -45,6 +47,18 @@ pub const components = .{
|
||||||
\\ If setting this component yourself, ensure the buffer is allocated using core.state().allocator
|
\\ If setting this component yourself, ensure the buffer is allocated using core.state().allocator
|
||||||
\\ as it will be freed for you as part of the .deinit event.
|
\\ as it will be freed for you as part of the .deinit event.
|
||||||
},
|
},
|
||||||
|
|
||||||
|
.framebuffer_format = .{ .type = gpu.Texture.Format, .description =
|
||||||
|
\\ The texture format of the framebuffer
|
||||||
|
},
|
||||||
|
|
||||||
|
.framebuffer_width = .{ .type = u32, .description =
|
||||||
|
\\ The width of the framebuffer in texels
|
||||||
|
},
|
||||||
|
|
||||||
|
.framebuffer_height = .{ .type = u32, .description =
|
||||||
|
\\ The width of the framebuffer in texels
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Prints into the window title buffer using a format string and arguments. e.g.
|
/// Prints into the window title buffer using a format string and arguments. e.g.
|
||||||
|
|
@ -78,11 +92,17 @@ fn init(core: *Mod) !void {
|
||||||
mach.core.allocator = gpa.allocator(); // TODO: banish this global allocator
|
mach.core.allocator = gpa.allocator(); // TODO: banish this global allocator
|
||||||
try mach.core.init(.{});
|
try mach.core.init(.{});
|
||||||
|
|
||||||
|
// TODO(important): update this information upon framebuffer resize events
|
||||||
|
const main_window = try core.newEntity();
|
||||||
|
try core.set(main_window, .framebuffer_format, mach.core.descriptor.format);
|
||||||
|
try core.set(main_window, .framebuffer_width, mach.core.descriptor.width);
|
||||||
|
try core.set(main_window, .framebuffer_height, mach.core.descriptor.height);
|
||||||
|
|
||||||
core.init(.{
|
core.init(.{
|
||||||
.allocator = mach.core.allocator,
|
.allocator = mach.core.allocator,
|
||||||
.device = mach.core.device,
|
.device = mach.core.device,
|
||||||
.queue = mach.core.device.getQueue(),
|
.queue = mach.core.device.getQueue(),
|
||||||
.main_window = try core.newEntity(),
|
.main_window = main_window,
|
||||||
});
|
});
|
||||||
|
|
||||||
core.sendGlobal(.init, .{});
|
core.sendGlobal(.init, .{});
|
||||||
|
|
|
||||||
|
|
@ -281,7 +281,7 @@ fn buildPipeline(
|
||||||
defer shader_module.release();
|
defer shader_module.release();
|
||||||
|
|
||||||
const color_target = opt_color_target_state orelse gpu.ColorTargetState{
|
const color_target = opt_color_target_state orelse gpu.ColorTargetState{
|
||||||
.format = mach.core.descriptor.format,
|
.format = core.get(core.state().main_window, .framebuffer_format).?,
|
||||||
.blend = &blend_state,
|
.blend = &blend_state,
|
||||||
.write_mask = gpu.ColorWriteMaskFlags.all,
|
.write_mask = gpu.ColorWriteMaskFlags.all,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -307,7 +307,7 @@ fn buildPipeline(
|
||||||
defer shader_module.release();
|
defer shader_module.release();
|
||||||
|
|
||||||
const color_target = opt_color_target_state orelse gpu.ColorTargetState{
|
const color_target = opt_color_target_state orelse gpu.ColorTargetState{
|
||||||
.format = mach.core.descriptor.format,
|
.format = core.get(core.state().main_window, .framebuffer_format).?,
|
||||||
.blend = &blend_state,
|
.blend = &blend_state,
|
||||||
.write_mask = gpu.ColorWriteMaskFlags.all,
|
.write_mask = gpu.ColorWriteMaskFlags.all,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue