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