| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2010, Google Inc. | 2 * Copyright 2010, Google Inc. |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 * The only reason to look at this flag is for things like video that are | 185 * The only reason to look at this flag is for things like video that are |
| 186 * updating the texture every frame. In that case, you might want to know | 186 * updating the texture every frame. In that case, you might want to know |
| 187 * that you could run faster if you used a power of 2 texture instead of | 187 * that you could run faster if you used a power of 2 texture instead of |
| 188 * a non power of 2 texture. | 188 * a non power of 2 texture. |
| 189 * | 189 * |
| 190 * @type {boolean} | 190 * @type {boolean} |
| 191 */ | 191 */ |
| 192 o3d.ClientInfo.prototype.non_power_of_two_textures = true; | 192 o3d.ClientInfo.prototype.non_power_of_two_textures = true; |
| 193 | 193 |
| 194 | 194 |
| 195 |
| 196 /** |
| 197 * True if shaders need to be GLSL instead of Cg/HLSL. |
| 198 * In this implementation of o3d, that is true by default. |
| 199 **/ |
| 200 o3d.ClientInfo.prototype.glsl = true; |
| 201 |
| 202 |
| 203 |
| 195 /** | 204 /** |
| 196 * The Client class is the main point of entry to O3D. It defines methods | 205 * The Client class is the main point of entry to O3D. It defines methods |
| 197 * for creating and deleting packs. Each new object created by the Client is | 206 * for creating and deleting packs. Each new object created by the Client is |
| 198 * assigned a unique ID. | 207 * assigned a unique ID. |
| 199 * | 208 * |
| 200 * The Client has a root transform for the transform graph and a root render | 209 * The Client has a root transform for the transform graph and a root render |
| 201 * node for the render graph. | 210 * node for the render graph. |
| 202 * @constructor | 211 * @constructor |
| 203 */ | 212 */ |
| 204 o3d.Client = function() { | 213 o3d.Client = function() { |
| 205 o3d.NamedObject.call(this); | 214 o3d.NamedObject.call(this); |
| 206 | 215 |
| 207 var tempPack = this.createPack(); | 216 var tempPack = this.createPack(); |
| 208 this.root = tempPack.createObject('Transform'); | 217 this.root = tempPack.createObject('Transform'); |
| 209 this.renderGraphRoot = tempPack.createObject('RenderNode'); | 218 this.renderGraphRoot = tempPack.createObject('RenderNode'); |
| 210 this.clientId = o3d.Client.nextId++; | 219 this.clientId = o3d.Client.nextId++; |
| 211 this.packs_ = [tempPack]; | 220 this.packs_ = [tempPack]; |
| 221 this.clientInfo = tempPack.createObject('ClientInfo'); |
| 212 | 222 |
| 213 if (o3d.Renderer.clients_.length == 0) | 223 if (o3d.Renderer.clients_.length == 0) |
| 214 o3d.Renderer.installRenderInterval(); | 224 o3d.Renderer.installRenderInterval(); |
| 215 | 225 |
| 216 o3d.Renderer.clients_.push(this); | 226 o3d.Renderer.clients_.push(this); |
| 217 }; | 227 }; |
| 218 o3d.inherit('Client', 'NamedObject'); | 228 o3d.inherit('Client', 'NamedObject'); |
| 219 | 229 |
| 220 /** | 230 /** |
| 221 * @type {function(!o3d.RenderEvent): void} | 231 * @type {function(!o3d.RenderEvent): void} |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 o3d.Client.prototype.__defineSetter__('height', | 577 o3d.Client.prototype.__defineSetter__('height', |
| 568 function(x) { | 578 function(x) { |
| 569 this.gl.hack_canvas.height = x; | 579 this.gl.hack_canvas.height = x; |
| 570 } | 580 } |
| 571 ); | 581 ); |
| 572 | 582 |
| 573 | 583 |
| 574 /** | 584 /** |
| 575 * Initializes this client using the canvas. | 585 * Initializes this client using the canvas. |
| 576 * @param {Canvas} | 586 * @param {Canvas} |
| 587 * @return {boolean} Success. |
| 577 */ | 588 */ |
| 578 o3d.Client.prototype.initWithCanvas = function(canvas) { | 589 o3d.Client.prototype.initWithCanvas = function(canvas) { |
| 579 var gl; | 590 var gl; |
| 580 | 591 |
| 581 var standard_attributes = { | 592 var standard_attributes = { |
| 582 alpha : true, | 593 alpha : true, |
| 583 depth : true, | 594 depth : true, |
| 584 stencil : true, | 595 stencil : true, |
| 585 antialias : true, | 596 antialias : true, |
| 586 premultipliedAlpha : true | 597 premultipliedAlpha : true |
| 587 }; | 598 }; |
| 588 | 599 |
| 600 if (!canvas || !canvas.getContext) { |
| 601 return false; |
| 602 } |
| 589 try {gl = canvas.getContext("experimental-webgl", standard_attributes) } catch
(e) { } | 603 try {gl = canvas.getContext("experimental-webgl", standard_attributes) } catch
(e) { } |
| 590 if (!gl) | |
| 591 try {gl = canvas.getContext("moz-webgl") } catch(e) { } | |
| 592 if (!gl) { | 604 if (!gl) { |
| 593 alert("No WebGL context found"); | 605 try { |
| 594 return null; | 606 gl = canvas.getContext("moz-webgl") |
| 607 } catch(e) { } |
| 595 } | 608 } |
| 596 | 609 |
| 597 // TODO(petersont): hack workaround for WebGLRenderingContext.canvas | 610 if (!gl) { |
| 598 // not being implemented in Firefox. Remove. | 611 return false; |
| 612 } |
| 613 |
| 614 // TODO(petersont): Remove this workaround once WebGLRenderingContext.canvas |
| 615 // is implemented in Firefox. |
| 599 gl.hack_canvas = canvas; | 616 gl.hack_canvas = canvas; |
| 600 this.gl = gl; | 617 this.gl = gl; |
| 601 this.root.gl = gl; | 618 this.root.gl = gl; |
| 602 this.renderGraphRoot.gl = gl; | 619 this.renderGraphRoot.gl = gl; |
| 603 | 620 |
| 604 gl.client = this; | 621 gl.client = this; |
| 605 gl.displayInfo = {width: canvas.width, | 622 gl.displayInfo = {width: canvas.width, |
| 606 height: canvas.height}; | 623 height: canvas.height}; |
| 624 |
| 625 return true; |
| 607 }; | 626 }; |
| 608 | 627 |
| 609 | 628 |
| 610 /** | 629 /** |
| 611 * Sets the per frame render callback. | 630 * Sets the per frame render callback. |
| 612 * | 631 * |
| 613 * Note: The callback will not be called recursively. When your callback is | 632 * Note: The callback will not be called recursively. When your callback is |
| 614 * called if you somehow manage to cause the client to render more frames | 633 * called if you somehow manage to cause the client to render more frames |
| 615 * before you've returned from the callback you will not be called for those | 634 * before you've returned from the callback you will not be called for those |
| 616 * frames. | 635 * frames. |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1069 | 1088 |
| 1070 /** | 1089 /** |
| 1071 * A unique id for this client. | 1090 * A unique id for this client. |
| 1072 * @type {number} | 1091 * @type {number} |
| 1073 */ | 1092 */ |
| 1074 o3d.Client.prototype.clientId = 0; | 1093 o3d.Client.prototype.clientId = 0; |
| 1075 | 1094 |
| 1076 | 1095 |
| 1077 | 1096 |
| 1078 /** | 1097 /** |
| 1098 * Gets info about the client. |
| 1099 */ |
| 1100 o3d.Client.prototype.clientInfo = null; |
| 1101 |
| 1102 |
| 1103 /** |
| 1079 * The canvas associated with this client. | 1104 * The canvas associated with this client. |
| 1080 * @type {Element} | 1105 * @type {Element} |
| 1081 */ | 1106 */ |
| 1082 o3d.Client.prototype.canvas = null; | 1107 o3d.Client.prototype.canvas = null; |
| 1083 | 1108 |
| 1084 | 1109 |
| OLD | NEW |