wgpu: Correctly set format when rendering to Stage3D texture
This fixes a panic when trying to render a texture with a type other than `TextureFormat::Rgba8Unorm`
This commit is contained in:
parent
a5b4b63edc
commit
c93020e729
|
@ -80,6 +80,8 @@ pub struct CurrentPipeline {
|
||||||
|
|
||||||
sample_count: u32,
|
sample_count: u32,
|
||||||
|
|
||||||
|
target_format: TextureFormat,
|
||||||
|
|
||||||
dirty: Cell<bool>,
|
dirty: Cell<bool>,
|
||||||
|
|
||||||
sampler_override: [Option<SamplerOverride>; 8],
|
sampler_override: [Option<SamplerOverride>; 8],
|
||||||
|
@ -155,6 +157,8 @@ impl CurrentPipeline {
|
||||||
alpha_component: wgpu::BlendComponent::REPLACE,
|
alpha_component: wgpu::BlendComponent::REPLACE,
|
||||||
sample_count: 1,
|
sample_count: 1,
|
||||||
|
|
||||||
|
target_format: TextureFormat::Rgba8Unorm,
|
||||||
|
|
||||||
sampler_override: [None; 8],
|
sampler_override: [None; 8],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -217,6 +221,13 @@ impl CurrentPipeline {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn update_target_format(&mut self, format: TextureFormat) {
|
||||||
|
if self.target_format != format {
|
||||||
|
self.dirty.set(true);
|
||||||
|
self.target_format = format;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// If the pipeline is dirty, recompiles it and returns `Some(freshly_compiled_pipeline`)
|
/// If the pipeline is dirty, recompiles it and returns `Some(freshly_compiled_pipeline`)
|
||||||
/// Otherwise, returns `None`.
|
/// Otherwise, returns `None`.
|
||||||
pub fn rebuild_pipeline(
|
pub fn rebuild_pipeline(
|
||||||
|
@ -464,7 +475,7 @@ impl CurrentPipeline {
|
||||||
module: &compiled_shaders.fragment_module,
|
module: &compiled_shaders.fragment_module,
|
||||||
entry_point: naga_agal::SHADER_ENTRY_POINT,
|
entry_point: naga_agal::SHADER_ENTRY_POINT,
|
||||||
targets: &[Some(ColorTargetState {
|
targets: &[Some(ColorTargetState {
|
||||||
format: TextureFormat::Rgba8Unorm,
|
format: self.target_format,
|
||||||
blend: Some(wgpu::BlendState {
|
blend: Some(wgpu::BlendState {
|
||||||
color: self.color_component,
|
color: self.color_component,
|
||||||
alpha: self.alpha_component,
|
alpha: self.alpha_component,
|
||||||
|
|
|
@ -210,6 +210,8 @@ impl WgpuContext3D {
|
||||||
.update_has_depth_texture(self.current_depth_texture_view.is_some());
|
.update_has_depth_texture(self.current_depth_texture_view.is_some());
|
||||||
self.current_pipeline
|
self.current_pipeline
|
||||||
.update_sample_count(self.back_buffer_sample_count);
|
.update_sample_count(self.back_buffer_sample_count);
|
||||||
|
self.current_pipeline
|
||||||
|
.update_target_format(TextureFormat::Rgba8Unorm);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn present(&mut self) {
|
pub(crate) fn present(&mut self) {
|
||||||
|
@ -828,6 +830,8 @@ impl Context3D for WgpuContext3D {
|
||||||
.update_has_depth_texture(enable_depth_and_stencil);
|
.update_has_depth_texture(enable_depth_and_stencil);
|
||||||
self.current_pipeline.remove_texture(&texture);
|
self.current_pipeline.remove_texture(&texture);
|
||||||
self.current_pipeline.update_sample_count(sample_count);
|
self.current_pipeline.update_sample_count(sample_count);
|
||||||
|
self.current_pipeline
|
||||||
|
.update_target_format(texture_wrapper.texture.format());
|
||||||
}
|
}
|
||||||
|
|
||||||
Context3DCommand::SetRenderToBackBuffer => {
|
Context3DCommand::SetRenderToBackBuffer => {
|
||||||
|
|
Loading…
Reference in New Issue