forked from BabylonJS/Babylon.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshaderCodeNode.ts
More file actions
77 lines (67 loc) · 4.1 KB
/
Copy pathshaderCodeNode.ts
File metadata and controls
77 lines (67 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { ProcessingOptions } from './shaderProcessingOptions';
import { StartsWith } from '../../Misc/stringTools';
/** @hidden */
export class ShaderCodeNode {
line: string;
children: ShaderCodeNode[] = [];
additionalDefineKey?: string;
additionalDefineValue?: string;
isValid(preprocessors: { [key: string]: string }): boolean {
return true;
}
process(preprocessors: { [key: string]: string }, options: ProcessingOptions): string {
let result = "";
if (this.line) {
let value: string = this.line;
let processor = options.processor;
if (processor) {
// This must be done before other replacements to avoid mistakenly changing something that was already changed.
if (processor.lineProcessor) {
value = processor.lineProcessor(value, options.isFragment, options.processingContext);
}
if (processor.attributeProcessor && StartsWith(this.line, "attribute")) {
value = processor.attributeProcessor(this.line, preprocessors, options.processingContext);
} else if (processor.varyingProcessor && StartsWith(this.line, "varying")) {
value = processor.varyingProcessor(this.line, options.isFragment, preprocessors, options.processingContext);
} else if (processor.uniformProcessor && processor.uniformRegexp && processor.uniformRegexp.test(this.line)) {
if (!options.lookForClosingBracketForUniformBuffer) {
value = processor.uniformProcessor(this.line, options.isFragment, preprocessors, options.processingContext);
}
} else if (processor.uniformBufferProcessor && processor.uniformBufferRegexp && processor.uniformBufferRegexp.test(this.line)) {
if (!options.lookForClosingBracketForUniformBuffer) {
value = processor.uniformBufferProcessor(this.line, options.isFragment, options.processingContext);
options.lookForClosingBracketForUniformBuffer = true;
}
} else if (processor.textureProcessor && processor.textureRegexp && processor.textureRegexp.test(this.line)) {
value = processor.textureProcessor(this.line, options.isFragment, preprocessors, options.processingContext);
} else if ((processor.uniformProcessor || processor.uniformBufferProcessor) && StartsWith(this.line, "uniform") && !options.lookForClosingBracketForUniformBuffer) {
let regex = /uniform\s+(?:(?:highp)?|(?:lowp)?)\s*(\S+)\s+(\S+)\s*;/;
if (regex.test(this.line)) { // uniform
if (processor.uniformProcessor) {
value = processor.uniformProcessor(this.line, options.isFragment, preprocessors, options.processingContext);
}
} else { // Uniform buffer
if (processor.uniformBufferProcessor) {
value = processor.uniformBufferProcessor(this.line, options.isFragment, options.processingContext);
options.lookForClosingBracketForUniformBuffer = true;
}
}
}
if (options.lookForClosingBracketForUniformBuffer && this.line.indexOf("}") !== -1) {
options.lookForClosingBracketForUniformBuffer = false;
if (processor.endOfUniformBufferProcessor) {
value = processor.endOfUniformBufferProcessor(this.line, options.isFragment, options.processingContext);
}
}
}
result += value + "\r\n";
}
this.children.forEach((child) => {
result += child.process(preprocessors, options);
});
if (this.additionalDefineKey) {
preprocessors[this.additionalDefineKey] = this.additionalDefineValue || "true";
}
return result;
}
}