@gjsify/webgl 0.0.2 → 0.0.3
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/cjs/extensions/ext-blend-minmax.js +4 -23
- package/lib/cjs/extensions/ext-texture-filter-anisotropic.js +4 -23
- package/lib/cjs/extensions/oes-element-index-unit.js +4 -23
- package/lib/cjs/extensions/oes-standard-derivatives.js +4 -23
- package/lib/cjs/extensions/oes-texture-float-linear.js +4 -23
- package/lib/cjs/extensions/oes-texture-float.js +4 -23
- package/lib/cjs/extensions/stackgl-destroy-context.js +4 -23
- package/lib/cjs/extensions/stackgl-resize-drawing-buffer.js +4 -23
- package/lib/cjs/html-canvas-element.js +15 -34
- package/lib/cjs/index.js +18 -34
- package/lib/cjs/index.spec.js +51 -80
- package/lib/cjs/linkable.js +3 -22
- package/lib/cjs/test.js +3 -25
- package/lib/cjs/types/constructor.js +0 -15
- package/lib/cjs/types/extension.js +0 -15
- package/lib/cjs/types/index.js +5 -21
- package/lib/cjs/types/typed-array.js +0 -15
- package/lib/cjs/types/webgl-constants.js +0 -15
- package/lib/cjs/types/webgl-context-attribute-options.js +0 -15
- package/lib/cjs/utils.js +24 -53
- package/lib/cjs/webgl-active-info.js +3 -22
- package/lib/cjs/webgl-buffer.js +6 -25
- package/lib/cjs/webgl-context-attributes.js +4 -23
- package/lib/cjs/webgl-drawing-buffer-wrapper.js +3 -22
- package/lib/cjs/webgl-framebuffer.js +6 -25
- package/lib/cjs/webgl-program.js +6 -25
- package/lib/cjs/webgl-renderbuffer.js +6 -25
- package/lib/cjs/webgl-rendering-context.js +204 -216
- package/lib/cjs/webgl-shader-precision-format.js +4 -23
- package/lib/cjs/webgl-shader.js +6 -25
- package/lib/cjs/webgl-texture-unit.js +3 -22
- package/lib/cjs/webgl-texture.js +6 -25
- package/lib/cjs/webgl-uniform-location.js +4 -23
- package/lib/cjs/webgl-vertex-attribute.js +9 -28
- package/package.json +5 -5
|
@@ -1,80 +1,64 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
var import_stackgl_resize_drawing_buffer = require("./extensions/stackgl-resize-drawing-buffer.js");
|
|
47
|
-
var import_ext_blend_minmax = require("./extensions/ext-blend-minmax.js");
|
|
48
|
-
var import_ext_texture_filter_anisotropic = require("./extensions/ext-texture-filter-anisotropic.js");
|
|
49
|
-
var import_webgl_active_info = require("./webgl-active-info.js");
|
|
50
|
-
var import_webgl_framebuffer = require("./webgl-framebuffer.js");
|
|
51
|
-
var import_webgl_buffer = require("./webgl-buffer.js");
|
|
52
|
-
var import_webgl_drawing_buffer_wrapper = require("./webgl-drawing-buffer-wrapper.js");
|
|
53
|
-
var import_webgl_program = require("./webgl-program.js");
|
|
54
|
-
var import_webgl_renderbuffer = require("./webgl-renderbuffer.js");
|
|
55
|
-
var import_webgl_shader = require("./webgl-shader.js");
|
|
56
|
-
var import_webgl_shader_precision_format = require("./webgl-shader-precision-format.js");
|
|
57
|
-
var import_webgl_texture_unit = require("./webgl-texture-unit.js");
|
|
58
|
-
var import_webgl_texture = require("./webgl-texture.js");
|
|
59
|
-
var import_webgl_uniform_location = require("./webgl-uniform-location.js");
|
|
60
|
-
var import_webgl_vertex_attribute = require("./webgl-vertex-attribute.js");
|
|
61
|
-
var import_utils2 = require("@gjsify/utils");
|
|
1
|
+
import "@girs/gdkpixbuf-2.0";
|
|
2
|
+
import * as bits from "bit-twiddle";
|
|
3
|
+
import tokenize from "glsl-tokenizer/string";
|
|
4
|
+
import Gwebgl from "@girs/gwebgl-0.1";
|
|
5
|
+
import GdkPixbuf from "gi://GdkPixbuf?version=2.0";
|
|
6
|
+
import { WebGLContextAttributes } from "./webgl-context-attributes.js";
|
|
7
|
+
import {
|
|
8
|
+
extractImageData,
|
|
9
|
+
checkObject,
|
|
10
|
+
checkFormat,
|
|
11
|
+
checkUniform,
|
|
12
|
+
convertPixels,
|
|
13
|
+
validCubeTarget,
|
|
14
|
+
formatSize,
|
|
15
|
+
isTypedArray,
|
|
16
|
+
arrayToUint8Array,
|
|
17
|
+
flag,
|
|
18
|
+
listToArray,
|
|
19
|
+
isValidString,
|
|
20
|
+
uniformTypeSize,
|
|
21
|
+
vertexCount,
|
|
22
|
+
typeSize,
|
|
23
|
+
Uint8ArrayToVariant
|
|
24
|
+
} from "./utils.js";
|
|
25
|
+
import { getOESElementIndexUint } from "./extensions/oes-element-index-unit.js";
|
|
26
|
+
import { getOESStandardDerivatives } from "./extensions/oes-standard-derivatives.js";
|
|
27
|
+
import { getOESTextureFloat } from "./extensions/oes-texture-float.js";
|
|
28
|
+
import { getOESTextureFloatLinear } from "./extensions/oes-texture-float-linear.js";
|
|
29
|
+
import { getSTACKGLDestroyContext } from "./extensions/stackgl-destroy-context.js";
|
|
30
|
+
import { getSTACKGLResizeDrawingBuffer } from "./extensions/stackgl-resize-drawing-buffer.js";
|
|
31
|
+
import { getEXTBlendMinMax } from "./extensions/ext-blend-minmax.js";
|
|
32
|
+
import { getEXTTextureFilterAnisotropic } from "./extensions/ext-texture-filter-anisotropic.js";
|
|
33
|
+
import { WebGLActiveInfo } from "./webgl-active-info.js";
|
|
34
|
+
import { WebGLFramebuffer } from "./webgl-framebuffer.js";
|
|
35
|
+
import { WebGLBuffer } from "./webgl-buffer.js";
|
|
36
|
+
import { WebGLDrawingBufferWrapper } from "./webgl-drawing-buffer-wrapper.js";
|
|
37
|
+
import { WebGLProgram } from "./webgl-program.js";
|
|
38
|
+
import { WebGLRenderbuffer } from "./webgl-renderbuffer.js";
|
|
39
|
+
import { WebGLShader } from "./webgl-shader.js";
|
|
40
|
+
import { WebGLShaderPrecisionFormat } from "./webgl-shader-precision-format.js";
|
|
41
|
+
import { WebGLTextureUnit } from "./webgl-texture-unit.js";
|
|
42
|
+
import { WebGLTexture } from "./webgl-texture.js";
|
|
43
|
+
import { WebGLUniformLocation } from "./webgl-uniform-location.js";
|
|
44
|
+
import { WebGLVertexArrayObjectState, WebGLVertexArrayGlobalState } from "./webgl-vertex-attribute.js";
|
|
45
|
+
import { warnNotImplemented } from "@gjsify/utils";
|
|
62
46
|
const VERSION = "0.0.1";
|
|
63
47
|
let CONTEXT_COUNTER = 0;
|
|
64
48
|
const MAX_UNIFORM_LENGTH = 256;
|
|
65
49
|
const MAX_ATTRIBUTE_LENGTH = 256;
|
|
66
50
|
const availableExtensions = {
|
|
67
51
|
// angle_instanced_arrays: getANGLEInstancedArrays,
|
|
68
|
-
oes_element_index_uint:
|
|
69
|
-
oes_texture_float:
|
|
70
|
-
oes_texture_float_linear:
|
|
71
|
-
oes_standard_derivatives:
|
|
52
|
+
oes_element_index_uint: getOESElementIndexUint,
|
|
53
|
+
oes_texture_float: getOESTextureFloat,
|
|
54
|
+
oes_texture_float_linear: getOESTextureFloatLinear,
|
|
55
|
+
oes_standard_derivatives: getOESStandardDerivatives,
|
|
72
56
|
// oes_vertex_array_object: getOESVertexArrayObject,
|
|
73
|
-
stackgl_destroy_context:
|
|
74
|
-
stackgl_resize_drawingbuffer:
|
|
57
|
+
stackgl_destroy_context: getSTACKGLDestroyContext,
|
|
58
|
+
stackgl_resize_drawingbuffer: getSTACKGLResizeDrawingBuffer,
|
|
75
59
|
// webgl_draw_buffers: getWebGLDrawBuffers,
|
|
76
|
-
ext_blend_minmax:
|
|
77
|
-
ext_texture_filter_anisotropic:
|
|
60
|
+
ext_blend_minmax: getEXTBlendMinMax,
|
|
61
|
+
ext_texture_filter_anisotropic: getEXTTextureFilterAnisotropic
|
|
78
62
|
};
|
|
79
63
|
class GjsifyWebGLRenderingContext {
|
|
80
64
|
constructor(canvas, options = {}) {
|
|
@@ -107,7 +91,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
107
91
|
this._attrib0Buffer = null;
|
|
108
92
|
this._textureUnits = [];
|
|
109
93
|
this._drawingBuffer = null;
|
|
110
|
-
this._native = new
|
|
94
|
+
this._native = new Gwebgl.WebGLRenderingContext(options);
|
|
111
95
|
this._initGLConstants();
|
|
112
96
|
this.DEFAULT_ATTACHMENTS = [
|
|
113
97
|
this.COLOR_ATTACHMENT0,
|
|
@@ -117,16 +101,16 @@ class GjsifyWebGLRenderingContext {
|
|
|
117
101
|
];
|
|
118
102
|
this.DEFAULT_COLOR_ATTACHMENTS = [this.COLOR_ATTACHMENT0];
|
|
119
103
|
this.canvas = canvas;
|
|
120
|
-
this._contextAttributes = new
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
104
|
+
this._contextAttributes = new WebGLContextAttributes(
|
|
105
|
+
flag(options, "alpha", true),
|
|
106
|
+
flag(options, "depth", true),
|
|
107
|
+
flag(options, "stencil", false),
|
|
124
108
|
false,
|
|
125
109
|
// flag(options, 'antialias', true),
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
110
|
+
flag(options, "premultipliedAlpha", true),
|
|
111
|
+
flag(options, "preserveDrawingBuffer", false),
|
|
112
|
+
flag(options, "preferLowPowerToHighPerformance", false),
|
|
113
|
+
flag(options, "failIfMajorPerformanceCaveat", false)
|
|
130
114
|
);
|
|
131
115
|
const width = this.drawingBufferWidth || options.width || 0;
|
|
132
116
|
const height = this.drawingBufferHeight || options.height || 0;
|
|
@@ -135,12 +119,12 @@ class GjsifyWebGLRenderingContext {
|
|
|
135
119
|
const numTextures = this.getParameter(this.MAX_COMBINED_TEXTURE_IMAGE_UNITS);
|
|
136
120
|
this._textureUnits = new Array(numTextures);
|
|
137
121
|
for (let i = 0; i < numTextures; ++i) {
|
|
138
|
-
this._textureUnits[i] = new
|
|
122
|
+
this._textureUnits[i] = new WebGLTextureUnit(this, i);
|
|
139
123
|
}
|
|
140
124
|
this.activeTexture(this.TEXTURE0);
|
|
141
|
-
this._defaultVertexObjectState = new
|
|
125
|
+
this._defaultVertexObjectState = new WebGLVertexArrayObjectState(this);
|
|
142
126
|
this._vertexObjectState = this._defaultVertexObjectState;
|
|
143
|
-
this._vertexGlobalState = new
|
|
127
|
+
this._vertexGlobalState = new WebGLVertexArrayGlobalState(this);
|
|
144
128
|
this._maxTextureSize = this.getParameter(this.MAX_TEXTURE_SIZE);
|
|
145
129
|
this._maxTextureLevel = bits.log2(bits.nextPow2(this._maxTextureSize));
|
|
146
130
|
this._maxCubeMapSize = this.getParameter(this.MAX_CUBE_MAP_TEXTURE_SIZE);
|
|
@@ -168,7 +152,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
168
152
|
return this.canvas.width || 0;
|
|
169
153
|
}
|
|
170
154
|
_initGLConstants() {
|
|
171
|
-
const giBaseClass = new
|
|
155
|
+
const giBaseClass = new Gwebgl.WebGLRenderingContextBase();
|
|
172
156
|
const hash = giBaseClass.get_webgl_constants();
|
|
173
157
|
for (const [k, v] of Object.entries(hash)) {
|
|
174
158
|
Object.defineProperty(this, k, { value: v });
|
|
@@ -202,7 +186,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
202
186
|
return true;
|
|
203
187
|
}
|
|
204
188
|
_checkLocation(location) {
|
|
205
|
-
if (!(location instanceof
|
|
189
|
+
if (!(location instanceof WebGLUniformLocation)) {
|
|
206
190
|
this.setError(this.INVALID_VALUE);
|
|
207
191
|
return false;
|
|
208
192
|
} else if (location._program._ctx !== this || location._linkCount !== location._program._linkCount) {
|
|
@@ -227,7 +211,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
227
211
|
}
|
|
228
212
|
_checkShaderSource(shader) {
|
|
229
213
|
const source = shader._source;
|
|
230
|
-
const tokens = (
|
|
214
|
+
const tokens = tokenize(source);
|
|
231
215
|
let errorStatus = false;
|
|
232
216
|
const errorLog = [];
|
|
233
217
|
for (let i = 0; i < tokens.length; ++i) {
|
|
@@ -246,7 +230,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
246
230
|
if (!match || match?.length < 2) {
|
|
247
231
|
break;
|
|
248
232
|
}
|
|
249
|
-
const bodyToks = (
|
|
233
|
+
const bodyToks = tokenize(match[1]);
|
|
250
234
|
for (let j = 0; j < bodyToks.length; ++j) {
|
|
251
235
|
const btok = bodyToks[j];
|
|
252
236
|
if (btok.type === "ident" || btok.type === void 0) {
|
|
@@ -365,7 +349,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
365
349
|
return true;
|
|
366
350
|
}
|
|
367
351
|
_computePixelSize(type, internalFormat) {
|
|
368
|
-
const pixelSize =
|
|
352
|
+
const pixelSize = formatSize(this, internalFormat);
|
|
369
353
|
if (pixelSize === 0) {
|
|
370
354
|
this.setError(this.INVALID_ENUM);
|
|
371
355
|
return 0;
|
|
@@ -482,7 +466,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
482
466
|
const unit = this._getActiveTextureUnit();
|
|
483
467
|
if (target === this.TEXTURE_2D) {
|
|
484
468
|
return unit._bind2D;
|
|
485
|
-
} else if (
|
|
469
|
+
} else if (validCubeTarget(this, target)) {
|
|
486
470
|
return unit._bindCube;
|
|
487
471
|
}
|
|
488
472
|
this.setError(this.INVALID_ENUM);
|
|
@@ -508,27 +492,27 @@ class GjsifyWebGLRenderingContext {
|
|
|
508
492
|
if (colorAttachmentCount === 0) {
|
|
509
493
|
return this.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;
|
|
510
494
|
}
|
|
511
|
-
if (depthStencilAttachment instanceof
|
|
495
|
+
if (depthStencilAttachment instanceof WebGLTexture) {
|
|
512
496
|
return this.FRAMEBUFFER_UNSUPPORTED;
|
|
513
|
-
} else if (depthStencilAttachment instanceof
|
|
497
|
+
} else if (depthStencilAttachment instanceof WebGLRenderbuffer) {
|
|
514
498
|
if (depthStencilAttachment._format !== this.DEPTH_STENCIL) {
|
|
515
499
|
return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
|
|
516
500
|
}
|
|
517
501
|
width.push(depthStencilAttachment._width);
|
|
518
502
|
height.push(depthStencilAttachment._height);
|
|
519
503
|
}
|
|
520
|
-
if (depthAttachment instanceof
|
|
504
|
+
if (depthAttachment instanceof WebGLTexture) {
|
|
521
505
|
return this.FRAMEBUFFER_UNSUPPORTED;
|
|
522
|
-
} else if (depthAttachment instanceof
|
|
506
|
+
} else if (depthAttachment instanceof WebGLRenderbuffer) {
|
|
523
507
|
if (depthAttachment._format !== this.DEPTH_COMPONENT16) {
|
|
524
508
|
return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
|
|
525
509
|
}
|
|
526
510
|
width.push(depthAttachment._width);
|
|
527
511
|
height.push(depthAttachment._height);
|
|
528
512
|
}
|
|
529
|
-
if (stencilAttachment instanceof
|
|
513
|
+
if (stencilAttachment instanceof WebGLTexture) {
|
|
530
514
|
return this.FRAMEBUFFER_UNSUPPORTED;
|
|
531
|
-
} else if (stencilAttachment instanceof
|
|
515
|
+
} else if (stencilAttachment instanceof WebGLRenderbuffer) {
|
|
532
516
|
if (stencilAttachment._format !== this.STENCIL_INDEX8) {
|
|
533
517
|
return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
|
|
534
518
|
}
|
|
@@ -538,7 +522,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
538
522
|
let colorAttached = false;
|
|
539
523
|
for (let i = 0; i < colorAttachments.length; ++i) {
|
|
540
524
|
const colorAttachment = attachments[colorAttachments[i]];
|
|
541
|
-
if (colorAttachment instanceof
|
|
525
|
+
if (colorAttachment instanceof WebGLTexture) {
|
|
542
526
|
if (colorAttachment._format !== this.RGBA || !(colorAttachment._type === this.UNSIGNED_BYTE || colorAttachment._type === this.FLOAT)) {
|
|
543
527
|
return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
|
|
544
528
|
}
|
|
@@ -548,7 +532,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
548
532
|
throw new TypeError("level is null!");
|
|
549
533
|
width.push(colorAttachment._levelWidth[level]);
|
|
550
534
|
height.push(colorAttachment._levelHeight[level]);
|
|
551
|
-
} else if (colorAttachment instanceof
|
|
535
|
+
} else if (colorAttachment instanceof WebGLRenderbuffer) {
|
|
552
536
|
const format = colorAttachment._format;
|
|
553
537
|
if (format !== this.RGBA4 && format !== this.RGB565 && format !== this.RGB5_A1) {
|
|
554
538
|
return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
|
|
@@ -620,7 +604,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
620
604
|
0,
|
|
621
605
|
colorFormat,
|
|
622
606
|
this.UNSIGNED_BYTE,
|
|
623
|
-
|
|
607
|
+
Uint8ArrayToVariant(null)
|
|
624
608
|
);
|
|
625
609
|
this._native.texParameteri(this.TEXTURE_2D, this.TEXTURE_MIN_FILTER, this.NEAREST);
|
|
626
610
|
this._native.texParameteri(this.TEXTURE_2D, this.TEXTURE_MAG_FILTER, this.NEAREST);
|
|
@@ -739,7 +723,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
739
723
|
for (let i = 0; i < attachments.length; ++i) {
|
|
740
724
|
const attachmentEnum = attachments[i];
|
|
741
725
|
const attachment = framebuffer._attachments[attachmentEnum];
|
|
742
|
-
if (attachment instanceof
|
|
726
|
+
if (attachment instanceof WebGLTexture) {
|
|
743
727
|
this._native.framebufferTexture2D(
|
|
744
728
|
this.FRAMEBUFFER,
|
|
745
729
|
attachmentEnum,
|
|
@@ -747,7 +731,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
747
731
|
attachment._ | 0,
|
|
748
732
|
framebuffer._attachmentLevel[attachmentEnum] || 0
|
|
749
733
|
);
|
|
750
|
-
} else if (attachment instanceof
|
|
734
|
+
} else if (attachment instanceof WebGLRenderbuffer) {
|
|
751
735
|
this._native.framebufferRenderbuffer(
|
|
752
736
|
this.FRAMEBUFFER,
|
|
753
737
|
attachmentEnum,
|
|
@@ -828,7 +812,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
828
812
|
const uInt8Data = new Uint8Array(this._vertexGlobalState._attribs[0]._data.buffer);
|
|
829
813
|
this._native.bufferData(
|
|
830
814
|
this.ARRAY_BUFFER,
|
|
831
|
-
|
|
815
|
+
Uint8ArrayToVariant(uInt8Data),
|
|
832
816
|
this.STREAM_DRAW
|
|
833
817
|
);
|
|
834
818
|
this._native.enableVertexAttribArray(0);
|
|
@@ -859,7 +843,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
859
843
|
}
|
|
860
844
|
}
|
|
861
845
|
_allocateDrawingBuffer(width, height) {
|
|
862
|
-
this._drawingBuffer = new
|
|
846
|
+
this._drawingBuffer = new WebGLDrawingBufferWrapper(
|
|
863
847
|
this._native.createFramebuffer(),
|
|
864
848
|
this._native.createTexture(),
|
|
865
849
|
this._native.createRenderbuffer()
|
|
@@ -909,8 +893,8 @@ class GjsifyWebGLRenderingContext {
|
|
|
909
893
|
}
|
|
910
894
|
if (data) {
|
|
911
895
|
let u8Data = null;
|
|
912
|
-
if (
|
|
913
|
-
u8Data =
|
|
896
|
+
if (isTypedArray(data) || data instanceof DataView) {
|
|
897
|
+
u8Data = arrayToUint8Array(data);
|
|
914
898
|
} else {
|
|
915
899
|
this.setError(this.INVALID_VALUE);
|
|
916
900
|
return;
|
|
@@ -918,7 +902,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
918
902
|
this._saveError();
|
|
919
903
|
this._native.bufferData(
|
|
920
904
|
target,
|
|
921
|
-
|
|
905
|
+
Uint8ArrayToVariant(u8Data),
|
|
922
906
|
usage
|
|
923
907
|
);
|
|
924
908
|
const error = this.getError();
|
|
@@ -976,8 +960,8 @@ class GjsifyWebGLRenderingContext {
|
|
|
976
960
|
return;
|
|
977
961
|
}
|
|
978
962
|
let u8Data = null;
|
|
979
|
-
if (
|
|
980
|
-
u8Data =
|
|
963
|
+
if (isTypedArray(data) || data instanceof DataView) {
|
|
964
|
+
u8Data = arrayToUint8Array(data);
|
|
981
965
|
} else {
|
|
982
966
|
this.setError(this.INVALID_VALUE);
|
|
983
967
|
return;
|
|
@@ -989,13 +973,13 @@ class GjsifyWebGLRenderingContext {
|
|
|
989
973
|
if (target === this.ELEMENT_ARRAY_BUFFER) {
|
|
990
974
|
active._elements.set(u8Data, offset);
|
|
991
975
|
}
|
|
992
|
-
this._native.bufferSubData(target, offset,
|
|
976
|
+
this._native.bufferSubData(target, offset, Uint8ArrayToVariant(u8Data));
|
|
993
977
|
}
|
|
994
978
|
compressedTexImage2D(target, level, internalFormat, width, height, border, data) {
|
|
995
|
-
return this._native.compressedTexImage2D(target, level, internalFormat, width, height, border,
|
|
979
|
+
return this._native.compressedTexImage2D(target, level, internalFormat, width, height, border, Uint8ArrayToVariant(arrayToUint8Array(data)));
|
|
996
980
|
}
|
|
997
981
|
compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, data) {
|
|
998
|
-
return this._native.compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format,
|
|
982
|
+
return this._native.compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, Uint8ArrayToVariant(arrayToUint8Array(data)));
|
|
999
983
|
}
|
|
1000
984
|
readPixels(x = 0, y = 0, width = 0, height = 0, format = 0, type = 0, pixels) {
|
|
1001
985
|
if (!pixels)
|
|
@@ -1035,7 +1019,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
1035
1019
|
viewWidth = this._activeFramebuffer._width;
|
|
1036
1020
|
viewHeight = this._activeFramebuffer._height;
|
|
1037
1021
|
}
|
|
1038
|
-
const pixelData =
|
|
1022
|
+
const pixelData = arrayToUint8Array(pixels);
|
|
1039
1023
|
if (x >= viewWidth || x + width <= 0 || y >= viewHeight || y + height <= 0) {
|
|
1040
1024
|
for (let i = 0; i < pixelData.length; ++i) {
|
|
1041
1025
|
pixelData[i] = 0;
|
|
@@ -1075,7 +1059,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
1075
1059
|
nHeight,
|
|
1076
1060
|
format,
|
|
1077
1061
|
type,
|
|
1078
|
-
|
|
1062
|
+
Uint8ArrayToVariant(subPixels)
|
|
1079
1063
|
);
|
|
1080
1064
|
const offset = 4 * (nx - x) + (ny - y) * rowStride;
|
|
1081
1065
|
for (let j = 0; j < nHeight; ++j) {
|
|
@@ -1094,7 +1078,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
1094
1078
|
height,
|
|
1095
1079
|
format,
|
|
1096
1080
|
type,
|
|
1097
|
-
|
|
1081
|
+
Uint8ArrayToVariant(pixelData)
|
|
1098
1082
|
);
|
|
1099
1083
|
}
|
|
1100
1084
|
}
|
|
@@ -1109,7 +1093,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
1109
1093
|
if (arguments.length === 6) {
|
|
1110
1094
|
type = typeOrHeight;
|
|
1111
1095
|
format = formatOrWidth;
|
|
1112
|
-
if (sourceOrBorder instanceof
|
|
1096
|
+
if (sourceOrBorder instanceof GdkPixbuf.Pixbuf) {
|
|
1113
1097
|
pixbuf = sourceOrBorder;
|
|
1114
1098
|
width = pixbuf.get_width();
|
|
1115
1099
|
height = pixbuf.get_height();
|
|
@@ -1117,7 +1101,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
1117
1101
|
pixels = pixbuf.get_pixels();
|
|
1118
1102
|
} else {
|
|
1119
1103
|
source = sourceOrBorder;
|
|
1120
|
-
const imageData =
|
|
1104
|
+
const imageData = extractImageData(source);
|
|
1121
1105
|
if (imageData == null) {
|
|
1122
1106
|
throw new TypeError("texImage2D(GLenum, GLint, GLenum, GLint, GLenum, GLenum, ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement)");
|
|
1123
1107
|
}
|
|
@@ -1136,7 +1120,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
1136
1120
|
if (typeof pixels !== "object" && pixels !== void 0) {
|
|
1137
1121
|
throw new TypeError("texImage2D(GLenum, GLint, GLenum, GLint, GLint, GLint, GLenum, GLenum, Uint8Array)");
|
|
1138
1122
|
}
|
|
1139
|
-
if (!
|
|
1123
|
+
if (!checkFormat(this, format) || !checkFormat(this, internalFormat)) {
|
|
1140
1124
|
this.setError(this.INVALID_ENUM);
|
|
1141
1125
|
return;
|
|
1142
1126
|
}
|
|
@@ -1161,19 +1145,19 @@ class GjsifyWebGLRenderingContext {
|
|
|
1161
1145
|
)) {
|
|
1162
1146
|
return;
|
|
1163
1147
|
}
|
|
1164
|
-
const data =
|
|
1148
|
+
const data = convertPixels(pixels);
|
|
1165
1149
|
const rowStride = this._computeRowStride(width, pixelSize);
|
|
1166
1150
|
const imageSize = rowStride * height;
|
|
1167
1151
|
if (data && data.length < imageSize) {
|
|
1168
1152
|
this.setError(this.INVALID_OPERATION);
|
|
1169
1153
|
return;
|
|
1170
1154
|
}
|
|
1171
|
-
if (border !== 0 ||
|
|
1155
|
+
if (border !== 0 || validCubeTarget(this, target) && width !== height) {
|
|
1172
1156
|
this.setError(this.INVALID_VALUE);
|
|
1173
1157
|
return;
|
|
1174
1158
|
}
|
|
1175
1159
|
this._saveError();
|
|
1176
|
-
this._native.texImage2D(target, level, internalFormat, width, height, border, format, type,
|
|
1160
|
+
this._native.texImage2D(target, level, internalFormat, width, height, border, format, type, Uint8ArrayToVariant(data));
|
|
1177
1161
|
const error = this.getError();
|
|
1178
1162
|
this._restoreError(error);
|
|
1179
1163
|
if (error !== this.NO_ERROR) {
|
|
@@ -1207,7 +1191,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
1207
1191
|
if (arguments.length === 7) {
|
|
1208
1192
|
type = typeOrHeight;
|
|
1209
1193
|
format = formatOrWidth;
|
|
1210
|
-
if (sourceOrFormat instanceof
|
|
1194
|
+
if (sourceOrFormat instanceof GdkPixbuf.Pixbuf) {
|
|
1211
1195
|
pixbuf = sourceOrFormat;
|
|
1212
1196
|
width = pixbuf.get_width();
|
|
1213
1197
|
height = pixbuf.get_height();
|
|
@@ -1215,7 +1199,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
1215
1199
|
pixels = pixbuf.get_pixels();
|
|
1216
1200
|
} else {
|
|
1217
1201
|
source = sourceOrFormat;
|
|
1218
|
-
const imageData =
|
|
1202
|
+
const imageData = extractImageData(source);
|
|
1219
1203
|
if (imageData == null) {
|
|
1220
1204
|
throw new TypeError("texSubImage2D(GLenum, GLint, GLint, GLint, GLenum, GLenum, ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement)");
|
|
1221
1205
|
}
|
|
@@ -1256,7 +1240,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
1256
1240
|
this.setError(this.INVALID_VALUE);
|
|
1257
1241
|
return;
|
|
1258
1242
|
}
|
|
1259
|
-
const data =
|
|
1243
|
+
const data = convertPixels(pixels);
|
|
1260
1244
|
const rowStride = this._computeRowStride(width, pixelSize);
|
|
1261
1245
|
const imageSize = rowStride * height;
|
|
1262
1246
|
if (!data || data.length < imageSize) {
|
|
@@ -1272,11 +1256,11 @@ class GjsifyWebGLRenderingContext {
|
|
|
1272
1256
|
height,
|
|
1273
1257
|
format,
|
|
1274
1258
|
type,
|
|
1275
|
-
|
|
1259
|
+
Uint8ArrayToVariant(data)
|
|
1276
1260
|
);
|
|
1277
1261
|
}
|
|
1278
1262
|
_checkUniformValid(location, v0, name, count, type) {
|
|
1279
|
-
if (!
|
|
1263
|
+
if (!checkObject(location)) {
|
|
1280
1264
|
throw new TypeError(`${name}(WebGLUniformLocation, ...)`);
|
|
1281
1265
|
} else if (!location) {
|
|
1282
1266
|
return false;
|
|
@@ -1296,7 +1280,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
1296
1280
|
return false;
|
|
1297
1281
|
}
|
|
1298
1282
|
}
|
|
1299
|
-
if (
|
|
1283
|
+
if (uniformTypeSize(this, utype) > count) {
|
|
1300
1284
|
this.setError(this.INVALID_OPERATION);
|
|
1301
1285
|
return false;
|
|
1302
1286
|
}
|
|
@@ -1305,7 +1289,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
1305
1289
|
return false;
|
|
1306
1290
|
}
|
|
1307
1291
|
_checkUniformValueValid(location, value, name, count, _type) {
|
|
1308
|
-
if (!
|
|
1292
|
+
if (!checkObject(location) || !checkObject(value)) {
|
|
1309
1293
|
throw new TypeError(`${name}v(WebGLUniformLocation, Array)`);
|
|
1310
1294
|
} else if (!location) {
|
|
1311
1295
|
return false;
|
|
@@ -1313,7 +1297,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
1313
1297
|
return false;
|
|
1314
1298
|
} else if (typeof value !== "object" || !value || typeof value.length !== "number") {
|
|
1315
1299
|
throw new TypeError(`Second argument to ${name} must be array`);
|
|
1316
|
-
} else if (
|
|
1300
|
+
} else if (uniformTypeSize(this, location._activeInfo.type) > count) {
|
|
1317
1301
|
this.setError(this.INVALID_OPERATION);
|
|
1318
1302
|
return false;
|
|
1319
1303
|
} else if (value.length >= count && value.length % count === 0) {
|
|
@@ -1450,7 +1434,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
1450
1434
|
this.uniform4i(location, v[0], v[1], v[2], v[3]);
|
|
1451
1435
|
}
|
|
1452
1436
|
_checkUniformMatrix(location, transpose, value, name, count) {
|
|
1453
|
-
if (!
|
|
1437
|
+
if (!checkObject(location) || typeof value !== "object") {
|
|
1454
1438
|
throw new TypeError(name + "(WebGLUniformLocation, Boolean, Array)");
|
|
1455
1439
|
} else if (!!transpose || typeof value !== "object" || value === null || !value.length || value.length % count * count !== 0) {
|
|
1456
1440
|
this.setError(this.INVALID_VALUE);
|
|
@@ -1477,7 +1461,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
1477
1461
|
this._native.uniformMatrix2fv(
|
|
1478
1462
|
location?._ || 0,
|
|
1479
1463
|
!!transpose,
|
|
1480
|
-
|
|
1464
|
+
listToArray(data)
|
|
1481
1465
|
);
|
|
1482
1466
|
}
|
|
1483
1467
|
uniformMatrix3fv(location, transpose, value) {
|
|
@@ -1487,7 +1471,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
1487
1471
|
this._native.uniformMatrix3fv(
|
|
1488
1472
|
location?._ || 0,
|
|
1489
1473
|
!!transpose,
|
|
1490
|
-
|
|
1474
|
+
listToArray(data)
|
|
1491
1475
|
);
|
|
1492
1476
|
}
|
|
1493
1477
|
uniformMatrix4fv(location, transpose, value) {
|
|
@@ -1497,7 +1481,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
1497
1481
|
this._native.uniformMatrix4fv(
|
|
1498
1482
|
location?._ || 0,
|
|
1499
1483
|
!!transpose,
|
|
1500
|
-
|
|
1484
|
+
listToArray(data)
|
|
1501
1485
|
);
|
|
1502
1486
|
}
|
|
1503
1487
|
//////////// BASE ////////////
|
|
@@ -1510,13 +1494,13 @@ class GjsifyWebGLRenderingContext {
|
|
|
1510
1494
|
this.setError(this.INVALID_ENUM);
|
|
1511
1495
|
}
|
|
1512
1496
|
attachShader(program, shader) {
|
|
1513
|
-
if (!
|
|
1497
|
+
if (!checkObject(program) || !checkObject(shader)) {
|
|
1514
1498
|
throw new TypeError("attachShader(WebGLProgram, WebGLShader)");
|
|
1515
1499
|
}
|
|
1516
1500
|
if (!program || !shader) {
|
|
1517
1501
|
this.setError(this.INVALID_VALUE);
|
|
1518
1502
|
return;
|
|
1519
|
-
} else if (program instanceof
|
|
1503
|
+
} else if (program instanceof WebGLProgram && shader instanceof WebGLShader && this._checkOwns(program) && this._checkOwns(shader)) {
|
|
1520
1504
|
if (!program._linked(shader)) {
|
|
1521
1505
|
this._saveError();
|
|
1522
1506
|
this._native.attachShader(
|
|
@@ -1534,15 +1518,15 @@ class GjsifyWebGLRenderingContext {
|
|
|
1534
1518
|
this.setError(this.INVALID_OPERATION);
|
|
1535
1519
|
}
|
|
1536
1520
|
bindAttribLocation(program, index, name) {
|
|
1537
|
-
if (!
|
|
1521
|
+
if (!checkObject(program) || typeof name !== "string") {
|
|
1538
1522
|
throw new TypeError("bindAttribLocation(WebGLProgram, GLint, String)");
|
|
1539
1523
|
}
|
|
1540
1524
|
name += "";
|
|
1541
|
-
if (!
|
|
1525
|
+
if (!isValidString(name) || name.length > MAX_ATTRIBUTE_LENGTH) {
|
|
1542
1526
|
this.setError(this.INVALID_VALUE);
|
|
1543
1527
|
} else if (/^_?webgl_a/.test(name)) {
|
|
1544
1528
|
this.setError(this.INVALID_OPERATION);
|
|
1545
|
-
} else if (this._checkWrapper(program,
|
|
1529
|
+
} else if (this._checkWrapper(program, WebGLProgram)) {
|
|
1546
1530
|
return this._native.bindAttribLocation(
|
|
1547
1531
|
program._ | 0,
|
|
1548
1532
|
index | 0,
|
|
@@ -1551,7 +1535,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
1551
1535
|
}
|
|
1552
1536
|
}
|
|
1553
1537
|
bindBuffer(target = 0, buffer) {
|
|
1554
|
-
if (!
|
|
1538
|
+
if (!checkObject(buffer)) {
|
|
1555
1539
|
throw new TypeError("bindBuffer(GLenum, WebGLBuffer)");
|
|
1556
1540
|
}
|
|
1557
1541
|
if (target !== this.ARRAY_BUFFER && target !== this.ELEMENT_ARRAY_BUFFER) {
|
|
@@ -1563,7 +1547,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
1563
1547
|
this._native.bindBuffer(target, 0);
|
|
1564
1548
|
} else if (buffer._pendingDelete) {
|
|
1565
1549
|
return;
|
|
1566
|
-
} else if (this._checkWrapper(buffer,
|
|
1550
|
+
} else if (this._checkWrapper(buffer, WebGLBuffer)) {
|
|
1567
1551
|
if (buffer._binding && buffer._binding !== target) {
|
|
1568
1552
|
this.setError(this.INVALID_OPERATION);
|
|
1569
1553
|
return;
|
|
@@ -1580,7 +1564,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
1580
1564
|
}
|
|
1581
1565
|
}
|
|
1582
1566
|
bindFramebuffer(target, framebuffer) {
|
|
1583
|
-
if (!
|
|
1567
|
+
if (!checkObject(framebuffer)) {
|
|
1584
1568
|
throw new TypeError("bindFramebuffer(GLenum, WebGLFramebuffer)");
|
|
1585
1569
|
}
|
|
1586
1570
|
if (target !== this.FRAMEBUFFER) {
|
|
@@ -1596,7 +1580,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
1596
1580
|
}
|
|
1597
1581
|
} else if (framebuffer._pendingDelete) {
|
|
1598
1582
|
return;
|
|
1599
|
-
} else if (this._checkWrapper(framebuffer,
|
|
1583
|
+
} else if (this._checkWrapper(framebuffer, WebGLFramebuffer)) {
|
|
1600
1584
|
this._native.bindFramebuffer(
|
|
1601
1585
|
this.FRAMEBUFFER,
|
|
1602
1586
|
framebuffer._ | 0
|
|
@@ -1620,7 +1604,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
1620
1604
|
}
|
|
1621
1605
|
}
|
|
1622
1606
|
bindRenderbuffer(target, renderbuffer) {
|
|
1623
|
-
if (!
|
|
1607
|
+
if (!checkObject(renderbuffer)) {
|
|
1624
1608
|
throw new TypeError("bindRenderbuffer(GLenum, WebGLRenderbuffer)");
|
|
1625
1609
|
}
|
|
1626
1610
|
if (target !== this.RENDERBUFFER) {
|
|
@@ -1634,7 +1618,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
1634
1618
|
);
|
|
1635
1619
|
} else if (renderbuffer._pendingDelete) {
|
|
1636
1620
|
return;
|
|
1637
|
-
} else if (this._checkWrapper(renderbuffer,
|
|
1621
|
+
} else if (this._checkWrapper(renderbuffer, WebGLRenderbuffer)) {
|
|
1638
1622
|
this._native.bindRenderbuffer(
|
|
1639
1623
|
target | 0,
|
|
1640
1624
|
renderbuffer._ | 0
|
|
@@ -1655,7 +1639,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
1655
1639
|
this._activeRenderbuffer = renderbuffer;
|
|
1656
1640
|
}
|
|
1657
1641
|
bindTexture(target = 0, texture) {
|
|
1658
|
-
if (!
|
|
1642
|
+
if (!checkObject(texture)) {
|
|
1659
1643
|
throw new TypeError("bindTexture(GLenum, WebGLTexture)");
|
|
1660
1644
|
}
|
|
1661
1645
|
if (!this._validTextureTarget(target)) {
|
|
@@ -1665,9 +1649,9 @@ class GjsifyWebGLRenderingContext {
|
|
|
1665
1649
|
let textureId = 0;
|
|
1666
1650
|
if (!texture) {
|
|
1667
1651
|
texture = null;
|
|
1668
|
-
} else if (texture instanceof
|
|
1652
|
+
} else if (texture instanceof WebGLTexture && texture._pendingDelete) {
|
|
1669
1653
|
return;
|
|
1670
|
-
} else if (this._checkWrapper(texture,
|
|
1654
|
+
} else if (this._checkWrapper(texture, WebGLTexture)) {
|
|
1671
1655
|
if (texture._binding && texture._binding !== target) {
|
|
1672
1656
|
this.setError(this.INVALID_OPERATION);
|
|
1673
1657
|
return;
|
|
@@ -1779,10 +1763,10 @@ class GjsifyWebGLRenderingContext {
|
|
|
1779
1763
|
return this._native.colorMask(!!red, !!green, !!blue, !!alpha);
|
|
1780
1764
|
}
|
|
1781
1765
|
compileShader(shader) {
|
|
1782
|
-
if (!
|
|
1766
|
+
if (!checkObject(shader)) {
|
|
1783
1767
|
throw new TypeError("compileShader(WebGLShader)");
|
|
1784
1768
|
}
|
|
1785
|
-
if (this._checkWrapper(shader,
|
|
1769
|
+
if (this._checkWrapper(shader, WebGLShader) && this._checkShaderSource(shader)) {
|
|
1786
1770
|
const prevError = this.getError();
|
|
1787
1771
|
this._native.compileShader(shader._ | 0);
|
|
1788
1772
|
const error = this.getError();
|
|
@@ -1858,7 +1842,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
1858
1842
|
const id = this._native.createBuffer();
|
|
1859
1843
|
if (!id || id <= 0)
|
|
1860
1844
|
return null;
|
|
1861
|
-
const webGLBuffer = new
|
|
1845
|
+
const webGLBuffer = new WebGLBuffer(id, this);
|
|
1862
1846
|
this._buffers[id] = webGLBuffer;
|
|
1863
1847
|
return webGLBuffer;
|
|
1864
1848
|
}
|
|
@@ -1866,7 +1850,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
1866
1850
|
const id = this._native.createFramebuffer();
|
|
1867
1851
|
if (id <= 0)
|
|
1868
1852
|
return null;
|
|
1869
|
-
const webGLFramebuffer = new
|
|
1853
|
+
const webGLFramebuffer = new WebGLFramebuffer(id, this);
|
|
1870
1854
|
this._framebuffers[id] = webGLFramebuffer;
|
|
1871
1855
|
return webGLFramebuffer;
|
|
1872
1856
|
}
|
|
@@ -1874,7 +1858,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
1874
1858
|
const id = this._native.createProgram();
|
|
1875
1859
|
if (id <= 0)
|
|
1876
1860
|
return null;
|
|
1877
|
-
const webGLProgram = new
|
|
1861
|
+
const webGLProgram = new WebGLProgram(id, this);
|
|
1878
1862
|
this._programs[id] = webGLProgram;
|
|
1879
1863
|
return webGLProgram;
|
|
1880
1864
|
}
|
|
@@ -1882,7 +1866,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
1882
1866
|
const id = this._native.createRenderbuffer();
|
|
1883
1867
|
if (id <= 0)
|
|
1884
1868
|
return null;
|
|
1885
|
-
const webGLRenderbuffer = new
|
|
1869
|
+
const webGLRenderbuffer = new WebGLRenderbuffer(id, this);
|
|
1886
1870
|
this._renderbuffers[id] = webGLRenderbuffer;
|
|
1887
1871
|
return webGLRenderbuffer;
|
|
1888
1872
|
}
|
|
@@ -1895,7 +1879,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
1895
1879
|
if (id < 0) {
|
|
1896
1880
|
return null;
|
|
1897
1881
|
}
|
|
1898
|
-
const result = new
|
|
1882
|
+
const result = new WebGLShader(id, this, type);
|
|
1899
1883
|
this._shaders[id] = result;
|
|
1900
1884
|
return result;
|
|
1901
1885
|
}
|
|
@@ -1903,7 +1887,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
1903
1887
|
const id = this._native.createTexture();
|
|
1904
1888
|
if (id <= 0)
|
|
1905
1889
|
return null;
|
|
1906
|
-
const webGlTexture = new
|
|
1890
|
+
const webGlTexture = new WebGLTexture(id, this);
|
|
1907
1891
|
this._textures[id] = webGlTexture;
|
|
1908
1892
|
return webGlTexture;
|
|
1909
1893
|
}
|
|
@@ -1911,10 +1895,10 @@ class GjsifyWebGLRenderingContext {
|
|
|
1911
1895
|
return this._native.cullFace(mode | 0);
|
|
1912
1896
|
}
|
|
1913
1897
|
deleteBuffer(buffer) {
|
|
1914
|
-
if (!
|
|
1898
|
+
if (!checkObject(buffer) || buffer !== null && !(buffer instanceof WebGLBuffer)) {
|
|
1915
1899
|
throw new TypeError("deleteBuffer(WebGLBuffer)");
|
|
1916
1900
|
}
|
|
1917
|
-
if (!(buffer instanceof
|
|
1901
|
+
if (!(buffer instanceof WebGLBuffer && this._checkOwns(buffer))) {
|
|
1918
1902
|
this.setError(this.INVALID_OPERATION);
|
|
1919
1903
|
return;
|
|
1920
1904
|
}
|
|
@@ -1931,10 +1915,10 @@ class GjsifyWebGLRenderingContext {
|
|
|
1931
1915
|
buffer._checkDelete();
|
|
1932
1916
|
}
|
|
1933
1917
|
deleteFramebuffer(framebuffer) {
|
|
1934
|
-
if (!
|
|
1918
|
+
if (!checkObject(framebuffer)) {
|
|
1935
1919
|
throw new TypeError("deleteFramebuffer(WebGLFramebuffer)");
|
|
1936
1920
|
}
|
|
1937
|
-
if (!(framebuffer instanceof
|
|
1921
|
+
if (!(framebuffer instanceof WebGLFramebuffer && this._checkOwns(framebuffer))) {
|
|
1938
1922
|
this.setError(this.INVALID_OPERATION);
|
|
1939
1923
|
return;
|
|
1940
1924
|
}
|
|
@@ -1945,7 +1929,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
1945
1929
|
framebuffer._checkDelete();
|
|
1946
1930
|
}
|
|
1947
1931
|
_deleteLinkable(name, object, Type) {
|
|
1948
|
-
if (!
|
|
1932
|
+
if (!checkObject(object)) {
|
|
1949
1933
|
throw new TypeError(name + "(" + Type.name + ")");
|
|
1950
1934
|
}
|
|
1951
1935
|
if (object instanceof Type && this._checkOwns(object)) {
|
|
@@ -1956,7 +1940,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
1956
1940
|
this.setError(this.INVALID_OPERATION);
|
|
1957
1941
|
}
|
|
1958
1942
|
deleteProgram(program) {
|
|
1959
|
-
return this._deleteLinkable("deleteProgram", program,
|
|
1943
|
+
return this._deleteLinkable("deleteProgram", program, WebGLProgram);
|
|
1960
1944
|
}
|
|
1961
1945
|
// Need to handle textures and render buffers as a special case:
|
|
1962
1946
|
// When a texture gets deleted, we need to do the following extra steps:
|
|
@@ -1970,10 +1954,10 @@ class GjsifyWebGLRenderingContext {
|
|
|
1970
1954
|
// After this, proceed with the usual deletion algorithm
|
|
1971
1955
|
//
|
|
1972
1956
|
deleteRenderbuffer(renderbuffer) {
|
|
1973
|
-
if (!
|
|
1957
|
+
if (!checkObject(renderbuffer)) {
|
|
1974
1958
|
throw new TypeError("deleteRenderbuffer(WebGLRenderbuffer)");
|
|
1975
1959
|
}
|
|
1976
|
-
if (!(renderbuffer instanceof
|
|
1960
|
+
if (!(renderbuffer instanceof WebGLRenderbuffer && this._checkOwns(renderbuffer))) {
|
|
1977
1961
|
this.setError(this.INVALID_OPERATION);
|
|
1978
1962
|
return;
|
|
1979
1963
|
}
|
|
@@ -1986,13 +1970,13 @@ class GjsifyWebGLRenderingContext {
|
|
|
1986
1970
|
renderbuffer._checkDelete();
|
|
1987
1971
|
}
|
|
1988
1972
|
deleteShader(shader) {
|
|
1989
|
-
return this._deleteLinkable("deleteShader", shader,
|
|
1973
|
+
return this._deleteLinkable("deleteShader", shader, WebGLShader);
|
|
1990
1974
|
}
|
|
1991
1975
|
deleteTexture(texture) {
|
|
1992
|
-
if (!
|
|
1976
|
+
if (!checkObject(texture)) {
|
|
1993
1977
|
throw new TypeError("deleteTexture(WebGLTexture)");
|
|
1994
1978
|
}
|
|
1995
|
-
if (texture instanceof
|
|
1979
|
+
if (texture instanceof WebGLTexture) {
|
|
1996
1980
|
if (!this._checkOwns(texture)) {
|
|
1997
1981
|
this.setError(this.INVALID_OPERATION);
|
|
1998
1982
|
return;
|
|
@@ -2062,13 +2046,13 @@ class GjsifyWebGLRenderingContext {
|
|
|
2062
2046
|
this.setError(this.INVALID_OPERATION);
|
|
2063
2047
|
}
|
|
2064
2048
|
destroy() {
|
|
2065
|
-
|
|
2049
|
+
warnNotImplemented("destroy");
|
|
2066
2050
|
}
|
|
2067
2051
|
detachShader(program, shader) {
|
|
2068
|
-
if (!
|
|
2052
|
+
if (!checkObject(program) || !checkObject(shader)) {
|
|
2069
2053
|
throw new TypeError("detachShader(WebGLProgram, WebGLShader)");
|
|
2070
2054
|
}
|
|
2071
|
-
if (this._checkWrapper(program,
|
|
2055
|
+
if (this._checkWrapper(program, WebGLProgram) && this._checkWrapper(shader, WebGLShader)) {
|
|
2072
2056
|
if (program._linked(shader)) {
|
|
2073
2057
|
this._native.detachShader(program._, shader._);
|
|
2074
2058
|
program._unlink(shader);
|
|
@@ -2102,7 +2086,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
2102
2086
|
if (!this._checkStencilState()) {
|
|
2103
2087
|
return;
|
|
2104
2088
|
}
|
|
2105
|
-
const reducedCount =
|
|
2089
|
+
const reducedCount = vertexCount(this, mode, count);
|
|
2106
2090
|
if (reducedCount < 0) {
|
|
2107
2091
|
this.setError(this.INVALID_ENUM);
|
|
2108
2092
|
return;
|
|
@@ -2243,7 +2227,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
2243
2227
|
return this._native.flush();
|
|
2244
2228
|
}
|
|
2245
2229
|
framebufferRenderbuffer(target, attachment, renderbufferTarget, renderbuffer) {
|
|
2246
|
-
if (!
|
|
2230
|
+
if (!checkObject(renderbuffer)) {
|
|
2247
2231
|
throw new TypeError("framebufferRenderbuffer(GLenum, GLenum, GLenum, WebGLRenderbuffer)");
|
|
2248
2232
|
}
|
|
2249
2233
|
if (target !== this.FRAMEBUFFER || !this._validFramebufferAttachment(attachment) || renderbufferTarget !== this.RENDERBUFFER) {
|
|
@@ -2255,7 +2239,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
2255
2239
|
this.setError(this.INVALID_OPERATION);
|
|
2256
2240
|
return;
|
|
2257
2241
|
}
|
|
2258
|
-
if (renderbuffer && !this._checkWrapper(renderbuffer,
|
|
2242
|
+
if (renderbuffer && !this._checkWrapper(renderbuffer, WebGLRenderbuffer)) {
|
|
2259
2243
|
return;
|
|
2260
2244
|
}
|
|
2261
2245
|
framebuffer._setAttachment(renderbuffer, attachment);
|
|
@@ -2266,7 +2250,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
2266
2250
|
attachment |= 0;
|
|
2267
2251
|
textarget |= 0;
|
|
2268
2252
|
level |= 0;
|
|
2269
|
-
if (!
|
|
2253
|
+
if (!checkObject(texture)) {
|
|
2270
2254
|
throw new TypeError("framebufferTexture2D(GLenum, GLenum, GLenum, WebGLTexture, GLint)");
|
|
2271
2255
|
}
|
|
2272
2256
|
if (target !== this.FRAMEBUFFER || !this._validFramebufferAttachment(attachment)) {
|
|
@@ -2277,7 +2261,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
2277
2261
|
this.setError(this.INVALID_VALUE);
|
|
2278
2262
|
return;
|
|
2279
2263
|
}
|
|
2280
|
-
if (texture && !this._checkWrapper(texture,
|
|
2264
|
+
if (texture && !this._checkWrapper(texture, WebGLTexture)) {
|
|
2281
2265
|
return;
|
|
2282
2266
|
}
|
|
2283
2267
|
if (textarget === this.TEXTURE_2D) {
|
|
@@ -2311,38 +2295,38 @@ class GjsifyWebGLRenderingContext {
|
|
|
2311
2295
|
return this._native.generateMipmap(target);
|
|
2312
2296
|
}
|
|
2313
2297
|
getActiveAttrib(program, index) {
|
|
2314
|
-
if (!
|
|
2298
|
+
if (!checkObject(program)) {
|
|
2315
2299
|
throw new TypeError("getActiveAttrib(WebGLProgram)");
|
|
2316
2300
|
} else if (!program) {
|
|
2317
2301
|
this.setError(this.INVALID_VALUE);
|
|
2318
|
-
} else if (this._checkWrapper(program,
|
|
2302
|
+
} else if (this._checkWrapper(program, WebGLProgram)) {
|
|
2319
2303
|
const info = this._native.getActiveAttrib(program._ | 0, index | 0);
|
|
2320
2304
|
if (info) {
|
|
2321
|
-
return new
|
|
2305
|
+
return new WebGLActiveInfo(info);
|
|
2322
2306
|
}
|
|
2323
2307
|
}
|
|
2324
2308
|
return null;
|
|
2325
2309
|
}
|
|
2326
2310
|
getActiveUniform(program, index) {
|
|
2327
|
-
if (!
|
|
2311
|
+
if (!checkObject(program)) {
|
|
2328
2312
|
throw new TypeError("getActiveUniform(WebGLProgram, GLint)");
|
|
2329
2313
|
} else if (!program) {
|
|
2330
2314
|
this.setError(this.INVALID_VALUE);
|
|
2331
|
-
} else if (this._checkWrapper(program,
|
|
2315
|
+
} else if (this._checkWrapper(program, WebGLProgram)) {
|
|
2332
2316
|
const info = this._native.getActiveUniform(program._ | 0, index | 0);
|
|
2333
2317
|
if (info) {
|
|
2334
|
-
return new
|
|
2318
|
+
return new WebGLActiveInfo(info);
|
|
2335
2319
|
}
|
|
2336
2320
|
}
|
|
2337
2321
|
return null;
|
|
2338
2322
|
}
|
|
2339
2323
|
getAttachedShaders(program) {
|
|
2340
|
-
if (!
|
|
2324
|
+
if (!checkObject(program) || typeof program === "object" && program !== null && !(program instanceof WebGLProgram)) {
|
|
2341
2325
|
throw new TypeError("getAttachedShaders(WebGLProgram)");
|
|
2342
2326
|
}
|
|
2343
2327
|
if (!program) {
|
|
2344
2328
|
this.setError(this.INVALID_VALUE);
|
|
2345
|
-
} else if (this._checkWrapper(program,
|
|
2329
|
+
} else if (this._checkWrapper(program, WebGLProgram)) {
|
|
2346
2330
|
const shaderArray = this._native.getAttachedShaders(program._ | 0);
|
|
2347
2331
|
if (!shaderArray) {
|
|
2348
2332
|
return null;
|
|
@@ -2356,13 +2340,13 @@ class GjsifyWebGLRenderingContext {
|
|
|
2356
2340
|
return null;
|
|
2357
2341
|
}
|
|
2358
2342
|
getAttribLocation(program, name) {
|
|
2359
|
-
if (!
|
|
2343
|
+
if (!checkObject(program)) {
|
|
2360
2344
|
throw new TypeError("getAttribLocation(WebGLProgram, String)");
|
|
2361
2345
|
}
|
|
2362
2346
|
name += "";
|
|
2363
|
-
if (!
|
|
2347
|
+
if (!isValidString(name) || name.length > MAX_ATTRIBUTE_LENGTH) {
|
|
2364
2348
|
this.setError(this.INVALID_VALUE);
|
|
2365
|
-
} else if (this._checkWrapper(program,
|
|
2349
|
+
} else if (this._checkWrapper(program, WebGLProgram)) {
|
|
2366
2350
|
return this._native.getAttribLocation(program._ | 0, name + "");
|
|
2367
2351
|
}
|
|
2368
2352
|
return -1;
|
|
@@ -2405,7 +2389,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
2405
2389
|
if (pname === this.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE) {
|
|
2406
2390
|
return this.NONE;
|
|
2407
2391
|
}
|
|
2408
|
-
} else if (object instanceof
|
|
2392
|
+
} else if (object instanceof WebGLTexture) {
|
|
2409
2393
|
switch (pname) {
|
|
2410
2394
|
case this.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
|
|
2411
2395
|
return object;
|
|
@@ -2421,7 +2405,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
2421
2405
|
return face;
|
|
2422
2406
|
}
|
|
2423
2407
|
}
|
|
2424
|
-
} else if (object instanceof
|
|
2408
|
+
} else if (object instanceof WebGLRenderbuffer) {
|
|
2425
2409
|
switch (pname) {
|
|
2426
2410
|
case this.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:
|
|
2427
2411
|
return object;
|
|
@@ -2583,17 +2567,17 @@ class GjsifyWebGLRenderingContext {
|
|
|
2583
2567
|
}
|
|
2584
2568
|
}
|
|
2585
2569
|
getProgramInfoLog(program) {
|
|
2586
|
-
if (!
|
|
2570
|
+
if (!checkObject(program)) {
|
|
2587
2571
|
throw new TypeError("getProgramInfoLog(WebGLProgram)");
|
|
2588
|
-
} else if (this._checkWrapper(program,
|
|
2572
|
+
} else if (this._checkWrapper(program, WebGLProgram)) {
|
|
2589
2573
|
return program._linkInfoLog;
|
|
2590
2574
|
}
|
|
2591
2575
|
return null;
|
|
2592
2576
|
}
|
|
2593
2577
|
getProgramParameter(program, pname = 0) {
|
|
2594
|
-
if (!
|
|
2578
|
+
if (!checkObject(program)) {
|
|
2595
2579
|
throw new TypeError("getProgramParameter(WebGLProgram, GLenum)");
|
|
2596
|
-
} else if (this._checkWrapper(program,
|
|
2580
|
+
} else if (this._checkWrapper(program, WebGLProgram)) {
|
|
2597
2581
|
switch (pname) {
|
|
2598
2582
|
case this.DELETE_STATUS:
|
|
2599
2583
|
return program._pendingDelete;
|
|
@@ -2640,17 +2624,17 @@ class GjsifyWebGLRenderingContext {
|
|
|
2640
2624
|
return null;
|
|
2641
2625
|
}
|
|
2642
2626
|
getShaderInfoLog(shader) {
|
|
2643
|
-
if (!
|
|
2627
|
+
if (!checkObject(shader)) {
|
|
2644
2628
|
throw new TypeError("getShaderInfoLog(WebGLShader)");
|
|
2645
|
-
} else if (this._checkWrapper(shader,
|
|
2629
|
+
} else if (this._checkWrapper(shader, WebGLShader)) {
|
|
2646
2630
|
return shader._compileInfo;
|
|
2647
2631
|
}
|
|
2648
2632
|
return null;
|
|
2649
2633
|
}
|
|
2650
2634
|
getShaderParameter(shader, pname = 0) {
|
|
2651
|
-
if (!
|
|
2635
|
+
if (!checkObject(shader)) {
|
|
2652
2636
|
throw new TypeError("getShaderParameter(WebGLShader, GLenum)");
|
|
2653
|
-
} else if (this._checkWrapper(shader,
|
|
2637
|
+
} else if (this._checkWrapper(shader, WebGLShader)) {
|
|
2654
2638
|
switch (pname) {
|
|
2655
2639
|
case this.DELETE_STATUS:
|
|
2656
2640
|
return shader._pendingDelete;
|
|
@@ -2672,12 +2656,12 @@ class GjsifyWebGLRenderingContext {
|
|
|
2672
2656
|
if (!format) {
|
|
2673
2657
|
return null;
|
|
2674
2658
|
}
|
|
2675
|
-
return new
|
|
2659
|
+
return new WebGLShaderPrecisionFormat(format);
|
|
2676
2660
|
}
|
|
2677
2661
|
getShaderSource(shader) {
|
|
2678
|
-
if (!
|
|
2662
|
+
if (!checkObject(shader)) {
|
|
2679
2663
|
throw new TypeError("Input to getShaderSource must be an object");
|
|
2680
|
-
} else if (this._checkWrapper(shader,
|
|
2664
|
+
} else if (this._checkWrapper(shader, WebGLShader)) {
|
|
2681
2665
|
return shader._source;
|
|
2682
2666
|
}
|
|
2683
2667
|
return null;
|
|
@@ -2744,15 +2728,15 @@ class GjsifyWebGLRenderingContext {
|
|
|
2744
2728
|
return null;
|
|
2745
2729
|
}
|
|
2746
2730
|
getUniform(program, location) {
|
|
2747
|
-
if (!
|
|
2731
|
+
if (!checkObject(program) || !checkObject(location)) {
|
|
2748
2732
|
throw new TypeError("getUniform(WebGLProgram, WebGLUniformLocation)");
|
|
2749
2733
|
} else if (!program) {
|
|
2750
2734
|
this.setError(this.INVALID_VALUE);
|
|
2751
2735
|
return null;
|
|
2752
2736
|
} else if (!location) {
|
|
2753
2737
|
return null;
|
|
2754
|
-
} else if (this._checkWrapper(program,
|
|
2755
|
-
if (!
|
|
2738
|
+
} else if (this._checkWrapper(program, WebGLProgram)) {
|
|
2739
|
+
if (!checkUniform(program, location)) {
|
|
2756
2740
|
this.setError(this.INVALID_OPERATION);
|
|
2757
2741
|
return null;
|
|
2758
2742
|
}
|
|
@@ -2801,15 +2785,15 @@ class GjsifyWebGLRenderingContext {
|
|
|
2801
2785
|
return null;
|
|
2802
2786
|
}
|
|
2803
2787
|
getUniformLocation(program, name) {
|
|
2804
|
-
if (!
|
|
2788
|
+
if (!checkObject(program)) {
|
|
2805
2789
|
throw new TypeError("getUniformLocation(WebGLProgram, String)");
|
|
2806
2790
|
}
|
|
2807
2791
|
name += "";
|
|
2808
|
-
if (!
|
|
2792
|
+
if (!isValidString(name)) {
|
|
2809
2793
|
this.setError(this.INVALID_VALUE);
|
|
2810
2794
|
return null;
|
|
2811
2795
|
}
|
|
2812
|
-
if (this._checkWrapper(program,
|
|
2796
|
+
if (this._checkWrapper(program, WebGLProgram)) {
|
|
2813
2797
|
const loc = this._native.getUniformLocation(program._ | 0, name);
|
|
2814
2798
|
if (loc !== null && loc >= 0) {
|
|
2815
2799
|
let searchName = name;
|
|
@@ -2830,7 +2814,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
2830
2814
|
if (!info) {
|
|
2831
2815
|
return null;
|
|
2832
2816
|
}
|
|
2833
|
-
const result = new
|
|
2817
|
+
const result = new WebGLUniformLocation(
|
|
2834
2818
|
loc,
|
|
2835
2819
|
program,
|
|
2836
2820
|
info
|
|
@@ -2923,7 +2907,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
2923
2907
|
return this._native.hint(target, mode);
|
|
2924
2908
|
}
|
|
2925
2909
|
isBuffer(buffer) {
|
|
2926
|
-
if (!this._isObject(buffer, "isBuffer",
|
|
2910
|
+
if (!this._isObject(buffer, "isBuffer", WebGLBuffer))
|
|
2927
2911
|
return false;
|
|
2928
2912
|
return this._native.isBuffer(buffer?._);
|
|
2929
2913
|
}
|
|
@@ -2934,27 +2918,27 @@ class GjsifyWebGLRenderingContext {
|
|
|
2934
2918
|
return this._native.isEnabled(cap);
|
|
2935
2919
|
}
|
|
2936
2920
|
isFramebuffer(framebuffer) {
|
|
2937
|
-
if (!this._isObject(framebuffer, "isFramebuffer",
|
|
2921
|
+
if (!this._isObject(framebuffer, "isFramebuffer", WebGLFramebuffer))
|
|
2938
2922
|
return false;
|
|
2939
2923
|
return this._native.isFramebuffer(framebuffer?._);
|
|
2940
2924
|
}
|
|
2941
2925
|
isProgram(program) {
|
|
2942
|
-
if (!this._isObject(program, "isProgram",
|
|
2926
|
+
if (!this._isObject(program, "isProgram", WebGLProgram))
|
|
2943
2927
|
return false;
|
|
2944
2928
|
return this._native.isProgram(program?._);
|
|
2945
2929
|
}
|
|
2946
2930
|
isRenderbuffer(renderbuffer) {
|
|
2947
|
-
if (!this._isObject(renderbuffer, "isRenderbuffer",
|
|
2931
|
+
if (!this._isObject(renderbuffer, "isRenderbuffer", WebGLRenderbuffer))
|
|
2948
2932
|
return false;
|
|
2949
2933
|
return this._native.isRenderbuffer(renderbuffer?._);
|
|
2950
2934
|
}
|
|
2951
2935
|
isShader(shader) {
|
|
2952
|
-
if (!this._isObject(shader, "isShader",
|
|
2936
|
+
if (!this._isObject(shader, "isShader", WebGLShader))
|
|
2953
2937
|
return false;
|
|
2954
2938
|
return this._native.isShader(shader?._);
|
|
2955
2939
|
}
|
|
2956
2940
|
isTexture(texture) {
|
|
2957
|
-
if (!this._isObject(texture, "isTexture",
|
|
2941
|
+
if (!this._isObject(texture, "isTexture", WebGLTexture))
|
|
2958
2942
|
return false;
|
|
2959
2943
|
return this._native.isTexture(texture?._);
|
|
2960
2944
|
}
|
|
@@ -2966,10 +2950,10 @@ class GjsifyWebGLRenderingContext {
|
|
|
2966
2950
|
return this._native.lineWidth(+width);
|
|
2967
2951
|
}
|
|
2968
2952
|
linkProgram(program) {
|
|
2969
|
-
if (!
|
|
2953
|
+
if (!checkObject(program)) {
|
|
2970
2954
|
throw new TypeError("linkProgram(WebGLProgram)");
|
|
2971
2955
|
}
|
|
2972
|
-
if (this._checkWrapper(program,
|
|
2956
|
+
if (this._checkWrapper(program, WebGLProgram)) {
|
|
2973
2957
|
program._linkCount += 1;
|
|
2974
2958
|
program._attributes = [];
|
|
2975
2959
|
const prevError = this.getError();
|
|
@@ -3072,16 +3056,16 @@ class GjsifyWebGLRenderingContext {
|
|
|
3072
3056
|
return this._native.scissor(x | 0, y | 0, width | 0, height | 0);
|
|
3073
3057
|
}
|
|
3074
3058
|
shaderSource(shader, source) {
|
|
3075
|
-
if (!
|
|
3059
|
+
if (!checkObject(shader)) {
|
|
3076
3060
|
throw new TypeError("shaderSource(WebGLShader, String)");
|
|
3077
3061
|
}
|
|
3078
3062
|
if (!shader || !source && typeof source !== "string") {
|
|
3079
3063
|
this.setError(this.INVALID_VALUE);
|
|
3080
3064
|
return;
|
|
3081
3065
|
}
|
|
3082
|
-
if (!
|
|
3066
|
+
if (!isValidString(source)) {
|
|
3083
3067
|
this.setError(this.INVALID_VALUE);
|
|
3084
|
-
} else if (this._checkWrapper(shader,
|
|
3068
|
+
} else if (this._checkWrapper(shader, WebGLShader)) {
|
|
3085
3069
|
source = this._wrapShader(shader._type, source);
|
|
3086
3070
|
this._native.shaderSource(shader._ | 0, source);
|
|
3087
3071
|
shader._source = source;
|
|
@@ -3185,13 +3169,13 @@ class GjsifyWebGLRenderingContext {
|
|
|
3185
3169
|
return this._native.uniform4i(location?._ || 0, x, y, z, w);
|
|
3186
3170
|
}
|
|
3187
3171
|
useProgram(program) {
|
|
3188
|
-
if (!
|
|
3172
|
+
if (!checkObject(program)) {
|
|
3189
3173
|
throw new TypeError("useProgram(WebGLProgram)");
|
|
3190
3174
|
} else if (!program) {
|
|
3191
3175
|
this._switchActiveProgram(this._activeProgram);
|
|
3192
3176
|
this._activeProgram = null;
|
|
3193
3177
|
return this._native.useProgram(0);
|
|
3194
|
-
} else if (this._checkWrapper(program,
|
|
3178
|
+
} else if (this._checkWrapper(program, WebGLProgram)) {
|
|
3195
3179
|
if (this._activeProgram !== program) {
|
|
3196
3180
|
this._switchActiveProgram(this._activeProgram);
|
|
3197
3181
|
this._activeProgram = program;
|
|
@@ -3201,7 +3185,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
3201
3185
|
}
|
|
3202
3186
|
}
|
|
3203
3187
|
validateProgram(program) {
|
|
3204
|
-
if (this._checkWrapper(program,
|
|
3188
|
+
if (this._checkWrapper(program, WebGLProgram)) {
|
|
3205
3189
|
this._native.validateProgram(program._ | 0);
|
|
3206
3190
|
const error = this.getError();
|
|
3207
3191
|
if (error === this.NO_ERROR) {
|
|
@@ -3314,7 +3298,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
3314
3298
|
this.setError(this.INVALID_OPERATION);
|
|
3315
3299
|
return;
|
|
3316
3300
|
}
|
|
3317
|
-
const byteSize =
|
|
3301
|
+
const byteSize = typeSize(this, type);
|
|
3318
3302
|
if (byteSize === 0 || type === this.INT || type === this.UNSIGNED_INT) {
|
|
3319
3303
|
this.setError(this.INVALID_ENUM);
|
|
3320
3304
|
return;
|
|
@@ -3353,3 +3337,7 @@ class GjsifyWebGLRenderingContext {
|
|
|
3353
3337
|
return this._native.viewport(x, y, width, height);
|
|
3354
3338
|
}
|
|
3355
3339
|
}
|
|
3340
|
+
export {
|
|
3341
|
+
GjsifyWebGLRenderingContext,
|
|
3342
|
+
GjsifyWebGLRenderingContext as WebGLRenderingContext
|
|
3343
|
+
};
|