@galacean/engine-rhi-webgl 2.0.0-alpha.60 → 2.0.0-alpha.61

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
@@ -406,6 +406,8 @@ var GLBuffer = /*#__PURE__*/ function() {
406
406
  * Check whether the given texture format is supported.
407
407
  */ _proto.supportsTextureFormat = function supportsTextureFormat(format) {
408
408
  switch(format){
409
+ case engineCore.TextureFormat.R16_UNorm:
410
+ return this.canIUse(engineCore.GLCapabilityType.textureNorm16);
409
411
  case engineCore.TextureFormat.BC1:
410
412
  case engineCore.TextureFormat.BC3:
411
413
  return this.canIUse(engineCore.GLCapabilityType.s3tc);
@@ -430,17 +432,21 @@ var GLBuffer = /*#__PURE__*/ function() {
430
432
  case engineCore.TextureFormat.ASTC_10x10:
431
433
  case engineCore.TextureFormat.ASTC_12x12:
432
434
  return this.canIUse(engineCore.GLCapabilityType.astc);
433
- case engineCore.TextureFormat.R8G8B8:
434
- case engineCore.TextureFormat.R8G8B8A8:
435
- case engineCore.TextureFormat.R4G4B4A4:
436
- case engineCore.TextureFormat.R5G5B5A1:
437
- case engineCore.TextureFormat.R5G6B5:
438
- case engineCore.TextureFormat.R16G16B16A16:
439
- case engineCore.TextureFormat.R32G32B32A32:
435
+ case engineCore.TextureFormat.R8G8B8_UNorm:
436
+ case engineCore.TextureFormat.R8G8B8A8_UNorm:
437
+ case engineCore.TextureFormat.R4G4B4A4_UNorm:
438
+ case engineCore.TextureFormat.R5G5B5A1_UNorm:
439
+ case engineCore.TextureFormat.R5G6B5_UNorm:
440
+ case engineCore.TextureFormat.R16G16B16A16_SFloat:
441
+ case engineCore.TextureFormat.R32G32B32A32_SFloat:
440
442
  case engineCore.TextureFormat.R32G32B32A32_UInt:
441
443
  case engineCore.TextureFormat.R11G11B10_UFloat:
442
- case engineCore.TextureFormat.R8:
443
- case engineCore.TextureFormat.R8G8:
444
+ case engineCore.TextureFormat.R16_SFloat:
445
+ case engineCore.TextureFormat.R16G16_SFloat:
446
+ case engineCore.TextureFormat.R32_SFloat:
447
+ case engineCore.TextureFormat.R32G32_SFloat:
448
+ case engineCore.TextureFormat.R8_UNorm:
449
+ case engineCore.TextureFormat.R8G8_UNorm:
444
450
  case engineCore.TextureFormat.Depth:
445
451
  case engineCore.TextureFormat.DepthStencil:
446
452
  case engineCore.TextureFormat.Depth16:
@@ -457,10 +463,13 @@ var GLBuffer = /*#__PURE__*/ function() {
457
463
  * Check whether the given texture format can be rendered to as a color attachment.
458
464
  */ _proto.supportsRenderTargetColorFormat = function supportsRenderTargetColorFormat(format) {
459
465
  switch(format){
460
- case engineCore.TextureFormat.R16G16B16A16:
466
+ case engineCore.TextureFormat.R16G16B16A16_SFloat:
461
467
  return this.canIUse(engineCore.GLCapabilityType.colorBufferHalfFloat);
462
- case engineCore.TextureFormat.R32G32B32A32:
463
- return this.canIUse(engineCore.GLCapabilityType.colorBufferFloat);
468
+ case engineCore.TextureFormat.R16_SFloat:
469
+ case engineCore.TextureFormat.R16G16_SFloat:
470
+ case engineCore.TextureFormat.R32_SFloat:
471
+ case engineCore.TextureFormat.R32G32_SFloat:
472
+ case engineCore.TextureFormat.R32G32B32A32_SFloat:
464
473
  case engineCore.TextureFormat.R11G11B10_UFloat:
465
474
  return this.canIUse(engineCore.GLCapabilityType.colorBufferFloat);
466
475
  default:
@@ -472,7 +481,8 @@ var GLBuffer = /*#__PURE__*/ function() {
472
481
  */ _proto._init = function _init() {
473
482
  var cap = this.capabilityList;
474
483
  var requireExtension = this.rhi.requireExtension.bind(this.rhi);
475
- var astc = engineCore.GLCapabilityType.astc, astc_webkit = engineCore.GLCapabilityType.astc_webkit, astc_hdr = engineCore.GLCapabilityType.astc_hdr, 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, s3tc_srgb = engineCore.GLCapabilityType.s3tc_srgb, textureFloatLinear = engineCore.GLCapabilityType.textureFloatLinear, colorBufferFloat = engineCore.GLCapabilityType.colorBufferFloat, colorBufferHalfFloat = engineCore.GLCapabilityType.colorBufferHalfFloat, textureFilterAnisotropic = engineCore.GLCapabilityType.textureFilterAnisotropic;
484
+ var astc = engineCore.GLCapabilityType.astc, astc_webkit = engineCore.GLCapabilityType.astc_webkit, astc_hdr = engineCore.GLCapabilityType.astc_hdr, 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, s3tc_srgb = engineCore.GLCapabilityType.s3tc_srgb, textureNorm16 = engineCore.GLCapabilityType.textureNorm16, textureFloatLinear = engineCore.GLCapabilityType.textureFloatLinear, colorBufferFloat = engineCore.GLCapabilityType.colorBufferFloat, colorBufferHalfFloat = engineCore.GLCapabilityType.colorBufferHalfFloat, textureFilterAnisotropic = engineCore.GLCapabilityType.textureFilterAnisotropic;
485
+ cap.set(textureNorm16, !!requireExtension(textureNorm16));
476
486
  cap.set(textureFloatLinear, !!requireExtension(textureFloatLinear));
477
487
  cap.set(colorBufferFloat, !!requireExtension(colorBufferFloat));
478
488
  cap.set(colorBufferHalfFloat, !!requireExtension(colorBufferFloat) || !!requireExtension(colorBufferHalfFloat));
@@ -769,7 +779,12 @@ var GLBuffer = /*#__PURE__*/ function() {
769
779
  var texture = this._texture;
770
780
  var mipmap = texture._mipmap;
771
781
  if (!engineCore.TextureUtils.supportGenerateMipmaps(texture.format, mipmap, texture.isSRGBColorSpace)) {
772
- engineCore.Logger.warn("Auto-generating mipmaps for sRGB textures is only supported in [WebGL2 + R8G8B8A8], you must generate mipmaps manually.");
782
+ engineCore.Logger.warn("Auto-generating mipmaps for sRGB textures is only supported in [WebGL2 + R8G8B8A8_UNorm], you must generate mipmaps manually.");
783
+ return;
784
+ }
785
+ // WebGL2 generateMipmap requires the format to be both color-renderable and texture-filterable
786
+ if (!this._rhi.supportsRenderTargetColorFormat(texture.format) || this._isFloat32Format(texture.format) && !this._rhi.canIUse(engineCore.GLCapabilityType.textureFloatLinear)) {
787
+ engineCore.Logger.warn("Auto-generating mipmaps is not supported for TextureFormat." + engineCore.TextureFormat[texture.format] + " on this device.");
773
788
  return;
774
789
  }
775
790
  // @todo (1x1).generateMipmap() will flash back in uc.
@@ -822,7 +837,8 @@ var GLBuffer = /*#__PURE__*/ function() {
822
837
  * @param mipLevel - Set mip level the data want to get from
823
838
  */ _proto._getPixelBuffer = function _getPixelBuffer(face, x, y, width, height, mipLevel, out) {
824
839
  var gl = this._gl;
825
- var _this__formatDetail = this._formatDetail, baseFormat = _this__formatDetail.baseFormat, dataType = _this__formatDetail.dataType, readFormat = _this__formatDetail.readFormat, alignment = _this__formatDetail.alignment;
840
+ var _this__formatDetail = this._formatDetail, dataType = _this__formatDetail.dataType, readType = _this__formatDetail.readType, alignment = _this__formatDetail.alignment;
841
+ var readFormat = this._getReadFormat();
826
842
  gl.bindFramebuffer(gl.FRAMEBUFFER, this._getReadFrameBuffer());
827
843
  if (face != null) {
828
844
  gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_CUBE_MAP_POSITIVE_X + face, this._glTexture, mipLevel);
@@ -830,9 +846,17 @@ var GLBuffer = /*#__PURE__*/ function() {
830
846
  gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this._glTexture, mipLevel);
831
847
  }
832
848
  gl.pixelStorei(gl.PACK_ALIGNMENT, alignment);
833
- gl.readPixels(x, y, width, height, readFormat != null ? readFormat : baseFormat, dataType, out);
849
+ gl.readPixels(x, y, width, height, readFormat, readType != null ? readType : dataType, out);
834
850
  gl.bindFramebuffer(gl.FRAMEBUFFER, null);
835
851
  };
852
+ _proto._getReadFormat = function _getReadFormat() {
853
+ var format = this._texture.format;
854
+ if (!this._rhi.supportsRenderTargetColorFormat(format)) {
855
+ throw new Error("Reading pixels from TextureFormat." + engineCore.TextureFormat[format] + " requires color-renderable support");
856
+ }
857
+ var _this__formatDetail = this._formatDetail, readFormat = _this__formatDetail.readFormat, baseFormat = _this__formatDetail.baseFormat;
858
+ return readFormat != null ? readFormat : baseFormat;
859
+ };
836
860
  _proto._getReadFrameBuffer = function _getReadFrameBuffer() {
837
861
  var frameBuffer = this._rhi._readFrameBuffer;
838
862
  if (!frameBuffer) {
@@ -851,6 +875,9 @@ var GLBuffer = /*#__PURE__*/ function() {
851
875
  texture._isSRGBColorSpace = false;
852
876
  }
853
877
  };
878
+ _proto._isFloat32Format = function _isFloat32Format(format) {
879
+ return format === engineCore.TextureFormat.R32_SFloat || format === engineCore.TextureFormat.R32G32_SFloat || format === engineCore.TextureFormat.R32G32B32A32_SFloat;
880
+ };
854
881
  _proto._setWrapMode = function _setWrapMode(value, pname) {
855
882
  var gl = this._gl;
856
883
  var target = this._target;
@@ -871,7 +898,7 @@ var GLBuffer = /*#__PURE__*/ function() {
871
898
  * @internal
872
899
  */ GLTexture._getFormatDetail = function _getFormatDetail(format, isSRGBColorSpace, gl) {
873
900
  switch(format){
874
- case engineCore.TextureFormat.R8G8B8:
901
+ case engineCore.TextureFormat.R8G8B8_UNorm:
875
902
  return {
876
903
  internalFormat: isSRGBColorSpace ? gl.SRGB8 : gl.RGB8,
877
904
  baseFormat: gl.RGB,
@@ -880,7 +907,7 @@ var GLBuffer = /*#__PURE__*/ function() {
880
907
  isCompressed: false,
881
908
  alignment: 1
882
909
  };
883
- case engineCore.TextureFormat.R8G8B8A8:
910
+ case engineCore.TextureFormat.R8G8B8A8_UNorm:
884
911
  return {
885
912
  internalFormat: isSRGBColorSpace ? gl.SRGB8_ALPHA8 : gl.RGBA8,
886
913
  baseFormat: gl.RGBA,
@@ -889,7 +916,7 @@ var GLBuffer = /*#__PURE__*/ function() {
889
916
  isCompressed: false,
890
917
  alignment: 4
891
918
  };
892
- case engineCore.TextureFormat.R4G4B4A4:
919
+ case engineCore.TextureFormat.R4G4B4A4_UNorm:
893
920
  return {
894
921
  internalFormat: gl.RGBA4,
895
922
  baseFormat: gl.RGBA,
@@ -897,7 +924,7 @@ var GLBuffer = /*#__PURE__*/ function() {
897
924
  isCompressed: false,
898
925
  alignment: 2
899
926
  };
900
- case engineCore.TextureFormat.R5G5B5A1:
927
+ case engineCore.TextureFormat.R5G5B5A1_UNorm:
901
928
  return {
902
929
  internalFormat: gl.RGB5_A1,
903
930
  baseFormat: gl.RGBA,
@@ -905,7 +932,7 @@ var GLBuffer = /*#__PURE__*/ function() {
905
932
  isCompressed: false,
906
933
  alignment: 2
907
934
  };
908
- case engineCore.TextureFormat.R5G6B5:
935
+ case engineCore.TextureFormat.R5G6B5_UNorm:
909
936
  return {
910
937
  internalFormat: gl.RGB565,
911
938
  baseFormat: gl.RGB,
@@ -913,15 +940,17 @@ var GLBuffer = /*#__PURE__*/ function() {
913
940
  isCompressed: false,
914
941
  alignment: 2
915
942
  };
916
- case engineCore.TextureFormat.R16G16B16A16:
943
+ case engineCore.TextureFormat.R16G16B16A16_SFloat:
917
944
  return {
918
945
  internalFormat: gl.RGBA16F,
919
946
  baseFormat: gl.RGBA,
947
+ readFormat: gl.RGBA,
948
+ readType: gl.FLOAT,
920
949
  dataType: gl.HALF_FLOAT,
921
950
  isCompressed: false,
922
951
  alignment: 8
923
952
  };
924
- case engineCore.TextureFormat.R32G32B32A32:
953
+ case engineCore.TextureFormat.R32G32B32A32_SFloat:
925
954
  return {
926
955
  internalFormat: gl.RGBA32F,
927
956
  baseFormat: gl.RGBA,
@@ -929,6 +958,36 @@ var GLBuffer = /*#__PURE__*/ function() {
929
958
  isCompressed: false,
930
959
  alignment: 8
931
960
  };
961
+ case engineCore.TextureFormat.R16_UNorm:
962
+ return {
963
+ internalFormat: 0x822a,
964
+ baseFormat: gl.RED,
965
+ readFormat: gl.RGBA,
966
+ dataType: gl.UNSIGNED_SHORT,
967
+ isCompressed: false,
968
+ alignment: 2
969
+ };
970
+ case engineCore.TextureFormat.R16_SFloat:
971
+ case engineCore.TextureFormat.R16G16_SFloat:
972
+ return {
973
+ internalFormat: format === engineCore.TextureFormat.R16_SFloat ? gl.R16F : gl.RG16F,
974
+ baseFormat: format === engineCore.TextureFormat.R16_SFloat ? gl.RED : gl.RG,
975
+ readFormat: gl.RGBA,
976
+ readType: gl.FLOAT,
977
+ dataType: gl.HALF_FLOAT,
978
+ isCompressed: false,
979
+ alignment: 2
980
+ };
981
+ case engineCore.TextureFormat.R32_SFloat:
982
+ case engineCore.TextureFormat.R32G32_SFloat:
983
+ return {
984
+ internalFormat: format === engineCore.TextureFormat.R32_SFloat ? gl.R32F : gl.RG32F,
985
+ baseFormat: format === engineCore.TextureFormat.R32_SFloat ? gl.RED : gl.RG,
986
+ readFormat: gl.RGBA,
987
+ dataType: gl.FLOAT,
988
+ isCompressed: false,
989
+ alignment: 4
990
+ };
932
991
  case engineCore.TextureFormat.R11G11B10_UFloat:
933
992
  return {
934
993
  internalFormat: gl.R11F_G11F_B10F,
@@ -946,7 +1005,7 @@ var GLBuffer = /*#__PURE__*/ function() {
946
1005
  isCompressed: false,
947
1006
  alignment: 8
948
1007
  };
949
- case engineCore.TextureFormat.R8:
1008
+ case engineCore.TextureFormat.R8_UNorm:
950
1009
  return {
951
1010
  internalFormat: gl.R8,
952
1011
  baseFormat: gl.RED,
@@ -954,7 +1013,7 @@ var GLBuffer = /*#__PURE__*/ function() {
954
1013
  isCompressed: false,
955
1014
  alignment: 1
956
1015
  };
957
- case engineCore.TextureFormat.R8G8:
1016
+ case engineCore.TextureFormat.R8G8_UNorm:
958
1017
  return {
959
1018
  internalFormat: gl.RG8,
960
1019
  baseFormat: gl.RG,
@@ -1210,7 +1269,10 @@ var GLBuffer = /*#__PURE__*/ function() {
1210
1269
  */ function set(value) {
1211
1270
  var gl = this._gl;
1212
1271
  var target = this._target;
1213
- var _mipmap = this._texture._mipmap;
1272
+ var _this__texture = this._texture, _mipmap = _this__texture._mipmap, format = _this__texture.format;
1273
+ if (value !== engineCore.TextureFilterMode.Point && this._isFloat32Format(format) && !this._rhi.canIUse(engineCore.GLCapabilityType.textureFloatLinear)) {
1274
+ value = engineCore.TextureFilterMode.Point;
1275
+ }
1214
1276
  this._bind();
1215
1277
  switch(value){
1216
1278
  case engineCore.TextureFilterMode.Point:
@@ -1296,8 +1358,8 @@ var GLBuffer = /*#__PURE__*/ function() {
1296
1358
  if (!rhi.supportsRenderTargetColorFormat(format)) {
1297
1359
  throw new Error("TextureFormat is not supported:" + engineCore.TextureFormat[format] + " in RenderTarget");
1298
1360
  }
1299
- if (isSRGBColorSpace && format === engineCore.TextureFormat.R8G8B8) {
1300
- throw new Error("If you want to use sRGB color space, only R8G8B8A8 format is supported in RenderTarget");
1361
+ if (isSRGBColorSpace && format === engineCore.TextureFormat.R8G8B8_UNorm) {
1362
+ throw new Error("If you want to use sRGB color space, only R8G8B8A8_UNorm format is supported in RenderTarget");
1301
1363
  }
1302
1364
  }
1303
1365
  if (_colorTextures.some(function(v) {
@@ -1599,10 +1661,12 @@ var GLBuffer = /*#__PURE__*/ function() {
1599
1661
  if (formatDetail.isCompressed) {
1600
1662
  throw new Error("Unable to read compressed texture");
1601
1663
  }
1664
+ var readFormat = this._getReadFormat();
1602
1665
  gl.pixelStorei(gl.PACK_ALIGNMENT, formatDetail.alignment);
1603
1666
  gl.bindFramebuffer(gl.FRAMEBUFFER, this._getReadFrameBuffer());
1604
1667
  gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, this._glTexture, mipLevel, elementIndex);
1605
- gl.readPixels(x, y, width, height, formatDetail.baseFormat, formatDetail.dataType, out);
1668
+ var _formatDetail_readType;
1669
+ gl.readPixels(x, y, width, height, readFormat, (_formatDetail_readType = formatDetail.readType) != null ? _formatDetail_readType : formatDetail.dataType, out);
1606
1670
  gl.bindFramebuffer(gl.FRAMEBUFFER, null);
1607
1671
  };
1608
1672
  _proto._validate = function _validate(texture) {