Module webgl2_context

Module webgl2_context 

Source
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).