Giter Club home page Giter Club logo

webgl-debug's Introduction

webgl-debug

stable

WebGL Debug Utils. This is a node port of WebGLDeveloperTools by Khronos Group.

Usage

NPM

var WebGLDebugUtil = require('webgl-debug');

Examples

Get error code string representation.

var WebGLDebugUtil = require('webgl-debug');

var str = WebGLDebugUtil.glEnumToString(gl.getError());

Create debug context that will throw error on invalid WebGL operation.

var WebGLDebugUtil = require('webgl-debug');

function throwOnGLError(err, funcName, args) {
   throw WebGLDebugUtils.glEnumToString(err) 
   + "was caused by call to " 
   + funcName;
};


gl = WebGLDebugUtils.makeDebugContext(gl, throwOnGLError);

Tutorial

WebGL Wiki: Debugging

API

init()

Initializes this module. Safe to call more than once.

mightBeEnum(value)

Returns true or false if value matches any WebGL enum

glEnumToString(value)

Gets an string version of an WebGL enum.

glFunctionArgToString(functionName, numArgs, argumentIndx, value)

Converts the argument of a WebGL function to a string

glFunctionArgsToString(functionName, args)

Converts the arguments of a WebGL function to a string.

makeDebugContext(ctx, onErrorCb, onFuncCallCb)

returns a wrapped context that calls gl.getError after every command and calls a function if the result is not NO_ERROR

makeLostContextSimulatingCanvas(canvas)

returns a wrapped canvas element that will simulate lost context

resetToInitialState(gl)

Resets a context to the initial state

License

MIT, see LICENSE.md for details.

webgl-debug's People

Contributors

vorg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

webgl-debug's Issues

Update to webgl2?

https://github.com/KhronosGroup/WebGLDeveloperTools has been updated to support WebGL2, which is great, but I just realized that the corresponding npm module is independent and published from this repo instead.

Any chance we could get an update published on npm? If it helps, I could try putting together a PR, let me know.

FWIW, we have been using this module for debugging with great success, but it doesn't cover WebGL2 functionality which we are increasingly relying on.

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) + ")");
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.