Skip to content

Commit fc190c3

Browse files
committed
gcore-shaders: add crate, move color and blending from gcore
1 parent ad17f8e commit fc190c3

13 files changed

Lines changed: 88 additions & 47 deletions

File tree

Cargo.lock

Lines changed: 17 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ members = [
77
"node-graph/gapplication-io",
88
"node-graph/gbrush",
99
"node-graph/gcore",
10+
"node-graph/gcore-shaders",
1011
"node-graph/gstd",
1112
"node-graph/gmath-nodes",
1213
"node-graph/gpath-bool",
@@ -28,6 +29,7 @@ default-members = [
2829
"frontend/wasm",
2930
"node-graph/gbrush",
3031
"node-graph/gcore",
32+
"node-graph/gcore-shaders",
3133
"node-graph/gstd",
3234
"node-graph/gmath-nodes",
3335
"node-graph/gpath-bool",
@@ -50,6 +52,7 @@ path-bool = { path = "libraries/path-bool" }
5052
graphene-application-io = { path = "node-graph/gapplication-io" }
5153
graphene-brush = { path = "node-graph/gbrush" }
5254
graphene-core = { path = "node-graph/gcore" }
55+
graphene-core-shaders = { path = "node-graph/gcore-shaders" }
5356
graphene-math-nodes = { path = "node-graph/gmath-nodes" }
5457
graphene-path-bool = { path = "node-graph/gpath-bool" }
5558
graph-craft = { path = "node-graph/graph-craft" }
@@ -161,6 +164,7 @@ opt-level = 1
161164

162165
[profile.dev.package]
163166
graphite-editor = { opt-level = 1 }
167+
graphene-core-shaders = { opt-level = 1 }
164168
graphene-core = { opt-level = 1 }
165169
graphene-std = { opt-level = 1 }
166170
interpreted-executor = { opt-level = 1 } # This is a mitigation for https://github.com/rustwasm/wasm-pack/issues/981 which is needed because the node_registry function is too large
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[package]
2+
name = "graphene-core-shaders"
3+
version = "0.1.0"
4+
edition = "2024"
5+
description = "no_std API definitions for Graphene"
6+
authors = ["Graphite Authors <contact@graphite.rs>"]
7+
license = "MIT OR Apache-2.0"
8+
9+
[features]
10+
std = ["dep:dyn-any", "dep:serde", "dep:specta", "dep:log"]
11+
12+
[dependencies]
13+
# Local std dependencies
14+
dyn-any = { workspace = true, optional = true }
15+
16+
# Workspace dependencies
17+
bytemuck = { workspace = true }
18+
glam = { version = "0.29", default-features = false, features = ["nostd-libm", "scalar-math"] }
19+
half = { workspace = true }
20+
num-derive = { workspace = true }
21+
num-traits = { workspace = true }
22+
23+
# Workspace std dependencies
24+
serde = { workspace = true, optional = true }
25+
specta = { workspace = true, optional = true }
26+
log = { workspace = true, optional = true }
27+
28+
[lints.rust]
29+
# the spirv target is not in the list of common cfgs so must be added manually
30+
unexpected_cfgs = { level = "warn", check-cfg = [
31+
'cfg(target_arch, values("spirv"))',
32+
] }
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
use dyn_any::DynAny;
2-
use std::hash::Hash;
1+
use core::fmt::Display;
2+
use core::hash::{Hash, Hasher};
33

4-
#[derive(Copy, Clone, Debug, PartialEq, DynAny, specta::Type, serde::Serialize, serde::Deserialize)]
5-
#[serde(default)]
4+
#[derive(Debug, Clone, Copy, PartialEq)]
5+
#[cfg_attr(feature = "std", derive(dyn_any::DynAny, specta::Type, serde::Serialize, serde::Deserialize))]
6+
#[cfg_attr(feature = "std", serde(default))]
67
pub struct AlphaBlending {
78
pub blend_mode: BlendMode,
89
pub opacity: f32,
@@ -15,14 +16,14 @@ impl Default for AlphaBlending {
1516
}
1617
}
1718
impl Hash for AlphaBlending {
18-
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
19+
fn hash<H: Hasher>(&self, state: &mut H) {
1920
self.opacity.to_bits().hash(state);
2021
self.fill.to_bits().hash(state);
2122
self.blend_mode.hash(state);
2223
self.clip.hash(state);
2324
}
2425
}
25-
impl std::fmt::Display for AlphaBlending {
26+
impl Display for AlphaBlending {
2627
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2728
let round = |x: f32| (x * 1e3).round() / 1e3;
2829
write!(
@@ -58,9 +59,9 @@ impl AlphaBlending {
5859
}
5960
}
6061

61-
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
62-
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, DynAny, Hash, specta::Type)]
6362
#[repr(i32)]
63+
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Hash)]
64+
#[cfg_attr(feature = "std", derive(dyn_any::DynAny, specta::Type, serde::Serialize, serde::Deserialize))]
6465
pub enum BlendMode {
6566
// Basic group
6667
#[default]
@@ -185,18 +186,19 @@ impl BlendMode {
185186
}
186187

187188
/// Renders the blend mode CSS style declaration.
189+
#[cfg(feature = "std")]
188190
pub fn render(&self) -> String {
189191
format!(
190192
r#" mix-blend-mode: {};"#,
191193
self.to_svg_style_name().unwrap_or_else(|| {
192-
warn!("Unsupported blend mode {self:?}");
194+
log::warn!("Unsupported blend mode {self:?}");
193195
"normal"
194196
})
195197
)
196198
}
197199
}
198200

199-
impl std::fmt::Display for BlendMode {
201+
impl Display for BlendMode {
200202
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
201203
match self {
202204
// Normal group

node-graph/gcore/src/color/color.rs renamed to node-graph/gcore-shaders/src/color/color.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
use super::color_traits::{Alpha, AlphaMut, AssociatedAlpha, Luminance, LuminanceMut, Pixel, RGB, RGBMut, Rec709Primaries, SRGB};
22
use super::discrete_srgb::{float_to_srgb_u8, srgb_u8_to_float};
33
use bytemuck::{Pod, Zeroable};
4-
use dyn_any::DynAny;
4+
use core::hash::Hash;
55
use half::f16;
66
#[cfg(target_arch = "spirv")]
77
use spirv_std::num_traits::Euclid;
88
#[cfg(target_arch = "spirv")]
99
use spirv_std::num_traits::float::Float;
10-
use std::hash::Hash;
1110

1211
#[repr(C)]
13-
#[derive(Debug, Default, Clone, Copy, PartialEq, DynAny, Pod, Zeroable, serde::Serialize, serde::Deserialize)]
12+
#[derive(Debug, Default, Clone, Copy, PartialEq, Pod, Zeroable)]
13+
#[cfg_attr(feature = "std", derive(dyn_any::DynAny, serde::Serialize, serde::Deserialize))]
1414
pub struct RGBA16F {
1515
red: f16,
1616
green: f16,
@@ -82,7 +82,8 @@ impl Alpha for RGBA16F {
8282
impl Pixel for RGBA16F {}
8383

8484
#[repr(C)]
85-
#[derive(Debug, Default, Clone, Copy, PartialEq, DynAny, Pod, Zeroable, specta::Type, serde::Serialize, serde::Deserialize)]
85+
#[derive(Debug, Default, Clone, Copy, PartialEq, Pod, Zeroable)]
86+
#[cfg_attr(feature = "std", derive(dyn_any::DynAny, specta::Type, serde::Serialize, serde::Deserialize))]
8687
pub struct SRGBA8 {
8788
red: u8,
8889
green: u8,
@@ -162,7 +163,8 @@ impl Alpha for SRGBA8 {
162163
impl Pixel for SRGBA8 {}
163164

164165
#[repr(C)]
165-
#[derive(Debug, Default, Clone, Copy, PartialEq, DynAny, Pod, Zeroable, specta::Type, serde::Serialize, serde::Deserialize)]
166+
#[derive(Debug, Default, Clone, Copy, PartialEq, Pod, Zeroable)]
167+
#[cfg_attr(feature = "std", derive(dyn_any::DynAny, specta::Type, serde::Serialize, serde::Deserialize))]
166168
pub struct Luma(pub f32);
167169

168170
impl Luminance for Luma {
@@ -202,7 +204,8 @@ impl Pixel for Luma {}
202204
/// The other components (RGB) are stored as `f32` that range from `0.0` up to `f32::MAX`,
203205
/// the values encode the brightness of each channel proportional to the light intensity in cd/m² (nits) in HDR, and `0.0` (black) to `1.0` (white) in SDR color.
204206
#[repr(C)]
205-
#[derive(Debug, Default, Clone, Copy, PartialEq, DynAny, Pod, Zeroable, specta::Type, serde::Serialize, serde::Deserialize)]
207+
#[derive(Debug, Default, Clone, Copy, PartialEq, Pod, Zeroable)]
208+
#[cfg_attr(feature = "std", derive(dyn_any::DynAny, specta::Type, serde::Serialize, serde::Deserialize))]
206209
pub struct Color {
207210
red: f32,
208211
green: f32,

node-graph/gcore/src/color/color_traits.rs renamed to node-graph/gcore-shaders/src/color/color_traits.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1+
pub use crate::blending::*;
12
use bytemuck::{Pod, Zeroable};
3+
use core::fmt::Debug;
24
use glam::DVec2;
3-
use std::fmt::Debug;
4-
5+
use num_derive::*;
56
#[cfg(target_arch = "spirv")]
6-
use spirv_std::num_traits::float::Float;
7-
8-
pub use crate::blending::*;
7+
use num_traits::float::Float;
98

109
pub trait Linear {
1110
fn from_f32(x: f32) -> Self;
@@ -64,7 +63,6 @@ impl<T: Linear + Debug + Copy> Channel for T {
6463

6564
impl<T: Linear + Debug + Copy> LinearChannel for T {}
6665

67-
use num_derive::*;
6866
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Num, NumCast, NumOps, One, Zero, ToPrimitive, FromPrimitive)]
6967
pub struct SRGBGammaFloat(f32);
7068

@@ -97,14 +95,6 @@ impl<T: Rec709Primaries> RGBPrimaries for T {
9795

9896
pub trait SRGB: Rec709Primaries {}
9997

100-
pub trait Serde: serde::Serialize + for<'a> serde::Deserialize<'a> {}
101-
#[cfg(not(feature = "serde"))]
102-
pub trait Serde {}
103-
104-
impl<T: serde::Serialize + for<'a> serde::Deserialize<'a>> Serde for T {}
105-
#[cfg(not(feature = "serde"))]
106-
impl<T> Serde for T {}
107-
10898
// TODO: Come up with a better name for this trait
10999
pub trait Pixel: Clone + Pod + Zeroable + Default {
110100
#[cfg(not(target_arch = "spirv"))]
File renamed without changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pub use glam;
2+
3+
pub mod blending;
4+
pub mod color;

node-graph/gcore/Cargo.toml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ wgpu = ["dep:wgpu"]
1414
dealloc_nodes = []
1515

1616
[dependencies]
17+
# Local dependencies
18+
graphene-core-shaders = { workspace = true, features = ["std"] }
19+
1720
# Workspace dependencies
1821
bytemuck = { workspace = true }
1922
node-macro = { workspace = true }
20-
num-derive = { workspace = true }
2123
num-traits = { workspace = true }
2224
rand = { workspace = true }
2325
glam = { workspace = true }
@@ -30,7 +32,6 @@ rand_chacha = { workspace = true }
3032
bezier-rs = { workspace = true }
3133
specta = { workspace = true }
3234
image = { workspace = true }
33-
half = { workspace = true }
3435
tinyvec = { workspace = true }
3536
parley = { workspace = true }
3637
skrifa = { workspace = true }
@@ -46,9 +47,3 @@ wgpu = { workspace = true, optional = true }
4647
# Workspace dependencies
4748
tokio = { workspace = true }
4849
serde_json = { workspace = true }
49-
50-
[lints.rust]
51-
# the spirv target is not in the list of common cfgs so must be added manually
52-
unexpected_cfgs = { level = "warn", check-cfg = [
53-
'cfg(target_arch, values("spirv"))',
54-
] }

0 commit comments

Comments
 (0)