Skip to content

Commit

Permalink
Improve setAttribPointers perf
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Wojciechowski committed Mar 7, 2016
1 parent 31834cf commit 44bd38e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
28 changes: 17 additions & 11 deletions js/data/bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,22 @@ function Bucket(options) {
this.createStyleLayers(options.style);
this.attributes = createAttributes(this);

this.setAttribPointersAttributes = {};
for (var shaderName in this.shaderInterfaces) {
this.setAttribPointersAttributes[shaderName] = {};
for (var i = 0; i < this.childLayers.length; i++) {
var layer = this.childLayers[i];
this.setAttribPointersAttributes[shaderName][layer.id] = {};
for (var j = 0; j < this.attributes[shaderName].enabled.length; j++) {
var attribute = this.attributes[shaderName].enabled[j];
if (attribute.isLayerConstant !== false || attribute.layerId === layer.id) {
this.setAttribPointersAttributes[shaderName][layer.id][attribute.name] = attribute.shaderName;
}
}
}
}


if (options.elementGroups) {
this.elementGroups = options.elementGroups;
this.buffers = util.mapObject(options.buffers, function(options) {
Expand Down Expand Up @@ -209,18 +225,8 @@ Bucket.prototype.setAttribPointers = function(shaderName, gl, shader, offset, la
}

// Set enabled attributes
var enabledAttributes = this.attributes[shaderName].enabled.filter(function(attribute) {
return attribute.isLayerConstant !== false || attribute.layerId === layer.id;
});
var vertexBuffer = this.buffers[this.getBufferName(shaderName, 'vertex')];
vertexBuffer.setAttribPointers(
gl,
shader,
offset,
util.mapObjectKV(enabledAttributes, function(attribute) {
return [attribute.name, attribute.shaderName];
})
);
vertexBuffer.setAttribPointers(gl, shader, offset, this.setAttribPointersAttributes[shaderName][layer.id]);
};

Bucket.prototype.bindBuffers = function(shaderInterfaceName, gl, options) {
Expand Down
1 change: 0 additions & 1 deletion js/data/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ Buffer.prototype.setAttribPointers = function(gl, shader, offset, attributes) {
var shaderAttributeName = attributes[bufferAttributeName];
var attribute = this.attributeLookup[bufferAttributeName];
var attributeId = shader[shaderAttributeName];
gl.enableVertexAttribArray(attributeId);
gl.vertexAttribPointer(
attributeId,
attribute.components,
Expand Down
1 change: 1 addition & 0 deletions js/render/draw_circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function drawCircles(painter, source, layer, coords) {
}
}

gl.enableVertexAttribArray(shader.a_color);
gl.enableVertexAttribArray(shader.a_blur);
gl.enableVertexAttribArray(shader.a_size);
}

0 comments on commit 44bd38e

Please sign in to comment.