From fab1905e55237804433f0e77a6d3fdceb4b8b056 Mon Sep 17 00:00:00 2001 From: jack Date: Thu, 12 Dec 2024 21:19:15 +0800 Subject: [PATCH] cleanup software-renderer related code --- examples/hello.zig | 2 +- src/config.zig | 14 -------------- src/context.zig | 8 +------- src/renderer.zig | 20 +++----------------- src/vendor/physfs/physfs.zig | 4 ++-- 5 files changed, 7 insertions(+), 41 deletions(-) diff --git a/examples/hello.zig b/examples/hello.zig index 84f78be2..e906b18e 100644 --- a/examples/hello.zig +++ b/examples/hello.zig @@ -35,7 +35,7 @@ var suppress: bool = true; pub fn init(ctx: jok.Context) !void { std.log.info("game init", .{}); - try physfs.setWriteDir(physfs.getPrefDir(ctx)); + try physfs.setWriteDir(physfs.getPrefDir("myorg", "mygame")); batchpool_2d = try @TypeOf(batchpool_2d).init(ctx); batchpool_3d = try @TypeOf(batchpool_3d).init(ctx); diff --git a/src/config.zig b/src/config.zig index 2c92e6a2..2e739013 100644 --- a/src/config.zig +++ b/src/config.zig @@ -16,16 +16,6 @@ pub const Config = struct { /// Assets accessing method jok_enable_physfs: bool = true, - /// Application preference directory info - jok_pref_org: [*:0]const u8 = "myorg", - jok_pref_app: [*:0]const u8 = "mygame", - - /// Whether use pure-software renderer (NOTE: SDL might ignore this setting when GPU is available) - jok_software_renderer: bool = false, - - /// Whether fallback to software renderer when gpu isn't found - jok_software_renderer_fallback: bool = true, - /// Canvas size (default to framebuffer's size) jok_canvas_size: ?jok.Size = null, @@ -107,10 +97,6 @@ pub fn init(comptime game: anytype) Config { .{ .name = "jok_mem_leak_checks", .desc = "whether default memory allocator check memleak when exiting" }, .{ .name = "jok_mem_detail_logs", .desc = "whether default memory allocator print detailed memory alloc/free logs" }, .{ .name = "jok_enable_physfs", .desc = "whether use physfs to access game assets" }, - .{ .name = "jok_pref_org", .desc = "Org part of app preference path" }, - .{ .name = "jok_pref_app", .desc = "App part of app preference path" }, - .{ .name = "jok_software_renderer", .desc = "whether use software renderer" }, - .{ .name = "jok_software_renderer_fallback", .desc = "whether fallback to software renderer when hardware acceleration isn't available" }, .{ .name = "jok_canvas_size", .desc = "size of canvas" }, .{ .name = "jok_enable_post_processing", .desc = "whether enable post-processing facility" }, .{ .name = "jok_window_title", .desc = "title of window" }, diff --git a/src/context.zig b/src/context.zig index be86abe7..3821a903 100644 --- a/src/context.zig +++ b/src/context.zig @@ -197,7 +197,6 @@ pub fn JokContext(comptime cfg: config.Config) type { // Renderer instance _renderer: jok.Renderer = undefined, - _is_software: bool = false, // Rendering target _canvas_texture: jok.Texture = undefined, @@ -335,7 +334,7 @@ pub fn JokContext(comptime cfg: config.Config) type { ) void { const pc_threshold: u64 = switch (cfg.jok_fps_limit) { .none => 0, - .auto => if (self._is_software) @divTrunc(self._pc_freq, 30) else 0, + .auto => 0, .manual => |_fps| self._pc_freq / @as(u64, _fps), }; @@ -565,11 +564,9 @@ pub fn JokContext(comptime cfg: config.Config) type { \\ Platform : {s} \\ Memory : {d}MB \\ App Dir : {s} - \\ Data Dir : {s} \\ \\Renderer info: \\ Vertical Sync : {} - \\ GPU Enabled : {} \\ Max Texture Size : {d}*{d} \\ \\ @@ -586,9 +583,7 @@ pub fn JokContext(comptime cfg: config.Config) type { @tagName(target.os.tag), ram_size, physfs.getBaseDir(), - physfs.getPrefDir(self._ctx), info.flags & sdl.SDL_RENDERER_PRESENTVSYNC != 0, - info.flags & sdl.SDL_RENDERER_ACCELERATED != 0, info.max_texture_width, info.max_texture_height, }, @@ -897,7 +892,6 @@ pub fn JokContext(comptime cfg: config.Config) type { imgui.text("Window Size: {d:.0}x{d:.0}", .{ ws.width, ws.height }); imgui.text("Canvas Size: {d:.0}x{d:.0}", .{ cs.width, cs.height }); imgui.text("Display DPI: {d:.1}", .{self._display_dpi}); - imgui.text("GPU Enabled: {}", .{!self._is_software}); imgui.text("V-Sync Enabled: {}", .{rdinfo.flags & sdl.SDL_RENDERER_PRESENTVSYNC != 0}); imgui.text("Optimize Mode: {s}", .{@tagName(builtin.mode)}); imgui.separator(); diff --git a/src/renderer.zig b/src/renderer.zig index 62794a11..339ea135 100644 --- a/src/renderer.zig +++ b/src/renderer.zig @@ -26,28 +26,15 @@ pub const dcstats = struct { pub const Renderer = struct { ptr: *sdl.SDL_Renderer, - is_software: bool, cfg: jok.config.Config, // Create hardware accelerated renderer - // Fallback to software renderer if allowed pub fn init(cfg: jok.config.Config, window: jok.Window) !Renderer { - var flags: u32 = sdl.SDL_RENDERER_TARGETTEXTURE; - if (cfg.jok_software_renderer) { - flags |= sdl.SDL_RENDERER_SOFTWARE; - } + var flags: u32 = sdl.SDL_RENDERER_TARGETTEXTURE | sdl.SDL_RENDERER_ACCELERATED; if (cfg.jok_fps_limit == .auto) { flags |= sdl.SDL_RENDERER_PRESENTVSYNC; } - var ptr = sdl.SDL_CreateRenderer(window.ptr, -1, flags); - if (ptr == null and - !cfg.jok_software_renderer and - cfg.jok_software_renderer_fallback) - { - log.warn("Hardware accelerated renderer isn't supported, fallback to software backend", .{}); - flags |= sdl.SDL_RENDERER_SOFTWARE; - ptr = sdl.SDL_CreateRenderer(window.ptr, -1, flags); - } + const ptr = sdl.SDL_CreateRenderer(window.ptr, -1, flags); if (ptr == null) { log.err("create renderer failed: {s}", .{sdl.SDL_GetError()}); return sdl.Error.SdlError; @@ -55,12 +42,11 @@ pub const Renderer = struct { var rd = Renderer{ .ptr = ptr.?, - .is_software = undefined, .cfg = cfg, }; try rd.setBlendMode(.blend); const rdinfo = try rd.getInfo(); - rd.is_software = ((rdinfo.flags & sdl.SDL_RENDERER_SOFTWARE) != 0); + assert((rdinfo.flags & sdl.SDL_RENDERER_ACCELERATED) != 0); return rd; } diff --git a/src/vendor/physfs/physfs.zig b/src/vendor/physfs/physfs.zig index cdfea77d..75d59c65 100644 --- a/src/vendor/physfs/physfs.zig +++ b/src/vendor/physfs/physfs.zig @@ -103,8 +103,8 @@ pub fn getBaseDir() [*:0]const u8 { /// "/Users/bob/Library/Application Support/My Program Name" /// /// (etc.) -pub fn getPrefDir(ctx: jok.Context) [*:0]const u8 { - if (PHYSFS_getPrefDir(ctx.cfg().jok_pref_org, ctx.cfg().jok_pref_app)) |p| { +pub fn getPrefDir(org: [*:0]const u8, app: [*:0]const u8) [*:0]const u8 { + if (PHYSFS_getPrefDir(org, app)) |p| { return p; } @panic("can't get data dir");