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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 117 |
118 | 118 |
119 | 119 |
120 /** | 120 /** |
121 * Binds the vertex and index streams required to draw the shape. | 121 * Binds the vertex and index streams required to draw the shape. |
122 */ | 122 */ |
123 o3d.Primitive.prototype.render = function() { | 123 o3d.Primitive.prototype.render = function() { |
124 var streamBank = this.streamBank; | 124 var streamBank = this.streamBank; |
125 var indexBuffer = this.indexBuffer; | 125 var indexBuffer = this.indexBuffer; |
126 | 126 |
| 127 var enabled_attribs = []; |
| 128 |
127 for (var semantic = 0; | 129 for (var semantic = 0; |
128 semantic < streamBank.vertexStreams.length; | 130 semantic < streamBank.vertexStreams.length; |
129 ++semantic) { | 131 ++semantic) { |
130 var streams = streamBank.vertexStreams[semantic]; | 132 var streams = streamBank.vertexStreams[semantic]; |
131 if (streams && streams.length) { | 133 if (streams && streams.length) { |
132 for (var semantic_index = 0; | 134 for (var semantic_index = 0; |
133 semantic_index < streams.length; | 135 semantic_index < streams.length; |
134 ++semantic_index) { | 136 ++semantic_index) { |
135 var gl_index = semantic + semantic_index - 1; | 137 var gl_index = semantic + semantic_index - 1; |
136 var stream = streams[semantic_index]; | 138 var stream = streams[semantic_index]; |
137 var field = stream.field; | 139 var field = stream.field; |
138 var buffer = field.buffer; | 140 var buffer = field.buffer; |
139 | 141 |
140 this.gl.bindBuffer(this.gl.ARRAY_BUFFER, buffer.gl_buffer_); | 142 this.gl.bindBuffer(this.gl.ARRAY_BUFFER, buffer.gl_buffer_); |
141 this.gl.enableVertexAttribArray(gl_index); | 143 this.gl.enableVertexAttribArray(gl_index); |
| 144 enabled_attribs.push(gl_index); |
142 | 145 |
143 // TODO(petersont): Change that hard-coded 4 down there. | 146 // TODO(petersont): Change that hard-coded 4 down there. |
144 this.gl.vertexAttribPointer( | 147 this.gl.vertexAttribPointer( |
145 gl_index, field.numComponents, this.gl.FLOAT, false, | 148 gl_index, field.numComponents, this.gl.FLOAT, false, |
146 buffer.totalComponents * 4, field.offset_ * 4); | 149 buffer.totalComponents * 4, field.offset_ * 4); |
147 } | 150 } |
148 } | 151 } |
149 } | 152 } |
150 | 153 |
151 // TODO(petersont): Change the hard-coded 3 and triangles too. | 154 // TODO(petersont): Change the hard-coded 3 and triangles too. |
152 this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER, indexBuffer.gl_buffer_); | 155 this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER, indexBuffer.gl_buffer_); |
153 this.gl.drawElements(this.gl.TRIANGLES, | 156 this.gl.drawElements(this.gl.TRIANGLES, |
154 this.numberPrimitives * 3, | 157 this.numberPrimitives * 3, |
155 this.gl.UNSIGNED_SHORT, | 158 this.gl.UNSIGNED_SHORT, |
156 0); | 159 0); |
| 160 |
| 161 for (var i = 0; i < enabled_attribs.length; ++i) { |
| 162 this.gl.disableVertexAttribArray(enabled_attribs[i]); |
| 163 } |
157 }; | 164 }; |
OLD | NEW |