gui changes, use glsl 3.0 es

This commit is contained in:
griffi-gh 2023-02-10 00:46:20 +01:00
parent 7c8a0fb66b
commit 2fc8db6740
12 changed files with 83 additions and 28 deletions

View file

@ -1,4 +1,6 @@
#version 150 core
#version 300 es
precision highp float;
out vec4 out_color;
uniform vec4 color;

View file

@ -1,4 +1,6 @@
#version 150 core
#version 300 es
precision highp float;
in vec3 position;
uniform mat4 model;

View file

@ -1,4 +1,6 @@
#version 150 core
#version 300 es
precision highp float;
in vec2 v_uv;
out vec4 out_color;

View file

@ -1,4 +1,4 @@
#version 150 core
#version 300 es
in vec2 position;
out vec2 v_uv;

View file

@ -1,4 +1,6 @@
#version 150 core
#version 300 es
precision highp float;
out vec4 color;
uniform vec4 u_color;

View file

@ -1,4 +1,6 @@
#version 150 core
#version 300 es
precision highp float;
in vec3 position;
uniform ivec3 u_position;

View file

@ -1,4 +1,7 @@
#version 150 core
#version 300 es
precision highp float;
precision lowp sampler2DArray;
in vec3 v_normal;
in vec2 v_uv;

View file

@ -1,4 +1,6 @@
#version 150 core
#version 300 es
precision highp float;
//TODO pack this data:
// uint position_normal_uv

View file

@ -1,6 +1,7 @@
use glam::UVec2;
use shipyard::{World, Component, AllStoragesViewMut, SparseSet};
use shipyard::{World, Component, AllStoragesViewMut, SparseSet, NonSendSync, UniqueView};
use glium::glutin::event::{Event, DeviceEvent, DeviceId, WindowEvent};
use crate::rendering::Renderer;
pub mod player_actions;
@ -50,6 +51,19 @@ pub fn process_glutin_events(world: &mut World, event: &Event<'_, ()>) {
}
}
pub fn initial_resize_event(
mut storages: AllStoragesViewMut,
) {
let (w, h) = {
let renderer = storages.borrow::<NonSendSync<UniqueView<Renderer>>>().unwrap();
renderer.display.get_framebuffer_dimensions()
};
storages.add_entity((
EventComponent,
WindowResizedEvent(UVec2::new(w, h))
));
}
pub fn clear_events(
mut all_storages: AllStoragesViewMut,
) {

View file

@ -1,6 +1,6 @@
use shipyard::{Component, Unique, Workload, IntoWorkload, AllStoragesView, AllStoragesViewMut};
use glam::{Vec2, Vec4, Mat3, vec2, Mat4};
use crate::{color::color_hex, transform::Transform2d};
use shipyard::{Component, Unique, Workload, IntoWorkload, AllStoragesView, AllStoragesViewMut, View, UniqueView, NonSendSync, UniqueViewMut, IntoIter};
use glam::{Vec4, Mat3, vec2, Mat4};
use crate::{color::color_hex, transform::Transform2d, events::WindowResizedEvent, rendering::Renderer};
pub mod text_widget;
pub mod progressbar;
@ -8,7 +8,7 @@ pub mod progressbar;
use progressbar::{render_progressbars, ProgressbarComponent};
//TODO compute gui scale on window resize
#[derive(Unique, Clone, Copy, Debug)]
#[derive(Unique, Clone, Copy, Debug, Default)]
pub struct GuiView(pub Mat4);
#[derive(Component, Clone, Copy, Debug, Default)]
@ -30,27 +30,44 @@ impl Default for SecondaryColor {
}
}
fn update_gui_view(
mut view: UniqueViewMut<GuiView>,
resize: View<WindowResizedEvent>,
) {
let Some(&size) = resize.iter().next() else {
return
};
let [w, h] = size.0.to_array();
view.0 = Mat4::orthographic_rh_gl(0.0, w as f32, h as f32, 0.0, -1.0, 1.0);
}
pub fn init_gui(
storages: AllStoragesView
) {
storages.add_unique(GuiView::default());
}
pub fn update_gui() -> Workload {
(
update_gui_view
).into_workload()
}
pub fn render_gui() -> Workload {
(
render_progressbars
).into_workload()
}
pub fn init_gui(
storages: AllStoragesView,
) {
storages.add_unique(GuiView(Mat4::orthographic_rh_gl(0.0, 1.0, 1.0, 0.0, 0.0, 1.0)));
}
pub fn gui_testing(
mut storages: AllStoragesViewMut,
) {
storages.add_entity((
GuiComponent,
Transform2d(Mat3::from_scale_angle_translation(
vec2(0.25, 0.05),
vec2(1920., 16.),
0.,
vec2(0.5, 0.25)
vec2(0., 0.)
)),
ProgressbarComponent {
progress: 0.33

View file

@ -1,11 +1,17 @@
use std::net::SocketAddr;
use shipyard::AllStoragesView;
use std::env;
use shipyard::{AllStoragesView, NonSendSync, UniqueView};
use glium::{Version, Api};
use std::{env, net::SocketAddr};
use crate::{
networking::{GameType, ServerAddress},
state::GameState
state::GameState, rendering::Renderer
};
pub fn assert_renderer(
renderer: NonSendSync<UniqueView<Renderer>>
) {
assert!(renderer.display.is_glsl_version_supported(&Version(Api::GlEs, 3, 0)), "GLES 3.0 is not supported");
}
pub fn initialize_from_args(
all_storages: AllStoragesView,
) {

View file

@ -48,7 +48,7 @@ use settings::load_settings;
use camera::compute_cameras;
use events::{
clear_events, process_glutin_events,
player_actions::generate_move_events
player_actions::generate_move_events, initial_resize_event
};
use input::{init_input, process_inputs};
use fly_controller::update_controllers;
@ -67,11 +67,13 @@ use delta_time::{DeltaTime, init_delta_time};
use cursor_lock::{insert_lock_state, update_cursor_lock_state, lock_cursor_now};
use control_flow::{exit_on_esc, insert_control_flow_unique, SetControlFlow};
use state::{is_ingame, is_ingame_or_loading, is_loading};
use init::initialize_from_args;
use gui::{render_gui, init_gui, gui_testing};
use init::{initialize_from_args, assert_renderer};
use gui::{render_gui, init_gui, gui_testing, update_gui};
fn startup() -> Workload {
(
assert_renderer,
initial_resize_event,
load_settings,
load_prefabs,
init_primitives,
@ -106,6 +108,7 @@ fn update() -> Workload {
apply_queued_blocks,
).into_workload().run_if(is_ingame),
compute_cameras,
update_gui,
).into_workload()
}
fn render() -> Workload {