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