From 3ca25237545812112ef3813aadd4319775ed982a Mon Sep 17 00:00:00 2001 From: Beyley Thomas Date: Wed, 6 Mar 2024 18:02:41 -0800 Subject: [PATCH] it worky :) --- game/app.zig | 37 +++++++++++++++++++++++-------------- game/gfx.zig | 15 ++++++++++++--- game/screens/main_menu.zig | 2 +- game/shader.wgsl | 35 ++++++++++++++++++----------------- 4 files changed, 54 insertions(+), 35 deletions(-) diff --git a/game/app.zig b/game/app.zig index baef6cc..d08660e 100644 --- a/game/app.zig +++ b/game/app.zig @@ -16,6 +16,11 @@ const AudioTracker = @import("audio_tracker.zig"); pub const App = @This(); +pub const mach_core_options = core.ComptimeOptions{ + .use_wgpu = true, + .use_sysgpu = false, +}; + is_running: bool, ///The tracker for our audio state audio_tracker: AudioTracker, @@ -44,16 +49,17 @@ fontstash: Fontstash, screen_stack: ScreenStack, pub fn init(app: *App) !void { + const config = try Config.readConfig(); + + const width: u32 = @intFromFloat(640 * config.window_scale); + const height: u32 = @intFromFloat(480 * config.window_scale); + try core.init(.{ .title = "ilo nanpa pi ilo nanpa", .power_preference = .low_power, + .size = .{ .width = width, .height = height }, }); - const config = try Config.readConfig(); - - //Initialize our graphics - var gfx: Gfx = try Gfx.init(app.config); - app.* = .{ .is_running = true, .audio_tracker = .{ @@ -66,7 +72,7 @@ pub fn init(app: *App) !void { .counter_curr = 0, .config = config, .name = undefined, - .gfx = try Gfx.init(config), + .gfx = try Gfx.init(app.config), .texture = try Gfx.createTexture(core.allocator, @embedFile("content/atlas.qoi")), .renderer = undefined, .fontstash = undefined, @@ -74,30 +80,32 @@ pub fn init(app: *App) !void { }; std.debug.print("loaded {d} maps!\n", .{app.map_list.len}); - const bass_window_ptr: usize = 0; + const bass_window_ptr: usize = if (builtin.os.tag == .windows) + core.nativeWindowWin32() + else + 0; try bass.init(.default, null, .{}, bass_window_ptr); - defer bass.deinit(); try bass.setConfig(.global_stream_volume, @intFromFloat(app.config.volume * 10000)); //Create the bind group for the texture - // try texture.createBindGroup(gfx.device, gfx.sampler, gfx.bind_group_layouts); + try app.texture.createBindGroup(app.gfx.sampler, app.gfx.bind_group_layouts); - gfx.updateProjectionMatrixBuffer(); + app.gfx.updateProjectionMatrixBuffer(); //Init the renderer - app.renderer = try Renderer.init(core.allocator, &gfx, app.texture); + app.renderer = try Renderer.init(core.allocator, &app.gfx, app.texture); //Init the font stash try app.fontstash.init(&app.gfx, core.allocator); //Load the main menu - try app.screen_stack.load(&Screen.MainMenu.MainMenu, gfx, app); + try app.screen_stack.load(&Screen.MainMenu.MainMenu, app.gfx, app); } pub fn deinit(app: *App) void { - defer core.deinit(); + defer bass.deinit(); defer app.gfx.deinit(); defer app.texture.deinit(); defer app.fontstash.deinit(); @@ -125,8 +133,9 @@ pub fn deinit(app: *App) void { app.convert.deinit(); } - app.gfx.deinit(); app.renderer.deinit(); + + core.deinit(); } pub fn update(app: *App) !bool { diff --git a/game/gfx.zig b/game/gfx.zig index 9bd08c6..6c077aa 100644 --- a/game/gfx.zig +++ b/game/gfx.zig @@ -131,7 +131,7 @@ pub fn init(config: Config) !Self { .min = .{ .width = width, .height = height }, .max = .{ .width = width, .height = height }, }); - core.setSize(.{ .width = width, .height = height }); + // core.setSize(.{ .width = width, .height = height }); //Update the viewport self.viewport = RectU{ 0, 0, @intCast(width), @intCast(height) }; @@ -153,12 +153,22 @@ pub fn init(config: Config) !Self { //Create the projection matrix buffer self.projection_matrix_buffer = try createBuffer(math.Mat4x4, 1, .{ .uniform = true, .copy_dst = true }); + std.debug.print("got proj matrix buffer {*}\n", .{self.projection_matrix_buffer}); //Create the projection matrix bind group self.projection_matrix_bind_group = core.device.createBindGroup(&core.gpu.BindGroup.Descriptor.init(.{ .label = "Projection Matrix Bind Group", .layout = self.bind_group_layouts.projection_matrix, - .entries = &.{core.gpu.BindGroup.Entry.buffer(0, self.projection_matrix_buffer, 0, @sizeOf(math.Mat4x4))}, + .entries = &.{ + core.gpu.BindGroup.Entry.buffer( + 0, + self.projection_matrix_buffer, + 0, + @sizeOf(math.Mat4x4), + // REENABLE THIS TO FIX SYSGPU + // @sizeOf(math.Mat4x4), + ), + }, })); std.debug.print("got projection matrix bind group {*}\n", .{self.projection_matrix_bind_group}); @@ -540,7 +550,6 @@ pub fn updateProjectionMatrixBuffer(self: *Self) void { 1, ); - std.debug.print("thsathss {}\n", .{mat}); core.queue.writeBuffer(self.projection_matrix_buffer, 0, &[_]math.Mat4x4{mat}); } diff --git a/game/screens/main_menu.zig b/game/screens/main_menu.zig index 88ef16d..eb8ee24 100644 --- a/game/screens/main_menu.zig +++ b/game/screens/main_menu.zig @@ -110,7 +110,7 @@ pub fn renderScreen(self: *Screen, render_state: RenderState) anyerror!void { _ = try render_state.fontstash.drawText( .{ Screen.display_width - 10, Screen.display_height - 10 }, - "(c)2023 Beyley", + "(c)2024 Beyley", .{ .font = Fontstash.Gothic, .size = Fontstash.ptToPx(16), diff --git a/game/shader.wgsl b/game/shader.wgsl index f67e1d8..d167d52 100644 --- a/game/shader.wgsl +++ b/game/shader.wgsl @@ -24,7 +24,7 @@ fn vs_main( ) -> VertexOutputs { var output: VertexOutputs; - output.position = projection_matrix * vec4(pos, 0.0, 1.0); + output.position = vec4(pos, 0.0, 1.0) * projection_matrix; output.tex_coord = tex_coord; output.vertex_col = vertex_col; @@ -44,23 +44,24 @@ fn fs_main(input: FragmentInputs) -> @location(0) vec4 { fn toLinear(sRGB: vec4) -> vec4 { - var cutoff: vec4 = vec4(0.0); + return sRGB; + // var cutoff: vec4 = vec4(0.0); - if(sRGB.r < 0.04045) { - cutoff.r = 1.0; - } - if(sRGB.g < 0.04045) { - cutoff.g = 1.0; - } - if(sRGB.b < 0.04045) { - cutoff.b = 1.0; - } - if(sRGB.a < 0.04045) { - cutoff.a = 1.0; - } + // if(sRGB.r < 0.04045) { + // cutoff.r = 1.0; + // } + // if(sRGB.g < 0.04045) { + // cutoff.g = 1.0; + // } + // if(sRGB.b < 0.04045) { + // cutoff.b = 1.0; + // } + // if(sRGB.a < 0.04045) { + // cutoff.a = 1.0; + // } - var higher: vec4 = pow((sRGB + vec4(0.055))/vec4(1.055), vec4(2.4)); - var lower: vec4 = sRGB/vec4(12.92); + // var higher: vec4 = pow((sRGB + vec4(0.055))/vec4(1.055), vec4(2.4)); + // var lower: vec4 = sRGB/vec4(12.92); - return mix(higher, lower, cutoff); + // return mix(higher, lower, cutoff); }