@gjsify/webgl 0.3.16 → 0.3.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/conformance/attribs.spec.js +3 -315
- package/lib/esm/conformance/buffers.spec.js +1 -220
- package/lib/esm/conformance/context.spec.js +3 -302
- package/lib/esm/conformance/programs.spec.js +3 -477
- package/lib/esm/conformance/rendering-basic.spec.js +3 -141
- package/lib/esm/conformance/rendering.spec.js +7 -514
- package/lib/esm/conformance/setup.js +1 -47
- package/lib/esm/conformance/state.spec.js +1 -365
- package/lib/esm/conformance/textures.spec.js +3 -337
- package/lib/esm/conformance/uniforms.spec.js +1 -484
- package/lib/esm/conformance-test.js +1 -25
- package/lib/esm/extensions/ext-blend-minmax.js +1 -18
- package/lib/esm/extensions/ext-color-buffer-float.js +1 -12
- package/lib/esm/extensions/ext-color-buffer-half-float.js +1 -12
- package/lib/esm/extensions/ext-texture-filter-anisotropic.js +1 -18
- package/lib/esm/extensions/oes-element-index-unit.js +1 -13
- package/lib/esm/extensions/oes-standard-derivatives.js +1 -17
- package/lib/esm/extensions/oes-texture-float-linear.js +1 -13
- package/lib/esm/extensions/oes-texture-float.js +1 -13
- package/lib/esm/extensions/oes-texture-half-float.js +1 -19
- package/lib/esm/extensions/stackgl-destroy-context.js +1 -12
- package/lib/esm/extensions/stackgl-resize-drawing-buffer.js +1 -12
- package/lib/esm/html-canvas-element.js +1 -65
- package/lib/esm/index.js +1 -33
- package/lib/esm/linkable.js +1 -50
- package/lib/esm/test-utils.js +4 -186
- package/lib/esm/test.js +1 -11
- package/lib/esm/types/index.js +1 -5
- package/lib/esm/utils.js +1 -201
- package/lib/esm/webgl-active-info.js +1 -11
- package/lib/esm/webgl-bridge.js +1 -167
- package/lib/esm/webgl-buffer.js +1 -19
- package/lib/esm/webgl-context-attributes.js +1 -24
- package/lib/esm/webgl-context-base.js +8 -3069
- package/lib/esm/webgl-drawing-buffer-wrapper.js +1 -11
- package/lib/esm/webgl-framebuffer.js +1 -110
- package/lib/esm/webgl-program.js +1 -27
- package/lib/esm/webgl-query.js +1 -17
- package/lib/esm/webgl-renderbuffer.js +1 -25
- package/lib/esm/webgl-rendering-context.js +1 -175
- package/lib/esm/webgl-sampler.js +1 -17
- package/lib/esm/webgl-shader-precision-format.js +1 -11
- package/lib/esm/webgl-shader.js +1 -25
- package/lib/esm/webgl-sync.js +1 -17
- package/lib/esm/webgl-texture-unit.js +1 -13
- package/lib/esm/webgl-texture.js +1 -23
- package/lib/esm/webgl-transform-feedback.js +1 -17
- package/lib/esm/webgl-uniform-location.js +1 -15
- package/lib/esm/webgl-vertex-array-object.js +1 -23
- package/lib/esm/webgl-vertex-attribute.js +1 -151
- package/lib/esm/webgl1.spec.js +10 -1044
- package/lib/esm/webgl2-rendering-context.js +1 -1218
- package/lib/esm/webgl2.spec.js +45 -1288
- package/lib/types/webgl-bridge.d.ts +9 -9
- package/package.json +9 -9
|
@@ -1,3069 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { WebGLUniformLocation } from "./webgl-uniform-location.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import { getSTACKGLDestroyContext } from "./extensions/stackgl-destroy-context.js";
|
|
9
|
-
import { getSTACKGLResizeDrawingBuffer } from "./extensions/stackgl-resize-drawing-buffer.js";
|
|
10
|
-
import { getEXTBlendMinMax } from "./extensions/ext-blend-minmax.js";
|
|
11
|
-
import { getEXTColorBufferFloat } from "./extensions/ext-color-buffer-float.js";
|
|
12
|
-
import { getEXTColorBufferHalfFloat } from "./extensions/ext-color-buffer-half-float.js";
|
|
13
|
-
import { getEXTTextureFilterAnisotropic } from "./extensions/ext-texture-filter-anisotropic.js";
|
|
14
|
-
import { getOESTextureHalfFloat } from "./extensions/oes-texture-half-float.js";
|
|
15
|
-
import { WebGLActiveInfo } from "./webgl-active-info.js";
|
|
16
|
-
import { WebGLFramebuffer } from "./webgl-framebuffer.js";
|
|
17
|
-
import { WebGLBuffer } from "./webgl-buffer.js";
|
|
18
|
-
import { WebGLDrawingBufferWrapper } from "./webgl-drawing-buffer-wrapper.js";
|
|
19
|
-
import { WebGLProgram } from "./webgl-program.js";
|
|
20
|
-
import { WebGLRenderbuffer } from "./webgl-renderbuffer.js";
|
|
21
|
-
import { WebGLShader } from "./webgl-shader.js";
|
|
22
|
-
import { WebGLShaderPrecisionFormat } from "./webgl-shader-precision-format.js";
|
|
23
|
-
import { WebGLTextureUnit } from "./webgl-texture-unit.js";
|
|
24
|
-
import { WebGLTexture } from "./webgl-texture.js";
|
|
25
|
-
import { WebGLVertexArrayGlobalState, WebGLVertexArrayObjectState } from "./webgl-vertex-attribute.js";
|
|
26
|
-
import Gwebgl from "@girs/gwebgl-0.1";
|
|
27
|
-
import "@girs/gdkpixbuf-2.0";
|
|
28
|
-
import * as bits from "bit-twiddle";
|
|
29
|
-
import tokenize from "glsl-tokenizer/string";
|
|
30
|
-
import GdkPixbuf from "gi://GdkPixbuf?version=2.0";
|
|
31
|
-
import { warnNotImplemented } from "@gjsify/utils";
|
|
32
|
-
|
|
33
|
-
//#region src/ts/webgl-context-base.ts
|
|
34
|
-
const VERSION = "0.0.1";
|
|
35
|
-
let CONTEXT_COUNTER = 0;
|
|
36
|
-
const MAX_UNIFORM_LENGTH = 256;
|
|
37
|
-
const MAX_ATTRIBUTE_LENGTH = 256;
|
|
38
|
-
const availableExtensions = {
|
|
39
|
-
oes_element_index_uint: getOESElementIndexUint,
|
|
40
|
-
oes_texture_float: getOESTextureFloat,
|
|
41
|
-
oes_texture_float_linear: getOESTextureFloatLinear,
|
|
42
|
-
oes_standard_derivatives: getOESStandardDerivatives,
|
|
43
|
-
stackgl_destroy_context: getSTACKGLDestroyContext,
|
|
44
|
-
stackgl_resize_drawingbuffer: getSTACKGLResizeDrawingBuffer,
|
|
45
|
-
ext_blend_minmax: getEXTBlendMinMax,
|
|
46
|
-
ext_color_buffer_float: getEXTColorBufferFloat,
|
|
47
|
-
ext_color_buffer_half_float: getEXTColorBufferHalfFloat,
|
|
48
|
-
ext_texture_filter_anisotropic: getEXTTextureFilterAnisotropic,
|
|
49
|
-
oes_texture_half_float: getOESTextureHalfFloat
|
|
50
|
-
};
|
|
51
|
-
var WebGLContextBase = class {
|
|
52
|
-
get drawingBufferHeight() {
|
|
53
|
-
return this.canvas.height || 0;
|
|
54
|
-
}
|
|
55
|
-
get drawingBufferWidth() {
|
|
56
|
-
return this.canvas.width || 0;
|
|
57
|
-
}
|
|
58
|
-
constructor(canvas, options = {}) {
|
|
59
|
-
this.unpackColorSpace = "srgb";
|
|
60
|
-
this.RGBA8 = 32856;
|
|
61
|
-
this.DEFAULT_ATTACHMENTS = [];
|
|
62
|
-
this.DEFAULT_COLOR_ATTACHMENTS = [];
|
|
63
|
-
this._ = 0;
|
|
64
|
-
this._extensions = {};
|
|
65
|
-
this._programs = {};
|
|
66
|
-
this._shaders = {};
|
|
67
|
-
this._textures = {};
|
|
68
|
-
this._framebuffers = {};
|
|
69
|
-
this._renderbuffers = {};
|
|
70
|
-
this._buffers = {};
|
|
71
|
-
this._activeProgram = null;
|
|
72
|
-
this._activeFramebuffer = null;
|
|
73
|
-
this._activeRenderbuffer = null;
|
|
74
|
-
this._checkStencil = false;
|
|
75
|
-
this._stencilState = true;
|
|
76
|
-
this._activeTextureUnit = 0;
|
|
77
|
-
this._errorStack = [];
|
|
78
|
-
this._maxTextureSize = 0;
|
|
79
|
-
this._maxTextureLevel = 0;
|
|
80
|
-
this._maxCubeMapSize = 0;
|
|
81
|
-
this._maxCubeMapLevel = 0;
|
|
82
|
-
this._unpackAlignment = 4;
|
|
83
|
-
this._packAlignment = 4;
|
|
84
|
-
this._unpackFlipY = false;
|
|
85
|
-
this._unpackPremultAlpha = false;
|
|
86
|
-
this._viewport = new Int32Array([
|
|
87
|
-
0,
|
|
88
|
-
0,
|
|
89
|
-
0,
|
|
90
|
-
0
|
|
91
|
-
]);
|
|
92
|
-
this._scissorBox = new Int32Array([
|
|
93
|
-
0,
|
|
94
|
-
0,
|
|
95
|
-
0,
|
|
96
|
-
0
|
|
97
|
-
]);
|
|
98
|
-
this._gtkFboId = 0;
|
|
99
|
-
this._textureUnits = [];
|
|
100
|
-
this._drawingBuffer = null;
|
|
101
|
-
this.canvas = canvas;
|
|
102
|
-
this._contextAttributes = new WebGLContextAttributes(flag(options, "alpha", true), flag(options, "depth", true), flag(options, "stencil", false), false, flag(options, "premultipliedAlpha", true), flag(options, "preserveDrawingBuffer", false), flag(options, "preferLowPowerToHighPerformance", false), flag(options, "failIfMajorPerformanceCaveat", false));
|
|
103
|
-
this._contextAttributes.premultipliedAlpha = this._contextAttributes.premultipliedAlpha && this._contextAttributes.alpha;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Must be called by subclass constructors AFTER setting up the native GL object
|
|
107
|
-
* so that `this._gl` is available for GL-dependent initialization.
|
|
108
|
-
*/
|
|
109
|
-
_init() {
|
|
110
|
-
const gtkFboVariant = this._gl.getParameterx(36006);
|
|
111
|
-
this._gtkFboId = gtkFboVariant?.deepUnpack() | 0;
|
|
112
|
-
this._initGLConstants();
|
|
113
|
-
this.DEFAULT_ATTACHMENTS = [
|
|
114
|
-
this.COLOR_ATTACHMENT0,
|
|
115
|
-
this.DEPTH_ATTACHMENT,
|
|
116
|
-
this.STENCIL_ATTACHMENT,
|
|
117
|
-
this.DEPTH_STENCIL_ATTACHMENT
|
|
118
|
-
];
|
|
119
|
-
this.DEFAULT_COLOR_ATTACHMENTS = [this.COLOR_ATTACHMENT0];
|
|
120
|
-
const options = this._contextAttributes;
|
|
121
|
-
const width = this.drawingBufferWidth || options.width || 0;
|
|
122
|
-
const height = this.drawingBufferHeight || options.height || 0;
|
|
123
|
-
this._ = CONTEXT_COUNTER++;
|
|
124
|
-
const numTextures = this.getParameter(this.MAX_COMBINED_TEXTURE_IMAGE_UNITS);
|
|
125
|
-
this._textureUnits = new Array(numTextures);
|
|
126
|
-
for (let i = 0; i < numTextures; ++i) {
|
|
127
|
-
this._textureUnits[i] = new WebGLTextureUnit(this, i);
|
|
128
|
-
}
|
|
129
|
-
this.activeTexture(this.TEXTURE0);
|
|
130
|
-
this._defaultVertexObjectState = new WebGLVertexArrayObjectState(this);
|
|
131
|
-
this._vertexObjectState = this._defaultVertexObjectState;
|
|
132
|
-
this._vertexGlobalState = new WebGLVertexArrayGlobalState(this);
|
|
133
|
-
this._maxTextureSize = this.getParameter(this.MAX_TEXTURE_SIZE);
|
|
134
|
-
this._maxTextureLevel = bits.log2(bits.nextPow2(this._maxTextureSize));
|
|
135
|
-
this._maxCubeMapSize = this.getParameter(this.MAX_CUBE_MAP_TEXTURE_SIZE);
|
|
136
|
-
this._maxCubeMapLevel = bits.log2(bits.nextPow2(this._maxCubeMapSize));
|
|
137
|
-
this._unpackAlignment = 4;
|
|
138
|
-
this._packAlignment = 4;
|
|
139
|
-
this._unpackFlipY = false;
|
|
140
|
-
this._unpackPremultAlpha = false;
|
|
141
|
-
this.bindBuffer(this.ARRAY_BUFFER, null);
|
|
142
|
-
this.bindBuffer(this.ELEMENT_ARRAY_BUFFER, null);
|
|
143
|
-
this.bindFramebuffer(this.FRAMEBUFFER, null);
|
|
144
|
-
this.bindRenderbuffer(this.RENDERBUFFER, null);
|
|
145
|
-
this.viewport(0, 0, width, height);
|
|
146
|
-
this.scissor(0, 0, width, height);
|
|
147
|
-
this.clearDepth(1);
|
|
148
|
-
this.clearColor(0, 0, 0, 0);
|
|
149
|
-
this.clearStencil(0);
|
|
150
|
-
this.clear(this.COLOR_BUFFER_BIT | this.DEPTH_BUFFER_BIT | this.STENCIL_BUFFER_BIT);
|
|
151
|
-
this.disable(this.DEPTH_TEST);
|
|
152
|
-
this.disable(this.STENCIL_TEST);
|
|
153
|
-
this.disable(this.BLEND);
|
|
154
|
-
this.disable(this.CULL_FACE);
|
|
155
|
-
this.disable(this.POLYGON_OFFSET_FILL);
|
|
156
|
-
this.disable(this.SCISSOR_TEST);
|
|
157
|
-
this._gl.colorMask(true, true, true, true);
|
|
158
|
-
}
|
|
159
|
-
_initGLConstants() {
|
|
160
|
-
const giBaseClass = new Gwebgl.WebGLRenderingContextBase();
|
|
161
|
-
const hash = giBaseClass.get_webgl_constants();
|
|
162
|
-
for (const [k, v] of Object.entries(hash)) {
|
|
163
|
-
Object.defineProperty(this, k, { value: v });
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
_getGlslVersion(es) {
|
|
167
|
-
return es ? "100" : "120";
|
|
168
|
-
}
|
|
169
|
-
_checkDimensions(target, width, height, level) {
|
|
170
|
-
if (level < 0 || width < 0 || height < 0) {
|
|
171
|
-
this.setError(this.INVALID_VALUE);
|
|
172
|
-
return false;
|
|
173
|
-
}
|
|
174
|
-
if (target === this.TEXTURE_2D) {
|
|
175
|
-
if (width > this._maxTextureSize || height > this._maxTextureSize || level > this._maxTextureLevel) {
|
|
176
|
-
this.setError(this.INVALID_VALUE);
|
|
177
|
-
return false;
|
|
178
|
-
}
|
|
179
|
-
} else if (this._validCubeTarget(target)) {
|
|
180
|
-
if (width > this._maxCubeMapSize || height > this._maxCubeMapSize || level > this._maxCubeMapLevel) {
|
|
181
|
-
this.setError(this.INVALID_VALUE);
|
|
182
|
-
return false;
|
|
183
|
-
}
|
|
184
|
-
} else {
|
|
185
|
-
this.setError(this.INVALID_ENUM);
|
|
186
|
-
return false;
|
|
187
|
-
}
|
|
188
|
-
return true;
|
|
189
|
-
}
|
|
190
|
-
_checkLocation(location) {
|
|
191
|
-
if (!(location instanceof WebGLUniformLocation)) {
|
|
192
|
-
this.setError(this.INVALID_VALUE);
|
|
193
|
-
return false;
|
|
194
|
-
} else if (location._program._ctx !== this || location._linkCount !== location._program._linkCount) {
|
|
195
|
-
this.setError(this.INVALID_OPERATION);
|
|
196
|
-
return false;
|
|
197
|
-
}
|
|
198
|
-
return true;
|
|
199
|
-
}
|
|
200
|
-
_checkLocationActive(location) {
|
|
201
|
-
if (!location) {
|
|
202
|
-
return false;
|
|
203
|
-
} else if (!this._checkLocation(location)) {
|
|
204
|
-
return false;
|
|
205
|
-
} else if (location._program !== this._activeProgram) {
|
|
206
|
-
this.setError(this.INVALID_OPERATION);
|
|
207
|
-
return false;
|
|
208
|
-
}
|
|
209
|
-
return true;
|
|
210
|
-
}
|
|
211
|
-
_checkOwns(object) {
|
|
212
|
-
return typeof object === "object" && object._ctx === this;
|
|
213
|
-
}
|
|
214
|
-
_checkShaderSource(shader) {
|
|
215
|
-
const source = shader._source;
|
|
216
|
-
const tokens = tokenize(source);
|
|
217
|
-
let errorStatus = false;
|
|
218
|
-
const errorLog = [];
|
|
219
|
-
for (let i = 0; i < tokens.length; ++i) {
|
|
220
|
-
const tok = tokens[i];
|
|
221
|
-
if (!tok) continue;
|
|
222
|
-
switch (tok.type) {
|
|
223
|
-
case "ident":
|
|
224
|
-
if (!this._validGLSLIdentifier(tok.data)) {
|
|
225
|
-
errorStatus = true;
|
|
226
|
-
errorLog.push(tok.line + ":" + tok.column + " invalid identifier - " + tok.data);
|
|
227
|
-
}
|
|
228
|
-
break;
|
|
229
|
-
case "preprocessor": {
|
|
230
|
-
const match = tok.data.match(/^\s*#\s*(.*)$/);
|
|
231
|
-
if (!match || match?.length < 2) {
|
|
232
|
-
break;
|
|
233
|
-
}
|
|
234
|
-
const bodyToks = tokenize(match[1]);
|
|
235
|
-
for (let j = 0; j < bodyToks.length; ++j) {
|
|
236
|
-
const btok = bodyToks[j];
|
|
237
|
-
if (btok.type === "ident" || btok.type === undefined) {
|
|
238
|
-
if (!this._validGLSLIdentifier(btok.data)) {
|
|
239
|
-
errorStatus = true;
|
|
240
|
-
errorLog.push(tok.line + ":" + btok.column + " invalid identifier - " + btok.data);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
break;
|
|
245
|
-
}
|
|
246
|
-
case "keyword":
|
|
247
|
-
switch (tok.data) {
|
|
248
|
-
case "do":
|
|
249
|
-
errorStatus = true;
|
|
250
|
-
errorLog.push(tok.line + ":" + tok.column + " do not supported");
|
|
251
|
-
break;
|
|
252
|
-
}
|
|
253
|
-
break;
|
|
254
|
-
case "builtin": switch (tok.data) {
|
|
255
|
-
case "dFdx":
|
|
256
|
-
case "dFdy":
|
|
257
|
-
case "fwidth":
|
|
258
|
-
if (!this._extensions.oes_standard_derivatives && this._getGlslVersion(true) === "100") {
|
|
259
|
-
errorStatus = true;
|
|
260
|
-
errorLog.push(tok.line + ":" + tok.column + " " + tok.data + " not supported");
|
|
261
|
-
}
|
|
262
|
-
break;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
if (errorStatus) {
|
|
267
|
-
shader._compileInfo = errorLog.join("\n");
|
|
268
|
-
}
|
|
269
|
-
return !errorStatus;
|
|
270
|
-
}
|
|
271
|
-
_checkStencilState() {
|
|
272
|
-
if (!this._checkStencil) {
|
|
273
|
-
return this._stencilState;
|
|
274
|
-
}
|
|
275
|
-
this._checkStencil = false;
|
|
276
|
-
this._stencilState = true;
|
|
277
|
-
if (this.getParameter(this.STENCIL_WRITEMASK) !== this.getParameter(this.STENCIL_BACK_WRITEMASK) || this.getParameter(this.STENCIL_VALUE_MASK) !== this.getParameter(this.STENCIL_BACK_VALUE_MASK) || this.getParameter(this.STENCIL_REF) !== this.getParameter(this.STENCIL_BACK_REF)) {
|
|
278
|
-
this.setError(this.INVALID_OPERATION);
|
|
279
|
-
this._stencilState = false;
|
|
280
|
-
}
|
|
281
|
-
return this._stencilState;
|
|
282
|
-
}
|
|
283
|
-
_checkTextureTarget(target) {
|
|
284
|
-
const unit = this._getActiveTextureUnit();
|
|
285
|
-
let tex = null;
|
|
286
|
-
if (target === this.TEXTURE_2D) {
|
|
287
|
-
tex = unit._bind2D;
|
|
288
|
-
} else if (target === this.TEXTURE_CUBE_MAP) {
|
|
289
|
-
tex = unit._bindCube;
|
|
290
|
-
} else {
|
|
291
|
-
this.setError(this.INVALID_ENUM);
|
|
292
|
-
return false;
|
|
293
|
-
}
|
|
294
|
-
if (!tex) {
|
|
295
|
-
this.setError(this.INVALID_OPERATION);
|
|
296
|
-
return false;
|
|
297
|
-
}
|
|
298
|
-
return true;
|
|
299
|
-
}
|
|
300
|
-
_checkWrapper(object, Wrapper) {
|
|
301
|
-
if (!this._checkValid(object, Wrapper)) {
|
|
302
|
-
this.setError(this.INVALID_VALUE);
|
|
303
|
-
return false;
|
|
304
|
-
} else if (!this._checkOwns(object)) {
|
|
305
|
-
this.setError(this.INVALID_OPERATION);
|
|
306
|
-
return false;
|
|
307
|
-
}
|
|
308
|
-
return true;
|
|
309
|
-
}
|
|
310
|
-
_checkValid(object, Type) {
|
|
311
|
-
return object instanceof Type && object._ !== 0;
|
|
312
|
-
}
|
|
313
|
-
_checkVertexAttribState(maxIndex) {
|
|
314
|
-
const program = this._activeProgram;
|
|
315
|
-
if (!program) {
|
|
316
|
-
this.setError(this.INVALID_OPERATION);
|
|
317
|
-
return false;
|
|
318
|
-
}
|
|
319
|
-
const attribs = this._vertexObjectState._attribs;
|
|
320
|
-
for (let i = 0; i < attribs.length; ++i) {
|
|
321
|
-
const attrib = attribs[i];
|
|
322
|
-
if (attrib._isPointer) {
|
|
323
|
-
const buffer = attrib._pointerBuffer;
|
|
324
|
-
if (!buffer) {
|
|
325
|
-
this.setError(this.INVALID_OPERATION);
|
|
326
|
-
return false;
|
|
327
|
-
}
|
|
328
|
-
if (program._attributes.indexOf(i) >= 0) {
|
|
329
|
-
let maxByte = 0;
|
|
330
|
-
if (attrib._divisor) {
|
|
331
|
-
maxByte = attrib._pointerSize + attrib._pointerOffset;
|
|
332
|
-
} else {
|
|
333
|
-
maxByte = attrib._pointerStride * maxIndex + attrib._pointerSize + attrib._pointerOffset;
|
|
334
|
-
}
|
|
335
|
-
if (maxByte > buffer._size) {
|
|
336
|
-
this.setError(this.INVALID_OPERATION);
|
|
337
|
-
return false;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
return true;
|
|
343
|
-
}
|
|
344
|
-
_checkVertexIndex(index) {
|
|
345
|
-
if (index < 0 || index >= this._vertexObjectState._attribs.length) {
|
|
346
|
-
this.setError(this.INVALID_VALUE);
|
|
347
|
-
return false;
|
|
348
|
-
}
|
|
349
|
-
return true;
|
|
350
|
-
}
|
|
351
|
-
_computePixelSize(type, internalFormat) {
|
|
352
|
-
const pixelSize = formatSize(this, internalFormat);
|
|
353
|
-
if (pixelSize === 0) {
|
|
354
|
-
this.setError(this.INVALID_ENUM);
|
|
355
|
-
return 0;
|
|
356
|
-
}
|
|
357
|
-
switch (type) {
|
|
358
|
-
case this.UNSIGNED_BYTE: return pixelSize;
|
|
359
|
-
case this.UNSIGNED_SHORT_5_6_5:
|
|
360
|
-
if (internalFormat !== this.RGB) {
|
|
361
|
-
this.setError(this.INVALID_OPERATION);
|
|
362
|
-
break;
|
|
363
|
-
}
|
|
364
|
-
return 2;
|
|
365
|
-
case this.UNSIGNED_SHORT_4_4_4_4:
|
|
366
|
-
case this.UNSIGNED_SHORT_5_5_5_1:
|
|
367
|
-
if (internalFormat !== this.RGBA) {
|
|
368
|
-
this.setError(this.INVALID_OPERATION);
|
|
369
|
-
break;
|
|
370
|
-
}
|
|
371
|
-
return 2;
|
|
372
|
-
case this.FLOAT: return 1;
|
|
373
|
-
}
|
|
374
|
-
this.setError(this.INVALID_ENUM);
|
|
375
|
-
return 0;
|
|
376
|
-
}
|
|
377
|
-
_computeRowStride(width, pixelSize) {
|
|
378
|
-
let rowStride = width * pixelSize;
|
|
379
|
-
if (rowStride % this._unpackAlignment) {
|
|
380
|
-
rowStride += this._unpackAlignment - rowStride % this._unpackAlignment;
|
|
381
|
-
}
|
|
382
|
-
return rowStride;
|
|
383
|
-
}
|
|
384
|
-
_fixupLink(program) {
|
|
385
|
-
if (!this._gl.getProgramParameter(program._, this.LINK_STATUS)) {
|
|
386
|
-
program._linkInfoLog = this._gl.getProgramInfoLog(program._);
|
|
387
|
-
return false;
|
|
388
|
-
}
|
|
389
|
-
const numAttribs = this.getProgramParameter(program, this.ACTIVE_ATTRIBUTES);
|
|
390
|
-
const names = new Array(numAttribs);
|
|
391
|
-
program._attributes.length = numAttribs;
|
|
392
|
-
for (let i = 0; i < numAttribs; ++i) {
|
|
393
|
-
names[i] = this.getActiveAttrib(program, i)?.name;
|
|
394
|
-
program._attributes[i] = this.getAttribLocation(program, names[i]) | 0;
|
|
395
|
-
}
|
|
396
|
-
for (let i = 0; i < names.length; ++i) {
|
|
397
|
-
if (names[i].length > MAX_ATTRIBUTE_LENGTH) {
|
|
398
|
-
program._linkInfoLog = "attribute " + names[i] + " is too long";
|
|
399
|
-
return false;
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
for (let i = 0; i < numAttribs; ++i) {
|
|
403
|
-
if (program._attributes[i] < 0) continue;
|
|
404
|
-
this._gl.bindAttribLocation(program._ | 0, program._attributes[i], names[i]);
|
|
405
|
-
}
|
|
406
|
-
this._gl.linkProgram(program._ | 0);
|
|
407
|
-
if (!this._gl.getProgramParameter(program._ | 0, this.LINK_STATUS)) {
|
|
408
|
-
program._linkInfoLog = this._gl.getProgramInfoLog(program._);
|
|
409
|
-
return false;
|
|
410
|
-
}
|
|
411
|
-
const numUniforms = this.getProgramParameter(program, this.ACTIVE_UNIFORMS);
|
|
412
|
-
program._uniforms.length = numUniforms;
|
|
413
|
-
for (let i = 0; i < numUniforms; ++i) {
|
|
414
|
-
const info = this.getActiveUniform(program, i);
|
|
415
|
-
if (info) program._uniforms[i] = info;
|
|
416
|
-
}
|
|
417
|
-
for (let i = 0; i < program._uniforms.length; ++i) {
|
|
418
|
-
if (program._uniforms[i].name.length > MAX_UNIFORM_LENGTH) {
|
|
419
|
-
program._linkInfoLog = "uniform " + program._uniforms[i].name + " is too long";
|
|
420
|
-
return false;
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
program._linkInfoLog = "";
|
|
424
|
-
return true;
|
|
425
|
-
}
|
|
426
|
-
_framebufferOk() {
|
|
427
|
-
const framebuffer = this._activeFramebuffer;
|
|
428
|
-
if (framebuffer && this._preCheckFramebufferStatus(framebuffer) !== this.FRAMEBUFFER_COMPLETE) {
|
|
429
|
-
this.setError(this.INVALID_FRAMEBUFFER_OPERATION);
|
|
430
|
-
return false;
|
|
431
|
-
}
|
|
432
|
-
return true;
|
|
433
|
-
}
|
|
434
|
-
_getActiveBuffer(target) {
|
|
435
|
-
if (target === this.ARRAY_BUFFER) {
|
|
436
|
-
return this._vertexGlobalState._arrayBufferBinding;
|
|
437
|
-
} else if (target === this.ELEMENT_ARRAY_BUFFER) {
|
|
438
|
-
return this._vertexObjectState._elementArrayBufferBinding;
|
|
439
|
-
}
|
|
440
|
-
return null;
|
|
441
|
-
}
|
|
442
|
-
_getActiveTextureUnit() {
|
|
443
|
-
return this._textureUnits[this._activeTextureUnit];
|
|
444
|
-
}
|
|
445
|
-
_getActiveTexture(target) {
|
|
446
|
-
const activeUnit = this._getActiveTextureUnit();
|
|
447
|
-
if (target === this.TEXTURE_2D) {
|
|
448
|
-
return activeUnit._bind2D;
|
|
449
|
-
} else if (target === this.TEXTURE_CUBE_MAP) {
|
|
450
|
-
return activeUnit._bindCube;
|
|
451
|
-
}
|
|
452
|
-
return null;
|
|
453
|
-
}
|
|
454
|
-
_getAttachments() {
|
|
455
|
-
return this._extensions.webgl_draw_buffers ? this._extensions.webgl_draw_buffers._ALL_ATTACHMENTS : this.DEFAULT_ATTACHMENTS;
|
|
456
|
-
}
|
|
457
|
-
_getColorAttachments() {
|
|
458
|
-
return this._extensions.webgl_draw_buffers ? this._extensions.webgl_draw_buffers._ALL_COLOR_ATTACHMENTS : this.DEFAULT_COLOR_ATTACHMENTS;
|
|
459
|
-
}
|
|
460
|
-
_getParameterDirect(pname) {
|
|
461
|
-
return this._gl.getParameterx(pname)?.deepUnpack();
|
|
462
|
-
}
|
|
463
|
-
_getTexImage(target) {
|
|
464
|
-
const unit = this._getActiveTextureUnit();
|
|
465
|
-
if (target === this.TEXTURE_2D) {
|
|
466
|
-
return unit._bind2D;
|
|
467
|
-
} else if (validCubeTarget(this, target)) {
|
|
468
|
-
return unit._bindCube;
|
|
469
|
-
}
|
|
470
|
-
this.setError(this.INVALID_ENUM);
|
|
471
|
-
return null;
|
|
472
|
-
}
|
|
473
|
-
_preCheckFramebufferStatus(framebuffer) {
|
|
474
|
-
const attachments = framebuffer._attachments;
|
|
475
|
-
const width = [];
|
|
476
|
-
const height = [];
|
|
477
|
-
const depthAttachment = attachments[this.DEPTH_ATTACHMENT];
|
|
478
|
-
const depthStencilAttachment = attachments[this.DEPTH_STENCIL_ATTACHMENT];
|
|
479
|
-
const stencilAttachment = attachments[this.STENCIL_ATTACHMENT];
|
|
480
|
-
if (depthStencilAttachment && (stencilAttachment || depthAttachment) || stencilAttachment && depthAttachment) {
|
|
481
|
-
return this.FRAMEBUFFER_UNSUPPORTED;
|
|
482
|
-
}
|
|
483
|
-
const colorAttachments = this._getColorAttachments();
|
|
484
|
-
let colorAttachmentCount = 0;
|
|
485
|
-
for (const attachmentEnum in attachments) {
|
|
486
|
-
if (attachments[attachmentEnum] && colorAttachments.indexOf(Number(attachmentEnum)) !== -1) {
|
|
487
|
-
colorAttachmentCount++;
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
if (colorAttachmentCount === 0) {
|
|
491
|
-
return this.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;
|
|
492
|
-
}
|
|
493
|
-
if (depthStencilAttachment instanceof WebGLTexture) {
|
|
494
|
-
return this.FRAMEBUFFER_UNSUPPORTED;
|
|
495
|
-
} else if (depthStencilAttachment instanceof WebGLRenderbuffer) {
|
|
496
|
-
if (depthStencilAttachment._format !== this.DEPTH_STENCIL) {
|
|
497
|
-
return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
|
|
498
|
-
}
|
|
499
|
-
width.push(depthStencilAttachment._width);
|
|
500
|
-
height.push(depthStencilAttachment._height);
|
|
501
|
-
}
|
|
502
|
-
if (depthAttachment instanceof WebGLTexture) {
|
|
503
|
-
return this.FRAMEBUFFER_UNSUPPORTED;
|
|
504
|
-
} else if (depthAttachment instanceof WebGLRenderbuffer) {
|
|
505
|
-
if (depthAttachment._format !== this.DEPTH_COMPONENT16) {
|
|
506
|
-
return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
|
|
507
|
-
}
|
|
508
|
-
width.push(depthAttachment._width);
|
|
509
|
-
height.push(depthAttachment._height);
|
|
510
|
-
}
|
|
511
|
-
if (stencilAttachment instanceof WebGLTexture) {
|
|
512
|
-
return this.FRAMEBUFFER_UNSUPPORTED;
|
|
513
|
-
} else if (stencilAttachment instanceof WebGLRenderbuffer) {
|
|
514
|
-
if (stencilAttachment._format !== this.STENCIL_INDEX8) {
|
|
515
|
-
return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
|
|
516
|
-
}
|
|
517
|
-
width.push(stencilAttachment._width);
|
|
518
|
-
height.push(stencilAttachment._height);
|
|
519
|
-
}
|
|
520
|
-
let colorAttached = false;
|
|
521
|
-
for (let i = 0; i < colorAttachments.length; ++i) {
|
|
522
|
-
const colorAttachment = attachments[colorAttachments[i]];
|
|
523
|
-
if (colorAttachment instanceof WebGLTexture) {
|
|
524
|
-
if (colorAttachment._format !== this.RGBA || !(colorAttachment._type === this.UNSIGNED_BYTE || colorAttachment._type === this.FLOAT)) {
|
|
525
|
-
return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
|
|
526
|
-
}
|
|
527
|
-
colorAttached = true;
|
|
528
|
-
const level = framebuffer._attachmentLevel[this.COLOR_ATTACHMENT0];
|
|
529
|
-
if (level === null) throw new TypeError("level is null!");
|
|
530
|
-
width.push(colorAttachment._levelWidth[level]);
|
|
531
|
-
height.push(colorAttachment._levelHeight[level]);
|
|
532
|
-
} else if (colorAttachment instanceof WebGLRenderbuffer) {
|
|
533
|
-
const format = colorAttachment._format;
|
|
534
|
-
if (format !== this.RGBA4 && format !== this.RGB565 && format !== this.RGB5_A1) {
|
|
535
|
-
return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
|
|
536
|
-
}
|
|
537
|
-
colorAttached = true;
|
|
538
|
-
width.push(colorAttachment._width);
|
|
539
|
-
height.push(colorAttachment._height);
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
if (!colorAttached && !stencilAttachment && !depthAttachment && !depthStencilAttachment) {
|
|
543
|
-
return this.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;
|
|
544
|
-
}
|
|
545
|
-
if (width.length <= 0 || height.length <= 0) {
|
|
546
|
-
return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
|
|
547
|
-
}
|
|
548
|
-
for (let i = 1; i < width.length; ++i) {
|
|
549
|
-
if (width[i - 1] !== width[i] || height[i - 1] !== height[i]) {
|
|
550
|
-
return this.FRAMEBUFFER_INCOMPLETE_DIMENSIONS;
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
if (width[0] === 0 || height[0] === 0) {
|
|
554
|
-
return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
|
|
555
|
-
}
|
|
556
|
-
framebuffer._width = width[0];
|
|
557
|
-
framebuffer._height = height[0];
|
|
558
|
-
return this.FRAMEBUFFER_COMPLETE;
|
|
559
|
-
}
|
|
560
|
-
_isConstantBlendFunc(factor) {
|
|
561
|
-
return factor === this.CONSTANT_COLOR || factor === this.ONE_MINUS_CONSTANT_COLOR || factor === this.CONSTANT_ALPHA || factor === this.ONE_MINUS_CONSTANT_ALPHA;
|
|
562
|
-
}
|
|
563
|
-
_isObject(object, method, Wrapper) {
|
|
564
|
-
if (!(object === null || object === undefined) && !(object instanceof Wrapper)) {
|
|
565
|
-
throw new TypeError(method + "(" + Wrapper.name + ")");
|
|
566
|
-
}
|
|
567
|
-
if (this._checkValid(object, Wrapper) && this._checkOwns(object)) {
|
|
568
|
-
return true;
|
|
569
|
-
}
|
|
570
|
-
return false;
|
|
571
|
-
}
|
|
572
|
-
_resizeDrawingBuffer(width, height) {
|
|
573
|
-
const prevFramebuffer = this._activeFramebuffer;
|
|
574
|
-
const prevTexture = this._getActiveTexture(this.TEXTURE_2D);
|
|
575
|
-
const prevRenderbuffer = this._activeRenderbuffer;
|
|
576
|
-
const contextAttributes = this._contextAttributes;
|
|
577
|
-
const drawingBuffer = this._drawingBuffer;
|
|
578
|
-
if (drawingBuffer?._framebuffer) {
|
|
579
|
-
this._gl.bindFramebuffer(this.FRAMEBUFFER, drawingBuffer?._framebuffer);
|
|
580
|
-
}
|
|
581
|
-
const attachments = this._getAttachments();
|
|
582
|
-
for (let i = 0; i < attachments.length; ++i) {
|
|
583
|
-
this._gl.framebufferTexture2D(this.FRAMEBUFFER, attachments[i], this.TEXTURE_2D, 0, 0);
|
|
584
|
-
}
|
|
585
|
-
if (drawingBuffer?._color) {
|
|
586
|
-
this._gl.bindTexture(this.TEXTURE_2D, drawingBuffer?._color);
|
|
587
|
-
}
|
|
588
|
-
const colorFormat = contextAttributes.alpha ? this.RGBA : this.RGB;
|
|
589
|
-
this._gl.texImage2D(this.TEXTURE_2D, 0, colorFormat, width, height, 0, colorFormat, this.UNSIGNED_BYTE, Uint8ArrayToVariant(null));
|
|
590
|
-
this._gl.texParameteri(this.TEXTURE_2D, this.TEXTURE_MIN_FILTER, this.NEAREST);
|
|
591
|
-
this._gl.texParameteri(this.TEXTURE_2D, this.TEXTURE_MAG_FILTER, this.NEAREST);
|
|
592
|
-
if (drawingBuffer?._color) {
|
|
593
|
-
this._gl.framebufferTexture2D(this.FRAMEBUFFER, this.COLOR_ATTACHMENT0, this.TEXTURE_2D, drawingBuffer?._color, 0);
|
|
594
|
-
}
|
|
595
|
-
let storage = 0;
|
|
596
|
-
let attachment = 0;
|
|
597
|
-
if (contextAttributes.depth && contextAttributes.stencil) {
|
|
598
|
-
storage = this.DEPTH_STENCIL;
|
|
599
|
-
attachment = this.DEPTH_STENCIL_ATTACHMENT;
|
|
600
|
-
} else if (contextAttributes.depth) {
|
|
601
|
-
storage = 33191;
|
|
602
|
-
attachment = this.DEPTH_ATTACHMENT;
|
|
603
|
-
} else if (contextAttributes.stencil) {
|
|
604
|
-
storage = this.STENCIL_INDEX8;
|
|
605
|
-
attachment = this.STENCIL_ATTACHMENT;
|
|
606
|
-
}
|
|
607
|
-
if (storage) {
|
|
608
|
-
if (drawingBuffer?._depthStencil) {
|
|
609
|
-
this._gl.bindRenderbuffer(this.RENDERBUFFER, drawingBuffer?._depthStencil);
|
|
610
|
-
}
|
|
611
|
-
this._gl.renderbufferStorage(this.RENDERBUFFER, storage, width, height);
|
|
612
|
-
if (drawingBuffer?._depthStencil) {
|
|
613
|
-
this._gl.framebufferRenderbuffer(this.FRAMEBUFFER, attachment, this.RENDERBUFFER, drawingBuffer?._depthStencil);
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
this.bindFramebuffer(this.FRAMEBUFFER, prevFramebuffer);
|
|
617
|
-
this.bindTexture(this.TEXTURE_2D, prevTexture);
|
|
618
|
-
this.bindRenderbuffer(this.RENDERBUFFER, prevRenderbuffer);
|
|
619
|
-
}
|
|
620
|
-
_restoreError(lastError) {
|
|
621
|
-
const topError = this._errorStack.pop();
|
|
622
|
-
if (topError === this.NO_ERROR) {
|
|
623
|
-
this.setError(lastError);
|
|
624
|
-
} else if (topError) {
|
|
625
|
-
this.setError(topError);
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
_saveError() {
|
|
629
|
-
this._errorStack.push(this.getError());
|
|
630
|
-
}
|
|
631
|
-
_switchActiveProgram(active) {
|
|
632
|
-
if (active) {
|
|
633
|
-
active._refCount -= 1;
|
|
634
|
-
active._checkDelete();
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
_tryDetachFramebuffer(framebuffer, renderbuffer) {
|
|
638
|
-
if (framebuffer && framebuffer._linked(renderbuffer)) {
|
|
639
|
-
const attachments = this._getAttachments();
|
|
640
|
-
const framebufferAttachments = Object.keys(framebuffer._attachments);
|
|
641
|
-
for (let i = 0; i < framebufferAttachments.length; ++i) {
|
|
642
|
-
if (framebuffer._attachments[attachments[i]] === renderbuffer) {
|
|
643
|
-
this.framebufferTexture2D(this.FRAMEBUFFER, attachments[i] | 0, this.TEXTURE_2D, null);
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
_updateFramebufferAttachments(framebuffer) {
|
|
649
|
-
if (!framebuffer) {
|
|
650
|
-
return;
|
|
651
|
-
}
|
|
652
|
-
const prevStatus = framebuffer._status;
|
|
653
|
-
const attachments = this._getAttachments();
|
|
654
|
-
framebuffer._status = this._preCheckFramebufferStatus(framebuffer);
|
|
655
|
-
if (framebuffer._status !== this.FRAMEBUFFER_COMPLETE) {
|
|
656
|
-
if (prevStatus === this.FRAMEBUFFER_COMPLETE) {
|
|
657
|
-
for (let i = 0; i < attachments.length; ++i) {
|
|
658
|
-
const attachmentEnum = attachments[i];
|
|
659
|
-
this._gl.framebufferTexture2D(this.FRAMEBUFFER, attachmentEnum, framebuffer._attachmentFace[attachmentEnum] || 0, 0, framebuffer._attachmentLevel[attachmentEnum] || 0);
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
return;
|
|
663
|
-
}
|
|
664
|
-
for (let i = 0; i < attachments.length; ++i) {
|
|
665
|
-
const attachmentEnum = attachments[i];
|
|
666
|
-
this._gl.framebufferTexture2D(this.FRAMEBUFFER, attachmentEnum, framebuffer._attachmentFace[attachmentEnum] || 0, 0, framebuffer._attachmentLevel[attachmentEnum] || 0);
|
|
667
|
-
}
|
|
668
|
-
for (let i = 0; i < attachments.length; ++i) {
|
|
669
|
-
const attachmentEnum = attachments[i];
|
|
670
|
-
const attachment = framebuffer._attachments[attachmentEnum];
|
|
671
|
-
if (attachment instanceof WebGLTexture) {
|
|
672
|
-
this._gl.framebufferTexture2D(this.FRAMEBUFFER, attachmentEnum, framebuffer._attachmentFace[attachmentEnum] || 0, attachment._ | 0, framebuffer._attachmentLevel[attachmentEnum] || 0);
|
|
673
|
-
} else if (attachment instanceof WebGLRenderbuffer) {
|
|
674
|
-
this._gl.framebufferRenderbuffer(this.FRAMEBUFFER, attachmentEnum, this.RENDERBUFFER, attachment._ | 0);
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
_validBlendFunc(factor) {
|
|
679
|
-
return factor === this.ZERO || factor === this.ONE || factor === this.SRC_COLOR || factor === this.ONE_MINUS_SRC_COLOR || factor === this.DST_COLOR || factor === this.ONE_MINUS_DST_COLOR || factor === this.SRC_ALPHA || factor === this.ONE_MINUS_SRC_ALPHA || factor === this.DST_ALPHA || factor === this.ONE_MINUS_DST_ALPHA || factor === this.SRC_ALPHA_SATURATE || factor === this.CONSTANT_COLOR || factor === this.ONE_MINUS_CONSTANT_COLOR || factor === this.CONSTANT_ALPHA || factor === this.ONE_MINUS_CONSTANT_ALPHA;
|
|
680
|
-
}
|
|
681
|
-
_validBlendMode(mode) {
|
|
682
|
-
return mode === this.FUNC_ADD || mode === this.FUNC_SUBTRACT || mode === this.FUNC_REVERSE_SUBTRACT || this._extensions.ext_blend_minmax && (mode === this._extensions.ext_blend_minmax.MIN_EXT || mode === this._extensions.ext_blend_minmax.MAX_EXT);
|
|
683
|
-
}
|
|
684
|
-
_validCubeTarget(target) {
|
|
685
|
-
return target === this.TEXTURE_CUBE_MAP_POSITIVE_X || target === this.TEXTURE_CUBE_MAP_NEGATIVE_X || target === this.TEXTURE_CUBE_MAP_POSITIVE_Y || target === this.TEXTURE_CUBE_MAP_NEGATIVE_Y || target === this.TEXTURE_CUBE_MAP_POSITIVE_Z || target === this.TEXTURE_CUBE_MAP_NEGATIVE_Z;
|
|
686
|
-
}
|
|
687
|
-
_validFramebufferAttachment(attachment) {
|
|
688
|
-
switch (attachment) {
|
|
689
|
-
case this.DEPTH_ATTACHMENT:
|
|
690
|
-
case this.STENCIL_ATTACHMENT:
|
|
691
|
-
case this.DEPTH_STENCIL_ATTACHMENT:
|
|
692
|
-
case this.COLOR_ATTACHMENT0: return true;
|
|
693
|
-
}
|
|
694
|
-
if (this._extensions.webgl_draw_buffers) {
|
|
695
|
-
const { webgl_draw_buffers } = this._extensions;
|
|
696
|
-
return attachment < webgl_draw_buffers.COLOR_ATTACHMENT0_WEBGL + webgl_draw_buffers._maxDrawBuffers;
|
|
697
|
-
}
|
|
698
|
-
return false;
|
|
699
|
-
}
|
|
700
|
-
_validGLSLIdentifier(str) {
|
|
701
|
-
return !(str.indexOf("webgl_") === 0 || str.indexOf("_webgl_") === 0 || str.length > 256);
|
|
702
|
-
}
|
|
703
|
-
_validTextureTarget(target) {
|
|
704
|
-
return target === this.TEXTURE_2D || target === this.TEXTURE_CUBE_MAP;
|
|
705
|
-
}
|
|
706
|
-
_verifyTextureCompleteness(target, pname, param) {
|
|
707
|
-
const unit = this._getActiveTextureUnit();
|
|
708
|
-
let texture = null;
|
|
709
|
-
if (target === this.TEXTURE_2D) {
|
|
710
|
-
texture = unit._bind2D;
|
|
711
|
-
} else if (this._validCubeTarget(target)) {
|
|
712
|
-
texture = unit._bindCube;
|
|
713
|
-
}
|
|
714
|
-
if (this._extensions.oes_texture_float && !this._extensions.oes_texture_float_linear && texture && texture._type === this.FLOAT && (pname === this.TEXTURE_MAG_FILTER || pname === this.TEXTURE_MIN_FILTER) && (param === this.LINEAR || param === this.LINEAR_MIPMAP_NEAREST || param === this.NEAREST_MIPMAP_LINEAR || param === this.LINEAR_MIPMAP_LINEAR)) {
|
|
715
|
-
texture._complete = false;
|
|
716
|
-
this.bindTexture(target, texture);
|
|
717
|
-
return;
|
|
718
|
-
}
|
|
719
|
-
if (texture && texture._complete === false) {
|
|
720
|
-
texture._complete = true;
|
|
721
|
-
this.bindTexture(target, texture);
|
|
722
|
-
}
|
|
723
|
-
}
|
|
724
|
-
_wrapShader(_type, source) {
|
|
725
|
-
const hasVersion = source.startsWith("#version") || source.includes("\n#version");
|
|
726
|
-
let preamble = "";
|
|
727
|
-
if (!this._extensions.oes_standard_derivatives && /#ifdef\s+GL_OES_standard_derivatives/.test(source)) {
|
|
728
|
-
preamble += "#undef GL_OES_standard_derivatives\n";
|
|
729
|
-
}
|
|
730
|
-
if (!this._extensions.webgl_draw_buffers && !hasVersion) {
|
|
731
|
-
preamble += "#define gl_MaxDrawBuffers 1\n";
|
|
732
|
-
}
|
|
733
|
-
if (hasVersion) {
|
|
734
|
-
if (preamble) {
|
|
735
|
-
const newline = source.indexOf("\n");
|
|
736
|
-
if (newline !== -1) {
|
|
737
|
-
source = source.slice(0, newline + 1) + preamble + source.slice(newline + 1);
|
|
738
|
-
} else {
|
|
739
|
-
source = source + "\n" + preamble;
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
} else {
|
|
743
|
-
if (this.canvas) {
|
|
744
|
-
const glArea = this.canvas.getGlArea();
|
|
745
|
-
const es = glArea.get_use_es();
|
|
746
|
-
const usesGlsl1Syntax = /\b(attribute|varying)\b/.test(source);
|
|
747
|
-
const version = usesGlsl1Syntax ? es ? "100" : "120" : this._getGlslVersion(es);
|
|
748
|
-
if (version) {
|
|
749
|
-
source = "#version " + version + "\n" + preamble + source;
|
|
750
|
-
} else if (preamble) {
|
|
751
|
-
source = preamble + source;
|
|
752
|
-
}
|
|
753
|
-
} else if (preamble) {
|
|
754
|
-
source = preamble + source;
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
return source;
|
|
758
|
-
}
|
|
759
|
-
_allocateDrawingBuffer(width, height) {
|
|
760
|
-
this._drawingBuffer = new WebGLDrawingBufferWrapper(this._gl.createFramebuffer(), this._gl.createTexture(), this._gl.createRenderbuffer());
|
|
761
|
-
this._resizeDrawingBuffer(width, height);
|
|
762
|
-
}
|
|
763
|
-
/**
|
|
764
|
-
* The `WebGLRenderingContext.getContextAttributes()` method returns a `WebGLContextAttributes` object that contains the actual context parameters.
|
|
765
|
-
* Might return `null`, if the context is lost.
|
|
766
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/getContextAttributes
|
|
767
|
-
* @returns A `WebGLContextAttributes` object that contains the actual context parameters, or `null` if the context is lost.
|
|
768
|
-
*/
|
|
769
|
-
getContextAttributes() {
|
|
770
|
-
return this._contextAttributes;
|
|
771
|
-
}
|
|
772
|
-
getExtension(name) {
|
|
773
|
-
const str = name.toLowerCase();
|
|
774
|
-
if (str in this._extensions) {
|
|
775
|
-
return this._extensions[str];
|
|
776
|
-
}
|
|
777
|
-
const ext = availableExtensions[str] ? availableExtensions[str](this) : null;
|
|
778
|
-
if (ext) {
|
|
779
|
-
this._extensions[str] = ext;
|
|
780
|
-
}
|
|
781
|
-
return ext;
|
|
782
|
-
}
|
|
783
|
-
bufferData(target = 0, dataOrSize, usage = 0) {
|
|
784
|
-
let size = 0;
|
|
785
|
-
let data = null;
|
|
786
|
-
if (typeof dataOrSize === "number") {
|
|
787
|
-
size = dataOrSize;
|
|
788
|
-
} else if (typeof dataOrSize === "object") {
|
|
789
|
-
data = dataOrSize;
|
|
790
|
-
}
|
|
791
|
-
if (usage !== this.STREAM_DRAW && usage !== this.STATIC_DRAW && usage !== this.DYNAMIC_DRAW) {
|
|
792
|
-
this.setError(this.INVALID_ENUM);
|
|
793
|
-
return;
|
|
794
|
-
}
|
|
795
|
-
if (target !== this.ARRAY_BUFFER && target !== this.ELEMENT_ARRAY_BUFFER) {
|
|
796
|
-
this.setError(this.INVALID_ENUM);
|
|
797
|
-
return;
|
|
798
|
-
}
|
|
799
|
-
const active = this._getActiveBuffer(target);
|
|
800
|
-
if (!active) {
|
|
801
|
-
this.setError(this.INVALID_OPERATION);
|
|
802
|
-
return;
|
|
803
|
-
}
|
|
804
|
-
if (data) {
|
|
805
|
-
let u8Data = null;
|
|
806
|
-
if (isTypedArray(data) || data instanceof DataView || data instanceof ArrayBuffer) {
|
|
807
|
-
u8Data = arrayToUint8Array(data);
|
|
808
|
-
} else {
|
|
809
|
-
this.setError(this.INVALID_VALUE);
|
|
810
|
-
return;
|
|
811
|
-
}
|
|
812
|
-
this._saveError();
|
|
813
|
-
this._gl.bufferData(target, Uint8ArrayToVariant(u8Data), usage);
|
|
814
|
-
const error = this.getError();
|
|
815
|
-
this._restoreError(error);
|
|
816
|
-
if (error !== this.NO_ERROR) {
|
|
817
|
-
return;
|
|
818
|
-
}
|
|
819
|
-
active._size = u8Data.length;
|
|
820
|
-
if (target === this.ELEMENT_ARRAY_BUFFER) {
|
|
821
|
-
active._elements = new Uint8Array(u8Data);
|
|
822
|
-
}
|
|
823
|
-
} else if (typeof dataOrSize === "number") {
|
|
824
|
-
if (size < 0) {
|
|
825
|
-
this.setError(this.INVALID_VALUE);
|
|
826
|
-
return;
|
|
827
|
-
}
|
|
828
|
-
this._saveError();
|
|
829
|
-
this._gl.bufferDataSizeOnly(target, size, usage);
|
|
830
|
-
const error = this.getError();
|
|
831
|
-
this._restoreError(error);
|
|
832
|
-
if (error !== this.NO_ERROR) {
|
|
833
|
-
return;
|
|
834
|
-
}
|
|
835
|
-
active._size = size;
|
|
836
|
-
if (target === this.ELEMENT_ARRAY_BUFFER) {
|
|
837
|
-
active._elements = new Uint8Array(size);
|
|
838
|
-
}
|
|
839
|
-
} else {
|
|
840
|
-
this.setError(this.INVALID_VALUE);
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
bufferSubData(target = 0, offset = 0, data) {
|
|
844
|
-
if (target !== this.ARRAY_BUFFER && target !== this.ELEMENT_ARRAY_BUFFER) {
|
|
845
|
-
this.setError(this.INVALID_ENUM);
|
|
846
|
-
return;
|
|
847
|
-
}
|
|
848
|
-
if (data === null || typeof data !== "object") {
|
|
849
|
-
throw new TypeError("bufferSubData: data must be a BufferSource");
|
|
850
|
-
}
|
|
851
|
-
const active = this._getActiveBuffer(target);
|
|
852
|
-
if (!active) {
|
|
853
|
-
this.setError(this.INVALID_OPERATION);
|
|
854
|
-
return;
|
|
855
|
-
}
|
|
856
|
-
if (offset < 0 || offset >= active._size) {
|
|
857
|
-
this.setError(this.INVALID_VALUE);
|
|
858
|
-
return;
|
|
859
|
-
}
|
|
860
|
-
let u8Data = null;
|
|
861
|
-
if (isTypedArray(data) || data instanceof DataView || data instanceof ArrayBuffer) {
|
|
862
|
-
u8Data = arrayToUint8Array(data);
|
|
863
|
-
} else {
|
|
864
|
-
this.setError(this.INVALID_VALUE);
|
|
865
|
-
return;
|
|
866
|
-
}
|
|
867
|
-
if (offset + u8Data.length > active._size) {
|
|
868
|
-
this.setError(this.INVALID_VALUE);
|
|
869
|
-
return;
|
|
870
|
-
}
|
|
871
|
-
if (target === this.ELEMENT_ARRAY_BUFFER) {
|
|
872
|
-
active._elements.set(u8Data, offset);
|
|
873
|
-
}
|
|
874
|
-
this._gl.bufferSubData(target, offset, Uint8ArrayToVariant(u8Data));
|
|
875
|
-
}
|
|
876
|
-
compressedTexImage2D(target, level, internalFormat, width, height, border, data) {
|
|
877
|
-
return this._gl.compressedTexImage2D(target, level, internalFormat, width, height, border, Uint8ArrayToVariant(arrayToUint8Array(data)));
|
|
878
|
-
}
|
|
879
|
-
compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, data) {
|
|
880
|
-
return this._gl.compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, Uint8ArrayToVariant(arrayToUint8Array(data)));
|
|
881
|
-
}
|
|
882
|
-
readPixels(x = 0, y = 0, width = 0, height = 0, format = 0, type = 0, pixels) {
|
|
883
|
-
if (!pixels) return;
|
|
884
|
-
if (!(this._extensions.oes_texture_float && type === this.FLOAT && format === this.RGBA)) {
|
|
885
|
-
if (format === this.RGB || format === this.ALPHA || type !== this.UNSIGNED_BYTE) {
|
|
886
|
-
this.setError(this.INVALID_OPERATION);
|
|
887
|
-
return;
|
|
888
|
-
} else if (format !== this.RGBA) {
|
|
889
|
-
this.setError(this.INVALID_ENUM);
|
|
890
|
-
return;
|
|
891
|
-
} else if (width < 0 || height < 0 || !(pixels instanceof Uint8Array)) {
|
|
892
|
-
this.setError(this.INVALID_VALUE);
|
|
893
|
-
return;
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
if (!this._framebufferOk()) {
|
|
897
|
-
console.error("framebuffer is not okay!");
|
|
898
|
-
return;
|
|
899
|
-
}
|
|
900
|
-
let rowStride = width * 4;
|
|
901
|
-
if (rowStride % this._packAlignment !== 0) {
|
|
902
|
-
rowStride += this._packAlignment - rowStride % this._packAlignment;
|
|
903
|
-
}
|
|
904
|
-
const imageSize = rowStride * (height - 1) + width * 4;
|
|
905
|
-
if (imageSize <= 0) {
|
|
906
|
-
return;
|
|
907
|
-
}
|
|
908
|
-
const pixelsLength = pixels.length || pixels.byteLength || 0;
|
|
909
|
-
if (pixelsLength < imageSize) {
|
|
910
|
-
this.setError(this.INVALID_VALUE);
|
|
911
|
-
return;
|
|
912
|
-
}
|
|
913
|
-
let viewWidth = this.drawingBufferWidth;
|
|
914
|
-
let viewHeight = this.drawingBufferHeight;
|
|
915
|
-
if (this._activeFramebuffer) {
|
|
916
|
-
viewWidth = this._activeFramebuffer._width;
|
|
917
|
-
viewHeight = this._activeFramebuffer._height;
|
|
918
|
-
}
|
|
919
|
-
const pixelData = arrayToUint8Array(pixels);
|
|
920
|
-
if (x >= viewWidth || x + width <= 0 || y >= viewHeight || y + height <= 0) {
|
|
921
|
-
for (let i = 0; i < pixelData.length; ++i) {
|
|
922
|
-
pixelData[i] = 0;
|
|
923
|
-
}
|
|
924
|
-
} else if (x < 0 || x + width > viewWidth || y < 0 || y + height > viewHeight) {
|
|
925
|
-
for (let i = 0; i < pixelData.length; ++i) {
|
|
926
|
-
pixelData[i] = 0;
|
|
927
|
-
}
|
|
928
|
-
let nx = x;
|
|
929
|
-
let nWidth = width;
|
|
930
|
-
if (x < 0) {
|
|
931
|
-
nWidth += x;
|
|
932
|
-
nx = 0;
|
|
933
|
-
}
|
|
934
|
-
if (nx + width > viewWidth) {
|
|
935
|
-
nWidth = viewWidth - nx;
|
|
936
|
-
}
|
|
937
|
-
let ny = y;
|
|
938
|
-
let nHeight = height;
|
|
939
|
-
if (y < 0) {
|
|
940
|
-
nHeight += y;
|
|
941
|
-
ny = 0;
|
|
942
|
-
}
|
|
943
|
-
if (ny + height > viewHeight) {
|
|
944
|
-
nHeight = viewHeight - ny;
|
|
945
|
-
}
|
|
946
|
-
let nRowStride = nWidth * 4;
|
|
947
|
-
if (nRowStride % this._packAlignment !== 0) {
|
|
948
|
-
nRowStride += this._packAlignment - nRowStride % this._packAlignment;
|
|
949
|
-
}
|
|
950
|
-
if (nWidth > 0 && nHeight > 0) {
|
|
951
|
-
const subPixels = new Uint8Array(nRowStride * nHeight);
|
|
952
|
-
const result = this._gl.readPixels(nx, ny, nWidth, nHeight, format, type, Uint8ArrayToVariant(subPixels));
|
|
953
|
-
const src = result && result.length > 0 ? result : subPixels;
|
|
954
|
-
const offset = 4 * (nx - x) + (ny - y) * rowStride;
|
|
955
|
-
for (let j = 0; j < nHeight; ++j) {
|
|
956
|
-
for (let i = 0; i < nWidth; ++i) {
|
|
957
|
-
for (let k = 0; k < 4; ++k) {
|
|
958
|
-
pixelData[offset + j * rowStride + 4 * i + k] = src[j * nRowStride + 4 * i + k];
|
|
959
|
-
}
|
|
960
|
-
}
|
|
961
|
-
}
|
|
962
|
-
}
|
|
963
|
-
} else {
|
|
964
|
-
const result = this._gl.readPixels(x, y, width, height, format, type, Uint8ArrayToVariant(pixelData));
|
|
965
|
-
if (result && result.length > 0) {
|
|
966
|
-
pixelData.set(result);
|
|
967
|
-
}
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
texImage2D(target = 0, level = 0, internalFormat = 0, formatOrWidth = 0, typeOrHeight = 0, sourceOrBorder = 0, _format = 0, type = 0, pixels) {
|
|
971
|
-
let width = 0;
|
|
972
|
-
let height = 0;
|
|
973
|
-
let format = 0;
|
|
974
|
-
let source;
|
|
975
|
-
let pixbuf;
|
|
976
|
-
let border = 0;
|
|
977
|
-
if (arguments.length === 6) {
|
|
978
|
-
type = typeOrHeight;
|
|
979
|
-
format = formatOrWidth;
|
|
980
|
-
if (sourceOrBorder instanceof GdkPixbuf.Pixbuf) {
|
|
981
|
-
pixbuf = sourceOrBorder;
|
|
982
|
-
width = pixbuf.get_width();
|
|
983
|
-
height = pixbuf.get_height();
|
|
984
|
-
;
|
|
985
|
-
pixels = pixbuf.get_pixels();
|
|
986
|
-
} else {
|
|
987
|
-
source = sourceOrBorder;
|
|
988
|
-
const imageData = extractImageData(source);
|
|
989
|
-
if (imageData == null) {
|
|
990
|
-
throw new TypeError("texImage2D(GLenum, GLint, GLenum, GLint, GLenum, GLenum, ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement)");
|
|
991
|
-
}
|
|
992
|
-
width = imageData.width;
|
|
993
|
-
height = imageData.height;
|
|
994
|
-
pixels = imageData.data;
|
|
995
|
-
}
|
|
996
|
-
} else if (arguments.length === 9) {
|
|
997
|
-
width = formatOrWidth;
|
|
998
|
-
height = typeOrHeight;
|
|
999
|
-
border = sourceOrBorder;
|
|
1000
|
-
format = _format;
|
|
1001
|
-
type = type;
|
|
1002
|
-
pixels = pixels;
|
|
1003
|
-
}
|
|
1004
|
-
if (typeof pixels !== "object" && pixels !== undefined) {
|
|
1005
|
-
throw new TypeError("texImage2D(GLenum, GLint, GLenum, GLint, GLint, GLint, GLenum, GLenum, Uint8Array)");
|
|
1006
|
-
}
|
|
1007
|
-
if (!checkFormat(this, format) || !checkFormat(this, internalFormat)) {
|
|
1008
|
-
this.setError(this.INVALID_ENUM);
|
|
1009
|
-
return;
|
|
1010
|
-
}
|
|
1011
|
-
if (type === this.FLOAT && !this._extensions.oes_texture_float) {
|
|
1012
|
-
this.setError(this.INVALID_ENUM);
|
|
1013
|
-
return;
|
|
1014
|
-
}
|
|
1015
|
-
const texture = this._getTexImage(target);
|
|
1016
|
-
if (!texture || format !== internalFormat) {
|
|
1017
|
-
this.setError(this.INVALID_OPERATION);
|
|
1018
|
-
return;
|
|
1019
|
-
}
|
|
1020
|
-
const pixelSize = this._computePixelSize(type, format);
|
|
1021
|
-
if (pixelSize === 0) {
|
|
1022
|
-
return;
|
|
1023
|
-
}
|
|
1024
|
-
if (!this._checkDimensions(target, width, height, level)) {
|
|
1025
|
-
return;
|
|
1026
|
-
}
|
|
1027
|
-
let data = convertPixels(pixels);
|
|
1028
|
-
const rowStride = this._computeRowStride(width, pixelSize);
|
|
1029
|
-
const imageSize = rowStride * height;
|
|
1030
|
-
if (data && data.length < imageSize) {
|
|
1031
|
-
this.setError(this.INVALID_OPERATION);
|
|
1032
|
-
return;
|
|
1033
|
-
}
|
|
1034
|
-
if (border !== 0 || validCubeTarget(this, target) && width !== height) {
|
|
1035
|
-
this.setError(this.INVALID_VALUE);
|
|
1036
|
-
return;
|
|
1037
|
-
}
|
|
1038
|
-
if (this._unpackPremultAlpha && data && format === this.RGBA) {
|
|
1039
|
-
data = premultiplyAlpha(data);
|
|
1040
|
-
}
|
|
1041
|
-
if (this._unpackFlipY && data && width > 0 && height > 0) {
|
|
1042
|
-
const flipped = new Uint8Array(data.length);
|
|
1043
|
-
for (let row = 0; row < height; row++) {
|
|
1044
|
-
const srcOffset = row * rowStride;
|
|
1045
|
-
const dstOffset = (height - 1 - row) * rowStride;
|
|
1046
|
-
flipped.set(data.subarray(srcOffset, srcOffset + rowStride), dstOffset);
|
|
1047
|
-
}
|
|
1048
|
-
data = flipped;
|
|
1049
|
-
}
|
|
1050
|
-
this._saveError();
|
|
1051
|
-
this._gl.texImage2D(target, level, internalFormat, width, height, border, format, type, Uint8ArrayToVariant(data));
|
|
1052
|
-
const error = this.getError();
|
|
1053
|
-
this._restoreError(error);
|
|
1054
|
-
if (error !== this.NO_ERROR) {
|
|
1055
|
-
return;
|
|
1056
|
-
}
|
|
1057
|
-
texture._levelWidth[level] = width;
|
|
1058
|
-
texture._levelHeight[level] = height;
|
|
1059
|
-
texture._format = format;
|
|
1060
|
-
texture._type = type;
|
|
1061
|
-
const activeFramebuffer = this._activeFramebuffer;
|
|
1062
|
-
if (activeFramebuffer) {
|
|
1063
|
-
let needsUpdate = false;
|
|
1064
|
-
const attachments = this._getAttachments();
|
|
1065
|
-
for (let i = 0; i < attachments.length; ++i) {
|
|
1066
|
-
if (activeFramebuffer._attachments[attachments[i]] === texture) {
|
|
1067
|
-
needsUpdate = true;
|
|
1068
|
-
break;
|
|
1069
|
-
}
|
|
1070
|
-
}
|
|
1071
|
-
if (needsUpdate && this._activeFramebuffer) {
|
|
1072
|
-
this._updateFramebufferAttachments(this._activeFramebuffer);
|
|
1073
|
-
}
|
|
1074
|
-
}
|
|
1075
|
-
}
|
|
1076
|
-
texSubImage2D(target = 0, level = 0, xoffset = 0, yoffset = 0, formatOrWidth = 0, typeOrHeight = 0, sourceOrFormat = 0, type = 0, pixels) {
|
|
1077
|
-
let width = 0;
|
|
1078
|
-
let height = 0;
|
|
1079
|
-
let format = 0;
|
|
1080
|
-
let source;
|
|
1081
|
-
let pixbuf;
|
|
1082
|
-
if (arguments.length === 7) {
|
|
1083
|
-
type = typeOrHeight;
|
|
1084
|
-
format = formatOrWidth;
|
|
1085
|
-
if (sourceOrFormat instanceof GdkPixbuf.Pixbuf) {
|
|
1086
|
-
pixbuf = sourceOrFormat;
|
|
1087
|
-
width = pixbuf.get_width();
|
|
1088
|
-
height = pixbuf.get_height();
|
|
1089
|
-
;
|
|
1090
|
-
pixels = pixbuf.get_pixels();
|
|
1091
|
-
} else {
|
|
1092
|
-
source = sourceOrFormat;
|
|
1093
|
-
const imageData = extractImageData(source);
|
|
1094
|
-
if (imageData == null) {
|
|
1095
|
-
throw new TypeError("texSubImage2D(GLenum, GLint, GLint, GLint, GLenum, GLenum, ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement)");
|
|
1096
|
-
}
|
|
1097
|
-
width = imageData.width;
|
|
1098
|
-
height = imageData.height;
|
|
1099
|
-
pixels = imageData.data;
|
|
1100
|
-
}
|
|
1101
|
-
} else {
|
|
1102
|
-
width = formatOrWidth;
|
|
1103
|
-
height = typeOrHeight;
|
|
1104
|
-
format = sourceOrFormat;
|
|
1105
|
-
}
|
|
1106
|
-
if (typeof pixels !== "object") {
|
|
1107
|
-
throw new TypeError("texSubImage2D(GLenum, GLint, GLint, GLint, GLint, GLint, GLenum, GLenum, Uint8Array)");
|
|
1108
|
-
}
|
|
1109
|
-
const texture = this._getTexImage(target);
|
|
1110
|
-
if (!texture) {
|
|
1111
|
-
this.setError(this.INVALID_OPERATION);
|
|
1112
|
-
return;
|
|
1113
|
-
}
|
|
1114
|
-
if (type === this.FLOAT && !this._extensions.oes_texture_float) {
|
|
1115
|
-
this.setError(this.INVALID_ENUM);
|
|
1116
|
-
return;
|
|
1117
|
-
}
|
|
1118
|
-
const pixelSize = this._computePixelSize(type, format);
|
|
1119
|
-
if (pixelSize === 0) {
|
|
1120
|
-
return;
|
|
1121
|
-
}
|
|
1122
|
-
if (!this._checkDimensions(target, width, height, level)) {
|
|
1123
|
-
return;
|
|
1124
|
-
}
|
|
1125
|
-
if (xoffset < 0 || yoffset < 0) {
|
|
1126
|
-
this.setError(this.INVALID_VALUE);
|
|
1127
|
-
return;
|
|
1128
|
-
}
|
|
1129
|
-
let data = convertPixels(pixels);
|
|
1130
|
-
const rowStride = this._computeRowStride(width, pixelSize);
|
|
1131
|
-
const imageSize = rowStride * height;
|
|
1132
|
-
if (!data || data.length < imageSize) {
|
|
1133
|
-
this.setError(this.INVALID_OPERATION);
|
|
1134
|
-
return;
|
|
1135
|
-
}
|
|
1136
|
-
if (this._unpackPremultAlpha && data && format === this.RGBA) {
|
|
1137
|
-
data = premultiplyAlpha(data);
|
|
1138
|
-
}
|
|
1139
|
-
if (this._unpackFlipY && data && width > 0 && height > 0) {
|
|
1140
|
-
const flipped = new Uint8Array(data.length);
|
|
1141
|
-
for (let row = 0; row < height; row++) {
|
|
1142
|
-
const srcOffset = row * rowStride;
|
|
1143
|
-
const dstOffset = (height - 1 - row) * rowStride;
|
|
1144
|
-
flipped.set(data.subarray(srcOffset, srcOffset + rowStride), dstOffset);
|
|
1145
|
-
}
|
|
1146
|
-
data = flipped;
|
|
1147
|
-
}
|
|
1148
|
-
this._gl.texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, Uint8ArrayToVariant(data));
|
|
1149
|
-
}
|
|
1150
|
-
_checkUniformValid(location, v0, name, count, type) {
|
|
1151
|
-
if (!checkObject(location)) {
|
|
1152
|
-
throw new TypeError(`${name}(WebGLUniformLocation, ...)`);
|
|
1153
|
-
} else if (!location) {
|
|
1154
|
-
return false;
|
|
1155
|
-
} else if (this._checkLocationActive(location)) {
|
|
1156
|
-
const utype = location._activeInfo.type;
|
|
1157
|
-
if (utype === this.SAMPLER_2D || utype === this.SAMPLER_CUBE) {
|
|
1158
|
-
if (count !== 1) {
|
|
1159
|
-
this.setError(this.INVALID_VALUE);
|
|
1160
|
-
return;
|
|
1161
|
-
}
|
|
1162
|
-
if (type !== "i") {
|
|
1163
|
-
this.setError(this.INVALID_OPERATION);
|
|
1164
|
-
return;
|
|
1165
|
-
}
|
|
1166
|
-
if (v0 < 0 || v0 >= this._textureUnits.length) {
|
|
1167
|
-
this.setError(this.INVALID_VALUE);
|
|
1168
|
-
return false;
|
|
1169
|
-
}
|
|
1170
|
-
}
|
|
1171
|
-
if (uniformTypeSize(this, utype) > count) {
|
|
1172
|
-
this.setError(this.INVALID_OPERATION);
|
|
1173
|
-
return false;
|
|
1174
|
-
}
|
|
1175
|
-
return true;
|
|
1176
|
-
}
|
|
1177
|
-
return false;
|
|
1178
|
-
}
|
|
1179
|
-
_checkUniformValueValid(location, value, name, count, _type) {
|
|
1180
|
-
if (!checkObject(location) || !checkObject(value)) {
|
|
1181
|
-
throw new TypeError(`${name}v(WebGLUniformLocation, Array)`);
|
|
1182
|
-
} else if (!location) {
|
|
1183
|
-
return false;
|
|
1184
|
-
} else if (!this._checkLocationActive(location)) {
|
|
1185
|
-
return false;
|
|
1186
|
-
} else if (typeof value !== "object" || !value || typeof value.length !== "number") {
|
|
1187
|
-
throw new TypeError(`Second argument to ${name} must be array`);
|
|
1188
|
-
} else if (uniformTypeSize(this, location._activeInfo.type) > count) {
|
|
1189
|
-
this.setError(this.INVALID_OPERATION);
|
|
1190
|
-
return false;
|
|
1191
|
-
} else if (value.length >= count && value.length % count === 0) {
|
|
1192
|
-
if (location._array) {
|
|
1193
|
-
return true;
|
|
1194
|
-
} else if (value.length === count) {
|
|
1195
|
-
return true;
|
|
1196
|
-
} else {
|
|
1197
|
-
this.setError(this.INVALID_OPERATION);
|
|
1198
|
-
return false;
|
|
1199
|
-
}
|
|
1200
|
-
}
|
|
1201
|
-
this.setError(this.INVALID_VALUE);
|
|
1202
|
-
return false;
|
|
1203
|
-
}
|
|
1204
|
-
uniform1fv(location, value) {
|
|
1205
|
-
if (!location || !this._checkUniformValueValid(location, value, "uniform1fv", 1, "f")) return;
|
|
1206
|
-
if (location?._array) {
|
|
1207
|
-
const locs = location._array;
|
|
1208
|
-
for (let i = 0; i < locs.length && i < value.length; ++i) {
|
|
1209
|
-
const loc = locs[i];
|
|
1210
|
-
if (loc != null) {
|
|
1211
|
-
this._gl.uniform1f(loc, value[i]);
|
|
1212
|
-
}
|
|
1213
|
-
}
|
|
1214
|
-
return;
|
|
1215
|
-
}
|
|
1216
|
-
this._gl.uniform1f(location?._ | 0, value[0]);
|
|
1217
|
-
}
|
|
1218
|
-
uniform1iv(location, v) {
|
|
1219
|
-
if (!this._checkUniformValueValid(location, v, "uniform1iv", 1, "i")) return;
|
|
1220
|
-
if (location?._array) {
|
|
1221
|
-
const locs = location._array;
|
|
1222
|
-
for (let i = 0; i < locs.length && i < v.length; ++i) {
|
|
1223
|
-
const loc = locs[i];
|
|
1224
|
-
if (loc != null) {
|
|
1225
|
-
this._gl.uniform1i(loc, v[i]);
|
|
1226
|
-
}
|
|
1227
|
-
}
|
|
1228
|
-
return;
|
|
1229
|
-
}
|
|
1230
|
-
this.uniform1i(location, v[0]);
|
|
1231
|
-
}
|
|
1232
|
-
uniform2fv(location, v) {
|
|
1233
|
-
if (!this._checkUniformValueValid(location, v, "uniform2fv", 2, "f")) return;
|
|
1234
|
-
if (location?._array) {
|
|
1235
|
-
const locs = location._array;
|
|
1236
|
-
for (let i = 0; i < locs.length && 2 * i < v.length; ++i) {
|
|
1237
|
-
const loc = locs[i];
|
|
1238
|
-
if (loc != null) {
|
|
1239
|
-
this._gl.uniform2f(loc, v[2 * i], v[2 * i + 1]);
|
|
1240
|
-
}
|
|
1241
|
-
}
|
|
1242
|
-
return;
|
|
1243
|
-
}
|
|
1244
|
-
this._gl.uniform2f(location?._ || 0, v[0], v[1]);
|
|
1245
|
-
}
|
|
1246
|
-
uniform2iv(location, v) {
|
|
1247
|
-
if (!this._checkUniformValueValid(location, v, "uniform2iv", 2, "i")) return;
|
|
1248
|
-
if (location?._array) {
|
|
1249
|
-
const locs = location._array;
|
|
1250
|
-
for (let i = 0; i < locs.length && 2 * i < v.length; ++i) {
|
|
1251
|
-
const loc = locs[i];
|
|
1252
|
-
if (loc != null) {
|
|
1253
|
-
this._gl.uniform2i(loc, v[2 * i], v[2 * i + 1]);
|
|
1254
|
-
}
|
|
1255
|
-
}
|
|
1256
|
-
return;
|
|
1257
|
-
}
|
|
1258
|
-
this.uniform2i(location, v[0], v[1]);
|
|
1259
|
-
}
|
|
1260
|
-
uniform3fv(location, v) {
|
|
1261
|
-
if (!this._checkUniformValueValid(location, v, "uniform3fv", 3, "f")) return;
|
|
1262
|
-
if (location?._array) {
|
|
1263
|
-
const locs = location._array;
|
|
1264
|
-
for (let i = 0; i < locs.length && 3 * i < v.length; ++i) {
|
|
1265
|
-
const loc = locs[i];
|
|
1266
|
-
if (loc != null) {
|
|
1267
|
-
this._gl.uniform3f(loc, v[3 * i], v[3 * i + 1], v[3 * i + 2]);
|
|
1268
|
-
}
|
|
1269
|
-
}
|
|
1270
|
-
return;
|
|
1271
|
-
}
|
|
1272
|
-
this._gl.uniform3f(location?._ || 0, v[0], v[1], v[2]);
|
|
1273
|
-
}
|
|
1274
|
-
uniform3iv(location, v) {
|
|
1275
|
-
if (!this._checkUniformValueValid(location, v, "uniform3iv", 3, "i")) return;
|
|
1276
|
-
if (location?._array) {
|
|
1277
|
-
const locs = location._array;
|
|
1278
|
-
for (let i = 0; i < locs.length && 3 * i < v.length; ++i) {
|
|
1279
|
-
const loc = locs[i];
|
|
1280
|
-
if (loc != null) {
|
|
1281
|
-
this._gl.uniform3i(loc, v[3 * i], v[3 * i + 1], v[3 * i + 2]);
|
|
1282
|
-
}
|
|
1283
|
-
}
|
|
1284
|
-
return;
|
|
1285
|
-
}
|
|
1286
|
-
this.uniform3i(location, v[0], v[1], v[2]);
|
|
1287
|
-
}
|
|
1288
|
-
uniform4fv(location, v) {
|
|
1289
|
-
if (!this._checkUniformValueValid(location, v, "uniform4fv", 4, "f")) return;
|
|
1290
|
-
if (location?._array) {
|
|
1291
|
-
const locs = location._array;
|
|
1292
|
-
for (let i = 0; i < locs.length && 4 * i < v.length; ++i) {
|
|
1293
|
-
const loc = locs[i];
|
|
1294
|
-
if (loc != null) {
|
|
1295
|
-
this._gl.uniform4f(loc, v[4 * i], v[4 * i + 1], v[4 * i + 2], v[4 * i + 3]);
|
|
1296
|
-
}
|
|
1297
|
-
}
|
|
1298
|
-
return;
|
|
1299
|
-
}
|
|
1300
|
-
this._gl.uniform4f(location?._ || 0, v[0], v[1], v[2], v[3]);
|
|
1301
|
-
}
|
|
1302
|
-
uniform4iv(location, v) {
|
|
1303
|
-
if (!this._checkUniformValueValid(location, v, "uniform4iv", 4, "i")) return;
|
|
1304
|
-
if (location?._array) {
|
|
1305
|
-
const locs = location._array;
|
|
1306
|
-
for (let i = 0; i < locs.length && 4 * i < v.length; ++i) {
|
|
1307
|
-
const loc = locs[i];
|
|
1308
|
-
if (loc != null) {
|
|
1309
|
-
this._gl.uniform4i(loc, v[4 * i], v[4 * i + 1], v[4 * i + 2], v[4 * i + 3]);
|
|
1310
|
-
}
|
|
1311
|
-
}
|
|
1312
|
-
return;
|
|
1313
|
-
}
|
|
1314
|
-
this.uniform4i(location, v[0], v[1], v[2], v[3]);
|
|
1315
|
-
}
|
|
1316
|
-
_checkUniformMatrix(location, transpose, value, name, count) {
|
|
1317
|
-
if (!checkObject(location) || typeof value !== "object") {
|
|
1318
|
-
throw new TypeError(name + "(WebGLUniformLocation, Boolean, Array)");
|
|
1319
|
-
} else if (!!transpose || typeof value !== "object" || value === null || !value.length || value.length % count * count !== 0) {
|
|
1320
|
-
this.setError(this.INVALID_VALUE);
|
|
1321
|
-
return false;
|
|
1322
|
-
}
|
|
1323
|
-
if (!location) {
|
|
1324
|
-
return false;
|
|
1325
|
-
}
|
|
1326
|
-
if (!this._checkLocationActive(location)) {
|
|
1327
|
-
return false;
|
|
1328
|
-
}
|
|
1329
|
-
if (value.length === count * count) {
|
|
1330
|
-
return true;
|
|
1331
|
-
} else if (location._array) {
|
|
1332
|
-
return true;
|
|
1333
|
-
}
|
|
1334
|
-
this.setError(this.INVALID_VALUE);
|
|
1335
|
-
return false;
|
|
1336
|
-
}
|
|
1337
|
-
uniformMatrix2fv(location, transpose, value) {
|
|
1338
|
-
if (!this._checkUniformMatrix(location, transpose, value, "uniformMatrix2fv", 2)) return;
|
|
1339
|
-
const data = new Float32Array(value);
|
|
1340
|
-
this._gl.uniformMatrix2fv(location?._ || 0, !!transpose, listToArray(data));
|
|
1341
|
-
}
|
|
1342
|
-
uniformMatrix3fv(location, transpose, value) {
|
|
1343
|
-
if (!this._checkUniformMatrix(location, transpose, value, "uniformMatrix3fv", 3)) return;
|
|
1344
|
-
const data = new Float32Array(value);
|
|
1345
|
-
this._gl.uniformMatrix3fv(location?._ || 0, !!transpose, listToArray(data));
|
|
1346
|
-
}
|
|
1347
|
-
uniformMatrix4fv(location, transpose, value) {
|
|
1348
|
-
if (!this._checkUniformMatrix(location, transpose, value, "uniformMatrix4fv", 4)) return;
|
|
1349
|
-
const data = new Float32Array(value);
|
|
1350
|
-
this._gl.uniformMatrix4fv(location?._ || 0, !!transpose, listToArray(data));
|
|
1351
|
-
}
|
|
1352
|
-
activeTexture(texture = 0) {
|
|
1353
|
-
const texNum = texture - this.TEXTURE0;
|
|
1354
|
-
if (texNum >= 0 && texNum < this._textureUnits.length) {
|
|
1355
|
-
this._activeTextureUnit = texNum;
|
|
1356
|
-
return this._gl.activeTexture(texture);
|
|
1357
|
-
}
|
|
1358
|
-
this.setError(this.INVALID_ENUM);
|
|
1359
|
-
}
|
|
1360
|
-
attachShader(program, shader) {
|
|
1361
|
-
if (!checkObject(program) || !checkObject(shader)) {
|
|
1362
|
-
throw new TypeError("attachShader(WebGLProgram, WebGLShader)");
|
|
1363
|
-
}
|
|
1364
|
-
if (!program || !shader) {
|
|
1365
|
-
this.setError(this.INVALID_VALUE);
|
|
1366
|
-
return;
|
|
1367
|
-
} else if (program instanceof WebGLProgram && shader instanceof WebGLShader && this._checkOwns(program) && this._checkOwns(shader)) {
|
|
1368
|
-
if (!program._linked(shader)) {
|
|
1369
|
-
this._saveError();
|
|
1370
|
-
this._gl.attachShader(program._ | 0, shader._ | 0);
|
|
1371
|
-
const error = this.getError();
|
|
1372
|
-
this._restoreError(error);
|
|
1373
|
-
if (error === this.NO_ERROR) {
|
|
1374
|
-
program._link(shader);
|
|
1375
|
-
}
|
|
1376
|
-
return;
|
|
1377
|
-
}
|
|
1378
|
-
}
|
|
1379
|
-
this.setError(this.INVALID_OPERATION);
|
|
1380
|
-
}
|
|
1381
|
-
bindAttribLocation(program, index, name) {
|
|
1382
|
-
if (!checkObject(program) || typeof name !== "string") {
|
|
1383
|
-
throw new TypeError("bindAttribLocation(WebGLProgram, GLint, String)");
|
|
1384
|
-
}
|
|
1385
|
-
name += "";
|
|
1386
|
-
if (!isValidString(name) || name.length > MAX_ATTRIBUTE_LENGTH) {
|
|
1387
|
-
this.setError(this.INVALID_VALUE);
|
|
1388
|
-
} else if (/^_?webgl_a/.test(name)) {
|
|
1389
|
-
this.setError(this.INVALID_OPERATION);
|
|
1390
|
-
} else if (this._checkWrapper(program, WebGLProgram)) {
|
|
1391
|
-
return this._gl.bindAttribLocation(program._ | 0, index | 0, name);
|
|
1392
|
-
}
|
|
1393
|
-
}
|
|
1394
|
-
bindBuffer(target = 0, buffer) {
|
|
1395
|
-
if (!checkObject(buffer)) {
|
|
1396
|
-
throw new TypeError("bindBuffer(GLenum, WebGLBuffer)");
|
|
1397
|
-
}
|
|
1398
|
-
if (target !== this.ARRAY_BUFFER && target !== this.ELEMENT_ARRAY_BUFFER) {
|
|
1399
|
-
this.setError(this.INVALID_ENUM);
|
|
1400
|
-
return;
|
|
1401
|
-
}
|
|
1402
|
-
if (!buffer) {
|
|
1403
|
-
buffer = null;
|
|
1404
|
-
this._gl.bindBuffer(target, 0);
|
|
1405
|
-
} else if (buffer._pendingDelete) {
|
|
1406
|
-
return;
|
|
1407
|
-
} else if (this._checkWrapper(buffer, WebGLBuffer)) {
|
|
1408
|
-
if (buffer._binding && buffer._binding !== target) {
|
|
1409
|
-
this.setError(this.INVALID_OPERATION);
|
|
1410
|
-
return;
|
|
1411
|
-
}
|
|
1412
|
-
buffer._binding = target | 0;
|
|
1413
|
-
this._gl.bindBuffer(target, buffer._ | 0);
|
|
1414
|
-
} else {
|
|
1415
|
-
return;
|
|
1416
|
-
}
|
|
1417
|
-
if (target === this.ARRAY_BUFFER) {
|
|
1418
|
-
this._vertexGlobalState.setArrayBuffer(buffer);
|
|
1419
|
-
} else {
|
|
1420
|
-
this._vertexObjectState.setElementArrayBuffer(buffer);
|
|
1421
|
-
}
|
|
1422
|
-
}
|
|
1423
|
-
bindFramebuffer(target, framebuffer) {
|
|
1424
|
-
if (!checkObject(framebuffer)) {
|
|
1425
|
-
throw new TypeError("bindFramebuffer(GLenum, WebGLFramebuffer)");
|
|
1426
|
-
}
|
|
1427
|
-
if (target !== this.FRAMEBUFFER) {
|
|
1428
|
-
this.setError(this.INVALID_ENUM);
|
|
1429
|
-
return;
|
|
1430
|
-
}
|
|
1431
|
-
if (!framebuffer) {
|
|
1432
|
-
this._gl.bindFramebuffer(this.FRAMEBUFFER, this._gtkFboId);
|
|
1433
|
-
} else if (framebuffer._pendingDelete) {
|
|
1434
|
-
return;
|
|
1435
|
-
} else if (this._checkWrapper(framebuffer, WebGLFramebuffer)) {
|
|
1436
|
-
this._gl.bindFramebuffer(this.FRAMEBUFFER, framebuffer._ | 0);
|
|
1437
|
-
} else {
|
|
1438
|
-
return;
|
|
1439
|
-
}
|
|
1440
|
-
const activeFramebuffer = this._activeFramebuffer;
|
|
1441
|
-
if (activeFramebuffer !== framebuffer) {
|
|
1442
|
-
if (activeFramebuffer) {
|
|
1443
|
-
activeFramebuffer._refCount -= 1;
|
|
1444
|
-
activeFramebuffer._checkDelete();
|
|
1445
|
-
}
|
|
1446
|
-
if (framebuffer) {
|
|
1447
|
-
framebuffer._refCount += 1;
|
|
1448
|
-
}
|
|
1449
|
-
}
|
|
1450
|
-
this._activeFramebuffer = framebuffer;
|
|
1451
|
-
if (framebuffer) {
|
|
1452
|
-
this._updateFramebufferAttachments(framebuffer);
|
|
1453
|
-
}
|
|
1454
|
-
}
|
|
1455
|
-
bindRenderbuffer(target, renderbuffer) {
|
|
1456
|
-
if (!checkObject(renderbuffer)) {
|
|
1457
|
-
throw new TypeError("bindRenderbuffer(GLenum, WebGLRenderbuffer)");
|
|
1458
|
-
}
|
|
1459
|
-
if (target !== this.RENDERBUFFER) {
|
|
1460
|
-
this.setError(this.INVALID_ENUM);
|
|
1461
|
-
return;
|
|
1462
|
-
}
|
|
1463
|
-
if (!renderbuffer) {
|
|
1464
|
-
this._gl.bindRenderbuffer(target | 0, 0);
|
|
1465
|
-
} else if (renderbuffer._pendingDelete) {
|
|
1466
|
-
return;
|
|
1467
|
-
} else if (this._checkWrapper(renderbuffer, WebGLRenderbuffer)) {
|
|
1468
|
-
this._gl.bindRenderbuffer(target | 0, renderbuffer._ | 0);
|
|
1469
|
-
} else {
|
|
1470
|
-
return;
|
|
1471
|
-
}
|
|
1472
|
-
const active = this._activeRenderbuffer;
|
|
1473
|
-
if (active !== renderbuffer) {
|
|
1474
|
-
if (active) {
|
|
1475
|
-
active._refCount -= 1;
|
|
1476
|
-
active._checkDelete();
|
|
1477
|
-
}
|
|
1478
|
-
if (renderbuffer) {
|
|
1479
|
-
renderbuffer._refCount += 1;
|
|
1480
|
-
}
|
|
1481
|
-
}
|
|
1482
|
-
this._activeRenderbuffer = renderbuffer;
|
|
1483
|
-
}
|
|
1484
|
-
bindTexture(target = 0, texture) {
|
|
1485
|
-
if (!checkObject(texture)) {
|
|
1486
|
-
throw new TypeError("bindTexture(GLenum, WebGLTexture)");
|
|
1487
|
-
}
|
|
1488
|
-
if (!this._validTextureTarget(target)) {
|
|
1489
|
-
this.setError(this.INVALID_ENUM);
|
|
1490
|
-
return;
|
|
1491
|
-
}
|
|
1492
|
-
let textureId = 0;
|
|
1493
|
-
if (!texture) {
|
|
1494
|
-
texture = null;
|
|
1495
|
-
} else if (texture instanceof WebGLTexture && texture._pendingDelete) {
|
|
1496
|
-
return;
|
|
1497
|
-
} else if (this._checkWrapper(texture, WebGLTexture)) {
|
|
1498
|
-
if (texture._binding && texture._binding !== target) {
|
|
1499
|
-
this.setError(this.INVALID_OPERATION);
|
|
1500
|
-
return;
|
|
1501
|
-
}
|
|
1502
|
-
texture._binding = target;
|
|
1503
|
-
if (texture._complete) {
|
|
1504
|
-
textureId = texture._ | 0;
|
|
1505
|
-
}
|
|
1506
|
-
} else {
|
|
1507
|
-
return;
|
|
1508
|
-
}
|
|
1509
|
-
this._saveError();
|
|
1510
|
-
this._gl.bindTexture(target, textureId);
|
|
1511
|
-
const error = this.getError();
|
|
1512
|
-
this._restoreError(error);
|
|
1513
|
-
if (error !== this.NO_ERROR) {
|
|
1514
|
-
return;
|
|
1515
|
-
}
|
|
1516
|
-
const activeUnit = this._getActiveTextureUnit();
|
|
1517
|
-
const activeTex = this._getActiveTexture(target);
|
|
1518
|
-
if (activeTex !== texture) {
|
|
1519
|
-
if (activeTex) {
|
|
1520
|
-
activeTex._refCount -= 1;
|
|
1521
|
-
activeTex._checkDelete();
|
|
1522
|
-
}
|
|
1523
|
-
if (texture) {
|
|
1524
|
-
texture._refCount += 1;
|
|
1525
|
-
}
|
|
1526
|
-
}
|
|
1527
|
-
if (target === this.TEXTURE_2D) {
|
|
1528
|
-
activeUnit._bind2D = texture;
|
|
1529
|
-
} else if (target === this.TEXTURE_CUBE_MAP) {
|
|
1530
|
-
activeUnit._bindCube = texture;
|
|
1531
|
-
}
|
|
1532
|
-
}
|
|
1533
|
-
blendColor(red = 0, green = 0, blue = 0, alpha = 0) {
|
|
1534
|
-
return this._gl.blendColor(+red, +green, +blue, +alpha);
|
|
1535
|
-
}
|
|
1536
|
-
blendEquation(mode = 0) {
|
|
1537
|
-
if (this._validBlendMode(mode)) {
|
|
1538
|
-
return this._gl.blendEquation(mode);
|
|
1539
|
-
}
|
|
1540
|
-
this.setError(this.INVALID_ENUM);
|
|
1541
|
-
}
|
|
1542
|
-
blendEquationSeparate(modeRGB = 0, modeAlpha = 0) {
|
|
1543
|
-
if (this._validBlendMode(modeRGB) && this._validBlendMode(modeAlpha)) {
|
|
1544
|
-
return this._gl.blendEquationSeparate(modeRGB, modeAlpha);
|
|
1545
|
-
}
|
|
1546
|
-
this.setError(this.INVALID_ENUM);
|
|
1547
|
-
}
|
|
1548
|
-
blendFunc(sfactor = 0, dfactor = 0) {
|
|
1549
|
-
if (!this._validBlendFunc(sfactor) || !this._validBlendFunc(dfactor)) {
|
|
1550
|
-
this.setError(this.INVALID_ENUM);
|
|
1551
|
-
return;
|
|
1552
|
-
}
|
|
1553
|
-
if (this._isConstantBlendFunc(sfactor) && this._isConstantBlendFunc(dfactor)) {
|
|
1554
|
-
this.setError(this.INVALID_OPERATION);
|
|
1555
|
-
return;
|
|
1556
|
-
}
|
|
1557
|
-
this._gl.blendFunc(sfactor, dfactor);
|
|
1558
|
-
}
|
|
1559
|
-
blendFuncSeparate(srcRGB = 0, dstRGB = 0, srcAlpha = 0, dstAlpha = 0) {
|
|
1560
|
-
if (!(this._validBlendFunc(srcRGB) && this._validBlendFunc(dstRGB) && this._validBlendFunc(srcAlpha) && this._validBlendFunc(dstAlpha))) {
|
|
1561
|
-
this.setError(this.INVALID_ENUM);
|
|
1562
|
-
return;
|
|
1563
|
-
}
|
|
1564
|
-
if (this._isConstantBlendFunc(srcRGB) && this._isConstantBlendFunc(dstRGB) || this._isConstantBlendFunc(srcAlpha) && this._isConstantBlendFunc(dstAlpha)) {
|
|
1565
|
-
this.setError(this.INVALID_OPERATION);
|
|
1566
|
-
return;
|
|
1567
|
-
}
|
|
1568
|
-
this._gl.blendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
|
|
1569
|
-
}
|
|
1570
|
-
checkFramebufferStatus(target) {
|
|
1571
|
-
if (target !== this.FRAMEBUFFER) {
|
|
1572
|
-
this.setError(this.INVALID_ENUM);
|
|
1573
|
-
return 0;
|
|
1574
|
-
}
|
|
1575
|
-
const framebuffer = this._activeFramebuffer;
|
|
1576
|
-
if (!framebuffer) {
|
|
1577
|
-
return this.FRAMEBUFFER_COMPLETE;
|
|
1578
|
-
}
|
|
1579
|
-
return this._preCheckFramebufferStatus(framebuffer);
|
|
1580
|
-
}
|
|
1581
|
-
clear(mask = 0) {
|
|
1582
|
-
if (!this._framebufferOk()) {
|
|
1583
|
-
return;
|
|
1584
|
-
}
|
|
1585
|
-
return this._gl.clear(mask);
|
|
1586
|
-
}
|
|
1587
|
-
clearColor(red, green, blue, alpha) {
|
|
1588
|
-
return this._gl.clearColor(+red, +green, +blue, +alpha);
|
|
1589
|
-
}
|
|
1590
|
-
clearDepth(depth) {
|
|
1591
|
-
return this._gl.clearDepth(+depth);
|
|
1592
|
-
}
|
|
1593
|
-
clearStencil(s = 0) {
|
|
1594
|
-
this._checkStencil = false;
|
|
1595
|
-
return this._gl.clearStencil(s);
|
|
1596
|
-
}
|
|
1597
|
-
colorMask(red, green, blue, alpha) {
|
|
1598
|
-
return this._gl.colorMask(!!red, !!green, !!blue, !!alpha);
|
|
1599
|
-
}
|
|
1600
|
-
compileShader(shader) {
|
|
1601
|
-
if (!checkObject(shader)) {
|
|
1602
|
-
throw new TypeError("compileShader(WebGLShader)");
|
|
1603
|
-
}
|
|
1604
|
-
if (this._checkWrapper(shader, WebGLShader) && this._checkShaderSource(shader)) {
|
|
1605
|
-
const prevError = this.getError();
|
|
1606
|
-
this._gl.compileShader(shader._ | 0);
|
|
1607
|
-
shader._needsRecompile = false;
|
|
1608
|
-
const error = this.getError();
|
|
1609
|
-
shader._compileStatus = !!this._gl.getShaderParameter(shader._ | 0, this.COMPILE_STATUS);
|
|
1610
|
-
shader._compileInfo = this._gl.getShaderInfoLog(shader._ | 0) || "null";
|
|
1611
|
-
this.getError();
|
|
1612
|
-
this.setError(prevError || error);
|
|
1613
|
-
}
|
|
1614
|
-
}
|
|
1615
|
-
copyTexImage2D(target = 0, level = 0, internalFormat = 0, x = 0, y = 0, width = 0, height = 0, border = 0) {
|
|
1616
|
-
const texture = this._getTexImage(target);
|
|
1617
|
-
if (!texture) {
|
|
1618
|
-
this.setError(this.INVALID_OPERATION);
|
|
1619
|
-
return;
|
|
1620
|
-
}
|
|
1621
|
-
if (internalFormat !== this.RGBA && internalFormat !== this.RGB && internalFormat !== this.ALPHA && internalFormat !== this.LUMINANCE && internalFormat !== this.LUMINANCE_ALPHA) {
|
|
1622
|
-
this.setError(this.INVALID_ENUM);
|
|
1623
|
-
return;
|
|
1624
|
-
}
|
|
1625
|
-
if (level < 0 || width < 0 || height < 0 || border !== 0) {
|
|
1626
|
-
this.setError(this.INVALID_VALUE);
|
|
1627
|
-
return;
|
|
1628
|
-
}
|
|
1629
|
-
if (level > 0 && !(bits.isPow2(width) && bits.isPow2(height))) {
|
|
1630
|
-
this.setError(this.INVALID_VALUE);
|
|
1631
|
-
return;
|
|
1632
|
-
}
|
|
1633
|
-
this._saveError();
|
|
1634
|
-
this._gl.copyTexImage2D(target, level, internalFormat, x, y, width, height, border);
|
|
1635
|
-
const error = this.getError();
|
|
1636
|
-
this._restoreError(error);
|
|
1637
|
-
if (error === this.NO_ERROR) {
|
|
1638
|
-
texture._levelWidth[level] = width;
|
|
1639
|
-
texture._levelHeight[level] = height;
|
|
1640
|
-
texture._format = this.RGBA;
|
|
1641
|
-
texture._type = this.UNSIGNED_BYTE;
|
|
1642
|
-
}
|
|
1643
|
-
}
|
|
1644
|
-
copyTexSubImage2D(target = 0, level = 0, xoffset = 0, yoffset = 0, x = 0, y = 0, width = 0, height = 0) {
|
|
1645
|
-
const texture = this._getTexImage(target);
|
|
1646
|
-
if (!texture) {
|
|
1647
|
-
this.setError(this.INVALID_OPERATION);
|
|
1648
|
-
return;
|
|
1649
|
-
}
|
|
1650
|
-
if (width < 0 || height < 0 || xoffset < 0 || yoffset < 0 || level < 0) {
|
|
1651
|
-
this.setError(this.INVALID_VALUE);
|
|
1652
|
-
return;
|
|
1653
|
-
}
|
|
1654
|
-
this._gl.copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
|
|
1655
|
-
}
|
|
1656
|
-
createBuffer() {
|
|
1657
|
-
const id = this._gl.createBuffer();
|
|
1658
|
-
if (!id || id <= 0) return null;
|
|
1659
|
-
const webGLBuffer = new WebGLBuffer(id, this);
|
|
1660
|
-
this._buffers[id] = webGLBuffer;
|
|
1661
|
-
return webGLBuffer;
|
|
1662
|
-
}
|
|
1663
|
-
createFramebuffer() {
|
|
1664
|
-
const id = this._gl.createFramebuffer();
|
|
1665
|
-
if (id <= 0) return null;
|
|
1666
|
-
const webGLFramebuffer = new WebGLFramebuffer(id, this);
|
|
1667
|
-
this._framebuffers[id] = webGLFramebuffer;
|
|
1668
|
-
return webGLFramebuffer;
|
|
1669
|
-
}
|
|
1670
|
-
createProgram() {
|
|
1671
|
-
const id = this._gl.createProgram();
|
|
1672
|
-
if (id <= 0) return null;
|
|
1673
|
-
const webGLProgram = new WebGLProgram(id, this);
|
|
1674
|
-
this._programs[id] = webGLProgram;
|
|
1675
|
-
return webGLProgram;
|
|
1676
|
-
}
|
|
1677
|
-
createRenderbuffer() {
|
|
1678
|
-
const id = this._gl.createRenderbuffer();
|
|
1679
|
-
if (id <= 0) return null;
|
|
1680
|
-
const webGLRenderbuffer = new WebGLRenderbuffer(id, this);
|
|
1681
|
-
this._renderbuffers[id] = webGLRenderbuffer;
|
|
1682
|
-
return webGLRenderbuffer;
|
|
1683
|
-
}
|
|
1684
|
-
createShader(type = 0) {
|
|
1685
|
-
if (type !== this.FRAGMENT_SHADER && type !== this.VERTEX_SHADER) {
|
|
1686
|
-
this.setError(this.INVALID_ENUM);
|
|
1687
|
-
return null;
|
|
1688
|
-
}
|
|
1689
|
-
const id = this._gl.createShader(type);
|
|
1690
|
-
if (id < 0) {
|
|
1691
|
-
return null;
|
|
1692
|
-
}
|
|
1693
|
-
const result = new WebGLShader(id, this, type);
|
|
1694
|
-
this._shaders[id] = result;
|
|
1695
|
-
return result;
|
|
1696
|
-
}
|
|
1697
|
-
createTexture() {
|
|
1698
|
-
const id = this._gl.createTexture();
|
|
1699
|
-
if (id <= 0) return null;
|
|
1700
|
-
const webGlTexture = new WebGLTexture(id, this);
|
|
1701
|
-
this._textures[id] = webGlTexture;
|
|
1702
|
-
return webGlTexture;
|
|
1703
|
-
}
|
|
1704
|
-
cullFace(mode) {
|
|
1705
|
-
return this._gl.cullFace(mode | 0);
|
|
1706
|
-
}
|
|
1707
|
-
deleteBuffer(buffer) {
|
|
1708
|
-
if (!checkObject(buffer) || buffer !== null && !(buffer instanceof WebGLBuffer)) {
|
|
1709
|
-
throw new TypeError("deleteBuffer(WebGLBuffer)");
|
|
1710
|
-
}
|
|
1711
|
-
if (!(buffer instanceof WebGLBuffer && this._checkOwns(buffer))) {
|
|
1712
|
-
this.setError(this.INVALID_OPERATION);
|
|
1713
|
-
return;
|
|
1714
|
-
}
|
|
1715
|
-
if (this._vertexGlobalState._arrayBufferBinding === buffer) {
|
|
1716
|
-
this.bindBuffer(this.ARRAY_BUFFER, null);
|
|
1717
|
-
}
|
|
1718
|
-
if (this._vertexObjectState._elementArrayBufferBinding === buffer) {
|
|
1719
|
-
this.bindBuffer(this.ELEMENT_ARRAY_BUFFER, null);
|
|
1720
|
-
}
|
|
1721
|
-
if (this._vertexObjectState === this._defaultVertexObjectState) {
|
|
1722
|
-
this._vertexObjectState.releaseArrayBuffer(buffer);
|
|
1723
|
-
}
|
|
1724
|
-
buffer._pendingDelete = true;
|
|
1725
|
-
buffer._checkDelete();
|
|
1726
|
-
}
|
|
1727
|
-
deleteFramebuffer(framebuffer) {
|
|
1728
|
-
if (!checkObject(framebuffer)) {
|
|
1729
|
-
throw new TypeError("deleteFramebuffer(WebGLFramebuffer)");
|
|
1730
|
-
}
|
|
1731
|
-
if (!(framebuffer instanceof WebGLFramebuffer && this._checkOwns(framebuffer))) {
|
|
1732
|
-
this.setError(this.INVALID_OPERATION);
|
|
1733
|
-
return;
|
|
1734
|
-
}
|
|
1735
|
-
if (this._activeFramebuffer === framebuffer) {
|
|
1736
|
-
this.bindFramebuffer(this.FRAMEBUFFER, null);
|
|
1737
|
-
}
|
|
1738
|
-
framebuffer._pendingDelete = true;
|
|
1739
|
-
framebuffer._checkDelete();
|
|
1740
|
-
}
|
|
1741
|
-
_deleteLinkable(name, object, Type) {
|
|
1742
|
-
if (!checkObject(object)) {
|
|
1743
|
-
throw new TypeError(name + "(" + Type.name + ")");
|
|
1744
|
-
}
|
|
1745
|
-
if (object instanceof Type && this._checkOwns(object)) {
|
|
1746
|
-
object._pendingDelete = true;
|
|
1747
|
-
object._checkDelete();
|
|
1748
|
-
return;
|
|
1749
|
-
}
|
|
1750
|
-
this.setError(this.INVALID_OPERATION);
|
|
1751
|
-
}
|
|
1752
|
-
deleteProgram(program) {
|
|
1753
|
-
return this._deleteLinkable("deleteProgram", program, WebGLProgram);
|
|
1754
|
-
}
|
|
1755
|
-
deleteRenderbuffer(renderbuffer) {
|
|
1756
|
-
if (!checkObject(renderbuffer)) {
|
|
1757
|
-
throw new TypeError("deleteRenderbuffer(WebGLRenderbuffer)");
|
|
1758
|
-
}
|
|
1759
|
-
if (!(renderbuffer instanceof WebGLRenderbuffer && this._checkOwns(renderbuffer))) {
|
|
1760
|
-
this.setError(this.INVALID_OPERATION);
|
|
1761
|
-
return;
|
|
1762
|
-
}
|
|
1763
|
-
if (this._activeRenderbuffer === renderbuffer) {
|
|
1764
|
-
this.bindRenderbuffer(this.RENDERBUFFER, null);
|
|
1765
|
-
}
|
|
1766
|
-
const activeFramebuffer = this._activeFramebuffer;
|
|
1767
|
-
this._tryDetachFramebuffer(activeFramebuffer, renderbuffer);
|
|
1768
|
-
renderbuffer._pendingDelete = true;
|
|
1769
|
-
renderbuffer._checkDelete();
|
|
1770
|
-
}
|
|
1771
|
-
deleteShader(shader) {
|
|
1772
|
-
return this._deleteLinkable("deleteShader", shader, WebGLShader);
|
|
1773
|
-
}
|
|
1774
|
-
deleteTexture(texture) {
|
|
1775
|
-
if (!checkObject(texture)) {
|
|
1776
|
-
throw new TypeError("deleteTexture(WebGLTexture)");
|
|
1777
|
-
}
|
|
1778
|
-
if (texture instanceof WebGLTexture) {
|
|
1779
|
-
if (!this._checkOwns(texture)) {
|
|
1780
|
-
this.setError(this.INVALID_OPERATION);
|
|
1781
|
-
return;
|
|
1782
|
-
}
|
|
1783
|
-
} else {
|
|
1784
|
-
return;
|
|
1785
|
-
}
|
|
1786
|
-
const curActive = this._activeTextureUnit;
|
|
1787
|
-
for (let i = 0; i < this._textureUnits.length; ++i) {
|
|
1788
|
-
const unit = this._textureUnits[i];
|
|
1789
|
-
if (unit._bind2D === texture) {
|
|
1790
|
-
this.activeTexture(this.TEXTURE0 + i);
|
|
1791
|
-
this.bindTexture(this.TEXTURE_2D, null);
|
|
1792
|
-
} else if (unit._bindCube === texture) {
|
|
1793
|
-
this.activeTexture(this.TEXTURE0 + i);
|
|
1794
|
-
this.bindTexture(this.TEXTURE_CUBE_MAP, null);
|
|
1795
|
-
}
|
|
1796
|
-
}
|
|
1797
|
-
this.activeTexture(this.TEXTURE0 + curActive);
|
|
1798
|
-
const ctx = this;
|
|
1799
|
-
const activeFramebuffer = this._activeFramebuffer;
|
|
1800
|
-
const tryDetach = (framebuffer) => {
|
|
1801
|
-
if (framebuffer && framebuffer._linked(texture)) {
|
|
1802
|
-
const attachments = ctx._getAttachments();
|
|
1803
|
-
for (let i = 0; i < attachments.length; ++i) {
|
|
1804
|
-
const attachment = attachments[i];
|
|
1805
|
-
if (framebuffer._attachments[attachment] === texture) {
|
|
1806
|
-
ctx.framebufferTexture2D(this.FRAMEBUFFER, attachment, this.TEXTURE_2D, null);
|
|
1807
|
-
}
|
|
1808
|
-
}
|
|
1809
|
-
}
|
|
1810
|
-
};
|
|
1811
|
-
tryDetach(activeFramebuffer);
|
|
1812
|
-
texture._pendingDelete = true;
|
|
1813
|
-
texture._checkDelete();
|
|
1814
|
-
}
|
|
1815
|
-
depthFunc(func) {
|
|
1816
|
-
func |= 0;
|
|
1817
|
-
switch (func) {
|
|
1818
|
-
case this.NEVER:
|
|
1819
|
-
case this.LESS:
|
|
1820
|
-
case this.EQUAL:
|
|
1821
|
-
case this.LEQUAL:
|
|
1822
|
-
case this.GREATER:
|
|
1823
|
-
case this.NOTEQUAL:
|
|
1824
|
-
case this.GEQUAL:
|
|
1825
|
-
case this.ALWAYS: return this._gl.depthFunc(func);
|
|
1826
|
-
default: this.setError(this.INVALID_ENUM);
|
|
1827
|
-
}
|
|
1828
|
-
}
|
|
1829
|
-
depthMask(flag) {
|
|
1830
|
-
return this._gl.depthMask(!!flag);
|
|
1831
|
-
}
|
|
1832
|
-
depthRange(zNear, zFar) {
|
|
1833
|
-
zNear = +zNear;
|
|
1834
|
-
zFar = +zFar;
|
|
1835
|
-
if (zNear <= zFar) {
|
|
1836
|
-
return this._gl.depthRange(zNear, zFar);
|
|
1837
|
-
}
|
|
1838
|
-
this.setError(this.INVALID_OPERATION);
|
|
1839
|
-
}
|
|
1840
|
-
destroy() {
|
|
1841
|
-
warnNotImplemented("destroy");
|
|
1842
|
-
}
|
|
1843
|
-
detachShader(program, shader) {
|
|
1844
|
-
if (!checkObject(program) || !checkObject(shader)) {
|
|
1845
|
-
throw new TypeError("detachShader(WebGLProgram, WebGLShader)");
|
|
1846
|
-
}
|
|
1847
|
-
if (this._checkWrapper(program, WebGLProgram) && this._checkWrapper(shader, WebGLShader)) {
|
|
1848
|
-
if (program._linked(shader)) {
|
|
1849
|
-
this._gl.detachShader(program._, shader._);
|
|
1850
|
-
program._unlink(shader);
|
|
1851
|
-
} else {
|
|
1852
|
-
this.setError(this.INVALID_OPERATION);
|
|
1853
|
-
}
|
|
1854
|
-
}
|
|
1855
|
-
}
|
|
1856
|
-
disable(cap = 0) {
|
|
1857
|
-
this._gl.disable(cap);
|
|
1858
|
-
if (cap === this.TEXTURE_2D || cap === this.TEXTURE_CUBE_MAP) {
|
|
1859
|
-
const active = this._getActiveTextureUnit();
|
|
1860
|
-
if (active._mode === cap) {
|
|
1861
|
-
active._mode = 0;
|
|
1862
|
-
}
|
|
1863
|
-
}
|
|
1864
|
-
}
|
|
1865
|
-
disableVertexAttribArray(index = 0) {
|
|
1866
|
-
if (index < 0 || index >= this._vertexObjectState._attribs.length) {
|
|
1867
|
-
this.setError(this.INVALID_VALUE);
|
|
1868
|
-
return;
|
|
1869
|
-
}
|
|
1870
|
-
this._gl.disableVertexAttribArray(index);
|
|
1871
|
-
this._vertexObjectState._attribs[index]._isPointer = false;
|
|
1872
|
-
}
|
|
1873
|
-
drawArrays(mode = 0, first = 0, count = 0) {
|
|
1874
|
-
if (first < 0 || count < 0) {
|
|
1875
|
-
this.setError(this.INVALID_VALUE);
|
|
1876
|
-
return;
|
|
1877
|
-
}
|
|
1878
|
-
if (!this._checkStencilState()) {
|
|
1879
|
-
return;
|
|
1880
|
-
}
|
|
1881
|
-
const reducedCount = vertexCount(this, mode, count);
|
|
1882
|
-
if (reducedCount < 0) {
|
|
1883
|
-
this.setError(this.INVALID_ENUM);
|
|
1884
|
-
return;
|
|
1885
|
-
}
|
|
1886
|
-
if (!this._framebufferOk()) {
|
|
1887
|
-
return;
|
|
1888
|
-
}
|
|
1889
|
-
if (count === 0) {
|
|
1890
|
-
return;
|
|
1891
|
-
}
|
|
1892
|
-
let maxIndex = first;
|
|
1893
|
-
if (count > 0) {
|
|
1894
|
-
maxIndex = count + first - 1 >>> 0;
|
|
1895
|
-
}
|
|
1896
|
-
if (this._checkVertexAttribState(maxIndex)) {
|
|
1897
|
-
this._gl.drawArrays(mode, first, reducedCount);
|
|
1898
|
-
}
|
|
1899
|
-
}
|
|
1900
|
-
drawElements(mode = 0, count = 0, type = 0, ioffset = 0) {
|
|
1901
|
-
if (count < 0 || ioffset < 0) {
|
|
1902
|
-
this.setError(this.INVALID_VALUE);
|
|
1903
|
-
return;
|
|
1904
|
-
}
|
|
1905
|
-
if (!this._checkStencilState()) {
|
|
1906
|
-
return;
|
|
1907
|
-
}
|
|
1908
|
-
const elementBuffer = this._vertexObjectState._elementArrayBufferBinding;
|
|
1909
|
-
if (!elementBuffer) {
|
|
1910
|
-
this.setError(this.INVALID_OPERATION);
|
|
1911
|
-
return;
|
|
1912
|
-
}
|
|
1913
|
-
let elementData = null;
|
|
1914
|
-
let offset = ioffset;
|
|
1915
|
-
if (type === this.UNSIGNED_SHORT) {
|
|
1916
|
-
if (offset % 2) {
|
|
1917
|
-
this.setError(this.INVALID_OPERATION);
|
|
1918
|
-
return;
|
|
1919
|
-
}
|
|
1920
|
-
offset >>= 1;
|
|
1921
|
-
elementData = new Uint16Array(elementBuffer._elements.buffer);
|
|
1922
|
-
} else if (this._extensions.oes_element_index_uint && type === this.UNSIGNED_INT) {
|
|
1923
|
-
if (offset % 4) {
|
|
1924
|
-
this.setError(this.INVALID_OPERATION);
|
|
1925
|
-
return;
|
|
1926
|
-
}
|
|
1927
|
-
offset >>= 2;
|
|
1928
|
-
elementData = new Uint32Array(elementBuffer._elements.buffer);
|
|
1929
|
-
} else if (type === this.UNSIGNED_BYTE) {
|
|
1930
|
-
elementData = elementBuffer._elements;
|
|
1931
|
-
} else {
|
|
1932
|
-
this.setError(this.INVALID_ENUM);
|
|
1933
|
-
return;
|
|
1934
|
-
}
|
|
1935
|
-
let reducedCount = count;
|
|
1936
|
-
switch (mode) {
|
|
1937
|
-
case this.TRIANGLES:
|
|
1938
|
-
if (count % 3) {
|
|
1939
|
-
reducedCount -= count % 3;
|
|
1940
|
-
}
|
|
1941
|
-
break;
|
|
1942
|
-
case this.LINES:
|
|
1943
|
-
if (count % 2) {
|
|
1944
|
-
reducedCount -= count % 2;
|
|
1945
|
-
}
|
|
1946
|
-
break;
|
|
1947
|
-
case this.POINTS: break;
|
|
1948
|
-
case this.LINE_LOOP:
|
|
1949
|
-
case this.LINE_STRIP:
|
|
1950
|
-
if (count < 2) {
|
|
1951
|
-
this.setError(this.INVALID_OPERATION);
|
|
1952
|
-
return;
|
|
1953
|
-
}
|
|
1954
|
-
break;
|
|
1955
|
-
case this.TRIANGLE_FAN:
|
|
1956
|
-
case this.TRIANGLE_STRIP:
|
|
1957
|
-
if (count < 3) {
|
|
1958
|
-
this.setError(this.INVALID_OPERATION);
|
|
1959
|
-
return;
|
|
1960
|
-
}
|
|
1961
|
-
break;
|
|
1962
|
-
default:
|
|
1963
|
-
this.setError(this.INVALID_ENUM);
|
|
1964
|
-
return;
|
|
1965
|
-
}
|
|
1966
|
-
if (!this._framebufferOk()) {
|
|
1967
|
-
return;
|
|
1968
|
-
}
|
|
1969
|
-
if (count === 0) {
|
|
1970
|
-
this._checkVertexAttribState(0);
|
|
1971
|
-
return;
|
|
1972
|
-
}
|
|
1973
|
-
if (count + offset >>> 0 > elementData.length) {
|
|
1974
|
-
this.setError(this.INVALID_OPERATION);
|
|
1975
|
-
return;
|
|
1976
|
-
}
|
|
1977
|
-
let maxIndex = -1;
|
|
1978
|
-
for (let i = offset; i < offset + count; ++i) {
|
|
1979
|
-
maxIndex = Math.max(maxIndex, elementData[i]);
|
|
1980
|
-
}
|
|
1981
|
-
if (maxIndex < 0) {
|
|
1982
|
-
this._checkVertexAttribState(0);
|
|
1983
|
-
return;
|
|
1984
|
-
}
|
|
1985
|
-
if (this._checkVertexAttribState(maxIndex)) {
|
|
1986
|
-
if (reducedCount > 0) {
|
|
1987
|
-
this._gl.drawElements(mode, reducedCount, type, ioffset);
|
|
1988
|
-
}
|
|
1989
|
-
}
|
|
1990
|
-
}
|
|
1991
|
-
enable(cap = 0) {
|
|
1992
|
-
return this._gl.enable(cap);
|
|
1993
|
-
}
|
|
1994
|
-
enableVertexAttribArray(index) {
|
|
1995
|
-
if (index < 0 || index >= this._vertexObjectState._attribs.length) {
|
|
1996
|
-
this.setError(this.INVALID_VALUE);
|
|
1997
|
-
return;
|
|
1998
|
-
}
|
|
1999
|
-
this._gl.enableVertexAttribArray(index);
|
|
2000
|
-
this._vertexObjectState._attribs[index]._isPointer = true;
|
|
2001
|
-
}
|
|
2002
|
-
finish() {
|
|
2003
|
-
return this._gl.finish();
|
|
2004
|
-
}
|
|
2005
|
-
flush() {
|
|
2006
|
-
return this._gl.flush();
|
|
2007
|
-
}
|
|
2008
|
-
framebufferRenderbuffer(target, attachment, renderbufferTarget, renderbuffer) {
|
|
2009
|
-
if (!checkObject(renderbuffer)) {
|
|
2010
|
-
throw new TypeError("framebufferRenderbuffer(GLenum, GLenum, GLenum, WebGLRenderbuffer)");
|
|
2011
|
-
}
|
|
2012
|
-
if (target !== this.FRAMEBUFFER || !this._validFramebufferAttachment(attachment) || renderbufferTarget !== this.RENDERBUFFER) {
|
|
2013
|
-
this.setError(this.INVALID_ENUM);
|
|
2014
|
-
return;
|
|
2015
|
-
}
|
|
2016
|
-
const framebuffer = this._activeFramebuffer;
|
|
2017
|
-
if (!framebuffer) {
|
|
2018
|
-
this.setError(this.INVALID_OPERATION);
|
|
2019
|
-
return;
|
|
2020
|
-
}
|
|
2021
|
-
if (renderbuffer && !this._checkWrapper(renderbuffer, WebGLRenderbuffer)) {
|
|
2022
|
-
return;
|
|
2023
|
-
}
|
|
2024
|
-
framebuffer._setAttachment(renderbuffer, attachment);
|
|
2025
|
-
this._updateFramebufferAttachments(framebuffer);
|
|
2026
|
-
}
|
|
2027
|
-
framebufferTexture2D(target, attachment, textarget, texture, level = 0) {
|
|
2028
|
-
target |= 0;
|
|
2029
|
-
attachment |= 0;
|
|
2030
|
-
textarget |= 0;
|
|
2031
|
-
level |= 0;
|
|
2032
|
-
if (!checkObject(texture)) {
|
|
2033
|
-
throw new TypeError("framebufferTexture2D(GLenum, GLenum, GLenum, WebGLTexture, GLint)");
|
|
2034
|
-
}
|
|
2035
|
-
if (target !== this.FRAMEBUFFER || !this._validFramebufferAttachment(attachment)) {
|
|
2036
|
-
this.setError(this.INVALID_ENUM);
|
|
2037
|
-
return;
|
|
2038
|
-
}
|
|
2039
|
-
if (level !== 0) {
|
|
2040
|
-
this.setError(this.INVALID_VALUE);
|
|
2041
|
-
return;
|
|
2042
|
-
}
|
|
2043
|
-
if (texture && !this._checkWrapper(texture, WebGLTexture)) {
|
|
2044
|
-
return;
|
|
2045
|
-
}
|
|
2046
|
-
if (textarget === this.TEXTURE_2D) {
|
|
2047
|
-
if (texture && texture._binding !== this.TEXTURE_2D) {
|
|
2048
|
-
this.setError(this.INVALID_OPERATION);
|
|
2049
|
-
return;
|
|
2050
|
-
}
|
|
2051
|
-
} else if (this._validCubeTarget(textarget)) {
|
|
2052
|
-
if (texture && texture._binding !== this.TEXTURE_CUBE_MAP) {
|
|
2053
|
-
this.setError(this.INVALID_OPERATION);
|
|
2054
|
-
return;
|
|
2055
|
-
}
|
|
2056
|
-
} else {
|
|
2057
|
-
this.setError(this.INVALID_ENUM);
|
|
2058
|
-
return;
|
|
2059
|
-
}
|
|
2060
|
-
const framebuffer = this._activeFramebuffer;
|
|
2061
|
-
if (!framebuffer) {
|
|
2062
|
-
this.setError(this.INVALID_OPERATION);
|
|
2063
|
-
return;
|
|
2064
|
-
}
|
|
2065
|
-
framebuffer._attachmentLevel[attachment] = level;
|
|
2066
|
-
framebuffer._attachmentFace[attachment] = textarget;
|
|
2067
|
-
framebuffer._setAttachment(texture, attachment);
|
|
2068
|
-
this._updateFramebufferAttachments(framebuffer);
|
|
2069
|
-
}
|
|
2070
|
-
frontFace(mode = 0) {
|
|
2071
|
-
return this._gl.frontFace(mode);
|
|
2072
|
-
}
|
|
2073
|
-
generateMipmap(target = 0) {
|
|
2074
|
-
return this._gl.generateMipmap(target);
|
|
2075
|
-
}
|
|
2076
|
-
getActiveAttrib(program, index) {
|
|
2077
|
-
if (!checkObject(program)) {
|
|
2078
|
-
throw new TypeError("getActiveAttrib(WebGLProgram)");
|
|
2079
|
-
} else if (!program) {
|
|
2080
|
-
throw new TypeError("getActiveAttrib(WebGLProgram, GLuint)");
|
|
2081
|
-
} else if (this._checkWrapper(program, WebGLProgram)) {
|
|
2082
|
-
const maxCount = program._linkStatus ? program._attributes.length : this._gl.getProgramParameter(program._ | 0, this.ACTIVE_ATTRIBUTES);
|
|
2083
|
-
if (index >= maxCount) {
|
|
2084
|
-
this._gl.getError();
|
|
2085
|
-
this.setError(this.INVALID_VALUE);
|
|
2086
|
-
return null;
|
|
2087
|
-
}
|
|
2088
|
-
const info = this._gl.getActiveAttrib(program._ | 0, index | 0);
|
|
2089
|
-
if (info) {
|
|
2090
|
-
return new WebGLActiveInfo(info);
|
|
2091
|
-
}
|
|
2092
|
-
}
|
|
2093
|
-
return null;
|
|
2094
|
-
}
|
|
2095
|
-
getActiveUniform(program, index) {
|
|
2096
|
-
if (!checkObject(program)) {
|
|
2097
|
-
throw new TypeError("getActiveUniform(WebGLProgram, GLint)");
|
|
2098
|
-
} else if (!program) {
|
|
2099
|
-
throw new TypeError("getActiveUniform(WebGLProgram, GLuint)");
|
|
2100
|
-
} else if (this._checkWrapper(program, WebGLProgram)) {
|
|
2101
|
-
const maxCount = program._linkStatus ? program._uniforms.length : this._gl.getProgramParameter(program._ | 0, this.ACTIVE_UNIFORMS);
|
|
2102
|
-
if (index >= maxCount) {
|
|
2103
|
-
this.setError(this.INVALID_VALUE);
|
|
2104
|
-
return null;
|
|
2105
|
-
}
|
|
2106
|
-
const info = this._gl.getActiveUniform(program._ | 0, index | 0);
|
|
2107
|
-
if (info) {
|
|
2108
|
-
return new WebGLActiveInfo(info);
|
|
2109
|
-
}
|
|
2110
|
-
}
|
|
2111
|
-
return null;
|
|
2112
|
-
}
|
|
2113
|
-
getAttachedShaders(program) {
|
|
2114
|
-
if (!checkObject(program) || typeof program === "object" && program !== null && !(program instanceof WebGLProgram)) {
|
|
2115
|
-
throw new TypeError("getAttachedShaders(WebGLProgram)");
|
|
2116
|
-
}
|
|
2117
|
-
if (!program) {
|
|
2118
|
-
this.setError(this.INVALID_VALUE);
|
|
2119
|
-
} else if (this._checkWrapper(program, WebGLProgram)) {
|
|
2120
|
-
return program._references.filter((r) => r instanceof WebGLShader);
|
|
2121
|
-
}
|
|
2122
|
-
return null;
|
|
2123
|
-
}
|
|
2124
|
-
getAttribLocation(program, name) {
|
|
2125
|
-
if (!checkObject(program)) {
|
|
2126
|
-
throw new TypeError("getAttribLocation(WebGLProgram, String)");
|
|
2127
|
-
}
|
|
2128
|
-
name += "";
|
|
2129
|
-
if (!isValidString(name) || name.length > MAX_ATTRIBUTE_LENGTH) {
|
|
2130
|
-
this.setError(this.INVALID_VALUE);
|
|
2131
|
-
} else if (this._checkWrapper(program, WebGLProgram)) {
|
|
2132
|
-
return this._gl.getAttribLocation(program._ | 0, name + "");
|
|
2133
|
-
}
|
|
2134
|
-
return -1;
|
|
2135
|
-
}
|
|
2136
|
-
getBufferParameter(target = 0, pname = 0) {
|
|
2137
|
-
if (target !== this.ARRAY_BUFFER && target !== this.ELEMENT_ARRAY_BUFFER) {
|
|
2138
|
-
this.setError(this.INVALID_ENUM);
|
|
2139
|
-
return null;
|
|
2140
|
-
}
|
|
2141
|
-
switch (pname) {
|
|
2142
|
-
case this.BUFFER_SIZE:
|
|
2143
|
-
case this.BUFFER_USAGE: return this._gl.getBufferParameteriv(target | 0, pname | 0)[0];
|
|
2144
|
-
default:
|
|
2145
|
-
this.setError(this.INVALID_ENUM);
|
|
2146
|
-
return null;
|
|
2147
|
-
}
|
|
2148
|
-
}
|
|
2149
|
-
getError() {
|
|
2150
|
-
return this._gl.getError();
|
|
2151
|
-
}
|
|
2152
|
-
setError(error) {
|
|
2153
|
-
this._gl.setError(error);
|
|
2154
|
-
}
|
|
2155
|
-
getFramebufferAttachmentParameter(target = 0, attachment = 0, pname = 0) {
|
|
2156
|
-
if (target !== this.FRAMEBUFFER || !this._validFramebufferAttachment(attachment)) {
|
|
2157
|
-
this.setError(this.INVALID_ENUM);
|
|
2158
|
-
return null;
|
|
2159
|
-
}
|
|
2160
|
-
const framebuffer = this._activeFramebuffer;
|
|
2161
|
-
if (!framebuffer) {
|
|
2162
|
-
this.setError(this.INVALID_OPERATION);
|
|
2163
|
-
return null;
|
|
2164
|
-
}
|
|
2165
|
-
const object = framebuffer._attachments[attachment];
|
|
2166
|
-
if (object === null) {
|
|
2167
|
-
if (pname === this.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE) {
|
|
2168
|
-
return this.NONE;
|
|
2169
|
-
}
|
|
2170
|
-
} else if (object instanceof WebGLTexture) {
|
|
2171
|
-
switch (pname) {
|
|
2172
|
-
case this.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: return object;
|
|
2173
|
-
case this.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: return this.TEXTURE;
|
|
2174
|
-
case this.FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: return framebuffer._attachmentLevel[attachment];
|
|
2175
|
-
case this.FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: {
|
|
2176
|
-
const face = framebuffer._attachmentFace[attachment];
|
|
2177
|
-
if (face === this.TEXTURE_2D) {
|
|
2178
|
-
return 0;
|
|
2179
|
-
}
|
|
2180
|
-
return face;
|
|
2181
|
-
}
|
|
2182
|
-
}
|
|
2183
|
-
} else if (object instanceof WebGLRenderbuffer) {
|
|
2184
|
-
switch (pname) {
|
|
2185
|
-
case this.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: return object;
|
|
2186
|
-
case this.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: return this.RENDERBUFFER;
|
|
2187
|
-
}
|
|
2188
|
-
}
|
|
2189
|
-
this.setError(this.INVALID_ENUM);
|
|
2190
|
-
return null;
|
|
2191
|
-
}
|
|
2192
|
-
getParameter(pname = 0) {
|
|
2193
|
-
switch (pname) {
|
|
2194
|
-
case this.ARRAY_BUFFER_BINDING: return this._vertexGlobalState._arrayBufferBinding;
|
|
2195
|
-
case this.ELEMENT_ARRAY_BUFFER_BINDING: return this._vertexObjectState._elementArrayBufferBinding;
|
|
2196
|
-
case this.CURRENT_PROGRAM: return this._activeProgram;
|
|
2197
|
-
case this.FRAMEBUFFER_BINDING: return this._activeFramebuffer;
|
|
2198
|
-
case this.RENDERBUFFER_BINDING: return this._activeRenderbuffer;
|
|
2199
|
-
case this.TEXTURE_BINDING_2D: return this._getActiveTextureUnit()._bind2D;
|
|
2200
|
-
case this.TEXTURE_BINDING_CUBE_MAP: return this._getActiveTextureUnit()._bindCube;
|
|
2201
|
-
case this.VERSION: return "WebGL 1.0 " + VERSION;
|
|
2202
|
-
case this.VENDOR: return "";
|
|
2203
|
-
case this.RENDERER: return "ANGLE";
|
|
2204
|
-
case this.SHADING_LANGUAGE_VERSION: return "WebGL GLSL ES 1.0 ";
|
|
2205
|
-
case this.COMPRESSED_TEXTURE_FORMATS: return new Uint32Array(0);
|
|
2206
|
-
case this.SCISSOR_BOX: return new Int32Array(this._scissorBox);
|
|
2207
|
-
case this.VIEWPORT: return new Int32Array(this._viewport);
|
|
2208
|
-
case this.MAX_VIEWPORT_DIMS: return new Int32Array([32767, 32767]);
|
|
2209
|
-
case this.ALIASED_LINE_WIDTH_RANGE:
|
|
2210
|
-
case this.ALIASED_POINT_SIZE_RANGE: return new Float32Array([1, 1]);
|
|
2211
|
-
case this.DEPTH_RANGE: return new Float32Array([0, 1]);
|
|
2212
|
-
case this.BLEND_COLOR:
|
|
2213
|
-
case this.COLOR_CLEAR_VALUE: return new Float32Array(this._gl.getParameterfv(pname, 4));
|
|
2214
|
-
case this.COLOR_WRITEMASK: {
|
|
2215
|
-
const iv = this._gl.getParameteriv(pname, 4);
|
|
2216
|
-
return [
|
|
2217
|
-
!!iv[0],
|
|
2218
|
-
!!iv[1],
|
|
2219
|
-
!!iv[2],
|
|
2220
|
-
!!iv[3]
|
|
2221
|
-
];
|
|
2222
|
-
}
|
|
2223
|
-
case this.DEPTH_CLEAR_VALUE:
|
|
2224
|
-
case this.LINE_WIDTH:
|
|
2225
|
-
case this.POLYGON_OFFSET_FACTOR:
|
|
2226
|
-
case this.POLYGON_OFFSET_UNITS:
|
|
2227
|
-
case this.SAMPLE_COVERAGE_VALUE: return this._gl.getParameterf(pname);
|
|
2228
|
-
case this.BLEND:
|
|
2229
|
-
case this.CULL_FACE:
|
|
2230
|
-
case this.DEPTH_TEST:
|
|
2231
|
-
case this.DEPTH_WRITEMASK:
|
|
2232
|
-
case this.DITHER:
|
|
2233
|
-
case this.POLYGON_OFFSET_FILL:
|
|
2234
|
-
case this.SAMPLE_COVERAGE_INVERT:
|
|
2235
|
-
case this.SCISSOR_TEST:
|
|
2236
|
-
case this.STENCIL_TEST:
|
|
2237
|
-
case this.UNPACK_PREMULTIPLY_ALPHA_WEBGL: return !!this._gl.getParameteri(pname);
|
|
2238
|
-
case this.UNPACK_FLIP_Y_WEBGL: return this._unpackFlipY;
|
|
2239
|
-
case this.ACTIVE_TEXTURE:
|
|
2240
|
-
case this.ALPHA_BITS:
|
|
2241
|
-
case this.BLEND_DST_ALPHA:
|
|
2242
|
-
case this.BLEND_DST_RGB:
|
|
2243
|
-
case this.BLEND_EQUATION_ALPHA:
|
|
2244
|
-
case this.BLEND_EQUATION_RGB:
|
|
2245
|
-
case this.BLEND_SRC_ALPHA:
|
|
2246
|
-
case this.BLEND_SRC_RGB:
|
|
2247
|
-
case this.BLUE_BITS:
|
|
2248
|
-
case this.CULL_FACE_MODE:
|
|
2249
|
-
case this.DEPTH_BITS:
|
|
2250
|
-
case this.DEPTH_FUNC:
|
|
2251
|
-
case this.FRONT_FACE:
|
|
2252
|
-
case this.GENERATE_MIPMAP_HINT:
|
|
2253
|
-
case this.GREEN_BITS:
|
|
2254
|
-
case this.MAX_COMBINED_TEXTURE_IMAGE_UNITS:
|
|
2255
|
-
case this.MAX_CUBE_MAP_TEXTURE_SIZE:
|
|
2256
|
-
case this.MAX_FRAGMENT_UNIFORM_VECTORS:
|
|
2257
|
-
case this.MAX_RENDERBUFFER_SIZE:
|
|
2258
|
-
case this.MAX_TEXTURE_IMAGE_UNITS:
|
|
2259
|
-
case this.MAX_TEXTURE_SIZE:
|
|
2260
|
-
case this.MAX_VARYING_VECTORS:
|
|
2261
|
-
case this.MAX_VERTEX_ATTRIBS:
|
|
2262
|
-
case this.MAX_VERTEX_TEXTURE_IMAGE_UNITS:
|
|
2263
|
-
case this.MAX_VERTEX_UNIFORM_VECTORS:
|
|
2264
|
-
case this.PACK_ALIGNMENT:
|
|
2265
|
-
case this.RED_BITS:
|
|
2266
|
-
case this.SAMPLE_BUFFERS:
|
|
2267
|
-
case this.SAMPLES:
|
|
2268
|
-
case this.STENCIL_BACK_FAIL:
|
|
2269
|
-
case this.STENCIL_BACK_FUNC:
|
|
2270
|
-
case this.STENCIL_BACK_PASS_DEPTH_FAIL:
|
|
2271
|
-
case this.STENCIL_BACK_PASS_DEPTH_PASS:
|
|
2272
|
-
case this.STENCIL_BACK_REF:
|
|
2273
|
-
case this.STENCIL_BACK_VALUE_MASK:
|
|
2274
|
-
case this.STENCIL_BACK_WRITEMASK:
|
|
2275
|
-
case this.STENCIL_BITS:
|
|
2276
|
-
case this.STENCIL_CLEAR_VALUE:
|
|
2277
|
-
case this.STENCIL_FAIL:
|
|
2278
|
-
case this.STENCIL_FUNC:
|
|
2279
|
-
case this.STENCIL_PASS_DEPTH_FAIL:
|
|
2280
|
-
case this.STENCIL_PASS_DEPTH_PASS:
|
|
2281
|
-
case this.STENCIL_REF:
|
|
2282
|
-
case this.STENCIL_VALUE_MASK:
|
|
2283
|
-
case this.STENCIL_WRITEMASK:
|
|
2284
|
-
case this.SUBPIXEL_BITS:
|
|
2285
|
-
case this.UNPACK_ALIGNMENT:
|
|
2286
|
-
case this.UNPACK_COLORSPACE_CONVERSION_WEBGL: return this._gl.getParameteri(pname);
|
|
2287
|
-
case this.IMPLEMENTATION_COLOR_READ_FORMAT:
|
|
2288
|
-
case this.IMPLEMENTATION_COLOR_READ_TYPE: return this._getParameterDirect(pname);
|
|
2289
|
-
default:
|
|
2290
|
-
if (this._extensions.webgl_draw_buffers) {
|
|
2291
|
-
const ext = this._extensions.webgl_draw_buffers;
|
|
2292
|
-
switch (pname) {
|
|
2293
|
-
case ext.DRAW_BUFFER0_WEBGL:
|
|
2294
|
-
case ext.DRAW_BUFFER1_WEBGL:
|
|
2295
|
-
case ext.DRAW_BUFFER2_WEBGL:
|
|
2296
|
-
case ext.DRAW_BUFFER3_WEBGL:
|
|
2297
|
-
case ext.DRAW_BUFFER4_WEBGL:
|
|
2298
|
-
case ext.DRAW_BUFFER5_WEBGL:
|
|
2299
|
-
case ext.DRAW_BUFFER6_WEBGL:
|
|
2300
|
-
case ext.DRAW_BUFFER7_WEBGL:
|
|
2301
|
-
case ext.DRAW_BUFFER8_WEBGL:
|
|
2302
|
-
case ext.DRAW_BUFFER9_WEBGL:
|
|
2303
|
-
case ext.DRAW_BUFFER10_WEBGL:
|
|
2304
|
-
case ext.DRAW_BUFFER11_WEBGL:
|
|
2305
|
-
case ext.DRAW_BUFFER12_WEBGL:
|
|
2306
|
-
case ext.DRAW_BUFFER13_WEBGL:
|
|
2307
|
-
case ext.DRAW_BUFFER14_WEBGL:
|
|
2308
|
-
case ext.DRAW_BUFFER15_WEBGL:
|
|
2309
|
-
if (ext._buffersState.length === 1 && ext._buffersState[0] === this.BACK) {
|
|
2310
|
-
return this.BACK;
|
|
2311
|
-
}
|
|
2312
|
-
return this._getParameterDirect(pname);
|
|
2313
|
-
case ext.MAX_DRAW_BUFFERS_WEBGL:
|
|
2314
|
-
case ext.MAX_COLOR_ATTACHMENTS_WEBGL: return this._getParameterDirect(pname);
|
|
2315
|
-
}
|
|
2316
|
-
}
|
|
2317
|
-
if (this._extensions.oes_standard_derivatives && pname === this._extensions.oes_standard_derivatives.FRAGMENT_SHADER_DERIVATIVE_HINT_OES) {
|
|
2318
|
-
return this._getParameterDirect(pname);
|
|
2319
|
-
}
|
|
2320
|
-
if (this._extensions.ext_texture_filter_anisotropic && pname === this._extensions.ext_texture_filter_anisotropic.MAX_TEXTURE_MAX_ANISOTROPY_EXT) {
|
|
2321
|
-
return this._getParameterDirect(pname);
|
|
2322
|
-
}
|
|
2323
|
-
if (this._extensions.oes_vertex_array_object && pname === this._extensions.oes_vertex_array_object.VERTEX_ARRAY_BINDING_OES) {
|
|
2324
|
-
return this._extensions.oes_vertex_array_object._activeVertexArrayObject;
|
|
2325
|
-
}
|
|
2326
|
-
this.setError(this.INVALID_ENUM);
|
|
2327
|
-
return null;
|
|
2328
|
-
}
|
|
2329
|
-
}
|
|
2330
|
-
getProgramInfoLog(program) {
|
|
2331
|
-
if (!checkObject(program)) {
|
|
2332
|
-
throw new TypeError("getProgramInfoLog(WebGLProgram)");
|
|
2333
|
-
} else if (this._checkWrapper(program, WebGLProgram)) {
|
|
2334
|
-
return program._linkInfoLog;
|
|
2335
|
-
}
|
|
2336
|
-
return null;
|
|
2337
|
-
}
|
|
2338
|
-
getProgramParameter(program, pname = 0) {
|
|
2339
|
-
if (!checkObject(program)) {
|
|
2340
|
-
throw new TypeError("getProgramParameter(WebGLProgram, GLenum)");
|
|
2341
|
-
} else if (this._checkWrapper(program, WebGLProgram)) {
|
|
2342
|
-
switch (pname) {
|
|
2343
|
-
case this.DELETE_STATUS: return program._pendingDelete;
|
|
2344
|
-
case this.LINK_STATUS: return program._linkStatus;
|
|
2345
|
-
case this.VALIDATE_STATUS: return !!this._gl.getProgramParameter(program._, pname);
|
|
2346
|
-
case this.ATTACHED_SHADERS: return this._gl.getProgramParameter(program._, pname);
|
|
2347
|
-
case this.ACTIVE_ATTRIBUTES: return program._linkStatus ? program._attributes.length : this._gl.getProgramParameter(program._, pname);
|
|
2348
|
-
case this.ACTIVE_UNIFORMS: return program._linkStatus ? program._uniforms.length : this._gl.getProgramParameter(program._, pname);
|
|
2349
|
-
}
|
|
2350
|
-
this.setError(this.INVALID_ENUM);
|
|
2351
|
-
}
|
|
2352
|
-
return null;
|
|
2353
|
-
}
|
|
2354
|
-
getRenderbufferParameter(target = 0, pname = 0) {
|
|
2355
|
-
if (target !== this.RENDERBUFFER) {
|
|
2356
|
-
this.setError(this.INVALID_ENUM);
|
|
2357
|
-
return null;
|
|
2358
|
-
}
|
|
2359
|
-
const renderbuffer = this._activeRenderbuffer;
|
|
2360
|
-
if (!renderbuffer) {
|
|
2361
|
-
this.setError(this.INVALID_OPERATION);
|
|
2362
|
-
return null;
|
|
2363
|
-
}
|
|
2364
|
-
switch (pname) {
|
|
2365
|
-
case this.RENDERBUFFER_INTERNAL_FORMAT: return renderbuffer._format;
|
|
2366
|
-
case this.RENDERBUFFER_WIDTH: return renderbuffer._width;
|
|
2367
|
-
case this.RENDERBUFFER_HEIGHT: return renderbuffer._height;
|
|
2368
|
-
case this.MAX_RENDERBUFFER_SIZE:
|
|
2369
|
-
case this.RENDERBUFFER_RED_SIZE:
|
|
2370
|
-
case this.RENDERBUFFER_GREEN_SIZE:
|
|
2371
|
-
case this.RENDERBUFFER_BLUE_SIZE:
|
|
2372
|
-
case this.RENDERBUFFER_ALPHA_SIZE:
|
|
2373
|
-
case this.RENDERBUFFER_DEPTH_SIZE:
|
|
2374
|
-
case this.RENDERBUFFER_STENCIL_SIZE: return this._gl.getRenderbufferParameter(target, pname);
|
|
2375
|
-
}
|
|
2376
|
-
this.setError(this.INVALID_ENUM);
|
|
2377
|
-
return null;
|
|
2378
|
-
}
|
|
2379
|
-
getShaderInfoLog(shader) {
|
|
2380
|
-
if (!checkObject(shader)) {
|
|
2381
|
-
throw new TypeError("getShaderInfoLog(WebGLShader)");
|
|
2382
|
-
} else if (this._checkWrapper(shader, WebGLShader)) {
|
|
2383
|
-
return shader._compileInfo;
|
|
2384
|
-
}
|
|
2385
|
-
return null;
|
|
2386
|
-
}
|
|
2387
|
-
getShaderParameter(shader, pname = 0) {
|
|
2388
|
-
if (!checkObject(shader)) {
|
|
2389
|
-
throw new TypeError("getShaderParameter(WebGLShader, GLenum)");
|
|
2390
|
-
} else if (this._checkWrapper(shader, WebGLShader)) {
|
|
2391
|
-
switch (pname) {
|
|
2392
|
-
case this.DELETE_STATUS: return shader._pendingDelete;
|
|
2393
|
-
case this.COMPILE_STATUS: return shader._compileStatus;
|
|
2394
|
-
case this.SHADER_TYPE: return shader._type;
|
|
2395
|
-
}
|
|
2396
|
-
this.setError(this.INVALID_ENUM);
|
|
2397
|
-
}
|
|
2398
|
-
return null;
|
|
2399
|
-
}
|
|
2400
|
-
getShaderPrecisionFormat(shaderType = 0, precisionType = 0) {
|
|
2401
|
-
if (!(shaderType === this.FRAGMENT_SHADER || shaderType === this.VERTEX_SHADER) || !(precisionType === this.LOW_FLOAT || precisionType === this.MEDIUM_FLOAT || precisionType === this.HIGH_FLOAT || precisionType === this.LOW_INT || precisionType === this.MEDIUM_INT || precisionType === this.HIGH_INT)) {
|
|
2402
|
-
this.setError(this.INVALID_ENUM);
|
|
2403
|
-
return null;
|
|
2404
|
-
}
|
|
2405
|
-
const format = this._gl.getShaderPrecisionFormat(shaderType, precisionType);
|
|
2406
|
-
if (!format) {
|
|
2407
|
-
return null;
|
|
2408
|
-
}
|
|
2409
|
-
return new WebGLShaderPrecisionFormat(format);
|
|
2410
|
-
}
|
|
2411
|
-
getShaderSource(shader) {
|
|
2412
|
-
if (!checkObject(shader)) {
|
|
2413
|
-
throw new TypeError("Input to getShaderSource must be an object");
|
|
2414
|
-
} else if (this._checkWrapper(shader, WebGLShader)) {
|
|
2415
|
-
return shader._source;
|
|
2416
|
-
}
|
|
2417
|
-
return null;
|
|
2418
|
-
}
|
|
2419
|
-
getSupportedExtensions() {
|
|
2420
|
-
const exts = [
|
|
2421
|
-
"ANGLE_instanced_arrays",
|
|
2422
|
-
"STACKGL_resize_drawingbuffer",
|
|
2423
|
-
"STACKGL_destroy_context"
|
|
2424
|
-
];
|
|
2425
|
-
const supportedExts = this._gl.getSupportedExtensions();
|
|
2426
|
-
if (!supportedExts) {
|
|
2427
|
-
return exts;
|
|
2428
|
-
}
|
|
2429
|
-
if (supportedExts.indexOf("GL_OES_element_index_uint") >= 0) {
|
|
2430
|
-
exts.push("OES_element_index_uint");
|
|
2431
|
-
}
|
|
2432
|
-
if (supportedExts.indexOf("GL_OES_standard_derivatives") >= 0) {
|
|
2433
|
-
exts.push("OES_standard_derivatives");
|
|
2434
|
-
}
|
|
2435
|
-
if (supportedExts.indexOf("GL_OES_texture_float") >= 0) {
|
|
2436
|
-
exts.push("OES_texture_float");
|
|
2437
|
-
}
|
|
2438
|
-
if (supportedExts.indexOf("GL_OES_texture_float_linear") >= 0) {
|
|
2439
|
-
exts.push("OES_texture_float_linear");
|
|
2440
|
-
}
|
|
2441
|
-
if (supportedExts.indexOf("GL_OES_texture_half_float") >= 0 || supportedExts.indexOf("GL_ARB_half_float_pixel") >= 0) {
|
|
2442
|
-
exts.push("OES_texture_half_float");
|
|
2443
|
-
}
|
|
2444
|
-
if (supportedExts.indexOf("GL_EXT_color_buffer_float") >= 0 || supportedExts.indexOf("GL_ARB_color_buffer_float") >= 0) {
|
|
2445
|
-
exts.push("EXT_color_buffer_float");
|
|
2446
|
-
}
|
|
2447
|
-
if (supportedExts.indexOf("GL_EXT_color_buffer_half_float") >= 0) {
|
|
2448
|
-
exts.push("EXT_color_buffer_half_float");
|
|
2449
|
-
}
|
|
2450
|
-
if (supportedExts.indexOf("EXT_draw_buffers") >= 0) {
|
|
2451
|
-
exts.push("WEBGL_draw_buffers");
|
|
2452
|
-
}
|
|
2453
|
-
if (supportedExts.indexOf("EXT_blend_minmax") >= 0) {
|
|
2454
|
-
exts.push("EXT_blend_minmax");
|
|
2455
|
-
}
|
|
2456
|
-
if (supportedExts.indexOf("EXT_texture_filter_anisotropic") >= 0) {
|
|
2457
|
-
exts.push("EXT_texture_filter_anisotropic");
|
|
2458
|
-
}
|
|
2459
|
-
if (supportedExts.indexOf("GL_OES_vertex_array_object") >= 0) {
|
|
2460
|
-
exts.push("OES_vertex_array_object");
|
|
2461
|
-
}
|
|
2462
|
-
return exts;
|
|
2463
|
-
}
|
|
2464
|
-
_getTexParameterDirect(target = 0, pname = 0) {
|
|
2465
|
-
return this._gl.getTexParameterx(target, pname)?.unpack();
|
|
2466
|
-
}
|
|
2467
|
-
getTexParameter(target = 0, pname = 0) {
|
|
2468
|
-
if (!this._checkTextureTarget(target)) {
|
|
2469
|
-
return null;
|
|
2470
|
-
}
|
|
2471
|
-
const unit = this._getActiveTextureUnit();
|
|
2472
|
-
if (target === this.TEXTURE_2D && !unit._bind2D || target === this.TEXTURE_CUBE_MAP && !unit._bindCube) {
|
|
2473
|
-
this.setError(this.INVALID_OPERATION);
|
|
2474
|
-
return null;
|
|
2475
|
-
}
|
|
2476
|
-
switch (pname) {
|
|
2477
|
-
case this.TEXTURE_MAG_FILTER:
|
|
2478
|
-
case this.TEXTURE_MIN_FILTER:
|
|
2479
|
-
case this.TEXTURE_WRAP_S:
|
|
2480
|
-
case this.TEXTURE_WRAP_T: return this._getTexParameterDirect(target, pname);
|
|
2481
|
-
}
|
|
2482
|
-
if (this._extensions.ext_texture_filter_anisotropic && pname === this._extensions.ext_texture_filter_anisotropic.TEXTURE_MAX_ANISOTROPY_EXT) {
|
|
2483
|
-
return this._getTexParameterDirect(target, pname);
|
|
2484
|
-
}
|
|
2485
|
-
this.setError(this.INVALID_ENUM);
|
|
2486
|
-
return null;
|
|
2487
|
-
}
|
|
2488
|
-
getUniform(program, location) {
|
|
2489
|
-
if (!checkObject(program) || !checkObject(location)) {
|
|
2490
|
-
throw new TypeError("getUniform(WebGLProgram, WebGLUniformLocation)");
|
|
2491
|
-
} else if (!program) {
|
|
2492
|
-
this.setError(this.INVALID_VALUE);
|
|
2493
|
-
return null;
|
|
2494
|
-
} else if (!location) {
|
|
2495
|
-
return null;
|
|
2496
|
-
} else if (this._checkWrapper(program, WebGLProgram)) {
|
|
2497
|
-
if (!checkUniform(program, location)) {
|
|
2498
|
-
this.setError(this.INVALID_OPERATION);
|
|
2499
|
-
return null;
|
|
2500
|
-
}
|
|
2501
|
-
const data = this._gl.getUniform(program._ | 0, location._ | 0);
|
|
2502
|
-
if (!data) {
|
|
2503
|
-
return null;
|
|
2504
|
-
}
|
|
2505
|
-
switch (location._activeInfo.type) {
|
|
2506
|
-
case this.FLOAT: return data[0];
|
|
2507
|
-
case this.FLOAT_VEC2: return new Float32Array(data.slice(0, 2));
|
|
2508
|
-
case this.FLOAT_VEC3: return new Float32Array(data.slice(0, 3));
|
|
2509
|
-
case this.FLOAT_VEC4: return new Float32Array(data.slice(0, 4));
|
|
2510
|
-
case this.INT: return data[0] | 0;
|
|
2511
|
-
case this.INT_VEC2: return new Int32Array(data.slice(0, 2));
|
|
2512
|
-
case this.INT_VEC3: return new Int32Array(data.slice(0, 3));
|
|
2513
|
-
case this.INT_VEC4: return new Int32Array(data.slice(0, 4));
|
|
2514
|
-
case this.BOOL: return !!data[0];
|
|
2515
|
-
case this.BOOL_VEC2: return [!!data[0], !!data[1]];
|
|
2516
|
-
case this.BOOL_VEC3: return [
|
|
2517
|
-
!!data[0],
|
|
2518
|
-
!!data[1],
|
|
2519
|
-
!!data[2]
|
|
2520
|
-
];
|
|
2521
|
-
case this.BOOL_VEC4: return [
|
|
2522
|
-
!!data[0],
|
|
2523
|
-
!!data[1],
|
|
2524
|
-
!!data[2],
|
|
2525
|
-
!!data[3]
|
|
2526
|
-
];
|
|
2527
|
-
case this.FLOAT_MAT2: return new Float32Array(data.slice(0, 4));
|
|
2528
|
-
case this.FLOAT_MAT3: return new Float32Array(data.slice(0, 9));
|
|
2529
|
-
case this.FLOAT_MAT4: return new Float32Array(data.slice(0, 16));
|
|
2530
|
-
case this.SAMPLER_2D:
|
|
2531
|
-
case this.SAMPLER_CUBE: return data[0] | 0;
|
|
2532
|
-
default: return null;
|
|
2533
|
-
}
|
|
2534
|
-
}
|
|
2535
|
-
return null;
|
|
2536
|
-
}
|
|
2537
|
-
getUniformLocation(program, name) {
|
|
2538
|
-
if (!checkObject(program)) {
|
|
2539
|
-
throw new TypeError("getUniformLocation(WebGLProgram, String)");
|
|
2540
|
-
}
|
|
2541
|
-
name += "";
|
|
2542
|
-
if (!isValidString(name)) {
|
|
2543
|
-
this.setError(this.INVALID_VALUE);
|
|
2544
|
-
return null;
|
|
2545
|
-
}
|
|
2546
|
-
if (this._checkWrapper(program, WebGLProgram)) {
|
|
2547
|
-
const loc = this._gl.getUniformLocation(program._ | 0, name);
|
|
2548
|
-
if (loc !== null && loc >= 0) {
|
|
2549
|
-
let searchName = name;
|
|
2550
|
-
if (/\[\d+\]$/.test(name)) {
|
|
2551
|
-
searchName = name.replace(/\[\d+\]$/, "[0]");
|
|
2552
|
-
}
|
|
2553
|
-
const arraySearchName = searchName + "[0]";
|
|
2554
|
-
let info = null;
|
|
2555
|
-
for (let i = 0; i < program._uniforms.length; ++i) {
|
|
2556
|
-
const infoItem = program._uniforms[i];
|
|
2557
|
-
if (infoItem.name === searchName || infoItem.name === arraySearchName) {
|
|
2558
|
-
info = {
|
|
2559
|
-
size: infoItem.size,
|
|
2560
|
-
type: infoItem.type,
|
|
2561
|
-
name: infoItem.name
|
|
2562
|
-
};
|
|
2563
|
-
break;
|
|
2564
|
-
}
|
|
2565
|
-
}
|
|
2566
|
-
if (!info) {
|
|
2567
|
-
info = {
|
|
2568
|
-
name: searchName,
|
|
2569
|
-
type: 0,
|
|
2570
|
-
size: 1
|
|
2571
|
-
};
|
|
2572
|
-
}
|
|
2573
|
-
const result = new WebGLUniformLocation(loc, program, info);
|
|
2574
|
-
const callerBracketMatch = name.match(/\[(\d+)\]$/);
|
|
2575
|
-
const callerIndex = callerBracketMatch ? +callerBracketMatch[1] : -1;
|
|
2576
|
-
const infoIsArray = /\[0\]$/.test(info.name);
|
|
2577
|
-
if (infoIsArray && (callerIndex === -1 || callerIndex === 0)) {
|
|
2578
|
-
const baseName = info.name.replace(/\[0\]$/, "");
|
|
2579
|
-
const arrayLocs = [];
|
|
2580
|
-
this._saveError();
|
|
2581
|
-
for (let i = 0; this.getError() === this.NO_ERROR; ++i) {
|
|
2582
|
-
const xloc = this._gl.getUniformLocation(program._ | 0, baseName + "[" + i + "]");
|
|
2583
|
-
if (this.getError() !== this.NO_ERROR || xloc == null || xloc < 0) {
|
|
2584
|
-
break;
|
|
2585
|
-
}
|
|
2586
|
-
arrayLocs.push(xloc);
|
|
2587
|
-
}
|
|
2588
|
-
this._restoreError(this.NO_ERROR);
|
|
2589
|
-
result._array = arrayLocs;
|
|
2590
|
-
} else if (callerIndex > 0) {
|
|
2591
|
-
if (callerIndex >= info.size) {
|
|
2592
|
-
return null;
|
|
2593
|
-
}
|
|
2594
|
-
}
|
|
2595
|
-
return result;
|
|
2596
|
-
}
|
|
2597
|
-
}
|
|
2598
|
-
return null;
|
|
2599
|
-
}
|
|
2600
|
-
getVertexAttrib(index = 0, pname = 0) {
|
|
2601
|
-
if (index < 0 || index >= this._vertexObjectState._attribs.length) {
|
|
2602
|
-
this.setError(this.INVALID_VALUE);
|
|
2603
|
-
return null;
|
|
2604
|
-
}
|
|
2605
|
-
const attrib = this._vertexObjectState._attribs[index];
|
|
2606
|
-
const vertexAttribValue = this._vertexGlobalState._attribs[index]._data;
|
|
2607
|
-
const extInstancing = this._extensions.angle_instanced_arrays;
|
|
2608
|
-
if (extInstancing) {
|
|
2609
|
-
if (pname === extInstancing.VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE) {
|
|
2610
|
-
return attrib._divisor;
|
|
2611
|
-
}
|
|
2612
|
-
}
|
|
2613
|
-
switch (pname) {
|
|
2614
|
-
case this.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: return attrib._pointerBuffer;
|
|
2615
|
-
case this.VERTEX_ATTRIB_ARRAY_ENABLED: return attrib._isPointer;
|
|
2616
|
-
case this.VERTEX_ATTRIB_ARRAY_SIZE: return attrib._inputSize;
|
|
2617
|
-
case this.VERTEX_ATTRIB_ARRAY_STRIDE: return attrib._inputStride;
|
|
2618
|
-
case this.VERTEX_ATTRIB_ARRAY_TYPE: return attrib._pointerType;
|
|
2619
|
-
case this.VERTEX_ATTRIB_ARRAY_NORMALIZED: return attrib._pointerNormal;
|
|
2620
|
-
case this.CURRENT_VERTEX_ATTRIB: return new Float32Array(vertexAttribValue);
|
|
2621
|
-
default:
|
|
2622
|
-
this.setError(this.INVALID_ENUM);
|
|
2623
|
-
return null;
|
|
2624
|
-
}
|
|
2625
|
-
}
|
|
2626
|
-
getVertexAttribOffset(index = 0, pname = 0) {
|
|
2627
|
-
if (index < 0 || index >= this._vertexObjectState._attribs.length) {
|
|
2628
|
-
this.setError(this.INVALID_VALUE);
|
|
2629
|
-
return -1;
|
|
2630
|
-
}
|
|
2631
|
-
if (pname === this.VERTEX_ATTRIB_ARRAY_POINTER) {
|
|
2632
|
-
return this._vertexObjectState._attribs[index]._pointerOffset;
|
|
2633
|
-
} else {
|
|
2634
|
-
this.setError(this.INVALID_ENUM);
|
|
2635
|
-
return -1;
|
|
2636
|
-
}
|
|
2637
|
-
}
|
|
2638
|
-
hint(target = 0, mode = 0) {
|
|
2639
|
-
if (!(target === this.GENERATE_MIPMAP_HINT || this._extensions.oes_standard_derivatives && target === this._extensions.oes_standard_derivatives.FRAGMENT_SHADER_DERIVATIVE_HINT_OES)) {
|
|
2640
|
-
this.setError(this.INVALID_ENUM);
|
|
2641
|
-
return;
|
|
2642
|
-
}
|
|
2643
|
-
if (mode !== this.FASTEST && mode !== this.NICEST && mode !== this.DONT_CARE) {
|
|
2644
|
-
this.setError(this.INVALID_ENUM);
|
|
2645
|
-
return;
|
|
2646
|
-
}
|
|
2647
|
-
return this._gl.hint(target, mode);
|
|
2648
|
-
}
|
|
2649
|
-
isBuffer(buffer) {
|
|
2650
|
-
if (!this._isObject(buffer, "isBuffer", WebGLBuffer)) return false;
|
|
2651
|
-
return this._gl.isBuffer(buffer?._);
|
|
2652
|
-
}
|
|
2653
|
-
isContextLost() {
|
|
2654
|
-
return false;
|
|
2655
|
-
}
|
|
2656
|
-
isEnabled(cap = 0) {
|
|
2657
|
-
return this._gl.isEnabled(cap);
|
|
2658
|
-
}
|
|
2659
|
-
isFramebuffer(framebuffer) {
|
|
2660
|
-
if (!this._isObject(framebuffer, "isFramebuffer", WebGLFramebuffer)) return false;
|
|
2661
|
-
return this._gl.isFramebuffer(framebuffer?._);
|
|
2662
|
-
}
|
|
2663
|
-
isProgram(program) {
|
|
2664
|
-
if (!this._isObject(program, "isProgram", WebGLProgram)) return false;
|
|
2665
|
-
return this._gl.isProgram(program?._);
|
|
2666
|
-
}
|
|
2667
|
-
isRenderbuffer(renderbuffer) {
|
|
2668
|
-
if (!this._isObject(renderbuffer, "isRenderbuffer", WebGLRenderbuffer)) return false;
|
|
2669
|
-
return this._gl.isRenderbuffer(renderbuffer?._);
|
|
2670
|
-
}
|
|
2671
|
-
isShader(shader) {
|
|
2672
|
-
if (!this._isObject(shader, "isShader", WebGLShader)) return false;
|
|
2673
|
-
return this._gl.isShader(shader?._);
|
|
2674
|
-
}
|
|
2675
|
-
isTexture(texture) {
|
|
2676
|
-
if (!this._isObject(texture, "isTexture", WebGLTexture)) return false;
|
|
2677
|
-
return this._gl.isTexture(texture?._);
|
|
2678
|
-
}
|
|
2679
|
-
lineWidth(width) {
|
|
2680
|
-
if (isNaN(width)) {
|
|
2681
|
-
this.setError(this.INVALID_VALUE);
|
|
2682
|
-
return;
|
|
2683
|
-
}
|
|
2684
|
-
return this._gl.lineWidth(+width);
|
|
2685
|
-
}
|
|
2686
|
-
linkProgram(program) {
|
|
2687
|
-
if (!checkObject(program)) {
|
|
2688
|
-
throw new TypeError("linkProgram(WebGLProgram)");
|
|
2689
|
-
}
|
|
2690
|
-
if (this._checkWrapper(program, WebGLProgram)) {
|
|
2691
|
-
program._linkCount += 1;
|
|
2692
|
-
program._attributes = [];
|
|
2693
|
-
const prevError = this.getError();
|
|
2694
|
-
for (const s of program._references) {
|
|
2695
|
-
if (s instanceof WebGLShader && s._needsRecompile) {
|
|
2696
|
-
this._gl.compileShader(s._ | 0);
|
|
2697
|
-
s._needsRecompile = false;
|
|
2698
|
-
}
|
|
2699
|
-
}
|
|
2700
|
-
this._gl.linkProgram(program._ | 0);
|
|
2701
|
-
const error = this.getError();
|
|
2702
|
-
if (error === this.NO_ERROR) {
|
|
2703
|
-
program._linkStatus = this._fixupLink(program);
|
|
2704
|
-
}
|
|
2705
|
-
this.getError();
|
|
2706
|
-
this.setError(prevError || error);
|
|
2707
|
-
}
|
|
2708
|
-
}
|
|
2709
|
-
/** The `WebGLRenderingContext.pixelStorei()` method of the WebGL API specifies the pixel storage modes. */
|
|
2710
|
-
pixelStorei(pname = 0, param = 0) {
|
|
2711
|
-
if (typeof param === "boolean") {
|
|
2712
|
-
param = param === false ? 0 : 1;
|
|
2713
|
-
}
|
|
2714
|
-
if (pname === this.UNPACK_ALIGNMENT) {
|
|
2715
|
-
if (param === 1 || param === 2 || param === 4 || param === 8) {
|
|
2716
|
-
this._unpackAlignment = param;
|
|
2717
|
-
} else {
|
|
2718
|
-
this.setError(this.INVALID_VALUE);
|
|
2719
|
-
return;
|
|
2720
|
-
}
|
|
2721
|
-
} else if (pname === this.PACK_ALIGNMENT) {
|
|
2722
|
-
if (param === 1 || param === 2 || param === 4 || param === 8) {
|
|
2723
|
-
this._packAlignment = param;
|
|
2724
|
-
} else {
|
|
2725
|
-
this.setError(this.INVALID_VALUE);
|
|
2726
|
-
return;
|
|
2727
|
-
}
|
|
2728
|
-
} else if (pname === this.UNPACK_COLORSPACE_CONVERSION_WEBGL) {
|
|
2729
|
-
if (!(param === this.NONE || param === this.BROWSER_DEFAULT_WEBGL)) {
|
|
2730
|
-
this.setError(this.INVALID_VALUE);
|
|
2731
|
-
return;
|
|
2732
|
-
}
|
|
2733
|
-
} else if (pname === this.UNPACK_FLIP_Y_WEBGL) {
|
|
2734
|
-
this._unpackFlipY = !!param;
|
|
2735
|
-
return;
|
|
2736
|
-
} else if (pname === this.UNPACK_PREMULTIPLY_ALPHA_WEBGL) {
|
|
2737
|
-
this._unpackPremultAlpha = !!param;
|
|
2738
|
-
return;
|
|
2739
|
-
}
|
|
2740
|
-
return this._gl.pixelStorei(pname, param);
|
|
2741
|
-
}
|
|
2742
|
-
polygonOffset(factor, units) {
|
|
2743
|
-
return this._gl.polygonOffset(+factor, +units);
|
|
2744
|
-
}
|
|
2745
|
-
renderbufferStorage(target = 0, internalFormat = 0, width = 0, height = 0) {
|
|
2746
|
-
if (target !== this.RENDERBUFFER) {
|
|
2747
|
-
this.setError(this.INVALID_ENUM);
|
|
2748
|
-
return;
|
|
2749
|
-
}
|
|
2750
|
-
const renderbuffer = this._activeRenderbuffer;
|
|
2751
|
-
if (!renderbuffer) {
|
|
2752
|
-
this.setError(this.INVALID_OPERATION);
|
|
2753
|
-
return;
|
|
2754
|
-
}
|
|
2755
|
-
if (internalFormat !== this.RGBA4 && internalFormat !== this.RGB565 && internalFormat !== this.RGB5_A1 && internalFormat !== this.DEPTH_COMPONENT16 && internalFormat !== this.STENCIL_INDEX && internalFormat !== this.STENCIL_INDEX8 && internalFormat !== this.DEPTH_STENCIL) {
|
|
2756
|
-
this.setError(this.INVALID_ENUM);
|
|
2757
|
-
return;
|
|
2758
|
-
}
|
|
2759
|
-
this._saveError();
|
|
2760
|
-
this._gl.renderbufferStorage(target, internalFormat, width, height);
|
|
2761
|
-
const error = this.getError();
|
|
2762
|
-
this._restoreError(error);
|
|
2763
|
-
if (error !== this.NO_ERROR) {
|
|
2764
|
-
return;
|
|
2765
|
-
}
|
|
2766
|
-
renderbuffer._width = width;
|
|
2767
|
-
renderbuffer._height = height;
|
|
2768
|
-
renderbuffer._format = internalFormat;
|
|
2769
|
-
const activeFramebuffer = this._activeFramebuffer;
|
|
2770
|
-
if (activeFramebuffer) {
|
|
2771
|
-
let needsUpdate = false;
|
|
2772
|
-
const attachments = this._getAttachments();
|
|
2773
|
-
for (let i = 0; i < attachments.length; ++i) {
|
|
2774
|
-
if (activeFramebuffer._attachments[attachments[i]] === renderbuffer) {
|
|
2775
|
-
needsUpdate = true;
|
|
2776
|
-
break;
|
|
2777
|
-
}
|
|
2778
|
-
}
|
|
2779
|
-
if (needsUpdate) {
|
|
2780
|
-
this._updateFramebufferAttachments(this._activeFramebuffer);
|
|
2781
|
-
}
|
|
2782
|
-
}
|
|
2783
|
-
}
|
|
2784
|
-
resize(width = 0, height = 0) {
|
|
2785
|
-
width = width | 0;
|
|
2786
|
-
height = height | 0;
|
|
2787
|
-
if (!(width > 0 && height > 0)) {
|
|
2788
|
-
throw new Error("Invalid surface dimensions");
|
|
2789
|
-
} else if (width !== this.drawingBufferWidth || height !== this.drawingBufferHeight) {
|
|
2790
|
-
this._resizeDrawingBuffer(width, height);
|
|
2791
|
-
}
|
|
2792
|
-
}
|
|
2793
|
-
sampleCoverage(value, invert) {
|
|
2794
|
-
return this._gl.sampleCoverage(+value, !!invert);
|
|
2795
|
-
}
|
|
2796
|
-
scissor(x, y, width, height) {
|
|
2797
|
-
this._scissorBox[0] = x | 0;
|
|
2798
|
-
this._scissorBox[1] = y | 0;
|
|
2799
|
-
this._scissorBox[2] = width | 0;
|
|
2800
|
-
this._scissorBox[3] = height | 0;
|
|
2801
|
-
return this._gl.scissor(x | 0, y | 0, width | 0, height | 0);
|
|
2802
|
-
}
|
|
2803
|
-
shaderSource(shader, source) {
|
|
2804
|
-
if (!checkObject(shader)) {
|
|
2805
|
-
throw new TypeError("shaderSource(WebGLShader, String)");
|
|
2806
|
-
}
|
|
2807
|
-
if (!shader || !source && typeof source !== "string") {
|
|
2808
|
-
this.setError(this.INVALID_VALUE);
|
|
2809
|
-
return;
|
|
2810
|
-
}
|
|
2811
|
-
if (!isValidString(source)) {
|
|
2812
|
-
this.setError(this.INVALID_VALUE);
|
|
2813
|
-
} else if (this._checkWrapper(shader, WebGLShader)) {
|
|
2814
|
-
source = this._wrapShader(shader._type, source);
|
|
2815
|
-
this._gl.shaderSource(shader._ | 0, source);
|
|
2816
|
-
shader._source = source;
|
|
2817
|
-
shader._needsRecompile = true;
|
|
2818
|
-
}
|
|
2819
|
-
}
|
|
2820
|
-
stencilFunc(func, ref, mask) {
|
|
2821
|
-
this._checkStencil = true;
|
|
2822
|
-
return this._gl.stencilFunc(func | 0, ref | 0, mask | 0);
|
|
2823
|
-
}
|
|
2824
|
-
stencilFuncSeparate(face, func, ref, mask) {
|
|
2825
|
-
this._checkStencil = true;
|
|
2826
|
-
return this._gl.stencilFuncSeparate(face | 0, func | 0, ref | 0, mask | 0);
|
|
2827
|
-
}
|
|
2828
|
-
stencilMask(mask) {
|
|
2829
|
-
this._checkStencil = true;
|
|
2830
|
-
return this._gl.stencilMask(mask >>> 0);
|
|
2831
|
-
}
|
|
2832
|
-
stencilMaskSeparate(face, mask) {
|
|
2833
|
-
this._checkStencil = true;
|
|
2834
|
-
return this._gl.stencilMaskSeparate(face | 0, mask >>> 0);
|
|
2835
|
-
}
|
|
2836
|
-
stencilOp(fail, zfail, zpass) {
|
|
2837
|
-
this._checkStencil = true;
|
|
2838
|
-
return this._gl.stencilOp(fail | 0, zfail | 0, zpass | 0);
|
|
2839
|
-
}
|
|
2840
|
-
stencilOpSeparate(face, fail, zfail, zpass) {
|
|
2841
|
-
this._checkStencil = true;
|
|
2842
|
-
return this._gl.stencilOpSeparate(face | 0, fail | 0, zfail | 0, zpass | 0);
|
|
2843
|
-
}
|
|
2844
|
-
texParameterf(target = 0, pname = 0, param) {
|
|
2845
|
-
param = +param;
|
|
2846
|
-
if (this._checkTextureTarget(target)) {
|
|
2847
|
-
this._verifyTextureCompleteness(target, pname, param);
|
|
2848
|
-
switch (pname) {
|
|
2849
|
-
case this.TEXTURE_MIN_FILTER:
|
|
2850
|
-
case this.TEXTURE_MAG_FILTER:
|
|
2851
|
-
case this.TEXTURE_WRAP_S:
|
|
2852
|
-
case this.TEXTURE_WRAP_T: return this._gl.texParameterf(target, pname, param);
|
|
2853
|
-
}
|
|
2854
|
-
if (this._extensions.ext_texture_filter_anisotropic && pname === this._extensions.ext_texture_filter_anisotropic.TEXTURE_MAX_ANISOTROPY_EXT) {
|
|
2855
|
-
return this._gl.texParameterf(target, pname, param);
|
|
2856
|
-
}
|
|
2857
|
-
this.setError(this.INVALID_ENUM);
|
|
2858
|
-
}
|
|
2859
|
-
}
|
|
2860
|
-
texParameteri(target = 0, pname = 0, param = 0) {
|
|
2861
|
-
if (this._checkTextureTarget(target)) {
|
|
2862
|
-
this._verifyTextureCompleteness(target, pname, param);
|
|
2863
|
-
switch (pname) {
|
|
2864
|
-
case this.TEXTURE_MIN_FILTER:
|
|
2865
|
-
case this.TEXTURE_MAG_FILTER:
|
|
2866
|
-
case this.TEXTURE_WRAP_S:
|
|
2867
|
-
case this.TEXTURE_WRAP_T: return this._gl.texParameteri(target, pname, param);
|
|
2868
|
-
}
|
|
2869
|
-
if (this._extensions.ext_texture_filter_anisotropic && pname === this._extensions.ext_texture_filter_anisotropic.TEXTURE_MAX_ANISOTROPY_EXT) {
|
|
2870
|
-
return this._gl.texParameteri(target, pname, param);
|
|
2871
|
-
}
|
|
2872
|
-
this.setError(this.INVALID_ENUM);
|
|
2873
|
-
}
|
|
2874
|
-
}
|
|
2875
|
-
uniform1f(location, x) {
|
|
2876
|
-
if (!this._checkUniformValid(location, x, "uniform1f", 1, "f")) return;
|
|
2877
|
-
return this._gl.uniform1f(location?._ || 0, x);
|
|
2878
|
-
}
|
|
2879
|
-
uniform1i(location, x) {
|
|
2880
|
-
return this._gl.uniform1i(location?._ || 0, x);
|
|
2881
|
-
}
|
|
2882
|
-
uniform2f(location, x, y) {
|
|
2883
|
-
if (!this._checkUniformValid(location, x, "uniform2f", 2, "f")) return;
|
|
2884
|
-
return this._gl.uniform2f(location?._ || 0, x, y);
|
|
2885
|
-
}
|
|
2886
|
-
uniform2i(location, x, y) {
|
|
2887
|
-
if (!this._checkUniformValid(location, x, "uniform2i", 2, "i")) return;
|
|
2888
|
-
this._gl.uniform2i(location?._ || 0, x, y);
|
|
2889
|
-
}
|
|
2890
|
-
uniform3f(location, x, y, z) {
|
|
2891
|
-
if (!this._checkUniformValid(location, x, "uniform3f", 3, "f")) return;
|
|
2892
|
-
return this._gl.uniform3f(location?._ || 0, x, y, z);
|
|
2893
|
-
}
|
|
2894
|
-
uniform3i(location, x, y, z) {
|
|
2895
|
-
if (!this._checkUniformValid(location, x, "uniform3i", 3, "i")) return;
|
|
2896
|
-
return this._gl.uniform3i(location?._ || 0, x, y, z);
|
|
2897
|
-
}
|
|
2898
|
-
uniform4f(location, x, y, z, w) {
|
|
2899
|
-
if (!this._checkUniformValid(location, x, "uniform4f", 4, "f")) {
|
|
2900
|
-
console.error("uniform4f is not valid!");
|
|
2901
|
-
return;
|
|
2902
|
-
}
|
|
2903
|
-
return this._gl.uniform4f(location?._ || 0, x, y, z, w);
|
|
2904
|
-
}
|
|
2905
|
-
uniform4i(location, x, y, z, w) {
|
|
2906
|
-
if (!this._checkUniformValid(location, x, "uniform4i", 4, "i")) return;
|
|
2907
|
-
return this._gl.uniform4i(location?._ || 0, x, y, z, w);
|
|
2908
|
-
}
|
|
2909
|
-
useProgram(program) {
|
|
2910
|
-
if (!checkObject(program)) {
|
|
2911
|
-
throw new TypeError("useProgram(WebGLProgram)");
|
|
2912
|
-
} else if (!program) {
|
|
2913
|
-
this._switchActiveProgram(this._activeProgram);
|
|
2914
|
-
this._activeProgram = null;
|
|
2915
|
-
return this._gl.useProgram(0);
|
|
2916
|
-
} else if (this._checkWrapper(program, WebGLProgram)) {
|
|
2917
|
-
if (this._activeProgram !== program) {
|
|
2918
|
-
this._switchActiveProgram(this._activeProgram);
|
|
2919
|
-
this._activeProgram = program;
|
|
2920
|
-
program._refCount += 1;
|
|
2921
|
-
}
|
|
2922
|
-
return this._gl.useProgram(program._ | 0);
|
|
2923
|
-
}
|
|
2924
|
-
}
|
|
2925
|
-
validateProgram(program) {
|
|
2926
|
-
if (this._checkWrapper(program, WebGLProgram)) {
|
|
2927
|
-
this._gl.validateProgram(program._ | 0);
|
|
2928
|
-
const error = this.getError();
|
|
2929
|
-
if (error === this.NO_ERROR) {
|
|
2930
|
-
program._linkInfoLog = this._gl.getProgramInfoLog(program._ | 0);
|
|
2931
|
-
}
|
|
2932
|
-
this.getError();
|
|
2933
|
-
this.setError(error);
|
|
2934
|
-
}
|
|
2935
|
-
}
|
|
2936
|
-
vertexAttrib1f(index, x) {
|
|
2937
|
-
index |= 0;
|
|
2938
|
-
if (!this._checkVertexIndex(index)) return;
|
|
2939
|
-
const data = this._vertexGlobalState._attribs[index]._data;
|
|
2940
|
-
data[3] = 1;
|
|
2941
|
-
data[1] = data[2] = 0;
|
|
2942
|
-
data[0] = x;
|
|
2943
|
-
return this._gl.vertexAttrib1f(index | 0, +x);
|
|
2944
|
-
}
|
|
2945
|
-
vertexAttrib1fv(index, values) {
|
|
2946
|
-
index |= 0;
|
|
2947
|
-
if (!this._checkVertexIndex(index)) return;
|
|
2948
|
-
if (typeof values !== "object" || values === null || values.length < 1) {
|
|
2949
|
-
this.setError(this.INVALID_OPERATION);
|
|
2950
|
-
return;
|
|
2951
|
-
}
|
|
2952
|
-
const data = this._vertexGlobalState._attribs[index]._data;
|
|
2953
|
-
data[3] = 1;
|
|
2954
|
-
data[2] = 0;
|
|
2955
|
-
data[1] = 0;
|
|
2956
|
-
data[0] = values[0];
|
|
2957
|
-
return this._gl.vertexAttrib1f(index | 0, +values[0]);
|
|
2958
|
-
}
|
|
2959
|
-
vertexAttrib2f(index, x, y) {
|
|
2960
|
-
index |= 0;
|
|
2961
|
-
if (!this._checkVertexIndex(index)) return;
|
|
2962
|
-
const data = this._vertexGlobalState._attribs[index]._data;
|
|
2963
|
-
data[3] = 1;
|
|
2964
|
-
data[2] = 0;
|
|
2965
|
-
data[1] = y;
|
|
2966
|
-
data[0] = x;
|
|
2967
|
-
return this._gl.vertexAttrib2f(index | 0, +x, +y);
|
|
2968
|
-
}
|
|
2969
|
-
vertexAttrib2fv(index, values) {
|
|
2970
|
-
index |= 0;
|
|
2971
|
-
if (!this._checkVertexIndex(index)) return;
|
|
2972
|
-
if (typeof values !== "object" || values === null || values.length < 2) {
|
|
2973
|
-
this.setError(this.INVALID_OPERATION);
|
|
2974
|
-
return;
|
|
2975
|
-
}
|
|
2976
|
-
const data = this._vertexGlobalState._attribs[index]._data;
|
|
2977
|
-
data[3] = 1;
|
|
2978
|
-
data[2] = 0;
|
|
2979
|
-
data[1] = values[1];
|
|
2980
|
-
data[0] = values[0];
|
|
2981
|
-
return this._gl.vertexAttrib2f(index | 0, +values[0], +values[1]);
|
|
2982
|
-
}
|
|
2983
|
-
vertexAttrib3f(index, x, y, z) {
|
|
2984
|
-
index |= 0;
|
|
2985
|
-
if (!this._checkVertexIndex(index)) return;
|
|
2986
|
-
const data = this._vertexGlobalState._attribs[index]._data;
|
|
2987
|
-
data[3] = 1;
|
|
2988
|
-
data[2] = z;
|
|
2989
|
-
data[1] = y;
|
|
2990
|
-
data[0] = x;
|
|
2991
|
-
return this._gl.vertexAttrib3f(index | 0, +x, +y, +z);
|
|
2992
|
-
}
|
|
2993
|
-
vertexAttrib3fv(index, values) {
|
|
2994
|
-
index |= 0;
|
|
2995
|
-
if (!this._checkVertexIndex(index)) return;
|
|
2996
|
-
if (typeof values !== "object" || values === null || values.length < 3) {
|
|
2997
|
-
this.setError(this.INVALID_OPERATION);
|
|
2998
|
-
return;
|
|
2999
|
-
}
|
|
3000
|
-
const data = this._vertexGlobalState._attribs[index]._data;
|
|
3001
|
-
data[3] = 1;
|
|
3002
|
-
data[2] = values[2];
|
|
3003
|
-
data[1] = values[1];
|
|
3004
|
-
data[0] = values[0];
|
|
3005
|
-
return this._gl.vertexAttrib3f(index | 0, +values[0], +values[1], +values[2]);
|
|
3006
|
-
}
|
|
3007
|
-
vertexAttrib4f(index = 0, x, y, z, w) {
|
|
3008
|
-
if (!this._checkVertexIndex(index)) return;
|
|
3009
|
-
const data = this._vertexGlobalState._attribs[index]._data;
|
|
3010
|
-
data[3] = w;
|
|
3011
|
-
data[2] = z;
|
|
3012
|
-
data[1] = y;
|
|
3013
|
-
data[0] = x;
|
|
3014
|
-
return this._gl.vertexAttrib4f(index | 0, +x, +y, +z, +w);
|
|
3015
|
-
}
|
|
3016
|
-
vertexAttrib4fv(index, values) {
|
|
3017
|
-
index |= 0;
|
|
3018
|
-
if (!this._checkVertexIndex(index)) return;
|
|
3019
|
-
if (typeof values !== "object" || values === null || values.length < 4) {
|
|
3020
|
-
this.setError(this.INVALID_OPERATION);
|
|
3021
|
-
return;
|
|
3022
|
-
}
|
|
3023
|
-
const data = this._vertexGlobalState._attribs[index]._data;
|
|
3024
|
-
data[3] = values[3];
|
|
3025
|
-
data[2] = values[2];
|
|
3026
|
-
data[1] = values[1];
|
|
3027
|
-
data[0] = values[0];
|
|
3028
|
-
return this._gl.vertexAttrib4f(index | 0, +values[0], +values[1], +values[2], +values[3]);
|
|
3029
|
-
}
|
|
3030
|
-
vertexAttribPointer(index = 0, size = 0, type = 0, normalized = false, stride = 0, offset = 0) {
|
|
3031
|
-
if (stride < 0 || offset < 0) {
|
|
3032
|
-
this.setError(this.INVALID_VALUE);
|
|
3033
|
-
return;
|
|
3034
|
-
}
|
|
3035
|
-
if (stride < 0 || offset < 0 || index < 0 || index >= this._vertexObjectState._attribs.length || !(size === 1 || size === 2 || size === 3 || size === 4)) {
|
|
3036
|
-
this.setError(this.INVALID_VALUE);
|
|
3037
|
-
return;
|
|
3038
|
-
}
|
|
3039
|
-
if (this._vertexGlobalState._arrayBufferBinding === null) {
|
|
3040
|
-
this.setError(this.INVALID_OPERATION);
|
|
3041
|
-
return;
|
|
3042
|
-
}
|
|
3043
|
-
const byteSize = typeSize(this, type);
|
|
3044
|
-
if (byteSize === 0 || type === this.INT || type === this.UNSIGNED_INT) {
|
|
3045
|
-
this.setError(this.INVALID_ENUM);
|
|
3046
|
-
return;
|
|
3047
|
-
}
|
|
3048
|
-
if (stride > 255 || stride < 0) {
|
|
3049
|
-
this.setError(this.INVALID_VALUE);
|
|
3050
|
-
return;
|
|
3051
|
-
}
|
|
3052
|
-
if (stride % byteSize !== 0 || offset % byteSize !== 0) {
|
|
3053
|
-
this.setError(this.INVALID_OPERATION);
|
|
3054
|
-
return;
|
|
3055
|
-
}
|
|
3056
|
-
this._gl.vertexAttribPointer(index, size, type, normalized, stride, offset);
|
|
3057
|
-
this._vertexObjectState.setVertexAttribPointer(this._vertexGlobalState._arrayBufferBinding, index, size * byteSize, offset, stride || size * byteSize, type, normalized, stride, size);
|
|
3058
|
-
}
|
|
3059
|
-
viewport(x, y, width, height) {
|
|
3060
|
-
this._viewport[0] = x | 0;
|
|
3061
|
-
this._viewport[1] = y | 0;
|
|
3062
|
-
this._viewport[2] = width | 0;
|
|
3063
|
-
this._viewport[3] = height | 0;
|
|
3064
|
-
return this._gl.viewport(x, y, width, height);
|
|
3065
|
-
}
|
|
3066
|
-
};
|
|
3067
|
-
|
|
3068
|
-
//#endregion
|
|
3069
|
-
export { WebGLContextBase };
|
|
1
|
+
import{WebGLContextAttributes as e}from"./webgl-context-attributes.js";import{WebGLUniformLocation as t}from"./webgl-uniform-location.js";import{Uint8ArrayToVariant as n,arrayToUint8Array as r,checkFormat as i,checkObject as a,checkUniform as o,convertPixels as s,extractImageData as c,flag as l,formatSize as u,isTypedArray as d,isValidString as f,listToArray as p,premultiplyAlpha as m,typeSize as h,uniformTypeSize as g,validCubeTarget as _,vertexCount as v}from"./utils.js";import{getOESElementIndexUint as y}from"./extensions/oes-element-index-unit.js";import{getOESStandardDerivatives as b}from"./extensions/oes-standard-derivatives.js";import{getOESTextureFloat as x}from"./extensions/oes-texture-float.js";import{getOESTextureFloatLinear as S}from"./extensions/oes-texture-float-linear.js";import{getSTACKGLDestroyContext as C}from"./extensions/stackgl-destroy-context.js";import{getSTACKGLResizeDrawingBuffer as w}from"./extensions/stackgl-resize-drawing-buffer.js";import{getEXTBlendMinMax as T}from"./extensions/ext-blend-minmax.js";import{getEXTColorBufferFloat as E}from"./extensions/ext-color-buffer-float.js";import{getEXTColorBufferHalfFloat as D}from"./extensions/ext-color-buffer-half-float.js";import{getEXTTextureFilterAnisotropic as O}from"./extensions/ext-texture-filter-anisotropic.js";import{getOESTextureHalfFloat as k}from"./extensions/oes-texture-half-float.js";import{WebGLActiveInfo as A}from"./webgl-active-info.js";import{WebGLFramebuffer as j}from"./webgl-framebuffer.js";import{WebGLBuffer as M}from"./webgl-buffer.js";import{WebGLDrawingBufferWrapper as N}from"./webgl-drawing-buffer-wrapper.js";import{WebGLProgram as P}from"./webgl-program.js";import{WebGLRenderbuffer as F}from"./webgl-renderbuffer.js";import{WebGLShader as I}from"./webgl-shader.js";import{WebGLShaderPrecisionFormat as L}from"./webgl-shader-precision-format.js";import{WebGLTextureUnit as R}from"./webgl-texture-unit.js";import{WebGLTexture as z}from"./webgl-texture.js";import{WebGLVertexArrayGlobalState as B,WebGLVertexArrayObjectState as V}from"./webgl-vertex-attribute.js";import H from"@girs/gwebgl-0.1";import"@girs/gdkpixbuf-2.0";import*as U from"bit-twiddle";import W from"glsl-tokenizer/string";import G from"gi://GdkPixbuf?version=2.0";import{warnNotImplemented as K}from"@gjsify/utils";let q=0;const J={oes_element_index_uint:y,oes_texture_float:x,oes_texture_float_linear:S,oes_standard_derivatives:b,stackgl_destroy_context:C,stackgl_resize_drawingbuffer:w,ext_blend_minmax:T,ext_color_buffer_float:E,ext_color_buffer_half_float:D,ext_texture_filter_anisotropic:O,oes_texture_half_float:k};var Y=class{get drawingBufferHeight(){return this.canvas.height||0}get drawingBufferWidth(){return this.canvas.width||0}constructor(t,n={}){this.unpackColorSpace=`srgb`,this.RGBA8=32856,this.DEFAULT_ATTACHMENTS=[],this.DEFAULT_COLOR_ATTACHMENTS=[],this._=0,this._extensions={},this._programs={},this._shaders={},this._textures={},this._framebuffers={},this._renderbuffers={},this._buffers={},this._activeProgram=null,this._activeFramebuffer=null,this._activeRenderbuffer=null,this._checkStencil=!1,this._stencilState=!0,this._activeTextureUnit=0,this._errorStack=[],this._maxTextureSize=0,this._maxTextureLevel=0,this._maxCubeMapSize=0,this._maxCubeMapLevel=0,this._unpackAlignment=4,this._packAlignment=4,this._unpackFlipY=!1,this._unpackPremultAlpha=!1,this._viewport=new Int32Array([0,0,0,0]),this._scissorBox=new Int32Array([0,0,0,0]),this._gtkFboId=0,this._textureUnits=[],this._drawingBuffer=null,this.canvas=t,this._contextAttributes=new e(l(n,`alpha`,!0),l(n,`depth`,!0),l(n,`stencil`,!1),!1,l(n,`premultipliedAlpha`,!0),l(n,`preserveDrawingBuffer`,!1),l(n,`preferLowPowerToHighPerformance`,!1),l(n,`failIfMajorPerformanceCaveat`,!1)),this._contextAttributes.premultipliedAlpha=this._contextAttributes.premultipliedAlpha&&this._contextAttributes.alpha}_init(){let e=this._gl.getParameterx(36006);this._gtkFboId=e?.deepUnpack()|0,this._initGLConstants(),this.DEFAULT_ATTACHMENTS=[this.COLOR_ATTACHMENT0,this.DEPTH_ATTACHMENT,this.STENCIL_ATTACHMENT,this.DEPTH_STENCIL_ATTACHMENT],this.DEFAULT_COLOR_ATTACHMENTS=[this.COLOR_ATTACHMENT0];let t=this._contextAttributes,n=this.drawingBufferWidth||t.width||0,r=this.drawingBufferHeight||t.height||0;this._=q++;let i=this.getParameter(this.MAX_COMBINED_TEXTURE_IMAGE_UNITS);this._textureUnits=Array(i);for(let e=0;e<i;++e)this._textureUnits[e]=new R(this,e);this.activeTexture(this.TEXTURE0),this._defaultVertexObjectState=new V(this),this._vertexObjectState=this._defaultVertexObjectState,this._vertexGlobalState=new B(this),this._maxTextureSize=this.getParameter(this.MAX_TEXTURE_SIZE),this._maxTextureLevel=U.log2(U.nextPow2(this._maxTextureSize)),this._maxCubeMapSize=this.getParameter(this.MAX_CUBE_MAP_TEXTURE_SIZE),this._maxCubeMapLevel=U.log2(U.nextPow2(this._maxCubeMapSize)),this._unpackAlignment=4,this._packAlignment=4,this._unpackFlipY=!1,this._unpackPremultAlpha=!1,this.bindBuffer(this.ARRAY_BUFFER,null),this.bindBuffer(this.ELEMENT_ARRAY_BUFFER,null),this.bindFramebuffer(this.FRAMEBUFFER,null),this.bindRenderbuffer(this.RENDERBUFFER,null),this.viewport(0,0,n,r),this.scissor(0,0,n,r),this.clearDepth(1),this.clearColor(0,0,0,0),this.clearStencil(0),this.clear(this.COLOR_BUFFER_BIT|this.DEPTH_BUFFER_BIT|this.STENCIL_BUFFER_BIT),this.disable(this.DEPTH_TEST),this.disable(this.STENCIL_TEST),this.disable(this.BLEND),this.disable(this.CULL_FACE),this.disable(this.POLYGON_OFFSET_FILL),this.disable(this.SCISSOR_TEST),this._gl.colorMask(!0,!0,!0,!0)}_initGLConstants(){let e=new H.WebGLRenderingContextBase().get_webgl_constants();for(let[t,n]of Object.entries(e))Object.defineProperty(this,t,{value:n})}_getGlslVersion(e){return e?`100`:`120`}_checkDimensions(e,t,n,r){if(r<0||t<0||n<0)return this.setError(this.INVALID_VALUE),!1;if(e===this.TEXTURE_2D){if(t>this._maxTextureSize||n>this._maxTextureSize||r>this._maxTextureLevel)return this.setError(this.INVALID_VALUE),!1}else if(this._validCubeTarget(e)){if(t>this._maxCubeMapSize||n>this._maxCubeMapSize||r>this._maxCubeMapLevel)return this.setError(this.INVALID_VALUE),!1}else return this.setError(this.INVALID_ENUM),!1;return!0}_checkLocation(e){return e instanceof t?e._program._ctx!==this||e._linkCount!==e._program._linkCount?(this.setError(this.INVALID_OPERATION),!1):!0:(this.setError(this.INVALID_VALUE),!1)}_checkLocationActive(e){return e&&this._checkLocation(e)?e._program===this._activeProgram?!0:(this.setError(this.INVALID_OPERATION),!1):!1}_checkOwns(e){return typeof e==`object`&&e._ctx===this}_checkShaderSource(e){let t=e._source,n=W(t),r=!1,i=[];for(let e=0;e<n.length;++e){let t=n[e];if(t)switch(t.type){case`ident`:this._validGLSLIdentifier(t.data)||(r=!0,i.push(t.line+`:`+t.column+` invalid identifier - `+t.data));break;case`preprocessor`:{let e=t.data.match(/^\s*#\s*(.*)$/);if(!e||e?.length<2)break;let n=W(e[1]);for(let e=0;e<n.length;++e){let a=n[e];(a.type===`ident`||a.type===void 0)&&(this._validGLSLIdentifier(a.data)||(r=!0,i.push(t.line+`:`+a.column+` invalid identifier - `+a.data)))}break}case`keyword`:switch(t.data){case`do`:r=!0,i.push(t.line+`:`+t.column+` do not supported`);break}break;case`builtin`:switch(t.data){case`dFdx`:case`dFdy`:case`fwidth`:!this._extensions.oes_standard_derivatives&&this._getGlslVersion(!0)===`100`&&(r=!0,i.push(t.line+`:`+t.column+` `+t.data+` not supported`));break}}}return r&&(e._compileInfo=i.join(`
|
|
2
|
+
`)),!r}_checkStencilState(){return this._checkStencil?(this._checkStencil=!1,this._stencilState=!0,(this.getParameter(this.STENCIL_WRITEMASK)!==this.getParameter(this.STENCIL_BACK_WRITEMASK)||this.getParameter(this.STENCIL_VALUE_MASK)!==this.getParameter(this.STENCIL_BACK_VALUE_MASK)||this.getParameter(this.STENCIL_REF)!==this.getParameter(this.STENCIL_BACK_REF))&&(this.setError(this.INVALID_OPERATION),this._stencilState=!1),this._stencilState):this._stencilState}_checkTextureTarget(e){let t=this._getActiveTextureUnit(),n=null;if(e===this.TEXTURE_2D)n=t._bind2D;else if(e===this.TEXTURE_CUBE_MAP)n=t._bindCube;else return this.setError(this.INVALID_ENUM),!1;return n?!0:(this.setError(this.INVALID_OPERATION),!1)}_checkWrapper(e,t){return this._checkValid(e,t)?this._checkOwns(e)?!0:(this.setError(this.INVALID_OPERATION),!1):(this.setError(this.INVALID_VALUE),!1)}_checkValid(e,t){return e instanceof t&&e._!==0}_checkVertexAttribState(e){let t=this._activeProgram;if(!t)return this.setError(this.INVALID_OPERATION),!1;let n=this._vertexObjectState._attribs;for(let r=0;r<n.length;++r){let i=n[r];if(i._isPointer){let n=i._pointerBuffer;if(!n)return this.setError(this.INVALID_OPERATION),!1;if(t._attributes.indexOf(r)>=0){let t=0;if(t=i._divisor?i._pointerSize+i._pointerOffset:i._pointerStride*e+i._pointerSize+i._pointerOffset,t>n._size)return this.setError(this.INVALID_OPERATION),!1}}}return!0}_checkVertexIndex(e){return e<0||e>=this._vertexObjectState._attribs.length?(this.setError(this.INVALID_VALUE),!1):!0}_computePixelSize(e,t){let n=u(this,t);if(n===0)return this.setError(this.INVALID_ENUM),0;switch(e){case this.UNSIGNED_BYTE:return n;case this.UNSIGNED_SHORT_5_6_5:if(t!==this.RGB){this.setError(this.INVALID_OPERATION);break}return 2;case this.UNSIGNED_SHORT_4_4_4_4:case this.UNSIGNED_SHORT_5_5_5_1:if(t!==this.RGBA){this.setError(this.INVALID_OPERATION);break}return 2;case this.FLOAT:return 1}return this.setError(this.INVALID_ENUM),0}_computeRowStride(e,t){let n=e*t;return n%this._unpackAlignment&&(n+=this._unpackAlignment-n%this._unpackAlignment),n}_fixupLink(e){if(!this._gl.getProgramParameter(e._,this.LINK_STATUS))return e._linkInfoLog=this._gl.getProgramInfoLog(e._),!1;let t=this.getProgramParameter(e,this.ACTIVE_ATTRIBUTES),n=Array(t);e._attributes.length=t;for(let r=0;r<t;++r)n[r]=this.getActiveAttrib(e,r)?.name,e._attributes[r]=this.getAttribLocation(e,n[r])|0;for(let t=0;t<n.length;++t)if(n[t].length>256)return e._linkInfoLog=`attribute `+n[t]+` is too long`,!1;for(let r=0;r<t;++r)e._attributes[r]<0||this._gl.bindAttribLocation(e._|0,e._attributes[r],n[r]);if(this._gl.linkProgram(e._|0),!this._gl.getProgramParameter(e._|0,this.LINK_STATUS))return e._linkInfoLog=this._gl.getProgramInfoLog(e._),!1;let r=this.getProgramParameter(e,this.ACTIVE_UNIFORMS);e._uniforms.length=r;for(let t=0;t<r;++t){let n=this.getActiveUniform(e,t);n&&(e._uniforms[t]=n)}for(let t=0;t<e._uniforms.length;++t)if(e._uniforms[t].name.length>256)return e._linkInfoLog=`uniform `+e._uniforms[t].name+` is too long`,!1;return e._linkInfoLog=``,!0}_framebufferOk(){let e=this._activeFramebuffer;return e&&this._preCheckFramebufferStatus(e)!==this.FRAMEBUFFER_COMPLETE?(this.setError(this.INVALID_FRAMEBUFFER_OPERATION),!1):!0}_getActiveBuffer(e){return e===this.ARRAY_BUFFER?this._vertexGlobalState._arrayBufferBinding:e===this.ELEMENT_ARRAY_BUFFER?this._vertexObjectState._elementArrayBufferBinding:null}_getActiveTextureUnit(){return this._textureUnits[this._activeTextureUnit]}_getActiveTexture(e){let t=this._getActiveTextureUnit();return e===this.TEXTURE_2D?t._bind2D:e===this.TEXTURE_CUBE_MAP?t._bindCube:null}_getAttachments(){return this._extensions.webgl_draw_buffers?this._extensions.webgl_draw_buffers._ALL_ATTACHMENTS:this.DEFAULT_ATTACHMENTS}_getColorAttachments(){return this._extensions.webgl_draw_buffers?this._extensions.webgl_draw_buffers._ALL_COLOR_ATTACHMENTS:this.DEFAULT_COLOR_ATTACHMENTS}_getParameterDirect(e){return this._gl.getParameterx(e)?.deepUnpack()}_getTexImage(e){let t=this._getActiveTextureUnit();return e===this.TEXTURE_2D?t._bind2D:_(this,e)?t._bindCube:(this.setError(this.INVALID_ENUM),null)}_preCheckFramebufferStatus(e){let t=e._attachments,n=[],r=[],i=t[this.DEPTH_ATTACHMENT],a=t[this.DEPTH_STENCIL_ATTACHMENT],o=t[this.STENCIL_ATTACHMENT];if(a&&(o||i)||o&&i)return this.FRAMEBUFFER_UNSUPPORTED;let s=this._getColorAttachments(),c=0;for(let e in t)t[e]&&s.indexOf(Number(e))!==-1&&c++;if(c===0)return this.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;if(a instanceof z)return this.FRAMEBUFFER_UNSUPPORTED;if(a instanceof F){if(a._format!==this.DEPTH_STENCIL)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;n.push(a._width),r.push(a._height)}if(i instanceof z)return this.FRAMEBUFFER_UNSUPPORTED;if(i instanceof F){if(i._format!==this.DEPTH_COMPONENT16)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;n.push(i._width),r.push(i._height)}if(o instanceof z)return this.FRAMEBUFFER_UNSUPPORTED;if(o instanceof F){if(o._format!==this.STENCIL_INDEX8)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;n.push(o._width),r.push(o._height)}let l=!1;for(let i=0;i<s.length;++i){let a=t[s[i]];if(a instanceof z){if(a._format!==this.RGBA||!(a._type===this.UNSIGNED_BYTE||a._type===this.FLOAT))return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;l=!0;let t=e._attachmentLevel[this.COLOR_ATTACHMENT0];if(t===null)throw TypeError(`level is null!`);n.push(a._levelWidth[t]),r.push(a._levelHeight[t])}else if(a instanceof F){let e=a._format;if(e!==this.RGBA4&&e!==this.RGB565&&e!==this.RGB5_A1)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;l=!0,n.push(a._width),r.push(a._height)}}if(!l&&!o&&!i&&!a)return this.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;if(n.length<=0||r.length<=0)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;for(let e=1;e<n.length;++e)if(n[e-1]!==n[e]||r[e-1]!==r[e])return this.FRAMEBUFFER_INCOMPLETE_DIMENSIONS;return n[0]===0||r[0]===0?this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:(e._width=n[0],e._height=r[0],this.FRAMEBUFFER_COMPLETE)}_isConstantBlendFunc(e){return e===this.CONSTANT_COLOR||e===this.ONE_MINUS_CONSTANT_COLOR||e===this.CONSTANT_ALPHA||e===this.ONE_MINUS_CONSTANT_ALPHA}_isObject(e,t,n){if(e!=null&&!(e instanceof n))throw TypeError(t+`(`+n.name+`)`);return!!(this._checkValid(e,n)&&this._checkOwns(e))}_resizeDrawingBuffer(e,t){let r=this._activeFramebuffer,i=this._getActiveTexture(this.TEXTURE_2D),a=this._activeRenderbuffer,o=this._contextAttributes,s=this._drawingBuffer;s?._framebuffer&&this._gl.bindFramebuffer(this.FRAMEBUFFER,s?._framebuffer);let c=this._getAttachments();for(let e=0;e<c.length;++e)this._gl.framebufferTexture2D(this.FRAMEBUFFER,c[e],this.TEXTURE_2D,0,0);s?._color&&this._gl.bindTexture(this.TEXTURE_2D,s?._color);let l=o.alpha?this.RGBA:this.RGB;this._gl.texImage2D(this.TEXTURE_2D,0,l,e,t,0,l,this.UNSIGNED_BYTE,n(null)),this._gl.texParameteri(this.TEXTURE_2D,this.TEXTURE_MIN_FILTER,this.NEAREST),this._gl.texParameteri(this.TEXTURE_2D,this.TEXTURE_MAG_FILTER,this.NEAREST),s?._color&&this._gl.framebufferTexture2D(this.FRAMEBUFFER,this.COLOR_ATTACHMENT0,this.TEXTURE_2D,s?._color,0);let u=0,d=0;o.depth&&o.stencil?(u=this.DEPTH_STENCIL,d=this.DEPTH_STENCIL_ATTACHMENT):o.depth?(u=33191,d=this.DEPTH_ATTACHMENT):o.stencil&&(u=this.STENCIL_INDEX8,d=this.STENCIL_ATTACHMENT),u&&(s?._depthStencil&&this._gl.bindRenderbuffer(this.RENDERBUFFER,s?._depthStencil),this._gl.renderbufferStorage(this.RENDERBUFFER,u,e,t),s?._depthStencil&&this._gl.framebufferRenderbuffer(this.FRAMEBUFFER,d,this.RENDERBUFFER,s?._depthStencil)),this.bindFramebuffer(this.FRAMEBUFFER,r),this.bindTexture(this.TEXTURE_2D,i),this.bindRenderbuffer(this.RENDERBUFFER,a)}_restoreError(e){let t=this._errorStack.pop();t===this.NO_ERROR?this.setError(e):t&&this.setError(t)}_saveError(){this._errorStack.push(this.getError())}_switchActiveProgram(e){e&&(--e._refCount,e._checkDelete())}_tryDetachFramebuffer(e,t){if(e&&e._linked(t)){let n=this._getAttachments(),r=Object.keys(e._attachments);for(let i=0;i<r.length;++i)e._attachments[n[i]]===t&&this.framebufferTexture2D(this.FRAMEBUFFER,n[i]|0,this.TEXTURE_2D,null)}}_updateFramebufferAttachments(e){if(!e)return;let t=e._status,n=this._getAttachments();if(e._status=this._preCheckFramebufferStatus(e),e._status!==this.FRAMEBUFFER_COMPLETE){if(t===this.FRAMEBUFFER_COMPLETE)for(let t=0;t<n.length;++t){let r=n[t];this._gl.framebufferTexture2D(this.FRAMEBUFFER,r,e._attachmentFace[r]||0,0,e._attachmentLevel[r]||0)}return}for(let t=0;t<n.length;++t){let r=n[t];this._gl.framebufferTexture2D(this.FRAMEBUFFER,r,e._attachmentFace[r]||0,0,e._attachmentLevel[r]||0)}for(let t=0;t<n.length;++t){let r=n[t],i=e._attachments[r];i instanceof z?this._gl.framebufferTexture2D(this.FRAMEBUFFER,r,e._attachmentFace[r]||0,i._|0,e._attachmentLevel[r]||0):i instanceof F&&this._gl.framebufferRenderbuffer(this.FRAMEBUFFER,r,this.RENDERBUFFER,i._|0)}}_validBlendFunc(e){return e===this.ZERO||e===this.ONE||e===this.SRC_COLOR||e===this.ONE_MINUS_SRC_COLOR||e===this.DST_COLOR||e===this.ONE_MINUS_DST_COLOR||e===this.SRC_ALPHA||e===this.ONE_MINUS_SRC_ALPHA||e===this.DST_ALPHA||e===this.ONE_MINUS_DST_ALPHA||e===this.SRC_ALPHA_SATURATE||e===this.CONSTANT_COLOR||e===this.ONE_MINUS_CONSTANT_COLOR||e===this.CONSTANT_ALPHA||e===this.ONE_MINUS_CONSTANT_ALPHA}_validBlendMode(e){return e===this.FUNC_ADD||e===this.FUNC_SUBTRACT||e===this.FUNC_REVERSE_SUBTRACT||this._extensions.ext_blend_minmax&&(e===this._extensions.ext_blend_minmax.MIN_EXT||e===this._extensions.ext_blend_minmax.MAX_EXT)}_validCubeTarget(e){return e===this.TEXTURE_CUBE_MAP_POSITIVE_X||e===this.TEXTURE_CUBE_MAP_NEGATIVE_X||e===this.TEXTURE_CUBE_MAP_POSITIVE_Y||e===this.TEXTURE_CUBE_MAP_NEGATIVE_Y||e===this.TEXTURE_CUBE_MAP_POSITIVE_Z||e===this.TEXTURE_CUBE_MAP_NEGATIVE_Z}_validFramebufferAttachment(e){switch(e){case this.DEPTH_ATTACHMENT:case this.STENCIL_ATTACHMENT:case this.DEPTH_STENCIL_ATTACHMENT:case this.COLOR_ATTACHMENT0:return!0}if(this._extensions.webgl_draw_buffers){let{webgl_draw_buffers:t}=this._extensions;return e<t.COLOR_ATTACHMENT0_WEBGL+t._maxDrawBuffers}return!1}_validGLSLIdentifier(e){return!(e.indexOf(`webgl_`)===0||e.indexOf(`_webgl_`)===0||e.length>256)}_validTextureTarget(e){return e===this.TEXTURE_2D||e===this.TEXTURE_CUBE_MAP}_verifyTextureCompleteness(e,t,n){let r=this._getActiveTextureUnit(),i=null;if(e===this.TEXTURE_2D?i=r._bind2D:this._validCubeTarget(e)&&(i=r._bindCube),this._extensions.oes_texture_float&&!this._extensions.oes_texture_float_linear&&i&&i._type===this.FLOAT&&(t===this.TEXTURE_MAG_FILTER||t===this.TEXTURE_MIN_FILTER)&&(n===this.LINEAR||n===this.LINEAR_MIPMAP_NEAREST||n===this.NEAREST_MIPMAP_LINEAR||n===this.LINEAR_MIPMAP_LINEAR)){i._complete=!1,this.bindTexture(e,i);return}i&&i._complete===!1&&(i._complete=!0,this.bindTexture(e,i))}_wrapShader(e,t){let n=t.startsWith(`#version`)||t.includes(`
|
|
3
|
+
#version`),r=``;if(!this._extensions.oes_standard_derivatives&&/#ifdef\s+GL_OES_standard_derivatives/.test(t)&&(r+=`#undef GL_OES_standard_derivatives
|
|
4
|
+
`),!this._extensions.webgl_draw_buffers&&!n&&(r+=`#define gl_MaxDrawBuffers 1
|
|
5
|
+
`),n){if(r){let e=t.indexOf(`
|
|
6
|
+
`);t=e===-1?t+`
|
|
7
|
+
`+r:t.slice(0,e+1)+r+t.slice(e+1)}}else if(this.canvas){let e=this.canvas.getGlArea().get_use_es(),n=/\b(attribute|varying)\b/.test(t)?e?`100`:`120`:this._getGlslVersion(e);n?t=`#version `+n+`
|
|
8
|
+
`+r+t:r&&(t=r+t)}else r&&(t=r+t);return t}_allocateDrawingBuffer(e,t){this._drawingBuffer=new N(this._gl.createFramebuffer(),this._gl.createTexture(),this._gl.createRenderbuffer()),this._resizeDrawingBuffer(e,t)}getContextAttributes(){return this._contextAttributes}getExtension(e){let t=e.toLowerCase();if(t in this._extensions)return this._extensions[t];let n=J[t]?J[t](this):null;return n&&(this._extensions[t]=n),n}bufferData(e=0,t,i=0){let a=0,o=null;if(typeof t==`number`?a=t:typeof t==`object`&&(o=t),i!==this.STREAM_DRAW&&i!==this.STATIC_DRAW&&i!==this.DYNAMIC_DRAW){this.setError(this.INVALID_ENUM);return}if(e!==this.ARRAY_BUFFER&&e!==this.ELEMENT_ARRAY_BUFFER){this.setError(this.INVALID_ENUM);return}let s=this._getActiveBuffer(e);if(!s){this.setError(this.INVALID_OPERATION);return}if(o){let t=null;if(d(o)||o instanceof DataView||o instanceof ArrayBuffer)t=r(o);else{this.setError(this.INVALID_VALUE);return}this._saveError(),this._gl.bufferData(e,n(t),i);let a=this.getError();if(this._restoreError(a),a!==this.NO_ERROR)return;s._size=t.length,e===this.ELEMENT_ARRAY_BUFFER&&(s._elements=new Uint8Array(t))}else if(typeof t==`number`){if(a<0){this.setError(this.INVALID_VALUE);return}this._saveError(),this._gl.bufferDataSizeOnly(e,a,i);let t=this.getError();if(this._restoreError(t),t!==this.NO_ERROR)return;s._size=a,e===this.ELEMENT_ARRAY_BUFFER&&(s._elements=new Uint8Array(a))}else this.setError(this.INVALID_VALUE)}bufferSubData(e=0,t=0,i){if(e!==this.ARRAY_BUFFER&&e!==this.ELEMENT_ARRAY_BUFFER){this.setError(this.INVALID_ENUM);return}if(typeof i!=`object`||!i)throw TypeError(`bufferSubData: data must be a BufferSource`);let a=this._getActiveBuffer(e);if(!a){this.setError(this.INVALID_OPERATION);return}if(t<0||t>=a._size){this.setError(this.INVALID_VALUE);return}let o=null;if(d(i)||i instanceof DataView||i instanceof ArrayBuffer)o=r(i);else{this.setError(this.INVALID_VALUE);return}if(t+o.length>a._size){this.setError(this.INVALID_VALUE);return}e===this.ELEMENT_ARRAY_BUFFER&&a._elements.set(o,t),this._gl.bufferSubData(e,t,n(o))}compressedTexImage2D(e,t,i,a,o,s,c){return this._gl.compressedTexImage2D(e,t,i,a,o,s,n(r(c)))}compressedTexSubImage2D(e,t,i,a,o,s,c,l){return this._gl.compressedTexSubImage2D(e,t,i,a,o,s,c,n(r(l)))}readPixels(e=0,t=0,i=0,a=0,o=0,s=0,c){if(!c)return;if(!(this._extensions.oes_texture_float&&s===this.FLOAT&&o===this.RGBA)){if(o===this.RGB||o===this.ALPHA||s!==this.UNSIGNED_BYTE){this.setError(this.INVALID_OPERATION);return}else if(o!==this.RGBA){this.setError(this.INVALID_ENUM);return}else if(i<0||a<0||!(c instanceof Uint8Array)){this.setError(this.INVALID_VALUE);return}}if(!this._framebufferOk()){console.error(`framebuffer is not okay!`);return}let l=i*4;l%this._packAlignment!==0&&(l+=this._packAlignment-l%this._packAlignment);let u=l*(a-1)+i*4;if(u<=0)return;if((c.length||c.byteLength||0)<u){this.setError(this.INVALID_VALUE);return}let d=this.drawingBufferWidth,f=this.drawingBufferHeight;this._activeFramebuffer&&(d=this._activeFramebuffer._width,f=this._activeFramebuffer._height);let p=r(c);if(e>=d||e+i<=0||t>=f||t+a<=0)for(let e=0;e<p.length;++e)p[e]=0;else if(e<0||e+i>d||t<0||t+a>f){for(let e=0;e<p.length;++e)p[e]=0;let r=e,c=i;e<0&&(c+=e,r=0),r+i>d&&(c=d-r);let u=t,m=a;t<0&&(m+=t,u=0),u+a>f&&(m=f-u);let h=c*4;if(h%this._packAlignment!==0&&(h+=this._packAlignment-h%this._packAlignment),c>0&&m>0){let i=new Uint8Array(h*m),a=this._gl.readPixels(r,u,c,m,o,s,n(i)),d=a&&a.length>0?a:i,f=4*(r-e)+(u-t)*l;for(let e=0;e<m;++e)for(let t=0;t<c;++t)for(let n=0;n<4;++n)p[f+e*l+4*t+n]=d[e*h+4*t+n]}}else{let r=this._gl.readPixels(e,t,i,a,o,s,n(p));r&&r.length>0&&p.set(r)}}texImage2D(e=0,t=0,r=0,a=0,o=0,l=0,u=0,d=0,f){let p=0,h=0,g=0,v,y,b=0;if(arguments.length===6)if(d=o,g=a,l instanceof G.Pixbuf)y=l,p=y.get_width(),h=y.get_height(),f=y.get_pixels();else{v=l;let e=c(v);if(e==null)throw TypeError(`texImage2D(GLenum, GLint, GLenum, GLint, GLenum, GLenum, ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement)`);p=e.width,h=e.height,f=e.data}else arguments.length===9&&(p=a,h=o,b=l,g=u,d=d,f=f);if(typeof f!=`object`&&f!==void 0)throw TypeError(`texImage2D(GLenum, GLint, GLenum, GLint, GLint, GLint, GLenum, GLenum, Uint8Array)`);if(!i(this,g)||!i(this,r)){this.setError(this.INVALID_ENUM);return}if(d===this.FLOAT&&!this._extensions.oes_texture_float){this.setError(this.INVALID_ENUM);return}let x=this._getTexImage(e);if(!x||g!==r){this.setError(this.INVALID_OPERATION);return}let S=this._computePixelSize(d,g);if(S===0||!this._checkDimensions(e,p,h,t))return;let C=s(f),w=this._computeRowStride(p,S),T=w*h;if(C&&C.length<T){this.setError(this.INVALID_OPERATION);return}if(b!==0||_(this,e)&&p!==h){this.setError(this.INVALID_VALUE);return}if(this._unpackPremultAlpha&&C&&g===this.RGBA&&(C=m(C)),this._unpackFlipY&&C&&p>0&&h>0){let e=new Uint8Array(C.length);for(let t=0;t<h;t++){let n=t*w,r=(h-1-t)*w;e.set(C.subarray(n,n+w),r)}C=e}this._saveError(),this._gl.texImage2D(e,t,r,p,h,b,g,d,n(C));let E=this.getError();if(this._restoreError(E),E!==this.NO_ERROR)return;x._levelWidth[t]=p,x._levelHeight[t]=h,x._format=g,x._type=d;let D=this._activeFramebuffer;if(D){let e=!1,t=this._getAttachments();for(let n=0;n<t.length;++n)if(D._attachments[t[n]]===x){e=!0;break}e&&this._activeFramebuffer&&this._updateFramebufferAttachments(this._activeFramebuffer)}}texSubImage2D(e=0,t=0,r=0,i=0,a=0,o=0,l=0,u=0,d){let f=0,p=0,h=0,g,_;if(arguments.length===7)if(u=o,h=a,l instanceof G.Pixbuf)_=l,f=_.get_width(),p=_.get_height(),d=_.get_pixels();else{g=l;let e=c(g);if(e==null)throw TypeError(`texSubImage2D(GLenum, GLint, GLint, GLint, GLenum, GLenum, ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement)`);f=e.width,p=e.height,d=e.data}else f=a,p=o,h=l;if(typeof d!=`object`)throw TypeError(`texSubImage2D(GLenum, GLint, GLint, GLint, GLint, GLint, GLenum, GLenum, Uint8Array)`);if(!this._getTexImage(e)){this.setError(this.INVALID_OPERATION);return}if(u===this.FLOAT&&!this._extensions.oes_texture_float){this.setError(this.INVALID_ENUM);return}let v=this._computePixelSize(u,h);if(v===0||!this._checkDimensions(e,f,p,t))return;if(r<0||i<0){this.setError(this.INVALID_VALUE);return}let y=s(d),b=this._computeRowStride(f,v),x=b*p;if(!y||y.length<x){this.setError(this.INVALID_OPERATION);return}if(this._unpackPremultAlpha&&y&&h===this.RGBA&&(y=m(y)),this._unpackFlipY&&y&&f>0&&p>0){let e=new Uint8Array(y.length);for(let t=0;t<p;t++){let n=t*b,r=(p-1-t)*b;e.set(y.subarray(n,n+b),r)}y=e}this._gl.texSubImage2D(e,t,r,i,f,p,h,u,n(y))}_checkUniformValid(e,t,n,r,i){if(!a(e))throw TypeError(`${n}(WebGLUniformLocation, ...)`);if(!e)return!1;if(this._checkLocationActive(e)){let n=e._activeInfo.type;if(n===this.SAMPLER_2D||n===this.SAMPLER_CUBE){if(r!==1){this.setError(this.INVALID_VALUE);return}if(i!==`i`){this.setError(this.INVALID_OPERATION);return}if(t<0||t>=this._textureUnits.length)return this.setError(this.INVALID_VALUE),!1}return g(this,n)>r?(this.setError(this.INVALID_OPERATION),!1):!0}return!1}_checkUniformValueValid(e,t,n,r,i){if(!a(e)||!a(t))throw TypeError(`${n}v(WebGLUniformLocation, Array)`);if(!e||!this._checkLocationActive(e))return!1;if(typeof t!=`object`||!t||typeof t.length!=`number`)throw TypeError(`Second argument to ${n} must be array`);return g(this,e._activeInfo.type)>r?(this.setError(this.INVALID_OPERATION),!1):t.length>=r&&t.length%r===0?e._array||t.length===r?!0:(this.setError(this.INVALID_OPERATION),!1):(this.setError(this.INVALID_VALUE),!1)}uniform1fv(e,t){if(!(!e||!this._checkUniformValueValid(e,t,`uniform1fv`,1,`f`))){if(e?._array){let n=e._array;for(let e=0;e<n.length&&e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform1f(r,t[e])}return}this._gl.uniform1f(e?._|0,t[0])}}uniform1iv(e,t){if(this._checkUniformValueValid(e,t,`uniform1iv`,1,`i`)){if(e?._array){let n=e._array;for(let e=0;e<n.length&&e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform1i(r,t[e])}return}this.uniform1i(e,t[0])}}uniform2fv(e,t){if(this._checkUniformValueValid(e,t,`uniform2fv`,2,`f`)){if(e?._array){let n=e._array;for(let e=0;e<n.length&&2*e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform2f(r,t[2*e],t[2*e+1])}return}this._gl.uniform2f(e?._||0,t[0],t[1])}}uniform2iv(e,t){if(this._checkUniformValueValid(e,t,`uniform2iv`,2,`i`)){if(e?._array){let n=e._array;for(let e=0;e<n.length&&2*e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform2i(r,t[2*e],t[2*e+1])}return}this.uniform2i(e,t[0],t[1])}}uniform3fv(e,t){if(this._checkUniformValueValid(e,t,`uniform3fv`,3,`f`)){if(e?._array){let n=e._array;for(let e=0;e<n.length&&3*e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform3f(r,t[3*e],t[3*e+1],t[3*e+2])}return}this._gl.uniform3f(e?._||0,t[0],t[1],t[2])}}uniform3iv(e,t){if(this._checkUniformValueValid(e,t,`uniform3iv`,3,`i`)){if(e?._array){let n=e._array;for(let e=0;e<n.length&&3*e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform3i(r,t[3*e],t[3*e+1],t[3*e+2])}return}this.uniform3i(e,t[0],t[1],t[2])}}uniform4fv(e,t){if(this._checkUniformValueValid(e,t,`uniform4fv`,4,`f`)){if(e?._array){let n=e._array;for(let e=0;e<n.length&&4*e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform4f(r,t[4*e],t[4*e+1],t[4*e+2],t[4*e+3])}return}this._gl.uniform4f(e?._||0,t[0],t[1],t[2],t[3])}}uniform4iv(e,t){if(this._checkUniformValueValid(e,t,`uniform4iv`,4,`i`)){if(e?._array){let n=e._array;for(let e=0;e<n.length&&4*e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform4i(r,t[4*e],t[4*e+1],t[4*e+2],t[4*e+3])}return}this.uniform4i(e,t[0],t[1],t[2],t[3])}}_checkUniformMatrix(e,t,n,r,i){if(!a(e)||typeof n!=`object`)throw TypeError(r+`(WebGLUniformLocation, Boolean, Array)`);return t||typeof n!=`object`||!n||!n.length||n.length%i*i!==0?(this.setError(this.INVALID_VALUE),!1):!e||!this._checkLocationActive(e)?!1:n.length===i*i||e._array?!0:(this.setError(this.INVALID_VALUE),!1)}uniformMatrix2fv(e,t,n){if(!this._checkUniformMatrix(e,t,n,`uniformMatrix2fv`,2))return;let r=new Float32Array(n);this._gl.uniformMatrix2fv(e?._||0,!!t,p(r))}uniformMatrix3fv(e,t,n){if(!this._checkUniformMatrix(e,t,n,`uniformMatrix3fv`,3))return;let r=new Float32Array(n);this._gl.uniformMatrix3fv(e?._||0,!!t,p(r))}uniformMatrix4fv(e,t,n){if(!this._checkUniformMatrix(e,t,n,`uniformMatrix4fv`,4))return;let r=new Float32Array(n);this._gl.uniformMatrix4fv(e?._||0,!!t,p(r))}activeTexture(e=0){let t=e-this.TEXTURE0;if(t>=0&&t<this._textureUnits.length)return this._activeTextureUnit=t,this._gl.activeTexture(e);this.setError(this.INVALID_ENUM)}attachShader(e,t){if(!a(e)||!a(t))throw TypeError(`attachShader(WebGLProgram, WebGLShader)`);if(!e||!t){this.setError(this.INVALID_VALUE);return}else if(e instanceof P&&t instanceof I&&this._checkOwns(e)&&this._checkOwns(t)&&!e._linked(t)){this._saveError(),this._gl.attachShader(e._|0,t._|0);let n=this.getError();this._restoreError(n),n===this.NO_ERROR&&e._link(t);return}this.setError(this.INVALID_OPERATION)}bindAttribLocation(e,t,n){if(!a(e)||typeof n!=`string`)throw TypeError(`bindAttribLocation(WebGLProgram, GLint, String)`);if(n+=``,!f(n)||n.length>256)this.setError(this.INVALID_VALUE);else if(/^_?webgl_a/.test(n))this.setError(this.INVALID_OPERATION);else if(this._checkWrapper(e,P))return this._gl.bindAttribLocation(e._|0,t|0,n)}bindBuffer(e=0,t){if(!a(t))throw TypeError(`bindBuffer(GLenum, WebGLBuffer)`);if(e!==this.ARRAY_BUFFER&&e!==this.ELEMENT_ARRAY_BUFFER){this.setError(this.INVALID_ENUM);return}if(!t)t=null,this._gl.bindBuffer(e,0);else if(t._pendingDelete)return;else if(this._checkWrapper(t,M)){if(t._binding&&t._binding!==e){this.setError(this.INVALID_OPERATION);return}t._binding=e|0,this._gl.bindBuffer(e,t._|0)}else return;e===this.ARRAY_BUFFER?this._vertexGlobalState.setArrayBuffer(t):this._vertexObjectState.setElementArrayBuffer(t)}bindFramebuffer(e,t){if(!a(t))throw TypeError(`bindFramebuffer(GLenum, WebGLFramebuffer)`);if(e!==this.FRAMEBUFFER){this.setError(this.INVALID_ENUM);return}if(!t)this._gl.bindFramebuffer(this.FRAMEBUFFER,this._gtkFboId);else if(t._pendingDelete)return;else if(this._checkWrapper(t,j))this._gl.bindFramebuffer(this.FRAMEBUFFER,t._|0);else return;let n=this._activeFramebuffer;n!==t&&(n&&(--n._refCount,n._checkDelete()),t&&(t._refCount+=1)),this._activeFramebuffer=t,t&&this._updateFramebufferAttachments(t)}bindRenderbuffer(e,t){if(!a(t))throw TypeError(`bindRenderbuffer(GLenum, WebGLRenderbuffer)`);if(e!==this.RENDERBUFFER){this.setError(this.INVALID_ENUM);return}if(!t)this._gl.bindRenderbuffer(e|0,0);else if(t._pendingDelete)return;else if(this._checkWrapper(t,F))this._gl.bindRenderbuffer(e|0,t._|0);else return;let n=this._activeRenderbuffer;n!==t&&(n&&(--n._refCount,n._checkDelete()),t&&(t._refCount+=1)),this._activeRenderbuffer=t}bindTexture(e=0,t){if(!a(t))throw TypeError(`bindTexture(GLenum, WebGLTexture)`);if(!this._validTextureTarget(e)){this.setError(this.INVALID_ENUM);return}let n=0;if(!t)t=null;else if(t instanceof z&&t._pendingDelete)return;else if(this._checkWrapper(t,z)){if(t._binding&&t._binding!==e){this.setError(this.INVALID_OPERATION);return}t._binding=e,t._complete&&(n=t._|0)}else return;this._saveError(),this._gl.bindTexture(e,n);let r=this.getError();if(this._restoreError(r),r!==this.NO_ERROR)return;let i=this._getActiveTextureUnit(),o=this._getActiveTexture(e);o!==t&&(o&&(--o._refCount,o._checkDelete()),t&&(t._refCount+=1)),e===this.TEXTURE_2D?i._bind2D=t:e===this.TEXTURE_CUBE_MAP&&(i._bindCube=t)}blendColor(e=0,t=0,n=0,r=0){return this._gl.blendColor(+e,+t,+n,+r)}blendEquation(e=0){if(this._validBlendMode(e))return this._gl.blendEquation(e);this.setError(this.INVALID_ENUM)}blendEquationSeparate(e=0,t=0){if(this._validBlendMode(e)&&this._validBlendMode(t))return this._gl.blendEquationSeparate(e,t);this.setError(this.INVALID_ENUM)}blendFunc(e=0,t=0){if(!this._validBlendFunc(e)||!this._validBlendFunc(t)){this.setError(this.INVALID_ENUM);return}if(this._isConstantBlendFunc(e)&&this._isConstantBlendFunc(t)){this.setError(this.INVALID_OPERATION);return}this._gl.blendFunc(e,t)}blendFuncSeparate(e=0,t=0,n=0,r=0){if(!(this._validBlendFunc(e)&&this._validBlendFunc(t)&&this._validBlendFunc(n)&&this._validBlendFunc(r))){this.setError(this.INVALID_ENUM);return}if(this._isConstantBlendFunc(e)&&this._isConstantBlendFunc(t)||this._isConstantBlendFunc(n)&&this._isConstantBlendFunc(r)){this.setError(this.INVALID_OPERATION);return}this._gl.blendFuncSeparate(e,t,n,r)}checkFramebufferStatus(e){if(e!==this.FRAMEBUFFER)return this.setError(this.INVALID_ENUM),0;let t=this._activeFramebuffer;return t?this._preCheckFramebufferStatus(t):this.FRAMEBUFFER_COMPLETE}clear(e=0){if(this._framebufferOk())return this._gl.clear(e)}clearColor(e,t,n,r){return this._gl.clearColor(+e,+t,+n,+r)}clearDepth(e){return this._gl.clearDepth(+e)}clearStencil(e=0){return this._checkStencil=!1,this._gl.clearStencil(e)}colorMask(e,t,n,r){return this._gl.colorMask(!!e,!!t,!!n,!!r)}compileShader(e){if(!a(e))throw TypeError(`compileShader(WebGLShader)`);if(this._checkWrapper(e,I)&&this._checkShaderSource(e)){let t=this.getError();this._gl.compileShader(e._|0),e._needsRecompile=!1;let n=this.getError();e._compileStatus=!!this._gl.getShaderParameter(e._|0,this.COMPILE_STATUS),e._compileInfo=this._gl.getShaderInfoLog(e._|0)||`null`,this.getError(),this.setError(t||n)}}copyTexImage2D(e=0,t=0,n=0,r=0,i=0,a=0,o=0,s=0){let c=this._getTexImage(e);if(!c){this.setError(this.INVALID_OPERATION);return}if(n!==this.RGBA&&n!==this.RGB&&n!==this.ALPHA&&n!==this.LUMINANCE&&n!==this.LUMINANCE_ALPHA){this.setError(this.INVALID_ENUM);return}if(t<0||a<0||o<0||s!==0){this.setError(this.INVALID_VALUE);return}if(t>0&&!(U.isPow2(a)&&U.isPow2(o))){this.setError(this.INVALID_VALUE);return}this._saveError(),this._gl.copyTexImage2D(e,t,n,r,i,a,o,s);let l=this.getError();this._restoreError(l),l===this.NO_ERROR&&(c._levelWidth[t]=a,c._levelHeight[t]=o,c._format=this.RGBA,c._type=this.UNSIGNED_BYTE)}copyTexSubImage2D(e=0,t=0,n=0,r=0,i=0,a=0,o=0,s=0){if(!this._getTexImage(e)){this.setError(this.INVALID_OPERATION);return}if(o<0||s<0||n<0||r<0||t<0){this.setError(this.INVALID_VALUE);return}this._gl.copyTexSubImage2D(e,t,n,r,i,a,o,s)}createBuffer(){let e=this._gl.createBuffer();if(!e||e<=0)return null;let t=new M(e,this);return this._buffers[e]=t,t}createFramebuffer(){let e=this._gl.createFramebuffer();if(e<=0)return null;let t=new j(e,this);return this._framebuffers[e]=t,t}createProgram(){let e=this._gl.createProgram();if(e<=0)return null;let t=new P(e,this);return this._programs[e]=t,t}createRenderbuffer(){let e=this._gl.createRenderbuffer();if(e<=0)return null;let t=new F(e,this);return this._renderbuffers[e]=t,t}createShader(e=0){if(e!==this.FRAGMENT_SHADER&&e!==this.VERTEX_SHADER)return this.setError(this.INVALID_ENUM),null;let t=this._gl.createShader(e);if(t<0)return null;let n=new I(t,this,e);return this._shaders[t]=n,n}createTexture(){let e=this._gl.createTexture();if(e<=0)return null;let t=new z(e,this);return this._textures[e]=t,t}cullFace(e){return this._gl.cullFace(e|0)}deleteBuffer(e){if(!a(e)||e!==null&&!(e instanceof M))throw TypeError(`deleteBuffer(WebGLBuffer)`);if(!(e instanceof M&&this._checkOwns(e))){this.setError(this.INVALID_OPERATION);return}this._vertexGlobalState._arrayBufferBinding===e&&this.bindBuffer(this.ARRAY_BUFFER,null),this._vertexObjectState._elementArrayBufferBinding===e&&this.bindBuffer(this.ELEMENT_ARRAY_BUFFER,null),this._vertexObjectState===this._defaultVertexObjectState&&this._vertexObjectState.releaseArrayBuffer(e),e._pendingDelete=!0,e._checkDelete()}deleteFramebuffer(e){if(!a(e))throw TypeError(`deleteFramebuffer(WebGLFramebuffer)`);if(!(e instanceof j&&this._checkOwns(e))){this.setError(this.INVALID_OPERATION);return}this._activeFramebuffer===e&&this.bindFramebuffer(this.FRAMEBUFFER,null),e._pendingDelete=!0,e._checkDelete()}_deleteLinkable(e,t,n){if(!a(t))throw TypeError(e+`(`+n.name+`)`);if(t instanceof n&&this._checkOwns(t)){t._pendingDelete=!0,t._checkDelete();return}this.setError(this.INVALID_OPERATION)}deleteProgram(e){return this._deleteLinkable(`deleteProgram`,e,P)}deleteRenderbuffer(e){if(!a(e))throw TypeError(`deleteRenderbuffer(WebGLRenderbuffer)`);if(!(e instanceof F&&this._checkOwns(e))){this.setError(this.INVALID_OPERATION);return}this._activeRenderbuffer===e&&this.bindRenderbuffer(this.RENDERBUFFER,null);let t=this._activeFramebuffer;this._tryDetachFramebuffer(t,e),e._pendingDelete=!0,e._checkDelete()}deleteShader(e){return this._deleteLinkable(`deleteShader`,e,I)}deleteTexture(e){if(!a(e))throw TypeError(`deleteTexture(WebGLTexture)`);if(e instanceof z){if(!this._checkOwns(e)){this.setError(this.INVALID_OPERATION);return}}else return;let t=this._activeTextureUnit;for(let t=0;t<this._textureUnits.length;++t){let n=this._textureUnits[t];n._bind2D===e?(this.activeTexture(this.TEXTURE0+t),this.bindTexture(this.TEXTURE_2D,null)):n._bindCube===e&&(this.activeTexture(this.TEXTURE0+t),this.bindTexture(this.TEXTURE_CUBE_MAP,null))}this.activeTexture(this.TEXTURE0+t);let n=this;(t=>{if(t&&t._linked(e)){let r=n._getAttachments();for(let i=0;i<r.length;++i){let a=r[i];t._attachments[a]===e&&n.framebufferTexture2D(this.FRAMEBUFFER,a,this.TEXTURE_2D,null)}}})(this._activeFramebuffer),e._pendingDelete=!0,e._checkDelete()}depthFunc(e){switch(e|=0,e){case this.NEVER:case this.LESS:case this.EQUAL:case this.LEQUAL:case this.GREATER:case this.NOTEQUAL:case this.GEQUAL:case this.ALWAYS:return this._gl.depthFunc(e);default:this.setError(this.INVALID_ENUM)}}depthMask(e){return this._gl.depthMask(!!e)}depthRange(e,t){if(e=+e,t=+t,e<=t)return this._gl.depthRange(e,t);this.setError(this.INVALID_OPERATION)}destroy(){K(`destroy`)}detachShader(e,t){if(!a(e)||!a(t))throw TypeError(`detachShader(WebGLProgram, WebGLShader)`);this._checkWrapper(e,P)&&this._checkWrapper(t,I)&&(e._linked(t)?(this._gl.detachShader(e._,t._),e._unlink(t)):this.setError(this.INVALID_OPERATION))}disable(e=0){if(this._gl.disable(e),e===this.TEXTURE_2D||e===this.TEXTURE_CUBE_MAP){let t=this._getActiveTextureUnit();t._mode===e&&(t._mode=0)}}disableVertexAttribArray(e=0){if(e<0||e>=this._vertexObjectState._attribs.length){this.setError(this.INVALID_VALUE);return}this._gl.disableVertexAttribArray(e),this._vertexObjectState._attribs[e]._isPointer=!1}drawArrays(e=0,t=0,n=0){if(t<0||n<0){this.setError(this.INVALID_VALUE);return}if(!this._checkStencilState())return;let r=v(this,e,n);if(r<0){this.setError(this.INVALID_ENUM);return}if(!this._framebufferOk()||n===0)return;let i=t;n>0&&(i=n+t-1>>>0),this._checkVertexAttribState(i)&&this._gl.drawArrays(e,t,r)}drawElements(e=0,t=0,n=0,r=0){if(t<0||r<0){this.setError(this.INVALID_VALUE);return}if(!this._checkStencilState())return;let i=this._vertexObjectState._elementArrayBufferBinding;if(!i){this.setError(this.INVALID_OPERATION);return}let a=null,o=r;if(n===this.UNSIGNED_SHORT){if(o%2){this.setError(this.INVALID_OPERATION);return}o>>=1,a=new Uint16Array(i._elements.buffer)}else if(this._extensions.oes_element_index_uint&&n===this.UNSIGNED_INT){if(o%4){this.setError(this.INVALID_OPERATION);return}o>>=2,a=new Uint32Array(i._elements.buffer)}else if(n===this.UNSIGNED_BYTE)a=i._elements;else{this.setError(this.INVALID_ENUM);return}let s=t;switch(e){case this.TRIANGLES:t%3&&(s-=t%3);break;case this.LINES:t%2&&(s-=t%2);break;case this.POINTS:break;case this.LINE_LOOP:case this.LINE_STRIP:if(t<2){this.setError(this.INVALID_OPERATION);return}break;case this.TRIANGLE_FAN:case this.TRIANGLE_STRIP:if(t<3){this.setError(this.INVALID_OPERATION);return}break;default:this.setError(this.INVALID_ENUM);return}if(!this._framebufferOk())return;if(t===0){this._checkVertexAttribState(0);return}if(t+o>>>0>a.length){this.setError(this.INVALID_OPERATION);return}let c=-1;for(let e=o;e<o+t;++e)c=Math.max(c,a[e]);if(c<0){this._checkVertexAttribState(0);return}this._checkVertexAttribState(c)&&s>0&&this._gl.drawElements(e,s,n,r)}enable(e=0){return this._gl.enable(e)}enableVertexAttribArray(e){if(e<0||e>=this._vertexObjectState._attribs.length){this.setError(this.INVALID_VALUE);return}this._gl.enableVertexAttribArray(e),this._vertexObjectState._attribs[e]._isPointer=!0}finish(){return this._gl.finish()}flush(){return this._gl.flush()}framebufferRenderbuffer(e,t,n,r){if(!a(r))throw TypeError(`framebufferRenderbuffer(GLenum, GLenum, GLenum, WebGLRenderbuffer)`);if(e!==this.FRAMEBUFFER||!this._validFramebufferAttachment(t)||n!==this.RENDERBUFFER){this.setError(this.INVALID_ENUM);return}let i=this._activeFramebuffer;if(!i){this.setError(this.INVALID_OPERATION);return}r&&!this._checkWrapper(r,F)||(i._setAttachment(r,t),this._updateFramebufferAttachments(i))}framebufferTexture2D(e,t,n,r,i=0){if(e|=0,t|=0,n|=0,i|=0,!a(r))throw TypeError(`framebufferTexture2D(GLenum, GLenum, GLenum, WebGLTexture, GLint)`);if(e!==this.FRAMEBUFFER||!this._validFramebufferAttachment(t)){this.setError(this.INVALID_ENUM);return}if(i!==0){this.setError(this.INVALID_VALUE);return}if(r&&!this._checkWrapper(r,z))return;if(n===this.TEXTURE_2D){if(r&&r._binding!==this.TEXTURE_2D){this.setError(this.INVALID_OPERATION);return}}else if(this._validCubeTarget(n)){if(r&&r._binding!==this.TEXTURE_CUBE_MAP){this.setError(this.INVALID_OPERATION);return}}else{this.setError(this.INVALID_ENUM);return}let o=this._activeFramebuffer;if(!o){this.setError(this.INVALID_OPERATION);return}o._attachmentLevel[t]=i,o._attachmentFace[t]=n,o._setAttachment(r,t),this._updateFramebufferAttachments(o)}frontFace(e=0){return this._gl.frontFace(e)}generateMipmap(e=0){return this._gl.generateMipmap(e)}getActiveAttrib(e,t){if(!a(e))throw TypeError(`getActiveAttrib(WebGLProgram)`);if(!e)throw TypeError(`getActiveAttrib(WebGLProgram, GLuint)`);if(this._checkWrapper(e,P)){if(t>=(e._linkStatus?e._attributes.length:this._gl.getProgramParameter(e._|0,this.ACTIVE_ATTRIBUTES)))return this._gl.getError(),this.setError(this.INVALID_VALUE),null;let n=this._gl.getActiveAttrib(e._|0,t|0);if(n)return new A(n)}return null}getActiveUniform(e,t){if(!a(e))throw TypeError(`getActiveUniform(WebGLProgram, GLint)`);if(!e)throw TypeError(`getActiveUniform(WebGLProgram, GLuint)`);if(this._checkWrapper(e,P)){if(t>=(e._linkStatus?e._uniforms.length:this._gl.getProgramParameter(e._|0,this.ACTIVE_UNIFORMS)))return this.setError(this.INVALID_VALUE),null;let n=this._gl.getActiveUniform(e._|0,t|0);if(n)return new A(n)}return null}getAttachedShaders(e){if(!a(e)||typeof e==`object`&&e&&!(e instanceof P))throw TypeError(`getAttachedShaders(WebGLProgram)`);if(!e)this.setError(this.INVALID_VALUE);else if(this._checkWrapper(e,P))return e._references.filter(e=>e instanceof I);return null}getAttribLocation(e,t){if(!a(e))throw TypeError(`getAttribLocation(WebGLProgram, String)`);if(t+=``,!f(t)||t.length>256)this.setError(this.INVALID_VALUE);else if(this._checkWrapper(e,P))return this._gl.getAttribLocation(e._|0,t+``);return-1}getBufferParameter(e=0,t=0){if(e!==this.ARRAY_BUFFER&&e!==this.ELEMENT_ARRAY_BUFFER)return this.setError(this.INVALID_ENUM),null;switch(t){case this.BUFFER_SIZE:case this.BUFFER_USAGE:return this._gl.getBufferParameteriv(e|0,t|0)[0];default:return this.setError(this.INVALID_ENUM),null}}getError(){return this._gl.getError()}setError(e){this._gl.setError(e)}getFramebufferAttachmentParameter(e=0,t=0,n=0){if(e!==this.FRAMEBUFFER||!this._validFramebufferAttachment(t))return this.setError(this.INVALID_ENUM),null;let r=this._activeFramebuffer;if(!r)return this.setError(this.INVALID_OPERATION),null;let i=r._attachments[t];if(i===null){if(n===this.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)return this.NONE}else if(i instanceof z)switch(n){case this.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:return i;case this.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:return this.TEXTURE;case this.FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:return r._attachmentLevel[t];case this.FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:{let e=r._attachmentFace[t];return e===this.TEXTURE_2D?0:e}}else if(i instanceof F)switch(n){case this.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:return i;case this.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:return this.RENDERBUFFER}return this.setError(this.INVALID_ENUM),null}getParameter(e=0){switch(e){case this.ARRAY_BUFFER_BINDING:return this._vertexGlobalState._arrayBufferBinding;case this.ELEMENT_ARRAY_BUFFER_BINDING:return this._vertexObjectState._elementArrayBufferBinding;case this.CURRENT_PROGRAM:return this._activeProgram;case this.FRAMEBUFFER_BINDING:return this._activeFramebuffer;case this.RENDERBUFFER_BINDING:return this._activeRenderbuffer;case this.TEXTURE_BINDING_2D:return this._getActiveTextureUnit()._bind2D;case this.TEXTURE_BINDING_CUBE_MAP:return this._getActiveTextureUnit()._bindCube;case this.VERSION:return`WebGL 1.0 0.0.1`;case this.VENDOR:return``;case this.RENDERER:return`ANGLE`;case this.SHADING_LANGUAGE_VERSION:return`WebGL GLSL ES 1.0 `;case this.COMPRESSED_TEXTURE_FORMATS:return new Uint32Array;case this.SCISSOR_BOX:return new Int32Array(this._scissorBox);case this.VIEWPORT:return new Int32Array(this._viewport);case this.MAX_VIEWPORT_DIMS:return new Int32Array([32767,32767]);case this.ALIASED_LINE_WIDTH_RANGE:case this.ALIASED_POINT_SIZE_RANGE:return new Float32Array([1,1]);case this.DEPTH_RANGE:return new Float32Array([0,1]);case this.BLEND_COLOR:case this.COLOR_CLEAR_VALUE:return new Float32Array(this._gl.getParameterfv(e,4));case this.COLOR_WRITEMASK:{let t=this._gl.getParameteriv(e,4);return[!!t[0],!!t[1],!!t[2],!!t[3]]}case this.DEPTH_CLEAR_VALUE:case this.LINE_WIDTH:case this.POLYGON_OFFSET_FACTOR:case this.POLYGON_OFFSET_UNITS:case this.SAMPLE_COVERAGE_VALUE:return this._gl.getParameterf(e);case this.BLEND:case this.CULL_FACE:case this.DEPTH_TEST:case this.DEPTH_WRITEMASK:case this.DITHER:case this.POLYGON_OFFSET_FILL:case this.SAMPLE_COVERAGE_INVERT:case this.SCISSOR_TEST:case this.STENCIL_TEST:case this.UNPACK_PREMULTIPLY_ALPHA_WEBGL:return!!this._gl.getParameteri(e);case this.UNPACK_FLIP_Y_WEBGL:return this._unpackFlipY;case this.ACTIVE_TEXTURE:case this.ALPHA_BITS:case this.BLEND_DST_ALPHA:case this.BLEND_DST_RGB:case this.BLEND_EQUATION_ALPHA:case this.BLEND_EQUATION_RGB:case this.BLEND_SRC_ALPHA:case this.BLEND_SRC_RGB:case this.BLUE_BITS:case this.CULL_FACE_MODE:case this.DEPTH_BITS:case this.DEPTH_FUNC:case this.FRONT_FACE:case this.GENERATE_MIPMAP_HINT:case this.GREEN_BITS:case this.MAX_COMBINED_TEXTURE_IMAGE_UNITS:case this.MAX_CUBE_MAP_TEXTURE_SIZE:case this.MAX_FRAGMENT_UNIFORM_VECTORS:case this.MAX_RENDERBUFFER_SIZE:case this.MAX_TEXTURE_IMAGE_UNITS:case this.MAX_TEXTURE_SIZE:case this.MAX_VARYING_VECTORS:case this.MAX_VERTEX_ATTRIBS:case this.MAX_VERTEX_TEXTURE_IMAGE_UNITS:case this.MAX_VERTEX_UNIFORM_VECTORS:case this.PACK_ALIGNMENT:case this.RED_BITS:case this.SAMPLE_BUFFERS:case this.SAMPLES:case this.STENCIL_BACK_FAIL:case this.STENCIL_BACK_FUNC:case this.STENCIL_BACK_PASS_DEPTH_FAIL:case this.STENCIL_BACK_PASS_DEPTH_PASS:case this.STENCIL_BACK_REF:case this.STENCIL_BACK_VALUE_MASK:case this.STENCIL_BACK_WRITEMASK:case this.STENCIL_BITS:case this.STENCIL_CLEAR_VALUE:case this.STENCIL_FAIL:case this.STENCIL_FUNC:case this.STENCIL_PASS_DEPTH_FAIL:case this.STENCIL_PASS_DEPTH_PASS:case this.STENCIL_REF:case this.STENCIL_VALUE_MASK:case this.STENCIL_WRITEMASK:case this.SUBPIXEL_BITS:case this.UNPACK_ALIGNMENT:case this.UNPACK_COLORSPACE_CONVERSION_WEBGL:return this._gl.getParameteri(e);case this.IMPLEMENTATION_COLOR_READ_FORMAT:case this.IMPLEMENTATION_COLOR_READ_TYPE:return this._getParameterDirect(e);default:if(this._extensions.webgl_draw_buffers){let t=this._extensions.webgl_draw_buffers;switch(e){case t.DRAW_BUFFER0_WEBGL:case t.DRAW_BUFFER1_WEBGL:case t.DRAW_BUFFER2_WEBGL:case t.DRAW_BUFFER3_WEBGL:case t.DRAW_BUFFER4_WEBGL:case t.DRAW_BUFFER5_WEBGL:case t.DRAW_BUFFER6_WEBGL:case t.DRAW_BUFFER7_WEBGL:case t.DRAW_BUFFER8_WEBGL:case t.DRAW_BUFFER9_WEBGL:case t.DRAW_BUFFER10_WEBGL:case t.DRAW_BUFFER11_WEBGL:case t.DRAW_BUFFER12_WEBGL:case t.DRAW_BUFFER13_WEBGL:case t.DRAW_BUFFER14_WEBGL:case t.DRAW_BUFFER15_WEBGL:return t._buffersState.length===1&&t._buffersState[0]===this.BACK?this.BACK:this._getParameterDirect(e);case t.MAX_DRAW_BUFFERS_WEBGL:case t.MAX_COLOR_ATTACHMENTS_WEBGL:return this._getParameterDirect(e)}}return this._extensions.oes_standard_derivatives&&e===this._extensions.oes_standard_derivatives.FRAGMENT_SHADER_DERIVATIVE_HINT_OES||this._extensions.ext_texture_filter_anisotropic&&e===this._extensions.ext_texture_filter_anisotropic.MAX_TEXTURE_MAX_ANISOTROPY_EXT?this._getParameterDirect(e):this._extensions.oes_vertex_array_object&&e===this._extensions.oes_vertex_array_object.VERTEX_ARRAY_BINDING_OES?this._extensions.oes_vertex_array_object._activeVertexArrayObject:(this.setError(this.INVALID_ENUM),null)}}getProgramInfoLog(e){if(!a(e))throw TypeError(`getProgramInfoLog(WebGLProgram)`);return this._checkWrapper(e,P)?e._linkInfoLog:null}getProgramParameter(e,t=0){if(!a(e))throw TypeError(`getProgramParameter(WebGLProgram, GLenum)`);if(this._checkWrapper(e,P)){switch(t){case this.DELETE_STATUS:return e._pendingDelete;case this.LINK_STATUS:return e._linkStatus;case this.VALIDATE_STATUS:return!!this._gl.getProgramParameter(e._,t);case this.ATTACHED_SHADERS:return this._gl.getProgramParameter(e._,t);case this.ACTIVE_ATTRIBUTES:return e._linkStatus?e._attributes.length:this._gl.getProgramParameter(e._,t);case this.ACTIVE_UNIFORMS:return e._linkStatus?e._uniforms.length:this._gl.getProgramParameter(e._,t)}this.setError(this.INVALID_ENUM)}return null}getRenderbufferParameter(e=0,t=0){if(e!==this.RENDERBUFFER)return this.setError(this.INVALID_ENUM),null;let n=this._activeRenderbuffer;if(!n)return this.setError(this.INVALID_OPERATION),null;switch(t){case this.RENDERBUFFER_INTERNAL_FORMAT:return n._format;case this.RENDERBUFFER_WIDTH:return n._width;case this.RENDERBUFFER_HEIGHT:return n._height;case this.MAX_RENDERBUFFER_SIZE:case this.RENDERBUFFER_RED_SIZE:case this.RENDERBUFFER_GREEN_SIZE:case this.RENDERBUFFER_BLUE_SIZE:case this.RENDERBUFFER_ALPHA_SIZE:case this.RENDERBUFFER_DEPTH_SIZE:case this.RENDERBUFFER_STENCIL_SIZE:return this._gl.getRenderbufferParameter(e,t)}return this.setError(this.INVALID_ENUM),null}getShaderInfoLog(e){if(!a(e))throw TypeError(`getShaderInfoLog(WebGLShader)`);return this._checkWrapper(e,I)?e._compileInfo:null}getShaderParameter(e,t=0){if(!a(e))throw TypeError(`getShaderParameter(WebGLShader, GLenum)`);if(this._checkWrapper(e,I)){switch(t){case this.DELETE_STATUS:return e._pendingDelete;case this.COMPILE_STATUS:return e._compileStatus;case this.SHADER_TYPE:return e._type}this.setError(this.INVALID_ENUM)}return null}getShaderPrecisionFormat(e=0,t=0){if(!(e===this.FRAGMENT_SHADER||e===this.VERTEX_SHADER)||!(t===this.LOW_FLOAT||t===this.MEDIUM_FLOAT||t===this.HIGH_FLOAT||t===this.LOW_INT||t===this.MEDIUM_INT||t===this.HIGH_INT))return this.setError(this.INVALID_ENUM),null;let n=this._gl.getShaderPrecisionFormat(e,t);return n?new L(n):null}getShaderSource(e){if(!a(e))throw TypeError(`Input to getShaderSource must be an object`);return this._checkWrapper(e,I)?e._source:null}getSupportedExtensions(){let e=[`ANGLE_instanced_arrays`,`STACKGL_resize_drawingbuffer`,`STACKGL_destroy_context`],t=this._gl.getSupportedExtensions();return t?(t.indexOf(`GL_OES_element_index_uint`)>=0&&e.push(`OES_element_index_uint`),t.indexOf(`GL_OES_standard_derivatives`)>=0&&e.push(`OES_standard_derivatives`),t.indexOf(`GL_OES_texture_float`)>=0&&e.push(`OES_texture_float`),t.indexOf(`GL_OES_texture_float_linear`)>=0&&e.push(`OES_texture_float_linear`),(t.indexOf(`GL_OES_texture_half_float`)>=0||t.indexOf(`GL_ARB_half_float_pixel`)>=0)&&e.push(`OES_texture_half_float`),(t.indexOf(`GL_EXT_color_buffer_float`)>=0||t.indexOf(`GL_ARB_color_buffer_float`)>=0)&&e.push(`EXT_color_buffer_float`),t.indexOf(`GL_EXT_color_buffer_half_float`)>=0&&e.push(`EXT_color_buffer_half_float`),t.indexOf(`EXT_draw_buffers`)>=0&&e.push(`WEBGL_draw_buffers`),t.indexOf(`EXT_blend_minmax`)>=0&&e.push(`EXT_blend_minmax`),t.indexOf(`EXT_texture_filter_anisotropic`)>=0&&e.push(`EXT_texture_filter_anisotropic`),t.indexOf(`GL_OES_vertex_array_object`)>=0&&e.push(`OES_vertex_array_object`),e):e}_getTexParameterDirect(e=0,t=0){return this._gl.getTexParameterx(e,t)?.unpack()}getTexParameter(e=0,t=0){if(!this._checkTextureTarget(e))return null;let n=this._getActiveTextureUnit();if(e===this.TEXTURE_2D&&!n._bind2D||e===this.TEXTURE_CUBE_MAP&&!n._bindCube)return this.setError(this.INVALID_OPERATION),null;switch(t){case this.TEXTURE_MAG_FILTER:case this.TEXTURE_MIN_FILTER:case this.TEXTURE_WRAP_S:case this.TEXTURE_WRAP_T:return this._getTexParameterDirect(e,t)}return this._extensions.ext_texture_filter_anisotropic&&t===this._extensions.ext_texture_filter_anisotropic.TEXTURE_MAX_ANISOTROPY_EXT?this._getTexParameterDirect(e,t):(this.setError(this.INVALID_ENUM),null)}getUniform(e,t){if(!a(e)||!a(t))throw TypeError(`getUniform(WebGLProgram, WebGLUniformLocation)`);if(!e)return this.setError(this.INVALID_VALUE),null;if(!t)return null;if(this._checkWrapper(e,P)){if(!o(e,t))return this.setError(this.INVALID_OPERATION),null;let n=this._gl.getUniform(e._|0,t._|0);if(!n)return null;switch(t._activeInfo.type){case this.FLOAT:return n[0];case this.FLOAT_VEC2:return new Float32Array(n.slice(0,2));case this.FLOAT_VEC3:return new Float32Array(n.slice(0,3));case this.FLOAT_VEC4:return new Float32Array(n.slice(0,4));case this.INT:return n[0]|0;case this.INT_VEC2:return new Int32Array(n.slice(0,2));case this.INT_VEC3:return new Int32Array(n.slice(0,3));case this.INT_VEC4:return new Int32Array(n.slice(0,4));case this.BOOL:return!!n[0];case this.BOOL_VEC2:return[!!n[0],!!n[1]];case this.BOOL_VEC3:return[!!n[0],!!n[1],!!n[2]];case this.BOOL_VEC4:return[!!n[0],!!n[1],!!n[2],!!n[3]];case this.FLOAT_MAT2:return new Float32Array(n.slice(0,4));case this.FLOAT_MAT3:return new Float32Array(n.slice(0,9));case this.FLOAT_MAT4:return new Float32Array(n.slice(0,16));case this.SAMPLER_2D:case this.SAMPLER_CUBE:return n[0]|0;default:return null}}return null}getUniformLocation(e,n){if(!a(e))throw TypeError(`getUniformLocation(WebGLProgram, String)`);if(n+=``,!f(n))return this.setError(this.INVALID_VALUE),null;if(this._checkWrapper(e,P)){let r=this._gl.getUniformLocation(e._|0,n);if(r!==null&&r>=0){let i=n;/\[\d+\]$/.test(n)&&(i=n.replace(/\[\d+\]$/,`[0]`));let a=i+`[0]`,o=null;for(let t=0;t<e._uniforms.length;++t){let n=e._uniforms[t];if(n.name===i||n.name===a){o={size:n.size,type:n.type,name:n.name};break}}o||={name:i,type:0,size:1};let s=new t(r,e,o),c=n.match(/\[(\d+)\]$/),l=c?+c[1]:-1;if(/\[0\]$/.test(o.name)&&(l===-1||l===0)){let t=o.name.replace(/\[0\]$/,``),n=[];this._saveError();for(let r=0;this.getError()===this.NO_ERROR;++r){let i=this._gl.getUniformLocation(e._|0,t+`[`+r+`]`);if(this.getError()!==this.NO_ERROR||i==null||i<0)break;n.push(i)}this._restoreError(this.NO_ERROR),s._array=n}else if(l>0&&l>=o.size)return null;return s}}return null}getVertexAttrib(e=0,t=0){if(e<0||e>=this._vertexObjectState._attribs.length)return this.setError(this.INVALID_VALUE),null;let n=this._vertexObjectState._attribs[e],r=this._vertexGlobalState._attribs[e]._data,i=this._extensions.angle_instanced_arrays;if(i&&t===i.VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE)return n._divisor;switch(t){case this.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:return n._pointerBuffer;case this.VERTEX_ATTRIB_ARRAY_ENABLED:return n._isPointer;case this.VERTEX_ATTRIB_ARRAY_SIZE:return n._inputSize;case this.VERTEX_ATTRIB_ARRAY_STRIDE:return n._inputStride;case this.VERTEX_ATTRIB_ARRAY_TYPE:return n._pointerType;case this.VERTEX_ATTRIB_ARRAY_NORMALIZED:return n._pointerNormal;case this.CURRENT_VERTEX_ATTRIB:return new Float32Array(r);default:return this.setError(this.INVALID_ENUM),null}}getVertexAttribOffset(e=0,t=0){return e<0||e>=this._vertexObjectState._attribs.length?(this.setError(this.INVALID_VALUE),-1):t===this.VERTEX_ATTRIB_ARRAY_POINTER?this._vertexObjectState._attribs[e]._pointerOffset:(this.setError(this.INVALID_ENUM),-1)}hint(e=0,t=0){if(!(e===this.GENERATE_MIPMAP_HINT||this._extensions.oes_standard_derivatives&&e===this._extensions.oes_standard_derivatives.FRAGMENT_SHADER_DERIVATIVE_HINT_OES)){this.setError(this.INVALID_ENUM);return}if(t!==this.FASTEST&&t!==this.NICEST&&t!==this.DONT_CARE){this.setError(this.INVALID_ENUM);return}return this._gl.hint(e,t)}isBuffer(e){return this._isObject(e,`isBuffer`,M)?this._gl.isBuffer(e?._):!1}isContextLost(){return!1}isEnabled(e=0){return this._gl.isEnabled(e)}isFramebuffer(e){return this._isObject(e,`isFramebuffer`,j)?this._gl.isFramebuffer(e?._):!1}isProgram(e){return this._isObject(e,`isProgram`,P)?this._gl.isProgram(e?._):!1}isRenderbuffer(e){return this._isObject(e,`isRenderbuffer`,F)?this._gl.isRenderbuffer(e?._):!1}isShader(e){return this._isObject(e,`isShader`,I)?this._gl.isShader(e?._):!1}isTexture(e){return this._isObject(e,`isTexture`,z)?this._gl.isTexture(e?._):!1}lineWidth(e){if(isNaN(e)){this.setError(this.INVALID_VALUE);return}return this._gl.lineWidth(+e)}linkProgram(e){if(!a(e))throw TypeError(`linkProgram(WebGLProgram)`);if(this._checkWrapper(e,P)){e._linkCount+=1,e._attributes=[];let t=this.getError();for(let t of e._references)t instanceof I&&t._needsRecompile&&(this._gl.compileShader(t._|0),t._needsRecompile=!1);this._gl.linkProgram(e._|0);let n=this.getError();n===this.NO_ERROR&&(e._linkStatus=this._fixupLink(e)),this.getError(),this.setError(t||n)}}pixelStorei(e=0,t=0){if(typeof t==`boolean`&&(t=t===!1?0:1),e===this.UNPACK_ALIGNMENT)if(t===1||t===2||t===4||t===8)this._unpackAlignment=t;else{this.setError(this.INVALID_VALUE);return}else if(e===this.PACK_ALIGNMENT)if(t===1||t===2||t===4||t===8)this._packAlignment=t;else{this.setError(this.INVALID_VALUE);return}else if(e===this.UNPACK_COLORSPACE_CONVERSION_WEBGL){if(!(t===this.NONE||t===this.BROWSER_DEFAULT_WEBGL)){this.setError(this.INVALID_VALUE);return}}else if(e===this.UNPACK_FLIP_Y_WEBGL){this._unpackFlipY=!!t;return}else if(e===this.UNPACK_PREMULTIPLY_ALPHA_WEBGL){this._unpackPremultAlpha=!!t;return}return this._gl.pixelStorei(e,t)}polygonOffset(e,t){return this._gl.polygonOffset(+e,+t)}renderbufferStorage(e=0,t=0,n=0,r=0){if(e!==this.RENDERBUFFER){this.setError(this.INVALID_ENUM);return}let i=this._activeRenderbuffer;if(!i){this.setError(this.INVALID_OPERATION);return}if(t!==this.RGBA4&&t!==this.RGB565&&t!==this.RGB5_A1&&t!==this.DEPTH_COMPONENT16&&t!==this.STENCIL_INDEX&&t!==this.STENCIL_INDEX8&&t!==this.DEPTH_STENCIL){this.setError(this.INVALID_ENUM);return}this._saveError(),this._gl.renderbufferStorage(e,t,n,r);let a=this.getError();if(this._restoreError(a),a!==this.NO_ERROR)return;i._width=n,i._height=r,i._format=t;let o=this._activeFramebuffer;if(o){let e=!1,t=this._getAttachments();for(let n=0;n<t.length;++n)if(o._attachments[t[n]]===i){e=!0;break}e&&this._updateFramebufferAttachments(this._activeFramebuffer)}}resize(e=0,t=0){if(e|=0,t|=0,e>0&&t>0)(e!==this.drawingBufferWidth||t!==this.drawingBufferHeight)&&this._resizeDrawingBuffer(e,t);else throw Error(`Invalid surface dimensions`)}sampleCoverage(e,t){return this._gl.sampleCoverage(+e,!!t)}scissor(e,t,n,r){return this._scissorBox[0]=e|0,this._scissorBox[1]=t|0,this._scissorBox[2]=n|0,this._scissorBox[3]=r|0,this._gl.scissor(e|0,t|0,n|0,r|0)}shaderSource(e,t){if(!a(e))throw TypeError(`shaderSource(WebGLShader, String)`);if(!e||!t&&typeof t!=`string`){this.setError(this.INVALID_VALUE);return}f(t)?this._checkWrapper(e,I)&&(t=this._wrapShader(e._type,t),this._gl.shaderSource(e._|0,t),e._source=t,e._needsRecompile=!0):this.setError(this.INVALID_VALUE)}stencilFunc(e,t,n){return this._checkStencil=!0,this._gl.stencilFunc(e|0,t|0,n|0)}stencilFuncSeparate(e,t,n,r){return this._checkStencil=!0,this._gl.stencilFuncSeparate(e|0,t|0,n|0,r|0)}stencilMask(e){return this._checkStencil=!0,this._gl.stencilMask(e>>>0)}stencilMaskSeparate(e,t){return this._checkStencil=!0,this._gl.stencilMaskSeparate(e|0,t>>>0)}stencilOp(e,t,n){return this._checkStencil=!0,this._gl.stencilOp(e|0,t|0,n|0)}stencilOpSeparate(e,t,n,r){return this._checkStencil=!0,this._gl.stencilOpSeparate(e|0,t|0,n|0,r|0)}texParameterf(e=0,t=0,n){if(n=+n,this._checkTextureTarget(e)){switch(this._verifyTextureCompleteness(e,t,n),t){case this.TEXTURE_MIN_FILTER:case this.TEXTURE_MAG_FILTER:case this.TEXTURE_WRAP_S:case this.TEXTURE_WRAP_T:return this._gl.texParameterf(e,t,n)}if(this._extensions.ext_texture_filter_anisotropic&&t===this._extensions.ext_texture_filter_anisotropic.TEXTURE_MAX_ANISOTROPY_EXT)return this._gl.texParameterf(e,t,n);this.setError(this.INVALID_ENUM)}}texParameteri(e=0,t=0,n=0){if(this._checkTextureTarget(e)){switch(this._verifyTextureCompleteness(e,t,n),t){case this.TEXTURE_MIN_FILTER:case this.TEXTURE_MAG_FILTER:case this.TEXTURE_WRAP_S:case this.TEXTURE_WRAP_T:return this._gl.texParameteri(e,t,n)}if(this._extensions.ext_texture_filter_anisotropic&&t===this._extensions.ext_texture_filter_anisotropic.TEXTURE_MAX_ANISOTROPY_EXT)return this._gl.texParameteri(e,t,n);this.setError(this.INVALID_ENUM)}}uniform1f(e,t){if(this._checkUniformValid(e,t,`uniform1f`,1,`f`))return this._gl.uniform1f(e?._||0,t)}uniform1i(e,t){return this._gl.uniform1i(e?._||0,t)}uniform2f(e,t,n){if(this._checkUniformValid(e,t,`uniform2f`,2,`f`))return this._gl.uniform2f(e?._||0,t,n)}uniform2i(e,t,n){this._checkUniformValid(e,t,`uniform2i`,2,`i`)&&this._gl.uniform2i(e?._||0,t,n)}uniform3f(e,t,n,r){if(this._checkUniformValid(e,t,`uniform3f`,3,`f`))return this._gl.uniform3f(e?._||0,t,n,r)}uniform3i(e,t,n,r){if(this._checkUniformValid(e,t,`uniform3i`,3,`i`))return this._gl.uniform3i(e?._||0,t,n,r)}uniform4f(e,t,n,r,i){if(!this._checkUniformValid(e,t,`uniform4f`,4,`f`)){console.error(`uniform4f is not valid!`);return}return this._gl.uniform4f(e?._||0,t,n,r,i)}uniform4i(e,t,n,r,i){if(this._checkUniformValid(e,t,`uniform4i`,4,`i`))return this._gl.uniform4i(e?._||0,t,n,r,i)}useProgram(e){if(!a(e))throw TypeError(`useProgram(WebGLProgram)`);if(!e)return this._switchActiveProgram(this._activeProgram),this._activeProgram=null,this._gl.useProgram(0);if(this._checkWrapper(e,P))return this._activeProgram!==e&&(this._switchActiveProgram(this._activeProgram),this._activeProgram=e,e._refCount+=1),this._gl.useProgram(e._|0)}validateProgram(e){if(this._checkWrapper(e,P)){this._gl.validateProgram(e._|0);let t=this.getError();t===this.NO_ERROR&&(e._linkInfoLog=this._gl.getProgramInfoLog(e._|0)),this.getError(),this.setError(t)}}vertexAttrib1f(e,t){if(e|=0,!this._checkVertexIndex(e))return;let n=this._vertexGlobalState._attribs[e]._data;return n[3]=1,n[1]=n[2]=0,n[0]=t,this._gl.vertexAttrib1f(e|0,+t)}vertexAttrib1fv(e,t){if(e|=0,!this._checkVertexIndex(e))return;if(typeof t!=`object`||!t||t.length<1){this.setError(this.INVALID_OPERATION);return}let n=this._vertexGlobalState._attribs[e]._data;return n[3]=1,n[2]=0,n[1]=0,n[0]=t[0],this._gl.vertexAttrib1f(e|0,+t[0])}vertexAttrib2f(e,t,n){if(e|=0,!this._checkVertexIndex(e))return;let r=this._vertexGlobalState._attribs[e]._data;return r[3]=1,r[2]=0,r[1]=n,r[0]=t,this._gl.vertexAttrib2f(e|0,+t,+n)}vertexAttrib2fv(e,t){if(e|=0,!this._checkVertexIndex(e))return;if(typeof t!=`object`||!t||t.length<2){this.setError(this.INVALID_OPERATION);return}let n=this._vertexGlobalState._attribs[e]._data;return n[3]=1,n[2]=0,n[1]=t[1],n[0]=t[0],this._gl.vertexAttrib2f(e|0,+t[0],+t[1])}vertexAttrib3f(e,t,n,r){if(e|=0,!this._checkVertexIndex(e))return;let i=this._vertexGlobalState._attribs[e]._data;return i[3]=1,i[2]=r,i[1]=n,i[0]=t,this._gl.vertexAttrib3f(e|0,+t,+n,+r)}vertexAttrib3fv(e,t){if(e|=0,!this._checkVertexIndex(e))return;if(typeof t!=`object`||!t||t.length<3){this.setError(this.INVALID_OPERATION);return}let n=this._vertexGlobalState._attribs[e]._data;return n[3]=1,n[2]=t[2],n[1]=t[1],n[0]=t[0],this._gl.vertexAttrib3f(e|0,+t[0],+t[1],+t[2])}vertexAttrib4f(e=0,t,n,r,i){if(!this._checkVertexIndex(e))return;let a=this._vertexGlobalState._attribs[e]._data;return a[3]=i,a[2]=r,a[1]=n,a[0]=t,this._gl.vertexAttrib4f(e|0,+t,+n,+r,+i)}vertexAttrib4fv(e,t){if(e|=0,!this._checkVertexIndex(e))return;if(typeof t!=`object`||!t||t.length<4){this.setError(this.INVALID_OPERATION);return}let n=this._vertexGlobalState._attribs[e]._data;return n[3]=t[3],n[2]=t[2],n[1]=t[1],n[0]=t[0],this._gl.vertexAttrib4f(e|0,+t[0],+t[1],+t[2],+t[3])}vertexAttribPointer(e=0,t=0,n=0,r=!1,i=0,a=0){if(i<0||a<0){this.setError(this.INVALID_VALUE);return}if(i<0||a<0||e<0||e>=this._vertexObjectState._attribs.length||!(t===1||t===2||t===3||t===4)){this.setError(this.INVALID_VALUE);return}if(this._vertexGlobalState._arrayBufferBinding===null){this.setError(this.INVALID_OPERATION);return}let o=h(this,n);if(o===0||n===this.INT||n===this.UNSIGNED_INT){this.setError(this.INVALID_ENUM);return}if(i>255||i<0){this.setError(this.INVALID_VALUE);return}if(i%o!==0||a%o!==0){this.setError(this.INVALID_OPERATION);return}this._gl.vertexAttribPointer(e,t,n,r,i,a),this._vertexObjectState.setVertexAttribPointer(this._vertexGlobalState._arrayBufferBinding,e,t*o,a,i||t*o,n,r,i,t)}viewport(e,t,n,r){return this._viewport[0]=e|0,this._viewport[1]=t|0,this._viewport[2]=n|0,this._viewport[3]=r|0,this._gl.viewport(e,t,n,r)}};export{Y as WebGLContextBase};
|