copy over simple init clode

This commit is contained in:
griffi-gh 2023-11-21 18:26:39 +01:00
parent 8c0004e990
commit d949d86ea8
3 changed files with 36 additions and 8 deletions

2
Cargo.lock generated
View file

@ -948,6 +948,7 @@ dependencies = [
"glam", "glam",
"glium", "glium",
"glutin", "glutin",
"glutin-winit",
"hashbrown", "hashbrown",
"image", "image",
"kubi-logging", "kubi-logging",
@ -958,6 +959,7 @@ dependencies = [
"ndk", "ndk",
"nohash-hasher", "nohash-hasher",
"postcard", "postcard",
"raw-window-handle 0.5.2",
"rayon", "rayon",
"serde_json", "serde_json",
"shipyard", "shipyard",

View file

@ -16,6 +16,8 @@ log = "0.4"
glium = { git = "https://github.com/glium/glium", rev = "968fc92378caf" } glium = { git = "https://github.com/glium/glium", rev = "968fc92378caf" }
glutin = "0.31" glutin = "0.31"
winit = { version = "0.29", features = ["android-native-activity"] } 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"] } glam = { version = "0.24", features = ["debug-glam-assert", "fast-math"] }
image = { version = "0.24", default_features = false, features = ["png"] } image = { version = "0.24", default_features = false, features = ["png"] }
strum = { version = "0.25", features = ["derive"] } strum = { version = "0.25", features = ["derive"] }

View file

@ -1,11 +1,13 @@
use std::num::NonZeroU32;
use raw_window_handle::HasRawWindowHandle;
use shipyard::{Unique, NonSendSync, UniqueView, UniqueViewMut, View, IntoIter, AllStoragesView}; use shipyard::{Unique, NonSendSync, UniqueView, UniqueViewMut, View, IntoIter, AllStoragesView};
use winit::{ use winit::{
event_loop::EventLoop, event_loop::EventLoopWindowTarget,
window::{WindowBuilder, Fullscreen, Window}, window::{WindowBuilder, Fullscreen, Window},
dpi::PhysicalSize dpi::PhysicalSize
}; };
use glium::{Display, Surface, Version, Api, backend::glutin::SimpleWindowBuilder}; use glium::{Display, Surface, Version, Api};
use glutin::surface::WindowSurface; use glutin::{surface::WindowSurface, display::{GetGlDisplay, GlDisplay}, context::NotCurrentGlContext};
use glam::{Vec3, UVec2}; use glam::{Vec3, UVec2};
use crate::{events::WindowResizedEvent, settings::{GameSettings, FullscreenMode}}; use crate::{events::WindowResizedEvent, settings::{GameSettings, FullscreenMode}};
@ -33,7 +35,7 @@ pub struct Renderer {
} }
impl 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"); log::info!("initializing display");
let wb = WindowBuilder::new() let wb = WindowBuilder::new()
@ -82,9 +84,31 @@ impl Renderer {
} }
}); });
let (window, display) = SimpleWindowBuilder::new() // First we start by opening a new Window
.set_window_builder(wb) let display_builder = glutin_winit::DisplayBuilder::new().with_window_builder(Some(wb));
.build(event_loop); 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::<glutin::surface::WindowSurface>::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 //TODO MIGRATION
// let cb = ContextBuilder::new() // 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_context_loss_possible() { log::warn!("OpenGL context loss possible") }
if display.is_robust() { log::warn!("OpenGL implementation is not robust") } if display.is_robust() { log::warn!("OpenGL implementation is not robust") }
if display.is_debug() { log::info!("OpenGL context is in debug mode") } 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"); assert!(display.is_glsl_version_supported(&Version(Api::GlEs, 3, 0)), "GLSL ES 3.0 is not supported");
Self { window, display } Self { window, display }