-
Notifications
You must be signed in to change notification settings - Fork 12
/
polyfill.js
81 lines (74 loc) · 2.74 KB
/
polyfill.js
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
export default function polyfill(ctx) {
const { gl, capabilities } = ctx;
if (!gl.HALF_FLOAT) {
const ext = gl.getExtension("OES_texture_half_float");
if (ext) gl.HALF_FLOAT = ext.HALF_FLOAT_OES;
}
if (!gl.createVertexArray) {
const ext = gl.getExtension("OES_vertex_array_object");
gl.createVertexArray = ext.createVertexArrayOES.bind(ext);
gl.bindVertexArray = ext.bindVertexArrayOES.bind(ext);
}
if (!gl.drawElementsInstanced) {
const ext = gl.getExtension("ANGLE_instanced_arrays");
gl.drawElementsInstanced = ext.drawElementsInstancedANGLE.bind(ext);
gl.drawArraysInstanced = ext.drawArraysInstancedANGLE.bind(ext);
gl.vertexAttribDivisor = ext.vertexAttribDivisorANGLE.bind(ext);
}
if (!gl.drawBuffers) {
const ext = gl.getExtension("WEBGL_draw_buffers");
if (!ext) {
gl.drawBuffers = () => {
throw new Error("WEBGL_draw_buffers not supported");
};
} else {
gl.drawBuffers = ext.drawBuffersWEBGL.bind(ext);
capabilities.maxColorAttachments = gl.getParameter(
ext.MAX_COLOR_ATTACHMENTS_WEBGL,
);
}
} else {
capabilities.maxColorAttachments = gl.getParameter(
gl.MAX_COLOR_ATTACHMENTS,
);
}
if (!capabilities.disjointTimerQuery) {
gl.TIME_ELAPSED ||= "TIME_ELAPSED";
gl.GPU_DISJOINT ||= "GPU_DISJOINT";
gl.QUERY_RESULT ||= "QUERY_RESULT";
gl.QUERY_RESULT_AVAILABLE ||= "QUERY_RESULT_AVAILABLE";
gl.createQuery ||= () => ({});
gl.deleteQuery ||= () => {};
gl.beginQuery ||= () => {};
gl.endQuery ||= () => {};
gl.getQueryParameter = (q, param) => {
if (param === gl.QUERY_RESULT_AVAILABLE) return true;
if (param === gl.QUERY_RESULT) return 0;
return undefined;
};
gl.getQueryObject = gl.getQueryParameter;
} else {
const extDTQ =
gl.getExtension("EXT_disjoint_timer_query_webgl2") ||
gl.getExtension("EXT_disjoint_timer_query");
gl.TIME_ELAPSED = extDTQ.TIME_ELAPSED_EXT;
gl.GPU_DISJOINT = extDTQ.GPU_DISJOINT_EXT;
gl.QUERY_RESULT ||= extDTQ.QUERY_RESULT_EXT;
gl.QUERY_RESULT_AVAILABLE ||= extDTQ.QUERY_RESULT_AVAILABLE_EXT;
gl.createQuery ||= extDTQ.createQueryEXT.bind(extDTQ);
gl.deleteQuery ||= extDTQ.deleteQueryEXT.bind(extDTQ);
gl.beginQuery ||= extDTQ.beginQueryEXT.bind(extDTQ);
gl.endQuery ||= extDTQ.endQueryEXT.bind(extDTQ);
gl.getQueryParameter ||= extDTQ.getQueryObjectEXT.bind(extDTQ);
}
if (!capabilities.isWebGL2) {
gl.getExtension("OES_element_index_uint");
gl.getExtension("OES_standard_derivatives");
const extsRGB = gl.getExtension("EXT_sRGB");
if (extsRGB) {
gl.SRGB ||= extsRGB.SRGB_EXT;
gl.SRGB8 ||= extsRGB.SRGB_ALPHA_EXT;
gl.SRGB8_ALPHA8 ||= extsRGB.SRGB8_ALPHA8_EXT;
}
}
}