Skip to content

feat: Add render_to_pixmap_at_offset for spritesheet support#1416

Merged
grebmeg merged 5 commits into
mainfrom
gemberg/render_to_pixmap_at_offset
Feb 9, 2026
Merged

feat: Add render_to_pixmap_at_offset for spritesheet support#1416
grebmeg merged 5 commits into
mainfrom
gemberg/render_to_pixmap_at_offset

Conversation

@grebmeg
Copy link
Copy Markdown
Collaborator

@grebmeg grebmeg commented Feb 4, 2026

Add the ability to render a RenderContext's content directly into a sub-region of a larger pixmap at a specified (x, y) offset. The method composites on top of existing content rather than clearing, allowing multiple renders to accumulate.

This is useful for building spritesheets where individual elements (like glyphs) are rendered to specific coordinates without intermediate buffer allocation.

An example test result from this PR:
render_to_pixmap_at_offset

@nicoburns
Copy link
Copy Markdown
Contributor

I think this would also solve #1382

@nicoburns nicoburns added enhancement New feature or request C-cpu Applies to the vello_cpu crate labels Feb 4, 2026
@grebmeg
Copy link
Copy Markdown
Collaborator Author

grebmeg commented Feb 4, 2026

I think this would also solve #1382

Yeah, that sounds very applicable to that case. I also think it could be useful for #1130 as well. In my case, it’s purely about populating the atlas glyph pixmap so it can be used later for rendering purposes. The next PR I’m preparing after this one will add support for such spritesheets in vello_cpu.

@grebmeg grebmeg requested a review from LaurenzV February 5, 2026 05:00
Comment thread sparse_strips/vello_cpu/src/render.rs Outdated
///
/// This is useful for rendering individual elements (like glyphs) into
/// a spritesheet at specific coordinates.
pub fn render_to_pixmap_at_offset(&self, pixmap: &mut Pixmap, dst_x: u16, dst_y: u16) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things:

  1. We need to add a big fat warning that this will panic in multi-threaded mode. 😄
  2. I think it's not ideal that this method has the same name as render_to_pixmap, even though they do different things (one will replace the pixmap, anther one will composite it on top of existing content). Maybe we should rename it to composite_onto_pixmap_at_offset or something?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also applies to all other usages as well as some of the related methods (i.e. the internal rasterize_at_offset methods).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with both comments.

Fixed.

let wtile = self.wide.get(x, y);
fine.set_coords(x, y);

fine.unpack(region);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a small comment that this achieves the effect of compositing onto the existing contents of a pixmap, instead of replacing it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@grebmeg grebmeg force-pushed the gemberg/render_to_pixmap_at_offset branch from 79f5520 to a1b5b90 Compare February 9, 2026 00:11
@grebmeg grebmeg enabled auto-merge February 9, 2026 00:12
@grebmeg grebmeg added this pull request to the merge queue Feb 9, 2026
Merged via the queue into main with commit 2eedc79 Feb 9, 2026
17 checks passed
@grebmeg grebmeg deleted the gemberg/render_to_pixmap_at_offset branch February 9, 2026 00:28
///
/// This method is only supported with the single-threaded dispatcher and will
/// **panic** if called on a `RenderContext` using the multi-threaded dispatcher.
pub fn composite_to_pixmap_at_offset(&self, pixmap: &mut Pixmap, dst_x: u16, dst_y: u16) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In future, Same approach for working with direct buffer would be like:

pub fn composite_to_buffer_at_offset(
    &self,
    buffer: &mut [u8],
    width: u16,
    height: u16,
    dst_x: u16,
    dst_y: u16,
) { ... }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-cpu Applies to the vello_cpu crate enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants