Skip to content

Commit

Permalink
core: comments, examples: fix core-custom-entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
foxnne committed Nov 30, 2024
1 parent 59826b4 commit ffed03b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 10 additions & 6 deletions examples/core-custom-entrypoint/App.zig
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,18 @@ pub fn init(
core.on_tick = app_mod.id.tick;
core.on_exit = app_mod.id.deinit;

const main_window = core.windows.getValue(core.main_window);

// Create our shader module
const shader_module = core.device.createShaderModuleWGSL("shader.wgsl", @embedFile("shader.wgsl"));
const shader_module = main_window.device.createShaderModuleWGSL("shader.wgsl", @embedFile("shader.wgsl"));
defer shader_module.release();

// Blend state describes how rendered colors get blended
const blend = gpu.BlendState{};

// Color target describes e.g. the pixel format of the window we are rendering to.
const color_target = gpu.ColorTargetState{
.format = core.windows.get(core.main_window, .framebuffer_format).?,
.format = main_window.framebuffer_format,
.blend = &blend,
};

Expand All @@ -58,7 +60,7 @@ pub fn init(
.entry_point = "vertex_main",
},
};
const pipeline = core.device.createRenderPipeline(&pipeline_descriptor);
const pipeline = main_window.device.createRenderPipeline(&pipeline_descriptor);

// Store our render pipeline in our module's state, so we can access it later on.
app.* = .{
Expand All @@ -78,14 +80,16 @@ pub fn tick(core: *mach.Core, app: *App) !void {
}
}

const main_window = core.windows.getValue(core.main_window);

// Grab the back buffer of the swapchain
// TODO(Core)
const back_buffer_view = core.swap_chain.getCurrentTextureView().?;
const back_buffer_view = main_window.swap_chain.getCurrentTextureView().?;
defer back_buffer_view.release();

// Create a command encoder
const label = @tagName(mach_module) ++ ".tick";
const encoder = core.device.createCommandEncoder(&.{ .label = label });
const encoder = main_window.device.createCommandEncoder(&.{ .label = label });
defer encoder.release();

// Begin render pass
Expand All @@ -112,7 +116,7 @@ pub fn tick(core: *mach.Core, app: *App) !void {
// Submit our commands to the queue
var command = encoder.finish(&.{ .label = label });
defer command.release();
core.queue.submit(&[_]*gpu.CommandBuffer{command});
main_window.queue.submit(&[_]*gpu.CommandBuffer{command});

// update the window title every second
if (app.title_timer.read() >= 1.0) {
Expand Down
2 changes: 2 additions & 0 deletions src/Core.zig
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ windows: mach.Objects(
framebuffer_format: gpu.Texture.Format = .bgra8_unorm,

/// Width of the framebuffer in texels (read-only)
/// Will be updated to reflect the actual framebuffer dimensions after window creation.
framebuffer_width: u32 = 1920 / 2,

/// Height of the framebuffer in texels (read-only)
/// Will be updated to reflect the actual framebuffer dimensions after window creation.
framebuffer_height: u32 = 1080 / 2,

/// Vertical sync mode, prevents screen tearing.
Expand Down

0 comments on commit ffed03b

Please sign in to comment.