2020-03-14 19:56:37 +00:00
|
|
|
use crate::{asset::Handle, math::Vec4, render::texture::Texture};
|
2020-02-18 03:53:48 +00:00
|
|
|
use zerocopy::AsBytes;
|
|
|
|
|
|
|
|
pub trait GetBytes {
|
|
|
|
fn get_bytes(&self) -> Vec<u8>;
|
|
|
|
fn get_bytes_ref(&self) -> Option<&[u8]>;
|
|
|
|
}
|
|
|
|
|
2020-03-22 01:12:30 +00:00
|
|
|
impl GetBytes for [f32; 2] {
|
|
|
|
fn get_bytes(&self) -> Vec<u8> {
|
|
|
|
self.as_bytes().to_vec()
|
|
|
|
}
|
|
|
|
fn get_bytes_ref(&self) -> Option<&[u8]> {
|
|
|
|
Some(self.as_bytes())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl GetBytes for [f32; 3] {
|
|
|
|
fn get_bytes(&self) -> Vec<u8> {
|
|
|
|
self.as_bytes().to_vec()
|
|
|
|
}
|
|
|
|
fn get_bytes_ref(&self) -> Option<&[u8]> {
|
|
|
|
Some(self.as_bytes())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl GetBytes for [f32; 4] {
|
|
|
|
fn get_bytes(&self) -> Vec<u8> {
|
|
|
|
self.as_bytes().to_vec()
|
|
|
|
}
|
|
|
|
fn get_bytes_ref(&self) -> Option<&[u8]> {
|
|
|
|
Some(self.as_bytes())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-18 03:53:48 +00:00
|
|
|
impl GetBytes for Vec4 {
|
|
|
|
fn get_bytes(&self) -> Vec<u8> {
|
|
|
|
let vec4_array: [f32; 4] = (*self).into();
|
|
|
|
vec4_array.as_bytes().into()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_bytes_ref(&self) -> Option<&[u8]> {
|
2020-03-15 01:32:33 +00:00
|
|
|
Some(self.as_ref().as_bytes())
|
2020-02-18 03:53:48 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-22 23:01:11 +00:00
|
|
|
|
|
|
|
impl GetBytes for Handle<Texture> {
|
|
|
|
fn get_bytes(&self) -> Vec<u8> {
|
|
|
|
Vec::new()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_bytes_ref(&self) -> Option<&[u8]> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|