mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
Fix shader time uniforms (#1462)
* fix shader time uniforms * renderer/metal: one typo --------- Co-authored-by: Mitchell Hashimoto <mitchell.hashimoto@gmail.com>
This commit is contained in:
@ -137,6 +137,11 @@ pub const CustomShaderState = struct {
|
||||
screen_texture: objc.Object, // MTLTexture
|
||||
sampler: mtl_sampler.Sampler,
|
||||
uniforms: mtl_shaders.PostUniforms,
|
||||
/// The first time a frame was drawn. This is used to update the time
|
||||
/// uniform.
|
||||
first_frame_time: std.time.Instant,
|
||||
/// The last time a frame was drawn. This is used to update the time
|
||||
/// uniform.
|
||||
last_frame_time: std.time.Instant,
|
||||
|
||||
pub fn deinit(self: *CustomShaderState) void {
|
||||
@ -412,6 +417,7 @@ pub fn init(alloc: Allocator, options: renderer.Options) !Metal {
|
||||
.sample_rate = 1,
|
||||
},
|
||||
|
||||
.first_frame_time = try std.time.Instant.now(),
|
||||
.last_frame_time = try std.time.Instant.now(),
|
||||
};
|
||||
};
|
||||
@ -757,10 +763,12 @@ pub fn drawFrame(self: *Metal, surface: *apprt.Surface) !void {
|
||||
|
||||
// If we have custom shaders, update the animation time.
|
||||
if (self.custom_shader_state) |*state| {
|
||||
const now = std.time.Instant.now() catch state.last_frame_time;
|
||||
const since_ns: f32 = @floatFromInt(now.since(state.last_frame_time));
|
||||
const now = std.time.Instant.now() catch state.first_frame_time;
|
||||
const since_ns: f32 = @floatFromInt(now.since(state.first_frame_time));
|
||||
const delta_ns: f32 = @floatFromInt(now.since(state.last_frame_time));
|
||||
state.uniforms.time = since_ns / std.time.ns_per_s;
|
||||
state.uniforms.time_delta = since_ns / std.time.ns_per_s;
|
||||
state.uniforms.time_delta = delta_ns / std.time.ns_per_s;
|
||||
state.last_frame_time = now;
|
||||
}
|
||||
|
||||
// @autoreleasepool {}
|
||||
|
@ -45,10 +45,14 @@ pub const State = struct {
|
||||
/// The set of programs for the custom shaders.
|
||||
programs: []const Program,
|
||||
|
||||
/// The last time the frame was drawn. This is used to update
|
||||
/// The first time a frame was drawn. This is used to update
|
||||
/// the time uniform.
|
||||
first_frame_time: std.time.Instant,
|
||||
|
||||
/// The last time a frame was drawn. This is used to update
|
||||
/// the time uniform.
|
||||
last_frame_time: std.time.Instant,
|
||||
|
||||
pub fn init(
|
||||
alloc: Allocator,
|
||||
srcs: []const [:0]const u8,
|
||||
@ -136,6 +140,7 @@ pub const State = struct {
|
||||
.ebo = ebo,
|
||||
.fb_texture = fb_tex,
|
||||
.first_frame_time = try std.time.Instant.now(),
|
||||
.last_frame_time = try std.time.Instant.now(),
|
||||
};
|
||||
}
|
||||
|
||||
@ -180,8 +185,10 @@ pub const State = struct {
|
||||
// Update our frame time
|
||||
const now = std.time.Instant.now() catch self.first_frame_time;
|
||||
const since_ns: f32 = @floatFromInt(now.since(self.first_frame_time));
|
||||
const delta_ns: f32 = @floatFromInt(now.since(self.last_frame_time));
|
||||
self.uniforms.time = since_ns / std.time.ns_per_s;
|
||||
self.uniforms.time_delta = since_ns / std.time.ns_per_s;
|
||||
self.uniforms.time_delta = delta_ns / std.time.ns_per_s;
|
||||
self.last_frame_time = now;
|
||||
|
||||
// Sync our uniform changes
|
||||
try self.syncUniforms();
|
||||
|
Reference in New Issue
Block a user