use std::vec;
use awsm_renderer_core::command::{
render_pass::{ColorAttachment, RenderPassDescriptor},
LoadOp, StoreOp,
};
use crate::{
error::Result,
render::RenderContext,
render_passes::{
display::{bind_group::DisplayBindGroups, pipeline::DisplayPipelines},
RenderPassInitContext,
},
};
pub struct DisplayRenderPass {
pub bind_groups: DisplayBindGroups,
pub pipelines: DisplayPipelines,
}
impl DisplayRenderPass {
pub async fn new(ctx: &mut RenderPassInitContext<'_>) -> Result<Self> {
let bind_groups = DisplayBindGroups::new(ctx).await?;
let pipelines = DisplayPipelines::new(ctx, &bind_groups).await?;
Ok(Self {
bind_groups,
pipelines,
})
}
pub fn render(&self, ctx: &RenderContext) -> Result<()> {
let render_pass = ctx.command_encoder.begin_render_pass(
&RenderPassDescriptor {
label: Some("Display Render Pass"),
color_attachments: vec![ColorAttachment::new(
&ctx.gpu.current_context_texture_view()?,
LoadOp::Clear,
StoreOp::Store,
)
.with_clear_color(ctx.clear_color)],
..Default::default()
}
.into(),
)?;
render_pass.set_bind_group(0, self.bind_groups.get_bind_group()?, None)?;
if let Some(pipeline_key) = self.pipelines.render_pipeline_key {
render_pass.set_pipeline(ctx.pipelines.render.get(pipeline_key)?);
render_pass.draw(3);
}
render_pass.end();
Ok(())
}
}