diff --git a/crates/bevy_render/src/camera.rs b/crates/bevy_render/src/camera.rs index cb5bcb2500bbe..bb8d50b220af7 100644 --- a/crates/bevy_render/src/camera.rs +++ b/crates/bevy_render/src/camera.rs @@ -213,9 +213,9 @@ impl NormalizedRenderTargetExt for NormalizedRenderTarget { NormalizedRenderTarget::Image(image_target) => images .get(&image_target.handle) .map(|image| image.texture_format), - NormalizedRenderTarget::TextureView(id) => { - manual_texture_views.get(id).map(|tex| tex.format) - } + NormalizedRenderTarget::TextureView(id) => manual_texture_views + .get(id) + .map(|view| view.texture_view.texture().format()), NormalizedRenderTarget::None { .. } => None, } } diff --git a/crates/bevy_render/src/texture/manual_texture_view.rs b/crates/bevy_render/src/texture/manual_texture_view.rs index b9faa84ab78f6..b03943d3c2750 100644 --- a/crates/bevy_render/src/texture/manual_texture_view.rs +++ b/crates/bevy_render/src/texture/manual_texture_view.rs @@ -1,10 +1,8 @@ use bevy_camera::ManualTextureViewHandle; use bevy_ecs::{prelude::Component, resource::Resource}; -use bevy_image::BevyDefault; use bevy_math::UVec2; use bevy_platform::collections::HashMap; use bevy_render_macros::ExtractResource; -use wgpu::TextureFormat; use crate::render_resource::TextureView; @@ -13,16 +11,11 @@ use crate::render_resource::TextureView; pub struct ManualTextureView { pub texture_view: TextureView, pub size: UVec2, - pub format: TextureFormat, } impl ManualTextureView { - pub fn with_default_format(texture_view: TextureView, size: UVec2) -> Self { - Self { - texture_view, - size, - format: TextureFormat::bevy_default(), - } + pub fn new(texture_view: TextureView, size: UVec2) -> Self { + Self { texture_view, size } } } @@ -36,7 +29,7 @@ impl ManualTextureView { /// # world.insert_resource(ManualTextureViews::default()); /// # let texture_view = todo!(); /// let manual_views = world.resource_mut::(); -/// let manual_view = ManualTextureView::with_default_format(texture_view, UVec2::new(1024, 1024)); +/// let manual_view = ManualTextureView::new(texture_view, UVec2::new(1024, 1024)); /// /// // Choose an unused handle value; it's likely only you are inserting manual views. /// const MANUAL_VIEW_HANDLE: ManualTextureViewHandle = ManualTextureViewHandle::new(42); diff --git a/crates/bevy_render/src/texture/texture_attachment.rs b/crates/bevy_render/src/texture/texture_attachment.rs index 269c2f1422820..26588212683c1 100644 --- a/crates/bevy_render/src/texture/texture_attachment.rs +++ b/crates/bevy_render/src/texture/texture_attachment.rs @@ -1,5 +1,5 @@ use super::CachedTexture; -use crate::render_resource::{TextureFormat, TextureView}; +use crate::render_resource::TextureView; use alloc::sync::Arc; use bevy_color::LinearRgba; use core::sync::atomic::{AtomicBool, Ordering}; @@ -127,15 +127,13 @@ impl DepthAttachment { #[derive(Clone)] pub struct OutputColorAttachment { pub view: TextureView, - pub format: TextureFormat, is_first_call: Arc, } impl OutputColorAttachment { - pub fn new(view: TextureView, format: TextureFormat) -> Self { + pub fn new(view: TextureView) -> Self { Self { view, - format, is_first_call: Arc::new(AtomicBool::new(true)), } } diff --git a/crates/bevy_render/src/view/mod.rs b/crates/bevy_render/src/view/mod.rs index 040d0ce7bc3cc..3c105a5774250 100644 --- a/crates/bevy_render/src/view/mod.rs +++ b/crates/bevy_render/src/view/mod.rs @@ -838,7 +838,7 @@ impl ViewTarget { /// The format of the final texture this view will render to #[inline] pub fn out_texture_format(&self) -> TextureFormat { - self.out_texture.format + self.out_texture.view.texture().format() } /// This will start a new "post process write", which assumes that the caller @@ -1014,10 +1014,7 @@ pub fn prepare_view_attachments( let Some(attachment) = target .get_texture_view(&windows, &images, &manual_texture_views) .cloned() - .zip(target.get_texture_format(&windows, &images, &manual_texture_views)) - .map(|(view, format)| { - OutputColorAttachment::new(view.clone(), format.add_srgb_suffix()) - }) + .map(OutputColorAttachment::new) else { continue; }; @@ -1086,11 +1083,7 @@ pub fn prepare_view_targets( dimension: TextureDimension::D2, format: main_texture_format, usage: texture_usage.0, - view_formats: match main_texture_format { - TextureFormat::Bgra8Unorm => &[TextureFormat::Bgra8UnormSrgb], - TextureFormat::Rgba8Unorm => &[TextureFormat::Rgba8UnormSrgb], - _ => &[], - }, + view_formats: &[], }; let a = texture_cache.get( &render_device, diff --git a/crates/bevy_render/src/view/window/screenshot.rs b/crates/bevy_render/src/view/window/screenshot.rs index 638d3cf7c6b68..4e908e63a23cd 100644 --- a/crates/bevy_render/src/view/window/screenshot.rs +++ b/crates/bevy_render/src/view/window/screenshot.rs @@ -293,7 +293,7 @@ fn prepare_screenshots( prepared.insert(*entity, state); view_target_attachments.insert( target.clone(), - OutputColorAttachment::new(texture_view.clone(), format.add_srgb_suffix()), + OutputColorAttachment::new(texture_view.clone()), ); } NormalizedRenderTarget::Image(image) => { @@ -313,7 +313,7 @@ fn prepare_screenshots( prepared.insert(*entity, state); view_target_attachments.insert( target.clone(), - OutputColorAttachment::new(texture_view.clone(), format.add_srgb_suffix()), + OutputColorAttachment::new(texture_view.clone()), ); } NormalizedRenderTarget::TextureView(texture_view) => { @@ -324,7 +324,7 @@ fn prepare_screenshots( ); continue; }; - let format = manual_texture_view.format; + let format = manual_texture_view.texture_view.texture().format(); let size = manual_texture_view.size.to_extents(); let (texture_view, state) = prepare_screenshot_state( size, @@ -337,7 +337,7 @@ fn prepare_screenshots( prepared.insert(*entity, state); view_target_attachments.insert( target.clone(), - OutputColorAttachment::new(texture_view.clone(), format.add_srgb_suffix()), + OutputColorAttachment::new(texture_view.clone()), ); } NormalizedRenderTarget::None { .. } => { @@ -548,7 +548,7 @@ pub(crate) fn submit_screenshot_commands(world: &World, encoder: &mut CommandEnc }; let width = texture_view.size.x; let height = texture_view.size.y; - let texture_format = texture_view.format; + let texture_format = texture_view.texture_view.texture().format(); let texture_view = texture_view.texture_view.deref(); render_screenshot( encoder,