mirror of
https://github.com/alacritty/alacritty.git
synced 2025-09-04 22:43:53 -04:00
Implement per vertex struct
This commit is contained in:
parent
eac2d01af4
commit
77cfb7b5cd
2 changed files with 48 additions and 43 deletions
|
@ -1,11 +1,12 @@
|
||||||
#version 330 core
|
#version 330 core
|
||||||
layout (location = 0) in vec4 vertex;
|
layout (location = 0) in vec2 position;
|
||||||
|
layout (location = 1) in vec2 uvMask;
|
||||||
out vec2 TexCoords;
|
out vec2 TexCoords;
|
||||||
|
|
||||||
uniform mat4 projection;
|
uniform mat4 projection;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = projection * vec4(vertex.xy, 0.0, 1.0);
|
gl_Position = projection * vec4(position.xy, 0.0, 1.0);
|
||||||
TexCoords = vertex.zw;
|
TexCoords = uvMask.xy;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,26 +23,15 @@ pub struct QuadRenderer {
|
||||||
ebo: GLuint,
|
ebo: GLuint,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct PackedQuad {
|
#[allow(dead_code)]
|
||||||
pub x_tr: f32,
|
#[derive(Debug)]
|
||||||
pub y_tr: f32,
|
pub struct PackedVertex {
|
||||||
pub u_tr: f32,
|
x: f32,
|
||||||
pub v_tr: f32,
|
y: f32,
|
||||||
pub x_br: f32,
|
u: f32,
|
||||||
pub y_br: f32,
|
v: f32,
|
||||||
pub u_br: f32,
|
|
||||||
pub v_br: f32,
|
|
||||||
pub x_bl: f32,
|
|
||||||
pub y_bl: f32,
|
|
||||||
pub u_bl: f32,
|
|
||||||
pub v_bl: f32,
|
|
||||||
pub x_tl: f32,
|
|
||||||
pub y_tl: f32,
|
|
||||||
pub u_tl: f32,
|
|
||||||
pub v_tl: f32,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl QuadRenderer {
|
impl QuadRenderer {
|
||||||
// TODO should probably hand this a transform instead of width/height
|
// TODO should probably hand this a transform instead of width/height
|
||||||
pub fn new(width: u32, height: u32) -> QuadRenderer {
|
pub fn new(width: u32, height: u32) -> QuadRenderer {
|
||||||
|
@ -61,7 +50,7 @@ impl QuadRenderer {
|
||||||
gl::BindBuffer(gl::ARRAY_BUFFER, vbo);
|
gl::BindBuffer(gl::ARRAY_BUFFER, vbo);
|
||||||
gl::BufferData(
|
gl::BufferData(
|
||||||
gl::ARRAY_BUFFER,
|
gl::ARRAY_BUFFER,
|
||||||
(size_of::<f32>() * 4 * 4) as GLsizeiptr,
|
(size_of::<PackedVertex>() * 4) as GLsizeiptr,
|
||||||
ptr::null(),
|
ptr::null(),
|
||||||
gl::DYNAMIC_DRAW
|
gl::DYNAMIC_DRAW
|
||||||
);
|
);
|
||||||
|
@ -76,12 +65,23 @@ impl QuadRenderer {
|
||||||
gl::STATIC_DRAW);
|
gl::STATIC_DRAW);
|
||||||
|
|
||||||
gl::EnableVertexAttribArray(0);
|
gl::EnableVertexAttribArray(0);
|
||||||
gl::VertexAttribPointer(0, 4, gl::FLOAT, gl::FALSE, 4 * size_of::<f32>() as i32,
|
gl::EnableVertexAttribArray(1);
|
||||||
|
|
||||||
|
// positions
|
||||||
|
gl::VertexAttribPointer(0, 2,
|
||||||
|
gl::FLOAT, gl::FALSE,
|
||||||
|
size_of::<PackedVertex>() as i32,
|
||||||
ptr::null());
|
ptr::null());
|
||||||
|
|
||||||
gl::BindBuffer(gl::ELEMENT_ARRAY_BUFFER, 0);
|
// uv mapping
|
||||||
gl::BindBuffer(gl::ARRAY_BUFFER, 0);
|
gl::VertexAttribPointer(1, 2,
|
||||||
|
gl::FLOAT, gl::FALSE,
|
||||||
|
size_of::<PackedVertex>() as i32,
|
||||||
|
(2 * size_of::<f32>()) as *const _);
|
||||||
|
|
||||||
gl::BindVertexArray(0);
|
gl::BindVertexArray(0);
|
||||||
|
gl::BindBuffer(gl::ARRAY_BUFFER, 0);
|
||||||
|
gl::BindBuffer(gl::ELEMENT_ARRAY_BUFFER, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
QuadRenderer {
|
QuadRenderer {
|
||||||
|
@ -101,23 +101,27 @@ impl QuadRenderer {
|
||||||
|
|
||||||
let rect = get_rect(glyph, x, y);
|
let rect = get_rect(glyph, x, y);
|
||||||
|
|
||||||
let packed = [PackedQuad {
|
// Top right, Bottom right, Bottom left, Top left
|
||||||
x_tr: rect.max_x(),
|
let packed = [PackedVertex {
|
||||||
y_tr: rect.max_y(),
|
x: rect.max_x(),
|
||||||
u_tr: 1.0,
|
y: rect.max_y(),
|
||||||
v_tr: 0.0,
|
u: 1.0,
|
||||||
x_br: rect.max_x(),
|
v: 0.0,
|
||||||
y_br: rect.min_y(),
|
}, PackedVertex {
|
||||||
u_br: 1.0,
|
x: rect.max_x(),
|
||||||
v_br: 1.0,
|
y: rect.min_y(),
|
||||||
x_bl: rect.min_x(),
|
u: 1.0,
|
||||||
y_bl: rect.min_y(),
|
v: 1.0,
|
||||||
u_bl: 0.0,
|
}, PackedVertex {
|
||||||
v_bl: 1.0,
|
x: rect.min_x(),
|
||||||
x_tl: rect.min_x(),
|
y: rect.min_y(),
|
||||||
y_tl: rect.max_y(),
|
u: 0.0,
|
||||||
u_tl: 0.0,
|
v: 1.0,
|
||||||
v_tl: 0.0,
|
}, PackedVertex {
|
||||||
|
x: rect.min_x(),
|
||||||
|
y: rect.max_y(),
|
||||||
|
u: 0.0,
|
||||||
|
v: 0.0,
|
||||||
}];
|
}];
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -128,7 +132,7 @@ impl QuadRenderer {
|
||||||
gl::BufferSubData(
|
gl::BufferSubData(
|
||||||
gl::ARRAY_BUFFER,
|
gl::ARRAY_BUFFER,
|
||||||
0,
|
0,
|
||||||
(packed.len() * size_of::<PackedQuad>()) as isize,
|
(packed.len() * size_of::<PackedVertex>()) as isize,
|
||||||
packed.as_ptr() as *const _
|
packed.as_ptr() as *const _
|
||||||
);
|
);
|
||||||
gl::BindBuffer(gl::ARRAY_BUFFER, 0);
|
gl::BindBuffer(gl::ARRAY_BUFFER, 0);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue