-
Notifications
You must be signed in to change notification settings - Fork 4
/
GLSLShader.ts
90 lines (82 loc) · 2.5 KB
/
GLSLShader.ts
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
78
79
80
81
82
83
84
85
86
87
88
89
90
import {CompositionTypeEnum} from '../../foundation/definitions/CompositionType';
import {ProcessApproach} from '../../foundation/definitions/ProcessApproach';
import {ShaderAttributeOrSemanticsOrString} from '../../foundation/materials/core/AbstractMaterialContent';
import {ShaderSemanticsClass} from '../../foundation/definitions/ShaderSemantics';
import {
VertexAttribute,
VertexAttributeEnum,
} from '../../foundation/definitions/VertexAttribute';
import {WebGLResourceRepository} from '../WebGLResourceRepository';
import SystemState from '../../foundation/system/SystemState';
import {AttributeNames} from '../types/CommonTypes';
export abstract class GLSLShader {
static __instance: GLSLShader;
__webglResourceRepository?: WebGLResourceRepository =
WebGLResourceRepository.getInstance();
constructor() {}
get glsl_fragColor() {
const repo = this.__webglResourceRepository!;
if (
repo.currentWebGLContextWrapper != null &&
repo.currentWebGLContextWrapper!.isWebGL2
) {
return '';
} else {
return 'gl_FragColor = rt0;\n';
}
}
get glsl_textureCube() {
const repo = this.__webglResourceRepository!;
if (repo.currentWebGLContextWrapper!.isWebGL2) {
return 'texture';
} else {
return 'textureCube';
}
}
static get glslMainBegin() {
return `
void main() {
`;
}
static get glslMainEnd() {
return `
}
`;
}
getGlslVertexShaderProperies(str = '') {
return str;
}
get prerequisites() {
const webGLResourceRepository = WebGLResourceRepository.getInstance();
const dataUboDefinition =
webGLResourceRepository.getGlslDataUBODefinitionString();
const dataUBOVec4SizeStr =
webGLResourceRepository.getGlslDataUBOVec4SizeString();
return `uniform float u_materialSID;
`;
}
get mainPrerequisites() {
const processApproach = SystemState.currentProcessApproach;
if (ProcessApproach.isDataTextureApproach(processApproach)) {
return `
`;
} else {
return `
`;
}
}
static getStringFromShaderAnyDataType(
data: ShaderAttributeOrSemanticsOrString
): string {
if (data instanceof ShaderSemanticsClass) {
return 'u_' + data.str;
} else if (VertexAttribute.isInstanceOfVertexAttributeClass(data)) {
return data.shaderStr;
} else {
return data as string;
}
}
abstract get attributeNames(): AttributeNames;
abstract get attributeSemantics(): Array<VertexAttributeEnum>;
abstract get attributeCompositions(): Array<CompositionTypeEnum>;
}