WebGLazor is a high-performance, low-level WebGL 2.0 binding library for Blazor WebAssembly. It provides a direct, zero-copy interface to the pure WebGL 2.0 API, enabling developers to build hardware-accelerated 2D and 3D graphics applications completely in C#.
- Key Features
- API Reference
- Package requirements
- Installation
- Quick Start
- License
- Third-Party Libraries
WebGLazor is engineered for speed. It utilizes direct memory access to the WebAssembly heap, allowing C# Span<T> and arrays to be passed directly to WebGL without the overhead of data marshaling or serialization.
- Direct Memory Access: Uses
pinnedmemory pointers for buffer and texture operations. - Zero Allocations: Rendering loops are designed to run with zero garbage collection pressure.
- Fast Interop: Optimized internal mappings bypass the standard Blazor JS interop overhead for critical paths.
WebGLazor exposes the entire WebGL 2.0 standard.
- Advanced Rendering: VAOs, Uniform Buffer Objects (UBOs), Transform Feedback, and Multi-Render Targets (MRT).
- Textures: Support for 3D textures, 2D Array textures, and immutable texture storage.
- State Management: Complete control over Samplers, Sync Objects, and Query objects.
- Shaders: Full GLSL shader support with strict typing for shader sources and precision formats.
- Strong Typing: All WebGL constants and enums are strongly typed to prevent invalid state usage.
- Blazor Component: Includes the
<WebGLCanvas>component for instant setup. - Context Management: Built-in support for multiple WebGL contexts and automatic context loss handling.
- WebGLazor is AOT-compatible and trimming safe, ensuring optimal performance in production builds.
For a complete and detailed reference of all available classes, methods, and constants, please read the API Reference Wiki.
- WebGLCanvas Component: Setup and event handling.
- WebGL 2.0 Implementation: Detailed method signatures and usage.
- Constants: Enumeration of all WebGL 2.0 constants.
This package uses Microsoft.AspNetCore.Components.Web package:
| .NET Version | Required Package |
|---|---|
| .NET 10.0 | Microsoft.AspNetCore.Components.Web ≥ 10.0.0 |
Install the package via NuGet:
dotnet add package WebGLazorAdd package reference
<PackageReference Include="WebGLazor" Version="*" />-
Add the Namespace: Add
using WebGLazor;to your_Imports.razor. -
Use the Component: Add the canvas to your page and handle the context creation.
<WebGLCanvas Width="800" Height="600" OnContextCreated="OnContextCreated" /> @code { private WebGLContext _gl; private void OnContextCreated(WebGLContext gl) { _gl = gl; // Set clear color to black, fully opaque _gl.ClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Clear the color buffer with specified clear color _gl.Clear(WebGLConsts.COLOR_BUFFER_BIT); } }
-
Constants: Use WebGL constants from
WebGLConstsclass, e.g.,WebGLConsts.COLOR_BUFFER_BIT.
This project is licensed under the MIT License - see the LICENSE file for details.
See the NOTICE file for attribution information.