Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Unified Diff: samples/o3d-webgl/client.js

Issue 1703014: Added culling sample. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/o3d/
Patch Set: '' Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « samples/o3d-webgl/bounding_box.js ('k') | samples/o3d-webgl/draw_list.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samples/o3d-webgl/client.js
===================================================================
--- samples/o3d-webgl/client.js (revision 45983)
+++ samples/o3d-webgl/client.js (working copy)
@@ -97,18 +97,8 @@
o3d.Renderer.renderClients = function() {
for (var i = 0; i < o3d.Renderer.clients_.length; ++i) {
var client = o3d.Renderer.clients_[i];
- var renderEvent = new o3d.RenderEvent;
- var now = (new Date()).getTime() * 0.001;
- if(client.then_ == 0.0)
- renderEvent.elapsedTime = 0.0;
- else
- renderEvent.elapsedTime = now - client.then_;
- client.updateDisplayInfo_();
- if (client.render_callback) {
- client.render_callback(renderEvent);
- }
- client.then_ = now;
- client.renderTree(client.renderGraphRoot);
+
+ client.render();
}
};
@@ -213,10 +203,12 @@
*/
o3d.Client = function() {
o3d.NamedObject.call(this);
- this.root = new o3d.Transform;
- this.renderGraphRoot = new o3d.RenderNode;
- this.root = new o3d.Transform;
+
+ var tempPack = this.createPack();
+ this.root = tempPack.createObject('Transform');
+ this.renderGraphRoot = tempPack.createObject('RenderNode');
this.clientId = o3d.Client.nextId++;
+ this.packs_ = [tempPack];
if (o3d.Renderer.clients_.length == 0)
o3d.Renderer.installRenderInterval();
@@ -269,6 +261,13 @@
/**
+ * A list of all packs for this client.
+ * @type {!Array.<!o3d.Pack>}
+ */
+o3d.Client.prototype.packs_ = [];
+
+
+/**
* Function that gets called when the client encounters an error.
*/
o3d.Client.prototype.error_callback = function(error_message) {
@@ -313,12 +312,26 @@
o3d.Client.prototype.createPack =
function() {
var pack = new o3d.Pack;
+ pack.client = this;
pack.gl = this.gl;
+ this.packs_.push(pack);
return pack;
};
/**
+ * Creates a pack object.
+ * A pack object.
+ * @param {!o3d.Pack} pack The pack to remove.
+ */
+o3d.Client.prototype.destroyPack =
+ function(pack) {
+ o3d.removeFromArray(this.packs_, pack);
+};
+
+
+
+/**
* Searches the Client for an object matching the given id.
*
* @param {number} id The id of the object to look for.
@@ -339,8 +352,14 @@
*/
o3d.Client.prototype.getObjects =
function(name, class_name) {
- o3d.notImplemented();
- return [];
+ var objects = [];
+
+ for (var i = 0; i < this.packs_.length; ++i) {
+ var pack = this.packs_[i];
+ objects = objects.concat(pack.getObjects(name, class_name));
+ }
+
+ return objects;
};
@@ -351,8 +370,14 @@
*/
o3d.Client.prototype.getObjectsByClassName =
function(class_name) {
- o3d.notImplemented();
- return [];
+ var objects = [];
+
+ for (var i = 0; i < this.packs_.length; ++i) {
+ var pack = this.packs_[i];
+ objects = objects.concat(pack.getObjectsByClassName(class_name));
+ }
+
+ return objects;
};
@@ -387,11 +412,35 @@
* RENDERMODE_ON_DEMAND.
*/
o3d.Client.prototype.render = function() {
- this.renderTree();
+ // Synthesize a render event.
+ var render_event = new o3d.RenderEvent;
+
+ var now = (new Date()).getTime() * 0.001;
+ if(this.then_ == 0.0)
+ render_event.elapsedTime = 0.0;
+ else
+ render_event.elapsedTime = now - this.then_;
+
+ if (this.render_callback) {
+ for (var stat in this.render_stats_) {
+ render_event[stat] = this.render_stats_[stat];
+ }
+ this.render_callback(render_event);
+ }
+ this.then_ = now;
+ this.renderTree(this.renderGraphRoot);
};
+/**
+ * An object for various statistics that are gather during the render tree
+ * tranversal.
+ *
+ * @type {Object}
+ */
+o3d.Client.prototype.render_stats = {}
+
/**
* Renders a render graph.
*
@@ -407,6 +456,16 @@
*/
o3d.Client.prototype.renderTree =
function(render_node) {
+
+ this.render_stats_ = {
+ drawElementsCulled: 0,
+ drawElementsProcessed: 0,
+ drawElementsRendered: 0,
+ primitivesRendered: 0,
+ transformsCulled: 0,
+ transformsProcessed: 0
+ };
+
render_node.render();
};
@@ -420,7 +479,6 @@
o3d.Client.prototype.getDisplayModes = [];
-
/**
* Makes a region of the plugin area that will invoke full-screen mode if
* clicked. The developer is responsible for communicating this to the user,
@@ -437,7 +495,7 @@
*/
o3d.Client.prototype.setFullscreenClickRegion =
function(x, y, width, height, mode_id) {
-
+ o3d.notImplemented();
};
@@ -537,9 +595,12 @@
}
this.gl = gl;
+ this.root.gl = gl;
+ this.renderGraphRoot.gl = gl;
gl.client = this;
- this.updateDisplayInfo_();
+ gl.displayInfo = {width: canvas.width,
+ height: canvas.height};
};
@@ -890,11 +951,3 @@
o3d.Client.prototype.canvas = null;
-/**
- * Updates the display information attached to the GL.
- * @private
- */
-o3d.Client.prototype.updateDisplayInfo_ = function() {
- this.gl.displayInfo = {width: this.width,
- height: this.height};
-};
« no previous file with comments | « samples/o3d-webgl/bounding_box.js ('k') | samples/o3d-webgl/draw_list.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698