@galacean/engine-rhi-webgl 1.2.0-alpha.8 → 1.2.0-beta.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/dist/main.js CHANGED
@@ -350,7 +350,7 @@ var GLBuffer = /*#__PURE__*/ function() {
350
350
  var cap = this.capabilityList;
351
351
  var isWebGL2 = this.rhi.isWebGL2;
352
352
  var requireExtension = this.rhi.requireExtension.bind(this.rhi);
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, 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;
354
354
  cap.set(shaderVertexID, isWebGL2);
355
355
  cap.set(standardDerivatives, isWebGL2 || !!requireExtension(standardDerivatives));
356
356
  cap.set(shaderTextureLod, isWebGL2 || !!requireExtension(shaderTextureLod));
@@ -360,6 +360,7 @@ var GLBuffer = /*#__PURE__*/ function() {
360
360
  cap.set(instancedArrays, isWebGL2 || !!requireExtension(instancedArrays));
361
361
  cap.set(multipleSample, isWebGL2);
362
362
  cap.set(drawBuffers, isWebGL2 || !!requireExtension(drawBuffers));
363
+ cap.set(blendMinMax, isWebGL2 || !!requireExtension(blendMinMax));
363
364
  cap.set(textureFloat, isWebGL2 || !!requireExtension(textureFloat));
364
365
  cap.set(textureHalfFloat, isWebGL2 || !!requireExtension(textureHalfFloat));
365
366
  cap.set(textureFloatLinear, !!requireExtension(textureFloatLinear));
@@ -400,9 +401,13 @@ var GLBuffer = /*#__PURE__*/ function() {
400
401
  }
401
402
  };
402
403
  _proto._compatibleAllInterface = function _compatibleAllInterface() {
403
- 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;
404
+ 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;
404
405
  var isWebGL2 = this.rhi.isWebGL2;
405
406
  if (!isWebGL2) {
407
+ this._compatibleInterface(blendMinMax, {
408
+ MIN: "MIN_EXT",
409
+ MAX: "MAX_EXT"
410
+ });
406
411
  this._compatibleInterface(depthTexture, {
407
412
  UNSIGNED_INT_24_8: "UNSIGNED_INT_24_8_WEBGL"
408
413
  });
@@ -915,6 +920,13 @@ var GLBuffer = /*#__PURE__*/ function() {
915
920
  dataType: gl.FLOAT,
916
921
  isCompressed: false
917
922
  };
923
+ case engineCore.TextureFormat.R32G32B32A32_UInt:
924
+ return {
925
+ internalFormat: isWebGL2 ? gl.RGBA32UI : gl.NONE,
926
+ baseFormat: gl.RGBA_INTEGER,
927
+ dataType: gl.UNSIGNED_INT,
928
+ isCompressed: false
929
+ };
918
930
  case engineCore.TextureFormat.BC1:
919
931
  return {
920
932
  internalFormat: exports.GLCompressedTextureInternalFormat.RGB_S3TC_DXT1_EXT,
@@ -1065,7 +1077,7 @@ var GLBuffer = /*#__PURE__*/ function() {
1065
1077
  * @internal
1066
1078
  */ GLTexture._getRenderBufferDepthFormatDetail = function _getRenderBufferDepthFormatDetail(format, gl, isWebGL2) {
1067
1079
  switch(format){
1068
- case engineCore.RenderBufferDepthFormat.Depth:
1080
+ case engineCore.TextureFormat.Depth:
1069
1081
  return {
1070
1082
  internalFormat: isWebGL2 ? gl.DEPTH_COMPONENT32F : gl.DEPTH_COMPONENT16,
1071
1083
  baseFormat: gl.DEPTH_COMPONENT,
@@ -1073,7 +1085,7 @@ var GLBuffer = /*#__PURE__*/ function() {
1073
1085
  isCompressed: false,
1074
1086
  attachment: gl.DEPTH_ATTACHMENT
1075
1087
  };
1076
- case engineCore.RenderBufferDepthFormat.DepthStencil:
1088
+ case engineCore.TextureFormat.DepthStencil:
1077
1089
  return {
1078
1090
  internalFormat: isWebGL2 ? gl.DEPTH32F_STENCIL8 : gl.DEPTH_STENCIL,
1079
1091
  baseFormat: gl.DEPTH_STENCIL,
@@ -1081,7 +1093,7 @@ var GLBuffer = /*#__PURE__*/ function() {
1081
1093
  isCompressed: false,
1082
1094
  attachment: gl.DEPTH_STENCIL_ATTACHMENT
1083
1095
  };
1084
- case engineCore.RenderBufferDepthFormat.Stencil:
1096
+ case engineCore.TextureFormat.Stencil:
1085
1097
  return {
1086
1098
  internalFormat: gl.STENCIL_INDEX8,
1087
1099
  baseFormat: gl.STENCIL_ATTACHMENT,
@@ -1089,7 +1101,7 @@ var GLBuffer = /*#__PURE__*/ function() {
1089
1101
  isCompressed: false,
1090
1102
  attachment: gl.STENCIL_ATTACHMENT
1091
1103
  };
1092
- case engineCore.RenderBufferDepthFormat.Depth16:
1104
+ case engineCore.TextureFormat.Depth16:
1093
1105
  return {
1094
1106
  internalFormat: gl.DEPTH_COMPONENT16,
1095
1107
  baseFormat: gl.DEPTH_COMPONENT,
@@ -1097,7 +1109,7 @@ var GLBuffer = /*#__PURE__*/ function() {
1097
1109
  isCompressed: false,
1098
1110
  attachment: gl.DEPTH_ATTACHMENT
1099
1111
  };
1100
- case engineCore.RenderBufferDepthFormat.Depth24Stencil8:
1112
+ case engineCore.TextureFormat.Depth24Stencil8:
1101
1113
  return {
1102
1114
  internalFormat: isWebGL2 ? gl.DEPTH24_STENCIL8 : gl.DEPTH_STENCIL,
1103
1115
  baseFormat: gl.DEPTH_STENCIL,
@@ -1105,7 +1117,7 @@ var GLBuffer = /*#__PURE__*/ function() {
1105
1117
  isCompressed: false,
1106
1118
  attachment: gl.DEPTH_STENCIL_ATTACHMENT
1107
1119
  };
1108
- case engineCore.RenderBufferDepthFormat.Depth24:
1120
+ case engineCore.TextureFormat.Depth24:
1109
1121
  return {
1110
1122
  internalFormat: gl.DEPTH_COMPONENT24,
1111
1123
  baseFormat: gl.DEPTH_COMPONENT,
@@ -1113,7 +1125,7 @@ var GLBuffer = /*#__PURE__*/ function() {
1113
1125
  isCompressed: false,
1114
1126
  attachment: gl.DEPTH_ATTACHMENT
1115
1127
  };
1116
- case engineCore.RenderBufferDepthFormat.Depth32:
1128
+ case engineCore.TextureFormat.Depth32:
1117
1129
  return {
1118
1130
  internalFormat: gl.DEPTH_COMPONENT32F,
1119
1131
  baseFormat: gl.DEPTH_COMPONENT,
@@ -1121,7 +1133,7 @@ var GLBuffer = /*#__PURE__*/ function() {
1121
1133
  isCompressed: false,
1122
1134
  attachment: gl.DEPTH_ATTACHMENT
1123
1135
  };
1124
- case engineCore.RenderBufferDepthFormat.Depth32Stencil8:
1136
+ case engineCore.TextureFormat.Depth32Stencil8:
1125
1137
  return {
1126
1138
  internalFormat: gl.DEPTH32F_STENCIL8,
1127
1139
  baseFormat: gl.DEPTH_STENCIL,
@@ -1156,6 +1168,7 @@ var GLBuffer = /*#__PURE__*/ function() {
1156
1168
  return false;
1157
1169
  }
1158
1170
  break;
1171
+ case engineCore.TextureFormat.R32G32B32A32_UInt:
1159
1172
  case engineCore.TextureFormat.Depth24:
1160
1173
  case engineCore.TextureFormat.Depth32:
1161
1174
  case engineCore.TextureFormat.Depth32Stencil8:
@@ -1190,9 +1203,9 @@ var GLBuffer = /*#__PURE__*/ function() {
1190
1203
  */ GLTexture._supportRenderBufferDepthFormat = function _supportRenderBufferDepthFormat(format, rhi) {
1191
1204
  if (!rhi.isWebGL2) {
1192
1205
  switch(format){
1193
- case engineCore.RenderBufferDepthFormat.Depth24:
1194
- case engineCore.RenderBufferDepthFormat.Depth32:
1195
- case engineCore.RenderBufferDepthFormat.Depth32Stencil8:
1206
+ case engineCore.TextureFormat.Depth24:
1207
+ case engineCore.TextureFormat.Depth32:
1208
+ case engineCore.TextureFormat.Depth32Stencil8:
1196
1209
  return false;
1197
1210
  }
1198
1211
  }
@@ -1295,6 +1308,7 @@ var GLBuffer = /*#__PURE__*/ function() {
1295
1308
  function GLRenderTarget(rhi, target) {
1296
1309
  this._MSAAColorRenderBuffers = [];
1297
1310
  this._curMipLevel = 0;
1311
+ this._curFaceIndex = undefined;
1298
1312
  this._gl = rhi.gl;
1299
1313
  this._isWebGL2 = rhi.isWebGL2;
1300
1314
  this._target = target;
@@ -1346,21 +1360,23 @@ var GLBuffer = /*#__PURE__*/ function() {
1346
1360
  var _proto = GLRenderTarget.prototype;
1347
1361
  /**
1348
1362
  * Set which face and mipLevel of the cube texture to render to.
1349
- * @param faceIndex - Cube texture face
1350
1363
  * @param mipLevel - Set mip level the data want to write
1351
- */ _proto.setRenderTargetInfo = function setRenderTargetInfo(faceIndex, mipLevel) {
1364
+ * @param faceIndex - Cube texture face
1365
+ */ _proto.activeRenderTarget = function activeRenderTarget(mipLevel, faceIndex) {
1366
+ // @todo: support MRT
1352
1367
  var _this = this, gl = _this._gl, target = _this._target;
1353
- var depthTexture = target.depthTexture;
1354
- var colorTexture = target.getColorTexture(0);
1355
- var mipChanged = mipLevel !== this._curMipLevel;
1356
1368
  gl.bindFramebuffer(gl.FRAMEBUFFER, this._frameBuffer);
1369
+ var mipChanged = mipLevel !== this._curMipLevel;
1370
+ var faceChanged = faceIndex !== this._curFaceIndex;
1371
+ var colorTexture = target.getColorTexture(0);
1357
1372
  if (colorTexture) {
1358
1373
  var isCube = _instanceof(colorTexture, engineCore.TextureCube);
1359
- if (mipChanged || isCube) {
1374
+ if (mipChanged || isCube && faceChanged) {
1360
1375
  gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, isCube ? gl.TEXTURE_CUBE_MAP_POSITIVE_X + faceIndex : gl.TEXTURE_2D, // @ts-ignore
1361
1376
  colorTexture._platformTexture._glTexture, mipLevel);
1362
1377
  }
1363
1378
  }
1379
+ var depthTexture = target.depthTexture;
1364
1380
  if (depthTexture) {
1365
1381
  var isCube1 = _instanceof(depthTexture, engineCore.TextureCube);
1366
1382
  if (mipChanged || isCube1) {
@@ -1377,8 +1393,10 @@ var GLBuffer = /*#__PURE__*/ function() {
1377
1393
  }
1378
1394
  }
1379
1395
  this._curMipLevel = mipLevel;
1380
- // revert current activated render target
1381
- this._activeRenderTarget();
1396
+ this._curFaceIndex = faceIndex;
1397
+ if (this._MSAAFrameBuffer) {
1398
+ gl.bindFramebuffer(gl.FRAMEBUFFER, this._MSAAFrameBuffer);
1399
+ }
1382
1400
  };
1383
1401
  /**
1384
1402
  * Blit FBO.
@@ -1416,20 +1434,6 @@ var GLBuffer = /*#__PURE__*/ function() {
1416
1434
  this._MSAAColorRenderBuffers.length = 0;
1417
1435
  this._MSAADepthRenderBuffer = null;
1418
1436
  };
1419
- /**
1420
- * Activate this RenderTarget.
1421
- * @internal
1422
- * @remarks
1423
- * If MSAA is turned on, MSAA FBO is activated, and then this._blitRenderTarget() is performed to exchange FBO.
1424
- * If MSAA is not turned on, activate the main FBO.
1425
- */ _proto._activeRenderTarget = function _activeRenderTarget() {
1426
- var gl = this._gl;
1427
- if (this._MSAAFrameBuffer) {
1428
- gl.bindFramebuffer(gl.FRAMEBUFFER, this._MSAAFrameBuffer);
1429
- } else {
1430
- gl.bindFramebuffer(gl.FRAMEBUFFER, this._frameBuffer);
1431
- }
1432
- };
1433
1437
  _proto._bindMainFBO = function _bindMainFBO() {
1434
1438
  var gl = this._gl;
1435
1439
  var isWebGL2 = this._isWebGL2;
@@ -1904,23 +1908,30 @@ exports.WebGLMode = void 0;
1904
1908
  engineCore.Logger.error("draw primitive failed.");
1905
1909
  }
1906
1910
  };
1907
- _proto.activeRenderTarget = function activeRenderTarget(renderTarget, viewport, mipLevel) {
1908
- var gl = this._gl;
1911
+ _proto.getMainFrameBufferWidth = function getMainFrameBufferWidth() {
1912
+ return this._mainFrameWidth || this._gl.drawingBufferWidth;
1913
+ };
1914
+ _proto.getMainFrameBufferHeight = function getMainFrameBufferHeight() {
1915
+ return this._mainFrameHeight || this._gl.drawingBufferHeight;
1916
+ };
1917
+ _proto.activeRenderTarget = function activeRenderTarget(renderTarget, viewport, isFlipProjection, mipLevel, faceIndex) {
1909
1918
  var bufferWidth, bufferHeight;
1910
1919
  if (renderTarget) {
1911
- var /** @ts-ignore */ _renderTarget__platformRenderTarget;
1912
- (_renderTarget__platformRenderTarget = renderTarget._platformRenderTarget) == null ? void 0 : _renderTarget__platformRenderTarget._activeRenderTarget();
1920
+ /** @ts-ignore */ renderTarget._isContentLost = false;
1921
+ /** @ts-ignore */ var platformRenderTarget = renderTarget._platformRenderTarget;
1922
+ platformRenderTarget.activeRenderTarget(mipLevel, faceIndex);
1913
1923
  bufferWidth = renderTarget.width >> mipLevel;
1914
1924
  bufferHeight = renderTarget.height >> mipLevel;
1915
1925
  } else {
1926
+ var gl = this._gl;
1916
1927
  gl.bindFramebuffer(gl.FRAMEBUFFER, this._mainFrameBuffer);
1917
- bufferWidth = this._mainFrameWidth || gl.drawingBufferWidth;
1918
- bufferHeight = this._mainFrameHeight || gl.drawingBufferHeight;
1928
+ bufferWidth = this.getMainFrameBufferWidth();
1929
+ bufferHeight = this.getMainFrameBufferHeight();
1919
1930
  }
1920
1931
  var width = bufferWidth * viewport.z;
1921
1932
  var height = bufferHeight * viewport.w;
1922
1933
  var x = viewport.x * bufferWidth;
1923
- var y = bufferHeight - viewport.y * bufferHeight - height;
1934
+ var y = isFlipProjection ? viewport.y * bufferHeight : bufferHeight - viewport.y * bufferHeight - height;
1924
1935
  this.viewport(x, y, width, height);
1925
1936
  this.scissor(x, y, width, height);
1926
1937
  };