aboutsummaryrefslogtreecommitdiff
path: root/src/classes/texture.rs
blob: 6d1c1020df3e8487bb9b463d408777dc2b9cdc89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use super::{cubemap::Cubemap, texture2d::Texture2D};
use crate::object::{Value, parser::FromValue};
use anyhow::Result;
use serde::Serialize;

#[derive(Debug, Serialize)]
pub enum AnyTexture {
    Cubemap(Cubemap),
    Texture2D(Texture2D),
}

impl FromValue for AnyTexture {
    fn from_value(v: Value) -> Result<Self> {
        match v.class_name().unwrap().as_str() {
            "Cubemap" => Ok(Self::Cubemap(v.parse()?)),
            "Texture2D" => Ok(Self::Texture2D(v.parse()?)),
            x => unreachable!("{x}"),
        }
    }
}
impl AnyTexture {
    pub fn as_texture2d(self) -> Option<Texture2D> {
        if let AnyTexture::Texture2D(x) = self {
            Some(x)
        } else {
            None
        }
    }
}