Skip to content

Rudimentary TypeScript definitions #6

Description

@bes

Leaving this here as a potential help to other developers (or future me, hi!). It could be fleshed out to become better, by someone else.

It's possible to use this library with TypeScript, at least partially, by using these rudimentary definitions:

webgl-debug.d.ts:

declare module "webgl-debug" {
    interface GLCanvasElement extends HTMLCanvasElement {
        loseContextInNCalls(nCalls: number): void;
        setRestoreTimeout(timeout: number): void;
    }

    /**
     * Use as >>> import WebGLDebugUtil from "webgl-debug";
     * @see https://www.khronos.org/webgl/wiki/Debugging
     * @see https://www.khronos.org/webgl/wiki/HandlingContextLost
     */
    namespace WebGLDebugUtil {
        function makeDebugContext(gl: WebGLRenderingContext | null, ...args: any): WebGLRenderingContext | undefined;
        function glFunctionArgsToString(name: any, args: any): void;
        function makeLostContextSimulatingCanvas(canvas: HTMLCanvasElement): GLCanvasElement;
    }

    export default WebGLDebugUtil;
}

webgl-debug-util.ts:

import WebGLDebugUtil from "webgl-debug";

/**
 * Use as THIRD argument to makeDebugContext:
 * makeDebugContext(gl, undefined, logGLCall);
 * @see webgl-debug.d.ts
 */
export function logGLCall(functionName: any, ...args: any): void {
    console.log("gl." + functionName + "(" +
        WebGLDebugUtil.glFunctionArgsToString(functionName, args) + ")");
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions