diff --git a/src/gfx/gfx.zig b/src/gfx/gfx.zig index 19ec459..45b02b2 100644 --- a/src/gfx/gfx.zig +++ b/src/gfx/gfx.zig @@ -119,7 +119,7 @@ pub const Command = union (enum) { draw_font: DrawFont, draw_texture: DrawTexture, set_effect: SetEffect, - set_scissor: SetScissor, + set_scissor_rect: ?Rect, set_target: SetTarget, pub const DrawFont = struct { @@ -147,10 +147,6 @@ pub const Command = union (enum) { properties: []const u8, }; - pub const SetScissor = struct { - has_rect: ?Rect, - }; - pub const SetTarget = struct { texture: ?Texture = null, clear_color: ?Color, @@ -261,8 +257,8 @@ pub const Commands = struct { }); } - pub fn set_scissor(self: Self, command: Command.SetScissor) std.mem.Allocator.Error!void { - try self.pending.stack.push_grow(.{.set_scissor = command}); + pub fn set_scissor_rect(self: Self, has_rect: Rect) std.mem.Allocator.Error!void { + try self.pending.stack.push_grow(.{.set_scissor_rect = has_rect}); } pub fn set_target(self: Self, command: Command.SetTarget) std.mem.Allocator.Error!void { diff --git a/src/gfx/rendering.zig b/src/gfx/rendering.zig index f964d2f..37bc952 100644 --- a/src/gfx/rendering.zig +++ b/src/gfx/rendering.zig @@ -224,10 +224,10 @@ const Frame = struct { } } - pub fn set_scissor(self: *Frame, resources: *Resources, command: gfx.Command.SetScissor) void { + pub fn set_scissor_rect(self: *Frame, resources: *Resources, has_rect: gfx.Rect) void { self.flush(resources); - if (command.has_rect) |rect| { + if (has_rect) |rect| { const width, const height = rect.size(); sokol.gfx.applyScissorRect( @@ -428,7 +428,7 @@ pub fn process_work(pending_work: *gfx.Assets.WorkQueue, window: *ext.SDL_Window .draw_font => |draw_font| frame.draw_font(&resources, draw_font), .draw_texture => |draw_texture| frame.draw_texture(&resources, draw_texture), .set_effect => |set_effect| frame.set_effect(&resources, set_effect), - .set_scissor => |set_scissor| frame.set_scissor(&resources, set_scissor), + .set_scissor_rect => |has_rect| frame.set_scissor_rect(&resources, has_rect), .set_target => |set_target| frame.set_target(&resources, set_target), }; } diff --git a/src/gui/gui.zig b/src/gui/gui.zig index f877d78..087be75 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -202,9 +202,7 @@ pub fn exit(canvas: ona.Write(Canvas)) !void { pub fn render(commands: gfx.Commands, canvas: ona.Read(Canvas)) !void { // TODO: Investigate if scissor rects are necessary for clipping content that overflows. for (canvas.state.drawable_blocks.values()) |block| { - try commands.set_scissor(.{ - .has_rect = block.clip, - }); + try commands.set_scissor_rect(block.clip); try commands.draw_texture(.{ .size = .{block.box.width, block.box.height}, @@ -216,9 +214,7 @@ pub fn render(commands: gfx.Commands, canvas: ona.Read(Canvas)) !void { } for (canvas.state.drawable_labels.values()) |label| { - try commands.set_scissor(.{ - .has_rect = label.clip, - }); + try commands.set_scissor_rect(label.clip); try commands.draw_font(.{ .size = .{label.box.width, label.box.height}, @@ -229,10 +225,6 @@ pub fn render(commands: gfx.Commands, canvas: ona.Read(Canvas)) !void { .font = label.state.font, }); } - - try commands.set_scissor(.{ - .has_rect = null, - }); } pub fn setup(world: *ona.World) !void {