Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Wojciechowski committed Mar 2, 2016
1 parent 083e10e commit b3e4975
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 10 deletions.
8 changes: 7 additions & 1 deletion js/data/bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var featureFilter = require('feature-filter');
var Buffer = require('./buffer');
var StyleLayer = require('../style/style_layer');
var util = require('../util/util');
var assert = require('assert');

module.exports = Bucket;

Expand Down Expand Up @@ -232,7 +233,12 @@ Bucket.prototype.setAttribPointers = function(shaderName, gl, shader, offset, ar
}

// Set enabled attributes
this.buffers[this.getBufferName(shaderName, 'vertex')].setAttribPointers(gl, shader, offset);
var enabledAttributes = this.getAttributes(shaderName, {isEnabled: true});
var vertexBuffer = this.buffers[this.getBufferName(shaderName, 'vertex')];
assert(enabledAttributes.length === vertexBuffer.attributes.length);
vertexBuffer.setAttribPointers(gl, shader, offset, util.mapObjectKV(enabledAttributes, function(attribute) {
return [attribute.name, 'a_' + attribute.name];
}));
};

/**
Expand Down
18 changes: 13 additions & 5 deletions js/data/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,21 @@ Buffer.prototype.destroy = function(gl) {
* @param shader The active WebGL shader
* @param {number} offset The offset of the attribute data in the currently bound GL buffer.
*/
Buffer.prototype.setAttribPointers = function(gl, shader, offset) {
for (var i = 0; i < this.attributes.length; i++) {
var attrib = this.attributes[i];
Buffer.prototype.setAttribPointers = function(gl, shader, offset, attribs) {
for (var bufferAttribName in attribs) {
var shaderAttribName = attribs[bufferAttribName];
var attrib = this.attributes.find(function(attribute) {
return attribute.name === bufferAttribName;
});

gl.vertexAttribPointer(
shader['a_' + attrib.name], attrib.components, gl[attrib.type.name],
false, this.itemSize, offset + attrib.offset);
shader[shaderName],
attrib.components,
gl[attrib.type.name],
false,
this.itemSize,
offset + attrib.offset
);
}
};

Expand Down
4 changes: 3 additions & 1 deletion js/render/draw_fill.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,15 @@ function drawFill(painter, source, layer, coord) {
for (var i = 0; i < elementGroups.length; i++) {
var group = elementGroups[i];
var offset = group.vertexStartIndex * vertex.itemSize;
vertex.setAttribPointers(gl, painter.fillShader, offset);
bucket.setAttribPointers('fill', gl, shader, offset, [{$zoom: painter.transform.zoom}]);

var count = group.elementLength * 3;
var elementOffset = group.elementStartIndex * elements.itemSize;
gl.drawElements(gl.TRIANGLES, count, gl.UNSIGNED_SHORT, elementOffset);
}

bucket.unsetAttribPointers('fill', gl, shader);

// Now that we have the stencil mask in the stencil buffer, we can start
// writing to the color buffer.
gl.colorMask(true, true, true, true);
Expand Down
6 changes: 3 additions & 3 deletions js/render/draw_symbol.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function drawSymbol(painter, layer, posMatrix, tile, bucket, elementGroups, pref
var extra = (topedgelength + x) / topedgelength - 1;

var text = prefix === 'text';
var shader, vertex, elements, texsize;
var shader, shaderName, vertex, elements, texsize;

if (!text && !painter.style.sprite.loaded())
return;
Expand Down Expand Up @@ -190,7 +190,7 @@ function drawSymbol(painter, layer, posMatrix, tile, bucket, elementGroups, pref
group = elementGroups[i];
offset = group.vertexStartIndex * vertex.itemSize;
vertex.bind(gl);
vertex.setAttribPointers(gl, shader, offset);
bucket.setAttribPointers('symbol', gl, shader, offset);

count = group.elementLength * 3;
elementOffset = group.elementStartIndex * elements.itemSize;
Expand All @@ -203,7 +203,7 @@ function drawSymbol(painter, layer, posMatrix, tile, bucket, elementGroups, pref
group = elementGroups[k];
offset = group.vertexStartIndex * vertex.itemSize;
vertex.bind(gl);
vertex.setAttribPointers(gl, shader, offset);
bucket.setAttribPointers('symbol', gl, shader, offset);

count = group.elementLength * 3;
elementOffset = group.elementStartIndex * elements.itemSize;
Expand Down
9 changes: 9 additions & 0 deletions js/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,15 @@ exports.mapObject = function(input, iterator, context) {
return output;
};

exports.mapObjectKV = function(input, iterator, context) {
var output = {};
for (var key in input) {
var pair = iterator.call(context || this, input[key], key, input);
output[pair[0]] = pair[1];
}
return output;
};

/**
* Create an object by filtering out values of an existing object
* @param {Object} input
Expand Down

0 comments on commit b3e4975

Please sign in to comment.