use bevy::{
prelude::*,
render::{
render_resource::{PipelineCache, RenderPassDescriptor},
renderer::{RenderContext, ViewQuery},
view::ViewTarget,
},
};
use crate::{
FragmentExtraBindGroups,
bindings::{AutoBufferBindGroups, AutoBufferLayouts, all_groups_bound},
pipeline::FullscreenPipeline,
};
pub fn fullscreen_pass(
view: ViewQuery<&ViewTarget>,
pipeline_res: Option<Res<FullscreenPipeline>>,
pipeline_cache: Res<PipelineCache>,
layouts: Res<AutoBufferLayouts>,
auto: Res<AutoBufferBindGroups>,
extra: Option<Res<FragmentExtraBindGroups>>,
mut ctx: RenderContext,
) {
let view_target = view.into_inner();
let Some(pipeline_res) = pipeline_res else {
return;
};
let Some(pipeline) = pipeline_res
.pipeline_id(view_target.main_texture_format())
.and_then(|id| pipeline_cache.get_render_pipeline(id))
else {
return;
};
if !all_groups_bound(&layouts, &auto) {
return;
}
let mut render_pass = ctx.begin_tracked_render_pass(RenderPassDescriptor {
label: Some("fullscreen_fragment_pass"),
color_attachments: &[Some(view_target.get_color_attachment())],
..default()
});
render_pass.set_render_pipeline(pipeline);
for (group_index, bind_group) in auto.0.iter() {
render_pass.set_bind_group(*group_index as usize, bind_group, &[]);
}
let auto_count = auto.0.len();
if let Some(extra) = &extra {
for (i, bind_group) in extra.0.iter().enumerate() {
render_pass.set_bind_group(auto_count + i, bind_group, &[]);
}
}
render_pass.draw(0..3, 0..1);
}