[Merged by Bors] - Support arbitrary RenderTarget texture formats#6380
[Merged by Bors] - Support arbitrary RenderTarget texture formats#6380cart wants to merge 4 commits intobevyengine:mainfrom
Conversation
alice-i-cecile
left a comment
There was a problem hiding this comment.
These changes make sense to me, code quality is good, and the explanation is solid.
|
bors r+ |
# Objective Currently, Bevy only supports rendering to the current "surface texture format". This means that "render to texture" scenarios must use the exact format the primary window's surface uses, or Bevy will crash. This is even harder than it used to be now that we detect preferred surface formats at runtime instead of using hard coded BevyDefault values. ## Solution 1. Look up and store each window surface's texture format alongside other extracted window information 2. Specialize the upscaling pass on the current `RenderTarget`'s texture format, now that we can cheaply correlate render targets to their current texture format 3. Remove the old `SurfaceTextureFormat` and `AvailableTextureFormats`: these are now redundant with the information stored on each extracted window, and probably should not have been globals in the first place (as in theory each surface could have a different format). This means you can now use any texture format you want when rendering to a texture! For example, changing the `render_to_texture` example to use `R16Float` now doesn't crash / properly only stores the red component: 
| } | ||
|
|
||
| /// Retrieves the [`TextureFormat`] of this render target, if it exists. | ||
| pub fn get_texture_format<'a>( |
There was a problem hiding this comment.
I'm slightly too late, but shouldn't this be called something like get_render_target_texture_format? And we could probably drop the get prefixes from this and similar functions.
There was a problem hiding this comment.
no firm position on my side on naming, but don't hesitate to open follow up PRs 👍
There was a problem hiding this comment.
We sometimes use "get" when either: (1) an option is returned or (2) it isn't a direct property of the object. This sort of falls into both categories, but I don't have super strong opinions here.
On the topic of get_render_target_texture_format: the "render target" is implicit as this type is RenderTarget. We wouldn't rename Window::position() to Window::window_position for the same reason.
# Objective Currently, Bevy only supports rendering to the current "surface texture format". This means that "render to texture" scenarios must use the exact format the primary window's surface uses, or Bevy will crash. This is even harder than it used to be now that we detect preferred surface formats at runtime instead of using hard coded BevyDefault values. ## Solution 1. Look up and store each window surface's texture format alongside other extracted window information 2. Specialize the upscaling pass on the current `RenderTarget`'s texture format, now that we can cheaply correlate render targets to their current texture format 3. Remove the old `SurfaceTextureFormat` and `AvailableTextureFormats`: these are now redundant with the information stored on each extracted window, and probably should not have been globals in the first place (as in theory each surface could have a different format). This means you can now use any texture format you want when rendering to a texture! For example, changing the `render_to_texture` example to use `R16Float` now doesn't crash / properly only stores the red component: 
# Objective Currently, Bevy only supports rendering to the current "surface texture format". This means that "render to texture" scenarios must use the exact format the primary window's surface uses, or Bevy will crash. This is even harder than it used to be now that we detect preferred surface formats at runtime instead of using hard coded BevyDefault values. ## Solution 1. Look up and store each window surface's texture format alongside other extracted window information 2. Specialize the upscaling pass on the current `RenderTarget`'s texture format, now that we can cheaply correlate render targets to their current texture format 3. Remove the old `SurfaceTextureFormat` and `AvailableTextureFormats`: these are now redundant with the information stored on each extracted window, and probably should not have been globals in the first place (as in theory each surface could have a different format). This means you can now use any texture format you want when rendering to a texture! For example, changing the `render_to_texture` example to use `R16Float` now doesn't crash / properly only stores the red component: 
Objective
Currently, Bevy only supports rendering to the current "surface texture format". This means that "render to texture" scenarios must use the exact format the primary window's surface uses, or Bevy will crash. This is even harder than it used to be now that we detect preferred surface formats at runtime instead of using hard coded BevyDefault values.
Solution
RenderTarget's texture format, now that we can cheaply correlate render targets to their current texture formatSurfaceTextureFormatandAvailableTextureFormats: these are now redundant with the information stored on each extracted window, and probably should not have been globals in the first place (as in theory each surface could have a different format).This means you can now use any texture format you want when rendering to a texture! For example, changing the

render_to_textureexample to useR16Floatnow doesn't crash / properly only stores the red component: