Skip to content
Permalink
main
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
92 lines (78 sloc) 2.99 KB
<!DOCTYPE html>
<html>
<head>
<title>WebGL Debgging Sample</title>
<!-- Note: this is intended to be checked out as a Git submodule of
https://github.com/KhronosGroup/WebGL under sdk/devtools/ . -->
<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>