library: texture: uniform: add deserialization
This commit is contained in:
parent
803b34641d
commit
eff133abf3
|
@ -1,9 +1,10 @@
|
||||||
use super::Texture;
|
use super::Texture;
|
||||||
use crate::core::LinearColor;
|
use crate::core::LinearColor;
|
||||||
use crate::Point2D;
|
use crate::Point2D;
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
/// A texture with the same color on all points.
|
/// A texture with the same color on all points.
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq, Deserialize)]
|
||||||
pub struct UniformTexture {
|
pub struct UniformTexture {
|
||||||
color: LinearColor,
|
color: LinearColor,
|
||||||
}
|
}
|
||||||
|
@ -34,6 +35,7 @@ mod test {
|
||||||
fn simple_texture() -> UniformTexture {
|
fn simple_texture() -> UniformTexture {
|
||||||
UniformTexture::new(LinearColor::new(0.25, 0.5, 1.))
|
UniformTexture::new(LinearColor::new(0.25, 0.5, 1.))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn texel_color_works() {
|
fn texel_color_works() {
|
||||||
let texture = simple_texture();
|
let texture = simple_texture();
|
||||||
|
@ -42,4 +44,16 @@ mod test {
|
||||||
LinearColor::new(0.25, 0.5, 1.)
|
LinearColor::new(0.25, 0.5, 1.)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn deserialization_works() {
|
||||||
|
let yaml = r#"
|
||||||
|
color: {r: 1.0, g: 0.5, b: 0.25}
|
||||||
|
"#;
|
||||||
|
let texture: UniformTexture = serde_yaml::from_str(yaml).unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
texture,
|
||||||
|
UniformTexture::new(LinearColor::new(1., 0.5, 0.25))
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue