@galacean/engine-rhi-webgl 0.0.0-experimental-renderSort.4 → 0.0.0-experimental-stateMachine.0

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License
2
2
 
3
- Copyright © 2020-2023 Galacean authors
3
+ Copyright (c) 2020 - present Ant Group
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
21
+ THE SOFTWARE.
package/dist/main.js CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var engineMath = require('@galacean/engine-math');
6
5
  var engineCore = require('@galacean/engine-core');
6
+ var engineMath = require('@galacean/engine-math');
7
7
 
8
8
  /**
9
9
  * Smoothing plug-in.
@@ -86,6 +86,26 @@ function _create_class(Constructor, protoProps, staticProps) {
86
86
  return Constructor;
87
87
  }
88
88
 
89
+ function _set_prototype_of(o, p) {
90
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
91
+ o.__proto__ = p;
92
+
93
+ return o;
94
+ };
95
+
96
+ return _set_prototype_of(o, p);
97
+ }
98
+
99
+ function _inherits(subClass, superClass) {
100
+ if (typeof superClass !== "function" && superClass !== null) {
101
+ throw new TypeError("Super expression must either be null or a function");
102
+ }
103
+
104
+ subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } });
105
+
106
+ if (superClass) _set_prototype_of(subClass, superClass);
107
+ }
108
+
89
109
  function _instanceof(left, right) {
90
110
  if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
91
111
  return !!right[Symbol.hasInstance](left);
@@ -94,14 +114,18 @@ function _instanceof(left, right) {
94
114
 
95
115
  /**
96
116
  * The canvas used on the web, which can support HTMLCanvasElement and OffscreenCanvas.
97
- */ var WebCanvas = /*#__PURE__*/ function() {
117
+ */ var WebCanvas = /*#__PURE__*/ function(Canvas1) {
118
+ _inherits(WebCanvas, Canvas1);
98
119
  function WebCanvas(webCanvas) {
99
- this._scale = new engineMath.Vector2();
120
+ var _this;
121
+ _this = Canvas1.call(this) || this;
122
+ _this._scale = new engineMath.Vector2();
100
123
  var width = webCanvas.width;
101
124
  var height = webCanvas.height;
102
- this._webCanvas = webCanvas;
103
- this._width = width;
104
- this._height = height;
125
+ _this._webCanvas = webCanvas;
126
+ _this.width = width;
127
+ _this.height = height;
128
+ return _this;
105
129
  }
106
130
  var _proto = WebCanvas.prototype;
107
131
  /**
@@ -111,8 +135,10 @@ function _instanceof(left, right) {
111
135
  if (pixelRatio === void 0) pixelRatio = window.devicePixelRatio;
112
136
  var webCanvas = this._webCanvas;
113
137
  if (typeof OffscreenCanvas === "undefined" || !_instanceof(webCanvas, OffscreenCanvas)) {
114
- this.width = webCanvas.clientWidth * pixelRatio;
115
- this.height = webCanvas.clientHeight * pixelRatio;
138
+ var exportWidth = webCanvas.clientWidth * pixelRatio;
139
+ var exportHeight = webCanvas.clientHeight * pixelRatio;
140
+ this.width = exportWidth;
141
+ this.height = exportHeight;
116
142
  }
117
143
  };
118
144
  /**
@@ -123,35 +149,13 @@ function _instanceof(left, right) {
123
149
  this._scale.set(x, y);
124
150
  this.scale = this._scale;
125
151
  };
152
+ _proto._onWidthChanged = function _onWidthChanged(value) {
153
+ this._webCanvas.width = value;
154
+ };
155
+ _proto._onHeightChange = function _onHeightChange(value) {
156
+ this._webCanvas.height = value;
157
+ };
126
158
  _create_class(WebCanvas, [
127
- {
128
- key: "width",
129
- get: /**
130
- * @inheritdoc
131
- */ function get() {
132
- return this._width;
133
- },
134
- set: function set(value) {
135
- if (this._width !== value) {
136
- this._webCanvas.width = value;
137
- this._width = value;
138
- }
139
- }
140
- },
141
- {
142
- key: "height",
143
- get: /**
144
- * @inheritdoc
145
- */ function get() {
146
- return this._height;
147
- },
148
- set: function set(value) {
149
- if (this._height !== value) {
150
- this._webCanvas.height = value;
151
- this._height = value;
152
- }
153
- }
154
- },
155
159
  {
156
160
  key: "scale",
157
161
  get: /**
@@ -174,27 +178,7 @@ function _instanceof(left, right) {
174
178
  }
175
179
  ]);
176
180
  return WebCanvas;
177
- }();
178
-
179
- function _set_prototype_of(o, p) {
180
- _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
181
- o.__proto__ = p;
182
-
183
- return o;
184
- };
185
-
186
- return _set_prototype_of(o, p);
187
- }
188
-
189
- function _inherits(subClass, superClass) {
190
- if (typeof superClass !== "function" && superClass !== null) {
191
- throw new TypeError("Super expression must either be null or a function");
192
- }
193
-
194
- subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } });
195
-
196
- if (superClass) _set_prototype_of(subClass, superClass);
197
- }
181
+ }(engineCore.Canvas);
198
182
 
199
183
  /**
200
184
  * WebGL platform engine,support includes WebGL1.0 and WebGL2.0.
@@ -366,7 +350,7 @@ var GLBuffer = /*#__PURE__*/ function() {
366
350
  var cap = this.capabilityList;
367
351
  var isWebGL2 = this.rhi.isWebGL2;
368
352
  var requireExtension = this.rhi.requireExtension.bind(this.rhi);
369
- 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, bptc = engineCore.GLCapabilityType.bptc, 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;
353
+ 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, blendMinMax = engineCore.GLCapabilityType.blendMinMax, 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, bptc = engineCore.GLCapabilityType.bptc, 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, fragDepth = engineCore.GLCapabilityType.fragDepth;
370
354
  cap.set(shaderVertexID, isWebGL2);
371
355
  cap.set(standardDerivatives, isWebGL2 || !!requireExtension(standardDerivatives));
372
356
  cap.set(shaderTextureLod, isWebGL2 || !!requireExtension(shaderTextureLod));
@@ -376,6 +360,7 @@ var GLBuffer = /*#__PURE__*/ function() {
376
360
  cap.set(instancedArrays, isWebGL2 || !!requireExtension(instancedArrays));
377
361
  cap.set(multipleSample, isWebGL2);
378
362
  cap.set(drawBuffers, isWebGL2 || !!requireExtension(drawBuffers));
363
+ cap.set(blendMinMax, isWebGL2 || !!requireExtension(blendMinMax));
379
364
  cap.set(textureFloat, isWebGL2 || !!requireExtension(textureFloat));
380
365
  cap.set(textureHalfFloat, isWebGL2 || !!requireExtension(textureHalfFloat));
381
366
  cap.set(textureFloatLinear, !!requireExtension(textureFloatLinear));
@@ -383,6 +368,7 @@ var GLBuffer = /*#__PURE__*/ function() {
383
368
  cap.set(colorBufferFloat, isWebGL2 && !!requireExtension(colorBufferFloat) || !!requireExtension(WEBGL_colorBufferFloat));
384
369
  cap.set(colorBufferHalfFloat, isWebGL2 && !!requireExtension(colorBufferFloat) || !!requireExtension(colorBufferHalfFloat));
385
370
  cap.set(textureFilterAnisotropic, !!requireExtension(textureFilterAnisotropic));
371
+ cap.set(fragDepth, isWebGL2 || !!requireExtension(fragDepth));
386
372
  cap.set(astc, !!(requireExtension(astc) || requireExtension(astc_webkit)));
387
373
  cap.set(etc, !!(requireExtension(etc) || requireExtension(etc_webkit)));
388
374
  cap.set(etc1, !!(requireExtension(etc1) || requireExtension(etc1_webkit)));
@@ -416,9 +402,13 @@ var GLBuffer = /*#__PURE__*/ function() {
416
402
  }
417
403
  };
418
404
  _proto._compatibleAllInterface = function _compatibleAllInterface() {
419
- 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;
405
+ 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, blendMinMax = engineCore.GLCapabilityType.blendMinMax;
420
406
  var isWebGL2 = this.rhi.isWebGL2;
421
407
  if (!isWebGL2) {
408
+ this._compatibleInterface(blendMinMax, {
409
+ MIN: "MIN_EXT",
410
+ MAX: "MAX_EXT"
411
+ });
422
412
  this._compatibleInterface(depthTexture, {
423
413
  UNSIGNED_INT_24_8: "UNSIGNED_INT_24_8_WEBGL"
424
414
  });
@@ -931,6 +921,13 @@ var GLBuffer = /*#__PURE__*/ function() {
931
921
  dataType: gl.FLOAT,
932
922
  isCompressed: false
933
923
  };
924
+ case engineCore.TextureFormat.R32G32B32A32_UInt:
925
+ return {
926
+ internalFormat: isWebGL2 ? gl.RGBA32UI : gl.NONE,
927
+ baseFormat: gl.RGBA_INTEGER,
928
+ dataType: gl.UNSIGNED_INT,
929
+ isCompressed: false
930
+ };
934
931
  case engineCore.TextureFormat.BC1:
935
932
  return {
936
933
  internalFormat: exports.GLCompressedTextureInternalFormat.RGB_S3TC_DXT1_EXT,
@@ -1081,7 +1078,7 @@ var GLBuffer = /*#__PURE__*/ function() {
1081
1078
  * @internal
1082
1079
  */ GLTexture._getRenderBufferDepthFormatDetail = function _getRenderBufferDepthFormatDetail(format, gl, isWebGL2) {
1083
1080
  switch(format){
1084
- case engineCore.RenderBufferDepthFormat.Depth:
1081
+ case engineCore.TextureFormat.Depth:
1085
1082
  return {
1086
1083
  internalFormat: isWebGL2 ? gl.DEPTH_COMPONENT32F : gl.DEPTH_COMPONENT16,
1087
1084
  baseFormat: gl.DEPTH_COMPONENT,
@@ -1089,7 +1086,7 @@ var GLBuffer = /*#__PURE__*/ function() {
1089
1086
  isCompressed: false,
1090
1087
  attachment: gl.DEPTH_ATTACHMENT
1091
1088
  };
1092
- case engineCore.RenderBufferDepthFormat.DepthStencil:
1089
+ case engineCore.TextureFormat.DepthStencil:
1093
1090
  return {
1094
1091
  internalFormat: isWebGL2 ? gl.DEPTH32F_STENCIL8 : gl.DEPTH_STENCIL,
1095
1092
  baseFormat: gl.DEPTH_STENCIL,
@@ -1097,7 +1094,7 @@ var GLBuffer = /*#__PURE__*/ function() {
1097
1094
  isCompressed: false,
1098
1095
  attachment: gl.DEPTH_STENCIL_ATTACHMENT
1099
1096
  };
1100
- case engineCore.RenderBufferDepthFormat.Stencil:
1097
+ case engineCore.TextureFormat.Stencil:
1101
1098
  return {
1102
1099
  internalFormat: gl.STENCIL_INDEX8,
1103
1100
  baseFormat: gl.STENCIL_ATTACHMENT,
@@ -1105,7 +1102,7 @@ var GLBuffer = /*#__PURE__*/ function() {
1105
1102
  isCompressed: false,
1106
1103
  attachment: gl.STENCIL_ATTACHMENT
1107
1104
  };
1108
- case engineCore.RenderBufferDepthFormat.Depth16:
1105
+ case engineCore.TextureFormat.Depth16:
1109
1106
  return {
1110
1107
  internalFormat: gl.DEPTH_COMPONENT16,
1111
1108
  baseFormat: gl.DEPTH_COMPONENT,
@@ -1113,7 +1110,7 @@ var GLBuffer = /*#__PURE__*/ function() {
1113
1110
  isCompressed: false,
1114
1111
  attachment: gl.DEPTH_ATTACHMENT
1115
1112
  };
1116
- case engineCore.RenderBufferDepthFormat.Depth24Stencil8:
1113
+ case engineCore.TextureFormat.Depth24Stencil8:
1117
1114
  return {
1118
1115
  internalFormat: isWebGL2 ? gl.DEPTH24_STENCIL8 : gl.DEPTH_STENCIL,
1119
1116
  baseFormat: gl.DEPTH_STENCIL,
@@ -1121,7 +1118,7 @@ var GLBuffer = /*#__PURE__*/ function() {
1121
1118
  isCompressed: false,
1122
1119
  attachment: gl.DEPTH_STENCIL_ATTACHMENT
1123
1120
  };
1124
- case engineCore.RenderBufferDepthFormat.Depth24:
1121
+ case engineCore.TextureFormat.Depth24:
1125
1122
  return {
1126
1123
  internalFormat: gl.DEPTH_COMPONENT24,
1127
1124
  baseFormat: gl.DEPTH_COMPONENT,
@@ -1129,7 +1126,7 @@ var GLBuffer = /*#__PURE__*/ function() {
1129
1126
  isCompressed: false,
1130
1127
  attachment: gl.DEPTH_ATTACHMENT
1131
1128
  };
1132
- case engineCore.RenderBufferDepthFormat.Depth32:
1129
+ case engineCore.TextureFormat.Depth32:
1133
1130
  return {
1134
1131
  internalFormat: gl.DEPTH_COMPONENT32F,
1135
1132
  baseFormat: gl.DEPTH_COMPONENT,
@@ -1137,7 +1134,7 @@ var GLBuffer = /*#__PURE__*/ function() {
1137
1134
  isCompressed: false,
1138
1135
  attachment: gl.DEPTH_ATTACHMENT
1139
1136
  };
1140
- case engineCore.RenderBufferDepthFormat.Depth32Stencil8:
1137
+ case engineCore.TextureFormat.Depth32Stencil8:
1141
1138
  return {
1142
1139
  internalFormat: gl.DEPTH32F_STENCIL8,
1143
1140
  baseFormat: gl.DEPTH_STENCIL,
@@ -1172,6 +1169,7 @@ var GLBuffer = /*#__PURE__*/ function() {
1172
1169
  return false;
1173
1170
  }
1174
1171
  break;
1172
+ case engineCore.TextureFormat.R32G32B32A32_UInt:
1175
1173
  case engineCore.TextureFormat.Depth24:
1176
1174
  case engineCore.TextureFormat.Depth32:
1177
1175
  case engineCore.TextureFormat.Depth32Stencil8:
@@ -1206,9 +1204,9 @@ var GLBuffer = /*#__PURE__*/ function() {
1206
1204
  */ GLTexture._supportRenderBufferDepthFormat = function _supportRenderBufferDepthFormat(format, rhi) {
1207
1205
  if (!rhi.isWebGL2) {
1208
1206
  switch(format){
1209
- case engineCore.RenderBufferDepthFormat.Depth24:
1210
- case engineCore.RenderBufferDepthFormat.Depth32:
1211
- case engineCore.RenderBufferDepthFormat.Depth32Stencil8:
1207
+ case engineCore.TextureFormat.Depth24:
1208
+ case engineCore.TextureFormat.Depth32:
1209
+ case engineCore.TextureFormat.Depth32Stencil8:
1212
1210
  return false;
1213
1211
  }
1214
1212
  }
@@ -1311,6 +1309,7 @@ var GLBuffer = /*#__PURE__*/ function() {
1311
1309
  function GLRenderTarget(rhi, target) {
1312
1310
  this._MSAAColorRenderBuffers = [];
1313
1311
  this._curMipLevel = 0;
1312
+ this._curFaceIndex = undefined;
1314
1313
  this._gl = rhi.gl;
1315
1314
  this._isWebGL2 = rhi.isWebGL2;
1316
1315
  this._target = target;
@@ -1362,21 +1361,23 @@ var GLBuffer = /*#__PURE__*/ function() {
1362
1361
  var _proto = GLRenderTarget.prototype;
1363
1362
  /**
1364
1363
  * Set which face and mipLevel of the cube texture to render to.
1365
- * @param faceIndex - Cube texture face
1366
1364
  * @param mipLevel - Set mip level the data want to write
1367
- */ _proto.setRenderTargetInfo = function setRenderTargetInfo(faceIndex, mipLevel) {
1365
+ * @param faceIndex - Cube texture face
1366
+ */ _proto.activeRenderTarget = function activeRenderTarget(mipLevel, faceIndex) {
1367
+ // @todo: support MRT
1368
1368
  var _this = this, gl = _this._gl, target = _this._target;
1369
- var depthTexture = target.depthTexture;
1370
- var colorTexture = target.getColorTexture(0);
1371
- var mipChanged = mipLevel !== this._curMipLevel;
1372
1369
  gl.bindFramebuffer(gl.FRAMEBUFFER, this._frameBuffer);
1370
+ var mipChanged = mipLevel !== this._curMipLevel;
1371
+ var faceChanged = faceIndex !== this._curFaceIndex;
1372
+ var colorTexture = target.getColorTexture(0);
1373
1373
  if (colorTexture) {
1374
1374
  var isCube = _instanceof(colorTexture, engineCore.TextureCube);
1375
- if (mipChanged || isCube) {
1375
+ if (mipChanged || isCube && faceChanged) {
1376
1376
  gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, isCube ? gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex : gl.TEXTURE_2D, // @ts-ignore
1377
1377
  colorTexture._platformTexture._glTexture, mipLevel);
1378
1378
  }
1379
1379
  }
1380
+ var depthTexture = target.depthTexture;
1380
1381
  if (depthTexture) {
1381
1382
  var isCube1 = _instanceof(depthTexture, engineCore.TextureCube);
1382
1383
  if (mipChanged || isCube1) {
@@ -1393,8 +1394,10 @@ var GLBuffer = /*#__PURE__*/ function() {
1393
1394
  }
1394
1395
  }
1395
1396
  this._curMipLevel = mipLevel;
1396
- // revert current activated render target
1397
- this._activeRenderTarget();
1397
+ this._curFaceIndex = faceIndex;
1398
+ if (this._MSAAFrameBuffer) {
1399
+ gl.bindFramebuffer(gl.FRAMEBUFFER, this._MSAAFrameBuffer);
1400
+ }
1398
1401
  };
1399
1402
  /**
1400
1403
  * Blit FBO.
@@ -1432,20 +1435,6 @@ var GLBuffer = /*#__PURE__*/ function() {
1432
1435
  this._MSAAColorRenderBuffers.length = 0;
1433
1436
  this._MSAADepthRenderBuffer = null;
1434
1437
  };
1435
- /**
1436
- * Activate this RenderTarget.
1437
- * @internal
1438
- * @remarks
1439
- * If MSAA is turned on, MSAA FBO is activated, and then this._blitRenderTarget() is performed to exchange FBO.
1440
- * If MSAA is not turned on, activate the main FBO.
1441
- */ _proto._activeRenderTarget = function _activeRenderTarget() {
1442
- var gl = this._gl;
1443
- if (this._MSAAFrameBuffer) {
1444
- gl.bindFramebuffer(gl.FRAMEBUFFER, this._MSAAFrameBuffer);
1445
- } else {
1446
- gl.bindFramebuffer(gl.FRAMEBUFFER, this._frameBuffer);
1447
- }
1448
- };
1449
1438
  _proto._bindMainFBO = function _bindMainFBO() {
1450
1439
  var gl = this._gl;
1451
1440
  var isWebGL2 = this._isWebGL2;
@@ -1755,6 +1744,9 @@ exports.WebGLMode = void 0;
1755
1744
  function WebGLGraphicDevice(initializeOptions) {
1756
1745
  if (initializeOptions === void 0) initializeOptions = {};
1757
1746
  /** @internal */ this._readFrameBuffer = null;
1747
+ /** @internal */ this._mainFrameBuffer = null;
1748
+ /** @internal */ this._mainFrameWidth = 0;
1749
+ /** @internal */ this._mainFrameHeight = 0;
1758
1750
  /** @internal */ this._enableGlobalDepthBias = false;
1759
1751
  this._activeTextures = new Array(32);
1760
1752
  this._lastViewport = new engineMath.Vector4(null, null, null, null);
@@ -1917,23 +1909,30 @@ exports.WebGLMode = void 0;
1917
1909
  engineCore.Logger.error("draw primitive failed.");
1918
1910
  }
1919
1911
  };
1920
- _proto.activeRenderTarget = function activeRenderTarget(renderTarget, viewport, mipLevel) {
1921
- var gl = this._gl;
1912
+ _proto.getMainFrameBufferWidth = function getMainFrameBufferWidth() {
1913
+ return this._mainFrameWidth || this._gl.drawingBufferWidth;
1914
+ };
1915
+ _proto.getMainFrameBufferHeight = function getMainFrameBufferHeight() {
1916
+ return this._mainFrameHeight || this._gl.drawingBufferHeight;
1917
+ };
1918
+ _proto.activeRenderTarget = function activeRenderTarget(renderTarget, viewport, isFlipProjection, mipLevel, faceIndex) {
1922
1919
  var bufferWidth, bufferHeight;
1923
1920
  if (renderTarget) {
1924
- var /** @ts-ignore */ _renderTarget__platformRenderTarget;
1925
- (_renderTarget__platformRenderTarget = renderTarget._platformRenderTarget) == null ? void 0 : _renderTarget__platformRenderTarget._activeRenderTarget();
1921
+ /** @ts-ignore */ renderTarget._isContentLost = false;
1922
+ /** @ts-ignore */ var platformRenderTarget = renderTarget._platformRenderTarget;
1923
+ platformRenderTarget.activeRenderTarget(mipLevel, faceIndex);
1926
1924
  bufferWidth = renderTarget.width >> mipLevel;
1927
1925
  bufferHeight = renderTarget.height >> mipLevel;
1928
1926
  } else {
1929
- gl.bindFramebuffer(gl.FRAMEBUFFER, null);
1930
- bufferWidth = gl.drawingBufferWidth;
1931
- bufferHeight = gl.drawingBufferHeight;
1927
+ var gl = this._gl;
1928
+ gl.bindFramebuffer(gl.FRAMEBUFFER, this._mainFrameBuffer);
1929
+ bufferWidth = this.getMainFrameBufferWidth();
1930
+ bufferHeight = this.getMainFrameBufferHeight();
1932
1931
  }
1933
1932
  var width = bufferWidth * viewport.z;
1934
1933
  var height = bufferHeight * viewport.w;
1935
1934
  var x = viewport.x * bufferWidth;
1936
- var y = bufferHeight - viewport.y * bufferHeight - height;
1935
+ var y = isFlipProjection ? viewport.y * bufferHeight : bufferHeight - viewport.y * bufferHeight - height;
1937
1936
  this.viewport(x, y, width, height);
1938
1937
  this.scissor(x, y, width, height);
1939
1938
  };