mujoco-rs 4.0.0+mj-3.8.0

A high-level Rust wrapper around the MuJoCo C library, with a native viewer (re-)written in Rust.
Documentation
//! Universal dependency, used for controlling the OpenGL context and surface.
//! This wraps [`RenderBase`] and thus renders to an invisible window.
//! This is meant as a fallback when true offscreen rendering fails to initialize.

use crate::winit_gl_base::RenderBase;
use super::RendererError;

use glutin::prelude::PossiblyCurrentGlContext;
use winit::event_loop::EventLoop;

use std::num::NonZero;


#[derive(Debug)]
pub(crate) struct GlStateWinit {
    inner: RenderBase,
}

impl GlStateWinit {
    pub(crate) fn new(width: NonZero<u32>, height: NonZero<u32>) -> Result<Self, RendererError> {
        let mut event_loop = EventLoop::new().map_err(
            RendererError::EventLoopError
        )?;

        let inner = RenderBase::new(
            width.into(), height.into(), "".to_string(),
            &mut event_loop,
            false
        )?;

        Ok(Self {inner})
    }

    pub(crate) fn make_current(&self) -> Result<(), glutin::error::Error> {
        // SAFETY: GlStateWinit::new() only returns Ok when RenderBase::new()
        // succeeds, which guarantees state is Some (pump_app_events called
        // resumed and RenderBase::new returns Err(NoWindow) otherwise).
        let inner_state = self.inner.state.as_ref().unwrap();
        inner_state.gl_context.make_current(&inner_state.gl_surface)
    }
}