Repository: versotile-org/verso
File: src/rendering.rs (Rust)

Code before:
    context: PossiblyCurrentContext,
    pub(crate) gl: Rc<dyn gl::Gl>,
}

impl RenderingContext {
    /// Create a rendering context instance.
    pub fn create(
        evl: &ActiveEventLoop,
        window: &Window,
    ) -> Result<(Self, Surface<WindowSurface>), Box<dyn std::error::Error>> {
        let template = ConfigTemplateBuilder::new()
            .with_alpha_size(8)
            .with_transparency(cfg!(macos));
        let (_, gl_config) = DisplayBuilder::new().build(evl, template, gl_config_picker)?;

        log::debug!("Picked a config with {} samples", gl_config.num_samples());

        // XXX This will panic on Andoird, but we care about Deskyop for now.
        let raw_window_handle = window.window_handle().ok().map(|handle| handle.as_raw());
        // XXX The display could be obtained from any object created by it, so we can
        // query it from the config.
        let gl_display = gl_config.display();
        // The context creation part.
        let context_attributes = ContextAttributesBuilder::new().build(raw_window_handle);
        // Since glutin by default tries to create OpenGL core context, which may not be
        // present we should try gles.
        let fallback_context_attributes = ContextAttributesBuilder::new()
            .with_context_api(ContextApi::Gles(None))
            .build(raw_window_handle);
        // There are also some old devices that support neither modern OpenGL nor GLES.
        // To support these we can try and create a 2.1 context.
        let legacy_context_attributes = ContextAttributesBuilder::new()
            .with_context_api(ContextApi::OpenGl(Some(Version::new(2, 1))))
            .build(raw_window_handle);
        let not_current_gl_context = unsafe {
            gl_display
                .create_context(&gl_config, &context_attributes)
                .unwrap_or_else(|_| {
                    gl_display
                        .create_context(&gl_config, &fallback_context_attributes)
                        .unwrap_or_else(|_| {
                            gl_display
                                .create_context(&gl_config, &legacy_context_attributes)
                                .expect("failed to create context")
                        })
                })
        };

        // Create surface
        let attrs = window
            .build_surface_attributes(Default::default())

Review comment (suggestion):
```suggestion
        // present we should try GLES.
```
minor, but since GLES is then mentioned in full capital then might as well use consistent wording.

Code after:
    context: PossiblyCurrentContext,
    pub(crate) gl: Rc<dyn gl::Gl>,
}

impl RenderingContext {
    /// Create a rendering context instance.
    pub fn create(
        evl: &ActiveEventLoop,
        window: &Window,
    ) -> Result<(Self, Surface<WindowSurface>), Box<dyn std::error::Error>> {
        let template = ConfigTemplateBuilder::new()
            .with_alpha_size(8)
            .with_transparency(cfg!(macos));
        let (_, gl_config) = DisplayBuilder::new().build(evl, template, gl_config_picker)?;

        log::debug!("Picked a config with {} samples", gl_config.num_samples());

        // XXX This will panic on Android, but we care about Desktop for now.
        let raw_window_handle = window.window_handle().ok().map(|handle| handle.as_raw());
        // XXX The display could be obtained from any object created by it, so we can
        // query it from the config.
        let gl_display = gl_config.display();
        // The context creation part.
        let context_attributes = ContextAttributesBuilder::new().build(raw_window_handle);
        // Since glutin by default tries to create OpenGL core context, which may not be
        // present we should try GLES.
        let fallback_context_attributes = ContextAttributesBuilder::new()
            .with_context_api(ContextApi::Gles(None))
            .build(raw_window_handle);
        // There are also some old devices that support neither modern OpenGL nor GLES.
        // To support these we can try and create a 2.1 context.
        let legacy_context_attributes = ContextAttributesBuilder::new()
            .with_context_api(ContextApi::OpenGl(Some(Version::new(2, 1))))
            .build(raw_window_handle);
        let not_current_gl_context = unsafe {
            gl_display
                .create_context(&gl_config, &context_attributes)
                .unwrap_or_else(|_| {
                    gl_display
                        .create_context(&gl_config, &fallback_context_attributes)
                        .unwrap_or_else(|_| {
                            gl_display
                                .create_context(&gl_config, &legacy_context_attributes)
                                .expect("failed to create context")
                        })
                })
        };

        // Create surface
        let attrs = window
            .build_surface_attributes(Default::default())