UNPKG

@tolokoban/tgd

Version:

ToloGameDev library for WebGL2

137 lines 4.44 kB
import { TgdCamera } from "../camera"; import { TgdInputs } from "../input"; import { TgdPainterFunction as TgdPainterFunctionType } from "../types/painter"; import { TgdPainter } from "../painter/painter"; import { TgdAnimation } from "../types/animation"; import { TgdEvent } from "../event"; /** * You can pass all the attributes of the [WebGLContextAttributes](https://developer.mozilla.org/en-US/docs/Web/API/WebGLContextAttributes) * object. * @see {@link TgdContext} */ export type TgdContextOptions = WebGLContextAttributes & { /** * You can override the behaviour for when a resize even occurs, * by providing a callback `onResize(...)`. * * By default, this is what will happen: * ``` * gl.canvas.width = width * gl.canvas.height = height * gl.viewport(0, 0, width, height) * ``` */ onResize?(this: void, context: TgdContext, width: number, height: number): void; name?: string; camera?: TgdCamera; enableTextureFloatStorage?: boolean; }; /** * This class gives you a [WebGL2RenderingContext](https://developer.mozilla.org/en-US/docs/Web/API/WebGL2RenderingContext) for a given canvas, * through its public readonly attribute `gl`. * * It also acts as a resource manager for most of the WebGL2 reources you need. * * @example * ``` * import { TgdContext, TgdPainterClear } from "@tgd" * * export function paint(canvas: HTMLCanvasElement) { * const ctx = new TgdContext(canvas) * const clear = new TgdPainterClear(ctx, { color: [1, 0.667, 0, 1] }) * ctx.add(clear) * ctx.paint() * } * ``` */ export declare class TgdContext { readonly canvas: HTMLCanvasElement; private readonly options; private static incrementalId; readonly name: string; readonly gl: WebGL2RenderingContext; readonly inputs: TgdInputs; readonly implementationColorReadFormat: number; readonly implementationColorReadType: number; readonly eventPaint: TgdEvent<TgdContext>; private _camera; private _aspectRatio; private _aspectRatioInverse; private readonly observer; private readonly painters; private isPlaying; private requestAnimationFrame; private lastTime; private timeShift; private readonly animationManager; /** * @param canvas The canvas to which attach a WebGL2 context. * @see {@link TgdContextOptions} */ constructor(canvas: HTMLCanvasElement, options?: TgdContextOptions); get time(): number; debugHierarchy(): import("../painter/painter").TgdDebugPainterhierarchy; get camera(): TgdCamera; set camera(camera: TgdCamera); animSchedule(animation: TgdAnimation): TgdAnimation; animCancel(animation: TgdAnimation): void; get onEnter(): TgdPainterFunctionType | undefined; set onEnter(v: TgdPainterFunctionType | undefined); get onExit(): TgdPainterFunctionType | undefined; set onExit(v: TgdPainterFunctionType | undefined); get width(): number; get height(): number; get aspectRatio(): number; get aspectRatioInverse(): number; /** * Is the animation playing? */ get playing(): boolean; /** * If `playing` is true, the method `paint()` will be called * for every animation frame. * @see paint() */ set playing(value: boolean); /** * Start the animation. * You can achieve the same result with `context.playing = true`. * * @see playing */ play(): void; /** * Pause the animation. * You can achieve the same result with `context.playing = false`. * * @see playing */ pause(): void; /** * Check if `painter` already exist in the current list of painters. */ has(painter: TgdPainter): boolean; /** * Add one or more painters. */ add(...painters: TgdPainter[]): void; /** * Add one or more painters at the beginning of the list. */ addFirst(...painters: TgdPainter[]): void; /** * Remove one or more painters. * */ remove(...painters: TgdPainter[]): void; removeAll(): void; takeSnapshot(target: HTMLCanvasElement): void; lookupWebglConstant(value: number): string; /** * Trigger the painters to render the scene. */ readonly paint: () => void; private readonly actualPaint; destroy(): void; stateReset(): WebGL2RenderingContext; } //# sourceMappingURL=context.d.ts.map