Application prototype #14
@ -11,7 +11,7 @@ extern crate js_sys;
|
|||||||
use core::array;
|
use core::array;
|
||||||
use nalgebra::DVector;
|
use nalgebra::DVector;
|
||||||
use sycamore::{prelude::*, rt::{JsCast, JsValue}};
|
use sycamore::{prelude::*, rt::{JsCast, JsValue}};
|
||||||
use web_sys::{console, WebGl2RenderingContext, WebGlShader};
|
use web_sys::{console, WebGl2RenderingContext, WebGlProgram, WebGlShader, WebGlUniformLocation};
|
||||||
|
|
||||||
mod engine;
|
mod engine;
|
||||||
|
|
||||||
@ -26,6 +26,18 @@ fn compile_shader(
|
|||||||
shader
|
shader
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_uniform_array_locations<const N: usize>(
|
||||||
|
context: &WebGl2RenderingContext,
|
||||||
|
program: &WebGlProgram,
|
||||||
|
var_name: &str,
|
||||||
|
member_name: &str
|
||||||
|
) -> [Option<WebGlUniformLocation>; N] {
|
||||||
|
array::from_fn(|n| {
|
||||||
|
let name = format!("{var_name}[{n}].{member_name}");
|
||||||
|
context.get_uniform_location(&program, name.as_str())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// load the given data into the vertex input of the given name
|
// load the given data into the vertex input of the given name
|
||||||
fn bind_vertex_attrib(
|
fn bind_vertex_attrib(
|
||||||
context: &WebGl2RenderingContext,
|
context: &WebGl2RenderingContext,
|
||||||
@ -131,11 +143,11 @@ fn main() {
|
|||||||
ctx.use_program(Some(&program));
|
ctx.use_program(Some(&program));
|
||||||
|
|
||||||
// find indices of vertex attributes and uniforms
|
// find indices of vertex attributes and uniforms
|
||||||
let sphere_sp_locs = array::from_fn::<_, SPHERE_MAX, _>(
|
let sphere_sp_locs = get_uniform_array_locations::<SPHERE_MAX>(
|
||||||
|n| ctx.get_uniform_location(&program, format!("sphere_list[{}].sp", n).as_str())
|
&ctx, &program, "sphere_list", "sp"
|
||||||
);
|
);
|
||||||
let sphere_lt_locs = array::from_fn::<_, SPHERE_MAX, _>(
|
let sphere_lt_locs = get_uniform_array_locations::<SPHERE_MAX>(
|
||||||
|n| ctx.get_uniform_location(&program, format!("sphere_list[{}].lt", n).as_str())
|
&ctx, &program, "sphere_list", "lt"
|
||||||
);
|
);
|
||||||
let position_index = ctx.get_attrib_location(&program, "position") as u32;
|
let position_index = ctx.get_attrib_location(&program, "position") as u32;
|
||||||
let resolution_loc = ctx.get_uniform_location(&program, "resolution");
|
let resolution_loc = ctx.get_uniform_location(&program, "resolution");
|
||||||
|
Loading…
Reference in New Issue
Block a user