godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.15k stars 97 forks source link

Implement updating texture data from a byte array directly #5342

Open kisg opened 2 years ago

kisg commented 2 years ago

Describe the project you are working on

Various AR / VR projects. In particular we implemented passthrough AR on the Oculus Quest 2 with the Foxus add-on camera.

Describe the problem or limitation you are having in your project

Currently to update the texture data of an ImageTexture, one has to first convert / wrap the byte array into an image, and after that set that image in the ImageTexture. This adds a lot of overhead that results in suboptimal performance. In our use case we have to update the image texture with new data for every rendered frame, while targeting high framerates (60 in the Foxus case, 90 / 120 in other projects).

Describe the feature / enhancement and how it helps to overcome the problem or limitation

We propose to implement additional methods on the Texture classes that allow updating the image data directly from a byte array. In addition, it should be possible to only use part of the supplied array (e.g. if the array contains data for multiple textures).

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

A PR was submitted for 3.x that implements the proposed feature: https://github.com/godotengine/godot/pull/65360

We are ready to implement these changes for the master branch as well. We are also happy to modify the proposed interfaces based on the review comments.

The implementation was done by Migeran while working on the Foxus project. The work was sponsored by Voxels.

If this enhancement will not be used often, can it be worked around with a few lines of script?

No.

Is there a reason why this should be core and not an add-on in the asset library?

It is a core feature.

Calinou commented 2 years ago

Related to https://github.com/godotengine/godot-proposals/issues/2158 and https://github.com/godotengine/godot-proposals/issues/3917.

Redwarx008 commented 1 year ago

We really need a way to update the texture directly to avoid a lot of copy overhead (especially important for large textures).

Calinou commented 1 year ago

@Redwarx008 Please don't bump issues without contributing significant new information. Use the :+1: reaction button on the first post instead.