Skip to main content

beamterm_core/gl/
renderer.rs

1use crate::gl::context::GlState;
2
3/// Rendering context that provides access to GL state.
4pub struct RenderContext<'a> {
5    pub gl: &'a glow::Context,
6    pub state: &'a mut GlState,
7}
8
9/// Trait for objects that can be rendered.
10pub trait Drawable {
11    /// Prepares the object for rendering.
12    ///
13    /// This method should set up all necessary OpenGL state, bind shaders,
14    /// textures, and vertex data required for rendering.
15    ///
16    /// # Errors
17    /// May return an error if GPU resource preparation fails (e.g., dynamic
18    /// atlas glyph upload).
19    fn prepare(&self, context: &mut RenderContext) -> Result<(), crate::Error>;
20
21    /// Performs the actual rendering.
22    ///
23    /// This method should issue draw calls to render the object. All necessary
24    /// state should already be set up from the `prepare()` call.
25    fn draw(&self, context: &mut RenderContext);
26
27    /// Cleans up after rendering.
28    ///
29    /// This method should restore OpenGL state and unbind any resources
30    /// that were bound during `prepare()`. This ensures proper cleanup
31    /// for subsequent rendering operations.
32    fn cleanup(&self, context: &mut RenderContext);
33}