Separate atlas pages from textures, and draw both through one instance list
Rework of the review on #11. Pages and standalone images were one `Textures` manager separated by a `TextureKind` tag, and images were a second instance list beside `Primitives::instances`. The tag forced `image_index()`/`layer()` to panic on the wrong kind of handle, and the second list forced an `is_image` branch through `free`, `region_mut`, `apply_free` and `PrimitiveChange`. Pages are now their own thing. `GlyphAtlas` owns its page images outright and hands the renderer dirty rectangles; `GpuPages` owns the array texture they upload to. `Textures` is standalone images only, so `TextureHandle` has one kind, `slot()` cannot be wrong, and nothing needs a free list that skips pages. `GlyphAtlas::insert` no longer takes a `Textures`, which drops that parameter from `TextData::render` and `SizeCtx` too. Images go back through the one instance list. A texture instance is an ordinary `PrimitiveInstance` whose `idx` names a texture rather than a group-1 entry, which `PrimitiveHandle::data_idx: Option` records. `RenderLayer::plan_draws` batches the layer's instances into runs sharing a bind group, so a ui with no images still plans a single draw, and an image draws in instance order rather than on top of its layer. Group 2 is now one `texture_2d_array` and a sampler, bound per run: the atlas for rects and glyphs, or one image viewed as an array of one. That removes the second texture binding and the 1x1 null view that had to fill it. Masks move to group 3, so resizing that buffer no longer stales every texture bind group, and `GpuTextures` no longer reports whether the caller must rebuild one. `GlyphPrimitive` drops its manual pad: the WGSL struct now declares the uvs as scalars, which matches the Rust layout exactly. `#[repr(C, align(8))]` would have left real padding bytes, which `bytemuck::Pod` forbids. Verified with a headless run of the `tabs` example and of a scratch example mixing images, rects, glyphs and a mask in one layer; 52 glyphs at size 300 grew the atlas array from 1 to 4 layers with every earlier page still sampling correctly.
This commit is contained in:
1 parent
bafaa1db6d
commit
0106257be0
15 files changed
+544
-932
No files matched your search
@@ -133,15 +133,15 @@ impl PrimitiveLayers {
|
||||
self[h.layer].free(h)
|
||||
}
|
||||
|
||||
pub fn write_image(
|
||||
pub fn write_texture(
|
||||
&mut self,
|
||||
layer: LayerId,
|
||||
id: WidgetId,
|
||||
texture_idx: u32,
|
||||
texture: u32,
|
||||
region: UiRegion,
|
||||
mask_idx: MaskIdx,
|
||||
) -> PrimitiveHandle {
|
||||
self[layer].write_image(layer, id, texture_idx, region, mask_idx)
|
||||
self[layer].write_texture(layer, id, texture, region, mask_idx)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user