Small World Engine API Reference - v0.78.00
    Preparing search index...

    Interface Renderer

    Interface for all renderer implementations.

    interface Renderer {
        clearColor: Color;
        gpuDevice?: GPUDevice;
        isContextLost?: boolean;
        onContextLost?: (info: { message?: string; reason?: string }) => void;
        postProcessing: PostProcessingGroup;
        quality: QualityConfig;
        type: RendererType;
        webglContext?: WebGLRenderingContext | WebGL2RenderingContext;
        applyPendingOcclusionResults?(scene: Scene): void;
        destroy?(): void;
        initialize(
            canvas: HTMLCanvasElement,
            attributes?: Record<string, unknown>,
            config?: EngineOptions,
        ): Promise<void>;
        render(
            scene: Scene,
            vpMatrix: Float32Array,
            camPos?: Vector3D,
            viewMatrix?: Float32Array<ArrayBufferLike>,
            near?: number,
            far?: number,
            projMatrix?: Float32Array<ArrayBufferLike>,
        ): void;
        setClearColor(color: Color): void;
        setRenderTarget(
            target: RenderTarget | RenderTargetCube | null,
            activeCubeFace?: number,
        ): void;
        setSize(width: number, height: number): void;
    }

    Implemented by

    Index
    clearColor: Color

    Gets the clear color of the renderer.

    gpuDevice?: GPUDevice

    WebGPU Device (only for WebGPU renderer)

    isContextLost?: boolean

    Whether the underlying GPU device or context has been lost.

    onContextLost?: (info: { message?: string; reason?: string }) => void

    Optional callback triggered when the GPU context is lost.

    postProcessing: PostProcessingGroup

    The global post-processing volume/group.

    quality: QualityConfig

    Gets the global quality settings of the renderer.

    The type of the renderer.

    webglContext?: WebGLRenderingContext | WebGL2RenderingContext

    WebGL Context (for WebGL1/2 renderers)

    • Applies the previous frame's Hierarchical-Z occlusion culling results (if ready) by setting occlusionCulled on the tested objects. Called once per frame, before FrustumCuller.cull(). WebGPU-only (see docs/adr/0008-hzb-occlusion-culling-webgpu-only.md); a no-op on WebGL1/WebGL2 and whenever occlusion culling isn't enabled.

      Parameters

      Returns void

    • Initializes the renderer.

      Parameters

      • canvas: HTMLCanvasElement
      • Optionalattributes: Record<string, unknown>
      • Optionalconfig: EngineOptions

      Returns Promise<void>

    • Renders a scene.

      Parameters

      • scene: Scene
      • vpMatrix: Float32Array
      • OptionalcamPos: Vector3D
      • OptionalviewMatrix: Float32Array<ArrayBufferLike>
      • Optionalnear: number
      • Optionalfar: number
      • OptionalprojMatrix: Float32Array<ArrayBufferLike>

        The camera's raw projection matrix, used by HBAO to reconstruct view-space position from depth.

      Returns void

    • Sets the active render target for off-screen rendering. If null, the renderer targets the screen/post-processing buffer.

      Parameters

      • target: RenderTarget | RenderTargetCube | null

        The target to render into.

      • OptionalactiveCubeFace: number

        Optional. Which face (0-5) of the RenderTargetCube to render into.

      Returns void

    • Sets the size of the render viewport.

      Parameters

      • width: number
      • height: number

      Returns void