| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 * Type of the array element. | 66 * Type of the array element. |
| 67 * @type {!WebGLFloatArray} | 67 * @type {!WebGLFloatArray} |
| 68 */ | 68 */ |
| 69 o3d.Buffer.prototype.ArrayType = WebGLFloatArray; | 69 o3d.Buffer.prototype.ArrayType = WebGLFloatArray; |
| 70 | 70 |
| 71 /** | 71 /** |
| 72 * Allocates memory for the data to be stored in the buffer based on | 72 * Allocates memory for the data to be stored in the buffer based on |
| 73 * the types of fields set on the buffer. | 73 * the types of fields set on the buffer. |
| 74 * | 74 * |
| 75 * @param {number} numElements Number of elements to allocate.. | 75 * @param {number} numElements Number of elements to allocate.. |
| 76 * @returns {boolean} True if operation was successful. | 76 * @return {boolean} True if operation was successful. |
| 77 */ | 77 */ |
| 78 o3d.Buffer.prototype.allocateElements = | 78 o3d.Buffer.prototype.allocateElements = |
| 79 function(numElements) { | 79 function(numElements) { |
| 80 var total = 0; | 80 var total = 0; |
| 81 for (var i = 0; i < this.fields_.length; ++i) { | 81 for (var i = 0; i < this.fields_.length; ++i) { |
| 82 this.fields_[i].offset_ = total; | 82 this.fields_[i].offset_ = total; |
| 83 total += this.fields_[i].numComponents; | 83 total += this.fields_[i].numComponents; |
| 84 } | 84 } |
| 85 this.totalComponents = total; | 85 this.totalComponents = total; |
| 86 | 86 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 99 /** | 99 /** |
| 100 * Defines a field on this buffer. | 100 * Defines a field on this buffer. |
| 101 * | 101 * |
| 102 * Note: Creating a field after having allocated the buffer is an expensive | 102 * Note: Creating a field after having allocated the buffer is an expensive |
| 103 * operation as the data currently in the buffer has to be shuffled around | 103 * operation as the data currently in the buffer has to be shuffled around |
| 104 * to make room for the new field. | 104 * to make room for the new field. |
| 105 * | 105 * |
| 106 * @param {string} field_type type of data in the field. Valid types | 106 * @param {string} field_type type of data in the field. Valid types |
| 107 * are "FloatField", "UInt32Field", and "UByteNField". | 107 * are "FloatField", "UInt32Field", and "UByteNField". |
| 108 * @param {number} num_components number of components in the field. | 108 * @param {number} num_components number of components in the field. |
| 109 * @returns {!o3d.Field} The created field. | 109 * @return {!o3d.Field} The created field. |
| 110 */ | 110 */ |
| 111 o3d.Buffer.prototype.createField = | 111 o3d.Buffer.prototype.createField = |
| 112 function(fieldType, numComponents) { | 112 function(fieldType, numComponents) { |
| 113 var f = new o3d.Field(); | 113 var f = new o3d.Field(); |
| 114 f.buffer = this; | 114 f.buffer = this; |
| 115 f.numComponents = numComponents; | 115 f.numComponents = numComponents; |
| 116 f.size = numComponents * (fieldType=='UByteNField' ? 1 : 4); | 116 f.size = numComponents * (fieldType=='UByteNField' ? 1 : 4); |
| 117 this.fields_.push(f); | 117 this.fields_.push(f); |
| 118 return f; | 118 return f; |
| 119 }; | 119 }; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 this.gl.bufferData(this.gl.ARRAY_BUFFER, this.array_, this.gl.STATIC_DRAW); | 159 this.gl.bufferData(this.gl.ARRAY_BUFFER, this.array_, this.gl.STATIC_DRAW); |
| 160 }; | 160 }; |
| 161 | 161 |
| 162 | 162 |
| 163 /** | 163 /** |
| 164 * Sets the values in the buffer given array. | 164 * Sets the values in the buffer given array. |
| 165 * TODO(petersont): This should take other kinds of arguments, like RawData. | 165 * TODO(petersont): This should take other kinds of arguments, like RawData. |
| 166 * | 166 * |
| 167 * @param {!Array.<number>} values contains data to assign to the Buffer | 167 * @param {!Array.<number>} values contains data to assign to the Buffer |
| 168 * data itself. | 168 * data itself. |
| 169 * @returns {boolean} True if operation was successful. | 169 * @return {boolean} True if operation was successful. |
| 170 */ | 170 */ |
| 171 o3d.Buffer.prototype.set = | 171 o3d.Buffer.prototype.set = |
| 172 function(values) { | 172 function(values) { |
| 173 if (this.array_ == null) { | 173 if (this.array_ == null) { |
| 174 this.resize(values.length); | 174 this.resize(values.length); |
| 175 } | 175 } |
| 176 this.lock(); | 176 this.lock(); |
| 177 for (var i = 0; i < values.length; ++i) { | 177 for (var i = 0; i < values.length; ++i) { |
| 178 this.array_[i] = values[i]; | 178 this.array_[i] = values[i]; |
| 179 } | 179 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 206 o3d.notImplemented(); | 206 o3d.notImplemented(); |
| 207 }; | 207 }; |
| 208 | 208 |
| 209 | 209 |
| 210 /** | 210 /** |
| 211 * Gets a copy of a sub range of the values in the data stored in the buffer. | 211 * Gets a copy of a sub range of the values in the data stored in the buffer. |
| 212 * Modifying this copy has no effect on the buffer. | 212 * Modifying this copy has no effect on the buffer. |
| 213 * | 213 * |
| 214 * @param {number} start_index index of the element value to get. | 214 * @param {number} start_index index of the element value to get. |
| 215 * @param {number} numElements the number of elements to get. | 215 * @param {number} numElements the number of elements to get. |
| 216 * @returns {!Array.<number>} An array of values. | 216 * @return {!Array.<number>} An array of values. |
| 217 */ | 217 */ |
| 218 o3d.VertexBufferBase.prototype.getAt = | 218 o3d.VertexBufferBase.prototype.getAt = |
| 219 function(start_index, numElements) { | 219 function(start_index, numElements) { |
| 220 }; | 220 }; |
| 221 | 221 |
| 222 | 222 |
| 223 /** | 223 /** |
| 224 * VertexBuffer is a Buffer object used for storing vertex data for geometry. | 224 * VertexBuffer is a Buffer object used for storing vertex data for geometry. |
| 225 * (e.g. vertex positions, normals, colors, etc). | 225 * (e.g. vertex positions, normals, colors, etc). |
| 226 * A VertexBuffer can be rendered directly by the GPU. | 226 * A VertexBuffer can be rendered directly by the GPU. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 | 271 |
| 272 | 272 |
| 273 /** | 273 /** |
| 274 * Delivers the buffer to the graphics hardware when read/write is finished. | 274 * Delivers the buffer to the graphics hardware when read/write is finished. |
| 275 */ | 275 */ |
| 276 o3d.IndexBuffer.prototype.unlock = function() { | 276 o3d.IndexBuffer.prototype.unlock = function() { |
| 277 this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER, this.gl_buffer_); | 277 this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER, this.gl_buffer_); |
| 278 this.gl.bufferData( | 278 this.gl.bufferData( |
| 279 this.gl.ELEMENT_ARRAY_BUFFER, this.array_, this.gl.STATIC_DRAW); | 279 this.gl.ELEMENT_ARRAY_BUFFER, this.array_, this.gl.STATIC_DRAW); |
| 280 }; | 280 }; |
| OLD | NEW |