summaryrefslogtreecommitdiffstats
path: root/o3d/samples/o3djs
diff options
context:
space:
mode:
authorpetersont@google.com <petersont@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-12 21:00:00 +0000
committerpetersont@google.com <petersont@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-12 21:00:00 +0000
commite512583b79e366db399a6566964412bb6e5af823 (patch)
treee15e3c05e273a0366caf2fcbc5689ae377b3e877 /o3d/samples/o3djs
parenta37a999f87eed77b08e7e1b6bdb86d406f31ea9b (diff)
downloadchromium_src-e512583b79e366db399a6566964412bb6e5af823.zip
chromium_src-e512583b79e366db399a6566964412bb6e5af823.tar.gz
chromium_src-e512583b79e366db399a6566964412bb6e5af823.tar.bz2
Added textures, texture samplers and render targets to o3d-webgl. Also fixed bugs, added calls to parent class constructor to classes that didn't have them before, added a few demos to exhibit/test textures and render surfaces.
Review URL: http://codereview.chromium.org/856004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41482 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/samples/o3djs')
-rw-r--r--o3d/samples/o3djs/webgl.js61
1 files changed, 50 insertions, 11 deletions
diff --git a/o3d/samples/o3djs/webgl.js b/o3d/samples/o3djs/webgl.js
index 6940660..1bbe168 100644
--- a/o3d/samples/o3djs/webgl.js
+++ b/o3d/samples/o3djs/webgl.js
@@ -82,31 +82,70 @@ o3djs.webgl.makeClients = function(callback,
/**
+ * Adds a wrapper object to single gl function context that checks for errors
+ * before the call.
+ * @param {WebGLContext} context
+ * @param {string} fname The name of the function.
+ * @return {}
+ */
+o3djs.webgl.createGLErrorWrapper = function(context, fname) {
+ return function() {
+ var rv = context[fname].apply(context, arguments);
+ var err = context.getError();
+ if (err != 0)
+ throw "GL error " + err + " in " + fname;
+ return rv;
+ };
+};
+
+/**
+ * Adds a wrapper object to a webgl context that checks for errors
+ * before each function call.
+ */
+o3djs.webgl.addDebuggingWrapper = function(context) {
+ // Thanks to Ilmari Heikkinen for the idea on how to implement this
+ // so elegantly.
+ var wrap = {};
+ for (var i in context) {
+ if (typeof context[i] == 'function') {
+ wrap[i] = createGLErrorWrapper(context, i);
+ } else {
+ wrap[i] = context[i];
+ }
+ }
+ wrap.getError = function() {
+ return context.getError();
+ };
+ return wrap;
+};
+
+
+/**
* Creates a canvas under the given parent element and an o3d.Client
* under that.
+ *
+ * @ param {!Element} element The element under which to insert the client.
+ * @ param {string} opt_features Features to turn on.
+ * @ param {boolean} opt_debug Whether gl debugging features should be
+ * enabled.
*/
-o3djs.webgl.createClient = function(element, opt_features) {
+o3djs.webgl.createClient = function(element, opt_features, opt_debug) {
opt_features = opt_features || '';
+ opt_debug = opt_debug || false;
- // TODO(petersont): Not sure what to do with the features object.
var canvas;
canvas = document.createElement('canvas');
canvas.setAttribute('width', element.getAttribute('width'));
canvas.setAttribute('height', element.getAttribute('height'));
+
canvas.client = new o3d.Client;
+ canvas.client.initWithCanvas(canvas);
canvas.o3d = o3d;
- var gl;
- try {gl = canvas.getContext("experimental-webgl") } catch(e) { }
- if (!gl)
- try {gl = canvas.getContext("moz-webgl") } catch(e) { }
- if (!gl) {
- alert("No WebGL context found");
- return null;
+ if (opt_debug) {
+ client.gl = o3djs.webgl.addDebuggingWrapper(client.gl);
}
- canvas.client.gl = gl;
-
element.appendChild(canvas);
return canvas;
};