use scenix_core::ValidationError;
use crate::Texture2D;
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct VideoTexture {
pub texture: Texture2D,
pub frame_index: u64,
pub dirty: bool,
}
impl VideoTexture {
#[inline]
pub fn new(texture: Texture2D) -> Self {
Self {
texture,
frame_index: 0,
dirty: true,
}
}
pub fn update_frame(&mut self, data: &[u8]) -> Result<(), ValidationError> {
if data.len() != self.texture.base_level_len()? {
return Err(ValidationError::OutOfRange);
}
self.texture.data.clear();
self.texture.data.extend_from_slice(data);
self.frame_index = self.frame_index.saturating_add(1);
self.dirty = true;
Ok(())
}
#[inline]
pub fn mark_clean(&mut self) {
self.dirty = false;
}
}