From 788626357a94cb44680052f22e88fe972eef5e03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Fri, 22 May 2020 01:57:42 +0200 Subject: [PATCH] Target GLSL 3.30 --- examples/clipping.rs | 2 +- examples/hello.rs | 2 +- src/pipeline.rs | 34 ++++++++++++++++++++++++++++++++-- src/shader/fragment.frag | 4 ++-- src/shader/vertex.vert | 4 ++-- 5 files changed, 38 insertions(+), 8 deletions(-) diff --git a/examples/clipping.rs b/examples/clipping.rs index 1afee93..f3e51e6 100644 --- a/examples/clipping.rs +++ b/examples/clipping.rs @@ -11,7 +11,7 @@ fn main() -> Result<(), String> { glutin::window::WindowBuilder::new().with_resizable(false); let context = glutin::ContextBuilder::new() - .with_srgb(true) + .with_vsync(true) .build_windowed(window_builder, &event_loop) .expect("Open window"); diff --git a/examples/hello.rs b/examples/hello.rs index 45d2446..68f8840 100644 --- a/examples/hello.rs +++ b/examples/hello.rs @@ -11,7 +11,7 @@ fn main() -> Result<(), String> { glutin::window::WindowBuilder::new().with_resizable(false); let context = glutin::ContextBuilder::new() - .with_srgb(true) + .with_vsync(true) .build_windowed(window_builder, &event_loop) .expect("Open window"); diff --git a/src/pipeline.rs b/src/pipeline.rs index 2130bf5..397d05e 100644 --- a/src/pipeline.rs +++ b/src/pipeline.rs @@ -10,6 +10,8 @@ pub struct Pipeline { program: ::Program, vertex_array: ::VertexArray, instances: ::Buffer, + transform: ::UniformLocation, + sampler: ::UniformLocation, cache: Cache, current_instances: usize, supported_instances: usize, @@ -40,11 +42,35 @@ impl Pipeline { let (vertex_array, instances) = unsafe { create_instance_buffer(gl, Instance::INITIAL_AMOUNT) }; + let transform = unsafe { + gl.get_uniform_location(program, "transform") + .expect("Get transform location") + }; + + let sampler = unsafe { + gl.get_uniform_location(program, "font_sampler") + .expect("Get sampler location") + }; + + unsafe { + gl.use_program(Some(program)); + + gl.uniform_matrix_4_f32_slice( + Some(&transform), + false, + &IDENTITY_MATRIX, + ); + + gl.use_program(None); + } + Pipeline { program, cache, vertex_array, instances, + transform, + sampler, current_instances: 0, supported_instances: Instance::INITIAL_AMOUNT, current_transform: IDENTITY_MATRIX, @@ -63,7 +89,11 @@ impl Pipeline { if self.current_transform != transform { unsafe { - gl.uniform_matrix_4_f32_slice(Some(&0), false, &transform); + gl.uniform_matrix_4_f32_slice( + Some(&self.transform), + false, + &transform, + ); } self.current_transform = transform; @@ -82,7 +112,7 @@ impl Pipeline { gl.active_texture(glow::TEXTURE0); gl.bind_texture(glow::TEXTURE_2D, Some(self.cache.texture)); - gl.uniform_1_i32(Some(&1), 0); + gl.uniform_1_i32(Some(&self.sampler), 0); gl.bind_vertex_array(Some(self.vertex_array)); diff --git a/src/shader/fragment.frag b/src/shader/fragment.frag index 4a335b1..5464b3f 100644 --- a/src/shader/fragment.frag +++ b/src/shader/fragment.frag @@ -1,6 +1,6 @@ -#version 450 +#version 330 -layout(location = 1) uniform sampler2D font_sampler; +uniform sampler2D font_sampler; in vec2 f_tex_pos; in vec4 f_color; diff --git a/src/shader/vertex.vert b/src/shader/vertex.vert index ddfb139..023ce31 100644 --- a/src/shader/vertex.vert +++ b/src/shader/vertex.vert @@ -1,6 +1,6 @@ -#version 450 +#version 330 -layout(location = 0) uniform mat4 transform; +uniform mat4 transform; layout(location = 0) in vec3 left_top; layout(location = 1) in vec2 right_bottom;