1use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
4
5use crate::ffi::ffgl2::*;
6
7#[derive(Debug)]
9pub struct GLInput<'a> {
10 pub textures: &'a [FFGLTextureStruct],
11 pub host: u32,
12}
13
14impl<'a> Into<GLInput<'a>> for &'a ProcessOpenGLStruct {
15 fn into(self) -> GLInput<'a> {
16 GLInput {
17 textures: unsafe {
18 std::slice::from_raw_parts(
19 *self.inputTextures as *const _,
20 self.numInputTextures as usize,
21 )
22 },
23 host: self.HostFBO,
24 }
25 }
26}
27
28#[derive(Debug)]
30pub struct FFGLData {
31 pub created_at: Instant,
32 pub viewport: FFGLViewportStruct,
33 pub host_time: SystemTime,
34 pub host_beat: SetBeatinfoStruct,
35 }
37
38impl FFGLData {
39 pub fn new(viewport: &FFGLViewportStruct) -> FFGLData {
40 Self {
41 created_at: Instant::now(),
42 viewport: viewport.clone(),
43 host_time: SystemTime::now(),
44 host_beat: SetBeatinfoStruct {
45 bpm: 120.0,
46 barPhase: 0.0,
47 },
48 }
49 }
50
51 pub fn set_beat(&mut self, beat: SetBeatinfoStruct) {
52 self.host_beat = beat;
53 }
54
55 pub fn set_time(&mut self, host_seconds: f64) {
56 self.host_time = UNIX_EPOCH + Duration::from_secs_f64(host_seconds / 1000.0)
57 }
58
59 pub fn get_dimensions(&self) -> (u32, u32) {
60 (self.viewport.width, self.viewport.height)
61 }
62}