gl-wiretap
Advanced tools
Comparing version 0.0.1 to 0.0.2
53
index.js
@@ -24,3 +24,4 @@ /** | ||
imageData: [], | ||
locations: [], | ||
attributeLocations: [], | ||
uniformLocations: [], | ||
textures: [], | ||
@@ -187,9 +188,14 @@ framebuffers: [], | ||
case 'getAttribLocation': | ||
recording.push('const location' + variables.locations.length + ' = gl.getAttribLocation(program' + variables.programs.indexOf(arguments[0]) + ', `' + arguments[1] + '`;'); | ||
const location = gl.getAttribLocation(arguments[0], arguments[1]); | ||
variables.locations.push(location); | ||
return location; | ||
recording.push('const attributeLocation' + variables.attributeLocations.length + ' = gl.getAttribLocation(program' + variables.programs.indexOf(arguments[0]) + ', `' + arguments[1] + '`;'); | ||
const attributeLocation = gl.getAttribLocation(arguments[0], arguments[1]); | ||
variables.attributeLocations.push(attributeLocation); | ||
return attributeLocation; | ||
case 'getUniformLocation': | ||
recording.push(`const uniformLocation${ variables.uniformLocations.length } = gl.getUniformLocation(program${ variables.programs.indexOf(arguments[0]) }, '${ arguments[1] }');`); | ||
const uniformLocation = gl.getUniformLocation(arguments[0], arguments[1]); | ||
variables.uniformLocations.push(uniformLocation); | ||
return uniformLocation; | ||
case 'vertexAttribPointer': | ||
if (variables.locations.indexOf(arguments[0]) > -1) { | ||
recording.push(`gl.vertexAttribPointer(location${variables.locations.indexOf(arguments[0])}, ${arguments[1]}, ${arguments[2]}, ${arguments[3]}, ${arguments[4]}, ${arguments[5]});`); | ||
if (variables.attributeLocations.indexOf(arguments[0]) > -1) { | ||
recording.push(`gl.vertexAttribPointer(attributeLocation${variables.attributeLocations.indexOf(arguments[0])}, ${arguments[1]}, ${arguments[2]}, ${arguments[3]}, ${arguments[4]}, ${arguments[5]});`); | ||
} else { | ||
@@ -200,4 +206,4 @@ recording.push(`gl.vertexAttribPointer(${arguments[0]}, ${arguments[1]}, ${arguments[2]}, ${arguments[3]}, ${arguments[4]}, ${arguments[5]});`); | ||
case 'enableVertexAttribArray': | ||
if (variables.locations.indexOf(arguments[0]) > -1) { | ||
recording.push(`gl.enableVertexAttribArray(location${variables.locations.indexOf(arguments[0])});`); | ||
if (variables.attributeLocations.indexOf(arguments[0]) > -1) { | ||
recording.push(`gl.enableVertexAttribArray(attributeLocation${variables.attributeLocations.indexOf(arguments[0])});`); | ||
} else { | ||
@@ -243,2 +249,28 @@ recording.push(`gl.enableVertexAttribArray(${arguments[0]});`); | ||
break; | ||
case 'uniform1fv': | ||
case 'uniform1iv': | ||
case 'uniform2fv': | ||
case 'uniform2iv': | ||
case 'uniform3fv': | ||
case 'uniform3iv': | ||
case 'uniform4fv': | ||
case 'uniform4iv': | ||
recording.push(`gl.${property}(uniformLocation${ variables.uniformLocations.indexOf(arguments[0])}, ${ JSON.stringify(Array.from(arguments[1])) });`); | ||
break; | ||
case 'uniform1f': | ||
case 'uniform1i': | ||
recording.push(`gl.${property}(uniformLocation${ variables.uniformLocations.indexOf(arguments[0])}, ${ arguments[1] });`); | ||
break; | ||
case 'uniform2f': | ||
case 'uniform2i': | ||
recording.push(`gl.${property}(uniformLocation${ variables.uniformLocations.indexOf(arguments[0])}, ${ arguments[1] }, ${ arguments[2] });`); | ||
break; | ||
case 'uniform3f': | ||
case 'uniform3i': | ||
recording.push(`gl.${property}(uniformLocation${ variables.uniformLocations.indexOf(arguments[0])}, ${ arguments[1] }, ${ arguments[2] }, ${ arguments[3] });`); | ||
break; | ||
case 'uniform4f': | ||
case 'uniform4i': | ||
recording.push(`gl.${property}(uniformLocation${ variables.uniformLocations.indexOf(arguments[0])}, ${ arguments[1] }, ${ arguments[2] }, ${ arguments[3] }, ${ arguments[4] });`); | ||
break; | ||
default: | ||
@@ -294,2 +326,5 @@ recording.push(`gl.${ property }(${ argumentsToString(arguments) });`); | ||
default: | ||
if (arg === null) { | ||
return 'null'; | ||
} | ||
throw new Error('unrecognized argument'); | ||
@@ -296,0 +331,0 @@ } |
{ | ||
"name": "gl-wiretap", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "listen and replay gl WebGL gpu commands ", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# gl-wiretap | ||
listen and replay gl (WebGL, WebGL2, and HeadlessGL) gpu commands | ||
listen and replay gl (WebGL, WebGL2, and HeadlessGL) gpu commands | ||
## Example | ||
```js | ||
const { glWiretap } = require('gl-wiretap'); | ||
const realGL = canvas.getContext('webgl'); | ||
const gl = glWiretap(realGL); | ||
// do a bunch of webgl commands.. | ||
// then later, see all commands ran | ||
const commands = gl.toString(); | ||
// possibly write commands to file, for unit testing or reproducing bug | ||
require('fs').writeFileSync('./file.js', | ||
"const canvas = document.createElement('canvas');" | ||
+ "const gl = canvas.getContext('webgl');" | ||
+ commands | ||
); | ||
``` | ||
## API | ||
```js | ||
const gl = glWiretap(realGL, options); | ||
// do a bunch of webgl commands.. | ||
// then later, see all commands ran | ||
const commands = gl.toString(); | ||
``` | ||
## glWiretap.toString() | ||
This is where the gl context outputs all values. The value for context here is `gl`, for simplicity. | ||
Any variables created here (example: `gl.createProgram()`, or `gl.createShader(gl.VERTEX_SHADER)`) are simply constants | ||
that increment on an index to prevent collision. | ||
## glWiretap options | ||
* readPixelsFile: String - Writes a file by this name when on node HeadlessGL using readPixels | ||
* throwGetError: Boolean - Causes `gl.getError()` to throw if there is an error | ||
* throwGetShaderParameter: Boolean - Causes `gl.getShaderParameter()` to throw if there is an error | ||
* throwGetProgramParameter: Boolean - Causes `gl.getProgramParameter()` to throw if there is an error |
20792
347
43