diff options
author | luchen@google.com <luchen@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-08 18:21:18 +0000 |
---|---|---|
committer | luchen@google.com <luchen@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-08 18:21:18 +0000 |
commit | 6e0a36b0e6cc24dacde23635af162cd4de464bd8 (patch) | |
tree | 7af6905eba487133eaccd707ae20392f58799bd1 /o3d/samples/o3d-webgl | |
parent | 9e3a1d836b29d513476df8942887c0ea22c3b86e (diff) | |
download | chromium_src-6e0a36b0e6cc24dacde23635af162cd4de464bd8.zip chromium_src-6e0a36b0e6cc24dacde23635af162cd4de464bd8.tar.gz chromium_src-6e0a36b0e6cc24dacde23635af162cd4de464bd8.tar.bz2 |
Adding support for pointlist, linelist, linestrip, trianglestrip and triangelfan primitive drawing types. Demo file included.
Review URL: http://codereview.chromium.org/2645003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49173 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/samples/o3d-webgl')
-rw-r--r-- | o3d/samples/o3d-webgl/buffer.js | 2 | ||||
-rw-r--r-- | o3d/samples/o3d-webgl/primitive.js | 41 |
2 files changed, 38 insertions, 5 deletions
diff --git a/o3d/samples/o3d-webgl/buffer.js b/o3d/samples/o3d-webgl/buffer.js index bf8d572..52520d2 100644 --- a/o3d/samples/o3d-webgl/buffer.js +++ b/o3d/samples/o3d-webgl/buffer.js @@ -194,7 +194,7 @@ o3d.Buffer.prototype.set = if (!values.length) { o3d.notImplemented(); } - if (this.array_ == null) { + if (this.array_ == null || this.array_.length != values.length) { this.resize(values.length); } this.lock(); diff --git a/o3d/samples/o3d-webgl/primitive.js b/o3d/samples/o3d-webgl/primitive.js index 904abf8..4c74c69 100644 --- a/o3d/samples/o3d-webgl/primitive.js +++ b/o3d/samples/o3d-webgl/primitive.js @@ -143,10 +143,44 @@ o3d.Primitive.prototype.render = function() { this.gl.client.render_stats_['primitivesRendered'] += this.numberPrimitives; - // TODO(petersont): Change the hard-coded 3 and triangles too. + var glMode; + var glNumElements; + + switch (this.primitiveType) { + case o3d.Primitive.POINTLIST: + glMode = this.gl.POINTS; + glNumElements = this.numberPrimitives; + break; + case o3d.Primitive.LINELIST: + glMode = this.gl.LINES; + glNumElements = this.numberPrimitives * 2; + break; + case o3d.Primitive.LINESTRIP: + glMode = this.gl.LINE_STRIP; + glNumElements = this.numberPrimitives + 1; + break; + case o3d.Primitive.TRIANGLELIST: + glMode = this.gl.TRIANGLES; + glNumElements = this.numberPrimitives * 3; + break; + case o3d.Primitive.TRIANGLESTRIP: + glMode = this.gl.TRIANGLE_STRIP; + glNumElements = this.numberPrimitives + 2; + break; + case o3d.Primitive.TRIANGLEFAN: + glMode = this.gl.TRIANGLE_FAN; + glNumElements = this.numberPrimitives + 2; + break; + case o3d.Primitive.TRIANGLELIST: + default: + glMode = this.gl.TRIANGLES; + glNumElements = this.numberPrimitives * 3; + break; + } + this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER, indexBuffer.gl_buffer_); - this.gl.drawElements(this.gl.TRIANGLES, - this.numberPrimitives * 3, + this.gl.drawElements(glMode, + glNumElements, this.gl.UNSIGNED_SHORT, 0); @@ -155,7 +189,6 @@ o3d.Primitive.prototype.render = function() { } }; - /** * Computes the bounding box in same coordinate system as the specified * POSITION stream. |