Replaces the bindless `binding_array<texture_2d<f32>>` the renderer bound every texture through. That array needs `VK_EXT_descriptor_indexing`, which a real share of Android GPUs lack, so the old shape did not run there at all. The two things being bound want opposite treatment, so they are now split: - **Glyph atlas pages become layers of one `texture_2d_array`.** A glyph primitive carries a `layer` instead of a view/sampler index pair. A layer index is an ordinary sampling operand, so this needs nothing beyond plain Vulkan 1.0 / GLES. Growing the atlas recreates the array with headroom and `copy_texture_to_texture`s the old layers across, no readback. - **A standalone image gets its own texture and its own bind group,** and draws in its own call. It no longer needs a per-instance entry in `PrimitiveData`: the bind group has already picked the texture. `Primitives` keeps images in a list of their own as a result, with `PrimitiveChange::is_image` naming which list a renumbering belongs to -- the two have independent index spaces, so `(layer, inst_idx)` alone would collide between them. Two notes on judgement calls, since this slice was rebuilt on top of `main` rather than transplanted: - The source version renamed `GlyphEntry::is_colored` to `is_color` and added a second `IS_COLOR` flag constant beside the existing `GlyphEntry::IS_COLORED`. Both dropped: #10's naming and its `flags()` are kept, and UVs stay `Vec2` rather than going back to `[f32; 2]`. - `ImageGpu` no longer holds the `Texture` behind its view, which removes an `#[allow(dead_code)]`. A `TextureView` keeps its own reference to the texture, checked by rendering rather than assumed -- see below. ### Verification ``` cargo fmt --all --check cargo clippy --workspace --all-targets --locked -- -D warnings cargo test --workspace --locked ``` All clean; the 4 text-edit tests pass. The only clippy output is the pre-existing future-incompatibility notice about `naga`/`wgpu`/`winit`. Because this is a rendering change, it was also run for real rather than only compiled. The `tabs` example was rendered on this machine's GPU -- Venus onto an RX 7900 XT, confirmed from the loaded ICD (`libvulkan_virtio.so` on `/dev/dri/renderD128`) rather than assumed, since a failed Vulkan init here silently falls back to llvmpipe and would make the screenshots meaningless. Screenshots before and after the change are **byte-identical** (same md5) in two scenes: the default tab, which exercises text (the atlas path) and rects, and the image tab with a standalone image pushed at startup, which exercises the per-image bind group. The image-tab scene needed a temporary local edit to the example to push the image without a click; that edit is not part of this branch. The same comparison, re-run after dropping the `Texture` field, is still byte-identical -- which is the check that the view alone keeps it alive. --------- Co-authored-by: iris <2+iris@noreply.localhost> Reviewed-on: #11 Reviewed-by: iris <2+iris@noreply.localhost> Co-authored-by: AIris <4+iris-ai@noreply.localhost>
225 lines
7.3 KiB
Rust
225 lines
7.3 KiB
Rust
use std::{cell::RefCell, rc::Rc};
|
|
use winit::event::WindowEvent;
|
|
|
|
use iris::prelude::*;
|
|
type ClientRsc = DefaultRsc<Client>;
|
|
|
|
fn main() {
|
|
DefaultApp::<Client>::run();
|
|
}
|
|
|
|
#[derive(DefaultUiState)]
|
|
pub struct Client {
|
|
ui_state: DefaultUiState,
|
|
info: WeakWidget<Text>,
|
|
}
|
|
|
|
impl DefaultAppState for Client {
|
|
fn new(
|
|
mut ui_state: DefaultUiState,
|
|
rsc: &mut DefaultRsc<Self>,
|
|
_: Proxy<Self::Event>,
|
|
) -> Self {
|
|
let rrect = rect(Color::WHITE).radius(20);
|
|
let pad_test = (
|
|
rrect.color(Color::BLUE),
|
|
(
|
|
rrect
|
|
.color(Color::RED)
|
|
.sized((100, 100))
|
|
.center()
|
|
.width(rest(2)),
|
|
(
|
|
rrect.color(Color::ORANGE),
|
|
rrect.color(Color::LIME).pad(10.0),
|
|
)
|
|
.span(Dir::RIGHT)
|
|
.width(rest(2)),
|
|
rrect.color(Color::YELLOW),
|
|
)
|
|
.span(Dir::RIGHT)
|
|
.pad(10)
|
|
.width(rest(3)),
|
|
)
|
|
.span(Dir::RIGHT)
|
|
.add(rsc);
|
|
|
|
let span_test = (
|
|
rrect.color(Color::GREEN).width(100),
|
|
rrect.color(Color::ORANGE),
|
|
rrect.color(Color::CYAN),
|
|
rrect.color(Color::BLUE).width(rel(0.5)),
|
|
rrect.color(Color::MAGENTA).width(100),
|
|
rrect.color(Color::RED).width(100),
|
|
)
|
|
.span(Dir::LEFT)
|
|
.add(rsc);
|
|
|
|
let span_add = Span::empty(Dir::RIGHT).add(rsc);
|
|
|
|
let add_button = rect(Color::LIME)
|
|
.radius(30)
|
|
.on(CursorSense::click(), move |_, rsc| {
|
|
let child = image(include_bytes!("assets/sungals.png"))
|
|
.center()
|
|
.add_strong(rsc);
|
|
span_add(rsc).push(child);
|
|
})
|
|
.sized((150, 150))
|
|
.align(Align::BOT_RIGHT);
|
|
|
|
let del_button = rect(Color::RED)
|
|
.radius(30)
|
|
.on(CursorSense::click(), move |_, rsc| {
|
|
span_add(rsc).pop();
|
|
})
|
|
.sized((150, 150))
|
|
.align(Align::BOT_LEFT);
|
|
|
|
let span_add_test = (span_add, add_button, del_button).stack().add(rsc);
|
|
|
|
let btext = |content| wtext(content).size(30);
|
|
|
|
let text_test = (
|
|
btext("this is a").align(Align::LEFT),
|
|
btext("teeeeeeeest").align(Align::RIGHT),
|
|
btext("okkk\nokkkkkk!").align(Align::LEFT),
|
|
btext("hmm"),
|
|
btext("a"),
|
|
(
|
|
btext("'").family(Family::Monospace).align(Align::TOP),
|
|
btext("'").family(Family::Monospace),
|
|
btext(":gamer mode").family(Family::Monospace),
|
|
rect(Color::CYAN).sized((10, 10)).center(),
|
|
rect(Color::RED).sized((100, 100)).center(),
|
|
rect(Color::PURPLE).sized((50, 50)).align(Align::TOP),
|
|
)
|
|
.span(Dir::RIGHT)
|
|
.center(),
|
|
wtext("pretty cool right?").size(50),
|
|
)
|
|
.span(Dir::DOWN)
|
|
.add(rsc);
|
|
|
|
let texts = Span::empty(Dir::DOWN).gap(10).add(rsc);
|
|
let msg_area = texts.scrollable().masked().background(rect(Color::SKY));
|
|
let add_text = wtext("add")
|
|
.editable(EditMode::MultiLine)
|
|
.text_align(Align::LEFT)
|
|
.size(30)
|
|
.attr::<Selectable>(())
|
|
.on(Submit, move |ctx, rsc| {
|
|
let w = ctx.widget;
|
|
let content = w.edit(rsc).take();
|
|
let text = wtext(content)
|
|
.editable(EditMode::MultiLine)
|
|
.size(30)
|
|
.text_align(Align::LEFT)
|
|
.wrap(true)
|
|
.attr::<Selectable>(());
|
|
let msg_box = text
|
|
.background(rect(Color::WHITE.darker(0.5)))
|
|
.add_strong(rsc);
|
|
texts(rsc).push(msg_box);
|
|
})
|
|
.add(rsc);
|
|
|
|
let text_edit_scroll = (
|
|
msg_area.height(rest(1)),
|
|
(
|
|
Rect::new(Color::WHITE.darker(0.9)),
|
|
(
|
|
add_text.width(rest(1)),
|
|
Rect::new(Color::GREEN)
|
|
.on(CursorSense::click(), move |ctx, rsc: &mut ClientRsc| {
|
|
rsc.run_event::<Submit>(add_text, (), ctx.state);
|
|
})
|
|
.sized((40, 40)),
|
|
)
|
|
.span(Dir::RIGHT)
|
|
.pad(10),
|
|
)
|
|
.stack()
|
|
.size(StackSize::Child(1))
|
|
.layer_offset(1)
|
|
.align(Align::BOT),
|
|
)
|
|
.span(Dir::DOWN)
|
|
.add(rsc);
|
|
|
|
let main = WidgetPtr::new().add(rsc);
|
|
|
|
let vals = Rc::new(RefCell::new((0, Vec::new())));
|
|
let mut switch_button = |color, to: WeakWidget, label| {
|
|
let to = to.upgrade(rsc);
|
|
let vec = &mut vals.borrow_mut().1;
|
|
let i = vec.len();
|
|
if vec.is_empty() {
|
|
vec.push(None);
|
|
main(rsc).set(to);
|
|
} else {
|
|
vec.push(Some(to));
|
|
}
|
|
let vals = vals.clone();
|
|
let rect = rect(color)
|
|
.on(CursorSense::click(), move |ctx, rsc| {
|
|
let (prev, vec) = &mut *vals.borrow_mut();
|
|
if let Some(h) = vec[i].take() {
|
|
vec[*prev] = main(rsc).replace(h);
|
|
*prev = i;
|
|
}
|
|
ctx.widget(rsc).color = color.darker(0.3);
|
|
})
|
|
.on(
|
|
CursorSense::HoverStart | CursorSense::unclick(),
|
|
move |ctx, rsc| {
|
|
ctx.widget(rsc).color = color.brighter(0.2);
|
|
},
|
|
)
|
|
.on(CursorSense::HoverEnd, move |ctx, rsc| {
|
|
ctx.widget(rsc).color = color;
|
|
});
|
|
(rect, wtext(label).size(30).text_align(Align::CENTER)).stack()
|
|
};
|
|
|
|
let tabs = (
|
|
switch_button(Color::RED, pad_test, "pad"),
|
|
switch_button(Color::GREEN, span_test, "span"),
|
|
switch_button(Color::BLUE, span_add_test, "image span"),
|
|
switch_button(Color::MAGENTA, text_test, "text layout"),
|
|
switch_button(
|
|
Color::YELLOW.mul_rgb(0.5),
|
|
text_edit_scroll,
|
|
"text edit scroll",
|
|
),
|
|
)
|
|
.span(Dir::RIGHT);
|
|
|
|
let info = wtext("").add(rsc);
|
|
let info_sect = info.pad(10).align(Align::RIGHT);
|
|
|
|
((tabs.height(40), main.pad(10)).span(Dir::DOWN), info_sect)
|
|
.stack()
|
|
.set_root(rsc, &mut ui_state);
|
|
|
|
Self { ui_state, info }
|
|
}
|
|
|
|
fn window_event(
|
|
&mut self,
|
|
_: WindowEvent,
|
|
rsc: &mut DefaultRsc<Self>,
|
|
render: &mut UiRenderState,
|
|
) {
|
|
let new = format!(
|
|
"widgets: {}\nactive: {}\ntextures: {}",
|
|
rsc.widgets().len(),
|
|
render.active_widgets(),
|
|
rsc.ui().textures.count(),
|
|
);
|
|
if new != *rsc.widgets()[self.info].content {
|
|
*rsc.widgets_mut()[self.info].content = new;
|
|
}
|
|
}
|
|
}
|