linebender / linebender/vello

[Sparse Strips] Consider exposing non-stateful rendering into scene?

Open
#1,857 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
4.3k
Forks
300
Avg merge
2d 13h
Merged PRs (30d)
61

Description

Building a library around vello_hybrid, I found the current Scene API a bit cumbersome. Because of the needs of my library (transforms need to be a stack that can be popped from, paint needs to be set per path, etc) my code ends up looking like this:

fn draw_path(ctx: Context, path: &Path) {
  scene.set_paint(path.paint);
  scene.set_paint_transform(path.paint_transform);
  scene.set_blend_mode(path.blend_mode);
  scene.set_stroke(&path.stroke_style);
  scene.set_transform(ctx.transform_stack.top());
  scene.fill_path(&path.path);
}

I thought maybe I should optimize my code to sort paths by paint, so I can re-use the current render state without having to completely change it for every path. But looking into vello's code, it seems that it clones the paint for every fill/stroke operation anyway, so there would be no benefit to doing that.

So I was wondering, would it make sense to expose the underlying drawing functions that take paint (and possibly everything else in RenderState) as arguments directly? So the code could look more like this:

fn draw_path(ctx: Context, path: &Path) {
  scene.fill_path(
    &path.path,
    ctx.transform_stack.top(),
    &path.paint_style, // Struct that contains paint, paint transform, blend mode, stroke style, etc...
  );
}

I understand that there is a desire to have vello's API resemble the HTML canvas API. But perhaps that could be better delivered by having a separate stateful layer on top of the raw scene API (possibly as a separate wrapper type, or in a separate crate).

Apologies if this was already discussed and rejected, I wasn't able to find another similar issue on here. I would appreciate a link to the reasoning, if that's the case!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the existing Scene API and the RenderState references described in the issue, then compare the current stateful calls with the proposed argument-based form. Determine whether the requested non-stateful rendering surface is a suitable API direction; done means an agreed design or documented decision about how this should be exposed.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api, computer-graphics
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.