use cranpose_ui_graphics::BlendMode;
use super::PassScratch;
use crate::{
effect_renderer::{PreparedCompositeDraw, PreparedProjectiveComposite, PreparedShaderDraw},
instant_triangles::InstantDraw,
render::{PassDepth, RunStage, StoreRunBatch, TargetRect},
run_store::RunDrawCall,
scissor::intersect_target_rects,
};
pub(super) enum Batch<'a> {
StoreRun {
batch: StoreRunBatch,
scissor: Option<(u32, u32, u32, u32)>,
},
Arena {
chunk: usize,
uniform_slot: usize,
paint: std::ops::Range<usize>,
interiors: Option<std::ops::Range<usize>>,
scissor: Option<(u32, u32, u32, u32)>,
clip: Option<(u32, u32, u32, u32)>,
},
Images {
cmds: std::ops::Range<usize>,
blend_mode: BlendMode,
uniform_slot: usize,
scissor: Option<(u32, u32, u32, u32)>,
},
Glyphs {
cmds: std::ops::Range<usize>,
uniform_slot: usize,
scissor: Option<(u32, u32, u32, u32)>,
},
Shadows {
instances: std::ops::Range<u32>,
uniform_slot: usize,
scissor: Option<(u32, u32, u32, u32)>,
},
Composite(PreparedCompositeDraw<'a>),
Shader(PreparedShaderDraw<'a>),
Projective(PreparedProjectiveComposite<'a>),
Instant(InstantDraw<'a>),
}
pub(super) fn stage_scissor(
scissor: TargetRect,
clip: Option<TargetRect>,
stage: RunStage,
) -> Option<TargetRect> {
match (stage, clip) {
(RunStage::Paint, Some(clip)) => intersect_target_rects(scissor, clip),
_ => Some(scissor),
}
}
#[derive(Clone, Copy)]
pub(crate) struct RunCalls<'a> {
pub(crate) uniform_slot: usize,
pub(crate) draws: &'a [RunDrawCall],
pub(crate) scissor: (u32, u32, u32, u32),
pub(crate) stage: RunStage,
pub(crate) meshes: Option<(crate::mesh_fallback::RunMeshes<'a>, PassDepth)>,
}
#[derive(Clone, Copy)]
pub(super) struct PassCmds<'a> {
pub(super) images: &'a [crate::render::ImageDrawCmd],
pub(super) glyphs: &'a [crate::render::GlyphDrawCmd],
pub(super) arena: &'a [RunDrawCall],
pub(super) meshes: &'a crate::mesh_fallback::PassMeshes,
}
pub(super) fn group_glyph_batches(batches: &[Batch<'_>], scratch: &mut PassScratch) {
for batch in batches {
if let Batch::Glyphs { cmds, .. } = batch {
let cmds = &mut scratch.glyph_cmds[cmds.clone()];
let shared = crate::render::defer_retained_glyph_runs(cmds, &mut scratch.glyph_moved);
crate::render::group_glyph_kinds(&mut cmds[..shared], &mut scratch.glyph_moved);
}
}
}