use bytemuck::{Pod, Zeroable};
#[repr(C)]
#[derive(Copy, Clone, Debug, Pod, Zeroable)]
pub struct QuadInstance {
pub pos: [f32; 2],
pub size: [f32; 2],
pub color: [f32; 4],
pub corner_radius: f32,
pub border_width: f32,
pub _pad0: [f32; 2],
pub border_color: [f32; 4],
pub clip_rect: [f32; 4],
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Pod, Zeroable)]
pub struct LineInstance {
pub start: [f32; 2],
pub end: [f32; 2],
pub color: [f32; 4],
pub width: f32,
pub cap_flags: f32,
pub _pad0: [f32; 2],
pub clip_rect: [f32; 4],
}
#[repr(C)]
#[derive(Copy, Clone, Debug, Pod, Zeroable)]
pub struct TriangleInstance {
pub v0: [f32; 2],
pub v1: [f32; 2],
pub v2: [f32; 2],
pub _pad0: [f32; 2],
pub color: [f32; 4],
pub clip_rect: [f32; 4],
}
const _: () = assert!(
std::mem::size_of::<QuadInstance>() % 16 == 0,
"QuadInstance must be 16-byte aligned"
);
const _: () = assert!(
std::mem::size_of::<LineInstance>() % 16 == 0,
"LineInstance must be 16-byte aligned"
);
const _: () = assert!(
std::mem::size_of::<TriangleInstance>() % 16 == 0,
"TriangleInstance must be 16-byte aligned"
);
#[derive(Clone)]
pub enum DrawCmd {
Quad(QuadInstance),
Triangle(TriangleInstance),
Line(LineInstance),
Text(crate::text::TextAreaData),
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn quad_instance_size_is_multiple_of_16() {
let size = std::mem::size_of::<QuadInstance>();
assert_eq!(size % 16, 0, "QuadInstance size {} is not 16-byte aligned", size);
}
#[test]
fn line_instance_size_is_multiple_of_16() {
let size = std::mem::size_of::<LineInstance>();
assert_eq!(size % 16, 0, "LineInstance size {} is not 16-byte aligned", size);
}
#[test]
fn triangle_instance_size_is_multiple_of_16() {
let size = std::mem::size_of::<TriangleInstance>();
assert_eq!(size % 16, 0, "TriangleInstance size {} is not 16-byte aligned", size);
}
}