Add support for BGRA textures with Texture*RD #98258
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Adds the ability to use BGRA textures created with RenderingDevice with classes such as Texture2DRD, which removes the need to unnecessarily convert from BGRA to RGBA.
Motivation and Context
I am creating a native GDExtension plugin for Godot that allows the ability to capture the screen, or specific windows, or possibly a game, as a texture, which is updated every frame. The over-arching goal is to give streamers the ability to composite their stream almost entirely in Godot if they so choose, allowing the ability for streamers to create some totally sick streamer setups.
However, after getting my plugin working, I noticed that BGRA textures created via
RenderingDevice::texture_create()
are not supported when you use them withTexture2DRD::set_texture_rd_rid()
, even though they are supported by the device. This seems to be an unnecessary and arbitrary limitation due to the fact that Image::Format enum does not have BGRA.This fix eliminates a completely unnecessary format conversion when one has a genuine need for BGRA texture support and needs to update textures frequently. Manually converting BGRA to RGBA every frame here would be an absolutely wasteful and pointless performance hit, especially when capturing 4K monitors which have a very large texture size, so I would preferably like to patch Godot to support BGRA so we don't have to do a conversion every frame.
How Has This Been Tested?
I tested this with capturing in real time and it works without issue. This should also not cause any sort of regression or affect anyone else because Godot did not originally allow this before this PR, thus no one's workflows should be affected by this.