1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- /**
- * A utility for dynamically-generating a GLSL function
- *
- * @alias ShaderFunction
- * @constructor
- *
- * @see {@link ShaderBuilder}
- * @param {String} signature The full signature of the function as it will appear in the shader. Do not include the curly braces.
- * @example
- * // generate the following function
- * //
- * // void assignVaryings(vec3 position)
- * // {
- * // v_positionEC = (czm_modelView * vec4(a_position, 1.0)).xyz;
- * // v_texCoord = a_texCoord;
- * // }
- * const signature = "void assignVaryings(vec3 position)";
- * const func = new ShaderFunction(signature);
- * func.addLine("v_positionEC = (czm_modelView * vec4(a_position, 1.0)).xyz;");
- * func.addLine("v_texCoord = a_texCoord;");
- * const generatedLines = func.generateGlslLines();
- *
- * @private
- */
- export default function ShaderFunction(signature) {
- this.signature = signature;
- this.body = [];
- }
- /**
- * Add an array of lines to the body of the function
- * @param {String[]} lines An array of lines of GLSL code to add to the function body. Do not include any preceding or ending whitespace, but do include the semicolon for each line.
- */
- ShaderFunction.prototype.addLines = function (lines) {
- const paddedLines = lines.map(function (line) {
- return ` ${line}`;
- });
- Array.prototype.push.apply(this.body, paddedLines);
- };
- /**
- * Generate lines of GLSL code for use with {@link ShaderBuilder}
- * @return {String[]}
- */
- ShaderFunction.prototype.generateGlslLines = function () {
- return [].concat(this.signature, "{", this.body, "}");
- };
|