@galacean/engine-rhi-webgl 0.9.0-beta.80

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/dist/main.js ADDED
@@ -0,0 +1,1927 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var engineMath = require('@galacean/engine-math');
6
+ var engineCore = require('@galacean/engine-core');
7
+
8
+ /**
9
+ * Smoothing plug-in.
10
+ * */ exports.GLCompressedTextureInternalFormat = void 0;
11
+ (function(GLCompressedTextureInternalFormat) {
12
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat[// astc
13
+ "RGBA_ASTC_4X4_KHR"] = 0x93b0] = "RGBA_ASTC_4X4_KHR";
14
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["RGBA_ASTC_5X4_KHR"] = 0x93b1] = "RGBA_ASTC_5X4_KHR";
15
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["RGBA_ASTC_5X5_KHR"] = 0x93b2] = "RGBA_ASTC_5X5_KHR";
16
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["RGBA_ASTC_6X5_KHR"] = 0x93b3] = "RGBA_ASTC_6X5_KHR";
17
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["RGBA_ASTC_6X6_KHR"] = 0x93b4] = "RGBA_ASTC_6X6_KHR";
18
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["RGBA_ASTC_8X5_KHR"] = 0x93b5] = "RGBA_ASTC_8X5_KHR";
19
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["RGBA_ASTC_8X6_KHR"] = 0x93b6] = "RGBA_ASTC_8X6_KHR";
20
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["RGBA_ASTC_8X8_KHR"] = 0x93b7] = "RGBA_ASTC_8X8_KHR";
21
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["RGBA_ASTC_10X5_KHR"] = 0x93b8] = "RGBA_ASTC_10X5_KHR";
22
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["RGBA_ASTC_10X6_KHR"] = 0x93b9] = "RGBA_ASTC_10X6_KHR";
23
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["RGBA_ASTC_10X8_KHR"] = 0x93ba] = "RGBA_ASTC_10X8_KHR";
24
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["RGBA_ASTC_10X10_KHR"] = 0x93bb] = "RGBA_ASTC_10X10_KHR";
25
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["RGBA_ASTC_12X10_KHR"] = 0x93bc] = "RGBA_ASTC_12X10_KHR";
26
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["RGBA_ASTC_12X12_KHR"] = 0x93bd] = "RGBA_ASTC_12X12_KHR";
27
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["SRGB8_ALPHA8_ASTC_4X4_KHR"] = 0x93d0] = "SRGB8_ALPHA8_ASTC_4X4_KHR";
28
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["SRGB8_ALPHA8_ASTC_5X4_KHR"] = 0x93d1] = "SRGB8_ALPHA8_ASTC_5X4_KHR";
29
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["SRGB8_ALPHA8_ASTC_5X5_KHR"] = 0x93d2] = "SRGB8_ALPHA8_ASTC_5X5_KHR";
30
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["SRGB8_ALPHA8_ASTC_6X5_KHR"] = 0x93d3] = "SRGB8_ALPHA8_ASTC_6X5_KHR";
31
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["SRGB8_ALPHA8_ASTC_6X6_KHR"] = 0x93d4] = "SRGB8_ALPHA8_ASTC_6X6_KHR";
32
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["SRGB8_ALPHA8_ASTC_8X5_KHR"] = 0x93d5] = "SRGB8_ALPHA8_ASTC_8X5_KHR";
33
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["SRGB8_ALPHA8_ASTC_8X6_KHR"] = 0x93d6] = "SRGB8_ALPHA8_ASTC_8X6_KHR";
34
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["SRGB8_ALPHA8_ASTC_8X8_KHR"] = 0x93d7] = "SRGB8_ALPHA8_ASTC_8X8_KHR";
35
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["SRGB8_ALPHA8_ASTC_10X5_KHR"] = 0x93d8] = "SRGB8_ALPHA8_ASTC_10X5_KHR";
36
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["SRGB8_ALPHA8_ASTC_10X6_KHR"] = 0x93d9] = "SRGB8_ALPHA8_ASTC_10X6_KHR";
37
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["SRGB8_ALPHA8_ASTC_10X8_KHR"] = 0x93da] = "SRGB8_ALPHA8_ASTC_10X8_KHR";
38
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["SRGB8_ALPHA8_ASTC_10X10_KHR"] = 0x93db] = "SRGB8_ALPHA8_ASTC_10X10_KHR";
39
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["SRGB8_ALPHA8_ASTC_12X10_KHR"] = 0x93dc] = "SRGB8_ALPHA8_ASTC_12X10_KHR";
40
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["SRGB8_ALPHA8_ASTC_12X12_KHR"] = 0x93dd] = "SRGB8_ALPHA8_ASTC_12X12_KHR";
41
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat[// etc1
42
+ "RGB_ETC1_WEBGL"] = 0x8d64] = "RGB_ETC1_WEBGL";
43
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat[// etc2
44
+ "R11_EAC"] = 0x9270] = "R11_EAC";
45
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["SIGNED_R11_EAC"] = 0x9271] = "SIGNED_R11_EAC";
46
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["RG11_EAC"] = 0x9272] = "RG11_EAC";
47
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["SIGNED_RG11_EAC"] = 0x9273] = "SIGNED_RG11_EAC";
48
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["RGB8_ETC2"] = 0x9274] = "RGB8_ETC2";
49
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["SRGB8_ETC2"] = 0x9275] = "SRGB8_ETC2";
50
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["RGB8_PUNCHTHROUGH_ALPHA1_ETC2"] = 0x9276] = "RGB8_PUNCHTHROUGH_ALPHA1_ETC2";
51
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["SRGB8_PUNCHTHROUGH_ALPHA1_ETC2"] = 0x9277] = "SRGB8_PUNCHTHROUGH_ALPHA1_ETC2";
52
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["RGBA8_ETC2_EAC"] = 0x9278] = "RGBA8_ETC2_EAC";
53
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["SRGB8_ALPHA8_ETC2_EAC"] = 0x9279] = "SRGB8_ALPHA8_ETC2_EAC";
54
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat[// pvrtc
55
+ "RGB_PVRTC_4BPPV1_IMG"] = 0x8c00] = "RGB_PVRTC_4BPPV1_IMG";
56
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["RGB_PVRTC_2BPPV1_IMG"] = 0x8c01] = "RGB_PVRTC_2BPPV1_IMG";
57
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["RGBA_PVRTC_4BPPV1_IMG"] = 0x8c02] = "RGBA_PVRTC_4BPPV1_IMG";
58
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["RGBA_PVRTC_2BPPV1_IMG"] = 0x8c03] = "RGBA_PVRTC_2BPPV1_IMG";
59
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat[// s3tc
60
+ "RGB_S3TC_DXT1_EXT"] = 0x83f0] = "RGB_S3TC_DXT1_EXT";
61
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["RGBA_S3TC_DXT1_EXT"] = 0x83f1] = "RGBA_S3TC_DXT1_EXT";
62
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["RGBA_S3TC_DXT3_EXT"] = 0x83f2] = "RGBA_S3TC_DXT3_EXT";
63
+ GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["RGBA_S3TC_DXT5_EXT"] = 0x83f3] = "RGBA_S3TC_DXT5_EXT";
64
+ })(exports.GLCompressedTextureInternalFormat || (exports.GLCompressedTextureInternalFormat = {}));
65
+
66
+ function _defineProperties(target, props) {
67
+ for (var i = 0; i < props.length; i++) {
68
+ var descriptor = props[i];
69
+ descriptor.enumerable = descriptor.enumerable || false;
70
+ descriptor.configurable = true;
71
+ if ("value" in descriptor) descriptor.writable = true;
72
+ Object.defineProperty(target, descriptor.key, descriptor);
73
+ }
74
+ }
75
+
76
+ function _createClass(Constructor, protoProps, staticProps) {
77
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
78
+ if (staticProps) _defineProperties(Constructor, staticProps);
79
+ return Constructor;
80
+ }
81
+
82
+ function _instanceof(left, right) {
83
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
84
+ return !!right[Symbol.hasInstance](left);
85
+ } else {
86
+ return left instanceof right;
87
+ }
88
+ }
89
+
90
+ /**
91
+ * The canvas used on the web, which can support HTMLCanvasElement and OffscreenCanvas.
92
+ */ var WebCanvas = /*#__PURE__*/ function() {
93
+ function WebCanvas(webCanvas) {
94
+ this._scale = new engineMath.Vector2();
95
+ var width = webCanvas.width;
96
+ var height = webCanvas.height;
97
+ this._webCanvas = webCanvas;
98
+ this._width = width;
99
+ this._height = height;
100
+ }
101
+ var _proto = WebCanvas.prototype;
102
+ /**
103
+ * Resize the rendering size according to the clientWidth and clientHeight of the canvas.
104
+ * @param pixelRatio - Pixel ratio
105
+ */ _proto.resizeByClientSize = function resizeByClientSize(pixelRatio) {
106
+ if (pixelRatio === void 0) pixelRatio = window.devicePixelRatio;
107
+ var webCanvas = this._webCanvas;
108
+ if (typeof OffscreenCanvas === "undefined" || !_instanceof(webCanvas, OffscreenCanvas)) {
109
+ this.width = webCanvas.clientWidth * pixelRatio;
110
+ this.height = webCanvas.clientHeight * pixelRatio;
111
+ }
112
+ };
113
+ /**
114
+ * Set scale.
115
+ * @param x - Scale along the X axis
116
+ * @param y - Scale along the Y axis
117
+ */ _proto.setScale = function setScale(x, y) {
118
+ this._scale.set(x, y);
119
+ this.scale = this._scale;
120
+ };
121
+ _createClass(WebCanvas, [
122
+ {
123
+ key: "width",
124
+ get: /**
125
+ * @inheritdoc
126
+ */ function get() {
127
+ return this._width;
128
+ },
129
+ set: function set(value) {
130
+ if (this._width !== value) {
131
+ this._webCanvas.width = value;
132
+ this._width = value;
133
+ }
134
+ }
135
+ },
136
+ {
137
+ key: "height",
138
+ get: /**
139
+ * @inheritdoc
140
+ */ function get() {
141
+ return this._height;
142
+ },
143
+ set: function set(value) {
144
+ if (this._height !== value) {
145
+ this._webCanvas.height = value;
146
+ this._height = value;
147
+ }
148
+ }
149
+ },
150
+ {
151
+ key: "scale",
152
+ get: /**
153
+ * The scale of canvas, the value is visible width/height divide the render width/height.
154
+ * @remarks Need to re-assign after modification to ensure that the modification takes effect.
155
+ */ function get() {
156
+ var webCanvas = this._webCanvas;
157
+ if (typeof OffscreenCanvas === "undefined" || !_instanceof(webCanvas, OffscreenCanvas)) {
158
+ this._scale.set(webCanvas.clientWidth * devicePixelRatio / webCanvas.width, webCanvas.clientHeight * devicePixelRatio / webCanvas.height);
159
+ }
160
+ return this._scale;
161
+ },
162
+ set: function set(value) {
163
+ var webCanvas = this._webCanvas;
164
+ if (typeof OffscreenCanvas === "undefined" || !_instanceof(webCanvas, OffscreenCanvas)) {
165
+ webCanvas.style.transformOrigin = "left top";
166
+ webCanvas.style.transform = "scale(" + value.x + ", " + value.y + ")";
167
+ }
168
+ }
169
+ }
170
+ ]);
171
+ return WebCanvas;
172
+ }();
173
+
174
+ function setPrototypeOf(o, p) {
175
+ setPrototypeOf = Object.setPrototypeOf || function setPrototypeOf(o, p) {
176
+ o.__proto__ = p;
177
+ return o;
178
+ };
179
+
180
+ return setPrototypeOf(o, p);
181
+ }
182
+
183
+ function _setPrototypeOf(o, p) {
184
+ return setPrototypeOf(o, p);
185
+ }
186
+
187
+ function _inherits(subClass, superClass) {
188
+ if (typeof superClass !== "function" && superClass !== null) {
189
+ throw new TypeError("Super expression must either be null or a function");
190
+ }
191
+
192
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
193
+ constructor: {
194
+ value: subClass,
195
+ writable: true,
196
+ configurable: true
197
+ }
198
+ });
199
+ if (superClass) _setPrototypeOf(subClass, superClass);
200
+ }
201
+
202
+ function extends_() {
203
+ extends_ = Object.assign || function (target) {
204
+ for (var i = 1; i < arguments.length; i++) {
205
+ var source = arguments[i];
206
+
207
+ for (var key in source) {
208
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
209
+ target[key] = source[key];
210
+ }
211
+ }
212
+ }
213
+
214
+ return target;
215
+ };
216
+
217
+ return extends_.apply(this, arguments);
218
+ }
219
+
220
+ function _extends() {
221
+ return extends_.apply(this, arguments);
222
+ }
223
+
224
+ /**
225
+ * GL capability.
226
+ */ var GLCapability = /*#__PURE__*/ function() {
227
+ function GLCapability(rhi) {
228
+ this._rhi = rhi;
229
+ this.capabilityList = new Map();
230
+ this._init();
231
+ this._compatibleAllInterface();
232
+ }
233
+ var _proto = GLCapability.prototype;
234
+ /**
235
+ * Check device capabilities.
236
+ */ _proto.canIUse = function canIUse(capabilityType) {
237
+ return this.capabilityList.get(capabilityType);
238
+ };
239
+ /**
240
+ * Check if can use some compressed texture format.
241
+ */ _proto.canIUseCompressedTextureInternalFormat = function canIUseCompressedTextureInternalFormat(internalType) {
242
+ var // astc
243
+ RGBA_ASTC_4X4_KHR = exports.GLCompressedTextureInternalFormat.RGBA_ASTC_4X4_KHR, RGBA_ASTC_12X12_KHR = exports.GLCompressedTextureInternalFormat.RGBA_ASTC_12X12_KHR, SRGB8_ALPHA8_ASTC_4X4_KHR = exports.GLCompressedTextureInternalFormat.SRGB8_ALPHA8_ASTC_4X4_KHR, SRGB8_ALPHA8_ASTC_12X12_KHR = exports.GLCompressedTextureInternalFormat.SRGB8_ALPHA8_ASTC_12X12_KHR, // etc1
244
+ RGB_ETC1_WEBGL = exports.GLCompressedTextureInternalFormat.RGB_ETC1_WEBGL, // etc
245
+ R11_EAC = exports.GLCompressedTextureInternalFormat.R11_EAC, SRGB8_ALPHA8_ETC2_EAC = exports.GLCompressedTextureInternalFormat.SRGB8_ALPHA8_ETC2_EAC, // pvrtc
246
+ RGB_PVRTC_4BPPV1_IMG = exports.GLCompressedTextureInternalFormat.RGB_PVRTC_4BPPV1_IMG, RGBA_PVRTC_2BPPV1_IMG = exports.GLCompressedTextureInternalFormat.RGBA_PVRTC_2BPPV1_IMG, // s3tc
247
+ RGB_S3TC_DXT1_EXT = exports.GLCompressedTextureInternalFormat.RGB_S3TC_DXT1_EXT, RGBA_S3TC_DXT5_EXT = exports.GLCompressedTextureInternalFormat.RGBA_S3TC_DXT5_EXT;
248
+ if (internalType >= RGBA_ASTC_4X4_KHR && RGBA_ASTC_12X12_KHR <= RGBA_ASTC_12X12_KHR || internalType >= SRGB8_ALPHA8_ASTC_4X4_KHR && internalType <= SRGB8_ALPHA8_ASTC_12X12_KHR) {
249
+ return this.canIUse(engineCore.GLCapabilityType.astc);
250
+ } else if (internalType === RGB_ETC1_WEBGL) {
251
+ return this.canIUse(engineCore.GLCapabilityType.etc1);
252
+ } else if (internalType >= R11_EAC && internalType <= SRGB8_ALPHA8_ETC2_EAC) {
253
+ return this.canIUse(engineCore.GLCapabilityType.etc);
254
+ } else if (internalType >= RGB_PVRTC_4BPPV1_IMG && internalType <= RGBA_PVRTC_2BPPV1_IMG) {
255
+ return this.canIUse(engineCore.GLCapabilityType.pvrtc);
256
+ } else if (internalType >= RGB_S3TC_DXT1_EXT && internalType <= RGBA_S3TC_DXT5_EXT) {
257
+ return this.canIUse(engineCore.GLCapabilityType.s3tc);
258
+ }
259
+ return false;
260
+ };
261
+ /**
262
+ * Init capabilities.
263
+ */ _proto._init = function _init() {
264
+ var cap = this.capabilityList;
265
+ var isWebGL2 = this.rhi.isWebGL2;
266
+ var requireExtension = this.rhi.requireExtension.bind(this.rhi);
267
+ var shaderVertexID = engineCore.GLCapabilityType.shaderVertexID, standardDerivatives = engineCore.GLCapabilityType.standardDerivatives, shaderTextureLod = engineCore.GLCapabilityType.shaderTextureLod, elementIndexUint = engineCore.GLCapabilityType.elementIndexUint, depthTexture = engineCore.GLCapabilityType.depthTexture, vertexArrayObject = engineCore.GLCapabilityType.vertexArrayObject, instancedArrays = engineCore.GLCapabilityType.instancedArrays, multipleSample = engineCore.GLCapabilityType.multipleSample, drawBuffers = engineCore.GLCapabilityType.drawBuffers, astc = engineCore.GLCapabilityType.astc, astc_webkit = engineCore.GLCapabilityType.astc_webkit, etc = engineCore.GLCapabilityType.etc, etc_webkit = engineCore.GLCapabilityType.etc_webkit, etc1 = engineCore.GLCapabilityType.etc1, etc1_webkit = engineCore.GLCapabilityType.etc1_webkit, pvrtc = engineCore.GLCapabilityType.pvrtc, pvrtc_webkit = engineCore.GLCapabilityType.pvrtc_webkit, s3tc = engineCore.GLCapabilityType.s3tc, s3tc_webkit = engineCore.GLCapabilityType.s3tc_webkit, textureFloat = engineCore.GLCapabilityType.textureFloat, textureHalfFloat = engineCore.GLCapabilityType.textureHalfFloat, textureFloatLinear = engineCore.GLCapabilityType.textureFloatLinear, textureHalfFloatLinear = engineCore.GLCapabilityType.textureHalfFloatLinear, WEBGL_colorBufferFloat = engineCore.GLCapabilityType.WEBGL_colorBufferFloat, colorBufferFloat = engineCore.GLCapabilityType.colorBufferFloat, colorBufferHalfFloat = engineCore.GLCapabilityType.colorBufferHalfFloat, textureFilterAnisotropic = engineCore.GLCapabilityType.textureFilterAnisotropic;
268
+ cap.set(shaderVertexID, isWebGL2);
269
+ cap.set(standardDerivatives, isWebGL2 || !!requireExtension(standardDerivatives));
270
+ cap.set(shaderTextureLod, isWebGL2 || !!requireExtension(shaderTextureLod));
271
+ cap.set(elementIndexUint, isWebGL2 || !!requireExtension(elementIndexUint));
272
+ cap.set(depthTexture, isWebGL2 || !!requireExtension(depthTexture));
273
+ cap.set(vertexArrayObject, isWebGL2 || !!requireExtension(vertexArrayObject));
274
+ cap.set(instancedArrays, isWebGL2 || !!requireExtension(instancedArrays));
275
+ cap.set(multipleSample, isWebGL2);
276
+ cap.set(drawBuffers, isWebGL2 || !!requireExtension(drawBuffers));
277
+ cap.set(textureFloat, isWebGL2 || !!requireExtension(textureFloat));
278
+ cap.set(textureHalfFloat, isWebGL2 || !!requireExtension(textureHalfFloat));
279
+ cap.set(textureFloatLinear, !!requireExtension(textureFloatLinear));
280
+ cap.set(textureHalfFloatLinear, isWebGL2 || !!requireExtension(textureHalfFloatLinear));
281
+ cap.set(colorBufferFloat, isWebGL2 && !!requireExtension(colorBufferFloat) || !!requireExtension(WEBGL_colorBufferFloat));
282
+ cap.set(colorBufferHalfFloat, isWebGL2 && !!requireExtension(colorBufferFloat) || !!requireExtension(colorBufferHalfFloat));
283
+ cap.set(textureFilterAnisotropic, !!requireExtension(textureFilterAnisotropic));
284
+ cap.set(astc, !!(requireExtension(astc) || requireExtension(astc_webkit)));
285
+ cap.set(etc, !!(requireExtension(etc) || requireExtension(etc_webkit)));
286
+ cap.set(etc1, !!(requireExtension(etc1) || requireExtension(etc1_webkit)));
287
+ cap.set(pvrtc, !!(requireExtension(pvrtc) || requireExtension(pvrtc_webkit)));
288
+ cap.set(s3tc, !!(requireExtension(s3tc) || requireExtension(s3tc_webkit)));
289
+ };
290
+ /**
291
+ * If there are extensions that can supplement this ability, smooth out the difference.
292
+ * @example
293
+ * compatible(GLCapabilityType.depthTexture,{
294
+ * UNSIGNED_INT_24_8: "UNSIGNED_INT_24_8_WEBGL"
295
+ * })
296
+ * gl.UNSIGNED_INT_24_8 = ext.UNSIGNED_INT_24_8_WEBGL
297
+ */ _proto._compatibleInterface = function _compatibleInterface(capabilityType, flatItem) {
298
+ var rhi = this.rhi;
299
+ var gl = rhi.gl;
300
+ var ext = null;
301
+ if (ext = rhi.requireExtension(capabilityType)) {
302
+ for(var glKey in flatItem){
303
+ var extensionKey = flatItem[glKey];
304
+ var extensionVal = ext[extensionKey];
305
+ // Mini game hack the native function,use “.bind” to smooth out if is “Funcion”.
306
+ if (extensionVal == null ? void 0 : extensionVal.bind) {
307
+ gl[glKey] = extensionVal.bind(ext);
308
+ } else {
309
+ gl[glKey] = extensionVal;
310
+ }
311
+ }
312
+ }
313
+ };
314
+ _proto._compatibleAllInterface = function _compatibleAllInterface() {
315
+ var depthTexture = engineCore.GLCapabilityType.depthTexture, vertexArrayObject = engineCore.GLCapabilityType.vertexArrayObject, instancedArrays = engineCore.GLCapabilityType.instancedArrays, drawBuffers = engineCore.GLCapabilityType.drawBuffers, textureFilterAnisotropic = engineCore.GLCapabilityType.textureFilterAnisotropic, textureHalfFloat = engineCore.GLCapabilityType.textureHalfFloat, colorBufferHalfFloat = engineCore.GLCapabilityType.colorBufferHalfFloat, WEBGL_colorBufferFloat = engineCore.GLCapabilityType.WEBGL_colorBufferFloat;
316
+ var isWebGL2 = this.rhi.isWebGL2;
317
+ if (!isWebGL2) {
318
+ this._compatibleInterface(depthTexture, {
319
+ UNSIGNED_INT_24_8: "UNSIGNED_INT_24_8_WEBGL"
320
+ });
321
+ this._compatibleInterface(vertexArrayObject, {
322
+ createVertexArray: "createVertexArrayOES",
323
+ deleteVertexArray: "deleteVertexArrayOES",
324
+ isVertexArray: "isVertexArrayOES",
325
+ bindVertexArray: "bindVertexArrayOES"
326
+ });
327
+ this._compatibleInterface(instancedArrays, {
328
+ drawArraysInstanced: "drawArraysInstancedANGLE",
329
+ drawElementsInstanced: "drawElementsInstancedANGLE",
330
+ vertexAttribDivisor: "vertexAttribDivisorANGLE"
331
+ });
332
+ this._compatibleInterface(drawBuffers, {
333
+ MAX_DRAW_BUFFERS: "MAX_DRAW_BUFFERS_WEBGL"
334
+ });
335
+ var items = {};
336
+ if (this.canIUse(engineCore.GLCapabilityType.drawBuffers)) {
337
+ var maxDrawBuffers = this.maxDrawBuffers;
338
+ for(var i = 0; i < maxDrawBuffers; i++){
339
+ i != 0 && (items["COLOR_ATTACHMENT" + i] = "COLOR_ATTACHMENT" + i + "_WEBGL");
340
+ items["DRAW_BUFFER" + i] = "DRAW_BUFFER" + i + "_WEBGL";
341
+ }
342
+ this._compatibleInterface(drawBuffers, _extends({
343
+ drawBuffers: "drawBuffersWEBGL"
344
+ }, items));
345
+ }
346
+ this._compatibleInterface(textureHalfFloat, {
347
+ HALF_FLOAT: "HALF_FLOAT_OES"
348
+ });
349
+ this._compatibleInterface(colorBufferHalfFloat, {
350
+ RGBA16F: "RBGA16F_EXT"
351
+ });
352
+ this._compatibleInterface(WEBGL_colorBufferFloat, {
353
+ RGBA32F: "RBGA32F_EXT"
354
+ });
355
+ }
356
+ this._compatibleInterface(textureFilterAnisotropic, {
357
+ TEXTURE_MAX_ANISOTROPY_EXT: "TEXTURE_MAX_ANISOTROPY_EXT"
358
+ });
359
+ };
360
+ _createClass(GLCapability, [
361
+ {
362
+ key: "maxTextureSize",
363
+ get: function get() {
364
+ return this.rhi.renderStates.getParameter(this.rhi.gl.MAX_TEXTURE_SIZE);
365
+ }
366
+ },
367
+ {
368
+ key: "canUseFloatTextureBlendShape",
369
+ get: function get() {
370
+ return this.canIUse(engineCore.GLCapabilityType.shaderVertexID) && this.canIUse(engineCore.GLCapabilityType.textureFloat) && this.rhi.renderStates.getParameter(this.rhi.gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS) > 0;
371
+ }
372
+ },
373
+ {
374
+ key: "canIUseMoreJoints",
375
+ get: /**
376
+ * Whether can use more joints.
377
+ */ function get() {
378
+ return this.canIUse(engineCore.GLCapabilityType.textureFloat) && this.rhi.renderStates.getParameter(this.rhi.gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS) > 0;
379
+ }
380
+ },
381
+ {
382
+ key: "maxDrawBuffers",
383
+ get: function get() {
384
+ if (!this._maxDrawBuffers) {
385
+ if (this.canIUse(engineCore.GLCapabilityType.drawBuffers)) {
386
+ this._maxDrawBuffers = this._rhi.gl.getParameter(this._rhi.gl.MAX_DRAW_BUFFERS);
387
+ } else {
388
+ this._maxDrawBuffers = 1;
389
+ }
390
+ }
391
+ return this._maxDrawBuffers;
392
+ }
393
+ },
394
+ {
395
+ key: "maxAnisoLevel",
396
+ get: /**
397
+ * Max anisoLevel.
398
+ */ function get() {
399
+ if (!this._maxAnisoLevel) {
400
+ var ext = this._rhi.requireExtension(engineCore.GLCapabilityType.textureFilterAnisotropic);
401
+ this._maxAnisoLevel = ext ? this._rhi.gl.getParameter(ext.MAX_TEXTURE_MAX_ANISOTROPY_EXT) : 1;
402
+ }
403
+ return this._maxAnisoLevel;
404
+ }
405
+ },
406
+ {
407
+ key: "maxAntiAliasing",
408
+ get: /**
409
+ * Max MSAA count.
410
+ */ function get() {
411
+ if (!this._maxAntiAliasing) {
412
+ var gl = this._rhi.gl;
413
+ var canMSAA = this.canIUse(engineCore.GLCapabilityType.multipleSample);
414
+ this._maxAntiAliasing = canMSAA ? gl.getParameter(gl.MAX_SAMPLES) : 1;
415
+ }
416
+ return this._maxAntiAliasing;
417
+ }
418
+ },
419
+ {
420
+ key: "rhi",
421
+ get: function get() {
422
+ return this._rhi;
423
+ }
424
+ }
425
+ ]);
426
+ return GLCapability;
427
+ }();
428
+
429
+ /**
430
+ * GLContext extension.
431
+ */ var GLExtensions = /*#__PURE__*/ function() {
432
+ function GLExtensions(rhi) {
433
+ this.rhi = rhi;
434
+ this._requireResult = {};
435
+ }
436
+ var _proto = GLExtensions.prototype;
437
+ /**
438
+ * Require an extension.
439
+ */ _proto.requireExtension = function requireExtension(ext) {
440
+ if (this._requireResult[ext] !== undefined) {
441
+ return this._requireResult[ext];
442
+ }
443
+ this._requireResult[ext] = this.rhi.gl.getExtension(ext);
444
+ return this._requireResult[ext];
445
+ };
446
+ return GLExtensions;
447
+ }();
448
+
449
+ /**
450
+ * Improvement of VAO:
451
+ * 1) WebGL2.0 must support VAO, almost all devices support vao extensions in webgl1.0, we can use PollyFill,only keep VAO mode.
452
+ */ /**
453
+ * @internal
454
+ * GL platform primitive.
455
+ */ var GLPrimitive = /*#__PURE__*/ function() {
456
+ function GLPrimitive(rhi, primitive) {
457
+ this._attribLocArray = [];
458
+ this._vaoMap = new Map();
459
+ this._primitive = primitive;
460
+ this._canUseInstancedArrays = rhi.canIUse(engineCore.GLCapabilityType.instancedArrays);
461
+ this._useVao = rhi.canIUse(engineCore.GLCapabilityType.vertexArrayObject);
462
+ this._gl = rhi.gl;
463
+ }
464
+ var _proto = GLPrimitive.prototype;
465
+ /**
466
+ * Draw the primitive.
467
+ */ _proto.draw = function draw(shaderProgram, subMesh) {
468
+ var gl = this._gl;
469
+ var primitive = this._primitive;
470
+ // @ts-ignore
471
+ var useVao = this._useVao && primitive._enableVAO;
472
+ if (useVao) {
473
+ // @ts-ignore
474
+ if (primitive._bufferStructChanged) {
475
+ this._clearVAO();
476
+ }
477
+ if (!this._vaoMap.has(shaderProgram.id)) {
478
+ this._registerVAO(shaderProgram);
479
+ }
480
+ var vao = this._vaoMap.get(shaderProgram.id);
481
+ gl.bindVertexArray(vao);
482
+ } else {
483
+ this._bindBufferAndAttrib(shaderProgram);
484
+ }
485
+ // @ts-ignore
486
+ var _indexBufferBinding = primitive._indexBufferBinding, _instanceCount = primitive._instanceCount, _glIndexType = primitive._glIndexType, _glIndexByteCount = primitive._glIndexByteCount;
487
+ var topology = subMesh.topology, start = subMesh.start, count = subMesh.count;
488
+ if (!_instanceCount) {
489
+ if (_indexBufferBinding) {
490
+ if (useVao) {
491
+ gl.drawElements(topology, count, _glIndexType, start * _glIndexByteCount);
492
+ } else {
493
+ var _nativeBuffer = _indexBufferBinding.buffer._nativeBuffer;
494
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _nativeBuffer);
495
+ gl.drawElements(topology, count, _glIndexType, start * _glIndexByteCount);
496
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
497
+ }
498
+ } else {
499
+ gl.drawArrays(topology, start, count);
500
+ }
501
+ } else {
502
+ if (this._canUseInstancedArrays) {
503
+ if (_indexBufferBinding) {
504
+ if (useVao) {
505
+ gl.drawElementsInstanced(topology, count, _glIndexType, start * _glIndexByteCount, _instanceCount);
506
+ } else {
507
+ var _nativeBuffer1 = _indexBufferBinding.buffer._nativeBuffer;
508
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _nativeBuffer1);
509
+ gl.drawElementsInstanced(topology, count, _glIndexType, start * _glIndexByteCount, _instanceCount);
510
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
511
+ }
512
+ } else {
513
+ gl.drawArraysInstanced(topology, start, count, _instanceCount);
514
+ }
515
+ } else {
516
+ engineCore.Logger.error("ANGLE_instanced_arrays extension is not supported");
517
+ }
518
+ }
519
+ // Unbind
520
+ if (useVao) {
521
+ gl.bindVertexArray(null);
522
+ } else {
523
+ this._disableAttrib();
524
+ }
525
+ };
526
+ _proto.destroy = function destroy() {
527
+ this._useVao && this._clearVAO();
528
+ };
529
+ /**
530
+ * Bind buffer and attribute.
531
+ */ _proto._bindBufferAndAttrib = function _bindBufferAndAttrib(shaderProgram) {
532
+ var gl = this._gl;
533
+ var primitive = this._primitive;
534
+ // @ts-ignore
535
+ var vertexBufferBindings = primitive._vertexBufferBindings;
536
+ this._attribLocArray.length = 0;
537
+ var attributeLocation = shaderProgram.attributeLocation;
538
+ // @ts-ignore
539
+ var attributes = primitive._vertexElementMap;
540
+ var vbo;
541
+ var lastBoundVbo;
542
+ for(var name in attributeLocation){
543
+ var loc = attributeLocation[name];
544
+ if (loc === -1) continue;
545
+ var element = attributes[name];
546
+ if (element) {
547
+ var _vertexBufferBindings_element_bindingIndex = vertexBufferBindings[element.bindingIndex], buffer = _vertexBufferBindings_element_bindingIndex.buffer, stride = _vertexBufferBindings_element_bindingIndex.stride;
548
+ vbo = buffer._nativeBuffer;
549
+ // prevent binding the vbo which already bound at the last loop, e.g. a buffer with multiple attributes.
550
+ if (lastBoundVbo !== vbo) {
551
+ lastBoundVbo = vbo;
552
+ gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
553
+ }
554
+ gl.enableVertexAttribArray(loc);
555
+ var elementInfo = element._glElementInfo;
556
+ gl.vertexAttribPointer(loc, elementInfo.size, elementInfo.type, elementInfo.normalized, stride, element.offset);
557
+ if (this._canUseInstancedArrays) {
558
+ gl.vertexAttribDivisor(loc, element.instanceStepRate);
559
+ }
560
+ this._attribLocArray.push(loc);
561
+ } else {
562
+ engineCore.Logger.warn("vertex attribute not found: " + name);
563
+ }
564
+ }
565
+ gl.bindBuffer(gl.ARRAY_BUFFER, null);
566
+ };
567
+ _proto._disableAttrib = function _disableAttrib() {
568
+ var gl = this._gl;
569
+ for(var i = 0, l = this._attribLocArray.length; i < l; i++){
570
+ gl.disableVertexAttribArray(this._attribLocArray[i]);
571
+ }
572
+ };
573
+ _proto._registerVAO = function _registerVAO(shaderProgram) {
574
+ var gl = this._gl;
575
+ var vao = gl.createVertexArray();
576
+ /** register VAO */ gl.bindVertexArray(vao);
577
+ // @ts-ignore
578
+ var _indexBufferBinding = this._primitive._indexBufferBinding;
579
+ if (_indexBufferBinding) {
580
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _indexBufferBinding.buffer._nativeBuffer);
581
+ }
582
+ this._bindBufferAndAttrib(shaderProgram);
583
+ /** unbind */ gl.bindVertexArray(null);
584
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
585
+ this._disableAttrib();
586
+ this._vaoMap.set(shaderProgram.id, vao);
587
+ };
588
+ _proto._clearVAO = function _clearVAO() {
589
+ var gl = this._gl;
590
+ this._vaoMap.forEach(function(vao) {
591
+ gl.deleteVertexArray(vao);
592
+ });
593
+ this._vaoMap.clear();
594
+ };
595
+ return GLPrimitive;
596
+ }();
597
+
598
+ /**
599
+ * @private
600
+ */ var GLRenderStates = /*#__PURE__*/ function() {
601
+ function GLRenderStates(gl) {
602
+ this._parameters = {};
603
+ this._gl = gl;
604
+ this._parameters = {}; // current gl state parameters
605
+ /** cache */ this._parameters[gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS] = gl.getParameter(gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS);
606
+ this._parameters[gl.MAX_VERTEX_UNIFORM_VECTORS] = gl.getParameter(gl.MAX_VERTEX_UNIFORM_VECTORS);
607
+ this._parameters[gl.MAX_VERTEX_ATTRIBS] = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
608
+ this._parameters[gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS] = gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS);
609
+ this._parameters[gl.MAX_TEXTURE_SIZE] = gl.getParameter(gl.MAX_TEXTURE_SIZE);
610
+ // init blend state same as BlendState default value.
611
+ gl.blendFuncSeparate(gl.ONE, gl.ZERO, gl.ONE, gl.ZERO);
612
+ gl.blendEquationSeparate(gl.FUNC_ADD, gl.FUNC_ADD);
613
+ gl.colorMask(true, true, true, true);
614
+ gl.blendColor(0, 0, 0, 0);
615
+ gl.disable(gl.SAMPLE_ALPHA_TO_COVERAGE);
616
+ // init depth state same as DepthState default value.
617
+ gl.enable(gl.DEPTH_TEST);
618
+ gl.depthFunc(gl.LESS);
619
+ gl.depthMask(true);
620
+ // init stencil state same as StencilState default value.
621
+ gl.disable(gl.STENCIL_TEST);
622
+ gl.stencilFuncSeparate(gl.FRONT, gl.ALWAYS, 0, 0xff);
623
+ gl.stencilFuncSeparate(gl.BACK, gl.ALWAYS, 0, 0xff);
624
+ gl.stencilOpSeparate(gl.FRONT, gl.KEEP, gl.KEEP, gl.KEEP);
625
+ gl.stencilOpSeparate(gl.BACK, gl.KEEP, gl.KEEP, gl.KEEP);
626
+ gl.stencilMask(0xff);
627
+ // init raster state same as RasterState default value.
628
+ gl.enable(gl.CULL_FACE);
629
+ gl.cullFace(gl.BACK);
630
+ gl.disable(gl.POLYGON_OFFSET_FILL);
631
+ gl.polygonOffset(0, 0);
632
+ }
633
+ var _proto = GLRenderStates.prototype;
634
+ /**
635
+ * Get a parameter.
636
+ */ _proto.getParameter = function getParameter(pname) {
637
+ return this._parameters[pname];
638
+ };
639
+ return GLRenderStates;
640
+ }();
641
+
642
+ /**
643
+ * Texture in WebGL platform.
644
+ */ var GLTexture = /*#__PURE__*/ function() {
645
+ function GLTexture(rhi, texture, target) {
646
+ this._texture = texture;
647
+ this._rhi = rhi;
648
+ this._gl = rhi.gl;
649
+ this._isWebGL2 = rhi.isWebGL2;
650
+ this._target = target;
651
+ this._glTexture = this._gl.createTexture();
652
+ }
653
+ var _proto = GLTexture.prototype;
654
+ /**
655
+ * Destroy texture.
656
+ */ _proto.destroy = function destroy() {
657
+ this._gl.deleteTexture(this._glTexture);
658
+ this._texture = null;
659
+ this._glTexture = null;
660
+ this._formatDetail = null;
661
+ };
662
+ /**
663
+ * @internal
664
+ */ _proto.setUseDepthCompareMode = function setUseDepthCompareMode(value) {
665
+ var gl = this._gl;
666
+ gl.texParameteri(this._target, gl.TEXTURE_COMPARE_MODE, value ? gl.COMPARE_REF_TO_TEXTURE : gl.NONE);
667
+ };
668
+ /**
669
+ * Generate multi-level textures based on the 0th level data.
670
+ */ _proto.generateMipmaps = function generateMipmaps() {
671
+ // @todo (1x1).generateMipmap() will flash back in uc.
672
+ if (this._texture.width !== 1 || this._texture.height !== 1) {
673
+ this._bind();
674
+ this._gl.generateMipmap(this._target);
675
+ }
676
+ };
677
+ _proto._bind = function _bind() {
678
+ this._rhi.bindTexture(this);
679
+ };
680
+ /**
681
+ * Pre-development mipmapping GPU memory.
682
+ */ _proto._init = function _init(isCube) {
683
+ var gl = this._gl;
684
+ var isWebGL2 = this._isWebGL2;
685
+ var _this__formatDetail = this._formatDetail, internalFormat = _this__formatDetail.internalFormat, baseFormat = _this__formatDetail.baseFormat, dataType = _this__formatDetail.dataType;
686
+ // @ts-ignore
687
+ var _this__texture = this._texture, mipmapCount = _this__texture.mipmapCount, width = _this__texture.width, height = _this__texture.height, _isDepthTexture = _this__texture._isDepthTexture;
688
+ this._bind();
689
+ if (isWebGL2 && !(baseFormat === gl.LUMINANCE_ALPHA || baseFormat === gl.ALPHA)) {
690
+ gl.texStorage2D(this._target, mipmapCount, internalFormat, width, height);
691
+ } else {
692
+ if (!isCube) {
693
+ if (_isDepthTexture) {
694
+ gl.texImage2D(this._target, 0, internalFormat, width, height, 0, baseFormat, dataType, null);
695
+ } else {
696
+ for(var i = 0; i < mipmapCount; i++){
697
+ var mipWidth = Math.max(1, width >> i);
698
+ var mipHeight = Math.max(1, height >> i);
699
+ gl.texImage2D(this._target, i, internalFormat, mipWidth, mipHeight, 0, baseFormat, dataType, null);
700
+ }
701
+ }
702
+ } else {
703
+ for(var i1 = 0; i1 < mipmapCount; i1++){
704
+ var size = Math.max(1, width >> i1);
705
+ for(var faceIndex = 0; faceIndex < 6; faceIndex++){
706
+ gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex, i1, internalFormat, size, size, 0, baseFormat, dataType, null);
707
+ }
708
+ }
709
+ }
710
+ }
711
+ };
712
+ /**
713
+ * Get the pixel color buffer according to the specified cube face and area.
714
+ * @param face - You can choose which cube face to read
715
+ * @param x - X coordinate of area start
716
+ * @param y - Y coordinate of area start
717
+ * @param width - Area width
718
+ * @param height - Area height
719
+ * @param out - Color buffer
720
+ * @param mipLevel - Set mip level the data want to get from
721
+ */ _proto._getPixelBuffer = function _getPixelBuffer(face, x, y, width, height, mipLevel, out) {
722
+ var gl = this._gl;
723
+ var _this__formatDetail = this._formatDetail, baseFormat = _this__formatDetail.baseFormat, dataType = _this__formatDetail.dataType;
724
+ gl.bindFramebuffer(gl.FRAMEBUFFER, this._getReadFrameBuffer());
725
+ if (mipLevel > 0 && !this._isWebGL2) {
726
+ mipLevel = 0;
727
+ engineCore.Logger.error("mipLevel only take effect in WebGL2.0");
728
+ }
729
+ if (face != null) {
730
+ gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_CUBE_MAP_POSITIVE_X + face, this._glTexture, mipLevel);
731
+ } else {
732
+ gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this._glTexture, mipLevel);
733
+ }
734
+ gl.readPixels(x, y, width, height, baseFormat, dataType, out);
735
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
736
+ };
737
+ _proto._setWrapMode = function _setWrapMode(value, pname) {
738
+ var gl = this._gl;
739
+ var isWebGL2 = this._isWebGL2;
740
+ var target = this._target;
741
+ var _this__texture = this._texture, width = _this__texture.width, height = _this__texture.height;
742
+ if (!isWebGL2 && value !== engineCore.TextureWrapMode.Clamp && (!GLTexture._isPowerOf2(width) || !GLTexture._isPowerOf2(height))) {
743
+ engineCore.Logger.warn("non-power-2 texture is not supported for REPEAT or MIRRORED_REPEAT in WebGL1,and has automatically downgraded to CLAMP_TO_EDGE");
744
+ value = engineCore.TextureWrapMode.Clamp;
745
+ }
746
+ switch(value){
747
+ case engineCore.TextureWrapMode.Clamp:
748
+ gl.texParameteri(target, pname, gl.CLAMP_TO_EDGE);
749
+ break;
750
+ case engineCore.TextureWrapMode.Repeat:
751
+ gl.texParameteri(target, pname, gl.REPEAT);
752
+ break;
753
+ case engineCore.TextureWrapMode.Mirror:
754
+ gl.texParameteri(target, pname, gl.MIRRORED_REPEAT);
755
+ break;
756
+ }
757
+ };
758
+ _proto._getReadFrameBuffer = function _getReadFrameBuffer() {
759
+ var frameBuffer = this._rhi._readFrameBuffer;
760
+ if (!frameBuffer) {
761
+ this._rhi._readFrameBuffer = frameBuffer = this._gl.createFramebuffer();
762
+ }
763
+ return frameBuffer;
764
+ };
765
+ /** @internal */ GLTexture._isPowerOf2 = function _isPowerOf2(v) {
766
+ return (v & v - 1) === 0;
767
+ };
768
+ /**
769
+ * Get more texture info from TextureFormat.
770
+ * @internal
771
+ */ GLTexture._getFormatDetail = function _getFormatDetail(format, gl, isWebGL2) {
772
+ switch(format){
773
+ case engineCore.TextureFormat.R8G8B8:
774
+ return {
775
+ internalFormat: isWebGL2 ? gl.RGB8 : gl.RGB,
776
+ baseFormat: gl.RGB,
777
+ dataType: gl.UNSIGNED_BYTE,
778
+ isCompressed: false
779
+ };
780
+ case engineCore.TextureFormat.R8G8B8A8:
781
+ return {
782
+ internalFormat: isWebGL2 ? gl.RGBA8 : gl.RGBA,
783
+ baseFormat: gl.RGBA,
784
+ dataType: gl.UNSIGNED_BYTE,
785
+ isCompressed: false
786
+ };
787
+ case engineCore.TextureFormat.R4G4B4A4:
788
+ return {
789
+ internalFormat: isWebGL2 ? gl.RGBA4 : gl.RGBA,
790
+ baseFormat: gl.RGBA,
791
+ dataType: gl.UNSIGNED_SHORT_4_4_4_4,
792
+ isCompressed: false
793
+ };
794
+ case engineCore.TextureFormat.R5G5B5A1:
795
+ return {
796
+ internalFormat: isWebGL2 ? gl.RGB5_A1 : gl.RGBA,
797
+ baseFormat: gl.RGBA,
798
+ dataType: gl.UNSIGNED_SHORT_5_5_5_1,
799
+ isCompressed: false
800
+ };
801
+ case engineCore.TextureFormat.R5G6B5:
802
+ return {
803
+ internalFormat: isWebGL2 ? gl.RGB565 : gl.RGB,
804
+ baseFormat: gl.RGB,
805
+ dataType: gl.UNSIGNED_SHORT_5_6_5,
806
+ isCompressed: false
807
+ };
808
+ case engineCore.TextureFormat.Alpha8:
809
+ return {
810
+ internalFormat: gl.ALPHA,
811
+ baseFormat: gl.ALPHA,
812
+ dataType: gl.UNSIGNED_BYTE,
813
+ isCompressed: false
814
+ };
815
+ case engineCore.TextureFormat.LuminanceAlpha:
816
+ return {
817
+ internalFormat: gl.LUMINANCE_ALPHA,
818
+ baseFormat: gl.LUMINANCE_ALPHA,
819
+ dataType: gl.UNSIGNED_BYTE,
820
+ isCompressed: false
821
+ };
822
+ case engineCore.TextureFormat.R16G16B16A16:
823
+ return {
824
+ internalFormat: isWebGL2 ? gl.RGBA16F : gl.RGBA,
825
+ baseFormat: gl.RGBA,
826
+ dataType: gl.HALF_FLOAT,
827
+ isCompressed: false
828
+ };
829
+ case engineCore.TextureFormat.R32G32B32A32:
830
+ return {
831
+ internalFormat: isWebGL2 ? gl.RGBA32F : gl.RGBA,
832
+ baseFormat: gl.RGBA,
833
+ dataType: gl.FLOAT,
834
+ isCompressed: false
835
+ };
836
+ case engineCore.TextureFormat.DXT1:
837
+ return {
838
+ internalFormat: exports.GLCompressedTextureInternalFormat.RGB_S3TC_DXT1_EXT,
839
+ isCompressed: true
840
+ };
841
+ case engineCore.TextureFormat.DXT5:
842
+ return {
843
+ internalFormat: exports.GLCompressedTextureInternalFormat.RGBA_S3TC_DXT5_EXT,
844
+ isCompressed: true
845
+ };
846
+ case engineCore.TextureFormat.ETC1_RGB:
847
+ return {
848
+ internalFormat: exports.GLCompressedTextureInternalFormat.RGB_ETC1_WEBGL,
849
+ isCompressed: true
850
+ };
851
+ case engineCore.TextureFormat.ETC2_RGB:
852
+ return {
853
+ internalFormat: exports.GLCompressedTextureInternalFormat.RGB8_ETC2,
854
+ isCompressed: true
855
+ };
856
+ case engineCore.TextureFormat.ETC2_RGBA5:
857
+ return {
858
+ internalFormat: exports.GLCompressedTextureInternalFormat.RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
859
+ isCompressed: true
860
+ };
861
+ case engineCore.TextureFormat.ETC2_RGBA8:
862
+ return {
863
+ internalFormat: exports.GLCompressedTextureInternalFormat.RGBA8_ETC2_EAC,
864
+ isCompressed: true
865
+ };
866
+ case engineCore.TextureFormat.PVRTC_RGB2:
867
+ return {
868
+ internalFormat: exports.GLCompressedTextureInternalFormat.RGB_PVRTC_2BPPV1_IMG,
869
+ isCompressed: true
870
+ };
871
+ case engineCore.TextureFormat.PVRTC_RGBA2:
872
+ return {
873
+ internalFormat: exports.GLCompressedTextureInternalFormat.RGBA_PVRTC_2BPPV1_IMG,
874
+ isCompressed: true
875
+ };
876
+ case engineCore.TextureFormat.PVRTC_RGB4:
877
+ return {
878
+ internalFormat: exports.GLCompressedTextureInternalFormat.RGB_PVRTC_4BPPV1_IMG,
879
+ isCompressed: true
880
+ };
881
+ case engineCore.TextureFormat.PVRTC_RGBA4:
882
+ return {
883
+ internalFormat: exports.GLCompressedTextureInternalFormat.RGBA_PVRTC_4BPPV1_IMG,
884
+ isCompressed: true
885
+ };
886
+ case engineCore.TextureFormat.ASTC_4x4:
887
+ return {
888
+ internalFormat: exports.GLCompressedTextureInternalFormat.RGBA_ASTC_4X4_KHR,
889
+ isCompressed: true
890
+ };
891
+ case engineCore.TextureFormat.ASTC_5x5:
892
+ return {
893
+ internalFormat: exports.GLCompressedTextureInternalFormat.RGBA_ASTC_5X5_KHR,
894
+ isCompressed: true
895
+ };
896
+ case engineCore.TextureFormat.ASTC_6x6:
897
+ return {
898
+ internalFormat: exports.GLCompressedTextureInternalFormat.RGBA_ASTC_6X6_KHR,
899
+ isCompressed: true
900
+ };
901
+ case engineCore.TextureFormat.ASTC_8x8:
902
+ return {
903
+ internalFormat: exports.GLCompressedTextureInternalFormat.RGBA_ASTC_8X8_KHR,
904
+ isCompressed: true
905
+ };
906
+ case engineCore.TextureFormat.ASTC_10x10:
907
+ return {
908
+ internalFormat: exports.GLCompressedTextureInternalFormat.RGBA_ASTC_10X10_KHR,
909
+ isCompressed: true
910
+ };
911
+ case engineCore.TextureFormat.ASTC_12x12:
912
+ return {
913
+ internalFormat: exports.GLCompressedTextureInternalFormat.RGBA_ASTC_12X12_KHR,
914
+ isCompressed: true
915
+ };
916
+ case engineCore.TextureFormat.Depth:
917
+ return {
918
+ internalFormat: isWebGL2 ? gl.DEPTH_COMPONENT32F : gl.DEPTH_COMPONENT,
919
+ baseFormat: gl.DEPTH_COMPONENT,
920
+ dataType: isWebGL2 ? gl.FLOAT : gl.UNSIGNED_SHORT,
921
+ isCompressed: false,
922
+ attachment: gl.DEPTH_ATTACHMENT
923
+ };
924
+ case engineCore.TextureFormat.DepthStencil:
925
+ return {
926
+ internalFormat: isWebGL2 ? gl.DEPTH32F_STENCIL8 : gl.DEPTH_STENCIL,
927
+ baseFormat: gl.DEPTH_STENCIL,
928
+ dataType: isWebGL2 ? gl.FLOAT_32_UNSIGNED_INT_24_8_REV : gl.UNSIGNED_INT_24_8,
929
+ isCompressed: false,
930
+ attachment: gl.DEPTH_STENCIL_ATTACHMENT
931
+ };
932
+ case engineCore.TextureFormat.Depth16:
933
+ return {
934
+ internalFormat: isWebGL2 ? gl.DEPTH_COMPONENT16 : gl.DEPTH_COMPONENT,
935
+ baseFormat: gl.DEPTH_COMPONENT,
936
+ dataType: gl.UNSIGNED_SHORT,
937
+ isCompressed: false,
938
+ attachment: gl.DEPTH_ATTACHMENT
939
+ };
940
+ case engineCore.TextureFormat.Depth24Stencil8:
941
+ return {
942
+ internalFormat: isWebGL2 ? gl.DEPTH24_STENCIL8 : gl.DEPTH_STENCIL,
943
+ baseFormat: gl.DEPTH_STENCIL,
944
+ dataType: gl.UNSIGNED_INT_24_8,
945
+ isCompressed: false,
946
+ attachment: gl.DEPTH_STENCIL_ATTACHMENT
947
+ };
948
+ case engineCore.TextureFormat.Depth24:
949
+ return {
950
+ internalFormat: gl.DEPTH_COMPONENT24,
951
+ baseFormat: gl.DEPTH_COMPONENT,
952
+ dataType: gl.UNSIGNED_INT,
953
+ isCompressed: false,
954
+ attachment: gl.DEPTH_ATTACHMENT
955
+ };
956
+ case engineCore.TextureFormat.Depth32:
957
+ return {
958
+ internalFormat: gl.DEPTH_COMPONENT32F,
959
+ baseFormat: gl.DEPTH_COMPONENT,
960
+ dataType: gl.FLOAT,
961
+ isCompressed: false,
962
+ attachment: gl.DEPTH_ATTACHMENT
963
+ };
964
+ case engineCore.TextureFormat.Depth32Stencil8:
965
+ return {
966
+ internalFormat: gl.DEPTH32F_STENCIL8,
967
+ baseFormat: gl.DEPTH_STENCIL,
968
+ dataType: gl.FLOAT_32_UNSIGNED_INT_24_8_REV,
969
+ isCompressed: false,
970
+ attachment: gl.DEPTH_STENCIL_ATTACHMENT
971
+ };
972
+ default:
973
+ throw new Error("this TextureFormat is not supported in Galacean Engine: " + format);
974
+ }
975
+ };
976
+ /**
977
+ * In WebGL 1, internalformat must be the same as baseFormat when call texImage2D.
978
+ * @internal
979
+ */ GLTexture._getRenderBufferDepthFormatDetail = function _getRenderBufferDepthFormatDetail(format, gl, isWebGL2) {
980
+ switch(format){
981
+ case engineCore.RenderBufferDepthFormat.Depth:
982
+ return {
983
+ internalFormat: isWebGL2 ? gl.DEPTH_COMPONENT32F : gl.DEPTH_COMPONENT16,
984
+ baseFormat: gl.DEPTH_COMPONENT,
985
+ dataType: isWebGL2 ? gl.FLOAT : gl.UNSIGNED_SHORT,
986
+ isCompressed: false,
987
+ attachment: gl.DEPTH_ATTACHMENT
988
+ };
989
+ case engineCore.RenderBufferDepthFormat.DepthStencil:
990
+ return {
991
+ internalFormat: isWebGL2 ? gl.DEPTH32F_STENCIL8 : gl.DEPTH_STENCIL,
992
+ baseFormat: gl.DEPTH_STENCIL,
993
+ dataType: isWebGL2 ? gl.FLOAT_32_UNSIGNED_INT_24_8_REV : gl.UNSIGNED_INT_24_8,
994
+ isCompressed: false,
995
+ attachment: gl.DEPTH_STENCIL_ATTACHMENT
996
+ };
997
+ case engineCore.RenderBufferDepthFormat.Stencil:
998
+ return {
999
+ internalFormat: gl.STENCIL_INDEX8,
1000
+ baseFormat: gl.STENCIL_ATTACHMENT,
1001
+ dataType: gl.UNSIGNED_BYTE,
1002
+ isCompressed: false,
1003
+ attachment: gl.STENCIL_ATTACHMENT
1004
+ };
1005
+ case engineCore.RenderBufferDepthFormat.Depth16:
1006
+ return {
1007
+ internalFormat: gl.DEPTH_COMPONENT16,
1008
+ baseFormat: gl.DEPTH_COMPONENT,
1009
+ dataType: gl.UNSIGNED_SHORT,
1010
+ isCompressed: false,
1011
+ attachment: gl.DEPTH_ATTACHMENT
1012
+ };
1013
+ case engineCore.RenderBufferDepthFormat.Depth24Stencil8:
1014
+ return {
1015
+ internalFormat: isWebGL2 ? gl.DEPTH24_STENCIL8 : gl.DEPTH_STENCIL,
1016
+ baseFormat: gl.DEPTH_STENCIL,
1017
+ dataType: gl.UNSIGNED_INT_24_8,
1018
+ isCompressed: false,
1019
+ attachment: gl.DEPTH_STENCIL_ATTACHMENT
1020
+ };
1021
+ case engineCore.RenderBufferDepthFormat.Depth24:
1022
+ return {
1023
+ internalFormat: gl.DEPTH_COMPONENT24,
1024
+ baseFormat: gl.DEPTH_COMPONENT,
1025
+ dataType: gl.UNSIGNED_INT,
1026
+ isCompressed: false,
1027
+ attachment: gl.DEPTH_ATTACHMENT
1028
+ };
1029
+ case engineCore.RenderBufferDepthFormat.Depth32:
1030
+ return {
1031
+ internalFormat: gl.DEPTH_COMPONENT32F,
1032
+ baseFormat: gl.DEPTH_COMPONENT,
1033
+ dataType: gl.FLOAT,
1034
+ isCompressed: false,
1035
+ attachment: gl.DEPTH_ATTACHMENT
1036
+ };
1037
+ case engineCore.RenderBufferDepthFormat.Depth32Stencil8:
1038
+ return {
1039
+ internalFormat: gl.DEPTH32F_STENCIL8,
1040
+ baseFormat: gl.DEPTH_STENCIL,
1041
+ dataType: gl.FLOAT_32_UNSIGNED_INT_24_8_REV,
1042
+ isCompressed: false,
1043
+ attachment: gl.DEPTH_STENCIL_ATTACHMENT
1044
+ };
1045
+ default:
1046
+ throw new Error("this TextureFormat is not supported in Galacean Engine: " + format);
1047
+ }
1048
+ };
1049
+ /**
1050
+ * Check whether the corresponding texture format is supported.
1051
+ * @internal
1052
+ */ GLTexture._supportTextureFormat = function _supportTextureFormat(format, rhi) {
1053
+ switch(format){
1054
+ case engineCore.TextureFormat.R16G16B16A16:
1055
+ if (!rhi.canIUse(engineCore.GLCapabilityType.textureHalfFloat)) {
1056
+ return false;
1057
+ }
1058
+ break;
1059
+ case engineCore.TextureFormat.R32G32B32A32:
1060
+ if (!rhi.canIUse(engineCore.GLCapabilityType.textureFloat)) {
1061
+ return false;
1062
+ }
1063
+ break;
1064
+ case engineCore.TextureFormat.Depth16:
1065
+ case engineCore.TextureFormat.Depth24Stencil8:
1066
+ case engineCore.TextureFormat.Depth:
1067
+ case engineCore.TextureFormat.DepthStencil:
1068
+ if (!rhi.canIUse(engineCore.GLCapabilityType.depthTexture)) {
1069
+ return false;
1070
+ }
1071
+ break;
1072
+ case engineCore.TextureFormat.Depth24:
1073
+ case engineCore.TextureFormat.Depth32:
1074
+ case engineCore.TextureFormat.Depth32Stencil8:
1075
+ return rhi.isWebGL2;
1076
+ }
1077
+ return true;
1078
+ };
1079
+ /**
1080
+ * @internal
1081
+ */ GLTexture._supportRenderBufferColorFormat = function _supportRenderBufferColorFormat(format, rhi) {
1082
+ var isSupported = true;
1083
+ switch(format){
1084
+ case engineCore.TextureFormat.R16G16B16A16:
1085
+ {
1086
+ if (!rhi.canIUse(engineCore.GLCapabilityType.colorBufferHalfFloat) || !rhi.canIUse(engineCore.GLCapabilityType.textureHalfFloat)) {
1087
+ isSupported = false;
1088
+ }
1089
+ }
1090
+ break;
1091
+ case engineCore.TextureFormat.R32G32B32A32:
1092
+ {
1093
+ if (!rhi.canIUse(engineCore.GLCapabilityType.colorBufferFloat) || !rhi.canIUse(engineCore.GLCapabilityType.textureFloat)) {
1094
+ isSupported = false;
1095
+ }
1096
+ }
1097
+ break;
1098
+ }
1099
+ return isSupported;
1100
+ };
1101
+ /**
1102
+ * @internal
1103
+ */ GLTexture._supportRenderBufferDepthFormat = function _supportRenderBufferDepthFormat(format, rhi) {
1104
+ if (!rhi.isWebGL2) {
1105
+ switch(format){
1106
+ case engineCore.RenderBufferDepthFormat.Depth24:
1107
+ case engineCore.RenderBufferDepthFormat.Depth32:
1108
+ case engineCore.RenderBufferDepthFormat.Depth32Stencil8:
1109
+ return false;
1110
+ }
1111
+ }
1112
+ return true;
1113
+ };
1114
+ _createClass(GLTexture, [
1115
+ {
1116
+ key: "wrapModeU",
1117
+ set: /**
1118
+ * Wrapping mode for texture coordinate S.
1119
+ */ function set(value) {
1120
+ this._bind();
1121
+ this._setWrapMode(value, this._gl.TEXTURE_WRAP_S);
1122
+ }
1123
+ },
1124
+ {
1125
+ key: "wrapModeV",
1126
+ set: /**
1127
+ * Wrapping mode for texture coordinate T.
1128
+ */ function set(value) {
1129
+ this._bind();
1130
+ this._setWrapMode(value, this._gl.TEXTURE_WRAP_T);
1131
+ }
1132
+ },
1133
+ {
1134
+ key: "filterMode",
1135
+ set: /**
1136
+ * Filter mode for texture.
1137
+ */ function set(value) {
1138
+ var gl = this._gl;
1139
+ var target = this._target;
1140
+ /** @ts-ignore */ var _mipmap = this._texture._mipmap;
1141
+ this._bind();
1142
+ switch(value){
1143
+ case engineCore.TextureFilterMode.Point:
1144
+ gl.texParameteri(target, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
1145
+ gl.texParameteri(target, gl.TEXTURE_MIN_FILTER, _mipmap ? gl.NEAREST_MIPMAP_NEAREST : gl.NEAREST);
1146
+ break;
1147
+ case engineCore.TextureFilterMode.Bilinear:
1148
+ gl.texParameteri(target, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
1149
+ gl.texParameteri(target, gl.TEXTURE_MIN_FILTER, _mipmap ? gl.LINEAR_MIPMAP_NEAREST : gl.LINEAR);
1150
+ break;
1151
+ case engineCore.TextureFilterMode.Trilinear:
1152
+ gl.texParameteri(target, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
1153
+ gl.texParameteri(target, gl.TEXTURE_MIN_FILTER, _mipmap ? gl.LINEAR_MIPMAP_LINEAR : gl.LINEAR);
1154
+ break;
1155
+ }
1156
+ }
1157
+ },
1158
+ {
1159
+ key: "anisoLevel",
1160
+ set: /**
1161
+ * Anisotropic level for texture.
1162
+ */ function set(value) {
1163
+ var gl = this._gl;
1164
+ this._bind();
1165
+ gl.texParameterf(this._target, gl.TEXTURE_MAX_ANISOTROPY_EXT, value);
1166
+ }
1167
+ },
1168
+ {
1169
+ key: "depthCompareFunction",
1170
+ set: function set(value) {
1171
+ this._bind();
1172
+ var gl = this._gl;
1173
+ switch(value){
1174
+ case engineCore.TextureDepthCompareFunction.Never:
1175
+ gl.texParameteri(this._target, gl.TEXTURE_COMPARE_FUNC, gl.NEVER);
1176
+ break;
1177
+ case engineCore.TextureDepthCompareFunction.Less:
1178
+ gl.texParameteri(this._target, gl.TEXTURE_COMPARE_FUNC, gl.LESS);
1179
+ break;
1180
+ case engineCore.TextureDepthCompareFunction.Equal:
1181
+ gl.texParameteri(this._target, gl.TEXTURE_COMPARE_FUNC, gl.EQUAL);
1182
+ break;
1183
+ case engineCore.TextureDepthCompareFunction.LessEqual:
1184
+ gl.texParameteri(this._target, gl.TEXTURE_COMPARE_FUNC, gl.LEQUAL);
1185
+ break;
1186
+ case engineCore.TextureDepthCompareFunction.Greater:
1187
+ gl.texParameteri(this._target, gl.TEXTURE_COMPARE_FUNC, gl.GREATER);
1188
+ break;
1189
+ case engineCore.TextureDepthCompareFunction.NotEqual:
1190
+ gl.texParameteri(this._target, gl.TEXTURE_COMPARE_FUNC, gl.NOTEQUAL);
1191
+ break;
1192
+ case engineCore.TextureDepthCompareFunction.GreaterEqual:
1193
+ gl.texParameteri(this._target, gl.TEXTURE_COMPARE_FUNC, gl.GEQUAL);
1194
+ break;
1195
+ case engineCore.TextureDepthCompareFunction.Always:
1196
+ gl.texParameteri(this._target, gl.TEXTURE_COMPARE_FUNC, gl.ALWAYS);
1197
+ break;
1198
+ }
1199
+ }
1200
+ }
1201
+ ]);
1202
+ return GLTexture;
1203
+ }();
1204
+
1205
+ /**
1206
+ * The render target in WebGL platform is used for off-screen rendering.
1207
+ */ var GLRenderTarget = /*#__PURE__*/ function() {
1208
+ function GLRenderTarget(rhi, target) {
1209
+ this._MSAAColorRenderBuffers = [];
1210
+ this._curMipLevel = 0;
1211
+ this._gl = rhi.gl;
1212
+ this._isWebGL2 = rhi.isWebGL2;
1213
+ this._target = target;
1214
+ /** @ts-ignore */ var _colorTextures = target._colorTextures, _depth = target._depth, width = target.width, height = target.height;
1215
+ var isDepthTexture = _instanceof(_depth, engineCore.Texture);
1216
+ /** todo
1217
+ * MRT + Cube + [,MSAA]
1218
+ * MRT + MSAA
1219
+ */ for(var i = 0, n = _colorTextures.length; i < n; i++){
1220
+ var format = _colorTextures[i]._format;
1221
+ if (!GLTexture._supportRenderBufferColorFormat(format, rhi)) {
1222
+ throw new Error("TextureFormat is not supported:" + engineCore.TextureFormat[format] + " in RenderTarget");
1223
+ }
1224
+ }
1225
+ if (!isDepthTexture && !GLTexture._supportRenderBufferDepthFormat(_depth, rhi)) {
1226
+ throw new Error("TextureFormat is not supported:" + engineCore.TextureFormat[_depth] + " in RenderTarget");
1227
+ }
1228
+ if (_colorTextures.length > 1 && !rhi.canIUse(engineCore.GLCapabilityType.drawBuffers)) {
1229
+ throw new Error("MRT is not supported");
1230
+ }
1231
+ if (_colorTextures.some(function(v) {
1232
+ return v.width !== width || v.height !== height;
1233
+ })) {
1234
+ throw new Error("ColorTexture's size must as same as RenderTarget");
1235
+ }
1236
+ if (isDepthTexture && (_depth.width !== width || _depth.height !== height)) {
1237
+ throw new Error("DepthTexture's size must as same as RenderTarget");
1238
+ }
1239
+ // todo: necessary to support MRT + Cube + [,MSAA] ?
1240
+ if (_colorTextures.length > 1 && _colorTextures.some(function(v) {
1241
+ return _instanceof(v, engineCore.TextureCube);
1242
+ })) {
1243
+ throw new Error("MRT+Cube+[,MSAA] is not supported");
1244
+ }
1245
+ var maxAntiAliasing = rhi.capability.maxAntiAliasing;
1246
+ if (target.antiAliasing > maxAntiAliasing) {
1247
+ engineCore.Logger.warn("MSAA antiAliasing exceeds the limit and is automatically downgraded to:" + maxAntiAliasing);
1248
+ /** @ts-ignore */ target._antiAliasing = maxAntiAliasing;
1249
+ }
1250
+ this._frameBuffer = this._gl.createFramebuffer();
1251
+ // bind main FBO
1252
+ this._bindMainFBO();
1253
+ // bind MSAA FBO
1254
+ if (target.antiAliasing > 1) {
1255
+ this._MSAAFrameBuffer = this._gl.createFramebuffer();
1256
+ this._bindMSAAFBO();
1257
+ }
1258
+ }
1259
+ var _proto = GLRenderTarget.prototype;
1260
+ /**
1261
+ * Set which face and mipLevel of the cube texture to render to.
1262
+ * @param faceIndex - Cube texture face
1263
+ * @param mipLevel - Set mip level the data want to write
1264
+ */ _proto.setRenderTargetInfo = function setRenderTargetInfo(faceIndex, mipLevel) {
1265
+ var _this = this, gl = _this._gl, target = _this._target;
1266
+ var depthTexture = target.depthTexture;
1267
+ var colorTexture = target.getColorTexture(0);
1268
+ var mipChanged = mipLevel !== this._curMipLevel;
1269
+ gl.bindFramebuffer(gl.FRAMEBUFFER, this._frameBuffer);
1270
+ if (colorTexture) {
1271
+ var isCube = _instanceof(colorTexture, engineCore.TextureCube);
1272
+ if (mipChanged || isCube) {
1273
+ gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, isCube ? gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex : gl.TEXTURE_2D, // @ts-ignore
1274
+ colorTexture._platformTexture._glTexture, mipLevel);
1275
+ }
1276
+ }
1277
+ if (depthTexture) {
1278
+ var isCube1 = _instanceof(depthTexture, engineCore.TextureCube);
1279
+ if (mipChanged || isCube1) {
1280
+ // @ts-ignore
1281
+ var platformTexture = depthTexture._platformTexture;
1282
+ gl.framebufferTexture2D(gl.FRAMEBUFFER, platformTexture._formatDetail.attachment, isCube1 ? gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex : gl.TEXTURE_2D, platformTexture._glTexture, mipLevel);
1283
+ }
1284
+ } else {
1285
+ if (mipChanged) {
1286
+ // @ts-ignore
1287
+ var internalFormat = GLTexture._getRenderBufferDepthFormatDetail(target._depth, gl, this._isWebGL2).internalFormat;
1288
+ gl.bindRenderbuffer(gl.RENDERBUFFER, this._depthRenderBuffer);
1289
+ gl.renderbufferStorage(gl.RENDERBUFFER, internalFormat, target.width >> mipLevel, target.height >> mipLevel);
1290
+ }
1291
+ }
1292
+ this._curMipLevel = mipLevel;
1293
+ // revert current activated render target
1294
+ this._activeRenderTarget();
1295
+ };
1296
+ /**
1297
+ * Blit FBO.
1298
+ */ _proto.blitRenderTarget = function blitRenderTarget() {
1299
+ if (!this._MSAAFrameBuffer) return;
1300
+ var gl = this._gl;
1301
+ var mask = gl.COLOR_BUFFER_BIT | (this._target.depthTexture ? gl.DEPTH_BUFFER_BIT : 0);
1302
+ var _this__target = this._target, colorTextureCount = _this__target.colorTextureCount, width = _this__target.width, height = _this__target.height;
1303
+ gl.bindFramebuffer(gl.READ_FRAMEBUFFER, this._MSAAFrameBuffer);
1304
+ gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, this._frameBuffer);
1305
+ for(var textureIndex = 0; textureIndex < colorTextureCount; textureIndex++){
1306
+ var attachment = gl.COLOR_ATTACHMENT0 + textureIndex;
1307
+ this._blitDrawBuffers[textureIndex] = attachment;
1308
+ gl.readBuffer(attachment);
1309
+ gl.drawBuffers(this._blitDrawBuffers);
1310
+ gl.blitFramebuffer(0, 0, width, height, 0, 0, width, height, mask, gl.NEAREST);
1311
+ this._blitDrawBuffers[textureIndex] = gl.NONE;
1312
+ }
1313
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
1314
+ };
1315
+ /**
1316
+ * Destroy render target.
1317
+ */ _proto.destroy = function destroy() {
1318
+ var gl = this._gl;
1319
+ this._frameBuffer && gl.deleteFramebuffer(this._frameBuffer);
1320
+ this._depthRenderBuffer && gl.deleteRenderbuffer(this._depthRenderBuffer);
1321
+ this._MSAAFrameBuffer && gl.deleteFramebuffer(this._MSAAFrameBuffer);
1322
+ this._MSAADepthRenderBuffer && gl.deleteRenderbuffer(this._MSAADepthRenderBuffer);
1323
+ for(var i = 0; i < this._MSAAColorRenderBuffers.length; i++){
1324
+ gl.deleteRenderbuffer(this._MSAAColorRenderBuffers[i]);
1325
+ }
1326
+ this._frameBuffer = null;
1327
+ this._depthRenderBuffer = null;
1328
+ this._MSAAFrameBuffer = null;
1329
+ this._MSAAColorRenderBuffers.length = 0;
1330
+ this._MSAADepthRenderBuffer = null;
1331
+ };
1332
+ /**
1333
+ * Activate this RenderTarget.
1334
+ * @internal
1335
+ * @remarks
1336
+ * If MSAA is turned on, MSAA FBO is activated, and then this._blitRenderTarget() is performed to exchange FBO.
1337
+ * If MSAA is not turned on, activate the main FBO.
1338
+ */ _proto._activeRenderTarget = function _activeRenderTarget() {
1339
+ var gl = this._gl;
1340
+ if (this._MSAAFrameBuffer) {
1341
+ gl.bindFramebuffer(gl.FRAMEBUFFER, this._MSAAFrameBuffer);
1342
+ } else {
1343
+ gl.bindFramebuffer(gl.FRAMEBUFFER, this._frameBuffer);
1344
+ }
1345
+ };
1346
+ _proto._bindMainFBO = function _bindMainFBO() {
1347
+ var gl = this._gl;
1348
+ var isWebGL2 = this._isWebGL2;
1349
+ /** @ts-ignore */ var _this__target = this._target, _depth = _this__target._depth, colorTextureCount = _this__target.colorTextureCount, width = _this__target.width, height = _this__target.height;
1350
+ var drawBuffers = new Array(colorTextureCount);
1351
+ gl.bindFramebuffer(gl.FRAMEBUFFER, this._frameBuffer);
1352
+ /** color render buffer */ for(var i = 0; i < colorTextureCount; i++){
1353
+ var colorTexture = this._target.getColorTexture(i);
1354
+ var attachment = gl.COLOR_ATTACHMENT0 + i;
1355
+ drawBuffers[i] = attachment;
1356
+ if (!_instanceof(colorTexture, engineCore.TextureCube)) {
1357
+ gl.framebufferTexture2D(gl.FRAMEBUFFER, attachment, gl.TEXTURE_2D, /** @ts-ignore */ colorTexture._platformTexture._glTexture, 0);
1358
+ }
1359
+ }
1360
+ if (colorTextureCount > 1) {
1361
+ gl.drawBuffers(drawBuffers);
1362
+ }
1363
+ this._oriDrawBuffers = drawBuffers;
1364
+ /** depth render buffer */ if (_depth !== null) {
1365
+ if (_instanceof(_depth, engineCore.Texture) && !_instanceof(_depth, engineCore.TextureCube)) {
1366
+ // @ts-ignore
1367
+ var platformTexture = _depth._platformTexture;
1368
+ gl.framebufferTexture2D(gl.FRAMEBUFFER, platformTexture._formatDetail.attachment, gl.TEXTURE_2D, platformTexture._glTexture, 0);
1369
+ } else if (this._target.antiAliasing <= 1) {
1370
+ var _GLTexture__getRenderBufferDepthFormatDetail = GLTexture._getRenderBufferDepthFormatDetail(_depth, gl, isWebGL2), internalFormat = _GLTexture__getRenderBufferDepthFormatDetail.internalFormat, attachment1 = _GLTexture__getRenderBufferDepthFormatDetail.attachment;
1371
+ var depthRenderBuffer = gl.createRenderbuffer();
1372
+ this._depthRenderBuffer = depthRenderBuffer;
1373
+ gl.bindRenderbuffer(gl.RENDERBUFFER, depthRenderBuffer);
1374
+ gl.renderbufferStorage(gl.RENDERBUFFER, internalFormat, width, height);
1375
+ gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment1, gl.RENDERBUFFER, depthRenderBuffer);
1376
+ }
1377
+ }
1378
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
1379
+ gl.bindRenderbuffer(gl.RENDERBUFFER, null);
1380
+ };
1381
+ _proto._bindMSAAFBO = function _bindMSAAFBO() {
1382
+ var gl = this._gl;
1383
+ var isWebGL2 = this._isWebGL2;
1384
+ var MSAADepthRenderBuffer = gl.createRenderbuffer();
1385
+ /** @ts-ignore */ var _this__target = this._target, _depth = _this__target._depth, colorTextureCount = _this__target.colorTextureCount, antiAliasing = _this__target.antiAliasing, width = _this__target.width, height = _this__target.height;
1386
+ this._blitDrawBuffers = new Array(colorTextureCount);
1387
+ this._MSAADepthRenderBuffer = MSAADepthRenderBuffer;
1388
+ gl.bindFramebuffer(gl.FRAMEBUFFER, this._MSAAFrameBuffer);
1389
+ // prepare MRT+MSAA color RBOs
1390
+ for(var i = 0; i < colorTextureCount; i++){
1391
+ var MSAAColorRenderBuffer = gl.createRenderbuffer();
1392
+ this._MSAAColorRenderBuffers[i] = MSAAColorRenderBuffer;
1393
+ this._blitDrawBuffers[i] = gl.NONE;
1394
+ gl.bindRenderbuffer(gl.RENDERBUFFER, MSAAColorRenderBuffer);
1395
+ gl.renderbufferStorageMultisample(gl.RENDERBUFFER, antiAliasing, /** @ts-ignore */ this._target.getColorTexture(i)._platformTexture._formatDetail.internalFormat, width, height);
1396
+ gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0 + i, gl.RENDERBUFFER, MSAAColorRenderBuffer);
1397
+ }
1398
+ gl.drawBuffers(this._oriDrawBuffers);
1399
+ // prepare MSAA depth RBO
1400
+ if (_depth !== null) {
1401
+ var _ref = _instanceof(_depth, engineCore.Texture) ? /** @ts-ignore */ _depth._platformTexture._formatDetail : GLTexture._getRenderBufferDepthFormatDetail(_depth, gl, isWebGL2), internalFormat = _ref.internalFormat, attachment = _ref.attachment;
1402
+ gl.bindRenderbuffer(gl.RENDERBUFFER, MSAADepthRenderBuffer);
1403
+ gl.renderbufferStorageMultisample(gl.RENDERBUFFER, antiAliasing, internalFormat, width, height);
1404
+ gl.framebufferRenderbuffer(gl.FRAMEBUFFER, attachment, gl.RENDERBUFFER, MSAADepthRenderBuffer);
1405
+ }
1406
+ this._checkFrameBuffer();
1407
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
1408
+ gl.bindRenderbuffer(gl.RENDERBUFFER, null);
1409
+ };
1410
+ _proto._checkFrameBuffer = function _checkFrameBuffer() {
1411
+ var gl = this._gl;
1412
+ var isWebGL2 = this._isWebGL2;
1413
+ var e = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
1414
+ switch(e){
1415
+ case gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
1416
+ throw new Error("The attachment types are mismatched or not all framebuffer attachment points are framebuffer attachment complete");
1417
+ case gl.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
1418
+ throw new Error("There is no attachment");
1419
+ case gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
1420
+ throw new Error(" Height and width of the attachment are not the same.");
1421
+ case gl.FRAMEBUFFER_UNSUPPORTED:
1422
+ throw new Error("The format of the attachment is not supported or if depth and stencil attachments are not the same renderbuffer");
1423
+ }
1424
+ if (isWebGL2 && e === gl.FRAMEBUFFER_INCOMPLETE_MULTISAMPLE) {
1425
+ throw new Error("The values of gl.RENDERBUFFER_SAMPLES are different among attached renderbuffers, or are non-zero if the attached images are a mix of renderbuffers and textures.");
1426
+ }
1427
+ };
1428
+ return GLRenderTarget;
1429
+ }();
1430
+
1431
+ /**
1432
+ * Texture 2d in WebGL platform.
1433
+ */ var GLTexture2D = /*#__PURE__*/ function(GLTexture1) {
1434
+ _inherits(GLTexture2D, GLTexture1);
1435
+ function GLTexture2D(rhi, texture2D) {
1436
+ var _this;
1437
+ _this = GLTexture1.call(this, rhi, texture2D, rhi.gl.TEXTURE_2D) || this;
1438
+ /** Backward compatible with WebGL1.0. */ _this._compressedMipFilled = 0;
1439
+ /** @ts-ignore */ var format = texture2D.format, _mipmap = texture2D._mipmap, width = texture2D.width, height = texture2D.height;
1440
+ var isWebGL2 = _this._isWebGL2;
1441
+ /** @ts-ignore */ if (!GLTexture._supportTextureFormat(format, rhi)) {
1442
+ throw new Error("Texture format is not supported:" + engineCore.TextureFormat[format]);
1443
+ }
1444
+ if (_mipmap && !isWebGL2 && (!GLTexture._isPowerOf2(width) || !GLTexture._isPowerOf2(height))) {
1445
+ engineCore.Logger.warn("non-power-2 texture is not supported for mipmap in WebGL1,and has automatically downgraded to non-mipmap");
1446
+ /** @ts-ignore */ texture2D._mipmap = false;
1447
+ /** @ts-ignore */ texture2D._mipmapCount = texture2D._getMipmapCount();
1448
+ }
1449
+ _this._formatDetail = GLTexture._getFormatDetail(format, _this._gl, isWebGL2);
1450
+ _this._formatDetail.isCompressed && !isWebGL2 || _this._init(false);
1451
+ return _this;
1452
+ }
1453
+ var _proto = GLTexture2D.prototype;
1454
+ /**
1455
+ * {@inheritDoc IPlatformTexture2D.setPixelBuffer}
1456
+ */ _proto.setPixelBuffer = function setPixelBuffer(colorBuffer, mipLevel, x, y, width, height) {
1457
+ if (mipLevel === void 0) mipLevel = 0;
1458
+ var gl = this._gl;
1459
+ var isWebGL2 = this._isWebGL2;
1460
+ var _this__formatDetail = this._formatDetail, internalFormat = _this__formatDetail.internalFormat, baseFormat = _this__formatDetail.baseFormat, dataType = _this__formatDetail.dataType, isCompressed = _this__formatDetail.isCompressed;
1461
+ var mipWidth = Math.max(1, this._texture.width >> mipLevel);
1462
+ var mipHeight = Math.max(1, this._texture.height >> mipLevel);
1463
+ width = width || mipWidth - x;
1464
+ height = height || mipHeight - y;
1465
+ this._bind();
1466
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 0);
1467
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 0);
1468
+ if (isCompressed) {
1469
+ var mipBit = 1 << mipLevel;
1470
+ if (isWebGL2 || this._compressedMipFilled & mipBit) {
1471
+ gl.compressedTexSubImage2D(this._target, mipLevel, x, y, width, height, internalFormat, colorBuffer);
1472
+ } else {
1473
+ gl.compressedTexImage2D(this._target, mipLevel, internalFormat, width, height, 0, colorBuffer);
1474
+ this._compressedMipFilled |= mipBit;
1475
+ }
1476
+ } else {
1477
+ gl.texSubImage2D(this._target, mipLevel, x, y, width, height, baseFormat, dataType, colorBuffer);
1478
+ }
1479
+ };
1480
+ /**
1481
+ * {@inheritDoc IPlatformTexture2D.setImageSource}
1482
+ */ _proto.setImageSource = function setImageSource(imageSource, mipLevel, flipY, premultiplyAlpha, x, y) {
1483
+ var gl = this._gl;
1484
+ var _this__formatDetail = this._formatDetail, baseFormat = _this__formatDetail.baseFormat, dataType = _this__formatDetail.dataType;
1485
+ this._bind();
1486
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, +flipY);
1487
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, +premultiplyAlpha);
1488
+ gl.texSubImage2D(this._target, mipLevel, x || 0, y || 0, baseFormat, dataType, imageSource);
1489
+ };
1490
+ /**
1491
+ * {@inheritDoc IPlatformTexture2D.getPixelBuffer }
1492
+ */ _proto.getPixelBuffer = function getPixelBuffer(x, y, width, height, mipLevel, out) {
1493
+ if (this._formatDetail.isCompressed) {
1494
+ throw new Error("Unable to read compressed texture");
1495
+ }
1496
+ GLTexture1.prototype._getPixelBuffer.call(this, null, x, y, width, height, mipLevel, out);
1497
+ };
1498
+ return GLTexture2D;
1499
+ }(GLTexture);
1500
+
1501
+ /**
1502
+ * Texture 2D array in WebGL platform.
1503
+ */ var GLTexture2DArray = /*#__PURE__*/ function(GLTexture1) {
1504
+ _inherits(GLTexture2DArray, GLTexture1);
1505
+ function GLTexture2DArray(rhi, texture2DArray) {
1506
+ var _this;
1507
+ _this = GLTexture1.call(this, rhi, texture2DArray, rhi.gl.TEXTURE_2D_ARRAY) || this;
1508
+ var format = texture2DArray.format, width = texture2DArray.width, height = texture2DArray.height, length = texture2DArray.length, mipmapCount = texture2DArray.mipmapCount;
1509
+ if (!_this._isWebGL2) {
1510
+ throw new Error("Texture2D Array is not supported in WebGL1.0");
1511
+ }
1512
+ /** @ts-ignore */ if (!GLTexture._supportTextureFormat(format, rhi)) {
1513
+ throw new Error("Texture format is not supported:" + engineCore.TextureFormat[format]);
1514
+ }
1515
+ _this._bind();
1516
+ _this._formatDetail = GLTexture._getFormatDetail(format, _this._gl, true);
1517
+ _this._gl.texStorage3D(_this._target, mipmapCount, _this._formatDetail.internalFormat, width, height, length);
1518
+ return _this;
1519
+ }
1520
+ var _proto = GLTexture2DArray.prototype;
1521
+ /**
1522
+ * {@inheritDoc IPlatformTexture2DArray.setPixelBuffer}
1523
+ */ _proto.setPixelBuffer = function setPixelBuffer(offsetIndex, colorBuffer, mipLevel, x, y, width, height, length) {
1524
+ var _this = this, target = _this._target, gl = _this._gl;
1525
+ var _this__formatDetail = this._formatDetail, internalFormat = _this__formatDetail.internalFormat, baseFormat = _this__formatDetail.baseFormat, dataType = _this__formatDetail.dataType, isCompressed = _this__formatDetail.isCompressed;
1526
+ width = width || Math.max(1, this._texture.width >> mipLevel) - x;
1527
+ height = height || Math.max(1, this._texture.height >> mipLevel) - y;
1528
+ length = length || this._texture.length;
1529
+ this._bind();
1530
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 0);
1531
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 0);
1532
+ if (isCompressed) {
1533
+ gl.compressedTexSubImage3D(target, mipLevel, x, y, offsetIndex, width, height, length, internalFormat, colorBuffer);
1534
+ } else {
1535
+ gl.texSubImage3D(target, mipLevel, x, y, offsetIndex, width, height, length, baseFormat, dataType, colorBuffer);
1536
+ }
1537
+ };
1538
+ /**
1539
+ * {@inheritDoc IPlatformTexture2DArray.setImageSource}
1540
+ */ _proto.setImageSource = function setImageSource(elementIndex, imageSource, mipLevel, flipY, premultiplyAlpha, x, y) {
1541
+ var gl = this._gl;
1542
+ var _this__formatDetail = this._formatDetail, baseFormat = _this__formatDetail.baseFormat, dataType = _this__formatDetail.dataType;
1543
+ this._bind();
1544
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, +flipY);
1545
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, +premultiplyAlpha);
1546
+ gl.texSubImage3D(this._target, mipLevel, x, y, elementIndex, imageSource.width, imageSource.height, 1, baseFormat, dataType, imageSource);
1547
+ };
1548
+ /**
1549
+ * {@inheritDoc IPlatformTexture2DArray.getPixelBuffer}
1550
+ */ _proto.getPixelBuffer = function getPixelBuffer(elementIndex, x, y, width, height, mipLevel, out) {
1551
+ var _this = this, gl = _this._gl, formatDetail = _this._formatDetail;
1552
+ if (formatDetail.isCompressed) {
1553
+ throw new Error("Unable to read compressed texture");
1554
+ }
1555
+ gl.bindFramebuffer(gl.FRAMEBUFFER, this._getReadFrameBuffer());
1556
+ gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, this._glTexture, mipLevel, elementIndex);
1557
+ gl.readPixels(x, y, width, height, formatDetail.baseFormat, formatDetail.dataType, out);
1558
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
1559
+ };
1560
+ return GLTexture2DArray;
1561
+ }(GLTexture);
1562
+
1563
+ /**
1564
+ * Cube texture in WebGL platform.
1565
+ */ var GLTextureCube = /*#__PURE__*/ function(GLTexture1) {
1566
+ _inherits(GLTextureCube, GLTexture1);
1567
+ function GLTextureCube(rhi, textureCube) {
1568
+ var _this;
1569
+ _this = GLTexture1.call(this, rhi, textureCube, rhi.gl.TEXTURE_CUBE_MAP) || this;
1570
+ /** Backward compatible with WebGL1.0. */ _this._compressedFaceFilled = [
1571
+ 0,
1572
+ 0,
1573
+ 0,
1574
+ 0,
1575
+ 0,
1576
+ 0
1577
+ ];
1578
+ /** @ts-ignore */ var format = textureCube.format, _mipmap = textureCube._mipmap, size = textureCube.width;
1579
+ var isWebGL2 = _this._isWebGL2;
1580
+ /** @ts-ignore */ if (!GLTexture._supportTextureFormat(format, rhi)) {
1581
+ throw new Error("Texture format is not supported:" + engineCore.TextureFormat[format]);
1582
+ }
1583
+ if (_mipmap && !isWebGL2 && !GLTexture._isPowerOf2(size)) {
1584
+ engineCore.Logger.warn("non-power-2 texture is not supported for mipmap in WebGL1,and has automatically downgraded to non-mipmap");
1585
+ /** @ts-ignore */ textureCube._mipmap = false;
1586
+ /** @ts-ignore */ textureCube._mipmapCount = textureCube._getMipmapCount();
1587
+ }
1588
+ _this._formatDetail = GLTexture._getFormatDetail(format, _this._gl, isWebGL2);
1589
+ _this._formatDetail.isCompressed && !isWebGL2 || _this._init(true);
1590
+ return _this;
1591
+ }
1592
+ var _proto = GLTextureCube.prototype;
1593
+ /**
1594
+ * {@inheritDoc IPlatformTextureCube.setPixelBuffer}
1595
+ */ _proto.setPixelBuffer = function setPixelBuffer(face, colorBuffer, mipLevel, x, y, width, height) {
1596
+ var gl = this._gl;
1597
+ var isWebGL2 = this._isWebGL2;
1598
+ var _this__formatDetail = this._formatDetail, internalFormat = _this__formatDetail.internalFormat, baseFormat = _this__formatDetail.baseFormat, dataType = _this__formatDetail.dataType, isCompressed = _this__formatDetail.isCompressed;
1599
+ var mipSize = Math.max(1, this._texture.width >> mipLevel);
1600
+ width = width || mipSize - x;
1601
+ height = height || mipSize - y;
1602
+ this._bind();
1603
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 0);
1604
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 0);
1605
+ if (isCompressed) {
1606
+ var mipBit = 1 << mipLevel;
1607
+ if (isWebGL2 || this._compressedFaceFilled[face] & mipBit) {
1608
+ gl.compressedTexSubImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + face, mipLevel, x, y, width, height, internalFormat, colorBuffer);
1609
+ } else {
1610
+ gl.compressedTexImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + face, mipLevel, internalFormat, width, height, 0, colorBuffer);
1611
+ this._compressedFaceFilled[face] |= mipBit;
1612
+ }
1613
+ } else {
1614
+ gl.texSubImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + face, mipLevel, x, y, width, height, baseFormat, dataType, colorBuffer);
1615
+ }
1616
+ };
1617
+ /**
1618
+ * {@inheritDoc IPlatformTextureCube.setImageSource}
1619
+ */ _proto.setImageSource = function setImageSource(face, imageSource, mipLevel, flipY, premultiplyAlpha, x, y) {
1620
+ var gl = this._gl;
1621
+ var _this__formatDetail = this._formatDetail, baseFormat = _this__formatDetail.baseFormat, dataType = _this__formatDetail.dataType;
1622
+ this._bind();
1623
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, +flipY);
1624
+ gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, +premultiplyAlpha);
1625
+ gl.texSubImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + face, mipLevel, x || 0, y || 0, baseFormat, dataType, imageSource);
1626
+ };
1627
+ /**
1628
+ * {@inheritDoc IPlatformTextureCube.getPixelBuffer}
1629
+ */ _proto.getPixelBuffer = function getPixelBuffer(face, x, y, width, height, mipLevel, out) {
1630
+ if (this._formatDetail.isCompressed) {
1631
+ throw new Error("Unable to read compressed texture");
1632
+ }
1633
+ GLTexture1.prototype._getPixelBuffer.call(this, face, x, y, width, height, mipLevel, out);
1634
+ };
1635
+ return GLTextureCube;
1636
+ }(GLTexture);
1637
+
1638
+ exports.WebGLMode = void 0;
1639
+ (function(WebGLMode) {
1640
+ WebGLMode[WebGLMode[/** Auto, use WebGL2.0 if support, or will fallback to WebGL1.0. */ "Auto"] = 0] = "Auto";
1641
+ WebGLMode[WebGLMode[/** WebGL2.0. */ "WebGL2"] = 1] = "WebGL2";
1642
+ WebGLMode[WebGLMode[/** WebGL1.0, */ "WebGL1"] = 2] = "WebGL1";
1643
+ })(exports.WebGLMode || (exports.WebGLMode = {}));
1644
+ /**
1645
+ * WebGL renderer, including WebGL1.0 and WebGL2.0.
1646
+ */ var WebGLRenderer = /*#__PURE__*/ function() {
1647
+ function WebGLRenderer(initializeOptions) {
1648
+ if (initializeOptions === void 0) initializeOptions = {};
1649
+ /** @internal */ this._enableGlobalDepthBias = false;
1650
+ this._activeTextures = new Array(32);
1651
+ // cache value
1652
+ this._lastViewport = new engineMath.Vector4(null, null, null, null);
1653
+ this._lastScissor = new engineMath.Vector4(null, null, null, null);
1654
+ this._lastClearColor = new engineMath.Color(null, null, null, null);
1655
+ this._scissorEnable = false;
1656
+ var options = _extends({
1657
+ webGLMode: 0,
1658
+ alpha: false,
1659
+ stencil: true,
1660
+ _forceFlush: false
1661
+ }, initializeOptions);
1662
+ if (engineCore.SystemInfo.platform === engineCore.Platform.IPhone || engineCore.SystemInfo.platform === engineCore.Platform.IPad) {
1663
+ var version = engineCore.SystemInfo.operatingSystem.match(/(\d+).?(\d+)?.?(\d+)?/);
1664
+ if (version) {
1665
+ var majorVersion = parseInt(version[1]);
1666
+ var minorVersion = parseInt(version[2]);
1667
+ if (majorVersion === 15 && minorVersion >= 0 && minorVersion <= 4) {
1668
+ options._forceFlush = true;
1669
+ }
1670
+ }
1671
+ }
1672
+ this._options = options;
1673
+ }
1674
+ var _proto = WebGLRenderer.prototype;
1675
+ _proto.init = function init(canvas) {
1676
+ var options = this._options;
1677
+ var webCanvas = this._webCanvas = canvas._webCanvas;
1678
+ var webGLMode = options.webGLMode;
1679
+ var gl;
1680
+ if (webGLMode == 0 || webGLMode == 1) {
1681
+ gl = webCanvas.getContext("webgl2", options);
1682
+ if (!gl && (typeof OffscreenCanvas === "undefined" || !_instanceof(webCanvas, OffscreenCanvas))) {
1683
+ gl = webCanvas.getContext("experimental-webgl2", options);
1684
+ }
1685
+ this._isWebGL2 = true;
1686
+ // Prevent weird browsers to lie (such as safari!)
1687
+ if (gl && !gl.deleteQuery) {
1688
+ this._isWebGL2 = false;
1689
+ }
1690
+ }
1691
+ if (!gl) {
1692
+ if (webGLMode == 0 || webGLMode == 2) {
1693
+ gl = webCanvas.getContext("webgl", options);
1694
+ if (!gl && (typeof OffscreenCanvas === "undefined" || !_instanceof(webCanvas, OffscreenCanvas))) {
1695
+ gl = webCanvas.getContext("experimental-webgl", options);
1696
+ }
1697
+ this._isWebGL2 = false;
1698
+ }
1699
+ }
1700
+ if (!gl) {
1701
+ throw new Error("Get GL Context FAILED.");
1702
+ }
1703
+ this._gl = gl;
1704
+ this._activeTextureID = gl.TEXTURE0;
1705
+ this._renderStates = new GLRenderStates(gl);
1706
+ this._extensions = new GLExtensions(this);
1707
+ this._capability = new GLCapability(this);
1708
+ // Make sure the active texture in gl context is on default, because gl context may be used in other webgl renderer.
1709
+ gl.activeTexture(gl.TEXTURE0);
1710
+ var debugRenderInfo = gl.getExtension("WEBGL_debug_renderer_info");
1711
+ if (debugRenderInfo != null) {
1712
+ this._renderer = gl.getParameter(debugRenderInfo.UNMASKED_RENDERER_WEBGL);
1713
+ }
1714
+ };
1715
+ _proto.createPlatformPrimitive = function createPlatformPrimitive(primitive) {
1716
+ return new GLPrimitive(this, primitive);
1717
+ };
1718
+ _proto.createPlatformTexture2D = function createPlatformTexture2D(texture2D) {
1719
+ return new GLTexture2D(this, texture2D);
1720
+ };
1721
+ _proto.createPlatformTexture2DArray = function createPlatformTexture2DArray(texture2D) {
1722
+ return new GLTexture2DArray(this, texture2D);
1723
+ };
1724
+ _proto.createPlatformTextureCube = function createPlatformTextureCube(textureCube) {
1725
+ return new GLTextureCube(this, textureCube);
1726
+ };
1727
+ _proto.createPlatformRenderTarget = function createPlatformRenderTarget(target) {
1728
+ return new GLRenderTarget(this, target);
1729
+ };
1730
+ _proto.requireExtension = function requireExtension(ext) {
1731
+ return this._extensions.requireExtension(ext);
1732
+ };
1733
+ _proto.canIUse = function canIUse(capabilityType) {
1734
+ return this.capability.canIUse(capabilityType);
1735
+ };
1736
+ _proto.canIUseCompressedTextureInternalFormat = function canIUseCompressedTextureInternalFormat(type) {
1737
+ return this.capability.canIUseCompressedTextureInternalFormat(type);
1738
+ };
1739
+ _proto.viewport = function viewport(x, y, width, height) {
1740
+ var _this = this, gl = _this._gl, lastViewport = _this._lastViewport;
1741
+ if (x !== lastViewport.x || y !== lastViewport.y || width !== lastViewport.z || height !== lastViewport.w) {
1742
+ gl.viewport(x, y, width, height);
1743
+ lastViewport.set(x, y, width, height);
1744
+ }
1745
+ };
1746
+ _proto.scissor = function scissor(x, y, width, height) {
1747
+ var _this = this, gl = _this._gl, lastScissor = _this._lastScissor;
1748
+ if (x !== lastScissor.x || y !== lastScissor.y || width !== lastScissor.z || height !== lastScissor.w) {
1749
+ var _this1 = this, webCanvas = _this1._webCanvas;
1750
+ if (x === 0 && y === 0 && width === webCanvas.width && height === webCanvas.height) {
1751
+ if (this._scissorEnable) {
1752
+ gl.disable(gl.SCISSOR_TEST);
1753
+ this._scissorEnable = false;
1754
+ }
1755
+ } else {
1756
+ if (!this._scissorEnable) {
1757
+ gl.enable(gl.SCISSOR_TEST);
1758
+ this._scissorEnable = true;
1759
+ }
1760
+ gl.scissor(x, y, width, height);
1761
+ }
1762
+ lastScissor.set(x, y, width, height);
1763
+ }
1764
+ };
1765
+ _proto.colorMask = function colorMask(r, g, b, a) {
1766
+ this._gl.colorMask(r, g, b, a);
1767
+ };
1768
+ _proto.clearRenderTarget = function clearRenderTarget(engine, clearFlags, clearColor) {
1769
+ var gl = this._gl;
1770
+ var _engine__lastRenderState = engine._lastRenderState, targetBlendState = _engine__lastRenderState.blendState.targetBlendState, depthState = _engine__lastRenderState.depthState, stencilState = _engine__lastRenderState.stencilState;
1771
+ var clearFlag = 0;
1772
+ if (clearFlags & engineCore.CameraClearFlags.Color) {
1773
+ clearFlag |= gl.COLOR_BUFFER_BIT;
1774
+ var lc = this._lastClearColor;
1775
+ var r = clearColor.r, g = clearColor.g, b = clearColor.b, a = clearColor.a;
1776
+ if (clearColor && (r !== lc.r || g !== lc.g || b !== lc.b || a !== lc.a)) {
1777
+ gl.clearColor(r, g, b, a);
1778
+ lc.set(r, g, b, a);
1779
+ }
1780
+ if (targetBlendState.colorWriteMask !== engineCore.ColorWriteMask.All) {
1781
+ gl.colorMask(true, true, true, true);
1782
+ targetBlendState.colorWriteMask = engineCore.ColorWriteMask.All;
1783
+ }
1784
+ }
1785
+ if (clearFlags & engineCore.CameraClearFlags.Depth) {
1786
+ clearFlag |= gl.DEPTH_BUFFER_BIT;
1787
+ if (depthState.writeEnabled !== true) {
1788
+ gl.depthMask(true);
1789
+ depthState.writeEnabled = true;
1790
+ }
1791
+ }
1792
+ if (clearFlags & engineCore.CameraClearFlags.Stencil) {
1793
+ clearFlag |= gl.STENCIL_BUFFER_BIT;
1794
+ if (stencilState.writeMask !== 0xff) {
1795
+ gl.stencilMask(0xff);
1796
+ stencilState.writeMask = 0xff;
1797
+ }
1798
+ }
1799
+ gl.clear(clearFlag);
1800
+ };
1801
+ _proto.drawPrimitive = function drawPrimitive(primitive, subPrimitive, shaderProgram) {
1802
+ // todo: VAO not support morph animation
1803
+ if (primitive) {
1804
+ //@ts-ignore
1805
+ primitive._draw(shaderProgram, subPrimitive);
1806
+ } else {
1807
+ engineCore.Logger.error("draw primitive failed.");
1808
+ }
1809
+ };
1810
+ _proto.activeRenderTarget = function activeRenderTarget(renderTarget, viewport, mipLevel) {
1811
+ var gl = this._gl;
1812
+ if (renderTarget) {
1813
+ var /** @ts-ignore */ _renderTarget__platformRenderTarget;
1814
+ (_renderTarget__platformRenderTarget = renderTarget._platformRenderTarget) == null ? void 0 : _renderTarget__platformRenderTarget._activeRenderTarget();
1815
+ var width = renderTarget.width >> mipLevel;
1816
+ var height = renderTarget.height >> mipLevel;
1817
+ this.viewport(0, 0, width, height);
1818
+ this.scissor(0, 0, width, height);
1819
+ } else {
1820
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
1821
+ var drawingBufferWidth = gl.drawingBufferWidth, drawingBufferHeight = gl.drawingBufferHeight;
1822
+ var width1 = drawingBufferWidth * viewport.z;
1823
+ var height1 = drawingBufferHeight * viewport.w;
1824
+ var x = viewport.x * drawingBufferWidth;
1825
+ var y = drawingBufferHeight - viewport.y * drawingBufferHeight - height1;
1826
+ this.viewport(x, y, width1, height1);
1827
+ this.scissor(x, y, width1, height1);
1828
+ }
1829
+ };
1830
+ _proto.activeTexture = function activeTexture(textureID) {
1831
+ if (this._activeTextureID !== textureID) {
1832
+ this._gl.activeTexture(textureID);
1833
+ this._activeTextureID = textureID;
1834
+ }
1835
+ };
1836
+ _proto.bindTexture = function bindTexture(texture) {
1837
+ var index = this._activeTextureID - this._gl.TEXTURE0;
1838
+ if (this._activeTextures[index] !== texture) {
1839
+ this._gl.bindTexture(texture._target, texture._glTexture);
1840
+ this._activeTextures[index] = texture;
1841
+ }
1842
+ };
1843
+ _proto.setGlobalDepthBias = function setGlobalDepthBias(bias, slopeBias) {
1844
+ var gl = this._gl;
1845
+ var enable = bias !== 0 || slopeBias !== 0;
1846
+ if (enable) {
1847
+ gl.enable(gl.POLYGON_OFFSET_FILL);
1848
+ gl.polygonOffset(slopeBias, bias);
1849
+ } else {
1850
+ gl.disable(gl.POLYGON_OFFSET_FILL);
1851
+ }
1852
+ this._enableGlobalDepthBias = enable;
1853
+ };
1854
+ _proto.flush = function flush() {
1855
+ this._gl.flush();
1856
+ };
1857
+ _proto.destroy = function destroy() {};
1858
+ _createClass(WebGLRenderer, [
1859
+ {
1860
+ key: "isWebGL2",
1861
+ get: function get() {
1862
+ return this._isWebGL2;
1863
+ }
1864
+ },
1865
+ {
1866
+ key: "renderer",
1867
+ get: function get() {
1868
+ return this._renderer;
1869
+ }
1870
+ },
1871
+ {
1872
+ key: "gl",
1873
+ get: /**
1874
+ * GL Context
1875
+ * @member {WebGLRenderingContext}
1876
+ */ function get() {
1877
+ return this._gl;
1878
+ }
1879
+ },
1880
+ {
1881
+ key: "renderStates",
1882
+ get: function get() {
1883
+ return this._renderStates;
1884
+ }
1885
+ },
1886
+ {
1887
+ key: "capability",
1888
+ get: function get() {
1889
+ return this._capability;
1890
+ }
1891
+ },
1892
+ {
1893
+ key: "canIUseMoreJoints",
1894
+ get: function get() {
1895
+ return this.capability.canIUseMoreJoints;
1896
+ }
1897
+ }
1898
+ ]);
1899
+ return WebGLRenderer;
1900
+ }();
1901
+
1902
+ /**
1903
+ * WebGL platform engine,support includes WebGL1.0 and WebGL2.0.
1904
+ */ var WebGLEngine = /*#__PURE__*/ function(Engine) {
1905
+ _inherits(WebGLEngine, Engine);
1906
+ function WebGLEngine(canvas, webGLRendererOptions) {
1907
+ var webCanvas = new WebCanvas(typeof canvas === "string" ? document.getElementById(canvas) : canvas);
1908
+ var hardwareRenderer = new WebGLRenderer(webGLRendererOptions);
1909
+ return Engine.call(this, webCanvas, hardwareRenderer);
1910
+ }
1911
+ _createClass(WebGLEngine, [
1912
+ {
1913
+ key: "canvas",
1914
+ get: /**
1915
+ * Web canvas.
1916
+ */ function get() {
1917
+ return this._canvas;
1918
+ }
1919
+ }
1920
+ ]);
1921
+ return WebGLEngine;
1922
+ }(engineCore.Engine);
1923
+
1924
+ exports.WebCanvas = WebCanvas;
1925
+ exports.WebGLEngine = WebGLEngine;
1926
+ exports.WebGLRenderer = WebGLRenderer;
1927
+ //# sourceMappingURL=main.js.map