mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 06:40:06 -04:00
Mesh::split_to_u16 now returns a 16-bit indexed Mesh16
This commit is contained in:
@@ -8,7 +8,7 @@ use {
|
||||
|
||||
use egui::{
|
||||
math::clamp,
|
||||
paint::{Color32, Mesh, Texture},
|
||||
paint::{Color32, Texture},
|
||||
vec2,
|
||||
};
|
||||
|
||||
@@ -255,9 +255,8 @@ impl WebGl2Painter {
|
||||
}
|
||||
}
|
||||
|
||||
fn paint_mesh(&self, mesh: &Mesh) -> Result<(), JsValue> {
|
||||
fn paint_mesh(&self, mesh: &egui::paint::Mesh16) -> Result<(), JsValue> {
|
||||
debug_assert!(mesh.is_valid());
|
||||
let indices: Vec<u16> = mesh.indices.iter().map(|idx| *idx as u16).collect();
|
||||
|
||||
let mut positions: Vec<f32> = Vec::with_capacity(2 * mesh.vertices.len());
|
||||
let mut tex_coords: Vec<f32> = Vec::with_capacity(2 * mesh.vertices.len());
|
||||
@@ -283,9 +282,9 @@ impl WebGl2Painter {
|
||||
let indices_memory_buffer = wasm_bindgen::memory()
|
||||
.dyn_into::<WebAssembly::Memory>()?
|
||||
.buffer();
|
||||
let indices_ptr = indices.as_ptr() as u32 / 2;
|
||||
let indices_ptr = mesh.indices.as_ptr() as u32 / 2;
|
||||
let indices_array = js_sys::Int16Array::new(&indices_memory_buffer)
|
||||
.subarray(indices_ptr, indices_ptr + indices.len() as u32);
|
||||
.subarray(indices_ptr, indices_ptr + mesh.indices.len() as u32);
|
||||
|
||||
gl.bind_buffer(Gl::ELEMENT_ARRAY_BUFFER, Some(&self.index_buffer));
|
||||
gl.buffer_data_with_array_buffer_view(
|
||||
@@ -369,7 +368,12 @@ impl WebGl2Painter {
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
gl.draw_elements_with_i32(Gl::TRIANGLES, indices.len() as i32, Gl::UNSIGNED_SHORT, 0);
|
||||
gl.draw_elements_with_i32(
|
||||
Gl::TRIANGLES,
|
||||
mesh.indices.len() as i32,
|
||||
Gl::UNSIGNED_SHORT,
|
||||
0,
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user