Godot Version
Godot Engine v4.4.1.stable.mono
Question
Hey!
I just tried using the RenderingDevice.texture_update interface to update the texture data in the RenderingDevice. During testing, I noticed that the texture_update interface call seems to have no effect.
After calling texture_update, I used the texture_get_data interface to retrieve the data from the texture, but the returned value is not the data I passed in for the update. Could you please tell me why this is happening? Is there an issue with how I am using the interface?
Here’s the relevant code :
func _ready() -> void:
rd = RenderingServer.get_rendering_device()
var new_image = Image.new()
new_image.load("res://test.png")
print(var_to_str(new_image.get_format()))
new_image.convert(Image.FORMAT_RGBA8)
print(var_to_str(new_image.get_format()))
var tf := RDTextureFormat.new()
tf.format = RenderingDevice.DATA_FORMAT_R8G8B8A8_UINT#RenderingDevice.DATA_FORMAT_R8G8B8_SRGB
tf.texture_type = RenderingDevice.TEXTURE_TYPE_2D
tf.width = new_image.get_width()
tf.height = new_image.get_height()
tf.depth = 1
tf.array_layers = 1
tf.mipmaps = 1
tf.usage_bits = (
RenderingDevice.TEXTURE_USAGE_CAN_UPDATE_BIT |
RenderingDevice.TEXTURE_USAGE_CPU_READ_BIT |
RenderingDevice.TEXTURE_USAGE_CAN_COPY_FROM_BIT |
RenderingDevice.TEXTURE_USAGE_CAN_COPY_TO_BIT
)
var texture_rd = rd.texture_create(tf, RDTextureView.new(), [])
var ret = rd.texture_update(texture_rd, 0, new_image.get_data())
var ret_data = rd.texture_get_data(texture_rd, 0)
if ret_data && !ret_data.is_empty():
new_image = Image.create_from_data(new_image.get_width(), new_image.get_height(), false, Image.FORMAT_RGBA8, ret_data)
new_image.save_png("ret_save.png")
return