1use scenix_core::ValidationError;
2
3use crate::Texture2D;
4
5#[derive(Clone, Debug, PartialEq)]
7#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
8pub struct VideoTexture {
9 pub texture: Texture2D,
11 pub frame_index: u64,
13 pub dirty: bool,
15}
16
17impl VideoTexture {
18 #[inline]
20 pub fn new(texture: Texture2D) -> Self {
21 Self {
22 texture,
23 frame_index: 0,
24 dirty: true,
25 }
26 }
27
28 pub fn update_frame(&mut self, data: &[u8]) -> Result<(), ValidationError> {
30 if data.len() != self.texture.base_level_len()? {
31 return Err(ValidationError::OutOfRange);
32 }
33 self.texture.data.clear();
34 self.texture.data.extend_from_slice(data);
35 self.frame_index = self.frame_index.saturating_add(1);
36 self.dirty = true;
37 Ok(())
38 }
39
40 #[inline]
42 pub fn mark_clean(&mut self) {
43 self.dirty = false;
44 }
45}