mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
add graphic cache clearing on resize
Former-commit-id: 49b3a52036171fd8b66d9fae73bebb15fbf83a0b
This commit is contained in:
parent
7707636c4e
commit
1143c58e37
30
Cargo.lock
generated
30
Cargo.lock
generated
@ -414,13 +414,13 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "dot_vox"
|
||||
version = "1.0.1"
|
||||
version = "4.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"nom 3.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -897,14 +897,6 @@ dependencies = [
|
||||
"libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.2.0"
|
||||
@ -1005,14 +997,6 @@ dependencies = [
|
||||
"rand 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nom"
|
||||
version = "3.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"memchr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nom"
|
||||
version = "4.2.3"
|
||||
@ -1933,7 +1917,7 @@ name = "veloren-common"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"bincode 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"dot_vox 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"dot_vox 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"mio-extras 2.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -1977,7 +1961,7 @@ dependencies = [
|
||||
"config 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"conrod_core 0.63.0 (git+https://gitlab.com/veloren/conrod.git)",
|
||||
"conrod_winit 0.63.0 (git+https://gitlab.com/veloren/conrod.git)",
|
||||
"dot_vox 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"dot_vox 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"euc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -2247,7 +2231,7 @@ dependencies = [
|
||||
"checksum deflate 0.7.19 (registry+https://github.com/rust-lang/crates.io-index)" = "8a6abb26e16e8d419b5c78662aa9f82857c2386a073da266840e474d5055ec86"
|
||||
"checksum derivative 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6073e9676dbebdddeabaeb63e3b7cefd23c86f5c41d381ee1237cc77b1079898"
|
||||
"checksum dlib 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "77e51249a9d823a4cb79e3eca6dcd756153e8ed0157b6c04775d04bf1b13b76a"
|
||||
"checksum dot_vox 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bfa4d1fc391ef151fff024e8427d206af1adbef4281fcd875090f74697000441"
|
||||
"checksum dot_vox 4.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "11afd3251e588f2770226659b2a1d55ec2f8aaf2ca42bdcdbd01ff53b4a81e70"
|
||||
"checksum downcast-rs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f2b92dfd5c2f75260cbf750572f95d387e7ca0ba5e3fbe9e1a33f23025be020f"
|
||||
"checksum draw_state 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "33cf9537e2d06891448799b96d5a8c8083e0e90522a7fdabe6ebf4f41d79d651"
|
||||
"checksum either 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5527cfe0d098f36e3f8839852688e63c8fff1c90b2b405aef730615f9a7bcf7b"
|
||||
@ -2305,7 +2289,6 @@ dependencies = [
|
||||
"checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6"
|
||||
"checksum lzw 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d947cbb889ed21c2a84be6ffbaebf5b4e0f4340638cba0444907e38b56be084"
|
||||
"checksum malloc_buf 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb"
|
||||
"checksum memchr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "148fab2e51b4f1cfc66da2a7c32981d1d3c083a803978268bb11fe4b86925e7a"
|
||||
"checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39"
|
||||
"checksum memmap 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b"
|
||||
"checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3"
|
||||
@ -2317,7 +2300,6 @@ dependencies = [
|
||||
"checksum nix 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "46f0f3210768d796e8fa79ec70ee6af172dacbe7147f5e69be5240a47778302b"
|
||||
"checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945"
|
||||
"checksum noise 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9a3a34d4f8a31f95919b7ead9f5b60afb9bda0cae98b9219432ffaa6f00b0141"
|
||||
"checksum nom 3.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05aec50c70fd288702bcd93284a8444607f3292dbdf2a30de5ea5dcdbe72287b"
|
||||
"checksum nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2ad2a91a8e869eeb30b9cb3119ae87773a8f4ae617f41b1eb9c154b2905f7bd6"
|
||||
"checksum nonzero_signed 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "02783a0482333b0d3f5f5411b8fb60454a596696da041da0470ac9ef3e6e37d8"
|
||||
"checksum num 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cf4825417e1e1406b3782a8ce92f4d53f26ec055e3622e1881ca8e9f5f9e08db"
|
||||
|
@ -10,7 +10,7 @@ sphynx = { git = "https://gitlab.com/veloren/sphynx.git", features = ["serde1"]
|
||||
specs = { version = "0.14", features = ["serde"] }
|
||||
shred = { version = "0.7", features = ["nightly"] }
|
||||
vek = { version = "0.9", features = ["serde"] }
|
||||
dot_vox = "1.0"
|
||||
dot_vox = "4.0"
|
||||
threadpool = "1.7"
|
||||
mio = "0.6"
|
||||
mio-extras = "2.0"
|
||||
|
@ -36,7 +36,7 @@ failure = "0.1"
|
||||
lazy_static = "1.1"
|
||||
log = "0.4"
|
||||
pretty_env_logger = "0.3"
|
||||
dot_vox = "1.0"
|
||||
dot_vox = "4.0"
|
||||
image = "0.21"
|
||||
config = "0.9"
|
||||
serde = "1.0"
|
||||
|
@ -44,7 +44,6 @@ widget_ids! {
|
||||
// Error
|
||||
error_frame,
|
||||
button_ok,
|
||||
test_vox,
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,14 +65,10 @@ struct Imgs {
|
||||
button_dark: ImgId,
|
||||
button_dark_hover: ImgId,
|
||||
button_dark_press: ImgId,
|
||||
test_vox: ImgId,
|
||||
}
|
||||
impl Imgs {
|
||||
fn new(ui: &mut Ui, renderer: &mut Renderer) -> Imgs {
|
||||
fn load_segment(filename: &'static str) -> Segment {
|
||||
Segment::from(dot_vox::load(&(concat!(env!("CARGO_MANIFEST_DIR"), "/../assets/voxygen/").to_string() + filename)).unwrap())
|
||||
}
|
||||
let mut load = |filename| {
|
||||
let mut load_img = |filename, ui: &mut Ui| {
|
||||
let fullpath: String = ["/voxygen/", filename].concat();
|
||||
let image = image::load_from_memory(
|
||||
assets::load(fullpath.as_str())
|
||||
@ -83,29 +78,39 @@ impl Imgs {
|
||||
.unwrap();
|
||||
ui.new_graphic(ui::Graphic::Image(image))
|
||||
};
|
||||
let mut load_vox = |filename, ui: &mut Ui| {
|
||||
let fullpath: String = ["/voxygen/", filename].concat();
|
||||
let dot_vox = dot_vox::load_bytes(
|
||||
assets::load(fullpath.as_str())
|
||||
.expect("Error loading file")
|
||||
.as_slice(),
|
||||
)
|
||||
.unwrap();
|
||||
ui.new_graphic(ui::Graphic::Voxel(Segment::from(dot_vox)))
|
||||
};
|
||||
Imgs {
|
||||
bg: load("background/bg_main.png"),
|
||||
v_logo: load("element/v_logo.png"),
|
||||
bg: load_img("background/bg_main.png", ui),
|
||||
v_logo: load_img("element/v_logo.png", ui),
|
||||
|
||||
// Input fields
|
||||
input_bg: load("element/misc_backgrounds/textbox.png"),
|
||||
input_bg: load_img("element/misc_backgrounds/textbox.png", ui),
|
||||
|
||||
// Login button
|
||||
login_button: load("element/buttons/button_login.png"),
|
||||
login_button_hover: load("element/buttons/button_login_hover.png"),
|
||||
login_button_press: load("element/buttons/button_login_press.png"),
|
||||
login_button: load_img("element/buttons/button_login.png", ui),
|
||||
login_button_hover: load_img("element/buttons/button_login_hover.png", ui),
|
||||
login_button_press: load_img("element/buttons/button_login_press.png", ui),
|
||||
|
||||
// Servers, settings, and quit buttons
|
||||
button: load("element/buttons/button.png"),
|
||||
button_hover: load("element/buttons/button_hover.png"),
|
||||
button_press: load("element/buttons/button_press.png"),
|
||||
//button: load_vox("element/buttons/button.vox", ui),
|
||||
button: load_img("element/buttons/button.png", ui),
|
||||
button_hover: load_img("element/buttons/button_hover.png", ui),
|
||||
button_press: load_img("element/buttons/button_press.png", ui),
|
||||
|
||||
//Error
|
||||
error_frame: load("element/frames/window_2.png"),
|
||||
button_dark: load("element/buttons/button_dark.png"),
|
||||
button_dark_hover: load("element/buttons/button_dark_hover.png"),
|
||||
button_dark_press: load("element/buttons/button_dark_press.png"),
|
||||
test_vox: ui.new_graphic(ui::Graphic::Voxel(load_segment("test.vox"))),
|
||||
error_frame: load_img("element/frames/window_2.png", ui),
|
||||
button_dark: load_img("element/buttons/button_dark.png", ui),
|
||||
button_dark_hover: load_img("element/buttons/button_dark_hover.png", ui),
|
||||
button_dark_press: load_img("element/buttons/button_dark_press.png", ui),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -186,11 +191,6 @@ impl MainMenuUi {
|
||||
.label_x(Relative::Scalar(-100.0))
|
||||
.set(self.ids.v_logo, ui_widgets);
|
||||
|
||||
Image::new(self.imgs.test_vox)
|
||||
.w_h(750.0, 750.0)
|
||||
.top_right_with_margins_on(self.ids.bg, 50.0, 50.0)
|
||||
.set(self.ids.test_vox, ui_widgets);
|
||||
|
||||
// Input fields
|
||||
// Used when the login button is pressed, or enter is pressed within input field
|
||||
macro_rules! login {
|
||||
|
@ -41,6 +41,10 @@ impl GraphicCache {
|
||||
pub fn get_graphic(&self, id: Id) -> Option<&Graphic> {
|
||||
self.graphic_map.get(&id)
|
||||
}
|
||||
pub fn clear_cache(&mut self, new_size: Vec2<u16>) {
|
||||
self.rect_map.clear();
|
||||
self.atlas = AtlasAllocator::new(size2(i32::from(new_size.x), i32::from(new_size.y)));
|
||||
}
|
||||
pub fn cache_res<F>(
|
||||
&mut self,
|
||||
graphic_id: Id,
|
||||
|
@ -58,7 +58,7 @@ impl<'a> Pipeline for Voxel {
|
||||
|
||||
pub fn draw_vox(segment: &Segment, output_size: Vec2<u16>) -> Vec<[u8; 4]> {
|
||||
let dims = output_size.map(|e| e as usize).into_array();
|
||||
let mut color = Buffer2d::new(dims, [50; 4]);
|
||||
let mut color = Buffer2d::new(dims, [0; 4]);
|
||||
let mut depth = Buffer2d::new(dims, 1.0);
|
||||
|
||||
let (w, h, d) = segment.get_size().map(|e| e as f32).into_tuple();
|
||||
@ -70,7 +70,8 @@ pub fn draw_vox(segment: &Segment, output_size: Vec2<u16>) -> Vec<[u8; 4]> {
|
||||
top: 1.0,
|
||||
near: 0.0,
|
||||
far: 1.0,
|
||||
}) * Mat4::scaling_3d(2.0 / w.max(h))
|
||||
}) * Mat4::rotation_x(-std::f32::consts::PI / 2.0)
|
||||
* Mat4::scaling_3d([2.0 / w, 2.0 / h, 2.0 / d])
|
||||
* Mat4::translation_3d([-w / 2.0, -h / 2.0, -d / 2.0]);
|
||||
Voxel { mvp }.draw::<rasterizer::Triangles<_>, _>(
|
||||
&generate_mesh(segment, Vec3::from(0.0)),
|
||||
|
@ -118,6 +118,10 @@ impl Cache {
|
||||
pub fn graphic_cache_tex(&self) -> &Texture<UiPipeline> { &self.graphic_cache_tex }
|
||||
pub fn graphic_cache_mut_and_tex(&mut self) -> (&mut GraphicCache, &Texture<UiPipeline>) { (&mut self.graphic_cache, &self.graphic_cache_tex) }
|
||||
pub fn new_graphic(&mut self, graphic: Graphic) -> GraphicId { self.graphic_cache.new_graphic(graphic) }
|
||||
pub fn clear_graphic_cache(&mut self, renderer: &mut Renderer, new_size: Vec2<u16>) {
|
||||
self.graphic_cache.clear_cache(new_size);
|
||||
self.graphic_cache_tex = renderer.create_dynamic_texture(new_size).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
enum DrawKind {
|
||||
@ -580,6 +584,8 @@ impl Ui {
|
||||
self.scale.window_resized(new_dims, renderer);
|
||||
let (w, h) = self.scale.scaled_window_size().into_tuple();
|
||||
self.ui.handle_event(Input::Resize(w, h));
|
||||
self.cache.clear_graphic_cache(renderer, new_dims.map(|e| (e * 4.0) as u16));
|
||||
// TODO: probably need to resize glyph cache, see conrod's gfx backend for reference
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user