Expand description
WebGL2 Context and Resource Management
This module implements the core plumbing for the Rust-owned WebGL2 context, following the design in docs/1.1.1-webgl2-prototype.md:
- Single-threaded global registry (OnceCell + RefCell
) - Handle-based resource lifecycle (Context, Textures, Framebuffers)
- errno-based error reporting + last_error string buffer
- Memory allocation (wasm_alloc / wasm_free)
Structs§
- Context
- Per-context state
Constants§
- ERR_GL
- ERR_
INTERNAL - ERR_
INVALID_ ARGS - ERR_
INVALID_ HANDLE - ERR_
NOT_ IMPLEMENTED - ERR_OK
- ERR_OOM
- GL_
ACTIVE_ ATTRIBUTES - GL_
ACTIVE_ UNIFORMS - GL_
ARRAY_ BUFFER - GL_
ATTACHED_ SHADERS - GL_
BUFFER_ SIZE - GL_
COLOR_ BUFFER_ BIT - GL_
COLOR_ CLEAR_ VALUE - GL_
COMPILE_ STATUS - GL_
DELETE_ STATUS - GL_
ELEMENT_ ARRAY_ BUFFER - GL_
INFO_ LOG_ LENGTH - GL_
INVALID_ ENUM - GL_
INVALID_ OPERATION - GL_
INVALID_ VALUE - GL_
LINK_ STATUS - GL_
NO_ ERROR - GL_
OUT_ OF_ MEMORY - GL_
SHADER_ TYPE - GL_
VIEWPORT
Functions§
- create_
context - Create a new WebGL2 context and return its handle. Returns 0 on failure (sets last_error).
- ctx_
active_ texture - ctx_
attach_ shader - Attach a shader to a program.
- ctx_
bind_ attrib_ location - Bind attribute location.
- ctx_
bind_ buffer - Bind a buffer to a target.
- ctx_
bind_ framebuffer - Bind a framebuffer in the given context. Returns errno.
- ctx_
bind_ texture - Bind a texture in the given context. Returns errno.
- ctx_
buffer_ data - Upload data to the bound buffer.
- ctx_
clear - Clear buffers to preset values.
- ctx_
clear_ color - Set the clear color.
- ctx_
compile_ shader - Compile a shader.
- ctx_
create_ buffer - Create a buffer in the given context.
- ctx_
create_ framebuffer - Create a framebuffer in the given context. Returns framebuffer handle (0 on failure).
- ctx_
create_ program - Create a program.
- ctx_
create_ shader - Create a shader.
- ctx_
create_ texture - Create a texture in the given context. Returns texture handle (0 on failure).
- ctx_
delete_ buffer - Delete a buffer.
- ctx_
delete_ framebuffer - Delete a framebuffer from the given context. Returns errno.
- ctx_
delete_ program - Delete a program.
- ctx_
delete_ shader - Delete a shader.
- ctx_
delete_ texture - Delete a texture from the given context. Returns errno.
- ctx_
depth_ func - ctx_
disable - ctx_
disable_ vertex_ attrib_ array - Disable vertex attribute array.
- ctx_
draw_ arrays - Draw arrays.
- ctx_
draw_ elements - Draw elements.
- ctx_
enable - ctx_
enable_ vertex_ attrib_ array - Enable vertex attribute array.
- ctx_
framebuffer_ texture2d - Attach a texture to a framebuffer. Returns errno.
- ctx_
get_ attrib_ location - Get attribute location.
- ctx_
get_ buffer_ parameter - Get buffer parameter.
- ctx_
get_ error - Get the last GL error.
- ctx_
get_ parameter_ v - Get a parameter (vector version).
- ctx_
get_ program_ info_ log - Get program info log.
- ctx_
get_ program_ parameter - Get program parameter.
- ctx_
get_ program_ wasm - Get the generated WASM for a program’s shader.
- ctx_
get_ program_ wasm_ len - Get the length of the generated WASM for a program’s shader.
- ctx_
get_ shader_ info_ log - Get shader info log.
- ctx_
get_ shader_ parameter - Get shader parameter.
- ctx_
get_ uniform_ location - Get uniform location.
- ctx_
link_ program - Link a program.
- ctx_
read_ pixels - Read pixels from the currently bound framebuffer’s color attachment. Writes RGBA u8 data to dest_ptr in WASM linear memory. Returns errno.
- ctx_
scissor - ctx_
set_ verbosity - Set verbosity level for the context.
- ctx_
shader_ source - Set shader source.
- ctx_
tex_ image_ 2d - Upload pixel data to a texture. ptr and len point to RGBA u8 pixel data in WASM linear memory. Returns errno.
- ctx_
uniform1f - Set uniform 1f.
- ctx_
uniform1i - Set uniform 1i.
- ctx_
uniform2f - Set uniform 2f.
- ctx_
uniform3f - Set uniform 3f.
- ctx_
uniform4f - Set uniform 4f.
- ctx_
uniform_ matrix_ 4fv - Set uniform matrix 4fv.
- ctx_
use_ program - Use a program.
- ctx_
vertex_ attrib1f - Set vertex attribute default value (1f).
- ctx_
vertex_ attrib2f - Set vertex attribute default value (2f).
- ctx_
vertex_ attrib3f - Set vertex attribute default value (3f).
- ctx_
vertex_ attrib4f - Set vertex attribute default value (4f).
- ctx_
vertex_ attrib_ pointer - Vertex attribute pointer.
- ctx_
viewport - Set the viewport.
- destroy_
context - Destroy a context by handle, freeing all its resources. Returns errno (0 on success).
- last_
error_ len - Get length of last error string
- last_
error_ ptr - Get pointer to last error string (UTF-8)
- set_
last_ error - Set last error message (internal helper)
- wasm_
alloc - Allocate memory within WASM linear memory. Returns pointer (0 on failure).
- wasm_
free - Free memory allocated by wasm_alloc. Returns errno (0 on success).