forked from KhronosGroup/WebGLDeveloperTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copied webgl-debug.js and related files from WebGL repository.
- Loading branch information
1 parent
07a5d21
commit 80658b1
Showing
6 changed files
with
1,235 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,8 @@ | ||
# WebGLDeveloperTools | ||
|
||
A small repository containing a few useful WebGL developer tools. | ||
|
||
Intended to be used as an ES6 module. | ||
|
||
For more information and other useful tools, consult the WebGL wiki: | ||
http://www.khronos.org/webgl/wiki/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>WebGL Debgging Sample</title> | ||
<script type="text/javascript" src="../demos/common/webgl-utils.js"></script> | ||
<script type="text/javascript" src="webgl-debug.js"></script> | ||
<script> | ||
window.onload = main; | ||
|
||
var g_canvas; | ||
var g_originalContext; | ||
|
||
function codeThatGeneratesGLErrors(gl) { | ||
gl.enable(gl.TEXTURE_2D); // gl.TEXTURE_2D is not a valid argument to gl.enable | ||
gl.enable(gl.TEXTURE_CUBE_MAP); // gl.TEXTURE_CUBE_MAP is not a valid argument to gl.enable | ||
} | ||
|
||
function codeThatPassesUndefinedToGL(gl) { | ||
var info = {}; | ||
gl.bindTexture(gl.TEXTURE_2D, info.tx); // info.tx is undefined | ||
} | ||
|
||
function exampleGLCode(gl) { | ||
gl.clearColor(Math.random(),1,0.7,1); | ||
gl.clear(gl.COLOR_BUFFER_BIT); | ||
var tex = gl.createTexture(); | ||
gl.bindTexture(gl.TEXTURE_2D, tex); | ||
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 4, 4, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); | ||
} | ||
|
||
|
||
function throwOnGLError(err, funcName, args) { | ||
throw WebGLDebugUtils.glEnumToString(err) + " was caused by call to: " + funcName; | ||
}; | ||
|
||
function logGLCall(functionName, args) { | ||
console.log("gl." + functionName + "(" + | ||
WebGLDebugUtils.glFunctionArgsToString(functionName, args) + ")"); | ||
} | ||
|
||
function validateNoneOfTheArgsAreUndefined(functionName, args) { | ||
for (var ii = 0; ii < args.length; ++ii) { | ||
if (args[ii] === undefined) { | ||
console.error("undefined passed to gl." + functionName + "(" + | ||
WebGLDebugUtils.glFunctionArgsToString(functionName, args) + ")"); | ||
} | ||
} | ||
} | ||
|
||
function makeButton(wrappedGLContext, func, label) { | ||
var div = document.createElement("div"); | ||
var button = document.createElement("button"); | ||
button.innerHTML = label; | ||
button.addEventListener('click', function() { | ||
func(wrappedGLContext); | ||
}); | ||
div.appendChild(button); | ||
document.body.appendChild(div); | ||
} | ||
|
||
function main() { | ||
var canvas = document.getElementsByTagName("canvas")[0]; | ||
g_originalContext = WebGLUtils.setupWebGL(canvas); | ||
|
||
var wrappedGLContext = WebGLDebugUtils.makeDebugContext(g_originalContext); | ||
makeButton(wrappedGLContext, codeThatGeneratesGLErrors, "Show WebGL Errors"); | ||
|
||
var wrappedGLContext = WebGLDebugUtils.makeDebugContext(g_originalContext, throwOnGLError); | ||
makeButton(wrappedGLContext, codeThatGeneratesGLErrors, "Throw on WebGL Error"); | ||
|
||
var wrappedGLContext = WebGLDebugUtils.makeDebugContext(g_originalContext, undefined, validateNoneOfTheArgsAreUndefined); | ||
makeButton(wrappedGLContext, codeThatPassesUndefinedToGL, "Throw if undefined is passed to WebGL"); | ||
|
||
var wrappedGLContext = WebGLDebugUtils.makeDebugContext(g_originalContext, undefined, logGLCall); | ||
makeButton(wrappedGLContext, exampleGLCode, "Show WebGL function calls" ); | ||
} | ||
</script> | ||
<style> | ||
canvas { | ||
border: 1px solid black; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div> | ||
<canvas></canvas> | ||
</div> | ||
Open the JavaScript Console or Web Console on your browser then click the buttons below. | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
This directory contains externs files for using webgl-debug.js with the Google | ||
Closure compiler. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/** | ||
* @externs | ||
* @see http://www.khronos.org/webgl/wiki/Debugging | ||
* @see http://www.khronos.org/webgl/wiki/HandlingContextLost | ||
*/ | ||
|
||
|
||
|
||
/** | ||
* @constructor | ||
* @extends {WebGLRenderingContext} | ||
*/ | ||
var WebGLDebugRenderingContext = function() {}; | ||
|
||
|
||
|
||
/** | ||
* @constructor | ||
* @extends {HTMLCanvasElement} | ||
*/ | ||
var WebGLDebugLostContextSimulatingCanvas = function() {}; | ||
|
||
|
||
/** | ||
* @nosideeffects | ||
* @return {number} | ||
*/ | ||
WebGLDebugLostContextSimulatingCanvas.prototype.getNumCalls = function() {}; | ||
|
||
|
||
/** | ||
*/ | ||
WebGLDebugLostContextSimulatingCanvas.prototype.loseContext = function() {}; | ||
|
||
|
||
/** | ||
* @param {number} numCalls | ||
*/ | ||
WebGLDebugLostContextSimulatingCanvas.prototype.loseContextInNCalls = | ||
function(numCalls) {}; | ||
|
||
|
||
/** | ||
*/ | ||
WebGLDebugLostContextSimulatingCanvas.prototype.restoreContext = function() {}; | ||
|
||
|
||
/** | ||
* @param {number} timeout | ||
*/ | ||
WebGLDebugLostContextSimulatingCanvas.prototype.setRestoreTimeout = | ||
function(timeout) {}; | ||
|
||
|
||
/** | ||
* @type {Object} | ||
*/ | ||
var WebGLDebugUtils = {}; | ||
|
||
|
||
/** | ||
* @nosideeffects | ||
* @param {number} value | ||
* @return {string} | ||
*/ | ||
WebGLDebugUtils.glEnumToString = function(value) {}; | ||
|
||
|
||
/** | ||
* @nosideeffects | ||
* @param {string} functionName | ||
* @param {Array} args Args. | ||
* @return {string} String. | ||
*/ | ||
WebGLDebugUtils.glFunctionArgsToString = function(functionName, args) {}; | ||
|
||
|
||
/** | ||
* @param {WebGLRenderingContext} ctx | ||
*/ | ||
WebGLDebugUtils.init = function(ctx) {}; | ||
|
||
|
||
/** | ||
* @param {HTMLCanvasElement} canvas | ||
* @return {WebGLDebugLostContextSimulatingCanvas} | ||
*/ | ||
WebGLDebugUtils.makeLostContextSimulatingCanvas = function(canvas) {}; | ||
|
||
|
||
/** | ||
* @param {WebGLRenderingContext} context | ||
* @param {Function=} opt_onErrorFunc | ||
* @param {Function=} opt_onFunc | ||
* @return {WebGLDebugRenderingContext} | ||
*/ | ||
WebGLDebugUtils.makeDebugContext = | ||
function(context, opt_onErrorFunc, opt_onFunc) {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<!-- this file is auto-generated. DO NOT EDIT. | ||
/* | ||
** Copyright (c) 2012 The Khronos Group Inc. | ||
** | ||
** Permission is hereby granted, free of charge, to any person obtaining a | ||
** copy of this software and/or associated documentation files (the | ||
** "Materials"), to deal in the Materials without restriction, including | ||
** without limitation the rights to use, copy, modify, merge, publish, | ||
** distribute, sublicense, and/or sell copies of the Materials, and to | ||
** permit persons to whom the Materials are furnished to do so, subject to | ||
** the following conditions: | ||
** | ||
** The above copyright notice and this permission notice shall be included | ||
** in all copies or substantial portions of the Materials. | ||
** | ||
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. | ||
*/ | ||
--> | ||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" | ||
"http://www.w3.org/TR/html4/loose.dtd"> | ||
<html> | ||
<head> | ||
<title>WebGL Lost Context Wrapper Test</title> | ||
<link rel="stylesheet" href="../tests/resources/js-test-style.css"/> | ||
<script src="../tests/resources/js-test-pre.js"></script> | ||
<script src="../tests/conformance/resources/webgl-test.js"> </script> | ||
<script src="webgl-debug.js"> </script> | ||
</head> | ||
<body> | ||
<canvas id="example" width="2" height="2" style="width: 40px; height: 40px;"></canvas> | ||
<div id="description"></div> | ||
<div id="console"></div> | ||
<script> | ||
debug("Tests the context lost simulator."); | ||
debug(""); | ||
var c = document.getElementById("example"); | ||
c = WebGLDebugUtils.makeLostContextSimulatingCanvas(c); | ||
c.addEventListener('webglcontextlost', handleContextLost, false); | ||
c.addEventListener('webglcontextrestored', afterContextRestored, false); | ||
var gl = create3DContext(c); | ||
|
||
c.loseContextInNCalls(5); | ||
|
||
assertMsg(gl, "Got 3d context."); | ||
|
||
var tex = gl.createTexture(); | ||
gl.bindTexture(gl.TEXTURE_2D, tex); | ||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); | ||
glErrorShouldBe(gl, gl.NO_ERROR, "no errors from setup"); | ||
glErrorShouldBe(gl, gl.CONTEXT_LOST_WEBGL, "error should be lost context"); | ||
shouldBeNull("gl.createBuffer()"); | ||
|
||
function handleContextLost(e) { | ||
e.preventDefault(); | ||
} | ||
|
||
function afterContextRestored(e) { | ||
glErrorShouldBe(gl, gl.NO_ERROR, "no errors after context restored"); | ||
gl.bindTexture(gl.TEXTURE_2D, tex); | ||
glErrorShouldBe(gl, gl.NO_ERROR, "no errors binding a resource from lost context"); | ||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); | ||
glErrorShouldBe(gl, gl.INVALID_OPERATION, "invalid operation using a resource from lost context"); | ||
tex = gl.createTexture(); | ||
gl.bindTexture(gl.TEXTURE_2D, tex); | ||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); | ||
glErrorShouldBe(gl, gl.NO_ERROR, "okay to use new context"); | ||
|
||
successfullyParsed = true; | ||
var epilogue = document.createElement("script"); | ||
epilogue.onload = finish; | ||
epilogue.src = "../tests/resources/js-test-post.js"; | ||
document.body.appendChild(epilogue); | ||
} | ||
|
||
function finish() { | ||
if (window.nonKhronosFrameworkNotifyDone) { | ||
window.nonKhronosFrameworkNotifyDone(); | ||
} | ||
} | ||
|
||
</script> | ||
</body> | ||
</html> | ||
|
Oops, something went wrong.