Initialize canary-wgpu from eframe

This commit is contained in:
mars 2022-11-17 14:25:07 -07:00
parent 24196adc3a
commit 0bf02ba93b
2 changed files with 15 additions and 5 deletions

View File

@ -6,4 +6,5 @@ license = "AGPL-3.0-or-later"
[dependencies]
canary = { path = "../.." }
canary-wgpu = { path = "../../renderers/wgpu" }
eframe = { version = "0.19", features = ["wgpu"] }

View File

@ -2,6 +2,7 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
use canary::{CursorEventKind, Panel, Runtime, Script, PX_PER_MM};
use canary_wgpu::Renderer;
use eframe::egui;
use std::time::Instant;
@ -20,14 +21,12 @@ fn main() {
eframe::run_native(
"Canary Sandbox",
native_options,
Box::new(move |cc| {
cc.egui_ctx.set_visuals(egui::Visuals::dark());
Box::new(App::new(&module_path))
}),
Box::new(move |cc| Box::new(App::new(cc, &module_path))),
);
}
struct App {
renderer: Renderer,
script: Script,
panels: Vec<PanelWindow>,
next_idx: usize,
@ -37,13 +36,23 @@ struct App {
}
impl App {
pub fn new(module_path: &str) -> Self {
pub fn new(cc: &eframe::CreationContext, module_path: &str) -> Self {
cc.egui_ctx.set_visuals(egui::Visuals::dark());
let wgpu_state = cc
.wgpu_render_state
.as_ref()
.expect("eframe should be using wgpu but has no wgpu render state");
let renderer = Renderer::new(wgpu_state.device.to_owned(), wgpu_state.queue.to_owned());
let backend = canary::backend::make_default_backend().unwrap();
let runtime = Runtime::new(backend).unwrap();
let module = std::fs::read(module_path).unwrap();
let script = runtime.load_module(&module).unwrap();
Self {
renderer,
script,
panels: vec![],
next_idx: 0,