change new_target_texture to take TextureFormat
This commit is contained in:
parent
a2d8f253a9
commit
ae0ee4f0e2
@ -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,
|
||||
|
@ -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<Assets<Image>>,
|
||||
) {
|
||||
// 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);
|
||||
|
||||
|
@ -51,9 +51,8 @@ fn main() {
|
||||
}
|
||||
|
||||
fn setup(mut commands: Commands, mut images: ResMut<Assets<Image>>) {
|
||||
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());
|
||||
|
Loading…
Reference in New Issue
Block a user