Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rudimentary TypeScript definitions #6

Open
bes opened this issue Feb 27, 2019 · 0 comments
Open

Rudimentary TypeScript definitions #6

bes opened this issue Feb 27, 2019 · 0 comments

Comments

@bes
Copy link

bes commented Feb 27, 2019

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) + ")");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant