summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorMolly Lloyd <molly@mapbox.com>2017-03-01 11:28:31 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-03-08 15:23:25 -0800
commit692f5e0a9f5321ee2932a976a8eb9e0a83fc3352 (patch)
treecb9ff13dc30455f1700eeb691dc155d0981c4116 /scripts
parent3afae825c7b2f95e58cbcb85c59857f2253c945e (diff)
downloadqtlocation-mapboxgl-692f5e0a9f5321ee2932a976a8eb9e0a83fc3352.tar.gz
Pack min + max into one attribute :muscle:
Some devices supported by Mapbox GL provide only 8 vertex attributes; this change packs existing attributes to get us just under that limit. For properties using a composite function, pack the min and max values into a single attribute with two logical components instead of using two separate attributes and buffers. Special logic is included for color attributes, whose integer components must be packed into the available bits of floating-point attributes. (We don't have access to ivec types in GL ES 2.0.) For source functions, continue to bind just a one-component attribute even though the GLSL type is vec2 (or vec4 for colors). The type-checking done by gl::Attribute is relaxed slightly to accommodate this.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/generate-shaders.js7
1 files changed, 4 insertions, 3 deletions
diff --git a/scripts/generate-shaders.js b/scripts/generate-shaders.js
index 892620cf21..cffe9d3854 100755
--- a/scripts/generate-shaders.js
+++ b/scripts/generate-shaders.js
@@ -60,9 +60,11 @@ ${fragmentPrelude}
].forEach(function (shaderName) {
function applyPragmas(source, pragmas) {
return source.replace(/#pragma mapbox: ([\w]+) ([\w]+) ([\w]+) ([\w]+)/g, (match, operation, precision, type, name) => {
+ const a_type = type === "float" ? "vec2" : "vec4";
return pragmas[operation]
.join("\n")
.replace(/\{type\}/g, type)
+ .replace(/\{a_type}/g, a_type)
.replace(/\{precision\}/g, precision)
.replace(/\{name\}/g, name);
});
@@ -73,12 +75,11 @@ ${fragmentPrelude}
return applyPragmas(source, {
define: [
"uniform lowp float a_{name}_t;",
- "attribute {precision} {type} a_{name}_min;",
- "attribute {precision} {type} a_{name}_max;",
+ "attribute {precision} {a_type} a_{name};",
"varying {precision} {type} {name};"
],
initialize: [
- "{name} = mix(a_{name}_min, a_{name}_max, a_{name}_t);"
+ "{name} = unpack_mix_{a_type}(a_{name}, a_{name}_t);"
]
});
}