summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--o3d/samples/o3d-webgl/base.js11
-rw-r--r--o3d/samples/o3d-webgl/buffer.js16
-rw-r--r--o3d/samples/o3djs/webgl.js48
3 files changed, 44 insertions, 31 deletions
diff --git a/o3d/samples/o3d-webgl/base.js b/o3d/samples/o3d-webgl/base.js
index c9876be..b484e484 100644
--- a/o3d/samples/o3d-webgl/base.js
+++ b/o3d/samples/o3d-webgl/base.js
@@ -77,6 +77,17 @@ o3d.global = this;
o3d.basePath = '';
/**
+ * Some javascripts don't support __defineGetter__ or __defineSetter__
+ * so we define some here so at least we don't get compile errors.
+ * We expect the initialzation code will check and complain. This stubs
+ * are just here to make sure we can actually get to the initialization code.
+ */
+if (!Object.prototype.__defineSetter__) {
+ Object.prototype.__defineSetter__ = function() {}
+ Object.prototype.__defineGetter__ = function() {}
+}
+
+/**
* Tries to detect the base path of the base.js script that
* bootstraps the o3d libraries.
* @private
diff --git a/o3d/samples/o3d-webgl/buffer.js b/o3d/samples/o3d-webgl/buffer.js
index 8f4e65e..f8dad1a 100644
--- a/o3d/samples/o3d-webgl/buffer.js
+++ b/o3d/samples/o3d-webgl/buffer.js
@@ -63,10 +63,13 @@ o3d.Buffer.prototype.totalComponents = 0;
o3d.Buffer.prototype.gl_buffer_ = 0;
/**
- * Type of the array element.
- * @type {!Float32Array}
+ * Function to create an array for the buffer.
+ * @param {number} numElements
+ * @return {!Float32Array}
*/
-o3d.Buffer.prototype.ArrayType = Float32Array;
+o3d.Buffer.prototype.createArray = function(numElements) {
+ return new Float32Array(numElements);
+};
o3d.Buffer.prototype.__defineGetter__('numElements',
function() {
@@ -108,7 +111,7 @@ o3d.Buffer.prototype.resize = function(numElements) {
this.gl_buffer_ = this.gl.createBuffer();
// Callers (in particular the deserializer) occasionally call this
// with floating-point numbers.
- this.array_ = new this.ArrayType(Math.floor(numElements));
+ this.array_ = this.createArray(Math.floor(numElements));
};
/**
@@ -320,8 +323,9 @@ o3d.inherit('IndexBuffer', 'Buffer');
* Type of the array element.
* @type {!Uint16Array}
*/
-o3d.IndexBuffer.prototype.ArrayType = Uint16Array;
-
+o3d.IndexBuffer.prototype.createArray = function(numElements) {
+ return new Uint16Array(numElements);
+};
/**
* Delivers the buffer to the graphics hardware when read/write is finished.
diff --git a/o3d/samples/o3djs/webgl.js b/o3d/samples/o3djs/webgl.js
index 7f979ee..3f15629 100644
--- a/o3d/samples/o3djs/webgl.js
+++ b/o3d/samples/o3djs/webgl.js
@@ -77,9 +77,11 @@ o3djs.webgl.makeClients = function(callback,
}
}
var objElem = o3djs.webgl.createClient(element, features, opt_debug);
- if (objElem) {
- clientElements.push(objElem);
+ if (!objElem) {
+ // If we couldn't create the client then we don't call the callback.
+ return;
}
+ clientElements.push(objElem);
}
// Wait for the client elements to be fully initialized. This
@@ -145,25 +147,18 @@ o3djs.webgl.addDebuggingWrapper = function(context) {
*/
o3djs.webgl.webGlCanvasError = function(parentNode, unavailableElement) {
var background = document.createElement('div');
- background.style.backgroundColor='#ccffff';
- background.style.textAlign='center';
- background.style.margin='10px';
-
- var message = document.createElement('p');
- var messageText = document.createTextNode(
- unavailableElement + ' unavailable. ' +
- 'Make sure you are using a WebGL capable browser ' +
- 'and WebGL is enabled. Click here for more information:');
- message.appendChild(messageText);
-
- var url = 'http://www.khronos.org/webgl/wiki/Getting_a_WebGL_Implementation';
- var link = document.createElement('a');
- link.appendChild(document.createTextNode(url));
- link.href = url;
-
- background.appendChild(message);
- background.appendChild(link);
- background.appendChild(document.createElement('br'));
+ background.style.backgroundColor = '#ccffff';
+ background.style.textAlign = 'center';
+ background.style.margin = '10px';
+ background.style.width = '100%';
+ background.style.height = '100%';
+
+ var messageHTML = '<br/><br/><a href="http://get.webgl.org">' +
+ 'Your browser does not appear to support WebGL.<br/><br/>' +
+ 'Check that WebGL is enabled or click here to upgrade your browser:' +
+ '</a><br/>';
+
+ background.innerHTML = messageHTML;
parentNode.appendChild(background);
};
@@ -192,14 +187,15 @@ o3djs.webgl.createClient = function(element, opt_features, opt_debug) {
// element (div), and initialize its size correctly.
var canvas;
canvas = document.createElement('canvas');
- canvas.style.width = "100%";
- canvas.style.height = "100%";
- if (!canvas) {
+ if (!canvas || !canvas.getContext) {
o3djs.webgl.webGlCanvasError(element, 'HTMLCanvas');
return null;
}
+ canvas.style.width = "100%";
+ canvas.style.height = "100%";
+
var client = new o3d.Client;
var resizeHandler = function() {
@@ -208,7 +204,9 @@ o3djs.webgl.createClient = function(element, opt_features, opt_debug) {
canvas.width = width;
canvas.height = height;
canvas.sizeInitialized_ = true;
- client.gl.displayInfo = {width: canvas.width, height: canvas.height};
+ if (client.gl) {
+ client.gl.displayInfo = {width: canvas.width, height: canvas.height};
+ }
};
window.addEventListener('resize', resizeHandler, false);
setTimeout(resizeHandler, 0);