Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/bevy_render/src/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down
13 changes: 3 additions & 10 deletions crates/bevy_render/src/texture/manual_texture_view.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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 }
}
}

Expand All @@ -36,7 +29,7 @@ impl ManualTextureView {
/// # world.insert_resource(ManualTextureViews::default());
/// # let texture_view = todo!();
/// let manual_views = world.resource_mut::<ManualTextureViews>();
/// 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);
Expand Down
6 changes: 2 additions & 4 deletions crates/bevy_render/src/texture/texture_attachment.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -127,15 +127,13 @@ impl DepthAttachment {
#[derive(Clone)]
pub struct OutputColorAttachment {
pub view: TextureView,
pub format: TextureFormat,
is_first_call: Arc<AtomicBool>,
}

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)),
}
}
Expand Down
13 changes: 3 additions & 10 deletions crates/bevy_render/src/view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like an important distinction here

}

/// This will start a new "post process write", which assumes that the caller
Expand Down Expand Up @@ -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())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the fix for the linked issue, no longer include the sRGB suffix.

})
.map(OutputColorAttachment::new)
else {
continue;
};
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions crates/bevy_render/src/view/window/screenshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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) => {
Expand All @@ -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,
Expand All @@ -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 { .. } => {
Expand Down Expand Up @@ -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,
Expand Down