Skip to content

Commit 07396cc

Browse files
committed
change new_target_texture to take TextureFormat
1 parent 4cea4e3 commit 07396cc

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

crates/bevy_image/src/image.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -823,14 +823,12 @@ impl Image {
823823
/// Create a new zero-filled image with a given size, which can be rendered to. This is primarily
824824
/// for use as a render target for a [`Camera`]. See [`RenderTarget::Image`].
825825
///
826+
/// You can use [TEXTURE_FORMAT_SDR] and [TEXTURE_FORMAT_HDR]
827+
/// for Standard Dynamic Range (SDR) and High Dynamic Range (HDR) respectively.
828+
///
826829
/// [`Camera`]: https://docs.rs/bevy/latest/bevy/render/camera/struct.Camera.html
827830
/// [`RenderTarget::Image`]: https://docs.rs/bevy/latest/bevy/render/camera/enum.RenderTarget.html#variant.Image
828-
pub fn new_target_texture(width: u32, height: u32, hdr: bool) -> Self {
829-
let format = if hdr {
830-
TEXTURE_FORMAT_HDR
831-
} else {
832-
TEXTURE_FORMAT_SDR
833-
};
831+
pub fn new_target_texture(width: u32, height: u32, format: TextureFormat) -> Self {
834832
let size = Extent3d {
835833
width,
836834
height,
@@ -844,7 +842,7 @@ impl Image {
844842
let data = vec![0; format.pixel_size() * size.volume()];
845843

846844
Image {
847-
data,
845+
data: Some(data),
848846
texture_descriptor: TextureDescriptor {
849847
size,
850848
format,

examples/3d/render_to_texture.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use std::f32::consts::PI;
44

5-
use bevy::{prelude::*, render::view::RenderLayers};
5+
use bevy::{image::TEXTURE_FORMAT_SDR, prelude::*, render::view::RenderLayers};
66

77
fn main() {
88
App::new()
@@ -27,7 +27,7 @@ fn setup(
2727
mut images: ResMut<Assets<Image>>,
2828
) {
2929
// This is the texture that will be rendered to.
30-
let image = Image::new_target_texture(512, 512, false);
30+
let image = Image::new_target_texture(512, 512, TEXTURE_FORMAT_SDR);
3131

3232
let image_handle = images.add(image);
3333

examples/shader/compute_shader_game_of_life.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,8 @@ fn main() {
5151
}
5252

5353
fn setup(mut commands: Commands, mut images: ResMut<Assets<Image>>) {
54-
let mut image = Image::new_target_texture(SIZE.0, SIZE.1, false);
54+
let mut image = Image::new_target_texture(SIZE.0, SIZE.1, TextureFormat::R32Float);
5555
image.asset_usage = RenderAssetUsages::RENDER_WORLD;
56-
image.texture_descriptor.format = TextureFormat::R32Float;
5756
image.texture_descriptor.usage =
5857
TextureUsages::COPY_DST | TextureUsages::STORAGE_BINDING | TextureUsages::TEXTURE_BINDING;
5958
let image0 = images.add(image.clone());

0 commit comments

Comments
 (0)