Add basic shader minification (#13500)
* add basic shader minification (same GL JS does) * don't remove line break at shader end
This commit is contained in:
committed by
GitHub
parent
aefcb1176a
commit
c89daf6bf1
@@ -13,14 +13,23 @@ require('./style-code');
|
||||
let concatenated = '';
|
||||
let offsets = {};
|
||||
|
||||
function basicMinify(src) {
|
||||
return src = src.trim() // strip whitespace at the start/end
|
||||
.replace(/\s*\/\/[^\n]*\n/g, '\n') // strip double-slash comments
|
||||
.replace(/\n+/g, '\n') // collapse multi line breaks
|
||||
.replace(/\n\s+/g, '\n') // strip identation
|
||||
.replace(/\s?([+-\/*=,])\s?/g, '$1') // strip whitespace around operators
|
||||
.replace(/([;\(\),\{\}])\n(?=[^#])/g, '$1'); // strip more line breaks
|
||||
}
|
||||
|
||||
for (const key in shaders) {
|
||||
const vertex = concatenated.length;
|
||||
concatenated += shaders[key].vertexSource;
|
||||
concatenated += '\0';
|
||||
concatenated += basicMinify(shaders[key].vertexSource);
|
||||
concatenated += '\n\0';
|
||||
|
||||
const fragment = concatenated.length;
|
||||
concatenated += shaders[key].fragmentSource;
|
||||
concatenated += '\0';
|
||||
concatenated += basicMinify(shaders[key].fragmentSource);
|
||||
concatenated += '\n\0';
|
||||
|
||||
offsets[key] = {vertex, fragment};
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
const char* background::name = "background";
|
||||
const char* background::vertexSource = source() + 2739;
|
||||
const char* background::fragmentSource = source() + 2851;
|
||||
const char* background::vertexSource = source() + 1429;
|
||||
const char* background::fragmentSource = source() + 1525;
|
||||
|
||||
// Uncompressed source of background.vertex.glsl:
|
||||
/*
|
||||
|
||||
@@ -7,8 +7,8 @@ namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
const char* background_pattern::name = "background_pattern";
|
||||
const char* background_pattern::vertexSource = source() + 3020;
|
||||
const char* background_pattern::fragmentSource = source() + 3664;
|
||||
const char* background_pattern::vertexSource = source() + 1675;
|
||||
const char* background_pattern::fragmentSource = source() + 2266;
|
||||
|
||||
// Uncompressed source of background_pattern.vertex.glsl:
|
||||
/*
|
||||
|
||||
@@ -7,8 +7,8 @@ namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
const char* circle::name = "circle";
|
||||
const char* circle::vertexSource = source() + 4416;
|
||||
const char* circle::fragmentSource = source() + 8666;
|
||||
const char* circle::vertexSource = source() + 2927;
|
||||
const char* circle::fragmentSource = source() + 6093;
|
||||
|
||||
// Uncompressed source of circle.vertex.glsl:
|
||||
/*
|
||||
|
||||
@@ -7,8 +7,8 @@ namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
const char* clipping_mask::name = "clipping_mask";
|
||||
const char* clipping_mask::vertexSource = source() + 10633;
|
||||
const char* clipping_mask::fragmentSource = source() + 10745;
|
||||
const char* clipping_mask::vertexSource = source() + 7848;
|
||||
const char* clipping_mask::fragmentSource = source() + 7944;
|
||||
|
||||
// Uncompressed source of clipping_mask.vertex.glsl:
|
||||
/*
|
||||
|
||||
@@ -7,8 +7,8 @@ namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
const char* collision_box::name = "collision_box";
|
||||
const char* collision_box::vertexSource = source() + 14428;
|
||||
const char* collision_box::fragmentSource = source() + 15252;
|
||||
const char* collision_box::vertexSource = source() + 9956;
|
||||
const char* collision_box::fragmentSource = source() + 10602;
|
||||
|
||||
// Uncompressed source of collision_box.vertex.glsl:
|
||||
/*
|
||||
|
||||
@@ -7,8 +7,8 @@ namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
const char* collision_circle::name = "collision_circle";
|
||||
const char* collision_circle::vertexSource = source() + 15671;
|
||||
const char* collision_circle::fragmentSource = source() + 16977;
|
||||
const char* collision_circle::vertexSource = source() + 10825;
|
||||
const char* collision_circle::fragmentSource = source() + 11741;
|
||||
|
||||
// Uncompressed source of collision_circle.vertex.glsl:
|
||||
/*
|
||||
|
||||
@@ -7,8 +7,8 @@ namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
const char* debug::name = "debug";
|
||||
const char* debug::vertexSource = source() + 17919;
|
||||
const char* debug::fragmentSource = source() + 18031;
|
||||
const char* debug::vertexSource = source() + 12417;
|
||||
const char* debug::fragmentSource = source() + 12513;
|
||||
|
||||
// Uncompressed source of debug.vertex.glsl:
|
||||
/*
|
||||
|
||||
@@ -7,8 +7,8 @@ namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
const char* extrusion_texture::name = "extrusion_texture";
|
||||
const char* extrusion_texture::vertexSource = source() + 36207;
|
||||
const char* extrusion_texture::fragmentSource = source() + 36423;
|
||||
const char* extrusion_texture::vertexSource = source() + 27521;
|
||||
const char* extrusion_texture::fragmentSource = source() + 27701;
|
||||
|
||||
// Uncompressed source of extrusion_texture.vertex.glsl:
|
||||
/*
|
||||
|
||||
@@ -7,8 +7,8 @@ namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
const char* fill::name = "fill";
|
||||
const char* fill::vertexSource = source() + 18105;
|
||||
const char* fill::fragmentSource = source() + 18811;
|
||||
const char* fill::vertexSource = source() + 12577;
|
||||
const char* fill::fragmentSource = source() + 13221;
|
||||
|
||||
// Uncompressed source of fill.vertex.glsl:
|
||||
/*
|
||||
|
||||
@@ -7,8 +7,8 @@ namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
const char* fill_extrusion::name = "fill_extrusion";
|
||||
const char* fill_extrusion::vertexSource = source() + 27816;
|
||||
const char* fill_extrusion::fragmentSource = source() + 30918;
|
||||
const char* fill_extrusion::vertexSource = source() + 21205;
|
||||
const char* fill_extrusion::fragmentSource = source() + 23088;
|
||||
|
||||
// Uncompressed source of fill_extrusion.vertex.glsl:
|
||||
/*
|
||||
|
||||
@@ -7,8 +7,8 @@ namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
const char* fill_extrusion_pattern::name = "fill_extrusion_pattern";
|
||||
const char* fill_extrusion_pattern::vertexSource = source() + 31050;
|
||||
const char* fill_extrusion_pattern::fragmentSource = source() + 34630;
|
||||
const char* fill_extrusion_pattern::vertexSource = source() + 23204;
|
||||
const char* fill_extrusion_pattern::fragmentSource = source() + 26124;
|
||||
|
||||
// Uncompressed source of fill_extrusion_pattern.vertex.glsl:
|
||||
/*
|
||||
|
||||
@@ -7,8 +7,8 @@ namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
const char* fill_outline::name = "fill_outline";
|
||||
const char* fill_outline::vertexSource = source() + 19280;
|
||||
const char* fill_outline::fragmentSource = source() + 20185;
|
||||
const char* fill_outline::vertexSource = source() + 13645;
|
||||
const char* fill_outline::fragmentSource = source() + 14470;
|
||||
|
||||
// Uncompressed source of fill_outline.vertex.glsl:
|
||||
/*
|
||||
|
||||
@@ -7,8 +7,8 @@ namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
const char* fill_outline_pattern::name = "fill_outline_pattern";
|
||||
const char* fill_outline_pattern::vertexSource = source() + 20843;
|
||||
const char* fill_outline_pattern::fragmentSource = source() + 22928;
|
||||
const char* fill_outline_pattern::vertexSource = source() + 15059;
|
||||
const char* fill_outline_pattern::fragmentSource = source() + 16919;
|
||||
|
||||
// Uncompressed source of fill_outline_pattern.vertex.glsl:
|
||||
/*
|
||||
|
||||
@@ -7,8 +7,8 @@ namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
const char* fill_pattern::name = "fill_pattern";
|
||||
const char* fill_pattern::vertexSource = source() + 24474;
|
||||
const char* fill_pattern::fragmentSource = source() + 26459;
|
||||
const char* fill_pattern::vertexSource = source() + 18226;
|
||||
const char* fill_pattern::fragmentSource = source() + 20005;
|
||||
|
||||
// Uncompressed source of fill_pattern.vertex.glsl:
|
||||
/*
|
||||
|
||||
@@ -7,8 +7,8 @@ namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
const char* heatmap::name = "heatmap";
|
||||
const char* heatmap::vertexSource = source() + 10792;
|
||||
const char* heatmap::fragmentSource = source() + 13248;
|
||||
const char* heatmap::vertexSource = source() + 7983;
|
||||
const char* heatmap::fragmentSource = source() + 9030;
|
||||
|
||||
// Uncompressed source of heatmap.vertex.glsl:
|
||||
/*
|
||||
|
||||
@@ -7,8 +7,8 @@ namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
const char* heatmap_texture::name = "heatmap_texture";
|
||||
const char* heatmap_texture::vertexSource = source() + 13889;
|
||||
const char* heatmap_texture::fragmentSource = source() + 14105;
|
||||
const char* heatmap_texture::vertexSource = source() + 9491;
|
||||
const char* heatmap_texture::fragmentSource = source() + 9671;
|
||||
|
||||
// Uncompressed source of heatmap_texture.vertex.glsl:
|
||||
/*
|
||||
|
||||
@@ -7,8 +7,8 @@ namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
const char* hillshade::name = "hillshade";
|
||||
const char* hillshade::vertexSource = source() + 39369;
|
||||
const char* hillshade::fragmentSource = source() + 39568;
|
||||
const char* hillshade::vertexSource = source() + 29196;
|
||||
const char* hillshade::fragmentSource = source() + 29367;
|
||||
|
||||
// Uncompressed source of hillshade.vertex.glsl:
|
||||
/*
|
||||
|
||||
@@ -7,8 +7,8 @@ namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
const char* hillshade_prepare::name = "hillshade_prepare";
|
||||
const char* hillshade_prepare::vertexSource = source() + 36635;
|
||||
const char* hillshade_prepare::fragmentSource = source() + 36849;
|
||||
const char* hillshade_prepare::vertexSource = source() + 27892;
|
||||
const char* hillshade_prepare::fragmentSource = source() + 28074;
|
||||
|
||||
// Uncompressed source of hillshade_prepare.vertex.glsl:
|
||||
/*
|
||||
|
||||
@@ -7,8 +7,8 @@ namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
const char* line::name = "line";
|
||||
const char* line::vertexSource = source() + 42204;
|
||||
const char* line::fragmentSource = source() + 46667;
|
||||
const char* line::vertexSource = source() + 30441;
|
||||
const char* line::fragmentSource = source() + 33365;
|
||||
|
||||
// Uncompressed source of line.vertex.glsl:
|
||||
/*
|
||||
|
||||
@@ -7,8 +7,8 @@ namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
const char* line_gradient::name = "line_gradient";
|
||||
const char* line_gradient::vertexSource = source() + 47839;
|
||||
const char* line_gradient::fragmentSource = source() + 52148;
|
||||
const char* line_gradient::vertexSource = source() + 34191;
|
||||
const char* line_gradient::fragmentSource = source() + 36910;
|
||||
|
||||
// Uncompressed source of line_gradient.vertex.glsl:
|
||||
/*
|
||||
|
||||
@@ -7,8 +7,8 @@ namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
const char* line_pattern::name = "line_pattern";
|
||||
const char* line_pattern::vertexSource = source() + 53433;
|
||||
const char* line_pattern::fragmentSource = source() + 58509;
|
||||
const char* line_pattern::vertexSource = source() + 37697;
|
||||
const char* line_pattern::fragmentSource = source() + 41018;
|
||||
|
||||
// Uncompressed source of line_pattern.vertex.glsl:
|
||||
/*
|
||||
|
||||
@@ -7,8 +7,8 @@ namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
const char* line_sdf::name = "line_sdf";
|
||||
const char* line_sdf::vertexSource = source() + 61808;
|
||||
const char* line_sdf::fragmentSource = source() + 67175;
|
||||
const char* line_sdf::vertexSource = source() + 43331;
|
||||
const char* line_sdf::fragmentSource = source() + 46945;
|
||||
|
||||
// Uncompressed source of line_sdf.vertex.glsl:
|
||||
/*
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
const char* vertexPrelude = source() + 0;
|
||||
const char* fragmentPrelude = source() + 2558;
|
||||
const char* fragmentPrelude = source() + 1252;
|
||||
|
||||
} // namespace shaders
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -7,8 +7,8 @@ namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
const char* raster::name = "raster";
|
||||
const char* raster::vertexSource = source() + 69101;
|
||||
const char* raster::fragmentSource = source() + 69914;
|
||||
const char* raster::vertexSource = source() + 48448;
|
||||
const char* raster::fragmentSource = source() + 48797;
|
||||
|
||||
// Uncompressed source of raster.vertex.glsl:
|
||||
/*
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -7,8 +7,8 @@ namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
const char* symbol_icon::name = "symbol_icon";
|
||||
const char* symbol_icon::vertexSource = source() + 71318;
|
||||
const char* symbol_icon::fragmentSource = source() + 74724;
|
||||
const char* symbol_icon::vertexSource = source() + 49856;
|
||||
const char* symbol_icon::fragmentSource = source() + 52510;
|
||||
|
||||
// Uncompressed source of symbol_icon.vertex.glsl:
|
||||
/*
|
||||
|
||||
@@ -7,8 +7,8 @@ namespace mbgl {
|
||||
namespace shaders {
|
||||
|
||||
const char* symbol_sdf::name = "symbol_sdf";
|
||||
const char* symbol_sdf::vertexSource = source() + 75174;
|
||||
const char* symbol_sdf::fragmentSource = source() + 81099;
|
||||
const char* symbol_sdf::vertexSource = source() + 52915;
|
||||
const char* symbol_sdf::fragmentSource = source() + 56955;
|
||||
|
||||
// Uncompressed source of symbol_sdf.vertex.glsl:
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user