mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 06:10:06 -04:00
egui_glow: Reduce memory allocations in Painter::set_texture (#1096)
Use bytemuck::cast_slice
This commit is contained in:
@@ -23,8 +23,9 @@ include = [
|
|||||||
all-features = true
|
all-features = true
|
||||||
|
|
||||||
[dependencies]
|
[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 }
|
epi = { version = "0.16.0", path = "../epi", optional = true }
|
||||||
glow = "0.11"
|
glow = "0.11"
|
||||||
memoffset = "0.6"
|
memoffset = "0.6"
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use bytemuck::cast_slice;
|
||||||
use egui::{
|
use egui::{
|
||||||
emath::Rect,
|
emath::Rect,
|
||||||
epaint::{Color32, Mesh, Vertex},
|
epaint::{Color32, Mesh, Vertex},
|
||||||
@@ -434,17 +435,14 @@ impl Painter {
|
|||||||
"Mismatch between texture size and texel count"
|
"Mismatch between texture size and texel count"
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut data = Vec::with_capacity(image.pixels.len() * 4);
|
let data: &[u8] = cast_slice(image.pixels.as_ref());
|
||||||
for srgba in &image.pixels {
|
|
||||||
data.extend_from_slice(&srgba.to_array());
|
|
||||||
}
|
|
||||||
|
|
||||||
let gl_texture = srgb_texture2d(
|
let gl_texture = srgb_texture2d(
|
||||||
gl,
|
gl,
|
||||||
self.is_webgl_1,
|
self.is_webgl_1,
|
||||||
self.srgb_support,
|
self.srgb_support,
|
||||||
self.texture_filter,
|
self.texture_filter,
|
||||||
&data,
|
data,
|
||||||
image.size[0],
|
image.size[0],
|
||||||
image.size[1],
|
image.size[1],
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user