WIP graster-nodes: change Color params to Option<Color>

This commit is contained in:
firestar99
2025-08-26 11:24:10 +02:00
parent c716e83a7c
commit 648178f852
5 changed files with 37 additions and 3 deletions

View File

@@ -0,0 +1,29 @@
//! custom BufferStruct impl for graphite
use crate::color::Color;
use crate::shaders::buffer_struct::BufferStruct;
use bytemuck::{Pod, Zeroable};
#[repr(C)]
#[derive(Copy, Clone, Zeroable, Pod)]
pub struct OptionalColorBuffer(u32, <Color as BufferStruct>::Buffer);
unsafe impl BufferStruct for Option<Color> {
type Buffer = OptionalColorBuffer;
#[inline]
fn write(from: Self) -> Self::Buffer {
match from {
None => OptionalColorBuffer(0, Color::write(Color::default())),
Some(t) => OptionalColorBuffer(1, Color::write(t)),
}
}
#[inline]
fn read(from: Self::Buffer) -> Self {
match from.0 {
1 => Some(Color::read(from.1)),
_ => None,
}
}
}

View File

@@ -6,6 +6,7 @@
use bytemuck::Pod;
mod glam;
mod graphite;
mod primitive;
/// A BufferStruct is a "parallel representation" of the original struct with some fundamental types remapped. This