egui_glow: Reduce memory allocations in Painter::set_texture (#1096)
Use bytemuck::cast_slice
This commit is contained in:
parent
d9cfeff72c
commit
6c616a1b69
2 changed files with 5 additions and 6 deletions
|
@ -23,8 +23,9 @@ include = [
|
|||
all-features = true
|
||||
|
||||
[dependencies]
|
||||
egui = { version = "0.16.0", path = "../egui", default-features = false, features = ["single_threaded"] }
|
||||
egui = { version = "0.16.0", path = "../egui", default-features = false, features = ["single_threaded", "convert_bytemuck"] }
|
||||
|
||||
bytemuck = "1.7"
|
||||
epi = { version = "0.16.0", path = "../epi", optional = true }
|
||||
glow = "0.11"
|
||||
memoffset = "0.6"
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use bytemuck::cast_slice;
|
||||
use egui::{
|
||||
emath::Rect,
|
||||
epaint::{Color32, Mesh, Vertex},
|
||||
|
@ -434,17 +435,14 @@ impl Painter {
|
|||
"Mismatch between texture size and texel count"
|
||||
);
|
||||
|
||||
let mut data = Vec::with_capacity(image.pixels.len() * 4);
|
||||
for srgba in &image.pixels {
|
||||
data.extend_from_slice(&srgba.to_array());
|
||||
}
|
||||
let data: &[u8] = cast_slice(image.pixels.as_ref());
|
||||
|
||||
let gl_texture = srgb_texture2d(
|
||||
gl,
|
||||
self.is_webgl_1,
|
||||
self.srgb_support,
|
||||
self.texture_filter,
|
||||
&data,
|
||||
data,
|
||||
image.size[0],
|
||||
image.size[1],
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue