ffgl_core/handler/
mod.rs

1//! This module provides the main traits for creating FFGL plugins
2//! Use [simplified] for a simpler way to create plugins
3
4use parameters::ParamInfo;
5
6use std;
7
8use std::error::Error;
9use std::fmt::Debug;
10
11use crate::inputs::FFGLData;
12
13use crate::{info, inputs::GLInput, parameters};
14
15#[doc(hidden)]
16pub struct Instance<T> {
17    pub(crate) data: FFGLData,
18    pub(crate) renderer: T,
19}
20
21impl<I> Debug for Instance<I> {
22    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23        f.debug_struct("Instance")
24            .field("data", &self.data)
25            .field("renderer", &std::any::type_name::<I>())
26            .finish()
27    }
28}
29
30///This type is created once per instance of a plugin
31pub trait FFGLInstance {
32    fn get_param(&self, index: usize) -> f32;
33    fn set_param(&mut self, index: usize, value: f32);
34
35    ///Called by [crate::conversions::Op::ProcessOpenGL] to draw the plugin
36    fn draw(&mut self, inst_data: &FFGLData, frame_data: GLInput);
37}
38
39///This type is created once per plugin load.
40/// You can use it to store static state and create instances
41pub trait FFGLHandler {
42    type Instance: FFGLInstance;
43    type NewInstanceError: Error + Send + Sync + 'static;
44    // type Param: ParamInfo + 'static;
45
46    ///Only called once per plugin
47    fn init() -> Self;
48
49    fn num_params(&'static self) -> usize;
50
51    fn param_info(&'static self, index: usize) -> &'static dyn ParamInfo;
52
53    fn plugin_info(&'static self) -> info::PluginInfo;
54
55    fn new_instance(
56        &'static self,
57        inst_data: &FFGLData,
58    ) -> Result<Self::Instance, Self::NewInstanceError>;
59}
60
61pub mod simplified;