struct
GlRenderer
pub struct GlRenderer {
/* private fields */
}Owns a WebGL2 context, its programs, GPU buffers, textures and the assets scenes load.
Methods
new
pub fn new(canvas: &HtmlCanvasElement) -> Result<GlRenderer, JsValue>Create a renderer on canvas; fails if WebGL2 is unavailable.
set_on_ready
pub fn set_on_ready(&mut self, f: Rc<dyn Fn()>)Call f whenever a texture, font or model finishes loading (to redraw a scene that isn't animating).
asset_bounds
pub fn asset_bounds(&self, g: &Geometry) -> Option<(Vec3, Vec3)>The local bounds of an object's loaded geometry (a model or text), for hit testing.
draw_shader
pub fn draw_shader(&mut self, spec: &ShaderSpec, w: u32, h: u32, time: f32, mouse: (f32, f32)) -> Result<(), JsValue>Draw a full-surface shader at time seconds with the pointer at mouse (UV, y up).
draw_scene
pub fn draw_scene(&mut self, scene: &Scene, w: u32, h: u32, time: f32, overrides: Option<&[(Transform, Color)]>) -> Result<(), JsValue>Draw a scene at time seconds. overrides replaces each object's transform and color (used for eased transitions).
cached_programs
pub fn cached_programs(&self) -> usizeNumber of compiled programs (mesh, particles, shaders, custom materials).
read_pixel
pub fn read_pixel(&self, x: i32, y: i32, out: &mut [u8; 4]) -> Result<(), JsValue>Read one RGBA pixel (origin bottom-left) — useful for tests.