1use std::{
2 sync::{Arc, Mutex},
3 usize,
4};
5
6use crate::traits;
7
8pub trait AsBytes {
10 fn as_bytes(&self) -> &[u8];
12}
13
14impl<T> AsBytes for Vec<T> {
15 fn as_bytes(&self) -> &[u8] {
16 unsafe {
17 std::slice::from_raw_parts(self.as_ptr() as *const u8, self.len() * size_of::<T>())
18 }
19 }
20}
21
22impl<T> AsBytes for &[T] {
23 fn as_bytes(&self) -> &[u8] {
24 unsafe {
25 std::slice::from_raw_parts(self.as_ptr() as *const u8, self.len() * size_of::<T>())
26 }
27 }
28}
29
30pub struct GpuSamplerSet {
32 pub(crate) id: Mutex<usize>,
33 pub(crate) textures: Vec<(u32, Arc<dyn traits::Texture>)>,
34}
35
36impl GpuSamplerSet {
37 pub fn from_textures(textures: &[(u32, Arc<dyn traits::Texture>)]) -> Arc<Self> {
39 Arc::new(Self {
40 id: Mutex::new(usize::MAX),
41 textures: textures.to_vec(),
42 })
43 }
44}