Skip to content

Commit

Permalink
move back applyPragmas to program configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
mourner committed Nov 5, 2016
1 parent 91aabf4 commit 95407bf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
22 changes: 16 additions & 6 deletions js/data/program_configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ class ProgramConfiguration {
this.attributes = [];
this.uniforms = [];
this.interpolationUniforms = [];
this.vertexPragmas = {};
this.fragmentPragmas = {};
this.pragmas = {vertex: {}, fragment: {}};
this.cacheKey = '';
}

Expand Down Expand Up @@ -149,13 +148,24 @@ class ProgramConfiguration {
}

getFragmentPragmas(name) {
this.fragmentPragmas[name] = this.fragmentPragmas[name] || {define: [], initialize: []};
return this.fragmentPragmas[name];
const frag = this.pragmas.fragment;
frag[name] = frag[name] || {define: [], initialize: []};
return frag[name];
}

getVertexPragmas(name) {
this.vertexPragmas[name] = this.vertexPragmas[name] || {define: [], initialize: []};
return this.vertexPragmas[name];
const vert = this.pragmas.vertex;
vert[name] = vert[name] || {define: [], initialize: []};
return vert[name];
}

applyPragmas(source, shaderType) {
return source.replace(/#pragma mapbox: ([\w]+) ([\w]+) ([\w]+) ([\w]+)/g, (match, operation, precision, type, name) => {
return this.pragmas[shaderType][name][operation]
.join('\n')
.replace(/{type}/g, type)
.replace(/{precision}/g, precision);
});
}

populatePaintArray(layer, paintArray, length, globalProperties, featureProperties) {
Expand Down
13 changes: 2 additions & 11 deletions js/render/painter.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,13 +384,13 @@ class Painter {
}

const fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
gl.shaderSource(fragmentShader, applyPragmas(definesSource + definition.fragmentSource, configuration.fragmentPragmas));
gl.shaderSource(fragmentShader, configuration.applyPragmas(definesSource + definition.fragmentSource, 'fragment'));
gl.compileShader(fragmentShader);
assert(gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS), gl.getShaderInfoLog(fragmentShader));
gl.attachShader(program, fragmentShader);

const vertexShader = gl.createShader(gl.VERTEX_SHADER);
gl.shaderSource(vertexShader, applyPragmas(definesSource + shaders.util + definition.vertexSource, configuration.vertexPragmas));
gl.shaderSource(vertexShader, configuration.applyPragmas(definesSource + shaders.util + definition.vertexSource, 'vertex'));
gl.compileShader(vertexShader);
assert(gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS), gl.getShaderInfoLog(vertexShader));
gl.attachShader(program, vertexShader);
Expand Down Expand Up @@ -435,13 +435,4 @@ class Painter {
}
}

function applyPragmas(source, pragmas) {
return source.replace(/#pragma mapbox: ([\w]+) ([\w]+) ([\w]+) ([\w]+)/g, (match, operation, precision, type, name) => {
return pragmas[name][operation]
.join('\n')
.replace(/{type}/g, type)
.replace(/{precision}/g, precision);
});
}

module.exports = Painter;

0 comments on commit 95407bf

Please sign in to comment.