SDL: Fixed support for SDL_PROP_TEXTURE_CREATE_METAL_PIXELBUFFER_POINTER

From b212874def245431b751c67c1bffc93af23a82da Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Fri, 31 Jul 2026 15:24:36 -0700
Subject: [PATCH] Fixed support for
 SDL_PROP_TEXTURE_CREATE_METAL_PIXELBUFFER_POINTER

---
 src/render/metal/SDL_render_metal.m | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/render/metal/SDL_render_metal.m b/src/render/metal/SDL_render_metal.m
index 332c1ca06281a..ccef22aa97b18 100644
--- a/src/render/metal/SDL_render_metal.m
+++ b/src/render/metal/SDL_render_metal.m
@@ -792,7 +792,11 @@ static bool METAL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SD
 
         mtltexture = (__bridge id<MTLTexture>)SDL_GetPointerProperty(create_props, SDL_PROP_TEXTURE_CREATE_METAL_TEXTURE_POINTER, nil);
         if (mtltexture == nil) {
-            mtltexture = [data.mtldevice newTextureWithDescriptor:mtltexdesc];
+            if (surface) {
+                mtltexture = [data.mtldevice newTextureWithDescriptor:mtltexdesc iosurface:surface plane:0];
+            } else {
+                mtltexture = [data.mtldevice newTextureWithDescriptor:mtltexdesc];
+            }
         }
         if (mtltexture == nil) {
             return SDL_SetError("Texture allocation failed");
@@ -847,7 +851,11 @@ static bool METAL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SD
         } else if (nv12) {
             mtltexture = (__bridge id<MTLTexture>)SDL_GetPointerProperty(create_props, SDL_PROP_TEXTURE_CREATE_METAL_TEXTURE_UV_POINTER, nil);
             if (mtltexture == nil) {
-                mtltexture = [data.mtldevice newTextureWithDescriptor:mtltexdesc];
+                if (surface) {
+                    mtltexture = [data.mtldevice newTextureWithDescriptor:mtltexdesc iosurface:surface plane:1];
+                } else {
+                    mtltexture = [data.mtldevice newTextureWithDescriptor:mtltexdesc];
+                }
             }
             if (mtltexture == nil) {
                 return SDL_SetError("Texture allocation failed");