Skip to content

Commit

Permalink
fix hello window
Browse files Browse the repository at this point in the history
  • Loading branch information
boralg committed Jun 26, 2024
1 parent 98ab387 commit d927932
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions examples/src/hello_window/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use sursface::{display::Display, std::{clear_screen, get_framebuffer}, wgpu, winit::event::WindowEvent};
use sursface::{display::Display, std::get_framebuffer, wgpu::{self, TextureView}, winit::event::WindowEvent};
#[cfg(target_arch = "wasm32")]
use sursface::wasm_bindgen;

Expand All @@ -8,7 +8,6 @@ fn main() {
sursface::start::create_window_desktop(PhysicalSize::new(1280, 720), &init, &render, &event);
}


#[cfg(target_arch = "wasm32")]
#[wasm_bindgen::prelude::wasm_bindgen]
pub fn start_browser(canvas: sursface::wgpu::web_sys::HtmlCanvasElement) {
Expand All @@ -19,7 +18,6 @@ pub fn start_browser(canvas: sursface::wgpu::web_sys::HtmlCanvasElement) {
#[cfg(target_arch = "wasm32")]
fn main() {}


#[derive(Clone)]
struct EmptyState {}

Expand All @@ -28,20 +26,42 @@ fn init<'a>(_display: &mut Display) -> EmptyState {
}

fn render<'a>(display: &mut Display, _state: &mut EmptyState) {
let output = display.surface.get_current_texture().unwrap();
let view = output.texture.create_view(&wgpu::TextureViewDescriptor::default());

clear_screen(display, &view, wgpu::Color {
r: 100.0 / 255.0,
g: 149.0 / 255.0,
b: 237.0 / 255.0,
a: 1.0,
});

output.present();
}

fn clear_screen<'a>(display: &mut Display, view: &TextureView, color: sursface::wgpu::Color) {
let mut encoder = display.device.create_command_encoder(&wgpu::CommandEncoderDescriptor {
label: Some("Encoder"),
label: Some("Clear Screen Encoder"),
});

let (output, view) = get_framebuffer(&display.surface);
{
clear_screen(&view, &mut encoder, wgpu::Color {
r: 100.0 / 255.0,
g: 149.0 / 255.0,
b: 237.0 / 255.0,
a: 1.0,
let _render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("Render Pass"),
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: &view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(color),
store: wgpu::StoreOp::Store,
},
})],
depth_stencil_attachment: None,
occlusion_query_set: None,
timestamp_writes: None,
});
}
output.present();

display.queue.submit(std::iter::once(encoder.finish()));
}

fn event<'a>(_display: &mut Display, _state: &mut EmptyState, _event: WindowEvent) {}
fn event<'a>(_display: &mut Display, _state: &mut EmptyState, _event: WindowEvent) {}

0 comments on commit d927932

Please sign in to comment.