pax
pax copied to clipboard
GPU Backend: Resource model refactor
This is the start of refactoring pax-pixels and the engines RenderContext trait from this model:
fn fill(&mut self, path: Path, fill: Fill);
to this model:
fn make_fill(&self, path: Path, fill: Fill) -> Box<dyn FillResource>;
fn draw_fill(&mut self, resource: &dyn FillResource);
exact API pending. The goal of this is to not need to re-tesselate/re-upload image data to the GPU for each draw, but only on significant changes.
Next Steps:
- currently, draw methods in
pax-pixels/src/render_contextlook like this:
pub fn fill_path(&mut self, path: Path, fill: Fill) {
let options = FillOptions::tolerance(self.tolerance);
let mut geometry = VertexBuffers::new();
let mut geometry_builder =
BuffersBuilder::new(&mut geometry, |vertex: FillVertex| GpuVertex {
position: vertex.position().to_array(),
normal: [0.0; 2],
prim_id: 0,
});
match FillTessellator::new().tessellate_path(&path, &options, &mut geometry_builder) {
Ok(_) => {}
Err(e) => log::warn!("{:?}", e),
};
let mesh = self
.mesh_renderer
.make_mesh(&self.backend.device, &geometry, fill);
// TODO code bellow becomes the "fill_path" method, everything above the "make_fill", returning the mesh resource
// or a wrapper of it.
let mut render_pass =
Self::main_draw_render_pass(&self.backend, &self.stencil_renderer, &mut self.encoder);
self.mesh_renderer.render_meshes(&mut render_pass, &[mesh]);
}
change the RenderContext trait (in pax-runtime-api/src/lib.rs) to allow for the create/draw API, implement it for the CPU backend (in pax-runtime/src/engine/piet_render_context.rs). Convert all drawing primitives to use this new API. Convert the pax-pixels render_context API by braking methods like the above into two, and implement the trait for the GPU backend (in pax-runtime/src/engine/pax_pixels_render_context.rs).
- Change pax-pixels to operate over multiple canvases, as to allow a DrawResource to be used between different canvases.
- Don't create a new render pass for each new shape drawn, instead batch them until transforms/clips are applied, and only flush them then.
Other features still missing from pax-pixels:
- Anti-aliasing
- try to run on WebGL