webgl-debug
webgl-debug copied to clipboard
Rudimentary TypeScript definitions
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) + ")");
}