mirror of
https://github.com/griffi-gh/hUI.git
synced 2024-12-22 04:18:21 -06:00
load shader based on api
This commit is contained in:
parent
55c908a3b9
commit
efe7326b4d
13
hui-glium/shaders/fragment.150.frag
Normal file
13
hui-glium/shaders/fragment.150.frag
Normal file
|
@ -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;
|
||||
}
|
17
hui-glium/shaders/vertex.150.vert
Normal file
17
hui-glium/shaders/vertex.150.vert
Normal file
|
@ -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.);
|
||||
}
|
|
@ -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<F: Facade>(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,
|
||||
|
|
Loading…
Reference in a new issue