@galacean/engine-rhi-webgl 2.0.0-alpha.59 → 2.0.0-alpha.60
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 +135 -390
- package/dist/main.js.map +1 -1
- package/dist/module.js +137 -391
- package/dist/module.js.map +1 -1
- package/package.json +3 -3
- package/types/GLBuffer.d.ts +0 -1
- package/types/GLCapability.d.ts +0 -16
- package/types/GLPrimitive.d.ts +0 -6
- package/types/GLRenderStates.d.ts +2 -2
- package/types/GLRenderTarget.d.ts +0 -1
- package/types/GLTexture.d.ts +4 -11
- package/types/GLTexture2D.d.ts +0 -2
- package/types/GLTexture2DArray.d.ts +1 -1
- package/types/GLTextureCube.d.ts +0 -2
- package/types/WebGLEngine.d.ts +1 -1
- package/types/WebGLGraphicDevice.d.ts +4 -21
- package/types/index.d.ts +1 -1
- package/types/type.d.ts +0 -24
package/dist/module.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { Canvas, Engine, BufferUsage, BufferBindFlag, SetDataOptions, GLCapabilityType, TextureFormat, Logger, TextureUtils, TextureUsage, TextureWrapMode, TextureFilterMode, TextureDepthCompareFunction, Texture, TextureCube, CameraClearFlags, ColorWriteMask, SystemInfo, Platform } from '@galacean/engine-core';
|
|
2
|
-
import {
|
|
2
|
+
import { Vector4, Color } from '@galacean/engine-math';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
* Smoothing plug-in.
|
|
6
|
-
* */ var GLCompressedTextureInternalFormat = /*#__PURE__*/ function(GLCompressedTextureInternalFormat) {
|
|
4
|
+
var GLCompressedTextureInternalFormat = /*#__PURE__*/ function(GLCompressedTextureInternalFormat) {
|
|
7
5
|
// astc
|
|
8
6
|
GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["RGBA_ASTC_4X4_KHR"] = 37808] = "RGBA_ASTC_4X4_KHR";
|
|
9
7
|
GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["RGBA_ASTC_5X4_KHR"] = 37809] = "RGBA_ASTC_5X4_KHR";
|
|
@@ -228,7 +226,7 @@ function _create_class(Constructor, protoProps, staticProps) {
|
|
|
228
226
|
}
|
|
229
227
|
|
|
230
228
|
/**
|
|
231
|
-
* WebGL platform engine, supports WebGL
|
|
229
|
+
* WebGL platform engine, supports WebGL 2.0.
|
|
232
230
|
*/ var WebGLEngine = /*#__PURE__*/ function(Engine) {
|
|
233
231
|
_inherits(WebGLEngine, Engine);
|
|
234
232
|
function WebGLEngine() {
|
|
@@ -294,7 +292,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
294
292
|
this._glBuffer = glBuffer;
|
|
295
293
|
this._glBufferUsage = glBufferUsage;
|
|
296
294
|
this._glBindTarget = glBindTarget;
|
|
297
|
-
this._isWebGL2 = rhi.isWebGL2;
|
|
298
295
|
this.bind();
|
|
299
296
|
if (data) {
|
|
300
297
|
gl.bufferData(glBindTarget, data, glBufferUsage);
|
|
@@ -319,7 +316,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
319
316
|
var dataByteLength = dataLength ? byteSize * dataLength : data.byteLength;
|
|
320
317
|
if (dataOffset !== 0 || dataByteLength < data.byteLength) {
|
|
321
318
|
var isArrayBufferView = data.byteOffset !== undefined;
|
|
322
|
-
if (
|
|
319
|
+
if (isArrayBufferView) {
|
|
323
320
|
gl.bufferSubData(glBindTarget, bufferByteOffset, data, dataOffset, dataByteLength / byteSize);
|
|
324
321
|
} else {
|
|
325
322
|
var subData = new Uint8Array(isArrayBufferView ? data.buffer : data, dataOffset * byteSize, dataByteLength);
|
|
@@ -331,13 +328,8 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
331
328
|
gl.bindBuffer(glBindTarget, null);
|
|
332
329
|
};
|
|
333
330
|
_proto.getData = function getData(data, bufferByteOffset, dataOffset, dataLength) {
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
this.bind();
|
|
337
|
-
gl.getBufferSubData(this._glBindTarget, bufferByteOffset, data, dataOffset, dataLength);
|
|
338
|
-
} else {
|
|
339
|
-
throw "Buffer is write-only on WebGL1.0 platforms.";
|
|
340
|
-
}
|
|
331
|
+
this.bind();
|
|
332
|
+
this._gl.getBufferSubData(this._glBindTarget, bufferByteOffset, data, dataOffset, dataLength);
|
|
341
333
|
};
|
|
342
334
|
_proto.copyFromBuffer = function copyFromBuffer(srcBuffer, srcByteOffset, dstByteOffset, byteLength) {
|
|
343
335
|
var gl = this._gl;
|
|
@@ -372,7 +364,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
372
364
|
this._rhi = rhi;
|
|
373
365
|
this.capabilityList = new Map();
|
|
374
366
|
this._init();
|
|
375
|
-
this._compatibleAllInterface();
|
|
376
367
|
}
|
|
377
368
|
var _proto = GLCapability.prototype;
|
|
378
369
|
/**
|
|
@@ -388,9 +379,9 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
388
379
|
RGB_ETC1_WEBGL = GLCompressedTextureInternalFormat.RGB_ETC1_WEBGL, // etc
|
|
389
380
|
R11_EAC = GLCompressedTextureInternalFormat.R11_EAC, SRGB8_ALPHA8_ETC2_EAC = GLCompressedTextureInternalFormat.SRGB8_ALPHA8_ETC2_EAC, // pvrtc
|
|
390
381
|
RGB_PVRTC_4BPPV1_IMG = GLCompressedTextureInternalFormat.RGB_PVRTC_4BPPV1_IMG, RGBA_PVRTC_2BPPV1_IMG = GLCompressedTextureInternalFormat.RGBA_PVRTC_2BPPV1_IMG, // s3tc
|
|
391
|
-
RGB_S3TC_DXT1_EXT = GLCompressedTextureInternalFormat.RGB_S3TC_DXT1_EXT, RGBA_S3TC_DXT5_EXT = GLCompressedTextureInternalFormat.RGBA_S3TC_DXT5_EXT, // bptc
|
|
382
|
+
RGB_S3TC_DXT1_EXT = GLCompressedTextureInternalFormat.RGB_S3TC_DXT1_EXT, RGBA_S3TC_DXT5_EXT = GLCompressedTextureInternalFormat.RGBA_S3TC_DXT5_EXT, SRGB_S3TC_DXT1_EXT = GLCompressedTextureInternalFormat.SRGB_S3TC_DXT1_EXT, SRGB_ALPHA_S3TC_DXT5_EXT = GLCompressedTextureInternalFormat.SRGB_ALPHA_S3TC_DXT5_EXT, // bptc
|
|
392
383
|
RGBA_BPTC_UNORM_EXT = GLCompressedTextureInternalFormat.RGBA_BPTC_UNORM_EXT, RGB_BPTC_UNSIGNED_FLOAT_EXT = GLCompressedTextureInternalFormat.RGB_BPTC_UNSIGNED_FLOAT_EXT;
|
|
393
|
-
if (internalType >= RGBA_ASTC_4X4_KHR &&
|
|
384
|
+
if (internalType >= RGBA_ASTC_4X4_KHR && internalType <= RGBA_ASTC_12X12_KHR || internalType >= SRGB8_ALPHA8_ASTC_4X4_KHR && internalType <= SRGB8_ALPHA8_ASTC_12X12_KHR) {
|
|
394
385
|
return this.canIUse(GLCapabilityType.astc);
|
|
395
386
|
} else if (internalType === RGB_ETC1_WEBGL) {
|
|
396
387
|
return this.canIUse(GLCapabilityType.etc1);
|
|
@@ -400,6 +391,8 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
400
391
|
return this.canIUse(GLCapabilityType.pvrtc);
|
|
401
392
|
} else if (internalType >= RGB_S3TC_DXT1_EXT && internalType <= RGBA_S3TC_DXT5_EXT) {
|
|
402
393
|
return this.canIUse(GLCapabilityType.s3tc);
|
|
394
|
+
} else if (internalType >= SRGB_S3TC_DXT1_EXT && internalType <= SRGB_ALPHA_S3TC_DXT5_EXT) {
|
|
395
|
+
return this.canIUse(GLCapabilityType.s3tc_srgb);
|
|
403
396
|
} else if (internalType >= RGBA_BPTC_UNORM_EXT && internalType <= RGB_BPTC_UNSIGNED_FLOAT_EXT) {
|
|
404
397
|
return this.canIUse(GLCapabilityType.bptc);
|
|
405
398
|
}
|
|
@@ -409,25 +402,51 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
409
402
|
* Check whether the given texture format is supported.
|
|
410
403
|
*/ _proto.supportsTextureFormat = function supportsTextureFormat(format) {
|
|
411
404
|
switch(format){
|
|
405
|
+
case TextureFormat.BC1:
|
|
406
|
+
case TextureFormat.BC3:
|
|
407
|
+
return this.canIUse(GLCapabilityType.s3tc);
|
|
408
|
+
case TextureFormat.BC7:
|
|
409
|
+
case TextureFormat.BC6H:
|
|
410
|
+
return this.canIUse(GLCapabilityType.bptc);
|
|
411
|
+
case TextureFormat.ETC1_RGB:
|
|
412
|
+
return this.canIUse(GLCapabilityType.etc1);
|
|
413
|
+
case TextureFormat.ETC2_RGB:
|
|
414
|
+
case TextureFormat.ETC2_RGBA5:
|
|
415
|
+
case TextureFormat.ETC2_RGBA8:
|
|
416
|
+
return this.canIUse(GLCapabilityType.etc);
|
|
417
|
+
case TextureFormat.PVRTC_RGB2:
|
|
418
|
+
case TextureFormat.PVRTC_RGBA2:
|
|
419
|
+
case TextureFormat.PVRTC_RGB4:
|
|
420
|
+
case TextureFormat.PVRTC_RGBA4:
|
|
421
|
+
return this.canIUse(GLCapabilityType.pvrtc);
|
|
422
|
+
case TextureFormat.ASTC_4x4:
|
|
423
|
+
case TextureFormat.ASTC_5x5:
|
|
424
|
+
case TextureFormat.ASTC_6x6:
|
|
425
|
+
case TextureFormat.ASTC_8x8:
|
|
426
|
+
case TextureFormat.ASTC_10x10:
|
|
427
|
+
case TextureFormat.ASTC_12x12:
|
|
428
|
+
return this.canIUse(GLCapabilityType.astc);
|
|
429
|
+
case TextureFormat.R8G8B8:
|
|
430
|
+
case TextureFormat.R8G8B8A8:
|
|
431
|
+
case TextureFormat.R4G4B4A4:
|
|
432
|
+
case TextureFormat.R5G5B5A1:
|
|
433
|
+
case TextureFormat.R5G6B5:
|
|
412
434
|
case TextureFormat.R16G16B16A16:
|
|
413
|
-
return this.canIUse(GLCapabilityType.textureHalfFloat);
|
|
414
435
|
case TextureFormat.R32G32B32A32:
|
|
415
|
-
|
|
416
|
-
case TextureFormat.
|
|
417
|
-
case TextureFormat.
|
|
436
|
+
case TextureFormat.R32G32B32A32_UInt:
|
|
437
|
+
case TextureFormat.R11G11B10_UFloat:
|
|
438
|
+
case TextureFormat.R8:
|
|
439
|
+
case TextureFormat.R8G8:
|
|
418
440
|
case TextureFormat.Depth:
|
|
419
441
|
case TextureFormat.DepthStencil:
|
|
420
|
-
|
|
421
|
-
case TextureFormat.R11G11B10_UFloat:
|
|
422
|
-
case TextureFormat.R32G32B32A32_UInt:
|
|
442
|
+
case TextureFormat.Depth16:
|
|
423
443
|
case TextureFormat.Depth24:
|
|
424
444
|
case TextureFormat.Depth32:
|
|
445
|
+
case TextureFormat.Depth24Stencil8:
|
|
425
446
|
case TextureFormat.Depth32Stencil8:
|
|
426
|
-
case TextureFormat.R8:
|
|
427
|
-
case TextureFormat.R8G8:
|
|
428
|
-
return this.rhi.isWebGL2;
|
|
429
|
-
default:
|
|
430
447
|
return true;
|
|
448
|
+
default:
|
|
449
|
+
return false;
|
|
431
450
|
}
|
|
432
451
|
};
|
|
433
452
|
/**
|
|
@@ -435,11 +454,11 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
435
454
|
*/ _proto.supportsRenderTargetColorFormat = function supportsRenderTargetColorFormat(format) {
|
|
436
455
|
switch(format){
|
|
437
456
|
case TextureFormat.R16G16B16A16:
|
|
438
|
-
return this.canIUse(GLCapabilityType.colorBufferHalfFloat)
|
|
457
|
+
return this.canIUse(GLCapabilityType.colorBufferHalfFloat);
|
|
439
458
|
case TextureFormat.R32G32B32A32:
|
|
440
|
-
return this.canIUse(GLCapabilityType.colorBufferFloat)
|
|
459
|
+
return this.canIUse(GLCapabilityType.colorBufferFloat);
|
|
441
460
|
case TextureFormat.R11G11B10_UFloat:
|
|
442
|
-
return this.
|
|
461
|
+
return this.canIUse(GLCapabilityType.colorBufferFloat);
|
|
443
462
|
default:
|
|
444
463
|
return this.supportsTextureFormat(format);
|
|
445
464
|
}
|
|
@@ -448,27 +467,12 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
448
467
|
* Init capabilities.
|
|
449
468
|
*/ _proto._init = function _init() {
|
|
450
469
|
var cap = this.capabilityList;
|
|
451
|
-
var isWebGL2 = this.rhi.isWebGL2;
|
|
452
470
|
var requireExtension = this.rhi.requireExtension.bind(this.rhi);
|
|
453
|
-
var
|
|
454
|
-
cap.set(shaderVertexID, isWebGL2);
|
|
455
|
-
cap.set(standardDerivatives, isWebGL2 || !!requireExtension(standardDerivatives));
|
|
456
|
-
cap.set(shaderTextureLod, isWebGL2 || !!requireExtension(shaderTextureLod));
|
|
457
|
-
cap.set(elementIndexUint, isWebGL2 || !!requireExtension(elementIndexUint));
|
|
458
|
-
cap.set(depthTexture, isWebGL2 || !!requireExtension(depthTexture));
|
|
459
|
-
cap.set(vertexArrayObject, isWebGL2 || !!requireExtension(vertexArrayObject));
|
|
460
|
-
cap.set(instancedArrays, isWebGL2 || !!requireExtension(instancedArrays));
|
|
461
|
-
cap.set(multipleSample, isWebGL2);
|
|
462
|
-
cap.set(drawBuffers, isWebGL2 || !!requireExtension(drawBuffers));
|
|
463
|
-
cap.set(blendMinMax, isWebGL2 || !!requireExtension(blendMinMax));
|
|
464
|
-
cap.set(textureFloat, isWebGL2 || !!requireExtension(textureFloat));
|
|
465
|
-
cap.set(textureHalfFloat, isWebGL2 || !!requireExtension(textureHalfFloat));
|
|
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;
|
|
466
472
|
cap.set(textureFloatLinear, !!requireExtension(textureFloatLinear));
|
|
467
|
-
cap.set(
|
|
468
|
-
cap.set(
|
|
469
|
-
cap.set(colorBufferHalfFloat, isWebGL2 && !!requireExtension(colorBufferFloat) || !!requireExtension(colorBufferHalfFloat));
|
|
473
|
+
cap.set(colorBufferFloat, !!requireExtension(colorBufferFloat));
|
|
474
|
+
cap.set(colorBufferHalfFloat, !!requireExtension(colorBufferFloat) || !!requireExtension(colorBufferHalfFloat));
|
|
470
475
|
cap.set(textureFilterAnisotropic, !!requireExtension(textureFilterAnisotropic));
|
|
471
|
-
cap.set(fragDepth, isWebGL2 || !!requireExtension(fragDepth));
|
|
472
476
|
cap.set(etc, !!(requireExtension(etc) || requireExtension(etc_webkit)));
|
|
473
477
|
cap.set(etc1, !!(requireExtension(etc1) || requireExtension(etc1_webkit)));
|
|
474
478
|
cap.set(pvrtc, !!(requireExtension(pvrtc) || requireExtension(pvrtc_webkit)));
|
|
@@ -478,85 +482,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
478
482
|
var astcExtension = requireExtension(astc) || requireExtension(astc_webkit);
|
|
479
483
|
cap.set(astc, !!astcExtension);
|
|
480
484
|
cap.set(astc_hdr, typeof (astcExtension == null ? void 0 : astcExtension.getSupportedProfiles) === "function" && astcExtension.getSupportedProfiles().includes("hdr"));
|
|
481
|
-
cap.set(sRGB, isWebGL2 || !!requireExtension(sRGB));
|
|
482
|
-
};
|
|
483
|
-
/**
|
|
484
|
-
* If there are extensions that can supplement this ability, smooth out the difference.
|
|
485
|
-
* @example
|
|
486
|
-
* compatible(GLCapabilityType.depthTexture,{
|
|
487
|
-
* UNSIGNED_INT_24_8: "UNSIGNED_INT_24_8_WEBGL"
|
|
488
|
-
* })
|
|
489
|
-
* gl.UNSIGNED_INT_24_8 = ext.UNSIGNED_INT_24_8_WEBGL
|
|
490
|
-
*/ _proto._compatibleInterface = function _compatibleInterface(capabilityType, flatItem) {
|
|
491
|
-
var rhi = this.rhi;
|
|
492
|
-
var gl = rhi.gl;
|
|
493
|
-
var ext = rhi.requireExtension(capabilityType);
|
|
494
|
-
if (ext) {
|
|
495
|
-
for(var glKey in flatItem){
|
|
496
|
-
var extensionKey = flatItem[glKey];
|
|
497
|
-
var extensionVal = ext[extensionKey];
|
|
498
|
-
// Mini game hack the native function,use “.bind” to smooth out if is “Funcion”.
|
|
499
|
-
if (extensionVal == null ? void 0 : extensionVal.bind) {
|
|
500
|
-
gl[glKey] = extensionVal.bind(ext);
|
|
501
|
-
} else {
|
|
502
|
-
gl[glKey] = extensionVal;
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
};
|
|
507
|
-
_proto._compatibleAllInterface = function _compatibleAllInterface() {
|
|
508
|
-
var depthTexture = GLCapabilityType.depthTexture, vertexArrayObject = GLCapabilityType.vertexArrayObject, instancedArrays = GLCapabilityType.instancedArrays, drawBuffers = GLCapabilityType.drawBuffers, textureFilterAnisotropic = GLCapabilityType.textureFilterAnisotropic, textureHalfFloat = GLCapabilityType.textureHalfFloat, colorBufferHalfFloat = GLCapabilityType.colorBufferHalfFloat, WEBGL_colorBufferFloat = GLCapabilityType.WEBGL_colorBufferFloat, blendMinMax = GLCapabilityType.blendMinMax, sRGB = GLCapabilityType.sRGB;
|
|
509
|
-
var isWebGL2 = this.rhi.isWebGL2;
|
|
510
|
-
if (!isWebGL2) {
|
|
511
|
-
this._compatibleInterface(blendMinMax, {
|
|
512
|
-
MIN: "MIN_EXT",
|
|
513
|
-
MAX: "MAX_EXT"
|
|
514
|
-
});
|
|
515
|
-
this._compatibleInterface(depthTexture, {
|
|
516
|
-
UNSIGNED_INT_24_8: "UNSIGNED_INT_24_8_WEBGL"
|
|
517
|
-
});
|
|
518
|
-
this._compatibleInterface(vertexArrayObject, {
|
|
519
|
-
createVertexArray: "createVertexArrayOES",
|
|
520
|
-
deleteVertexArray: "deleteVertexArrayOES",
|
|
521
|
-
isVertexArray: "isVertexArrayOES",
|
|
522
|
-
bindVertexArray: "bindVertexArrayOES"
|
|
523
|
-
});
|
|
524
|
-
this._compatibleInterface(instancedArrays, {
|
|
525
|
-
drawArraysInstanced: "drawArraysInstancedANGLE",
|
|
526
|
-
drawElementsInstanced: "drawElementsInstancedANGLE",
|
|
527
|
-
vertexAttribDivisor: "vertexAttribDivisorANGLE"
|
|
528
|
-
});
|
|
529
|
-
this._compatibleInterface(drawBuffers, {
|
|
530
|
-
MAX_DRAW_BUFFERS: "MAX_DRAW_BUFFERS_WEBGL"
|
|
531
|
-
});
|
|
532
|
-
var items = {};
|
|
533
|
-
if (this.canIUse(GLCapabilityType.drawBuffers)) {
|
|
534
|
-
var maxDrawBuffers = this.maxDrawBuffers;
|
|
535
|
-
for(var i = 0; i < maxDrawBuffers; i++){
|
|
536
|
-
i != 0 && (items["COLOR_ATTACHMENT" + i] = "COLOR_ATTACHMENT" + i + "_WEBGL");
|
|
537
|
-
items["DRAW_BUFFER" + i] = "DRAW_BUFFER" + i + "_WEBGL";
|
|
538
|
-
}
|
|
539
|
-
this._compatibleInterface(drawBuffers, _extends({
|
|
540
|
-
drawBuffers: "drawBuffersWEBGL"
|
|
541
|
-
}, items));
|
|
542
|
-
}
|
|
543
|
-
this._compatibleInterface(textureHalfFloat, {
|
|
544
|
-
HALF_FLOAT: "HALF_FLOAT_OES"
|
|
545
|
-
});
|
|
546
|
-
this._compatibleInterface(colorBufferHalfFloat, {
|
|
547
|
-
RGBA16F: "RBGA16F_EXT"
|
|
548
|
-
});
|
|
549
|
-
this._compatibleInterface(WEBGL_colorBufferFloat, {
|
|
550
|
-
RGBA32F: "RBGA32F_EXT"
|
|
551
|
-
});
|
|
552
|
-
this._compatibleInterface(sRGB, {
|
|
553
|
-
SRGB8: "SRGB_EXT",
|
|
554
|
-
SRGB8_ALPHA8: "SRGB_ALPHA_EXT"
|
|
555
|
-
});
|
|
556
|
-
}
|
|
557
|
-
this._compatibleInterface(textureFilterAnisotropic, {
|
|
558
|
-
TEXTURE_MAX_ANISOTROPY_EXT: "TEXTURE_MAX_ANISOTROPY_EXT"
|
|
559
|
-
});
|
|
560
485
|
};
|
|
561
486
|
_create_class(GLCapability, [
|
|
562
487
|
{
|
|
@@ -571,29 +496,11 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
571
496
|
return this.rhi.renderStates.getParameter(this.rhi.gl.MAX_VERTEX_UNIFORM_VECTORS);
|
|
572
497
|
}
|
|
573
498
|
},
|
|
574
|
-
{
|
|
575
|
-
key: "canUseFloatTextureBlendShape",
|
|
576
|
-
get: function get() {
|
|
577
|
-
return this.canIUse(GLCapabilityType.shaderVertexID) && this.canIUse(GLCapabilityType.textureFloat) && this.rhi.renderStates.getParameter(this.rhi.gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS) > 0;
|
|
578
|
-
}
|
|
579
|
-
},
|
|
580
|
-
{
|
|
581
|
-
key: "canIUseMoreJoints",
|
|
582
|
-
get: /**
|
|
583
|
-
* Whether can use more joints.
|
|
584
|
-
*/ function get() {
|
|
585
|
-
return this.canIUse(GLCapabilityType.textureFloat) && this.rhi.renderStates.getParameter(this.rhi.gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS) > 0;
|
|
586
|
-
}
|
|
587
|
-
},
|
|
588
499
|
{
|
|
589
500
|
key: "maxDrawBuffers",
|
|
590
501
|
get: function get() {
|
|
591
502
|
if (!this._maxDrawBuffers) {
|
|
592
|
-
|
|
593
|
-
this._maxDrawBuffers = this._rhi.gl.getParameter(this._rhi.gl.MAX_DRAW_BUFFERS);
|
|
594
|
-
} else {
|
|
595
|
-
this._maxDrawBuffers = 1;
|
|
596
|
-
}
|
|
503
|
+
this._maxDrawBuffers = this._rhi.gl.getParameter(this._rhi.gl.MAX_DRAW_BUFFERS);
|
|
597
504
|
}
|
|
598
505
|
return this._maxDrawBuffers;
|
|
599
506
|
}
|
|
@@ -617,19 +524,11 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
617
524
|
*/ function get() {
|
|
618
525
|
if (!this._maxAntiAliasing) {
|
|
619
526
|
var gl = this._rhi.gl;
|
|
620
|
-
|
|
621
|
-
this._maxAntiAliasing = canMSAA ? gl.getParameter(gl.MAX_SAMPLES) : 1;
|
|
527
|
+
this._maxAntiAliasing = gl.getParameter(gl.MAX_SAMPLES);
|
|
622
528
|
}
|
|
623
529
|
return this._maxAntiAliasing;
|
|
624
530
|
}
|
|
625
531
|
},
|
|
626
|
-
{
|
|
627
|
-
key: "isFragmentHighPrecision",
|
|
628
|
-
get: function get() {
|
|
629
|
-
var gl = this._rhi.gl;
|
|
630
|
-
return gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.HIGH_FLOAT).precision !== 0;
|
|
631
|
-
}
|
|
632
|
-
},
|
|
633
532
|
{
|
|
634
533
|
key: "rhi",
|
|
635
534
|
get: function get() {
|
|
@@ -661,9 +560,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
661
560
|
}();
|
|
662
561
|
|
|
663
562
|
/**
|
|
664
|
-
* Improvement of VAO:
|
|
665
|
-
* 1) WebGL2.0 must support VAO, almost all devices support vao extensions in webgl1.0, we can use PollyFill,only keep VAO mode.
|
|
666
|
-
*/ /**
|
|
667
563
|
* @internal
|
|
668
564
|
* GL platform primitive.
|
|
669
565
|
*/ var GLPrimitive = /*#__PURE__*/ function() {
|
|
@@ -671,8 +567,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
671
567
|
this._attribLocArray = [];
|
|
672
568
|
this._vaoMap = new Map();
|
|
673
569
|
this._primitive = primitive;
|
|
674
|
-
this._canUseInstancedArrays = rhi.canIUse(GLCapabilityType.instancedArrays);
|
|
675
|
-
this._isSupportVAO = rhi.canIUse(GLCapabilityType.vertexArrayObject);
|
|
676
570
|
this._gl = rhi.gl;
|
|
677
571
|
}
|
|
678
572
|
var _proto = GLPrimitive.prototype;
|
|
@@ -681,7 +575,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
681
575
|
*/ _proto.draw = function draw(shaderProgram, subMesh) {
|
|
682
576
|
var gl = this._gl;
|
|
683
577
|
var primitive = this._primitive;
|
|
684
|
-
var useVao =
|
|
578
|
+
var useVao = primitive.enableVAO;
|
|
685
579
|
if (useVao) {
|
|
686
580
|
if (primitive._bufferStructChanged) {
|
|
687
581
|
this._clearVAO();
|
|
@@ -710,21 +604,17 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
710
604
|
gl.drawArrays(topology, start, count);
|
|
711
605
|
}
|
|
712
606
|
} else {
|
|
713
|
-
if (
|
|
714
|
-
if (
|
|
715
|
-
|
|
716
|
-
gl.drawElementsInstanced(topology, count, _glIndexType, start * _glIndexByteCount, instanceCount);
|
|
717
|
-
} else {
|
|
718
|
-
var _glBuffer1 = indexBufferBinding.buffer._platformBuffer._glBuffer;
|
|
719
|
-
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _glBuffer1);
|
|
720
|
-
gl.drawElementsInstanced(topology, count, _glIndexType, start * _glIndexByteCount, instanceCount);
|
|
721
|
-
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
|
|
722
|
-
}
|
|
607
|
+
if (indexBufferBinding) {
|
|
608
|
+
if (useVao) {
|
|
609
|
+
gl.drawElementsInstanced(topology, count, _glIndexType, start * _glIndexByteCount, instanceCount);
|
|
723
610
|
} else {
|
|
724
|
-
|
|
611
|
+
var _glBuffer1 = indexBufferBinding.buffer._platformBuffer._glBuffer;
|
|
612
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _glBuffer1);
|
|
613
|
+
gl.drawElementsInstanced(topology, count, _glIndexType, start * _glIndexByteCount, instanceCount);
|
|
614
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
|
|
725
615
|
}
|
|
726
616
|
} else {
|
|
727
|
-
|
|
617
|
+
gl.drawArraysInstanced(topology, start, count, instanceCount);
|
|
728
618
|
}
|
|
729
619
|
}
|
|
730
620
|
// Unbind
|
|
@@ -735,7 +625,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
735
625
|
}
|
|
736
626
|
};
|
|
737
627
|
_proto.destroy = function destroy() {
|
|
738
|
-
this.
|
|
628
|
+
this._clearVAO();
|
|
739
629
|
};
|
|
740
630
|
/**
|
|
741
631
|
* Bind buffer and attribute.
|
|
@@ -763,9 +653,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
763
653
|
gl.enableVertexAttribArray(loc);
|
|
764
654
|
var elementInfo = element._formatMetaInfo;
|
|
765
655
|
gl.vertexAttribPointer(loc, elementInfo.size, elementInfo.type, elementInfo.normalized, stride, element.offset);
|
|
766
|
-
|
|
767
|
-
gl.vertexAttribDivisor(loc, element.instanceStepRate);
|
|
768
|
-
}
|
|
656
|
+
gl.vertexAttribDivisor(loc, element.instanceStepRate);
|
|
769
657
|
this._attribLocArray.push(loc);
|
|
770
658
|
} else {
|
|
771
659
|
Logger.warn("vertex attribute not found: " + name);
|
|
@@ -813,7 +701,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
813
701
|
/** cache */ this._parameters[gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS] = gl.getParameter(gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS);
|
|
814
702
|
this._parameters[gl.MAX_VERTEX_UNIFORM_VECTORS] = gl.getParameter(gl.MAX_VERTEX_UNIFORM_VECTORS);
|
|
815
703
|
this._parameters[gl.MAX_VERTEX_ATTRIBS] = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
|
|
816
|
-
this._parameters[gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS] = gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS);
|
|
817
704
|
this._parameters[gl.MAX_TEXTURE_SIZE] = gl.getParameter(gl.MAX_TEXTURE_SIZE);
|
|
818
705
|
// init blend state same as BlendState default value.
|
|
819
706
|
gl.blendFuncSeparate(gl.ONE, gl.ZERO, gl.ONE, gl.ZERO);
|
|
@@ -854,7 +741,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
854
741
|
this._texture = texture;
|
|
855
742
|
this._rhi = rhi;
|
|
856
743
|
this._gl = rhi.gl;
|
|
857
|
-
this._isWebGL2 = rhi.isWebGL2;
|
|
858
744
|
this._target = target;
|
|
859
745
|
this._glTexture = this._gl.createTexture();
|
|
860
746
|
}
|
|
@@ -870,7 +756,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
870
756
|
/**
|
|
871
757
|
* @internal
|
|
872
758
|
*/ _proto.setUseDepthCompareMode = function setUseDepthCompareMode(value) {
|
|
873
|
-
if (!this._isWebGL2) return;
|
|
874
759
|
var gl = this._gl;
|
|
875
760
|
gl.texParameteri(this._target, gl.TEXTURE_COMPARE_MODE, value ? gl.COMPARE_REF_TO_TEXTURE : gl.NONE);
|
|
876
761
|
};
|
|
@@ -879,7 +764,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
879
764
|
*/ _proto.generateMipmaps = function generateMipmaps() {
|
|
880
765
|
var texture = this._texture;
|
|
881
766
|
var mipmap = texture._mipmap;
|
|
882
|
-
if (!TextureUtils.supportGenerateMipmaps(texture.format, mipmap, texture.isSRGBColorSpace
|
|
767
|
+
if (!TextureUtils.supportGenerateMipmaps(texture.format, mipmap, texture.isSRGBColorSpace)) {
|
|
883
768
|
Logger.warn("Auto-generating mipmaps for sRGB textures is only supported in [WebGL2 + R8G8B8A8], you must generate mipmaps manually.");
|
|
884
769
|
return;
|
|
885
770
|
}
|
|
@@ -896,11 +781,10 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
896
781
|
* Pre-development mipmapping GPU memory.
|
|
897
782
|
*/ _proto._init = function _init(isCube) {
|
|
898
783
|
var gl = this._gl;
|
|
899
|
-
var isWebGL2 = this._isWebGL2;
|
|
900
784
|
var _this__formatDetail = this._formatDetail, internalFormat = _this__formatDetail.internalFormat, baseFormat = _this__formatDetail.baseFormat, dataType = _this__formatDetail.dataType;
|
|
901
785
|
var _this__texture = this._texture, mipmapCount = _this__texture.mipmapCount, width = _this__texture.width, height = _this__texture.height, usage = _this__texture.usage, _isDepthTexture = _this__texture._isDepthTexture;
|
|
902
786
|
this._bind();
|
|
903
|
-
if (
|
|
787
|
+
if (usage !== TextureUsage.Dynamic) {
|
|
904
788
|
gl.texStorage2D(this._target, mipmapCount, internalFormat, width, height);
|
|
905
789
|
} else {
|
|
906
790
|
if (!isCube) {
|
|
@@ -936,17 +820,12 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
936
820
|
var gl = this._gl;
|
|
937
821
|
var _this__formatDetail = this._formatDetail, baseFormat = _this__formatDetail.baseFormat, dataType = _this__formatDetail.dataType, readFormat = _this__formatDetail.readFormat, alignment = _this__formatDetail.alignment;
|
|
938
822
|
gl.bindFramebuffer(gl.FRAMEBUFFER, this._getReadFrameBuffer());
|
|
939
|
-
if (mipLevel > 0 && !this._isWebGL2) {
|
|
940
|
-
mipLevel = 0;
|
|
941
|
-
Logger.error("mipLevel only take effect in WebGL2.0");
|
|
942
|
-
}
|
|
943
823
|
if (face != null) {
|
|
944
824
|
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_CUBE_MAP_POSITIVE_X + face, this._glTexture, mipLevel);
|
|
945
825
|
} else {
|
|
946
826
|
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this._glTexture, mipLevel);
|
|
947
827
|
}
|
|
948
828
|
gl.pixelStorei(gl.PACK_ALIGNMENT, alignment);
|
|
949
|
-
// Base format is different from read format in webgl1.0 with sRGB
|
|
950
829
|
gl.readPixels(x, y, width, height, readFormat != null ? readFormat : baseFormat, dataType, out);
|
|
951
830
|
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
952
831
|
};
|
|
@@ -957,8 +836,8 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
957
836
|
}
|
|
958
837
|
return frameBuffer;
|
|
959
838
|
};
|
|
960
|
-
_proto._validate = function _validate(texture
|
|
961
|
-
var format = texture.format
|
|
839
|
+
_proto._validate = function _validate(texture) {
|
|
840
|
+
var format = texture.format;
|
|
962
841
|
// Validate sRGB format
|
|
963
842
|
// @ts-ignore
|
|
964
843
|
var isSRGBColorSpace = texture._isSRGBColorSpace;
|
|
@@ -967,24 +846,10 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
967
846
|
// @ts-ignore
|
|
968
847
|
texture._isSRGBColorSpace = false;
|
|
969
848
|
}
|
|
970
|
-
var isWebGL2 = rhi.isWebGL2;
|
|
971
|
-
// Validate mipmap
|
|
972
|
-
var mipmap = texture._mipmap;
|
|
973
|
-
if (mipmap && !TextureUtils.supportMipmaps(width, height, isWebGL2)) {
|
|
974
|
-
Logger.warn("Non-power-2 texture is not supported for mipmap in WebGL1, and has automatically downgraded to non-mipmap");
|
|
975
|
-
texture._mipmap = false;
|
|
976
|
-
/** @ts-ignore */ texture._mipmapCount = texture._getMipmapCount();
|
|
977
|
-
}
|
|
978
849
|
};
|
|
979
850
|
_proto._setWrapMode = function _setWrapMode(value, pname) {
|
|
980
851
|
var gl = this._gl;
|
|
981
|
-
var isWebGL2 = this._isWebGL2;
|
|
982
852
|
var target = this._target;
|
|
983
|
-
var _this__texture = this._texture, width = _this__texture.width, height = _this__texture.height;
|
|
984
|
-
if (!isWebGL2 && value !== TextureWrapMode.Clamp && (!MathUtil.isPowerOf2(width) || !MathUtil.isPowerOf2(height))) {
|
|
985
|
-
Logger.warn("non-power-2 texture is not supported for REPEAT or MIRRORED_REPEAT in WebGL1,and has automatically downgraded to CLAMP_TO_EDGE");
|
|
986
|
-
value = TextureWrapMode.Clamp;
|
|
987
|
-
}
|
|
988
853
|
switch(value){
|
|
989
854
|
case TextureWrapMode.Clamp:
|
|
990
855
|
gl.texParameteri(target, pname, gl.CLAMP_TO_EDGE);
|
|
@@ -1000,21 +865,21 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1000
865
|
/**
|
|
1001
866
|
* Get more texture info from TextureFormat.
|
|
1002
867
|
* @internal
|
|
1003
|
-
*/ GLTexture._getFormatDetail = function _getFormatDetail(format, isSRGBColorSpace, gl
|
|
868
|
+
*/ GLTexture._getFormatDetail = function _getFormatDetail(format, isSRGBColorSpace, gl) {
|
|
1004
869
|
switch(format){
|
|
1005
870
|
case TextureFormat.R8G8B8:
|
|
1006
871
|
return {
|
|
1007
|
-
internalFormat: isSRGBColorSpace ? gl.SRGB8 :
|
|
1008
|
-
baseFormat:
|
|
1009
|
-
readFormat:
|
|
872
|
+
internalFormat: isSRGBColorSpace ? gl.SRGB8 : gl.RGB8,
|
|
873
|
+
baseFormat: gl.RGB,
|
|
874
|
+
readFormat: gl.RGBA,
|
|
1010
875
|
dataType: gl.UNSIGNED_BYTE,
|
|
1011
876
|
isCompressed: false,
|
|
1012
877
|
alignment: 1
|
|
1013
878
|
};
|
|
1014
879
|
case TextureFormat.R8G8B8A8:
|
|
1015
880
|
return {
|
|
1016
|
-
internalFormat: isSRGBColorSpace ? gl.SRGB8_ALPHA8 :
|
|
1017
|
-
baseFormat:
|
|
881
|
+
internalFormat: isSRGBColorSpace ? gl.SRGB8_ALPHA8 : gl.RGBA8,
|
|
882
|
+
baseFormat: gl.RGBA,
|
|
1018
883
|
readFormat: gl.RGBA,
|
|
1019
884
|
dataType: gl.UNSIGNED_BYTE,
|
|
1020
885
|
isCompressed: false,
|
|
@@ -1022,7 +887,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1022
887
|
};
|
|
1023
888
|
case TextureFormat.R4G4B4A4:
|
|
1024
889
|
return {
|
|
1025
|
-
internalFormat:
|
|
890
|
+
internalFormat: gl.RGBA4,
|
|
1026
891
|
baseFormat: gl.RGBA,
|
|
1027
892
|
dataType: gl.UNSIGNED_SHORT_4_4_4_4,
|
|
1028
893
|
isCompressed: false,
|
|
@@ -1030,7 +895,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1030
895
|
};
|
|
1031
896
|
case TextureFormat.R5G5B5A1:
|
|
1032
897
|
return {
|
|
1033
|
-
internalFormat:
|
|
898
|
+
internalFormat: gl.RGB5_A1,
|
|
1034
899
|
baseFormat: gl.RGBA,
|
|
1035
900
|
dataType: gl.UNSIGNED_SHORT_5_5_5_1,
|
|
1036
901
|
isCompressed: false,
|
|
@@ -1038,31 +903,15 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1038
903
|
};
|
|
1039
904
|
case TextureFormat.R5G6B5:
|
|
1040
905
|
return {
|
|
1041
|
-
internalFormat:
|
|
906
|
+
internalFormat: gl.RGB565,
|
|
1042
907
|
baseFormat: gl.RGB,
|
|
1043
908
|
dataType: gl.UNSIGNED_SHORT_5_6_5,
|
|
1044
909
|
isCompressed: false,
|
|
1045
910
|
alignment: 2
|
|
1046
911
|
};
|
|
1047
|
-
case TextureFormat.Alpha8:
|
|
1048
|
-
return {
|
|
1049
|
-
internalFormat: gl.ALPHA,
|
|
1050
|
-
baseFormat: gl.ALPHA,
|
|
1051
|
-
dataType: gl.UNSIGNED_BYTE,
|
|
1052
|
-
isCompressed: false,
|
|
1053
|
-
alignment: 1
|
|
1054
|
-
};
|
|
1055
|
-
case TextureFormat.LuminanceAlpha:
|
|
1056
|
-
return {
|
|
1057
|
-
internalFormat: gl.LUMINANCE_ALPHA,
|
|
1058
|
-
baseFormat: gl.LUMINANCE_ALPHA,
|
|
1059
|
-
dataType: gl.UNSIGNED_BYTE,
|
|
1060
|
-
isCompressed: false,
|
|
1061
|
-
alignment: 2
|
|
1062
|
-
};
|
|
1063
912
|
case TextureFormat.R16G16B16A16:
|
|
1064
913
|
return {
|
|
1065
|
-
internalFormat:
|
|
914
|
+
internalFormat: gl.RGBA16F,
|
|
1066
915
|
baseFormat: gl.RGBA,
|
|
1067
916
|
dataType: gl.HALF_FLOAT,
|
|
1068
917
|
isCompressed: false,
|
|
@@ -1070,13 +919,12 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1070
919
|
};
|
|
1071
920
|
case TextureFormat.R32G32B32A32:
|
|
1072
921
|
return {
|
|
1073
|
-
internalFormat:
|
|
922
|
+
internalFormat: gl.RGBA32F,
|
|
1074
923
|
baseFormat: gl.RGBA,
|
|
1075
924
|
dataType: gl.FLOAT,
|
|
1076
925
|
isCompressed: false,
|
|
1077
926
|
alignment: 8
|
|
1078
927
|
};
|
|
1079
|
-
// Only WebGL2 support
|
|
1080
928
|
case TextureFormat.R11G11B10_UFloat:
|
|
1081
929
|
return {
|
|
1082
930
|
internalFormat: gl.R11F_G11F_B10F,
|
|
@@ -1086,7 +934,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1086
934
|
isCompressed: false,
|
|
1087
935
|
alignment: 4
|
|
1088
936
|
};
|
|
1089
|
-
// Only WebGL2 support
|
|
1090
937
|
case TextureFormat.R32G32B32A32_UInt:
|
|
1091
938
|
return {
|
|
1092
939
|
internalFormat: gl.RGBA32UI,
|
|
@@ -1095,7 +942,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1095
942
|
isCompressed: false,
|
|
1096
943
|
alignment: 8
|
|
1097
944
|
};
|
|
1098
|
-
// Only WebGL2 support
|
|
1099
945
|
case TextureFormat.R8:
|
|
1100
946
|
return {
|
|
1101
947
|
internalFormat: gl.R8,
|
|
@@ -1104,7 +950,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1104
950
|
isCompressed: false,
|
|
1105
951
|
alignment: 1
|
|
1106
952
|
};
|
|
1107
|
-
// Only WebGL2 support
|
|
1108
953
|
case TextureFormat.R8G8:
|
|
1109
954
|
return {
|
|
1110
955
|
internalFormat: gl.RG8,
|
|
@@ -1205,23 +1050,23 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1205
1050
|
};
|
|
1206
1051
|
case TextureFormat.Depth:
|
|
1207
1052
|
return {
|
|
1208
|
-
internalFormat:
|
|
1053
|
+
internalFormat: gl.DEPTH_COMPONENT32F,
|
|
1209
1054
|
baseFormat: gl.DEPTH_COMPONENT,
|
|
1210
|
-
dataType:
|
|
1055
|
+
dataType: gl.FLOAT,
|
|
1211
1056
|
isCompressed: false,
|
|
1212
1057
|
attachment: gl.DEPTH_ATTACHMENT
|
|
1213
1058
|
};
|
|
1214
1059
|
case TextureFormat.DepthStencil:
|
|
1215
1060
|
return {
|
|
1216
|
-
internalFormat:
|
|
1061
|
+
internalFormat: gl.DEPTH32F_STENCIL8,
|
|
1217
1062
|
baseFormat: gl.DEPTH_STENCIL,
|
|
1218
|
-
dataType:
|
|
1063
|
+
dataType: gl.FLOAT_32_UNSIGNED_INT_24_8_REV,
|
|
1219
1064
|
isCompressed: false,
|
|
1220
1065
|
attachment: gl.DEPTH_STENCIL_ATTACHMENT
|
|
1221
1066
|
};
|
|
1222
1067
|
case TextureFormat.Depth16:
|
|
1223
1068
|
return {
|
|
1224
|
-
internalFormat:
|
|
1069
|
+
internalFormat: gl.DEPTH_COMPONENT16,
|
|
1225
1070
|
baseFormat: gl.DEPTH_COMPONENT,
|
|
1226
1071
|
dataType: gl.UNSIGNED_SHORT,
|
|
1227
1072
|
isCompressed: false,
|
|
@@ -1229,13 +1074,12 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1229
1074
|
};
|
|
1230
1075
|
case TextureFormat.Depth24Stencil8:
|
|
1231
1076
|
return {
|
|
1232
|
-
internalFormat:
|
|
1077
|
+
internalFormat: gl.DEPTH24_STENCIL8,
|
|
1233
1078
|
baseFormat: gl.DEPTH_STENCIL,
|
|
1234
1079
|
dataType: gl.UNSIGNED_INT_24_8,
|
|
1235
1080
|
isCompressed: false,
|
|
1236
1081
|
attachment: gl.DEPTH_STENCIL_ATTACHMENT
|
|
1237
1082
|
};
|
|
1238
|
-
// Only WebGL2 support
|
|
1239
1083
|
case TextureFormat.Depth24:
|
|
1240
1084
|
return {
|
|
1241
1085
|
internalFormat: gl.DEPTH_COMPONENT24,
|
|
@@ -1244,7 +1088,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1244
1088
|
isCompressed: false,
|
|
1245
1089
|
attachment: gl.DEPTH_ATTACHMENT
|
|
1246
1090
|
};
|
|
1247
|
-
// Only WebGL2 support
|
|
1248
1091
|
case TextureFormat.Depth32:
|
|
1249
1092
|
return {
|
|
1250
1093
|
internalFormat: gl.DEPTH_COMPONENT32F,
|
|
@@ -1253,7 +1096,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1253
1096
|
isCompressed: false,
|
|
1254
1097
|
attachment: gl.DEPTH_ATTACHMENT
|
|
1255
1098
|
};
|
|
1256
|
-
// Only WebGL2 support
|
|
1257
1099
|
case TextureFormat.Depth32Stencil8:
|
|
1258
1100
|
return {
|
|
1259
1101
|
internalFormat: gl.DEPTH32F_STENCIL8,
|
|
@@ -1267,23 +1109,22 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1267
1109
|
}
|
|
1268
1110
|
};
|
|
1269
1111
|
/**
|
|
1270
|
-
* In WebGL 1, internalformat must be the same as baseFormat when call texImage2D.
|
|
1271
1112
|
* @internal
|
|
1272
|
-
*/ GLTexture._getRenderBufferDepthFormatDetail = function _getRenderBufferDepthFormatDetail(format, gl
|
|
1113
|
+
*/ GLTexture._getRenderBufferDepthFormatDetail = function _getRenderBufferDepthFormatDetail(format, gl) {
|
|
1273
1114
|
switch(format){
|
|
1274
1115
|
case TextureFormat.Depth:
|
|
1275
1116
|
return {
|
|
1276
|
-
internalFormat:
|
|
1117
|
+
internalFormat: gl.DEPTH_COMPONENT32F,
|
|
1277
1118
|
baseFormat: gl.DEPTH_COMPONENT,
|
|
1278
|
-
dataType:
|
|
1119
|
+
dataType: gl.FLOAT,
|
|
1279
1120
|
isCompressed: false,
|
|
1280
1121
|
attachment: gl.DEPTH_ATTACHMENT
|
|
1281
1122
|
};
|
|
1282
1123
|
case TextureFormat.DepthStencil:
|
|
1283
1124
|
return {
|
|
1284
|
-
internalFormat:
|
|
1125
|
+
internalFormat: gl.DEPTH32F_STENCIL8,
|
|
1285
1126
|
baseFormat: gl.DEPTH_STENCIL,
|
|
1286
|
-
dataType:
|
|
1127
|
+
dataType: gl.FLOAT_32_UNSIGNED_INT_24_8_REV,
|
|
1287
1128
|
isCompressed: false,
|
|
1288
1129
|
attachment: gl.DEPTH_STENCIL_ATTACHMENT
|
|
1289
1130
|
};
|
|
@@ -1305,7 +1146,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1305
1146
|
};
|
|
1306
1147
|
case TextureFormat.Depth24Stencil8:
|
|
1307
1148
|
return {
|
|
1308
|
-
internalFormat:
|
|
1149
|
+
internalFormat: gl.DEPTH24_STENCIL8,
|
|
1309
1150
|
baseFormat: gl.DEPTH_STENCIL,
|
|
1310
1151
|
dataType: gl.UNSIGNED_INT_24_8,
|
|
1311
1152
|
isCompressed: false,
|
|
@@ -1339,19 +1180,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1339
1180
|
throw new Error("this TextureFormat is not supported in Galacean Engine: " + format);
|
|
1340
1181
|
}
|
|
1341
1182
|
};
|
|
1342
|
-
/**
|
|
1343
|
-
* @internal
|
|
1344
|
-
*/ GLTexture._supportRenderBufferDepthFormat = function _supportRenderBufferDepthFormat(format, rhi) {
|
|
1345
|
-
if (!rhi.isWebGL2) {
|
|
1346
|
-
switch(format){
|
|
1347
|
-
case TextureFormat.Depth24:
|
|
1348
|
-
case TextureFormat.Depth32:
|
|
1349
|
-
case TextureFormat.Depth32Stencil8:
|
|
1350
|
-
return false;
|
|
1351
|
-
}
|
|
1352
|
-
}
|
|
1353
|
-
return true;
|
|
1354
|
-
};
|
|
1355
1183
|
_create_class(GLTexture, [
|
|
1356
1184
|
{
|
|
1357
1185
|
key: "wrapModeU",
|
|
@@ -1401,15 +1229,16 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1401
1229
|
set: /**
|
|
1402
1230
|
* Anisotropic level for texture.
|
|
1403
1231
|
*/ function set(value) {
|
|
1404
|
-
var
|
|
1232
|
+
var extension = this._rhi.requireExtension(GLCapabilityType.textureFilterAnisotropic);
|
|
1233
|
+
if (!extension) return;
|
|
1405
1234
|
this._bind();
|
|
1406
|
-
|
|
1235
|
+
this._gl.texParameterf(this._target, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(value, this._rhi.capability.maxAnisoLevel));
|
|
1407
1236
|
}
|
|
1408
1237
|
},
|
|
1409
1238
|
{
|
|
1410
1239
|
key: "depthCompareFunction",
|
|
1411
1240
|
set: function set(value) {
|
|
1412
|
-
if (
|
|
1241
|
+
if (value === undefined) return;
|
|
1413
1242
|
this._bind();
|
|
1414
1243
|
var gl = this._gl;
|
|
1415
1244
|
switch(value){
|
|
@@ -1452,11 +1281,9 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1452
1281
|
this._curMipLevel = 0;
|
|
1453
1282
|
this._curFaceIndex = undefined;
|
|
1454
1283
|
this._gl = rhi.gl;
|
|
1455
|
-
this._isWebGL2 = rhi.isWebGL2;
|
|
1456
1284
|
this._target = target;
|
|
1457
1285
|
this._antiAliasing = Math.min(target.antiAliasing, rhi.capability.maxAntiAliasing);
|
|
1458
1286
|
/** @ts-ignore */ var _colorTextures = target._colorTextures, _depth = target._depth, width = target.width, height = target.height;
|
|
1459
|
-
var isDepthTexture = _instanceof(_depth, Texture);
|
|
1460
1287
|
/** todo
|
|
1461
1288
|
* MRT + Cube + [,MSAA]
|
|
1462
1289
|
* MRT + MSAA
|
|
@@ -1469,18 +1296,12 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1469
1296
|
throw new Error("If you want to use sRGB color space, only R8G8B8A8 format is supported in RenderTarget");
|
|
1470
1297
|
}
|
|
1471
1298
|
}
|
|
1472
|
-
if (!isDepthTexture && _depth !== null && !GLTexture._supportRenderBufferDepthFormat(_depth, rhi)) {
|
|
1473
|
-
throw new Error("TextureFormat is not supported:" + TextureFormat[_depth] + " in RenderTarget");
|
|
1474
|
-
}
|
|
1475
|
-
if (_colorTextures.length > 1 && !rhi.canIUse(GLCapabilityType.drawBuffers)) {
|
|
1476
|
-
throw new Error("MRT is not supported");
|
|
1477
|
-
}
|
|
1478
1299
|
if (_colorTextures.some(function(v) {
|
|
1479
1300
|
return v.width !== width || v.height !== height;
|
|
1480
1301
|
})) {
|
|
1481
1302
|
throw new Error("ColorTexture's size must as same as RenderTarget");
|
|
1482
1303
|
}
|
|
1483
|
-
if (
|
|
1304
|
+
if (_instanceof(_depth, Texture) && (_depth.width !== width || _depth.height !== height)) {
|
|
1484
1305
|
throw new Error("DepthTexture's size must as same as RenderTarget");
|
|
1485
1306
|
}
|
|
1486
1307
|
// todo: necessary to support MRT + Cube + [,MSAA] ?
|
|
@@ -1526,7 +1347,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1526
1347
|
} else {
|
|
1527
1348
|
if (mipChanged) {
|
|
1528
1349
|
// @ts-ignore
|
|
1529
|
-
var internalFormat = GLTexture._getRenderBufferDepthFormatDetail(target._depth, gl
|
|
1350
|
+
var internalFormat = GLTexture._getRenderBufferDepthFormatDetail(target._depth, gl).internalFormat;
|
|
1530
1351
|
gl.bindRenderbuffer(gl.RENDERBUFFER, this._depthRenderBuffer);
|
|
1531
1352
|
gl.renderbufferStorage(gl.RENDERBUFFER, internalFormat, target.width >> mipLevel, target.height >> mipLevel);
|
|
1532
1353
|
}
|
|
@@ -1575,7 +1396,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1575
1396
|
};
|
|
1576
1397
|
_proto._bindMainFBO = function _bindMainFBO() {
|
|
1577
1398
|
var gl = this._gl;
|
|
1578
|
-
var isWebGL2 = this._isWebGL2;
|
|
1579
1399
|
var _this__target = this._target, _depth = _this__target._depth, colorTextureCount = _this__target.colorTextureCount; _this__target.width; _this__target.height;
|
|
1580
1400
|
var drawBuffers = new Array(colorTextureCount);
|
|
1581
1401
|
gl.bindFramebuffer(gl.FRAMEBUFFER, this._frameBuffer);
|
|
@@ -1598,7 +1418,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1598
1418
|
gl.framebufferTexture2D(gl.FRAMEBUFFER, platformTexture._formatDetail.attachment, gl.TEXTURE_2D, platformTexture._glTexture, 0);
|
|
1599
1419
|
}
|
|
1600
1420
|
} else if (this._antiAliasing <= 1) {
|
|
1601
|
-
var _GLTexture__getRenderBufferDepthFormatDetail = GLTexture._getRenderBufferDepthFormatDetail(_depth, gl
|
|
1421
|
+
var _GLTexture__getRenderBufferDepthFormatDetail = GLTexture._getRenderBufferDepthFormatDetail(_depth, gl), internalFormat = _GLTexture__getRenderBufferDepthFormatDetail.internalFormat, attachment1 = _GLTexture__getRenderBufferDepthFormatDetail.attachment;
|
|
1602
1422
|
this._depthRenderBuffer = this._createRenderBuffer(internalFormat, attachment1);
|
|
1603
1423
|
}
|
|
1604
1424
|
}
|
|
@@ -1607,7 +1427,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1607
1427
|
};
|
|
1608
1428
|
_proto._bindMSAAFBO = function _bindMSAAFBO() {
|
|
1609
1429
|
var gl = this._gl;
|
|
1610
|
-
var isWebGL2 = this._isWebGL2;
|
|
1611
1430
|
var _this__target = this._target, _depth = _this__target._depth, colorTextureCount = _this__target.colorTextureCount;
|
|
1612
1431
|
this._blitDrawBuffers = new Array(colorTextureCount);
|
|
1613
1432
|
gl.bindFramebuffer(gl.FRAMEBUFFER, this._MSAAFrameBuffer);
|
|
@@ -1620,7 +1439,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1620
1439
|
gl.drawBuffers(this._oriDrawBuffers);
|
|
1621
1440
|
// prepare MSAA depth RBO
|
|
1622
1441
|
if (_depth !== null) {
|
|
1623
|
-
var _ref = _instanceof(_depth, Texture) ? _depth._platformTexture._formatDetail : GLTexture._getRenderBufferDepthFormatDetail(_depth, gl
|
|
1442
|
+
var _ref = _instanceof(_depth, Texture) ? _depth._platformTexture._formatDetail : GLTexture._getRenderBufferDepthFormatDetail(_depth, gl), internalFormat1 = _ref.internalFormat, attachment = _ref.attachment;
|
|
1624
1443
|
this._MSAADepthRenderBuffer = this._createRenderBuffer(internalFormat1, attachment);
|
|
1625
1444
|
}
|
|
1626
1445
|
this._checkFrameBuffer();
|
|
@@ -1670,12 +1489,11 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1670
1489
|
_inherits(GLTexture2D, GLTexture1);
|
|
1671
1490
|
function GLTexture2D(rhi, texture2D) {
|
|
1672
1491
|
var _this;
|
|
1673
|
-
_this = GLTexture1.call(this, rhi, texture2D, rhi.gl.TEXTURE_2D) || this
|
|
1674
|
-
_this._validate(texture2D
|
|
1492
|
+
_this = GLTexture1.call(this, rhi, texture2D, rhi.gl.TEXTURE_2D) || this;
|
|
1493
|
+
_this._validate(texture2D);
|
|
1675
1494
|
var format = texture2D.format, isSRGBColorSpace = texture2D.isSRGBColorSpace;
|
|
1676
|
-
|
|
1677
|
-
_this.
|
|
1678
|
-
_this._formatDetail.isCompressed && !isWebGL2 || _this._init(false);
|
|
1495
|
+
_this._formatDetail = GLTexture._getFormatDetail(format, isSRGBColorSpace, _this._gl);
|
|
1496
|
+
_this._init(false);
|
|
1679
1497
|
return _this;
|
|
1680
1498
|
}
|
|
1681
1499
|
var _proto = GLTexture2D.prototype;
|
|
@@ -1691,15 +1509,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1691
1509
|
height = height || mipHeight - y;
|
|
1692
1510
|
this._bind();
|
|
1693
1511
|
if (formatDetail.isCompressed) {
|
|
1694
|
-
|
|
1695
|
-
var internalFormat = formatDetail.internalFormat;
|
|
1696
|
-
var mipBit = 1 << mipLevel;
|
|
1697
|
-
if (isWebGL2 || this._compressedMipFilled & mipBit) {
|
|
1698
|
-
gl.compressedTexSubImage2D(this._target, mipLevel, x, y, width, height, internalFormat, colorBuffer);
|
|
1699
|
-
} else {
|
|
1700
|
-
gl.compressedTexImage2D(this._target, mipLevel, internalFormat, width, height, 0, colorBuffer);
|
|
1701
|
-
this._compressedMipFilled |= mipBit;
|
|
1702
|
-
}
|
|
1512
|
+
gl.compressedTexSubImage2D(this._target, mipLevel, x, y, width, height, formatDetail.internalFormat, colorBuffer);
|
|
1703
1513
|
} else {
|
|
1704
1514
|
var baseFormat = formatDetail.baseFormat, dataType = formatDetail.dataType;
|
|
1705
1515
|
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 0);
|
|
@@ -1739,14 +1549,11 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1739
1549
|
_inherits(GLTexture2DArray, GLTexture1);
|
|
1740
1550
|
function GLTexture2DArray(rhi, texture2DArray) {
|
|
1741
1551
|
var _this;
|
|
1742
|
-
if (!rhi.isWebGL2) {
|
|
1743
|
-
throw new Error("Texture2D Array is not supported in WebGL1.0");
|
|
1744
|
-
}
|
|
1745
1552
|
_this = GLTexture1.call(this, rhi, texture2DArray, rhi.gl.TEXTURE_2D_ARRAY) || this;
|
|
1746
|
-
_this._validate(texture2DArray
|
|
1553
|
+
_this._validate(texture2DArray);
|
|
1747
1554
|
var format = texture2DArray.format, width = texture2DArray.width, height = texture2DArray.height, length = texture2DArray.length, mipmapCount = texture2DArray.mipmapCount, isSRGBColorSpace = texture2DArray.isSRGBColorSpace;
|
|
1748
1555
|
_this._bind();
|
|
1749
|
-
_this._formatDetail = GLTexture._getFormatDetail(format, isSRGBColorSpace, _this._gl
|
|
1556
|
+
_this._formatDetail = GLTexture._getFormatDetail(format, isSRGBColorSpace, _this._gl);
|
|
1750
1557
|
_this._gl.texStorage3D(_this._target, mipmapCount, _this._formatDetail.internalFormat, width, height, length);
|
|
1751
1558
|
return _this;
|
|
1752
1559
|
}
|
|
@@ -1794,7 +1601,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1794
1601
|
gl.readPixels(x, y, width, height, formatDetail.baseFormat, formatDetail.dataType, out);
|
|
1795
1602
|
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
1796
1603
|
};
|
|
1797
|
-
_proto._validate = function _validate(texture
|
|
1604
|
+
_proto._validate = function _validate(texture) {
|
|
1798
1605
|
var format = texture.format;
|
|
1799
1606
|
// Validate sRGB format
|
|
1800
1607
|
// @ts-ignore
|
|
@@ -1814,19 +1621,11 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1814
1621
|
_inherits(GLTextureCube, GLTexture1);
|
|
1815
1622
|
function GLTextureCube(rhi, textureCube) {
|
|
1816
1623
|
var _this;
|
|
1817
|
-
_this = GLTexture1.call(this, rhi, textureCube, rhi.gl.TEXTURE_CUBE_MAP) || this
|
|
1818
|
-
|
|
1819
|
-
0,
|
|
1820
|
-
0,
|
|
1821
|
-
0,
|
|
1822
|
-
0,
|
|
1823
|
-
0
|
|
1824
|
-
];
|
|
1825
|
-
_this._validate(textureCube, rhi);
|
|
1624
|
+
_this = GLTexture1.call(this, rhi, textureCube, rhi.gl.TEXTURE_CUBE_MAP) || this;
|
|
1625
|
+
_this._validate(textureCube);
|
|
1826
1626
|
var format = textureCube.format, isSRGBColorSpace = textureCube.isSRGBColorSpace;
|
|
1827
|
-
|
|
1828
|
-
_this.
|
|
1829
|
-
_this._formatDetail.isCompressed && !isWebGL2 || _this._init(true);
|
|
1627
|
+
_this._formatDetail = GLTexture._getFormatDetail(format, isSRGBColorSpace, _this._gl);
|
|
1628
|
+
_this._init(true);
|
|
1830
1629
|
return _this;
|
|
1831
1630
|
}
|
|
1832
1631
|
var _proto = GLTextureCube.prototype;
|
|
@@ -1834,21 +1633,14 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1834
1633
|
* {@inheritDoc IPlatformTextureCube.setPixelBuffer}
|
|
1835
1634
|
*/ _proto.setPixelBuffer = function setPixelBuffer(face, colorBuffer, mipLevel, x, y, width, height) {
|
|
1836
1635
|
var gl = this._gl;
|
|
1837
|
-
var isWebGL2 = this._isWebGL2;
|
|
1838
1636
|
var formatDetail = this._formatDetail;
|
|
1839
|
-
var
|
|
1637
|
+
var baseFormat = formatDetail.baseFormat, dataType = formatDetail.dataType, isCompressed = formatDetail.isCompressed;
|
|
1840
1638
|
var mipSize = Math.max(1, this._texture.width >> mipLevel);
|
|
1841
1639
|
width = width || mipSize - x;
|
|
1842
1640
|
height = height || mipSize - y;
|
|
1843
1641
|
this._bind();
|
|
1844
1642
|
if (isCompressed) {
|
|
1845
|
-
|
|
1846
|
-
if (isWebGL2 || this._compressedFaceFilled[face] & mipBit) {
|
|
1847
|
-
gl.compressedTexSubImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + face, mipLevel, x, y, width, height, internalFormat, colorBuffer);
|
|
1848
|
-
} else {
|
|
1849
|
-
gl.compressedTexImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + face, mipLevel, internalFormat, width, height, 0, colorBuffer);
|
|
1850
|
-
this._compressedFaceFilled[face] |= mipBit;
|
|
1851
|
-
}
|
|
1643
|
+
gl.compressedTexSubImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + face, mipLevel, x, y, width, height, formatDetail.internalFormat, colorBuffer);
|
|
1852
1644
|
} else {
|
|
1853
1645
|
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 0);
|
|
1854
1646
|
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 0);
|
|
@@ -2017,15 +1809,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2017
1809
|
}();
|
|
2018
1810
|
|
|
2019
1811
|
/**
|
|
2020
|
-
* WebGL
|
|
2021
|
-
*/ var WebGLMode = /*#__PURE__*/ function(WebGLMode) {
|
|
2022
|
-
/** Auto, use WebGL2.0 if support, or will fallback to WebGL1.0. */ WebGLMode[WebGLMode["Auto"] = 0] = "Auto";
|
|
2023
|
-
/** WebGL2.0. */ WebGLMode[WebGLMode["WebGL2"] = 1] = "WebGL2";
|
|
2024
|
-
/** WebGL1.0, */ WebGLMode[WebGLMode["WebGL1"] = 2] = "WebGL1";
|
|
2025
|
-
return WebGLMode;
|
|
2026
|
-
}({});
|
|
2027
|
-
/**
|
|
2028
|
-
* WebGL graphic device, including WebGL1.0 and WebGL2.0.
|
|
1812
|
+
* WebGL graphic device, using WebGL2.0.
|
|
2029
1813
|
*/ var WebGLGraphicDevice = /*#__PURE__*/ function() {
|
|
2030
1814
|
function WebGLGraphicDevice(initializeOptions) {
|
|
2031
1815
|
if (initializeOptions === void 0) initializeOptions = {};
|
|
@@ -2041,7 +1825,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2041
1825
|
this._lastClearColor = new Color(null, null, null, null);
|
|
2042
1826
|
this._scissorEnable = false;
|
|
2043
1827
|
var options = _extends({
|
|
2044
|
-
webGLMode: 0,
|
|
2045
1828
|
_forceFlush: false,
|
|
2046
1829
|
_maxAllowSkinUniformVectorCount: 256,
|
|
2047
1830
|
alpha: true,
|
|
@@ -2084,40 +1867,26 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2084
1867
|
var _proto = WebGLGraphicDevice.prototype;
|
|
2085
1868
|
_proto.init = function init(canvas, onDeviceLost, onDeviceRestored) {
|
|
2086
1869
|
var webCanvas = canvas._webCanvas;
|
|
2087
|
-
var webGLMode = this._options.webGLMode;
|
|
2088
|
-
this._onDeviceLost = onDeviceLost;
|
|
2089
|
-
this._onDeviceRestored = onDeviceRestored;
|
|
2090
|
-
webCanvas.addEventListener("webglcontextlost", this._onWebGLContextLost, false);
|
|
2091
|
-
webCanvas.addEventListener("webglcontextrestored", this._onWebGLContextRestored, false);
|
|
2092
1870
|
webCanvas.addEventListener("webglcontextcreationerror", this._onContextCreationError, false);
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
if (webGLMode == 0 || webGLMode == 1) {
|
|
2097
|
-
gl = webCanvas.getContext("webgl2", webGLOptions);
|
|
1871
|
+
try {
|
|
1872
|
+
var webGLOptions = this._webGLOptions;
|
|
1873
|
+
var gl = webCanvas.getContext("webgl2", webGLOptions);
|
|
2098
1874
|
if (!gl && !canvas._isOffscreenCanvas()) {
|
|
2099
1875
|
gl = webCanvas.getContext("experimental-webgl2", webGLOptions);
|
|
2100
1876
|
}
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
if (gl && !gl.deleteQuery) {
|
|
2104
|
-
this._isWebGL2 = false;
|
|
2105
|
-
}
|
|
2106
|
-
}
|
|
2107
|
-
if (!gl) {
|
|
2108
|
-
if (webGLMode == 0 || webGLMode == 2) {
|
|
2109
|
-
gl = webCanvas.getContext("webgl", webGLOptions);
|
|
2110
|
-
if (!gl && !canvas._isOffscreenCanvas()) {
|
|
2111
|
-
gl = webCanvas.getContext("experimental-webgl", webGLOptions);
|
|
2112
|
-
}
|
|
2113
|
-
this._isWebGL2 = false;
|
|
1877
|
+
if (!gl || !gl.deleteQuery) {
|
|
1878
|
+
throw new Error("WebGL2 is not supported.");
|
|
2114
1879
|
}
|
|
1880
|
+
this._gl = gl;
|
|
1881
|
+
this._initGLState(gl);
|
|
1882
|
+
} finally{
|
|
1883
|
+
webCanvas.removeEventListener("webglcontextcreationerror", this._onContextCreationError, false);
|
|
2115
1884
|
}
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
this.
|
|
2120
|
-
this.
|
|
1885
|
+
this._webCanvas = webCanvas;
|
|
1886
|
+
this._onDeviceLost = onDeviceLost;
|
|
1887
|
+
this._onDeviceRestored = onDeviceRestored;
|
|
1888
|
+
webCanvas.addEventListener("webglcontextlost", this._onWebGLContextLost, false);
|
|
1889
|
+
webCanvas.addEventListener("webglcontextrestored", this._onWebGLContextRestored, false);
|
|
2121
1890
|
};
|
|
2122
1891
|
_proto.createPlatformPrimitive = function createPlatformPrimitive(primitive) {
|
|
2123
1892
|
return new GLPrimitive(this, primitive);
|
|
@@ -2159,18 +1928,14 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2159
1928
|
/**
|
|
2160
1929
|
* Enable GL_RASTERIZER_DISCARD (WebGL2 only).
|
|
2161
1930
|
*/ _proto.enableRasterizerDiscard = function enableRasterizerDiscard() {
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
gl.enable(gl.RASTERIZER_DISCARD);
|
|
2165
|
-
}
|
|
1931
|
+
var gl = this._gl;
|
|
1932
|
+
gl.enable(gl.RASTERIZER_DISCARD);
|
|
2166
1933
|
};
|
|
2167
1934
|
/**
|
|
2168
1935
|
* Disable GL_RASTERIZER_DISCARD (WebGL2 only).
|
|
2169
1936
|
*/ _proto.disableRasterizerDiscard = function disableRasterizerDiscard() {
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
gl.disable(gl.RASTERIZER_DISCARD);
|
|
2173
|
-
}
|
|
1937
|
+
var gl = this._gl;
|
|
1938
|
+
gl.disable(gl.RASTERIZER_DISCARD);
|
|
2174
1939
|
};
|
|
2175
1940
|
/**
|
|
2176
1941
|
* Invalidate the cached shader program state.
|
|
@@ -2294,10 +2059,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2294
2059
|
this.scissor(x, y, width, height);
|
|
2295
2060
|
};
|
|
2296
2061
|
_proto.blitInternalRTByBlitFrameBuffer = function blitInternalRTByBlitFrameBuffer(srcRT, destRT, clearFlags, viewport) {
|
|
2297
|
-
if (!this._isWebGL2) {
|
|
2298
|
-
Logger.warn("WebGL1.0 not support blit frame buffer.");
|
|
2299
|
-
return;
|
|
2300
|
-
}
|
|
2301
2062
|
var gl = this._gl;
|
|
2302
2063
|
// @ts-ignore
|
|
2303
2064
|
var srcFrameBuffer = srcRT ? srcRT._platformRenderTarget._frameBuffer : null;
|
|
@@ -2425,13 +2186,10 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2425
2186
|
if (debugRenderInfo != null) {
|
|
2426
2187
|
this._renderer = gl.getParameter(debugRenderInfo.UNMASKED_RENDERER_WEBGL);
|
|
2427
2188
|
}
|
|
2428
|
-
|
|
2429
|
-
this.maxUniformBlockSize = gl.getParameter(gl.MAX_UNIFORM_BLOCK_SIZE);
|
|
2430
|
-
}
|
|
2189
|
+
this.maxUniformBlockSize = gl.getParameter(gl.MAX_UNIFORM_BLOCK_SIZE);
|
|
2431
2190
|
};
|
|
2432
2191
|
_proto.destroy = function destroy() {
|
|
2433
2192
|
var webCanvas = this._webCanvas;
|
|
2434
|
-
webCanvas.removeEventListener("webglcontextcreationerror", this._onContextCreationError, false);
|
|
2435
2193
|
webCanvas.removeEventListener("webglcontextlost", this._onWebGLContextLost, false);
|
|
2436
2194
|
webCanvas.removeEventListener("webglcontextrestored", this._onWebGLContextRestored, false);
|
|
2437
2195
|
};
|
|
@@ -2446,12 +2204,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2446
2204
|
this._onDeviceRestored();
|
|
2447
2205
|
};
|
|
2448
2206
|
_create_class(WebGLGraphicDevice, [
|
|
2449
|
-
{
|
|
2450
|
-
key: "isWebGL2",
|
|
2451
|
-
get: function get() {
|
|
2452
|
-
return this._isWebGL2;
|
|
2453
|
-
}
|
|
2454
|
-
},
|
|
2455
2207
|
{
|
|
2456
2208
|
key: "renderer",
|
|
2457
2209
|
get: function get() {
|
|
@@ -2462,7 +2214,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2462
2214
|
key: "gl",
|
|
2463
2215
|
get: /**
|
|
2464
2216
|
* GL Context
|
|
2465
|
-
* @member {
|
|
2217
|
+
* @member {WebGL2RenderingContext}
|
|
2466
2218
|
*/ function get() {
|
|
2467
2219
|
return this._gl;
|
|
2468
2220
|
}
|
|
@@ -2478,16 +2230,10 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2478
2230
|
get: function get() {
|
|
2479
2231
|
return this._capability;
|
|
2480
2232
|
}
|
|
2481
|
-
},
|
|
2482
|
-
{
|
|
2483
|
-
key: "canIUseMoreJoints",
|
|
2484
|
-
get: function get() {
|
|
2485
|
-
return this.capability.canIUseMoreJoints;
|
|
2486
|
-
}
|
|
2487
2233
|
}
|
|
2488
2234
|
]);
|
|
2489
2235
|
return WebGLGraphicDevice;
|
|
2490
2236
|
}();
|
|
2491
2237
|
|
|
2492
|
-
export { GLCompressedTextureInternalFormat, WebCanvas, WebGLEngine, WebGLGraphicDevice
|
|
2238
|
+
export { GLCompressedTextureInternalFormat, WebCanvas, WebGLEngine, WebGLGraphicDevice };
|
|
2493
2239
|
//# sourceMappingURL=module.js.map
|