renderer: add cursor color to custom shader uniforms

This commit is contained in:
Qwerasd
2025-06-22 11:02:16 -06:00
parent bb576d1340
commit d0ff2452d5
3 changed files with 28 additions and 16 deletions

View File

@@ -677,6 +677,8 @@ pub fn Renderer(comptime GraphicsAPI: type) type {
.sample_rate = 0, // N/A, we don't have any audio
.current_cursor = @splat(0),
.previous_cursor = @splat(0),
.current_cursor_color = @splat(0),
.previous_cursor_color = @splat(0),
.cursor_change_time = 0,
},
@@ -2012,25 +2014,31 @@ pub fn Renderer(comptime GraphicsAPI: type) type {
pixel_y += cursor_height;
}
const cursor_changed: bool =
pixel_x != self.custom_shader_uniforms.current_cursor[0] or
pixel_y != self.custom_shader_uniforms.current_cursor[1] or
cursor_width != self.custom_shader_uniforms.current_cursor[2] or
cursor_height != self.custom_shader_uniforms.current_cursor[3];
if (cursor_changed) {
self.custom_shader_uniforms.previous_cursor =
self.custom_shader_uniforms.current_cursor;
self.custom_shader_uniforms.current_cursor = .{
const new_cursor: [4]f32 = .{
pixel_x,
pixel_y,
cursor_width,
cursor_height,
};
const cursor_color: [4]f32 = .{
@as(f32, @floatFromInt(cursor.color[0])) / 255.0,
@as(f32, @floatFromInt(cursor.color[1])) / 255.0,
@as(f32, @floatFromInt(cursor.color[2])) / 255.0,
@as(f32, @floatFromInt(cursor.color[3])) / 255.0,
};
self.custom_shader_uniforms.cursor_change_time =
self.custom_shader_uniforms.time;
const uniforms = &self.custom_shader_uniforms;
const cursor_changed: bool =
!std.meta.eql(new_cursor, uniforms.current_cursor) or
!std.meta.eql(cursor_color, uniforms.current_cursor_color);
if (cursor_changed) {
uniforms.previous_cursor = uniforms.current_cursor;
uniforms.previous_cursor_color = uniforms.current_cursor_color;
uniforms.current_cursor = new_cursor;
uniforms.current_cursor_color = cursor_color;
uniforms.cursor_change_time = uniforms.time;
}
}
}

View File

@@ -13,6 +13,8 @@ layout(binding = 1, std140) uniform Globals {
uniform float iSampleRate;
uniform vec4 iCurrentCursor;
uniform vec4 iPreviousCursor;
uniform vec4 iCurrentCursorColor;
uniform vec4 iPreviousCursorColor;
uniform float iTimeCursorChange;
};

View File

@@ -23,6 +23,8 @@ pub const Uniforms = extern struct {
sample_rate: f32 align(4),
current_cursor: [4]f32 align(16),
previous_cursor: [4]f32 align(16),
current_cursor_color: [4]f32 align(16),
previous_cursor_color: [4]f32 align(16),
cursor_change_time: f32 align(4),
};