change ui pipeline fns push_quad/tri_to_mesh() into create_quad/tri()

Former-commit-id: 236ef2f0065ddb6e913923c41a37f172b323d610
This commit is contained in:
Imbris 2019-03-31 18:03:46 -04:00
parent ca454d0c8b
commit 6653376492
3 changed files with 18 additions and 22 deletions

View File

@ -30,8 +30,8 @@ pub use self::{
Locals as TerrainLocals,
},
ui::{
push_quad_to_mesh as push_ui_quad_to_mesh,
push_tri_to_mesh as push_ui_tri_to_mesh,
create_quad as create_ui_quad,
create_tri as create_ui_tri,
Mode as UiMode,
UiPipeline,
},

View File

@ -66,7 +66,7 @@ impl Mode {
}
}
pub fn push_quad_to_mesh(mesh: &mut Mesh<UiPipeline>, rect: Aabr<f32>, uv_rect: Aabr<f32>, color: [f32; 4], mode: Mode) {
pub fn create_quad(rect: Aabr<f32>, uv_rect: Aabr<f32>, color: [f32; 4], mode: Mode) -> Quad<UiPipeline> {
let mode_val = mode.value();
let v = |pos, uv| {
Vertex {
@ -83,15 +83,15 @@ pub fn push_quad_to_mesh(mesh: &mut Mesh<UiPipeline>, rect: Aabr<f32>, uv_rect:
let (l, b, r, t) = aabr_to_lbrt(rect);
let (uv_l, uv_b, uv_r, uv_t) = aabr_to_lbrt(uv_rect);
mesh.push_quad(Quad::new(
Quad::new(
v([r, t], [uv_r, uv_t]),
v([l, t], [uv_l, uv_t]),
v([l, b], [uv_l, uv_b]),
v([r, b], [uv_r, uv_b]),
));
)
}
pub fn push_tri_to_mesh(mesh: &mut Mesh<UiPipeline>, tri: [[f32; 2]; 3], uv_tri: [[f32; 2]; 3], color: [f32; 4], mode: Mode) {
pub fn create_tri(tri: [[f32; 2]; 3], uv_tri: [[f32; 2]; 3], color: [f32; 4], mode: Mode) -> Tri<UiPipeline> {
let mode_val = mode.value();
let v = |pos, uv| {
Vertex {
@ -101,9 +101,9 @@ pub fn push_tri_to_mesh(mesh: &mut Mesh<UiPipeline>, tri: [[f32; 2]; 3], uv_tri:
mode: mode_val,
}
};
mesh.push_tri(Tri::new(
Tri::new(
v([tri[0][0], tri[0][1]], [uv_tri[0][0], uv_tri[0][1]]),
v([tri[1][0], tri[1][1]], [uv_tri[1][0], uv_tri[1][1]]),
v([tri[2][0], tri[2][1]], [uv_tri[2][0], uv_tri[2][1]]),
));
)
}

View File

@ -29,8 +29,8 @@ use crate::{
Texture,
UiPipeline,
UiMode,
push_ui_quad_to_mesh,
push_ui_tri_to_mesh,
create_ui_quad,
create_ui_tri,
},
window::Window,
};
@ -412,13 +412,12 @@ impl Ui {
min: Vec2::new(uv_l, uv_b),
max: Vec2::new(uv_r, uv_t),
};
push_ui_quad_to_mesh(
&mut mesh,
mesh.push_quad(create_ui_quad(
gl_aabr(rect),
uv,
color,
UiMode::Image,
);
));
}
PrimitiveKind::Text { color, text, font_id } => {
@ -463,13 +462,12 @@ impl Ui {
(screen_rect.min.y as f32 / screen_h - 0.5) * -2.0,
),
};
push_ui_quad_to_mesh(
&mut mesh,
mesh.push_quad(create_ui_quad(
rect,
uv,
color,
UiMode::Text,
);
));
}
}
}
@ -483,8 +481,7 @@ impl Ui {
switch_to_plain_state!();
push_ui_quad_to_mesh(
&mut mesh,
mesh.push_quad(create_ui_quad(
gl_aabr(rect),
Aabr {
min: Vec2::new(0.0, 0.0),
@ -492,7 +489,7 @@ impl Ui {
},
color,
UiMode::Geometry,
);
));
}
PrimitiveKind::TrianglesSingleColor { color, triangles } => {
// Don't draw transparent triangle or switch state if there are actually no triangles
@ -518,13 +515,12 @@ impl Ui {
p1.into_array(),
p3.into_array(),
]};
push_ui_tri_to_mesh(
&mut mesh,
mesh.push_tri(create_ui_tri(
triangle,
[[0.0; 2]; 3],
color,
UiMode::Geometry,
);
));
}
}