Reduce number of arrays created

This commit is contained in:
tsauerwein
2014-12-19 15:34:32 +01:00
parent 6c48b2067b
commit 060c9f3bc6
+19 -11
View File
@@ -199,11 +199,18 @@ ol.render.webgl.ImageReplay = function(tolerance, maxExtent) {
this.verticesBuffer_ = null; this.verticesBuffer_ = null;
/** /**
* Start indices per feature. * Start index per feature (the index).
* @type {Array.<Array.<?>>} * @type {Array.<number>}
* @private * @private
*/ */
this.startIndexForFeature_ = []; this.startIndices_ = [];
/**
* Start index per feature (the feature).
* @type {Array.<ol.Feature>}
* @private
*/
this.startIndicesFeature_ = [];
/** /**
* @type {number|undefined} * @type {number|undefined}
@@ -406,7 +413,8 @@ ol.render.webgl.ImageReplay.prototype.drawMultiLineStringGeometry =
*/ */
ol.render.webgl.ImageReplay.prototype.drawMultiPointGeometry = ol.render.webgl.ImageReplay.prototype.drawMultiPointGeometry =
function(multiPointGeometry, feature) { function(multiPointGeometry, feature) {
this.startIndexForFeature_.push([this.indices_.length, feature]); this.startIndices_.push(this.indices_.length);
this.startIndicesFeature_.push(feature);
var flatCoordinates = multiPointGeometry.getFlatCoordinates(); var flatCoordinates = multiPointGeometry.getFlatCoordinates();
var stride = multiPointGeometry.getStride(); var stride = multiPointGeometry.getStride();
this.drawCoordinates_( this.drawCoordinates_(
@@ -426,7 +434,8 @@ ol.render.webgl.ImageReplay.prototype.drawMultiPolygonGeometry =
*/ */
ol.render.webgl.ImageReplay.prototype.drawPointGeometry = ol.render.webgl.ImageReplay.prototype.drawPointGeometry =
function(pointGeometry, feature) { function(pointGeometry, feature) {
this.startIndexForFeature_.push([this.indices_.length, feature]); this.startIndices_.push(this.indices_.length);
this.startIndicesFeature_.push(feature);
var flatCoordinates = pointGeometry.getFlatCoordinates(); var flatCoordinates = pointGeometry.getFlatCoordinates();
var stride = pointGeometry.getStride(); var stride = pointGeometry.getStride();
this.drawCoordinates_( this.drawCoordinates_(
@@ -723,8 +732,8 @@ ol.render.webgl.ImageReplay.prototype.drawHitDetectionReplay_ =
goog.webgl.UNSIGNED_INT : goog.webgl.UNSIGNED_SHORT; goog.webgl.UNSIGNED_INT : goog.webgl.UNSIGNED_SHORT;
var elementSize = context.hasOESElementIndexUint ? 4 : 2; var elementSize = context.hasOESElementIndexUint ? 4 : 2;
var i, groupStart, groupEnd, numItems, featureInfo, start, end; var i, groupStart, groupEnd, numItems, start, end;
var featureIndex = this.startIndexForFeature_.length - 1; var featureIndex = this.startIndices_.length - 1;
for (i = this.hitDetectionTextures_.length - 1; i >= 0; --i) { for (i = this.hitDetectionTextures_.length - 1; i >= 0; --i) {
gl.bindTexture(goog.webgl.TEXTURE_2D, this.hitDetectionTextures_[i]); gl.bindTexture(goog.webgl.TEXTURE_2D, this.hitDetectionTextures_[i]);
groupStart = (i > 0) ? this.hitDetectionGroupIndices_[i - 1] : 0; groupStart = (i > 0) ? this.hitDetectionGroupIndices_[i - 1] : 0;
@@ -732,9 +741,8 @@ ol.render.webgl.ImageReplay.prototype.drawHitDetectionReplay_ =
// draw all features for this texture group // draw all features for this texture group
while (featureIndex >= 0 && while (featureIndex >= 0 &&
this.startIndexForFeature_[featureIndex][0] >= groupStart) { this.startIndices_[featureIndex] >= groupStart) {
featureInfo = this.startIndexForFeature_[featureIndex]; start = this.startIndices_[featureIndex];
start = featureInfo[0];
numItems = end - start; numItems = end - start;
var offsetInBytes = start * elementSize; var offsetInBytes = start * elementSize;
@@ -742,7 +750,7 @@ ol.render.webgl.ImageReplay.prototype.drawHitDetectionReplay_ =
gl.drawElements( gl.drawElements(
goog.webgl.TRIANGLES, numItems, elementType, offsetInBytes); goog.webgl.TRIANGLES, numItems, elementType, offsetInBytes);
var result = featureCallback(/** @type {ol.Feature} */ (featureInfo[1])); var result = featureCallback(this.startIndicesFeature_[featureIndex]);
if (result) { if (result) {
return result; return result;
} }