Skip to main content

RendererFactory API Reference

The RendererFactory provides a centralized API for creating and managing Three.js WebGPU renderers in Hyperscape. Location: packages/shared/src/utils/rendering/RendererFactory.ts

Overview

As of commit 47782ed (2026-02-27), Hyperscape only supports WebGPU. All WebGL fallback code has been removed.

Breaking Changes

  • UniversalRenderer type removed (always WebGPURenderer)
  • RendererBackend type now only accepts "webgpu"
  • All WebGL detection methods removed
  • WebGL fallback flags ignored

API

createRenderer

Creates a WebGPU renderer instance.
Parameters:
  • canvas - HTMLCanvasElement to render to
  • options - Optional renderer configuration
    • antialias - Enable antialiasing (default: true)
    • alpha - Enable alpha channel (default: false)
    • powerPreference - GPU power preference (default: 'high-performance')
Returns: WebGPURenderer instance Throws: Error if WebGPU is not available Example:

getBackend

Returns the current renderer backend (always "webgpu").
Returns: "webgpu" (string literal) Example:

Error Handling

WebGPU Not Available

If WebGPU is not available, createRenderer throws an error:

Migration from WebGL

Before (WebGL Fallback)

After (WebGPU Only)

Type Definitions

Browser Compatibility

Check compatibility at webgpureport.org.

Performance Considerations

GPU Selection

WebGPU automatically selects the best available GPU:

Memory Management

WebGPU uses GPU memory more efficiently than WebGL:
  • Shared buffers: Geometry and textures shared across instances
  • Automatic cleanup: GPU resources freed when renderer is destroyed
  • Memory limits: Respects GPU memory limits (no overallocation)

Render Pipeline

WebGPU uses a modern render pipeline:
  • Compute shaders: For particle systems, grass, terrain
  • Storage buffers: For large datasets (vegetation, NPCs)
  • Indirect rendering: For instanced meshes (trees, rocks)

Examples

Basic Setup

With Error Handling

Cleanup