diff --git a/hui-glium/shaders/fragment.150.frag b/hui-glium/shaders/fragment.150.frag new file mode 100644 index 0000000..d53bea1 --- /dev/null +++ b/hui-glium/shaders/fragment.150.frag @@ -0,0 +1,13 @@ +#version 150 core + +precision highp float; +precision highp sampler2D; + +out vec4 out_color; +in vec4 vtx_color; +in vec2 vtx_uv; +uniform sampler2D tex; + +void main() { + out_color = texture(tex, vtx_uv) * vtx_color; +} diff --git a/hui-glium/shaders/fragment.frag b/hui-glium/shaders/fragment.es.frag similarity index 100% rename from hui-glium/shaders/fragment.frag rename to hui-glium/shaders/fragment.es.frag diff --git a/hui-glium/shaders/vertex.150.vert b/hui-glium/shaders/vertex.150.vert new file mode 100644 index 0000000..874e872 --- /dev/null +++ b/hui-glium/shaders/vertex.150.vert @@ -0,0 +1,17 @@ +#version 150 core + +precision highp float; + +uniform vec2 resolution; +in vec2 uv; +in vec4 color; +in vec2 position; +out vec4 vtx_color; +out vec2 vtx_uv; + +void main() { + vtx_color = color; + vtx_uv = uv; + vec2 pos2d = (vec2(2., -2.) * (position / resolution)) + vec2(-1, 1); + gl_Position = vec4(pos2d, 0., 1.); +} diff --git a/hui-glium/shaders/vertex.vert b/hui-glium/shaders/vertex.es.vert similarity index 100% rename from hui-glium/shaders/vertex.vert rename to hui-glium/shaders/vertex.es.vert diff --git a/hui-glium/src/lib.rs b/hui-glium/src/lib.rs index 6ce47b1..d75651b 100644 --- a/hui-glium/src/lib.rs +++ b/hui-glium/src/lib.rs @@ -1,19 +1,17 @@ use std::rc::Rc; use glam::Vec2; use glium::{ - Blend, DrawParameters, IndexBuffer, Program, Surface, VertexBuffer, - implement_vertex, uniform, - backend::{Context, Facade}, - index::PrimitiveType, - texture::{RawImage2d, Texture2d}, - uniforms::{MagnifySamplerFilter, MinifySamplerFilter, Sampler, SamplerBehavior, SamplerWrapFunction}, + backend::{Context, Facade}, implement_vertex, index::PrimitiveType, texture::{RawImage2d, Texture2d}, uniform, uniforms::{MagnifySamplerFilter, MinifySamplerFilter, Sampler, SamplerBehavior, SamplerWrapFunction}, Api, Blend, DrawParameters, IndexBuffer, Program, Surface, VertexBuffer }; use hui::{ draw::{TextureAtlasMeta, UiDrawCall, UiVertex}, UiInstance }; -const VERTEX_SHADER: &str = include_str!("../shaders/vertex.vert"); -const FRAGMENT_SHADER: &str = include_str!("../shaders/fragment.frag"); +const VERTEX_SHADER_GLES3: &str = include_str!("../shaders/vertex.es.vert"); +const FRAGMENT_SHADER_GLES3: &str = include_str!("../shaders/fragment.es.frag"); + +const VERTEX_SHADER_150: &str = include_str!("../shaders/vertex.150.vert"); +const FRAGMENT_SHADER_150: &str = include_str!("../shaders/fragment.150.frag"); #[derive(Clone, Copy)] #[repr(C)] @@ -122,7 +120,10 @@ impl GliumUiRenderer { pub fn new(facade: &F) -> Self { log::info!("initializing hui-glium"); Self { - program: Program::from_source(facade, VERTEX_SHADER, FRAGMENT_SHADER, None).unwrap(), + program: match facade.get_context().get_supported_glsl_version().0 { + Api::Gl => Program::from_source(facade, VERTEX_SHADER_150, FRAGMENT_SHADER_150, None).unwrap(), + Api::GlEs => Program::from_source(facade, VERTEX_SHADER_GLES3, FRAGMENT_SHADER_GLES3, None).unwrap(), + }, context: Rc::clone(facade.get_context()), ui_texture: None, buffer_pair: None,