Removed the legacy shader build system
This commit is contained in:
13
Makefile
13
Makefile
@@ -1,13 +0,0 @@
|
|||||||
SRC_GLSL := $(shell find src -type f -name '*.glsl')
|
|
||||||
SRC_SHADER_JS := $(patsubst %shader.glsl,%shader.js,$(SRC_GLSL))
|
|
||||||
SRC_SHADERLOCATIONS_JS := $(patsubst %shader.glsl,%shader/Locations.js,$(SRC_GLSL))
|
|
||||||
|
|
||||||
.PHONY: shaders
|
|
||||||
shaders: $(SRC_SHADER_JS) $(SRC_SHADERLOCATIONS_JS)
|
|
||||||
|
|
||||||
%shader.js: %shader.glsl src/ol/webgl/shader.mustache tasks/glslunit.js
|
|
||||||
@node tasks/glslunit.js --input $< | ./node_modules/.bin/mustache - src/ol/webgl/shader.mustache > $@
|
|
||||||
|
|
||||||
%shader/Locations.js: %shader.glsl src/ol/webgl/shaderlocations.mustache tasks/glslunit.js
|
|
||||||
@mkdir -p $(@D)
|
|
||||||
@node tasks/glslunit.js --input $< | ./node_modules/.bin/mustache - src/ol/webgl/shaderlocations.mustache > $@
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
/**
|
|
||||||
* @module {{{module}}}
|
|
||||||
*/
|
|
||||||
// This file is automatically generated, do not edit.
|
|
||||||
// Run `make shaders` to generate, and commit the result.
|
|
||||||
|
|
||||||
import {DEBUG as DEBUG_WEBGL} from '../../../webgl.js';
|
|
||||||
import WebGLFragment from '../../../webgl/Fragment.js';
|
|
||||||
import WebGLVertex from '../../../webgl/Vertex.js';
|
|
||||||
|
|
||||||
export const fragment = new WebGLFragment(DEBUG_WEBGL ?
|
|
||||||
'precision mediump float;\n{{{originalFragmentSource}}}' :
|
|
||||||
'precision mediump float;{{{fragmentSource}}}');
|
|
||||||
|
|
||||||
export const vertex = new WebGLVertex(DEBUG_WEBGL ?
|
|
||||||
'{{{originalVertexSource}}}' :
|
|
||||||
'{{{vertexSource}}}');
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
/**
|
|
||||||
* @module {{{module}}}/Locations
|
|
||||||
*/
|
|
||||||
// This file is automatically generated, do not edit
|
|
||||||
// Run `make shaders` to generate, and commit the result.
|
|
||||||
|
|
||||||
import {DEBUG as DEBUG_WEBGL} from '../../../../webgl.js';
|
|
||||||
|
|
||||||
class Locations {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {WebGLRenderingContext} gl GL.
|
|
||||||
* @param {WebGLProgram} program Program.
|
|
||||||
*/
|
|
||||||
constructor(gl, program) {
|
|
||||||
{{#uniforms}}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @type {WebGLUniformLocation}
|
|
||||||
*/
|
|
||||||
this.{{originalName}} = gl.getUniformLocation(
|
|
||||||
program, DEBUG_WEBGL ? '{{originalName}}' : '{{shortName}}');
|
|
||||||
{{/uniforms}}
|
|
||||||
{{#attributes}}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @type {number}
|
|
||||||
*/
|
|
||||||
this.{{originalName}} = gl.getAttribLocation(
|
|
||||||
program, DEBUG_WEBGL ? '{{originalName}}' : '{{shortName}}');
|
|
||||||
{{/attributes}}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export default Locations;
|
|
||||||
@@ -1,146 +0,0 @@
|
|||||||
const fs = require('fs');
|
|
||||||
|
|
||||||
const ESCAPE_SEQUENCE = {
|
|
||||||
'\\': '\\\\',
|
|
||||||
'\n': '\\n',
|
|
||||||
'\t': '\\t'
|
|
||||||
};
|
|
||||||
|
|
||||||
function js_escape(s) {
|
|
||||||
return s.split('').map(function(c) {
|
|
||||||
return ESCAPE_SEQUENCE[c] || c;
|
|
||||||
}).join('');
|
|
||||||
}
|
|
||||||
|
|
||||||
function glsl_compress(s, shortNames) {
|
|
||||||
// strip leading whitespace
|
|
||||||
s = s.replace(/^\s+/g, '');
|
|
||||||
// strip trailing whitespace
|
|
||||||
s = s.replace(/\s+$/g, '');
|
|
||||||
// strip multi-line comments
|
|
||||||
s = s.replace(/\/\*[\s\S]*?\*\//g, '');
|
|
||||||
// strip single line comments
|
|
||||||
s = s.replace(/\/\/.*?\n/g, '');
|
|
||||||
// replace multiple whitespace with a single space
|
|
||||||
s = s.replace(/\s+/g, ' ');
|
|
||||||
// remove whitespace between non-word tokens
|
|
||||||
s = s.replace(/(\S)\s+([^\w])/g, '$1$2')
|
|
||||||
.replace(/([^\w])\s+(\S)/g, '$1$2');
|
|
||||||
// replace original names with short names
|
|
||||||
for (const originalName in shortNames) {
|
|
||||||
s = s.replace(new RegExp(originalName, 'gm'), shortNames[originalName]);
|
|
||||||
}
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
function main(argv) {
|
|
||||||
const options = {};
|
|
||||||
for (let i = 2, ii = argv.length; i < ii; i += 2) {
|
|
||||||
options[argv[i].replace(/^../, '')] = argv[i + 1];
|
|
||||||
}
|
|
||||||
if (!options.input) {
|
|
||||||
process.stdout.write('--input option missing\n');
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
const json = {};
|
|
||||||
let nextShortName = 'a'.charCodeAt(0);
|
|
||||||
const shortNames = {};
|
|
||||||
|
|
||||||
const attributes = {};
|
|
||||||
const uniforms = {};
|
|
||||||
const varyings = {};
|
|
||||||
const blocks = {
|
|
||||||
common: '',
|
|
||||||
vertex: '',
|
|
||||||
fragment: ''
|
|
||||||
};
|
|
||||||
let block = undefined;
|
|
||||||
const inFile = fs.readFileSync(options.input, 'utf-8');
|
|
||||||
const lines = inFile.split('\n');
|
|
||||||
|
|
||||||
let m, shortName;
|
|
||||||
lines.forEach(function(line, i) {
|
|
||||||
if (line.indexOf('//!') == 0) {
|
|
||||||
m = line.match(/\/\/!\s+MODULE=(\S+)\s*$/);
|
|
||||||
if (m) {
|
|
||||||
json.module = m[1];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m = line.match(/\/\/!\s+COMMON\s*$/);
|
|
||||||
if (m) {
|
|
||||||
block = 'common';
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m = line.match(/\/\/!\s+VERTEX\s*$/);
|
|
||||||
if (m) {
|
|
||||||
block = 'vertex';
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m = line.match(/\/\/!\s+FRAGMENT\s*$/);
|
|
||||||
if (m) {
|
|
||||||
block = 'fragment';
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (block === undefined) {
|
|
||||||
if (line.replace(/\s+$/g, '') != '') {
|
|
||||||
process.stdout.write(`Error parsing ${options.input}\n`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
blocks[block] += line + (i == lines.length - 1 ? '' : '\n');
|
|
||||||
}
|
|
||||||
m = line.match(/attribute\s+\S+\s+(\S+);\s*$/);
|
|
||||||
if (m) {
|
|
||||||
const attribute = m[1];
|
|
||||||
if (!(attribute in attributes)) {
|
|
||||||
shortName = String.fromCharCode(nextShortName++);
|
|
||||||
attributes[attribute] = {
|
|
||||||
originalName: attribute,
|
|
||||||
shortName: shortName
|
|
||||||
};
|
|
||||||
shortNames[attribute] = shortName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m = line.match(/uniform\s+\S+\s+(\S+);\s*$/);
|
|
||||||
if (m) {
|
|
||||||
const uniform = m[1];
|
|
||||||
if (!(uniform in uniforms)) {
|
|
||||||
shortName = String.fromCharCode(nextShortName++);
|
|
||||||
uniforms[uniform] = {
|
|
||||||
originalName: uniform,
|
|
||||||
shortName: shortName
|
|
||||||
};
|
|
||||||
shortNames[uniform] = shortName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m = line.match(/varying\s+\S+\s+(\S+);\s*$/);
|
|
||||||
if (m) {
|
|
||||||
const varying = m[1];
|
|
||||||
if (!(varying in varyings)) {
|
|
||||||
shortName = String.fromCharCode(nextShortName++);
|
|
||||||
shortNames[varying] = shortName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
json.originalFragmentSource = js_escape(blocks.common + blocks.fragment);
|
|
||||||
json.originalVertexSource = js_escape(blocks.common + blocks.vertex);
|
|
||||||
json.fragmentSource = glsl_compress(blocks.common + blocks.fragment, shortNames);
|
|
||||||
json.vertexSource = glsl_compress(blocks.common + blocks.vertex, shortNames);
|
|
||||||
json.attributes = Object.keys(attributes).map(a => attributes[a]);
|
|
||||||
json.uniforms = Object.keys(uniforms).map(u => uniforms[u]);
|
|
||||||
|
|
||||||
if (options.output && options.output != '-') {
|
|
||||||
fs.writeFileSync(options.output, JSON.stringify(json));
|
|
||||||
} else {
|
|
||||||
process.stdout.write(JSON.stringify(json));
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (require.main === module) {
|
|
||||||
process.exit(main(process.argv));
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user