@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 +93 -29
- package/dist/main.js.map +1 -1
- package/dist/module.js +93 -29
- package/dist/module.js.map +1 -1
- package/package.json +3 -3
- package/types/GLTexture.d.ts +2 -0
- package/types/type.d.ts +1 -0
package/dist/module.js
CHANGED
|
@@ -402,6 +402,8 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
402
402
|
* Check whether the given texture format is supported.
|
|
403
403
|
*/ _proto.supportsTextureFormat = function supportsTextureFormat(format) {
|
|
404
404
|
switch(format){
|
|
405
|
+
case TextureFormat.R16_UNorm:
|
|
406
|
+
return this.canIUse(GLCapabilityType.textureNorm16);
|
|
405
407
|
case TextureFormat.BC1:
|
|
406
408
|
case TextureFormat.BC3:
|
|
407
409
|
return this.canIUse(GLCapabilityType.s3tc);
|
|
@@ -426,17 +428,21 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
426
428
|
case TextureFormat.ASTC_10x10:
|
|
427
429
|
case TextureFormat.ASTC_12x12:
|
|
428
430
|
return this.canIUse(GLCapabilityType.astc);
|
|
429
|
-
case TextureFormat.
|
|
430
|
-
case TextureFormat.
|
|
431
|
-
case TextureFormat.
|
|
432
|
-
case TextureFormat.
|
|
433
|
-
case TextureFormat.
|
|
434
|
-
case TextureFormat.
|
|
435
|
-
case TextureFormat.
|
|
431
|
+
case TextureFormat.R8G8B8_UNorm:
|
|
432
|
+
case TextureFormat.R8G8B8A8_UNorm:
|
|
433
|
+
case TextureFormat.R4G4B4A4_UNorm:
|
|
434
|
+
case TextureFormat.R5G5B5A1_UNorm:
|
|
435
|
+
case TextureFormat.R5G6B5_UNorm:
|
|
436
|
+
case TextureFormat.R16G16B16A16_SFloat:
|
|
437
|
+
case TextureFormat.R32G32B32A32_SFloat:
|
|
436
438
|
case TextureFormat.R32G32B32A32_UInt:
|
|
437
439
|
case TextureFormat.R11G11B10_UFloat:
|
|
438
|
-
case TextureFormat.
|
|
439
|
-
case TextureFormat.
|
|
440
|
+
case TextureFormat.R16_SFloat:
|
|
441
|
+
case TextureFormat.R16G16_SFloat:
|
|
442
|
+
case TextureFormat.R32_SFloat:
|
|
443
|
+
case TextureFormat.R32G32_SFloat:
|
|
444
|
+
case TextureFormat.R8_UNorm:
|
|
445
|
+
case TextureFormat.R8G8_UNorm:
|
|
440
446
|
case TextureFormat.Depth:
|
|
441
447
|
case TextureFormat.DepthStencil:
|
|
442
448
|
case TextureFormat.Depth16:
|
|
@@ -453,10 +459,13 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
453
459
|
* Check whether the given texture format can be rendered to as a color attachment.
|
|
454
460
|
*/ _proto.supportsRenderTargetColorFormat = function supportsRenderTargetColorFormat(format) {
|
|
455
461
|
switch(format){
|
|
456
|
-
case TextureFormat.
|
|
462
|
+
case TextureFormat.R16G16B16A16_SFloat:
|
|
457
463
|
return this.canIUse(GLCapabilityType.colorBufferHalfFloat);
|
|
458
|
-
case TextureFormat.
|
|
459
|
-
|
|
464
|
+
case TextureFormat.R16_SFloat:
|
|
465
|
+
case TextureFormat.R16G16_SFloat:
|
|
466
|
+
case TextureFormat.R32_SFloat:
|
|
467
|
+
case TextureFormat.R32G32_SFloat:
|
|
468
|
+
case TextureFormat.R32G32B32A32_SFloat:
|
|
460
469
|
case TextureFormat.R11G11B10_UFloat:
|
|
461
470
|
return this.canIUse(GLCapabilityType.colorBufferFloat);
|
|
462
471
|
default:
|
|
@@ -468,7 +477,8 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
468
477
|
*/ _proto._init = function _init() {
|
|
469
478
|
var cap = this.capabilityList;
|
|
470
479
|
var requireExtension = this.rhi.requireExtension.bind(this.rhi);
|
|
471
|
-
var astc = GLCapabilityType.astc, astc_webkit = GLCapabilityType.astc_webkit, astc_hdr = GLCapabilityType.astc_hdr, etc = GLCapabilityType.etc, etc_webkit = GLCapabilityType.etc_webkit, etc1 = GLCapabilityType.etc1, etc1_webkit = GLCapabilityType.etc1_webkit, pvrtc = GLCapabilityType.pvrtc, pvrtc_webkit = GLCapabilityType.pvrtc_webkit, s3tc = GLCapabilityType.s3tc, s3tc_webkit = GLCapabilityType.s3tc_webkit, bptc = GLCapabilityType.bptc, s3tc_srgb = GLCapabilityType.s3tc_srgb, textureFloatLinear = GLCapabilityType.textureFloatLinear, colorBufferFloat = GLCapabilityType.colorBufferFloat, colorBufferHalfFloat = GLCapabilityType.colorBufferHalfFloat, textureFilterAnisotropic = GLCapabilityType.textureFilterAnisotropic;
|
|
480
|
+
var astc = GLCapabilityType.astc, astc_webkit = GLCapabilityType.astc_webkit, astc_hdr = GLCapabilityType.astc_hdr, etc = GLCapabilityType.etc, etc_webkit = GLCapabilityType.etc_webkit, etc1 = GLCapabilityType.etc1, etc1_webkit = GLCapabilityType.etc1_webkit, pvrtc = GLCapabilityType.pvrtc, pvrtc_webkit = GLCapabilityType.pvrtc_webkit, s3tc = GLCapabilityType.s3tc, s3tc_webkit = GLCapabilityType.s3tc_webkit, bptc = GLCapabilityType.bptc, s3tc_srgb = GLCapabilityType.s3tc_srgb, textureNorm16 = GLCapabilityType.textureNorm16, textureFloatLinear = GLCapabilityType.textureFloatLinear, colorBufferFloat = GLCapabilityType.colorBufferFloat, colorBufferHalfFloat = GLCapabilityType.colorBufferHalfFloat, textureFilterAnisotropic = GLCapabilityType.textureFilterAnisotropic;
|
|
481
|
+
cap.set(textureNorm16, !!requireExtension(textureNorm16));
|
|
472
482
|
cap.set(textureFloatLinear, !!requireExtension(textureFloatLinear));
|
|
473
483
|
cap.set(colorBufferFloat, !!requireExtension(colorBufferFloat));
|
|
474
484
|
cap.set(colorBufferHalfFloat, !!requireExtension(colorBufferFloat) || !!requireExtension(colorBufferHalfFloat));
|
|
@@ -765,7 +775,12 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
765
775
|
var texture = this._texture;
|
|
766
776
|
var mipmap = texture._mipmap;
|
|
767
777
|
if (!TextureUtils.supportGenerateMipmaps(texture.format, mipmap, texture.isSRGBColorSpace)) {
|
|
768
|
-
Logger.warn("Auto-generating mipmaps for sRGB textures is only supported in [WebGL2 +
|
|
778
|
+
Logger.warn("Auto-generating mipmaps for sRGB textures is only supported in [WebGL2 + R8G8B8A8_UNorm], you must generate mipmaps manually.");
|
|
779
|
+
return;
|
|
780
|
+
}
|
|
781
|
+
// WebGL2 generateMipmap requires the format to be both color-renderable and texture-filterable
|
|
782
|
+
if (!this._rhi.supportsRenderTargetColorFormat(texture.format) || this._isFloat32Format(texture.format) && !this._rhi.canIUse(GLCapabilityType.textureFloatLinear)) {
|
|
783
|
+
Logger.warn("Auto-generating mipmaps is not supported for TextureFormat." + TextureFormat[texture.format] + " on this device.");
|
|
769
784
|
return;
|
|
770
785
|
}
|
|
771
786
|
// @todo (1x1).generateMipmap() will flash back in uc.
|
|
@@ -818,7 +833,8 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
818
833
|
* @param mipLevel - Set mip level the data want to get from
|
|
819
834
|
*/ _proto._getPixelBuffer = function _getPixelBuffer(face, x, y, width, height, mipLevel, out) {
|
|
820
835
|
var gl = this._gl;
|
|
821
|
-
var _this__formatDetail = this._formatDetail,
|
|
836
|
+
var _this__formatDetail = this._formatDetail, dataType = _this__formatDetail.dataType, readType = _this__formatDetail.readType, alignment = _this__formatDetail.alignment;
|
|
837
|
+
var readFormat = this._getReadFormat();
|
|
822
838
|
gl.bindFramebuffer(gl.FRAMEBUFFER, this._getReadFrameBuffer());
|
|
823
839
|
if (face != null) {
|
|
824
840
|
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_CUBE_MAP_POSITIVE_X + face, this._glTexture, mipLevel);
|
|
@@ -826,9 +842,17 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
826
842
|
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this._glTexture, mipLevel);
|
|
827
843
|
}
|
|
828
844
|
gl.pixelStorei(gl.PACK_ALIGNMENT, alignment);
|
|
829
|
-
gl.readPixels(x, y, width, height, readFormat != null ?
|
|
845
|
+
gl.readPixels(x, y, width, height, readFormat, readType != null ? readType : dataType, out);
|
|
830
846
|
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
831
847
|
};
|
|
848
|
+
_proto._getReadFormat = function _getReadFormat() {
|
|
849
|
+
var format = this._texture.format;
|
|
850
|
+
if (!this._rhi.supportsRenderTargetColorFormat(format)) {
|
|
851
|
+
throw new Error("Reading pixels from TextureFormat." + TextureFormat[format] + " requires color-renderable support");
|
|
852
|
+
}
|
|
853
|
+
var _this__formatDetail = this._formatDetail, readFormat = _this__formatDetail.readFormat, baseFormat = _this__formatDetail.baseFormat;
|
|
854
|
+
return readFormat != null ? readFormat : baseFormat;
|
|
855
|
+
};
|
|
832
856
|
_proto._getReadFrameBuffer = function _getReadFrameBuffer() {
|
|
833
857
|
var frameBuffer = this._rhi._readFrameBuffer;
|
|
834
858
|
if (!frameBuffer) {
|
|
@@ -847,6 +871,9 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
847
871
|
texture._isSRGBColorSpace = false;
|
|
848
872
|
}
|
|
849
873
|
};
|
|
874
|
+
_proto._isFloat32Format = function _isFloat32Format(format) {
|
|
875
|
+
return format === TextureFormat.R32_SFloat || format === TextureFormat.R32G32_SFloat || format === TextureFormat.R32G32B32A32_SFloat;
|
|
876
|
+
};
|
|
850
877
|
_proto._setWrapMode = function _setWrapMode(value, pname) {
|
|
851
878
|
var gl = this._gl;
|
|
852
879
|
var target = this._target;
|
|
@@ -867,7 +894,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
867
894
|
* @internal
|
|
868
895
|
*/ GLTexture._getFormatDetail = function _getFormatDetail(format, isSRGBColorSpace, gl) {
|
|
869
896
|
switch(format){
|
|
870
|
-
case TextureFormat.
|
|
897
|
+
case TextureFormat.R8G8B8_UNorm:
|
|
871
898
|
return {
|
|
872
899
|
internalFormat: isSRGBColorSpace ? gl.SRGB8 : gl.RGB8,
|
|
873
900
|
baseFormat: gl.RGB,
|
|
@@ -876,7 +903,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
876
903
|
isCompressed: false,
|
|
877
904
|
alignment: 1
|
|
878
905
|
};
|
|
879
|
-
case TextureFormat.
|
|
906
|
+
case TextureFormat.R8G8B8A8_UNorm:
|
|
880
907
|
return {
|
|
881
908
|
internalFormat: isSRGBColorSpace ? gl.SRGB8_ALPHA8 : gl.RGBA8,
|
|
882
909
|
baseFormat: gl.RGBA,
|
|
@@ -885,7 +912,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
885
912
|
isCompressed: false,
|
|
886
913
|
alignment: 4
|
|
887
914
|
};
|
|
888
|
-
case TextureFormat.
|
|
915
|
+
case TextureFormat.R4G4B4A4_UNorm:
|
|
889
916
|
return {
|
|
890
917
|
internalFormat: gl.RGBA4,
|
|
891
918
|
baseFormat: gl.RGBA,
|
|
@@ -893,7 +920,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
893
920
|
isCompressed: false,
|
|
894
921
|
alignment: 2
|
|
895
922
|
};
|
|
896
|
-
case TextureFormat.
|
|
923
|
+
case TextureFormat.R5G5B5A1_UNorm:
|
|
897
924
|
return {
|
|
898
925
|
internalFormat: gl.RGB5_A1,
|
|
899
926
|
baseFormat: gl.RGBA,
|
|
@@ -901,7 +928,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
901
928
|
isCompressed: false,
|
|
902
929
|
alignment: 2
|
|
903
930
|
};
|
|
904
|
-
case TextureFormat.
|
|
931
|
+
case TextureFormat.R5G6B5_UNorm:
|
|
905
932
|
return {
|
|
906
933
|
internalFormat: gl.RGB565,
|
|
907
934
|
baseFormat: gl.RGB,
|
|
@@ -909,15 +936,17 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
909
936
|
isCompressed: false,
|
|
910
937
|
alignment: 2
|
|
911
938
|
};
|
|
912
|
-
case TextureFormat.
|
|
939
|
+
case TextureFormat.R16G16B16A16_SFloat:
|
|
913
940
|
return {
|
|
914
941
|
internalFormat: gl.RGBA16F,
|
|
915
942
|
baseFormat: gl.RGBA,
|
|
943
|
+
readFormat: gl.RGBA,
|
|
944
|
+
readType: gl.FLOAT,
|
|
916
945
|
dataType: gl.HALF_FLOAT,
|
|
917
946
|
isCompressed: false,
|
|
918
947
|
alignment: 8
|
|
919
948
|
};
|
|
920
|
-
case TextureFormat.
|
|
949
|
+
case TextureFormat.R32G32B32A32_SFloat:
|
|
921
950
|
return {
|
|
922
951
|
internalFormat: gl.RGBA32F,
|
|
923
952
|
baseFormat: gl.RGBA,
|
|
@@ -925,6 +954,36 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
925
954
|
isCompressed: false,
|
|
926
955
|
alignment: 8
|
|
927
956
|
};
|
|
957
|
+
case TextureFormat.R16_UNorm:
|
|
958
|
+
return {
|
|
959
|
+
internalFormat: 0x822a,
|
|
960
|
+
baseFormat: gl.RED,
|
|
961
|
+
readFormat: gl.RGBA,
|
|
962
|
+
dataType: gl.UNSIGNED_SHORT,
|
|
963
|
+
isCompressed: false,
|
|
964
|
+
alignment: 2
|
|
965
|
+
};
|
|
966
|
+
case TextureFormat.R16_SFloat:
|
|
967
|
+
case TextureFormat.R16G16_SFloat:
|
|
968
|
+
return {
|
|
969
|
+
internalFormat: format === TextureFormat.R16_SFloat ? gl.R16F : gl.RG16F,
|
|
970
|
+
baseFormat: format === TextureFormat.R16_SFloat ? gl.RED : gl.RG,
|
|
971
|
+
readFormat: gl.RGBA,
|
|
972
|
+
readType: gl.FLOAT,
|
|
973
|
+
dataType: gl.HALF_FLOAT,
|
|
974
|
+
isCompressed: false,
|
|
975
|
+
alignment: 2
|
|
976
|
+
};
|
|
977
|
+
case TextureFormat.R32_SFloat:
|
|
978
|
+
case TextureFormat.R32G32_SFloat:
|
|
979
|
+
return {
|
|
980
|
+
internalFormat: format === TextureFormat.R32_SFloat ? gl.R32F : gl.RG32F,
|
|
981
|
+
baseFormat: format === TextureFormat.R32_SFloat ? gl.RED : gl.RG,
|
|
982
|
+
readFormat: gl.RGBA,
|
|
983
|
+
dataType: gl.FLOAT,
|
|
984
|
+
isCompressed: false,
|
|
985
|
+
alignment: 4
|
|
986
|
+
};
|
|
928
987
|
case TextureFormat.R11G11B10_UFloat:
|
|
929
988
|
return {
|
|
930
989
|
internalFormat: gl.R11F_G11F_B10F,
|
|
@@ -942,7 +1001,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
942
1001
|
isCompressed: false,
|
|
943
1002
|
alignment: 8
|
|
944
1003
|
};
|
|
945
|
-
case TextureFormat.
|
|
1004
|
+
case TextureFormat.R8_UNorm:
|
|
946
1005
|
return {
|
|
947
1006
|
internalFormat: gl.R8,
|
|
948
1007
|
baseFormat: gl.RED,
|
|
@@ -950,7 +1009,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
950
1009
|
isCompressed: false,
|
|
951
1010
|
alignment: 1
|
|
952
1011
|
};
|
|
953
|
-
case TextureFormat.
|
|
1012
|
+
case TextureFormat.R8G8_UNorm:
|
|
954
1013
|
return {
|
|
955
1014
|
internalFormat: gl.RG8,
|
|
956
1015
|
baseFormat: gl.RG,
|
|
@@ -1206,7 +1265,10 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1206
1265
|
*/ function set(value) {
|
|
1207
1266
|
var gl = this._gl;
|
|
1208
1267
|
var target = this._target;
|
|
1209
|
-
var
|
|
1268
|
+
var _this__texture = this._texture, _mipmap = _this__texture._mipmap, format = _this__texture.format;
|
|
1269
|
+
if (value !== TextureFilterMode.Point && this._isFloat32Format(format) && !this._rhi.canIUse(GLCapabilityType.textureFloatLinear)) {
|
|
1270
|
+
value = TextureFilterMode.Point;
|
|
1271
|
+
}
|
|
1210
1272
|
this._bind();
|
|
1211
1273
|
switch(value){
|
|
1212
1274
|
case TextureFilterMode.Point:
|
|
@@ -1292,8 +1354,8 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1292
1354
|
if (!rhi.supportsRenderTargetColorFormat(format)) {
|
|
1293
1355
|
throw new Error("TextureFormat is not supported:" + TextureFormat[format] + " in RenderTarget");
|
|
1294
1356
|
}
|
|
1295
|
-
if (isSRGBColorSpace && format === TextureFormat.
|
|
1296
|
-
throw new Error("If you want to use sRGB color space, only
|
|
1357
|
+
if (isSRGBColorSpace && format === TextureFormat.R8G8B8_UNorm) {
|
|
1358
|
+
throw new Error("If you want to use sRGB color space, only R8G8B8A8_UNorm format is supported in RenderTarget");
|
|
1297
1359
|
}
|
|
1298
1360
|
}
|
|
1299
1361
|
if (_colorTextures.some(function(v) {
|
|
@@ -1595,10 +1657,12 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1595
1657
|
if (formatDetail.isCompressed) {
|
|
1596
1658
|
throw new Error("Unable to read compressed texture");
|
|
1597
1659
|
}
|
|
1660
|
+
var readFormat = this._getReadFormat();
|
|
1598
1661
|
gl.pixelStorei(gl.PACK_ALIGNMENT, formatDetail.alignment);
|
|
1599
1662
|
gl.bindFramebuffer(gl.FRAMEBUFFER, this._getReadFrameBuffer());
|
|
1600
1663
|
gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, this._glTexture, mipLevel, elementIndex);
|
|
1601
|
-
|
|
1664
|
+
var _formatDetail_readType;
|
|
1665
|
+
gl.readPixels(x, y, width, height, readFormat, (_formatDetail_readType = formatDetail.readType) != null ? _formatDetail_readType : formatDetail.dataType, out);
|
|
1602
1666
|
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
1603
1667
|
};
|
|
1604
1668
|
_proto._validate = function _validate(texture) {
|