iOS lock step keyboard + metal

This commit is contained in:
agra
2026-05-18 17:40:10 +03:00
parent b43472e6ab
commit f9ecf9d00e
68 changed files with 4794 additions and 203 deletions

View File

@@ -3,6 +3,7 @@
#import "modules/gpu/types.sx";
#import "modules/gpu/api.sx";
#import "modules/stb_truetype.sx";
#import "modules/stb.sx";
#import "modules/ui/types.sx";
// Cached glyph data with UV coordinates into the atlas texture
@@ -426,17 +427,26 @@ GlyphCache :: struct {
context.allocator.dealloc(old_vals);
}
// Upload dirty atlas to GPU
// Upload dirty atlas to GPU. On the Metal path, defer the upload to
// end-of-frame (`upload_atlas_to_gpu`) — calling `replaceRegion:` against
// the same R8 MTLTexture multiple times within one frame garbles the
// contents on iOS-sim Metal. The dirty flag carries over so the final
// end-of-frame upload picks up every rasterization that happened during
// the frame's render pass.
flush :: (self: *GlyphCache) {
if self.dirty == false { return; }
if self.has_gpu {
self.gpu.update_texture_region(self.texture_id, 0, 0,
self.atlas_width, self.atlas_height, xx self.bitmap);
} else {
glBindTexture(GL_TEXTURE_2D, self.texture_id);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, self.atlas_width, self.atlas_height, GL_RED, GL_UNSIGNED_BYTE, self.bitmap);
}
if self.has_gpu { return; }
glBindTexture(GL_TEXTURE_2D, self.texture_id);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, self.atlas_width, self.atlas_height, GL_RED, GL_UNSIGNED_BYTE, self.bitmap);
self.dirty = false;
}
upload_atlas_to_gpu :: (self: *GlyphCache) {
if self.has_gpu == false { return; }
if self.dirty == false { return; }
self.gpu.update_texture_region(self.texture_id, 0, 0,
self.atlas_width, self.atlas_height, xx self.bitmap);
self.dirty = false;
}