1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2025-09-18 22:59:47 -04:00

Bit of cleanup

- Commend vertex slice
- Add helper for binding mask texture (and specify that it's a mask)
- Prefix uniform members of ShaderProgram with u_. This makes it easy to
  identify in the rest of code.
This commit is contained in:
Joe Wilm 2016-02-24 20:37:17 -08:00
parent 5226666690
commit cda4952145
2 changed files with 23 additions and 16 deletions

View file

@ -1,11 +1,11 @@
#version 330 core #version 330 core
in vec2 TexCoords; in vec2 TexCoords;
uniform sampler2D text; uniform sampler2D mask;
uniform vec3 textColor; uniform vec3 textColor;
void main() void main()
{ {
vec4 sampled = vec4(1.0, 1.0, 1.0, texture(text, TexCoords).r); vec4 sampled = vec4(1.0, 1.0, 1.0, texture(mask, TexCoords).r);
gl_FragColor = vec4(textColor, 1.0) * sampled; gl_FragColor = vec4(textColor, 1.0) * sampled;
} }

View file

@ -120,24 +120,23 @@ fn render(program: &ShaderProgram, glyph: &RasterizedGlyph, tex: &AlphaTexture,
program.activate(); program.activate();
unsafe { unsafe {
// set color // set color
gl::Uniform3f(program.color, 1., 1., 0.5); gl::Uniform3f(program.u_color, 1., 1., 0.5);
} }
let rect = get_rect(glyph, 10.0, 10.0); let rect = get_rect(glyph, 10.0, 10.0);
// top right of character // top right of character
let vertices: [[f32; 4]; 4] = [ let vertices: [[f32; 4]; 4] = [
[rect.max_x(), rect.max_y(), 1., 0.], [rect.max_x(), rect.max_y(), 1., 0.], // top-right
[rect.max_x(), rect.min_y(), 1., 1.], [rect.max_x(), rect.min_y(), 1., 1.], // bottom-right
[rect.min_x(), rect.min_y(), 0., 1.], [rect.min_x(), rect.min_y(), 0., 1.], // bottom-left
[rect.min_x(), rect.max_y(), 0., 0.], [rect.min_x(), rect.max_y(), 0., 0.], // top-left
]; ];
unsafe { unsafe {
gl::ActiveTexture(gl::TEXTURE0); bind_mask_texture(tex.id);
gl::BindVertexArray(vao); gl::BindVertexArray(vao);
gl::BindTexture(gl::TEXTURE_2D, tex.id);
gl::BindBuffer(gl::ARRAY_BUFFER, vbo); gl::BindBuffer(gl::ARRAY_BUFFER, vbo);
gl::BufferSubData( gl::BufferSubData(
gl::ARRAY_BUFFER, gl::ARRAY_BUFFER,
@ -156,12 +155,19 @@ fn render(program: &ShaderProgram, glyph: &RasterizedGlyph, tex: &AlphaTexture,
program.deactivate(); program.deactivate();
} }
fn bind_mask_texture(id: u32) {
unsafe {
gl::ActiveTexture(gl::TEXTURE0);
gl::BindTexture(gl::TEXTURE_2D, id);
}
}
pub struct ShaderProgram { pub struct ShaderProgram {
id: GLuint, id: GLuint,
/// uniform location for projection matrix /// projection matrix uniform
projection: GLint, u_projection: GLint,
/// uniform location foyr textColor /// color uniform
color: GLint, u_color: GLint,
} }
impl ShaderProgram { impl ShaderProgram {
@ -205,8 +211,8 @@ impl ShaderProgram {
let shader = ShaderProgram { let shader = ShaderProgram {
id: program, id: program,
projection: projection, u_projection: projection,
color: color, u_color: color,
}; };
// set projection uniform // set projection uniform
@ -217,7 +223,8 @@ impl ShaderProgram {
shader.activate(); shader.activate();
unsafe { unsafe {
gl::UniformMatrix4fv(shader.projection, 1, gl::FALSE, projection.as_ptr() as *const _); gl::UniformMatrix4fv(shader.u_projection,
1, gl::FALSE, projection.as_ptr() as *const _);
} }
shader.deactivate(); shader.deactivate();