From a285d1aa989e5d16aa31eeeacc26bf71006137e2 Mon Sep 17 00:00:00 2001 From: David Snopek Date: Tue, 25 Feb 2025 14:04:51 -0600 Subject: [PATCH] `texture_create_from_native_handle()` should return `RID` for texture from `RenderingServer`, not `RenderingDevice` --- doc/classes/RenderingServer.xml | 2 +- .../rendering/renderer_rd/storage_rd/texture_storage.cpp | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/doc/classes/RenderingServer.xml b/doc/classes/RenderingServer.xml index d4a1a67dea6..7ccaf880ee2 100644 --- a/doc/classes/RenderingServer.xml +++ b/doc/classes/RenderingServer.xml @@ -3725,7 +3725,7 @@ Creates a texture based on a native handle that was created outside of Godot's renderer. - [b]Note:[/b] If using the rendering device renderer, using [method RenderingDevice.texture_create_from_extension] rather than this method is recommended. It will give you much more control over the texture's format and usage. + [b]Note:[/b] If using only the rendering device renderer, it's recommend to use [method RenderingDevice.texture_create_from_extension] together with [method RenderingServer.texture_rd_create], rather than this method. It will give you much more control over the texture's format and usage. diff --git a/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp b/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp index 5707b993afc..02b28473951 100644 --- a/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp +++ b/servers/rendering/renderer_rd/storage_rd/texture_storage.cpp @@ -1292,7 +1292,12 @@ RID TextureStorage::texture_create_from_native_handle(RS::TextureType p_type, Im // Assumed to be a color attachment - see note above. uint64_t usage_flags = RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT; - return RD::get_singleton()->texture_create_from_extension(type, format, RD::TEXTURE_SAMPLES_1, usage_flags, p_native_handle, p_width, p_height, p_depth, p_layers); + RID rd_texture = RD::get_singleton()->texture_create_from_extension(type, format, RD::TEXTURE_SAMPLES_1, usage_flags, p_native_handle, p_width, p_height, p_depth, p_layers); + + RID texture = texture_allocate(); + texture_rd_initialize(texture, rd_texture, p_layered_type); + + return texture; } void TextureStorage::_texture_2d_update(RID p_texture, const Ref &p_image, int p_layer, bool p_immediate) {