Skip to content
Browse files

Hide context creation in a function entirely

  • Loading branch information...
1 parent 095e4e4 commit 4955718c98618482b109358474af4f6b9c5d47d8 @ttencate committed Aug 24, 2012
Showing with 35 additions and 32 deletions.
  1. +35 −32 src/gladder.js
View
67 src/gladder.js
@@ -62,51 +62,54 @@ function Gladder(args) {
/////////////
// TODO implement WebGLContextAttributes (alpha, etc.)
- processArgs(args, {
- canvas: REQUIRED,
- debug: false,
- errorCallback: null,
- callCallback: null,
- });
-
- function getGl(canvas) {
+ function getGl(args) {
+ processArgs(args, {
+ canvas: REQUIRED,
+ debug: false,
+ errorCallback: null,
+ callCallback: null,
+ });
+
+ var gl = null;
+ var canvas = getElement(args.canvas);
+
var CONTEXT_NAMES = ["webgl", "experimental-webgl", "moz-webgl", "webkit-3d"];
for (var i = 0; i < CONTEXT_NAMES.length; ++i) {
- var gl = canvas.getContext(CONTEXT_NAMES[i]);
+ gl = canvas.getContext(CONTEXT_NAMES[i]);
if (gl !== null) {
break;
}
}
if (gl === null) {
throw new Error("WebGL not supported");
}
- return gl;
- }
-
- gl = getGl(getElement(args.canvas));
- if (args.debug) {
- if (WebGLDebugUtils === undefined) {
- throw new Error("To use debug mode, you need to load webgl-debug.js. Get it from http://www.khronos.org/webgl/wiki/Debugging");
- }
- var onError = null;
- if (args.errorCallback !== null) {
- onError = function(err, funcName, passedArguments) {
- args.errorCallback(
- WebGLDebugUtils.glEnumToString(err) + " in call " +
- funcName + "(" + Array.prototype.slice.call(passedArguments).join(", ") + ")");
- };
- }
- var onCall = null;
- if (args.callCallback !== null) {
- onCall = function(funcName, passedArguments) {
- args.callCallback(
- funcName + "(" + Array.prototype.slice.call(passedArguments).join(", ") + ")");
- };
+ if (args.debug) {
+ if (WebGLDebugUtils === undefined) {
+ throw new Error("To use debug mode, you need to load webgl-debug.js. Get it from http://www.khronos.org/webgl/wiki/Debugging");
+ }
+ var onError = null;
+ if (args.errorCallback !== null) {
+ onError = function(err, funcName, passedArguments) {
+ args.errorCallback(
+ WebGLDebugUtils.glEnumToString(err) + " in call " +
+ funcName + "(" + Array.prototype.slice.call(passedArguments).join(", ") + ")");
+ };
+ }
+ var onCall = null;
+ if (args.callCallback !== null) {
+ onCall = function(funcName, passedArguments) {
+ args.callCallback(
+ funcName + "(" + Array.prototype.slice.call(passedArguments).join(", ") + ")");
+ };
+ }
+ gl = WebGLDebugUtils.makeDebugContext(gl, onError, onCall);
}
- gl = WebGLDebugUtils.makeDebugContext(gl, onError, onCall);
+ return gl;
}
+ gl = getGl(args);
+
this.canvas = gl.canvas;
//////////////////

0 comments on commit 4955718

Please sign in to comment.
Something went wrong with that request. Please try again.