docs.rs failed to build minwebgl-0.3.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build:
minwebgl-0.2.0
🎮 minwebgl
Minimal, type-safe WebGL 2.0 wrapper for Rust and WebAssembly
A concise and performant WebGL 2.0 abstraction layer designed specifically for Rust applications targeting WebAssembly. Built with ergonomics and safety in mind, minwebgl eliminates WebGL boilerplate while maintaining full control over rendering pipelines.
✨ Features
🚀 Core Capabilities
- Modern WebGL 2.0 - Full WebGL 2.0 API coverage with type safety
- Zero-Cost Abstractions - Minimal overhead over raw WebGL calls
- Memory Safe - Rust ownership prevents common WebGL errors
- WebAssembly Optimized - Designed for efficient WASM deployment
🛠️ Rendering Features
- Attribute Management - Type-safe vertex attribute uploading
- Matrix Support - Row-major matrix handling in attributes
- Instanced Rendering - Efficient batch rendering support
- Uniform Buffer Objects - Modern uniform data management
- Vertex Array Objects - Optimized vertex state caching
- Shader Management - Compile-time shader validation
- Texture Operations - 2D/3D textures, cube maps, and arrays
- Framebuffer Control - Render-to-texture and multi-target rendering
🚀 Quick Start
Add to Your Project
[]
= { = true, = ["enabled"] }
= "0.2"
= "0.3"
Basic Triangle Example
use minwebgl as gl;
use *;
Advanced Features Example
use minwebgl as gl;
// Instanced rendering with matrices
let instances = vec!;
// Upload instance matrices
let instance_buffer = make;
bind;
upload_matrix_4x4;
// Set up instanced attribute (divisor = 1)
vertex_attrib_divisor;
// Instanced draw call
arrays_instanced;
🛠️ Building and Deployment
Prerequisites
Option 1: wasm-pack (Recommended)
# Install wasm-pack
# Build for web
# Use in HTML
Option 2: Trunk (Development)
# Install trunk
# Serve with hot reload
# Build for production
For asset loading with Trunk:
📚 API Overview
Module | Description | Key Functions |
---|---|---|
canvas |
Canvas creation and management | make() , resize() |
context |
WebGL context initialization | from_canvas() , from_canvas_with() |
shader |
Shader compilation and programs | make() , compile_vertex() , compile_fragment() |
buffer |
Buffer operations | make() , upload_f32() , upload_matrix_4x4() |
attrib |
Vertex attributes | vertex_attrib_pointer_f32() , enable_vertex_attrib_array() |
texture |
Texture management | make_2d() , upload_2d() , bind() |
framebuffer |
Render targets | make() , bind() , attach_texture() |
draw |
Draw commands | arrays() , elements() , arrays_instanced() |
🎯 Examples
- Basic Triangle - Simple triangle rendering
- Hexagonal Grid - Interactive grid with pathfinding
- Deferred Shading - Advanced lighting pipeline
- Text Rendering - GPU text rendering with MSDF
- Object Picking - Mouse interaction with 3D objects
🔧 Advanced Usage
Custom Context Options
let options = default
.antialias
.alpha
.depth
.stencil
.premultiplied_alpha;
let gl_context = from_canvas_with?;
Uniform Buffer Objects
// Create UBO
let ubo = make;
bind_uniform;
// Upload uniform data
let uniforms = MyUniformStruct ;
upload_uniform;
// Bind to shader
let block_index = get_uniform_block_index;
uniform_block_binding;
bind_buffer_base_uniform;
Error Handling
// Enable debug output
enable;
// Check for errors
if let Some = get_error
🤝 Contributing
This crate is part of the CGTools workspace. Feel free to submit issues and pull requests on GitHub.
📄 License
MIT