diff --git a/crates/bevy_image/src/image.rs b/crates/bevy_image/src/image.rs index 7e8633151d..af328d0d76 100644 --- a/crates/bevy_image/src/image.rs +++ b/crates/bevy_image/src/image.rs @@ -846,14 +846,12 @@ impl Image { /// Create a new zero-filled image with a given size, which can be rendered to. This is primarily /// for use as a render target for a [`Camera`]. See [`RenderTarget::Image`]. /// + /// You can use [`TEXTURE_FORMAT_SDR`] and [`TEXTURE_FORMAT_HDR`] + /// for Standard Dynamic Range (SDR) and High Dynamic Range (HDR) respectively. + /// /// [`Camera`]: https://docs.rs/bevy/latest/bevy/render/camera/struct.Camera.html /// [`RenderTarget::Image`]: https://docs.rs/bevy/latest/bevy/render/camera/enum.RenderTarget.html#variant.Image - pub fn new_target_texture(width: u32, height: u32, hdr: bool) -> Self { - let format = if hdr { - TEXTURE_FORMAT_HDR - } else { - TEXTURE_FORMAT_SDR - }; + pub fn new_target_texture(width: u32, height: u32, format: TextureFormat) -> Self { let size = Extent3d { width, height, @@ -867,7 +865,7 @@ impl Image { let data = vec![0; format.pixel_size() * size.volume()]; Image { - data, + data: Some(data), texture_descriptor: TextureDescriptor { size, format, diff --git a/examples/3d/render_to_texture.rs b/examples/3d/render_to_texture.rs index f5e7d2667d..5ba3ec7010 100644 --- a/examples/3d/render_to_texture.rs +++ b/examples/3d/render_to_texture.rs @@ -2,7 +2,7 @@ use std::f32::consts::PI; -use bevy::{prelude::*, render::view::RenderLayers}; +use bevy::{image::TEXTURE_FORMAT_SDR, prelude::*, render::view::RenderLayers}; fn main() { App::new() @@ -27,7 +27,7 @@ fn setup( mut images: ResMut>, ) { // This is the texture that will be rendered to. - let image = Image::new_target_texture(512, 512, false); + let image = Image::new_target_texture(512, 512, TEXTURE_FORMAT_SDR); let image_handle = images.add(image); diff --git a/examples/shader/compute_shader_game_of_life.rs b/examples/shader/compute_shader_game_of_life.rs index 5f209e73c9..a11767f06f 100644 --- a/examples/shader/compute_shader_game_of_life.rs +++ b/examples/shader/compute_shader_game_of_life.rs @@ -51,9 +51,8 @@ fn main() { } fn setup(mut commands: Commands, mut images: ResMut>) { - let mut image = Image::new_target_texture(SIZE.0, SIZE.1, false); + let mut image = Image::new_target_texture(SIZE.0, SIZE.1, TextureFormat::R32Float); image.asset_usage = RenderAssetUsages::RENDER_WORLD; - image.texture_descriptor.format = TextureFormat::R32Float; image.texture_descriptor.usage = TextureUsages::COPY_DST | TextureUsages::STORAGE_BINDING | TextureUsages::TEXTURE_BINDING; let image0 = images.add(image.clone());