| 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 15 matching lines...) Expand all Loading... |
| 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 */ | 30 */ |
| 31 | 31 |
| 32 | 32 |
| 33 /** | 33 /** |
| 34 * A Primitive is a type of Element that is made from a list of points, | 34 * A Primitive is a type of Element that is made from a list of points, |
| 35 * lines or triangles that use a single material. | 35 * lines or triangles that use a single material. |
| 36 * | 36 * |
| 37 * @param opt_streamBank o3d.StreamBank The StreamBank used by this | 37 * @param opt_streamBank o3d.StreamBank The StreamBank used by this |
| 38 * Primitive. | 38 * Primitive. |
| 39 * @constructor | 39 * @constructor |
| 40 */ | 40 */ |
| 41 o3d.Primitive = function(opt_streamBank) { | 41 o3d.Primitive = function(opt_streamBank) { |
| 42 o3d.Element.call(this); | 42 o3d.Element.call(this); |
| 43 /** | 43 /** |
| 44 * The stream bank this primitive uses for vertices. | 44 * The stream bank this primitive uses for vertices. |
| 45 * @type {o3d.StreamBank} | 45 * @type {o3d.StreamBank} |
| 46 */ | 46 */ |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 enabled_attribs.push(gl_index); | 131 enabled_attribs.push(gl_index); |
| 132 | 132 |
| 133 // TODO(petersont): Change that hard-coded 4 down there. | 133 // TODO(petersont): Change that hard-coded 4 down there. |
| 134 this.gl.vertexAttribPointer( | 134 this.gl.vertexAttribPointer( |
| 135 gl_index, field.numComponents, this.gl.FLOAT, false, | 135 gl_index, field.numComponents, this.gl.FLOAT, false, |
| 136 buffer.totalComponents * 4, field.offset_ * 4); | 136 buffer.totalComponents * 4, field.offset_ * 4); |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 | 140 |
| 141 this.gl.client.render_stats_['primitivesRendered'] += this.numberPrimitives; |
| 142 |
| 141 // TODO(petersont): Change the hard-coded 3 and triangles too. | 143 // TODO(petersont): Change the hard-coded 3 and triangles too. |
| 142 this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER, indexBuffer.gl_buffer_); | 144 this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER, indexBuffer.gl_buffer_); |
| 143 this.gl.drawElements(this.gl.TRIANGLES, | 145 this.gl.drawElements(this.gl.TRIANGLES, |
| 144 this.numberPrimitives * 3, | 146 this.numberPrimitives * 3, |
| 145 this.gl.UNSIGNED_SHORT, | 147 this.gl.UNSIGNED_SHORT, |
| 146 0); | 148 0); |
| 147 | 149 |
| 148 for (var i = 0; i < enabled_attribs.length; ++i) { | 150 for (var i = 0; i < enabled_attribs.length; ++i) { |
| 149 this.gl.disableVertexAttribArray(enabled_attribs[i]); | 151 this.gl.disableVertexAttribArray(enabled_attribs[i]); |
| 150 } | 152 } |
| 151 }; | 153 }; |
| 154 |
| 155 |
| 156 /** |
| 157 * Computes the bounding box in same coordinate system as the specified |
| 158 * POSITION stream. |
| 159 * @param {number} position_stream_index Index of POSITION stream. |
| 160 * @return {!o3d.BoundingBox} The boundingbox for this element in local space. |
| 161 */ |
| 162 o3d.Primitive.prototype.getBoundingBox = |
| 163 function(position_stream_index) { |
| 164 var streamBank = this.streamBank; |
| 165 var indexBuffer = this.indexBuffer; |
| 166 var stream = |
| 167 this.streamBank.vertexStreams[o3d.Stream.POSITION][position_stream_index]; |
| 168 |
| 169 var points = []; |
| 170 var field = stream.field; |
| 171 var buffer = field.buffer; |
| 172 var numPoints = buffer.array_.length / buffer.totalComponents; |
| 173 |
| 174 var elements = field.getAt(0, numPoints); |
| 175 |
| 176 for (var index = 0; index < numPoints; ++index) { |
| 177 var p = [0, 0, 0]; |
| 178 for (var i = 0; i < field.numComponents; ++i) { |
| 179 p[i] = elements[field.numComponents * index + i]; |
| 180 } |
| 181 points.push(p); |
| 182 } |
| 183 |
| 184 o3d.BoundingBox.fitBoxToPoints_(points, this.boundingBox); |
| 185 return this.boundingBox; |
| 186 }; |
| 187 |
| 188 |
| 189 |
| OLD | NEW |