setup graphics directly

This commit is contained in:
2026-02-18 10:50:22 -08:00
parent 3117a56d51
commit 4a8c9e05a1
2 changed files with 9 additions and 25 deletions

View File

@@ -20,14 +20,12 @@ impl From<ToSurfaceTarget> for wgpu::SurfaceTarget<'static>{
}
#[wasm_bindgen]
pub struct Setup{
device:wgpu::Device,
queue:wgpu::Queue,
pub struct Graphics{
graphics:graphics::Graphics,
surface:wgpu::Surface<'static>,
config:wgpu::SurfaceConfiguration,
}
#[wasm_bindgen]
pub async fn setup(canvas:web_sys::HtmlCanvasElement)->Setup{
pub async fn setup_graphics(canvas:web_sys::HtmlCanvasElement)->Graphics{
let size=(canvas.width(),canvas.height());
let instance=setup::step1::create_instance();
@@ -35,25 +33,13 @@ pub async fn setup(canvas:web_sys::HtmlCanvasElement)->Setup{
let adapter=setup::step3::pick_adapter(&instance,&surface).await.expect("No suitable GPU adapters found on the system!");
let (device,queue)=setup::step4::request_device(&adapter).await;
let config=setup::step5::configure_surface(&adapter,&device,&surface,size);
Setup{device,queue,surface,config}
}
#[wasm_bindgen]
pub struct Graphics{
graphics:graphics::Graphics,
surface:wgpu::Surface<'static>,
Graphics{
graphics:graphics::Graphics::new(device,queue,config),
surface:surface,
}
}
#[wasm_bindgen]
impl Graphics{
#[wasm_bindgen(constructor)]
pub fn new(
setup:Setup,
)->Self{
Self{
graphics:graphics::Graphics::new(setup.device,setup.queue,setup.config),
surface:setup.surface,
}
}
#[wasm_bindgen]
pub fn render(&mut self,bot:&CompleteBot,head:&PlaybackHead,time:f64){
// TODO: check f64 range