renderer/metal: use new atlas APIs

This commit is contained in:
Mitchell Hashimoto
2024-04-05 21:13:10 -07:00
parent de2b0f6857
commit 29b172b3ac

View File

@ -118,6 +118,8 @@ queue: objc.Object, // MTLCommandQueue
layer: objc.Object, // CAMetalLayer layer: objc.Object, // CAMetalLayer
texture_greyscale: objc.Object, // MTLTexture texture_greyscale: objc.Object, // MTLTexture
texture_color: objc.Object, // MTLTexture texture_color: objc.Object, // MTLTexture
texture_greyscale_modified: usize = 0,
texture_color_modified: usize = 0,
/// Custom shader state. This is only set if we have custom shaders. /// Custom shader state. This is only set if we have custom shaders.
custom_shader_state: ?CustomShaderState = null, custom_shader_state: ?CustomShaderState = null,
@ -774,13 +776,21 @@ pub fn drawFrame(self: *Metal, surface: *apprt.Surface) !void {
}; };
// If our font atlas changed, sync the texture data // If our font atlas changed, sync the texture data
if (self.font_group.atlas_greyscale.modified) { texture: {
try syncAtlasTexture(self.device, &self.font_group.atlas_greyscale, &self.texture_greyscale); const modified = self.font_grid.atlas_greyscale.modified.load(.monotonic);
self.font_group.atlas_greyscale.modified = false; if (modified <= self.texture_greyscale_modified) break :texture;
self.font_grid.lock.lockShared();
defer self.font_grid.lock.unlockShared();
self.texture_greyscale_modified = self.font_grid.atlas_greyscale.modified.load(.monotonic);
try syncAtlasTexture(self.device, &self.font_grid.atlas_greyscale, &self.texture_greyscale);
} }
if (self.font_group.atlas_color.modified) { texture: {
try syncAtlasTexture(self.device, &self.font_group.atlas_color, &self.texture_color); const modified = self.font_grid.atlas_color.modified.load(.monotonic);
self.font_group.atlas_color.modified = false; if (modified <= self.texture_color_modified) break :texture;
self.font_grid.lock.lockShared();
defer self.font_grid.lock.unlockShared();
self.texture_color_modified = self.font_grid.atlas_color.modified.load(.monotonic);
try syncAtlasTexture(self.device, &self.font_grid.atlas_color, &self.texture_color);
} }
// Command buffer (MTLCommandBuffer) // Command buffer (MTLCommandBuffer)