Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bind vertex attributes in the order determined by their ProgramInterface #4795

Merged
merged 1 commit into from
Jun 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/data/array_group.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ArrayGroup {
this.layerData = {};
for (const layer of layers) {
const programConfiguration = ProgramConfiguration.createDynamic(
programInterface.paintAttributes || [], layer, zoom);
programInterface, layer, zoom);
this.layerData[layer.id] = {
layer: layer,
programConfiguration: programConfiguration,
Expand Down
2 changes: 1 addition & 1 deletion src/data/buffer_group.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class BufferGroup {
this.layerData = {};
for (const layer of layers) {
const array = arrays.paintVertexArrays && arrays.paintVertexArrays[layer.id];
const programConfiguration = ProgramConfiguration.createDynamic(programInterface.paintAttributes || [], layer, zoom);
const programConfiguration = ProgramConfiguration.createDynamic(programInterface, layer, zoom);
const paintVertexBuffer = array ? new Buffer(array.array, array.type, Buffer.BufferType.VERTEX) : null;
this.layerData[layer.id] = {programConfiguration, paintVertexBuffer};
}
Expand Down
6 changes: 4 additions & 2 deletions src/data/program_configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ class ProgramConfiguration {
this.interpolationUniforms = [];
this.pragmas = {vertex: {}, fragment: {}};
this.cacheKey = '';
this.interface = {};
}

static createDynamic(attributes, layer, zoom) {
static createDynamic(programInterface, layer, zoom) {
const self = new ProgramConfiguration();

for (const attributeConfig of attributes) {
for (const attributeConfig of programInterface.paintAttributes || []) {
const attribute = normalizePaintAttribute(attributeConfig, layer);
assert(/^a_/.test(attribute.name));
const name = attribute.name.slice(2);
Expand All @@ -51,6 +52,7 @@ class ProgramConfiguration {
}
}
self.PaintVertexArray = createVertexArrayType(self.attributes);
self.interface = programInterface;

return self;
}
Expand Down
13 changes: 7 additions & 6 deletions src/render/painter.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,13 @@ class Painter {
assert(gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS), gl.getShaderInfoLog(vertexShader));
gl.attachShader(program, vertexShader);


// For the symbol programs, manually ensure the attrib bound to position 0 is always used (either a_data or a_pos_offset would work here).
// This is needed to fix https://github.com/mapbox/mapbox-gl-js/issues/4607 — otherwise a_size can be bound first, causing rendering to fail.
// All remaining attribs will be bound dynamically below.
if (name === 'symbolSDF' || name === 'symbolIcon') {
gl.bindAttribLocation(program, 0, 'a_data');
// Manually bind layout attributes in the order defined by their
// ProgramInterface so that we don't dynamically link an unused
// attribute at position 0, which can cause rendering to fail for an
// entire layer (see #4607, #4728)
const layoutAttributes = configuration.interface.layoutAttributes || [];
for (let i = 0; i < layoutAttributes.length; i++) {
gl.bindAttribLocation(program, i, layoutAttributes[i].name);
}

gl.linkProgram(program);
Expand Down
2 changes: 1 addition & 1 deletion src/shaders/describe_shaders
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function addProgramInfo(layer, programInterface, shaderDefinition) {
const styleLayer = new StyleLayer(layer);
styleLayer.updatePaintTransitions([], {}, { zoom: zoom }, new AnimationLoop(), {});
const configuration = ProgramConfiguration.createDynamic(
programInterface.paintAttributes, styleLayer, zoom);
programInterface, styleLayer, zoom);
const key = `${layer.type}${configuration.cacheKey || ''}`;
const program = programs[key] = programs[key] || { layers: [] };
program.layers.push(layer);
Expand Down
2 changes: 0 additions & 2 deletions src/shaders/symbol_icon.vertex.glsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// NOTE: the a_data attribute in this shader is manually bound (see https://github.com/mapbox/mapbox-gl-js/issues/4607 / #4728).
// If removing or renaming a_data, revisit the manual binding in painter.js accordingly.
attribute vec4 a_pos_offset;
attribute vec2 a_label_pos;
attribute vec4 a_data;
Expand Down
2 changes: 0 additions & 2 deletions src/shaders/symbol_sdf.vertex.glsl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const float PI = 3.141592653589793;

// NOTE: the a_data attribute in this shader is manually bound (see https://github.com/mapbox/mapbox-gl-js/issues/4607).
// If removing or renaming a_data, revisit the manual binding in painter.js accordingly.
attribute vec4 a_pos_offset;
attribute vec2 a_label_pos;
attribute vec4 a_data;
Expand Down