From d949d86ea80488b2912cc2b2fa9e37df6ed44406 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Tue, 21 Nov 2023 18:26:39 +0100 Subject: [PATCH] copy over simple init clode --- Cargo.lock | 2 ++ kubi/Cargo.toml | 2 ++ kubi/src/rendering.rs | 40 ++++++++++++++++++++++++++++++++-------- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f7c302b..ecaee72 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -948,6 +948,7 @@ dependencies = [ "glam", "glium", "glutin", + "glutin-winit", "hashbrown", "image", "kubi-logging", @@ -958,6 +959,7 @@ dependencies = [ "ndk", "nohash-hasher", "postcard", + "raw-window-handle 0.5.2", "rayon", "serde_json", "shipyard", diff --git a/kubi/Cargo.toml b/kubi/Cargo.toml index 48a3c81..e4a5b05 100644 --- a/kubi/Cargo.toml +++ b/kubi/Cargo.toml @@ -16,6 +16,8 @@ log = "0.4" glium = { git = "https://github.com/glium/glium", rev = "968fc92378caf" } glutin = "0.31" winit = { version = "0.29", features = ["android-native-activity"] } +glutin-winit = "0.4" +raw-window-handle = "0.5" glam = { version = "0.24", features = ["debug-glam-assert", "fast-math"] } image = { version = "0.24", default_features = false, features = ["png"] } strum = { version = "0.25", features = ["derive"] } diff --git a/kubi/src/rendering.rs b/kubi/src/rendering.rs index 8438ebb..4431346 100644 --- a/kubi/src/rendering.rs +++ b/kubi/src/rendering.rs @@ -1,11 +1,13 @@ +use std::num::NonZeroU32; +use raw_window_handle::HasRawWindowHandle; use shipyard::{Unique, NonSendSync, UniqueView, UniqueViewMut, View, IntoIter, AllStoragesView}; use winit::{ - event_loop::EventLoop, + event_loop::EventLoopWindowTarget, window::{WindowBuilder, Fullscreen, Window}, dpi::PhysicalSize }; -use glium::{Display, Surface, Version, Api, backend::glutin::SimpleWindowBuilder}; -use glutin::surface::WindowSurface; +use glium::{Display, Surface, Version, Api}; +use glutin::{surface::WindowSurface, display::{GetGlDisplay, GlDisplay}, context::NotCurrentGlContext}; use glam::{Vec3, UVec2}; use crate::{events::WindowResizedEvent, settings::{GameSettings, FullscreenMode}}; @@ -33,7 +35,7 @@ pub struct Renderer { } impl Renderer { - pub fn init(event_loop: &EventLoop<()>, settings: &GameSettings) -> Self { + pub fn init(event_loop: &EventLoopWindowTarget<()>, settings: &GameSettings) -> Self { log::info!("initializing display"); let wb = WindowBuilder::new() @@ -82,9 +84,31 @@ impl Renderer { } }); - let (window, display) = SimpleWindowBuilder::new() - .set_window_builder(wb) - .build(event_loop); + // First we start by opening a new Window + let display_builder = glutin_winit::DisplayBuilder::new().with_window_builder(Some(wb)); + let config_template_builder = glutin::config::ConfigTemplateBuilder::new(); + let (window, gl_config) = display_builder + .build(&event_loop, config_template_builder, |mut configs| { + configs.next().unwrap() + }) + .unwrap(); + let window = window.unwrap(); + + // Now we get the window size to use as the initial size of the Surface + let (width, height): (u32, u32) = window.inner_size().into(); + let attrs = glutin::surface::SurfaceAttributesBuilder::::new().build( + window.raw_window_handle(), + NonZeroU32::new(width).unwrap(), + NonZeroU32::new(height).unwrap(), + ); + + // Finally we can create a Surface, use it to make a PossiblyCurrentContext and create the glium Display + let surface = unsafe { gl_config.display().create_window_surface(&gl_config, &attrs).unwrap() }; + let context_attributes = glutin::context::ContextAttributesBuilder::new().build(Some(window.raw_window_handle())); + let current_context = unsafe { + gl_config.display().create_context(&gl_config, &context_attributes).expect("failed to create context") + }.make_current(&surface).unwrap(); + let display = Display::from_context_surface(current_context, surface).unwrap(); //TODO MIGRATION // let cb = ContextBuilder::new() @@ -106,7 +130,7 @@ impl Renderer { if display.is_context_loss_possible() { log::warn!("OpenGL context loss possible") } if display.is_robust() { log::warn!("OpenGL implementation is not robust") } if display.is_debug() { log::info!("OpenGL context is in debug mode") } - + assert!(display.is_glsl_version_supported(&Version(Api::GlEs, 3, 0)), "GLSL ES 3.0 is not supported"); Self { window, display }