{gfx,examples}: use core.state().device
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
bffc668005
commit
79dccb4d73
6 changed files with 16 additions and 22 deletions
|
|
@ -13,9 +13,9 @@ pub const global_events = .{
|
||||||
title_timer: mach.Timer,
|
title_timer: mach.Timer,
|
||||||
pipeline: *gpu.RenderPipeline,
|
pipeline: *gpu.RenderPipeline,
|
||||||
|
|
||||||
fn init(game: *Mod) !void {
|
fn init(game: *Mod, core: *mach.Core.Mod) !void {
|
||||||
// Create our shader module
|
// Create our shader module
|
||||||
const shader_module = mach.core.device.createShaderModuleWGSL("shader.wgsl", @embedFile("shader.wgsl"));
|
const shader_module = core.state().device.createShaderModuleWGSL("shader.wgsl", @embedFile("shader.wgsl"));
|
||||||
defer shader_module.release();
|
defer shader_module.release();
|
||||||
|
|
||||||
// Blend state describes how rendered colors get blended
|
// Blend state describes how rendered colors get blended
|
||||||
|
|
@ -44,7 +44,7 @@ fn init(game: *Mod) !void {
|
||||||
.entry_point = "vertex_main",
|
.entry_point = "vertex_main",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const pipeline = mach.core.device.createRenderPipeline(&pipeline_descriptor);
|
const pipeline = core.state().device.createRenderPipeline(&pipeline_descriptor);
|
||||||
|
|
||||||
// Store our render pipeline in our module's state, so we can access it later on.
|
// Store our render pipeline in our module's state, so we can access it later on.
|
||||||
game.init(.{
|
game.init(.{
|
||||||
|
|
@ -59,10 +59,7 @@ pub fn deinit(game: *Mod) void {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(important): remove need for returning an error here
|
// TODO(important): remove need for returning an error here
|
||||||
fn tick(
|
fn tick(core: *mach.Core.Mod, game: *Mod) !void {
|
||||||
core: *mach.Core.Mod,
|
|
||||||
game: *Mod,
|
|
||||||
) !void {
|
|
||||||
// TODO(important): event polling should occur in mach.Core module and get fired as ECS event.
|
// TODO(important): event polling should occur in mach.Core module and get fired as ECS event.
|
||||||
var iter = mach.core.pollEvents();
|
var iter = mach.core.pollEvents();
|
||||||
while (iter.next()) |event| {
|
while (iter.next()) |event| {
|
||||||
|
|
@ -78,7 +75,7 @@ fn tick(
|
||||||
|
|
||||||
// Create a command encoder
|
// Create a command encoder
|
||||||
const label = @tagName(name) ++ ".tick";
|
const label = @tagName(name) ++ ".tick";
|
||||||
const encoder = mach.core.device.createCommandEncoder(&.{ .label = label });
|
const encoder = core.state().device.createCommandEncoder(&.{ .label = label });
|
||||||
defer encoder.release();
|
defer encoder.release();
|
||||||
|
|
||||||
// Begin render pass
|
// Begin render pass
|
||||||
|
|
|
||||||
|
|
@ -42,10 +42,7 @@ pub const local_events = .{
|
||||||
.end_frame = .{ .handler = endFrame },
|
.end_frame = .{ .handler = endFrame },
|
||||||
};
|
};
|
||||||
|
|
||||||
fn init(
|
fn init(glyphs: *Glyphs.Mod, game: *Mod) !void {
|
||||||
glyphs: *Glyphs.Mod,
|
|
||||||
game: *Mod,
|
|
||||||
) !void {
|
|
||||||
// Prepare which glyphs we will render
|
// Prepare which glyphs we will render
|
||||||
glyphs.send(.init, .{});
|
glyphs.send(.init, .{});
|
||||||
glyphs.send(.prepare, .{&[_]u21{ '?', '!', 'a', 'b', '#', '@', '%', '$', '&', '^', '*', '+', '=', '<', '>', '/', ':', ';', 'Q', '~' }});
|
glyphs.send(.prepare, .{&[_]u21{ '?', '!', 'a', 'b', '#', '@', '%', '$', '&', '^', '*', '+', '=', '<', '>', '/', ':', ';', 'Q', '~' }});
|
||||||
|
|
@ -203,7 +200,7 @@ fn tick(
|
||||||
|
|
||||||
// Create a command encoder for this frame
|
// Create a command encoder for this frame
|
||||||
const label = @tagName(name) ++ ".tick";
|
const label = @tagName(name) ++ ".tick";
|
||||||
game.state().frame_encoder = mach.core.device.createCommandEncoder(&.{ .label = label });
|
game.state().frame_encoder = core.state().device.createCommandEncoder(&.{ .label = label });
|
||||||
|
|
||||||
// Grab the back buffer of the swapchain
|
// Grab the back buffer of the swapchain
|
||||||
const back_buffer_view = mach.core.swap_chain.getCurrentTextureView().?;
|
const back_buffer_view = mach.core.swap_chain.getCurrentTextureView().?;
|
||||||
|
|
@ -218,7 +215,7 @@ fn tick(
|
||||||
.store_op = .store,
|
.store_op = .store,
|
||||||
}};
|
}};
|
||||||
// TODO: can we eliminate this assignment
|
// TODO: can we eliminate this assignment
|
||||||
game.state().frame_encoder = mach.core.device.createCommandEncoder(&.{ .label = label });
|
game.state().frame_encoder = core.state().device.createCommandEncoder(&.{ .label = label });
|
||||||
game.state().frame_render_pass = game.state().frame_encoder.beginRenderPass(&gpu.RenderPassDescriptor.init(.{
|
game.state().frame_render_pass = game.state().frame_encoder.beginRenderPass(&gpu.RenderPassDescriptor.init(.{
|
||||||
.label = label,
|
.label = label,
|
||||||
.color_attachments = &color_attachments,
|
.color_attachments = &color_attachments,
|
||||||
|
|
|
||||||
|
|
@ -184,7 +184,7 @@ fn tick(
|
||||||
|
|
||||||
// Create a command encoder for this frame
|
// Create a command encoder for this frame
|
||||||
const label = @tagName(name) ++ ".tick";
|
const label = @tagName(name) ++ ".tick";
|
||||||
game.state().frame_encoder = mach.core.device.createCommandEncoder(&.{ .label = label });
|
game.state().frame_encoder = core.state().device.createCommandEncoder(&.{ .label = label });
|
||||||
|
|
||||||
// Grab the back buffer of the swapchain
|
// Grab the back buffer of the swapchain
|
||||||
const back_buffer_view = mach.core.swap_chain.getCurrentTextureView().?;
|
const back_buffer_view = mach.core.swap_chain.getCurrentTextureView().?;
|
||||||
|
|
@ -199,7 +199,7 @@ fn tick(
|
||||||
.store_op = .store,
|
.store_op = .store,
|
||||||
}};
|
}};
|
||||||
// TODO: can we eliminate this assignment
|
// TODO: can we eliminate this assignment
|
||||||
game.state().frame_encoder = mach.core.device.createCommandEncoder(&.{ .label = label });
|
game.state().frame_encoder = core.state().device.createCommandEncoder(&.{ .label = label });
|
||||||
game.state().frame_render_pass = game.state().frame_encoder.beginRenderPass(&gpu.RenderPassDescriptor.init(.{
|
game.state().frame_render_pass = game.state().frame_encoder.beginRenderPass(&gpu.RenderPassDescriptor.init(.{
|
||||||
.label = label,
|
.label = label,
|
||||||
.color_attachments = &color_attachments,
|
.color_attachments = &color_attachments,
|
||||||
|
|
|
||||||
|
|
@ -228,7 +228,7 @@ fn tick(
|
||||||
|
|
||||||
// Create a command encoder for this frame
|
// Create a command encoder for this frame
|
||||||
const label = @tagName(name) ++ ".tick";
|
const label = @tagName(name) ++ ".tick";
|
||||||
game.state().frame_encoder = mach.core.device.createCommandEncoder(&.{ .label = label });
|
game.state().frame_encoder = core.state().device.createCommandEncoder(&.{ .label = label });
|
||||||
|
|
||||||
// Grab the back buffer of the swapchain
|
// Grab the back buffer of the swapchain
|
||||||
const back_buffer_view = mach.core.swap_chain.getCurrentTextureView().?;
|
const back_buffer_view = mach.core.swap_chain.getCurrentTextureView().?;
|
||||||
|
|
@ -242,7 +242,7 @@ fn tick(
|
||||||
.load_op = .clear,
|
.load_op = .clear,
|
||||||
.store_op = .store,
|
.store_op = .store,
|
||||||
}};
|
}};
|
||||||
game.state().frame_encoder = mach.core.device.createCommandEncoder(&.{ .label = label });
|
game.state().frame_encoder = core.state().device.createCommandEncoder(&.{ .label = label });
|
||||||
game.state().frame_render_pass = game.state().frame_encoder.beginRenderPass(&gpu.RenderPassDescriptor.init(.{
|
game.state().frame_render_pass = game.state().frame_encoder.beginRenderPass(&gpu.RenderPassDescriptor.init(.{
|
||||||
.label = label,
|
.label = label,
|
||||||
.color_attachments = &color_attachments,
|
.color_attachments = &color_attachments,
|
||||||
|
|
|
||||||
|
|
@ -325,9 +325,9 @@ fn buildPipeline(
|
||||||
try sprite_pipeline.set(pipeline_id, .num_sprites, 0);
|
try sprite_pipeline.set(pipeline_id, .num_sprites, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn preRender(sprite_pipeline: *Mod) void {
|
fn preRender(sprite_pipeline: *Mod, core: *mach.Core.Mod) void {
|
||||||
const label = @tagName(name) ++ ".preRender";
|
const label = @tagName(name) ++ ".preRender";
|
||||||
const encoder = mach.core.device.createCommandEncoder(&.{ .label = label });
|
const encoder = core.state().device.createCommandEncoder(&.{ .label = label });
|
||||||
defer encoder.release();
|
defer encoder.release();
|
||||||
|
|
||||||
var archetypes_iter = sprite_pipeline.entities.query(.{ .all = &.{
|
var archetypes_iter = sprite_pipeline.entities.query(.{ .all = &.{
|
||||||
|
|
|
||||||
|
|
@ -350,9 +350,9 @@ fn buildPipeline(
|
||||||
try text_pipeline.set(pipeline_id, .num_glyphs, 0);
|
try text_pipeline.set(pipeline_id, .num_glyphs, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn preRender(text_pipeline: *Mod) void {
|
fn preRender(text_pipeline: *Mod, core: *mach.Core.Mod) void {
|
||||||
const label = @tagName(name) ++ ".preRender";
|
const label = @tagName(name) ++ ".preRender";
|
||||||
const encoder = mach.core.device.createCommandEncoder(&.{ .label = label });
|
const encoder = core.state().device.createCommandEncoder(&.{ .label = label });
|
||||||
defer encoder.release();
|
defer encoder.release();
|
||||||
|
|
||||||
var archetypes_iter = text_pipeline.entities.query(.{ .all = &.{
|
var archetypes_iter = text_pipeline.entities.query(.{ .all = &.{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue