How to enable multisampling in WebGL2 rust / web_sys

48 views Asked by At

I'm trying to get multisampling working with rust / webgl2 / web_sys

Basically, I'm using most of the code from here (I just want to draw some basic lines) https://rustwasm.github.io/wasm-bindgen/examples/webgl.html

let document = web_sys::window().unwrap().document().unwrap();
let canvas = document.get_element_by_id("canvas").unwrap();
let canvas: web_sys::HtmlCanvasElement =
    canvas.dyn_into::<web_sys::HtmlCanvasElement>().unwrap();
let options = canvas.get_context("webgl2").unwrap().unwrap();
let context = options.dyn_into::<WebGl2RenderingContext>().unwrap();

let program = link_program(&context, ..., ...).unwrap();
context.use_program(Some(&program));

let position_attribute_location = context.get_attrib_location(&program, "position");
let buffer = context
    .create_buffer()
    .ok_or("Failed to create buffer")
    .unwrap();
context.bind_buffer(WebGl2RenderingContext::ARRAY_BUFFER, Some(&buffer));

I had hoped that there might be a functionality like this (I had seen something similar in various opengl examples)

context.enable(WebGl2RenderingContext::MULTISAMPLING);
...
context.clear_color(0.0, 0.0, 0.0, 1.0);
context.clear(WebGl2RenderingContext::COLOR_BUFFER_BIT);    context.draw_arrays(WebGl2RenderingContext::LINES, 0, vert_count);

Reading https://registry.khronos.org/webgl/specs/latest/2.0/ as well as https://github.com/rustwasm/wasm-bindgen/blob/main/crates/web-sys/src/features/gen_WebGl2RenderingContext.rs#L2059 I found out that there definitely should be a functionality to do this but unfortunately I cannot figure out how. Also, I couldn't find any examples on the web on how to accomplish this with rust.

0

There are 0 answers