godot
godot copied to clipboard
Metal: Implement `texture_create_from_extension`
This PR implements texture_create_from_extension()
for Metal.
The Vulkan device driver implements texture_create_from_extension()
to handle externally backed textures (OpenXR module, or otherwise), which takes an incoming VkImage
, creates a view, and returns it as TextureID
.
https://github.com/godotengine/godot/blob/e4e024ab88efe74677769395886bc1b09eccbac7/drivers/vulkan/rendering_device_driver_vulkan.cpp#L1745-L1750
For Metal, there is no exact equivalent to Vulkan's VkImageView
, so for this driver we only need to cast the incoming handle to id<MTLTexture>
, then return as TextureID
.
Parameters p_type
, p_format
, p_array_layers
, p_depth_stencil
are ignored - MTLTexture
(and the callee) already have this information and is only relevant when reinterpreting or remaping the texture in different ways.
The use of __bridge
with void*
in the casting is to signal we are not transferring ownership, and is a safe cast to bridge from C-style memory to Objective-C memory management (but correct me if I'm wrong).
loosely related to #96860