Skip to main content

Crate webglue

Crate webglue 

Source
Expand description

Webglue: WebGL2 wrapper for Rust and WebAssembly

This library provides an OpenGL-like API for WebAssembly/Browser environments. This crate is WASM-only and must be compiled with --target wasm32-unknown-unknown.

§Features

  • 59 GL functions implemented (buffers, shaders, textures, uniforms, drawing)
  • Handle-based registry - Translates u32 IDs to glow’s opaque handles
  • Instanced rendering - DrawElementsInstanced for high-performance rendering
  • Matrix math library - Perspective, lookAt, rotate, translate, scale
  • Optional GLTF loading - Load and render GLTF/GLB models

§Usage

ⓘ
// This crate requires wasm32 target
use webglue as gl;
 
unsafe {
    // Initialize once with WebGL2 context
    gl::init_with_webgl2_context(webgl2_context);

    // Use standard GL calls
    let mut vbo = 0;
    gl::GenBuffers(1, &mut vbo);
    gl::BindBuffer(gl::ARRAY_BUFFER, vbo);
    // ... rest of your WebGL code
}

Re-exports§

pub use super::constants::*;
pub use super::types::*;
pub use types::*;
pub use constants::*;

Modules§

constants
math
types
utils
Utility functions for webglue

Functions§

ActiveTexture⚠
AttachShader⚠
BindBuffer⚠
BindFramebuffer⚠
BindRenderbuffer⚠
BindTexture⚠
BindVertexArray⚠
BlendFunc⚠
BlendFuncSeparate⚠
BufferData⚠
BufferSubData⚠
CheckFramebufferStatus⚠
Clear⚠
ClearColor⚠
CompileShader⚠
CreateProgram⚠
CreateShader⚠
DeleteBuffers⚠
DeleteProgram⚠
DeleteShader⚠
DeleteTextures⚠
DeleteVertexArrays⚠
DepthMask⚠
Disable⚠
DisableVertexAttribArray⚠
DrawArrays⚠
DrawElements⚠
DrawElementsInstanced⚠
Enable⚠
EnableVertexAttribArray⚠
Finish⚠
FramebufferRenderbuffer⚠
FramebufferTexture2D⚠
GenBuffers⚠
GenFramebuffers⚠
GenRenderbuffers⚠
GenTextures⚠
GenVertexArrays⚠
GenerateMipmap⚠
GetError⚠
GetGraphicsResetStatus⚠
GetIntegerv⚠
GetProgramInfoLog⚠
GetProgramiv⚠
GetShaderInfoLog⚠
GetShaderiv⚠
GetString⚠
GetStringi⚠
GetUniformLocation⚠
LinkProgram⚠
PixelStorei⚠
PointSize⚠
PointSize - Set point sprite size (not supported in WebGL2, use shader)
ReadPixels⚠
ReadPixels - Read pixels from framebuffer (stub - use browser APIs instead)
RenderbufferStorage⚠
ShaderSource⚠
TexImage2D⚠
TexParameteri⚠
TexSubImage2D⚠
Uniform1f⚠
Uniform1i⚠
Uniform2f⚠
Uniform3f⚠
Uniform3fv⚠
Uniform3fv - Set vec3 array uniform (stub)
Uniform4f⚠
Uniform4fv⚠
Uniform4fv - Set vec4 array uniform (stub)
UniformMatrix3fv⚠
Set 3x3 matrix uniform (mat3) Used for normal transforms in lighting calculations
UniformMatrix4fv⚠
Set 4x4 matrix uniform (mat4) Critical for 3D transforms: Model-View-Projection matrices From gl-rs patterns for matrix uniforms
UseProgram⚠
VertexAttribDivisor⚠
VertexAttribPointer⚠
Viewport⚠
init_with_context⚠
Initialize the GL context (must be called once from WASM entry point)
load_with
Stub for gl::load_with - no-op since glow context is already initialized This is re-exported from mod.rs but duplicated here for completeness