Skip to content

Commit def974c

Browse files
committed
Revert "Support non-sRGB image formats for RenderTarget::Image (bevyengine#22031)"
This reverts commit 000ddca.
1 parent 2d4e140 commit def974c

5 files changed

Lines changed: 32 additions & 16 deletions

File tree

crates/bevy_render/src/camera.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,9 @@ impl NormalizedRenderTargetExt for NormalizedRenderTarget {
213213
NormalizedRenderTarget::Image(image_target) => images
214214
.get(&image_target.handle)
215215
.map(|image| image.texture_format),
216-
NormalizedRenderTarget::TextureView(id) => manual_texture_views
217-
.get(id)
218-
.map(|view| view.texture_view.texture().format()),
216+
NormalizedRenderTarget::TextureView(id) => {
217+
manual_texture_views.get(id).map(|tex| tex.format)
218+
}
219219
NormalizedRenderTarget::None { .. } => None,
220220
}
221221
}

crates/bevy_render/src/texture/manual_texture_view.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use bevy_camera::ManualTextureViewHandle;
22
use bevy_ecs::{prelude::Component, resource::Resource};
3+
use bevy_image::BevyDefault;
34
use bevy_math::UVec2;
45
use bevy_platform::collections::HashMap;
56
use bevy_render_macros::ExtractResource;
7+
use wgpu::TextureFormat;
68

79
use crate::render_resource::TextureView;
810

@@ -11,11 +13,16 @@ use crate::render_resource::TextureView;
1113
pub struct ManualTextureView {
1214
pub texture_view: TextureView,
1315
pub size: UVec2,
16+
pub format: TextureFormat,
1417
}
1518

1619
impl ManualTextureView {
17-
pub fn new(texture_view: TextureView, size: UVec2) -> Self {
18-
Self { texture_view, size }
20+
pub fn with_default_format(texture_view: TextureView, size: UVec2) -> Self {
21+
Self {
22+
texture_view,
23+
size,
24+
format: TextureFormat::bevy_default(),
25+
}
1926
}
2027
}
2128

@@ -29,7 +36,7 @@ impl ManualTextureView {
2936
/// # world.insert_resource(ManualTextureViews::default());
3037
/// # let texture_view = todo!();
3138
/// let manual_views = world.resource_mut::<ManualTextureViews>();
32-
/// let manual_view = ManualTextureView::new(texture_view, UVec2::new(1024, 1024));
39+
/// let manual_view = ManualTextureView::with_default_format(texture_view, UVec2::new(1024, 1024));
3340
///
3441
/// // Choose an unused handle value; it's likely only you are inserting manual views.
3542
/// const MANUAL_VIEW_HANDLE: ManualTextureViewHandle = ManualTextureViewHandle::new(42);

crates/bevy_render/src/texture/texture_attachment.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::CachedTexture;
2-
use crate::render_resource::TextureView;
2+
use crate::render_resource::{TextureFormat, TextureView};
33
use alloc::sync::Arc;
44
use bevy_color::LinearRgba;
55
use core::sync::atomic::{AtomicBool, Ordering};
@@ -127,13 +127,15 @@ impl DepthAttachment {
127127
#[derive(Clone)]
128128
pub struct OutputColorAttachment {
129129
pub view: TextureView,
130+
pub format: TextureFormat,
130131
is_first_call: Arc<AtomicBool>,
131132
}
132133

133134
impl OutputColorAttachment {
134-
pub fn new(view: TextureView) -> Self {
135+
pub fn new(view: TextureView, format: TextureFormat) -> Self {
135136
Self {
136137
view,
138+
format,
137139
is_first_call: Arc::new(AtomicBool::new(true)),
138140
}
139141
}

crates/bevy_render/src/view/mod.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ impl ViewTarget {
848848
/// The format of the final texture this view will render to
849849
#[inline]
850850
pub fn out_texture_format(&self) -> TextureFormat {
851-
self.out_texture.view.texture().format()
851+
self.out_texture.format
852852
}
853853

854854
/// This will start a new "post process write", which assumes that the caller
@@ -1024,7 +1024,10 @@ pub fn prepare_view_attachments(
10241024
let Some(attachment) = target
10251025
.get_texture_view(&windows, &images, &manual_texture_views)
10261026
.cloned()
1027-
.map(OutputColorAttachment::new)
1027+
.zip(target.get_texture_format(&windows, &images, &manual_texture_views))
1028+
.map(|(view, format)| {
1029+
OutputColorAttachment::new(view.clone(), format.add_srgb_suffix())
1030+
})
10281031
else {
10291032
continue;
10301033
};
@@ -1093,7 +1096,11 @@ pub fn prepare_view_targets(
10931096
dimension: TextureDimension::D2,
10941097
format: main_texture_format,
10951098
usage: texture_usage.0,
1096-
view_formats: &[],
1099+
view_formats: match main_texture_format {
1100+
TextureFormat::Bgra8Unorm => &[TextureFormat::Bgra8UnormSrgb],
1101+
TextureFormat::Rgba8Unorm => &[TextureFormat::Rgba8UnormSrgb],
1102+
_ => &[],
1103+
},
10971104
};
10981105
let a = texture_cache.get(
10991106
&render_device,

crates/bevy_render/src/view/window/screenshot.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ fn prepare_screenshots(
295295
prepared.insert(*entity, state);
296296
view_target_attachments.insert(
297297
target.clone(),
298-
OutputColorAttachment::new(texture_view.clone()),
298+
OutputColorAttachment::new(texture_view.clone(), format.add_srgb_suffix()),
299299
);
300300
}
301301
NormalizedRenderTarget::Image(image) => {
@@ -315,7 +315,7 @@ fn prepare_screenshots(
315315
prepared.insert(*entity, state);
316316
view_target_attachments.insert(
317317
target.clone(),
318-
OutputColorAttachment::new(texture_view.clone()),
318+
OutputColorAttachment::new(texture_view.clone(), format.add_srgb_suffix()),
319319
);
320320
}
321321
NormalizedRenderTarget::TextureView(texture_view) => {
@@ -326,7 +326,7 @@ fn prepare_screenshots(
326326
);
327327
continue;
328328
};
329-
let format = manual_texture_view.texture_view.texture().format();
329+
let format = manual_texture_view.format;
330330
let size = manual_texture_view.size.to_extents();
331331
let (texture_view, state) = prepare_screenshot_state(
332332
size,
@@ -339,7 +339,7 @@ fn prepare_screenshots(
339339
prepared.insert(*entity, state);
340340
view_target_attachments.insert(
341341
target.clone(),
342-
OutputColorAttachment::new(texture_view.clone()),
342+
OutputColorAttachment::new(texture_view.clone(), format.add_srgb_suffix()),
343343
);
344344
}
345345
NormalizedRenderTarget::None { .. } => {
@@ -550,7 +550,7 @@ pub(crate) fn submit_screenshot_commands(world: &World, encoder: &mut CommandEnc
550550
};
551551
let width = texture_view.size.x;
552552
let height = texture_view.size.y;
553-
let texture_format = texture_view.texture_view.texture().format();
553+
let texture_format = texture_view.format;
554554
let texture_view = texture_view.texture_view.deref();
555555
render_screenshot(
556556
encoder,

0 commit comments

Comments
 (0)