From df8a190e28f8fc9dd4efcdbe84570281479fa75d Mon Sep 17 00:00:00 2001 From: Andros Fenollosa Date: Tue, 2 Jun 2026 14:53:33 +0200 Subject: [PATCH] Metal: fix inline images rendering upside down mtl_texture_for_image flipped the CGBitmapContext CTM before drawing the NSImage, but an upright draw into a bitmap context already places the visual top of the image in the first memory row, which is what Metal's texture row 0 (V=0, top of the quad) expects. The extra flip was the lone inversion, so images came out upside down. Drop it. Verified with a top-red/bottom-blue probe: red now lands on top. --- src/mtlterm.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mtlterm.m b/src/mtlterm.m index a8a8338359c..ef824e4e927 100644 --- a/src/mtlterm.m +++ b/src/mtlterm.m @@ -1736,10 +1736,10 @@ mtl_texture_for_image (struct image *img) CGColorSpaceRelease (cs); if (!ctx) { free (px); return nil; } - /* Flip Y so that Metal's top-left origin matches */ - CGContextTranslateCTM (ctx, 0, (CGFloat)h); - CGContextScaleCTM (ctx, 1.0, -1.0); - + /* No CTM flip: drawing the image upright into a CGBitmapContext already puts + the visual top of the image in the first memory row, which is exactly what + Metal's texture row 0 (V=0, the top of the quad) expects. Flipping here + would invert the lone orientation and render the image upside down. */ NSGraphicsContext *gc = [NSGraphicsContext graphicsContextWithCGContext:ctx flipped:NO]; [NSGraphicsContext saveGraphicsState];