@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/main.js
CHANGED
|
@@ -5,9 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var engineCore = require('@galacean/engine-core');
|
|
6
6
|
var engineMath = require('@galacean/engine-math');
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
* Smoothing plug-in.
|
|
10
|
-
* */ var GLCompressedTextureInternalFormat = /*#__PURE__*/ function(GLCompressedTextureInternalFormat) {
|
|
8
|
+
var GLCompressedTextureInternalFormat = /*#__PURE__*/ function(GLCompressedTextureInternalFormat) {
|
|
11
9
|
// astc
|
|
12
10
|
GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["RGBA_ASTC_4X4_KHR"] = 37808] = "RGBA_ASTC_4X4_KHR";
|
|
13
11
|
GLCompressedTextureInternalFormat[GLCompressedTextureInternalFormat["RGBA_ASTC_5X4_KHR"] = 37809] = "RGBA_ASTC_5X4_KHR";
|
|
@@ -232,7 +230,7 @@ function _create_class(Constructor, protoProps, staticProps) {
|
|
|
232
230
|
}
|
|
233
231
|
|
|
234
232
|
/**
|
|
235
|
-
* WebGL platform engine, supports WebGL
|
|
233
|
+
* WebGL platform engine, supports WebGL 2.0.
|
|
236
234
|
*/ var WebGLEngine = /*#__PURE__*/ function(Engine) {
|
|
237
235
|
_inherits(WebGLEngine, Engine);
|
|
238
236
|
function WebGLEngine() {
|
|
@@ -298,7 +296,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
298
296
|
this._glBuffer = glBuffer;
|
|
299
297
|
this._glBufferUsage = glBufferUsage;
|
|
300
298
|
this._glBindTarget = glBindTarget;
|
|
301
|
-
this._isWebGL2 = rhi.isWebGL2;
|
|
302
299
|
this.bind();
|
|
303
300
|
if (data) {
|
|
304
301
|
gl.bufferData(glBindTarget, data, glBufferUsage);
|
|
@@ -323,7 +320,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
323
320
|
var dataByteLength = dataLength ? byteSize * dataLength : data.byteLength;
|
|
324
321
|
if (dataOffset !== 0 || dataByteLength < data.byteLength) {
|
|
325
322
|
var isArrayBufferView = data.byteOffset !== undefined;
|
|
326
|
-
if (
|
|
323
|
+
if (isArrayBufferView) {
|
|
327
324
|
gl.bufferSubData(glBindTarget, bufferByteOffset, data, dataOffset, dataByteLength / byteSize);
|
|
328
325
|
} else {
|
|
329
326
|
var subData = new Uint8Array(isArrayBufferView ? data.buffer : data, dataOffset * byteSize, dataByteLength);
|
|
@@ -335,13 +332,8 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
335
332
|
gl.bindBuffer(glBindTarget, null);
|
|
336
333
|
};
|
|
337
334
|
_proto.getData = function getData(data, bufferByteOffset, dataOffset, dataLength) {
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
this.bind();
|
|
341
|
-
gl.getBufferSubData(this._glBindTarget, bufferByteOffset, data, dataOffset, dataLength);
|
|
342
|
-
} else {
|
|
343
|
-
throw "Buffer is write-only on WebGL1.0 platforms.";
|
|
344
|
-
}
|
|
335
|
+
this.bind();
|
|
336
|
+
this._gl.getBufferSubData(this._glBindTarget, bufferByteOffset, data, dataOffset, dataLength);
|
|
345
337
|
};
|
|
346
338
|
_proto.copyFromBuffer = function copyFromBuffer(srcBuffer, srcByteOffset, dstByteOffset, byteLength) {
|
|
347
339
|
var gl = this._gl;
|
|
@@ -376,7 +368,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
376
368
|
this._rhi = rhi;
|
|
377
369
|
this.capabilityList = new Map();
|
|
378
370
|
this._init();
|
|
379
|
-
this._compatibleAllInterface();
|
|
380
371
|
}
|
|
381
372
|
var _proto = GLCapability.prototype;
|
|
382
373
|
/**
|
|
@@ -392,9 +383,9 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
392
383
|
RGB_ETC1_WEBGL = GLCompressedTextureInternalFormat.RGB_ETC1_WEBGL, // etc
|
|
393
384
|
R11_EAC = GLCompressedTextureInternalFormat.R11_EAC, SRGB8_ALPHA8_ETC2_EAC = GLCompressedTextureInternalFormat.SRGB8_ALPHA8_ETC2_EAC, // pvrtc
|
|
394
385
|
RGB_PVRTC_4BPPV1_IMG = GLCompressedTextureInternalFormat.RGB_PVRTC_4BPPV1_IMG, RGBA_PVRTC_2BPPV1_IMG = GLCompressedTextureInternalFormat.RGBA_PVRTC_2BPPV1_IMG, // s3tc
|
|
395
|
-
RGB_S3TC_DXT1_EXT = GLCompressedTextureInternalFormat.RGB_S3TC_DXT1_EXT, RGBA_S3TC_DXT5_EXT = GLCompressedTextureInternalFormat.RGBA_S3TC_DXT5_EXT, // bptc
|
|
386
|
+
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
|
|
396
387
|
RGBA_BPTC_UNORM_EXT = GLCompressedTextureInternalFormat.RGBA_BPTC_UNORM_EXT, RGB_BPTC_UNSIGNED_FLOAT_EXT = GLCompressedTextureInternalFormat.RGB_BPTC_UNSIGNED_FLOAT_EXT;
|
|
397
|
-
if (internalType >= RGBA_ASTC_4X4_KHR &&
|
|
388
|
+
if (internalType >= RGBA_ASTC_4X4_KHR && internalType <= RGBA_ASTC_12X12_KHR || internalType >= SRGB8_ALPHA8_ASTC_4X4_KHR && internalType <= SRGB8_ALPHA8_ASTC_12X12_KHR) {
|
|
398
389
|
return this.canIUse(engineCore.GLCapabilityType.astc);
|
|
399
390
|
} else if (internalType === RGB_ETC1_WEBGL) {
|
|
400
391
|
return this.canIUse(engineCore.GLCapabilityType.etc1);
|
|
@@ -404,6 +395,8 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
404
395
|
return this.canIUse(engineCore.GLCapabilityType.pvrtc);
|
|
405
396
|
} else if (internalType >= RGB_S3TC_DXT1_EXT && internalType <= RGBA_S3TC_DXT5_EXT) {
|
|
406
397
|
return this.canIUse(engineCore.GLCapabilityType.s3tc);
|
|
398
|
+
} else if (internalType >= SRGB_S3TC_DXT1_EXT && internalType <= SRGB_ALPHA_S3TC_DXT5_EXT) {
|
|
399
|
+
return this.canIUse(engineCore.GLCapabilityType.s3tc_srgb);
|
|
407
400
|
} else if (internalType >= RGBA_BPTC_UNORM_EXT && internalType <= RGB_BPTC_UNSIGNED_FLOAT_EXT) {
|
|
408
401
|
return this.canIUse(engineCore.GLCapabilityType.bptc);
|
|
409
402
|
}
|
|
@@ -413,25 +406,51 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
413
406
|
* Check whether the given texture format is supported.
|
|
414
407
|
*/ _proto.supportsTextureFormat = function supportsTextureFormat(format) {
|
|
415
408
|
switch(format){
|
|
409
|
+
case engineCore.TextureFormat.BC1:
|
|
410
|
+
case engineCore.TextureFormat.BC3:
|
|
411
|
+
return this.canIUse(engineCore.GLCapabilityType.s3tc);
|
|
412
|
+
case engineCore.TextureFormat.BC7:
|
|
413
|
+
case engineCore.TextureFormat.BC6H:
|
|
414
|
+
return this.canIUse(engineCore.GLCapabilityType.bptc);
|
|
415
|
+
case engineCore.TextureFormat.ETC1_RGB:
|
|
416
|
+
return this.canIUse(engineCore.GLCapabilityType.etc1);
|
|
417
|
+
case engineCore.TextureFormat.ETC2_RGB:
|
|
418
|
+
case engineCore.TextureFormat.ETC2_RGBA5:
|
|
419
|
+
case engineCore.TextureFormat.ETC2_RGBA8:
|
|
420
|
+
return this.canIUse(engineCore.GLCapabilityType.etc);
|
|
421
|
+
case engineCore.TextureFormat.PVRTC_RGB2:
|
|
422
|
+
case engineCore.TextureFormat.PVRTC_RGBA2:
|
|
423
|
+
case engineCore.TextureFormat.PVRTC_RGB4:
|
|
424
|
+
case engineCore.TextureFormat.PVRTC_RGBA4:
|
|
425
|
+
return this.canIUse(engineCore.GLCapabilityType.pvrtc);
|
|
426
|
+
case engineCore.TextureFormat.ASTC_4x4:
|
|
427
|
+
case engineCore.TextureFormat.ASTC_5x5:
|
|
428
|
+
case engineCore.TextureFormat.ASTC_6x6:
|
|
429
|
+
case engineCore.TextureFormat.ASTC_8x8:
|
|
430
|
+
case engineCore.TextureFormat.ASTC_10x10:
|
|
431
|
+
case engineCore.TextureFormat.ASTC_12x12:
|
|
432
|
+
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:
|
|
416
438
|
case engineCore.TextureFormat.R16G16B16A16:
|
|
417
|
-
return this.canIUse(engineCore.GLCapabilityType.textureHalfFloat);
|
|
418
439
|
case engineCore.TextureFormat.R32G32B32A32:
|
|
419
|
-
|
|
420
|
-
case engineCore.TextureFormat.
|
|
421
|
-
case engineCore.TextureFormat.
|
|
440
|
+
case engineCore.TextureFormat.R32G32B32A32_UInt:
|
|
441
|
+
case engineCore.TextureFormat.R11G11B10_UFloat:
|
|
442
|
+
case engineCore.TextureFormat.R8:
|
|
443
|
+
case engineCore.TextureFormat.R8G8:
|
|
422
444
|
case engineCore.TextureFormat.Depth:
|
|
423
445
|
case engineCore.TextureFormat.DepthStencil:
|
|
424
|
-
|
|
425
|
-
case engineCore.TextureFormat.R11G11B10_UFloat:
|
|
426
|
-
case engineCore.TextureFormat.R32G32B32A32_UInt:
|
|
446
|
+
case engineCore.TextureFormat.Depth16:
|
|
427
447
|
case engineCore.TextureFormat.Depth24:
|
|
428
448
|
case engineCore.TextureFormat.Depth32:
|
|
449
|
+
case engineCore.TextureFormat.Depth24Stencil8:
|
|
429
450
|
case engineCore.TextureFormat.Depth32Stencil8:
|
|
430
|
-
case engineCore.TextureFormat.R8:
|
|
431
|
-
case engineCore.TextureFormat.R8G8:
|
|
432
|
-
return this.rhi.isWebGL2;
|
|
433
|
-
default:
|
|
434
451
|
return true;
|
|
452
|
+
default:
|
|
453
|
+
return false;
|
|
435
454
|
}
|
|
436
455
|
};
|
|
437
456
|
/**
|
|
@@ -439,11 +458,11 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
439
458
|
*/ _proto.supportsRenderTargetColorFormat = function supportsRenderTargetColorFormat(format) {
|
|
440
459
|
switch(format){
|
|
441
460
|
case engineCore.TextureFormat.R16G16B16A16:
|
|
442
|
-
return this.canIUse(engineCore.GLCapabilityType.colorBufferHalfFloat)
|
|
461
|
+
return this.canIUse(engineCore.GLCapabilityType.colorBufferHalfFloat);
|
|
443
462
|
case engineCore.TextureFormat.R32G32B32A32:
|
|
444
|
-
return this.canIUse(engineCore.GLCapabilityType.colorBufferFloat)
|
|
463
|
+
return this.canIUse(engineCore.GLCapabilityType.colorBufferFloat);
|
|
445
464
|
case engineCore.TextureFormat.R11G11B10_UFloat:
|
|
446
|
-
return this.
|
|
465
|
+
return this.canIUse(engineCore.GLCapabilityType.colorBufferFloat);
|
|
447
466
|
default:
|
|
448
467
|
return this.supportsTextureFormat(format);
|
|
449
468
|
}
|
|
@@ -452,27 +471,12 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
452
471
|
* Init capabilities.
|
|
453
472
|
*/ _proto._init = function _init() {
|
|
454
473
|
var cap = this.capabilityList;
|
|
455
|
-
var isWebGL2 = this.rhi.isWebGL2;
|
|
456
474
|
var requireExtension = this.rhi.requireExtension.bind(this.rhi);
|
|
457
|
-
var
|
|
458
|
-
cap.set(shaderVertexID, isWebGL2);
|
|
459
|
-
cap.set(standardDerivatives, isWebGL2 || !!requireExtension(standardDerivatives));
|
|
460
|
-
cap.set(shaderTextureLod, isWebGL2 || !!requireExtension(shaderTextureLod));
|
|
461
|
-
cap.set(elementIndexUint, isWebGL2 || !!requireExtension(elementIndexUint));
|
|
462
|
-
cap.set(depthTexture, isWebGL2 || !!requireExtension(depthTexture));
|
|
463
|
-
cap.set(vertexArrayObject, isWebGL2 || !!requireExtension(vertexArrayObject));
|
|
464
|
-
cap.set(instancedArrays, isWebGL2 || !!requireExtension(instancedArrays));
|
|
465
|
-
cap.set(multipleSample, isWebGL2);
|
|
466
|
-
cap.set(drawBuffers, isWebGL2 || !!requireExtension(drawBuffers));
|
|
467
|
-
cap.set(blendMinMax, isWebGL2 || !!requireExtension(blendMinMax));
|
|
468
|
-
cap.set(textureFloat, isWebGL2 || !!requireExtension(textureFloat));
|
|
469
|
-
cap.set(textureHalfFloat, isWebGL2 || !!requireExtension(textureHalfFloat));
|
|
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;
|
|
470
476
|
cap.set(textureFloatLinear, !!requireExtension(textureFloatLinear));
|
|
471
|
-
cap.set(
|
|
472
|
-
cap.set(
|
|
473
|
-
cap.set(colorBufferHalfFloat, isWebGL2 && !!requireExtension(colorBufferFloat) || !!requireExtension(colorBufferHalfFloat));
|
|
477
|
+
cap.set(colorBufferFloat, !!requireExtension(colorBufferFloat));
|
|
478
|
+
cap.set(colorBufferHalfFloat, !!requireExtension(colorBufferFloat) || !!requireExtension(colorBufferHalfFloat));
|
|
474
479
|
cap.set(textureFilterAnisotropic, !!requireExtension(textureFilterAnisotropic));
|
|
475
|
-
cap.set(fragDepth, isWebGL2 || !!requireExtension(fragDepth));
|
|
476
480
|
cap.set(etc, !!(requireExtension(etc) || requireExtension(etc_webkit)));
|
|
477
481
|
cap.set(etc1, !!(requireExtension(etc1) || requireExtension(etc1_webkit)));
|
|
478
482
|
cap.set(pvrtc, !!(requireExtension(pvrtc) || requireExtension(pvrtc_webkit)));
|
|
@@ -482,85 +486,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
482
486
|
var astcExtension = requireExtension(astc) || requireExtension(astc_webkit);
|
|
483
487
|
cap.set(astc, !!astcExtension);
|
|
484
488
|
cap.set(astc_hdr, typeof (astcExtension == null ? void 0 : astcExtension.getSupportedProfiles) === "function" && astcExtension.getSupportedProfiles().includes("hdr"));
|
|
485
|
-
cap.set(sRGB, isWebGL2 || !!requireExtension(sRGB));
|
|
486
|
-
};
|
|
487
|
-
/**
|
|
488
|
-
* If there are extensions that can supplement this ability, smooth out the difference.
|
|
489
|
-
* @example
|
|
490
|
-
* compatible(GLCapabilityType.depthTexture,{
|
|
491
|
-
* UNSIGNED_INT_24_8: "UNSIGNED_INT_24_8_WEBGL"
|
|
492
|
-
* })
|
|
493
|
-
* gl.UNSIGNED_INT_24_8 = ext.UNSIGNED_INT_24_8_WEBGL
|
|
494
|
-
*/ _proto._compatibleInterface = function _compatibleInterface(capabilityType, flatItem) {
|
|
495
|
-
var rhi = this.rhi;
|
|
496
|
-
var gl = rhi.gl;
|
|
497
|
-
var ext = rhi.requireExtension(capabilityType);
|
|
498
|
-
if (ext) {
|
|
499
|
-
for(var glKey in flatItem){
|
|
500
|
-
var extensionKey = flatItem[glKey];
|
|
501
|
-
var extensionVal = ext[extensionKey];
|
|
502
|
-
// Mini game hack the native function,use “.bind” to smooth out if is “Funcion”.
|
|
503
|
-
if (extensionVal == null ? void 0 : extensionVal.bind) {
|
|
504
|
-
gl[glKey] = extensionVal.bind(ext);
|
|
505
|
-
} else {
|
|
506
|
-
gl[glKey] = extensionVal;
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
};
|
|
511
|
-
_proto._compatibleAllInterface = function _compatibleAllInterface() {
|
|
512
|
-
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, sRGB = engineCore.GLCapabilityType.sRGB;
|
|
513
|
-
var isWebGL2 = this.rhi.isWebGL2;
|
|
514
|
-
if (!isWebGL2) {
|
|
515
|
-
this._compatibleInterface(blendMinMax, {
|
|
516
|
-
MIN: "MIN_EXT",
|
|
517
|
-
MAX: "MAX_EXT"
|
|
518
|
-
});
|
|
519
|
-
this._compatibleInterface(depthTexture, {
|
|
520
|
-
UNSIGNED_INT_24_8: "UNSIGNED_INT_24_8_WEBGL"
|
|
521
|
-
});
|
|
522
|
-
this._compatibleInterface(vertexArrayObject, {
|
|
523
|
-
createVertexArray: "createVertexArrayOES",
|
|
524
|
-
deleteVertexArray: "deleteVertexArrayOES",
|
|
525
|
-
isVertexArray: "isVertexArrayOES",
|
|
526
|
-
bindVertexArray: "bindVertexArrayOES"
|
|
527
|
-
});
|
|
528
|
-
this._compatibleInterface(instancedArrays, {
|
|
529
|
-
drawArraysInstanced: "drawArraysInstancedANGLE",
|
|
530
|
-
drawElementsInstanced: "drawElementsInstancedANGLE",
|
|
531
|
-
vertexAttribDivisor: "vertexAttribDivisorANGLE"
|
|
532
|
-
});
|
|
533
|
-
this._compatibleInterface(drawBuffers, {
|
|
534
|
-
MAX_DRAW_BUFFERS: "MAX_DRAW_BUFFERS_WEBGL"
|
|
535
|
-
});
|
|
536
|
-
var items = {};
|
|
537
|
-
if (this.canIUse(engineCore.GLCapabilityType.drawBuffers)) {
|
|
538
|
-
var maxDrawBuffers = this.maxDrawBuffers;
|
|
539
|
-
for(var i = 0; i < maxDrawBuffers; i++){
|
|
540
|
-
i != 0 && (items["COLOR_ATTACHMENT" + i] = "COLOR_ATTACHMENT" + i + "_WEBGL");
|
|
541
|
-
items["DRAW_BUFFER" + i] = "DRAW_BUFFER" + i + "_WEBGL";
|
|
542
|
-
}
|
|
543
|
-
this._compatibleInterface(drawBuffers, _extends({
|
|
544
|
-
drawBuffers: "drawBuffersWEBGL"
|
|
545
|
-
}, items));
|
|
546
|
-
}
|
|
547
|
-
this._compatibleInterface(textureHalfFloat, {
|
|
548
|
-
HALF_FLOAT: "HALF_FLOAT_OES"
|
|
549
|
-
});
|
|
550
|
-
this._compatibleInterface(colorBufferHalfFloat, {
|
|
551
|
-
RGBA16F: "RBGA16F_EXT"
|
|
552
|
-
});
|
|
553
|
-
this._compatibleInterface(WEBGL_colorBufferFloat, {
|
|
554
|
-
RGBA32F: "RBGA32F_EXT"
|
|
555
|
-
});
|
|
556
|
-
this._compatibleInterface(sRGB, {
|
|
557
|
-
SRGB8: "SRGB_EXT",
|
|
558
|
-
SRGB8_ALPHA8: "SRGB_ALPHA_EXT"
|
|
559
|
-
});
|
|
560
|
-
}
|
|
561
|
-
this._compatibleInterface(textureFilterAnisotropic, {
|
|
562
|
-
TEXTURE_MAX_ANISOTROPY_EXT: "TEXTURE_MAX_ANISOTROPY_EXT"
|
|
563
|
-
});
|
|
564
489
|
};
|
|
565
490
|
_create_class(GLCapability, [
|
|
566
491
|
{
|
|
@@ -575,29 +500,11 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
575
500
|
return this.rhi.renderStates.getParameter(this.rhi.gl.MAX_VERTEX_UNIFORM_VECTORS);
|
|
576
501
|
}
|
|
577
502
|
},
|
|
578
|
-
{
|
|
579
|
-
key: "canUseFloatTextureBlendShape",
|
|
580
|
-
get: function get() {
|
|
581
|
-
return this.canIUse(engineCore.GLCapabilityType.shaderVertexID) && this.canIUse(engineCore.GLCapabilityType.textureFloat) && this.rhi.renderStates.getParameter(this.rhi.gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS) > 0;
|
|
582
|
-
}
|
|
583
|
-
},
|
|
584
|
-
{
|
|
585
|
-
key: "canIUseMoreJoints",
|
|
586
|
-
get: /**
|
|
587
|
-
* Whether can use more joints.
|
|
588
|
-
*/ function get() {
|
|
589
|
-
return this.canIUse(engineCore.GLCapabilityType.textureFloat) && this.rhi.renderStates.getParameter(this.rhi.gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS) > 0;
|
|
590
|
-
}
|
|
591
|
-
},
|
|
592
503
|
{
|
|
593
504
|
key: "maxDrawBuffers",
|
|
594
505
|
get: function get() {
|
|
595
506
|
if (!this._maxDrawBuffers) {
|
|
596
|
-
|
|
597
|
-
this._maxDrawBuffers = this._rhi.gl.getParameter(this._rhi.gl.MAX_DRAW_BUFFERS);
|
|
598
|
-
} else {
|
|
599
|
-
this._maxDrawBuffers = 1;
|
|
600
|
-
}
|
|
507
|
+
this._maxDrawBuffers = this._rhi.gl.getParameter(this._rhi.gl.MAX_DRAW_BUFFERS);
|
|
601
508
|
}
|
|
602
509
|
return this._maxDrawBuffers;
|
|
603
510
|
}
|
|
@@ -621,19 +528,11 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
621
528
|
*/ function get() {
|
|
622
529
|
if (!this._maxAntiAliasing) {
|
|
623
530
|
var gl = this._rhi.gl;
|
|
624
|
-
|
|
625
|
-
this._maxAntiAliasing = canMSAA ? gl.getParameter(gl.MAX_SAMPLES) : 1;
|
|
531
|
+
this._maxAntiAliasing = gl.getParameter(gl.MAX_SAMPLES);
|
|
626
532
|
}
|
|
627
533
|
return this._maxAntiAliasing;
|
|
628
534
|
}
|
|
629
535
|
},
|
|
630
|
-
{
|
|
631
|
-
key: "isFragmentHighPrecision",
|
|
632
|
-
get: function get() {
|
|
633
|
-
var gl = this._rhi.gl;
|
|
634
|
-
return gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.HIGH_FLOAT).precision !== 0;
|
|
635
|
-
}
|
|
636
|
-
},
|
|
637
536
|
{
|
|
638
537
|
key: "rhi",
|
|
639
538
|
get: function get() {
|
|
@@ -665,9 +564,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
665
564
|
}();
|
|
666
565
|
|
|
667
566
|
/**
|
|
668
|
-
* Improvement of VAO:
|
|
669
|
-
* 1) WebGL2.0 must support VAO, almost all devices support vao extensions in webgl1.0, we can use PollyFill,only keep VAO mode.
|
|
670
|
-
*/ /**
|
|
671
567
|
* @internal
|
|
672
568
|
* GL platform primitive.
|
|
673
569
|
*/ var GLPrimitive = /*#__PURE__*/ function() {
|
|
@@ -675,8 +571,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
675
571
|
this._attribLocArray = [];
|
|
676
572
|
this._vaoMap = new Map();
|
|
677
573
|
this._primitive = primitive;
|
|
678
|
-
this._canUseInstancedArrays = rhi.canIUse(engineCore.GLCapabilityType.instancedArrays);
|
|
679
|
-
this._isSupportVAO = rhi.canIUse(engineCore.GLCapabilityType.vertexArrayObject);
|
|
680
574
|
this._gl = rhi.gl;
|
|
681
575
|
}
|
|
682
576
|
var _proto = GLPrimitive.prototype;
|
|
@@ -685,7 +579,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
685
579
|
*/ _proto.draw = function draw(shaderProgram, subMesh) {
|
|
686
580
|
var gl = this._gl;
|
|
687
581
|
var primitive = this._primitive;
|
|
688
|
-
var useVao =
|
|
582
|
+
var useVao = primitive.enableVAO;
|
|
689
583
|
if (useVao) {
|
|
690
584
|
if (primitive._bufferStructChanged) {
|
|
691
585
|
this._clearVAO();
|
|
@@ -714,21 +608,17 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
714
608
|
gl.drawArrays(topology, start, count);
|
|
715
609
|
}
|
|
716
610
|
} else {
|
|
717
|
-
if (
|
|
718
|
-
if (
|
|
719
|
-
|
|
720
|
-
gl.drawElementsInstanced(topology, count, _glIndexType, start * _glIndexByteCount, instanceCount);
|
|
721
|
-
} else {
|
|
722
|
-
var _glBuffer1 = indexBufferBinding.buffer._platformBuffer._glBuffer;
|
|
723
|
-
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _glBuffer1);
|
|
724
|
-
gl.drawElementsInstanced(topology, count, _glIndexType, start * _glIndexByteCount, instanceCount);
|
|
725
|
-
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
|
|
726
|
-
}
|
|
611
|
+
if (indexBufferBinding) {
|
|
612
|
+
if (useVao) {
|
|
613
|
+
gl.drawElementsInstanced(topology, count, _glIndexType, start * _glIndexByteCount, instanceCount);
|
|
727
614
|
} else {
|
|
728
|
-
|
|
615
|
+
var _glBuffer1 = indexBufferBinding.buffer._platformBuffer._glBuffer;
|
|
616
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, _glBuffer1);
|
|
617
|
+
gl.drawElementsInstanced(topology, count, _glIndexType, start * _glIndexByteCount, instanceCount);
|
|
618
|
+
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
|
|
729
619
|
}
|
|
730
620
|
} else {
|
|
731
|
-
|
|
621
|
+
gl.drawArraysInstanced(topology, start, count, instanceCount);
|
|
732
622
|
}
|
|
733
623
|
}
|
|
734
624
|
// Unbind
|
|
@@ -739,7 +629,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
739
629
|
}
|
|
740
630
|
};
|
|
741
631
|
_proto.destroy = function destroy() {
|
|
742
|
-
this.
|
|
632
|
+
this._clearVAO();
|
|
743
633
|
};
|
|
744
634
|
/**
|
|
745
635
|
* Bind buffer and attribute.
|
|
@@ -767,9 +657,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
767
657
|
gl.enableVertexAttribArray(loc);
|
|
768
658
|
var elementInfo = element._formatMetaInfo;
|
|
769
659
|
gl.vertexAttribPointer(loc, elementInfo.size, elementInfo.type, elementInfo.normalized, stride, element.offset);
|
|
770
|
-
|
|
771
|
-
gl.vertexAttribDivisor(loc, element.instanceStepRate);
|
|
772
|
-
}
|
|
660
|
+
gl.vertexAttribDivisor(loc, element.instanceStepRate);
|
|
773
661
|
this._attribLocArray.push(loc);
|
|
774
662
|
} else {
|
|
775
663
|
engineCore.Logger.warn("vertex attribute not found: " + name);
|
|
@@ -817,7 +705,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
817
705
|
/** cache */ this._parameters[gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS] = gl.getParameter(gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS);
|
|
818
706
|
this._parameters[gl.MAX_VERTEX_UNIFORM_VECTORS] = gl.getParameter(gl.MAX_VERTEX_UNIFORM_VECTORS);
|
|
819
707
|
this._parameters[gl.MAX_VERTEX_ATTRIBS] = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
|
|
820
|
-
this._parameters[gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS] = gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS);
|
|
821
708
|
this._parameters[gl.MAX_TEXTURE_SIZE] = gl.getParameter(gl.MAX_TEXTURE_SIZE);
|
|
822
709
|
// init blend state same as BlendState default value.
|
|
823
710
|
gl.blendFuncSeparate(gl.ONE, gl.ZERO, gl.ONE, gl.ZERO);
|
|
@@ -858,7 +745,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
858
745
|
this._texture = texture;
|
|
859
746
|
this._rhi = rhi;
|
|
860
747
|
this._gl = rhi.gl;
|
|
861
|
-
this._isWebGL2 = rhi.isWebGL2;
|
|
862
748
|
this._target = target;
|
|
863
749
|
this._glTexture = this._gl.createTexture();
|
|
864
750
|
}
|
|
@@ -874,7 +760,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
874
760
|
/**
|
|
875
761
|
* @internal
|
|
876
762
|
*/ _proto.setUseDepthCompareMode = function setUseDepthCompareMode(value) {
|
|
877
|
-
if (!this._isWebGL2) return;
|
|
878
763
|
var gl = this._gl;
|
|
879
764
|
gl.texParameteri(this._target, gl.TEXTURE_COMPARE_MODE, value ? gl.COMPARE_REF_TO_TEXTURE : gl.NONE);
|
|
880
765
|
};
|
|
@@ -883,7 +768,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
883
768
|
*/ _proto.generateMipmaps = function generateMipmaps() {
|
|
884
769
|
var texture = this._texture;
|
|
885
770
|
var mipmap = texture._mipmap;
|
|
886
|
-
if (!engineCore.TextureUtils.supportGenerateMipmaps(texture.format, mipmap, texture.isSRGBColorSpace
|
|
771
|
+
if (!engineCore.TextureUtils.supportGenerateMipmaps(texture.format, mipmap, texture.isSRGBColorSpace)) {
|
|
887
772
|
engineCore.Logger.warn("Auto-generating mipmaps for sRGB textures is only supported in [WebGL2 + R8G8B8A8], you must generate mipmaps manually.");
|
|
888
773
|
return;
|
|
889
774
|
}
|
|
@@ -900,11 +785,10 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
900
785
|
* Pre-development mipmapping GPU memory.
|
|
901
786
|
*/ _proto._init = function _init(isCube) {
|
|
902
787
|
var gl = this._gl;
|
|
903
|
-
var isWebGL2 = this._isWebGL2;
|
|
904
788
|
var _this__formatDetail = this._formatDetail, internalFormat = _this__formatDetail.internalFormat, baseFormat = _this__formatDetail.baseFormat, dataType = _this__formatDetail.dataType;
|
|
905
789
|
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;
|
|
906
790
|
this._bind();
|
|
907
|
-
if (
|
|
791
|
+
if (usage !== engineCore.TextureUsage.Dynamic) {
|
|
908
792
|
gl.texStorage2D(this._target, mipmapCount, internalFormat, width, height);
|
|
909
793
|
} else {
|
|
910
794
|
if (!isCube) {
|
|
@@ -940,17 +824,12 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
940
824
|
var gl = this._gl;
|
|
941
825
|
var _this__formatDetail = this._formatDetail, baseFormat = _this__formatDetail.baseFormat, dataType = _this__formatDetail.dataType, readFormat = _this__formatDetail.readFormat, alignment = _this__formatDetail.alignment;
|
|
942
826
|
gl.bindFramebuffer(gl.FRAMEBUFFER, this._getReadFrameBuffer());
|
|
943
|
-
if (mipLevel > 0 && !this._isWebGL2) {
|
|
944
|
-
mipLevel = 0;
|
|
945
|
-
engineCore.Logger.error("mipLevel only take effect in WebGL2.0");
|
|
946
|
-
}
|
|
947
827
|
if (face != null) {
|
|
948
828
|
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_CUBE_MAP_POSITIVE_X + face, this._glTexture, mipLevel);
|
|
949
829
|
} else {
|
|
950
830
|
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this._glTexture, mipLevel);
|
|
951
831
|
}
|
|
952
832
|
gl.pixelStorei(gl.PACK_ALIGNMENT, alignment);
|
|
953
|
-
// Base format is different from read format in webgl1.0 with sRGB
|
|
954
833
|
gl.readPixels(x, y, width, height, readFormat != null ? readFormat : baseFormat, dataType, out);
|
|
955
834
|
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
956
835
|
};
|
|
@@ -961,8 +840,8 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
961
840
|
}
|
|
962
841
|
return frameBuffer;
|
|
963
842
|
};
|
|
964
|
-
_proto._validate = function _validate(texture
|
|
965
|
-
var format = texture.format
|
|
843
|
+
_proto._validate = function _validate(texture) {
|
|
844
|
+
var format = texture.format;
|
|
966
845
|
// Validate sRGB format
|
|
967
846
|
// @ts-ignore
|
|
968
847
|
var isSRGBColorSpace = texture._isSRGBColorSpace;
|
|
@@ -971,24 +850,10 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
971
850
|
// @ts-ignore
|
|
972
851
|
texture._isSRGBColorSpace = false;
|
|
973
852
|
}
|
|
974
|
-
var isWebGL2 = rhi.isWebGL2;
|
|
975
|
-
// Validate mipmap
|
|
976
|
-
var mipmap = texture._mipmap;
|
|
977
|
-
if (mipmap && !engineCore.TextureUtils.supportMipmaps(width, height, isWebGL2)) {
|
|
978
|
-
engineCore.Logger.warn("Non-power-2 texture is not supported for mipmap in WebGL1, and has automatically downgraded to non-mipmap");
|
|
979
|
-
texture._mipmap = false;
|
|
980
|
-
/** @ts-ignore */ texture._mipmapCount = texture._getMipmapCount();
|
|
981
|
-
}
|
|
982
853
|
};
|
|
983
854
|
_proto._setWrapMode = function _setWrapMode(value, pname) {
|
|
984
855
|
var gl = this._gl;
|
|
985
|
-
var isWebGL2 = this._isWebGL2;
|
|
986
856
|
var target = this._target;
|
|
987
|
-
var _this__texture = this._texture, width = _this__texture.width, height = _this__texture.height;
|
|
988
|
-
if (!isWebGL2 && value !== engineCore.TextureWrapMode.Clamp && (!engineMath.MathUtil.isPowerOf2(width) || !engineMath.MathUtil.isPowerOf2(height))) {
|
|
989
|
-
engineCore.Logger.warn("non-power-2 texture is not supported for REPEAT or MIRRORED_REPEAT in WebGL1,and has automatically downgraded to CLAMP_TO_EDGE");
|
|
990
|
-
value = engineCore.TextureWrapMode.Clamp;
|
|
991
|
-
}
|
|
992
857
|
switch(value){
|
|
993
858
|
case engineCore.TextureWrapMode.Clamp:
|
|
994
859
|
gl.texParameteri(target, pname, gl.CLAMP_TO_EDGE);
|
|
@@ -1004,21 +869,21 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1004
869
|
/**
|
|
1005
870
|
* Get more texture info from TextureFormat.
|
|
1006
871
|
* @internal
|
|
1007
|
-
*/ GLTexture._getFormatDetail = function _getFormatDetail(format, isSRGBColorSpace, gl
|
|
872
|
+
*/ GLTexture._getFormatDetail = function _getFormatDetail(format, isSRGBColorSpace, gl) {
|
|
1008
873
|
switch(format){
|
|
1009
874
|
case engineCore.TextureFormat.R8G8B8:
|
|
1010
875
|
return {
|
|
1011
|
-
internalFormat: isSRGBColorSpace ? gl.SRGB8 :
|
|
1012
|
-
baseFormat:
|
|
1013
|
-
readFormat:
|
|
876
|
+
internalFormat: isSRGBColorSpace ? gl.SRGB8 : gl.RGB8,
|
|
877
|
+
baseFormat: gl.RGB,
|
|
878
|
+
readFormat: gl.RGBA,
|
|
1014
879
|
dataType: gl.UNSIGNED_BYTE,
|
|
1015
880
|
isCompressed: false,
|
|
1016
881
|
alignment: 1
|
|
1017
882
|
};
|
|
1018
883
|
case engineCore.TextureFormat.R8G8B8A8:
|
|
1019
884
|
return {
|
|
1020
|
-
internalFormat: isSRGBColorSpace ? gl.SRGB8_ALPHA8 :
|
|
1021
|
-
baseFormat:
|
|
885
|
+
internalFormat: isSRGBColorSpace ? gl.SRGB8_ALPHA8 : gl.RGBA8,
|
|
886
|
+
baseFormat: gl.RGBA,
|
|
1022
887
|
readFormat: gl.RGBA,
|
|
1023
888
|
dataType: gl.UNSIGNED_BYTE,
|
|
1024
889
|
isCompressed: false,
|
|
@@ -1026,7 +891,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1026
891
|
};
|
|
1027
892
|
case engineCore.TextureFormat.R4G4B4A4:
|
|
1028
893
|
return {
|
|
1029
|
-
internalFormat:
|
|
894
|
+
internalFormat: gl.RGBA4,
|
|
1030
895
|
baseFormat: gl.RGBA,
|
|
1031
896
|
dataType: gl.UNSIGNED_SHORT_4_4_4_4,
|
|
1032
897
|
isCompressed: false,
|
|
@@ -1034,7 +899,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1034
899
|
};
|
|
1035
900
|
case engineCore.TextureFormat.R5G5B5A1:
|
|
1036
901
|
return {
|
|
1037
|
-
internalFormat:
|
|
902
|
+
internalFormat: gl.RGB5_A1,
|
|
1038
903
|
baseFormat: gl.RGBA,
|
|
1039
904
|
dataType: gl.UNSIGNED_SHORT_5_5_5_1,
|
|
1040
905
|
isCompressed: false,
|
|
@@ -1042,31 +907,15 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1042
907
|
};
|
|
1043
908
|
case engineCore.TextureFormat.R5G6B5:
|
|
1044
909
|
return {
|
|
1045
|
-
internalFormat:
|
|
910
|
+
internalFormat: gl.RGB565,
|
|
1046
911
|
baseFormat: gl.RGB,
|
|
1047
912
|
dataType: gl.UNSIGNED_SHORT_5_6_5,
|
|
1048
913
|
isCompressed: false,
|
|
1049
914
|
alignment: 2
|
|
1050
915
|
};
|
|
1051
|
-
case engineCore.TextureFormat.Alpha8:
|
|
1052
|
-
return {
|
|
1053
|
-
internalFormat: gl.ALPHA,
|
|
1054
|
-
baseFormat: gl.ALPHA,
|
|
1055
|
-
dataType: gl.UNSIGNED_BYTE,
|
|
1056
|
-
isCompressed: false,
|
|
1057
|
-
alignment: 1
|
|
1058
|
-
};
|
|
1059
|
-
case engineCore.TextureFormat.LuminanceAlpha:
|
|
1060
|
-
return {
|
|
1061
|
-
internalFormat: gl.LUMINANCE_ALPHA,
|
|
1062
|
-
baseFormat: gl.LUMINANCE_ALPHA,
|
|
1063
|
-
dataType: gl.UNSIGNED_BYTE,
|
|
1064
|
-
isCompressed: false,
|
|
1065
|
-
alignment: 2
|
|
1066
|
-
};
|
|
1067
916
|
case engineCore.TextureFormat.R16G16B16A16:
|
|
1068
917
|
return {
|
|
1069
|
-
internalFormat:
|
|
918
|
+
internalFormat: gl.RGBA16F,
|
|
1070
919
|
baseFormat: gl.RGBA,
|
|
1071
920
|
dataType: gl.HALF_FLOAT,
|
|
1072
921
|
isCompressed: false,
|
|
@@ -1074,13 +923,12 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1074
923
|
};
|
|
1075
924
|
case engineCore.TextureFormat.R32G32B32A32:
|
|
1076
925
|
return {
|
|
1077
|
-
internalFormat:
|
|
926
|
+
internalFormat: gl.RGBA32F,
|
|
1078
927
|
baseFormat: gl.RGBA,
|
|
1079
928
|
dataType: gl.FLOAT,
|
|
1080
929
|
isCompressed: false,
|
|
1081
930
|
alignment: 8
|
|
1082
931
|
};
|
|
1083
|
-
// Only WebGL2 support
|
|
1084
932
|
case engineCore.TextureFormat.R11G11B10_UFloat:
|
|
1085
933
|
return {
|
|
1086
934
|
internalFormat: gl.R11F_G11F_B10F,
|
|
@@ -1090,7 +938,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1090
938
|
isCompressed: false,
|
|
1091
939
|
alignment: 4
|
|
1092
940
|
};
|
|
1093
|
-
// Only WebGL2 support
|
|
1094
941
|
case engineCore.TextureFormat.R32G32B32A32_UInt:
|
|
1095
942
|
return {
|
|
1096
943
|
internalFormat: gl.RGBA32UI,
|
|
@@ -1099,7 +946,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1099
946
|
isCompressed: false,
|
|
1100
947
|
alignment: 8
|
|
1101
948
|
};
|
|
1102
|
-
// Only WebGL2 support
|
|
1103
949
|
case engineCore.TextureFormat.R8:
|
|
1104
950
|
return {
|
|
1105
951
|
internalFormat: gl.R8,
|
|
@@ -1108,7 +954,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1108
954
|
isCompressed: false,
|
|
1109
955
|
alignment: 1
|
|
1110
956
|
};
|
|
1111
|
-
// Only WebGL2 support
|
|
1112
957
|
case engineCore.TextureFormat.R8G8:
|
|
1113
958
|
return {
|
|
1114
959
|
internalFormat: gl.RG8,
|
|
@@ -1209,23 +1054,23 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1209
1054
|
};
|
|
1210
1055
|
case engineCore.TextureFormat.Depth:
|
|
1211
1056
|
return {
|
|
1212
|
-
internalFormat:
|
|
1057
|
+
internalFormat: gl.DEPTH_COMPONENT32F,
|
|
1213
1058
|
baseFormat: gl.DEPTH_COMPONENT,
|
|
1214
|
-
dataType:
|
|
1059
|
+
dataType: gl.FLOAT,
|
|
1215
1060
|
isCompressed: false,
|
|
1216
1061
|
attachment: gl.DEPTH_ATTACHMENT
|
|
1217
1062
|
};
|
|
1218
1063
|
case engineCore.TextureFormat.DepthStencil:
|
|
1219
1064
|
return {
|
|
1220
|
-
internalFormat:
|
|
1065
|
+
internalFormat: gl.DEPTH32F_STENCIL8,
|
|
1221
1066
|
baseFormat: gl.DEPTH_STENCIL,
|
|
1222
|
-
dataType:
|
|
1067
|
+
dataType: gl.FLOAT_32_UNSIGNED_INT_24_8_REV,
|
|
1223
1068
|
isCompressed: false,
|
|
1224
1069
|
attachment: gl.DEPTH_STENCIL_ATTACHMENT
|
|
1225
1070
|
};
|
|
1226
1071
|
case engineCore.TextureFormat.Depth16:
|
|
1227
1072
|
return {
|
|
1228
|
-
internalFormat:
|
|
1073
|
+
internalFormat: gl.DEPTH_COMPONENT16,
|
|
1229
1074
|
baseFormat: gl.DEPTH_COMPONENT,
|
|
1230
1075
|
dataType: gl.UNSIGNED_SHORT,
|
|
1231
1076
|
isCompressed: false,
|
|
@@ -1233,13 +1078,12 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1233
1078
|
};
|
|
1234
1079
|
case engineCore.TextureFormat.Depth24Stencil8:
|
|
1235
1080
|
return {
|
|
1236
|
-
internalFormat:
|
|
1081
|
+
internalFormat: gl.DEPTH24_STENCIL8,
|
|
1237
1082
|
baseFormat: gl.DEPTH_STENCIL,
|
|
1238
1083
|
dataType: gl.UNSIGNED_INT_24_8,
|
|
1239
1084
|
isCompressed: false,
|
|
1240
1085
|
attachment: gl.DEPTH_STENCIL_ATTACHMENT
|
|
1241
1086
|
};
|
|
1242
|
-
// Only WebGL2 support
|
|
1243
1087
|
case engineCore.TextureFormat.Depth24:
|
|
1244
1088
|
return {
|
|
1245
1089
|
internalFormat: gl.DEPTH_COMPONENT24,
|
|
@@ -1248,7 +1092,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1248
1092
|
isCompressed: false,
|
|
1249
1093
|
attachment: gl.DEPTH_ATTACHMENT
|
|
1250
1094
|
};
|
|
1251
|
-
// Only WebGL2 support
|
|
1252
1095
|
case engineCore.TextureFormat.Depth32:
|
|
1253
1096
|
return {
|
|
1254
1097
|
internalFormat: gl.DEPTH_COMPONENT32F,
|
|
@@ -1257,7 +1100,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1257
1100
|
isCompressed: false,
|
|
1258
1101
|
attachment: gl.DEPTH_ATTACHMENT
|
|
1259
1102
|
};
|
|
1260
|
-
// Only WebGL2 support
|
|
1261
1103
|
case engineCore.TextureFormat.Depth32Stencil8:
|
|
1262
1104
|
return {
|
|
1263
1105
|
internalFormat: gl.DEPTH32F_STENCIL8,
|
|
@@ -1271,23 +1113,22 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1271
1113
|
}
|
|
1272
1114
|
};
|
|
1273
1115
|
/**
|
|
1274
|
-
* In WebGL 1, internalformat must be the same as baseFormat when call texImage2D.
|
|
1275
1116
|
* @internal
|
|
1276
|
-
*/ GLTexture._getRenderBufferDepthFormatDetail = function _getRenderBufferDepthFormatDetail(format, gl
|
|
1117
|
+
*/ GLTexture._getRenderBufferDepthFormatDetail = function _getRenderBufferDepthFormatDetail(format, gl) {
|
|
1277
1118
|
switch(format){
|
|
1278
1119
|
case engineCore.TextureFormat.Depth:
|
|
1279
1120
|
return {
|
|
1280
|
-
internalFormat:
|
|
1121
|
+
internalFormat: gl.DEPTH_COMPONENT32F,
|
|
1281
1122
|
baseFormat: gl.DEPTH_COMPONENT,
|
|
1282
|
-
dataType:
|
|
1123
|
+
dataType: gl.FLOAT,
|
|
1283
1124
|
isCompressed: false,
|
|
1284
1125
|
attachment: gl.DEPTH_ATTACHMENT
|
|
1285
1126
|
};
|
|
1286
1127
|
case engineCore.TextureFormat.DepthStencil:
|
|
1287
1128
|
return {
|
|
1288
|
-
internalFormat:
|
|
1129
|
+
internalFormat: gl.DEPTH32F_STENCIL8,
|
|
1289
1130
|
baseFormat: gl.DEPTH_STENCIL,
|
|
1290
|
-
dataType:
|
|
1131
|
+
dataType: gl.FLOAT_32_UNSIGNED_INT_24_8_REV,
|
|
1291
1132
|
isCompressed: false,
|
|
1292
1133
|
attachment: gl.DEPTH_STENCIL_ATTACHMENT
|
|
1293
1134
|
};
|
|
@@ -1309,7 +1150,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1309
1150
|
};
|
|
1310
1151
|
case engineCore.TextureFormat.Depth24Stencil8:
|
|
1311
1152
|
return {
|
|
1312
|
-
internalFormat:
|
|
1153
|
+
internalFormat: gl.DEPTH24_STENCIL8,
|
|
1313
1154
|
baseFormat: gl.DEPTH_STENCIL,
|
|
1314
1155
|
dataType: gl.UNSIGNED_INT_24_8,
|
|
1315
1156
|
isCompressed: false,
|
|
@@ -1343,19 +1184,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1343
1184
|
throw new Error("this TextureFormat is not supported in Galacean Engine: " + format);
|
|
1344
1185
|
}
|
|
1345
1186
|
};
|
|
1346
|
-
/**
|
|
1347
|
-
* @internal
|
|
1348
|
-
*/ GLTexture._supportRenderBufferDepthFormat = function _supportRenderBufferDepthFormat(format, rhi) {
|
|
1349
|
-
if (!rhi.isWebGL2) {
|
|
1350
|
-
switch(format){
|
|
1351
|
-
case engineCore.TextureFormat.Depth24:
|
|
1352
|
-
case engineCore.TextureFormat.Depth32:
|
|
1353
|
-
case engineCore.TextureFormat.Depth32Stencil8:
|
|
1354
|
-
return false;
|
|
1355
|
-
}
|
|
1356
|
-
}
|
|
1357
|
-
return true;
|
|
1358
|
-
};
|
|
1359
1187
|
_create_class(GLTexture, [
|
|
1360
1188
|
{
|
|
1361
1189
|
key: "wrapModeU",
|
|
@@ -1405,15 +1233,16 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1405
1233
|
set: /**
|
|
1406
1234
|
* Anisotropic level for texture.
|
|
1407
1235
|
*/ function set(value) {
|
|
1408
|
-
var
|
|
1236
|
+
var extension = this._rhi.requireExtension(engineCore.GLCapabilityType.textureFilterAnisotropic);
|
|
1237
|
+
if (!extension) return;
|
|
1409
1238
|
this._bind();
|
|
1410
|
-
|
|
1239
|
+
this._gl.texParameterf(this._target, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(value, this._rhi.capability.maxAnisoLevel));
|
|
1411
1240
|
}
|
|
1412
1241
|
},
|
|
1413
1242
|
{
|
|
1414
1243
|
key: "depthCompareFunction",
|
|
1415
1244
|
set: function set(value) {
|
|
1416
|
-
if (
|
|
1245
|
+
if (value === undefined) return;
|
|
1417
1246
|
this._bind();
|
|
1418
1247
|
var gl = this._gl;
|
|
1419
1248
|
switch(value){
|
|
@@ -1456,11 +1285,9 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1456
1285
|
this._curMipLevel = 0;
|
|
1457
1286
|
this._curFaceIndex = undefined;
|
|
1458
1287
|
this._gl = rhi.gl;
|
|
1459
|
-
this._isWebGL2 = rhi.isWebGL2;
|
|
1460
1288
|
this._target = target;
|
|
1461
1289
|
this._antiAliasing = Math.min(target.antiAliasing, rhi.capability.maxAntiAliasing);
|
|
1462
1290
|
/** @ts-ignore */ var _colorTextures = target._colorTextures, _depth = target._depth, width = target.width, height = target.height;
|
|
1463
|
-
var isDepthTexture = _instanceof(_depth, engineCore.Texture);
|
|
1464
1291
|
/** todo
|
|
1465
1292
|
* MRT + Cube + [,MSAA]
|
|
1466
1293
|
* MRT + MSAA
|
|
@@ -1473,18 +1300,12 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1473
1300
|
throw new Error("If you want to use sRGB color space, only R8G8B8A8 format is supported in RenderTarget");
|
|
1474
1301
|
}
|
|
1475
1302
|
}
|
|
1476
|
-
if (!isDepthTexture && _depth !== null && !GLTexture._supportRenderBufferDepthFormat(_depth, rhi)) {
|
|
1477
|
-
throw new Error("TextureFormat is not supported:" + engineCore.TextureFormat[_depth] + " in RenderTarget");
|
|
1478
|
-
}
|
|
1479
|
-
if (_colorTextures.length > 1 && !rhi.canIUse(engineCore.GLCapabilityType.drawBuffers)) {
|
|
1480
|
-
throw new Error("MRT is not supported");
|
|
1481
|
-
}
|
|
1482
1303
|
if (_colorTextures.some(function(v) {
|
|
1483
1304
|
return v.width !== width || v.height !== height;
|
|
1484
1305
|
})) {
|
|
1485
1306
|
throw new Error("ColorTexture's size must as same as RenderTarget");
|
|
1486
1307
|
}
|
|
1487
|
-
if (
|
|
1308
|
+
if (_instanceof(_depth, engineCore.Texture) && (_depth.width !== width || _depth.height !== height)) {
|
|
1488
1309
|
throw new Error("DepthTexture's size must as same as RenderTarget");
|
|
1489
1310
|
}
|
|
1490
1311
|
// todo: necessary to support MRT + Cube + [,MSAA] ?
|
|
@@ -1530,7 +1351,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1530
1351
|
} else {
|
|
1531
1352
|
if (mipChanged) {
|
|
1532
1353
|
// @ts-ignore
|
|
1533
|
-
var internalFormat = GLTexture._getRenderBufferDepthFormatDetail(target._depth, gl
|
|
1354
|
+
var internalFormat = GLTexture._getRenderBufferDepthFormatDetail(target._depth, gl).internalFormat;
|
|
1534
1355
|
gl.bindRenderbuffer(gl.RENDERBUFFER, this._depthRenderBuffer);
|
|
1535
1356
|
gl.renderbufferStorage(gl.RENDERBUFFER, internalFormat, target.width >> mipLevel, target.height >> mipLevel);
|
|
1536
1357
|
}
|
|
@@ -1579,7 +1400,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1579
1400
|
};
|
|
1580
1401
|
_proto._bindMainFBO = function _bindMainFBO() {
|
|
1581
1402
|
var gl = this._gl;
|
|
1582
|
-
var isWebGL2 = this._isWebGL2;
|
|
1583
1403
|
var _this__target = this._target, _depth = _this__target._depth, colorTextureCount = _this__target.colorTextureCount; _this__target.width; _this__target.height;
|
|
1584
1404
|
var drawBuffers = new Array(colorTextureCount);
|
|
1585
1405
|
gl.bindFramebuffer(gl.FRAMEBUFFER, this._frameBuffer);
|
|
@@ -1602,7 +1422,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1602
1422
|
gl.framebufferTexture2D(gl.FRAMEBUFFER, platformTexture._formatDetail.attachment, gl.TEXTURE_2D, platformTexture._glTexture, 0);
|
|
1603
1423
|
}
|
|
1604
1424
|
} else if (this._antiAliasing <= 1) {
|
|
1605
|
-
var _GLTexture__getRenderBufferDepthFormatDetail = GLTexture._getRenderBufferDepthFormatDetail(_depth, gl
|
|
1425
|
+
var _GLTexture__getRenderBufferDepthFormatDetail = GLTexture._getRenderBufferDepthFormatDetail(_depth, gl), internalFormat = _GLTexture__getRenderBufferDepthFormatDetail.internalFormat, attachment1 = _GLTexture__getRenderBufferDepthFormatDetail.attachment;
|
|
1606
1426
|
this._depthRenderBuffer = this._createRenderBuffer(internalFormat, attachment1);
|
|
1607
1427
|
}
|
|
1608
1428
|
}
|
|
@@ -1611,7 +1431,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1611
1431
|
};
|
|
1612
1432
|
_proto._bindMSAAFBO = function _bindMSAAFBO() {
|
|
1613
1433
|
var gl = this._gl;
|
|
1614
|
-
var isWebGL2 = this._isWebGL2;
|
|
1615
1434
|
var _this__target = this._target, _depth = _this__target._depth, colorTextureCount = _this__target.colorTextureCount;
|
|
1616
1435
|
this._blitDrawBuffers = new Array(colorTextureCount);
|
|
1617
1436
|
gl.bindFramebuffer(gl.FRAMEBUFFER, this._MSAAFrameBuffer);
|
|
@@ -1624,7 +1443,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1624
1443
|
gl.drawBuffers(this._oriDrawBuffers);
|
|
1625
1444
|
// prepare MSAA depth RBO
|
|
1626
1445
|
if (_depth !== null) {
|
|
1627
|
-
var _ref = _instanceof(_depth, engineCore.Texture) ? _depth._platformTexture._formatDetail : GLTexture._getRenderBufferDepthFormatDetail(_depth, gl
|
|
1446
|
+
var _ref = _instanceof(_depth, engineCore.Texture) ? _depth._platformTexture._formatDetail : GLTexture._getRenderBufferDepthFormatDetail(_depth, gl), internalFormat1 = _ref.internalFormat, attachment = _ref.attachment;
|
|
1628
1447
|
this._MSAADepthRenderBuffer = this._createRenderBuffer(internalFormat1, attachment);
|
|
1629
1448
|
}
|
|
1630
1449
|
this._checkFrameBuffer();
|
|
@@ -1674,12 +1493,11 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1674
1493
|
_inherits(GLTexture2D, GLTexture1);
|
|
1675
1494
|
function GLTexture2D(rhi, texture2D) {
|
|
1676
1495
|
var _this;
|
|
1677
|
-
_this = GLTexture1.call(this, rhi, texture2D, rhi.gl.TEXTURE_2D) || this
|
|
1678
|
-
_this._validate(texture2D
|
|
1496
|
+
_this = GLTexture1.call(this, rhi, texture2D, rhi.gl.TEXTURE_2D) || this;
|
|
1497
|
+
_this._validate(texture2D);
|
|
1679
1498
|
var format = texture2D.format, isSRGBColorSpace = texture2D.isSRGBColorSpace;
|
|
1680
|
-
|
|
1681
|
-
_this.
|
|
1682
|
-
_this._formatDetail.isCompressed && !isWebGL2 || _this._init(false);
|
|
1499
|
+
_this._formatDetail = GLTexture._getFormatDetail(format, isSRGBColorSpace, _this._gl);
|
|
1500
|
+
_this._init(false);
|
|
1683
1501
|
return _this;
|
|
1684
1502
|
}
|
|
1685
1503
|
var _proto = GLTexture2D.prototype;
|
|
@@ -1695,15 +1513,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1695
1513
|
height = height || mipHeight - y;
|
|
1696
1514
|
this._bind();
|
|
1697
1515
|
if (formatDetail.isCompressed) {
|
|
1698
|
-
|
|
1699
|
-
var internalFormat = formatDetail.internalFormat;
|
|
1700
|
-
var mipBit = 1 << mipLevel;
|
|
1701
|
-
if (isWebGL2 || this._compressedMipFilled & mipBit) {
|
|
1702
|
-
gl.compressedTexSubImage2D(this._target, mipLevel, x, y, width, height, internalFormat, colorBuffer);
|
|
1703
|
-
} else {
|
|
1704
|
-
gl.compressedTexImage2D(this._target, mipLevel, internalFormat, width, height, 0, colorBuffer);
|
|
1705
|
-
this._compressedMipFilled |= mipBit;
|
|
1706
|
-
}
|
|
1516
|
+
gl.compressedTexSubImage2D(this._target, mipLevel, x, y, width, height, formatDetail.internalFormat, colorBuffer);
|
|
1707
1517
|
} else {
|
|
1708
1518
|
var baseFormat = formatDetail.baseFormat, dataType = formatDetail.dataType;
|
|
1709
1519
|
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 0);
|
|
@@ -1743,14 +1553,11 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1743
1553
|
_inherits(GLTexture2DArray, GLTexture1);
|
|
1744
1554
|
function GLTexture2DArray(rhi, texture2DArray) {
|
|
1745
1555
|
var _this;
|
|
1746
|
-
if (!rhi.isWebGL2) {
|
|
1747
|
-
throw new Error("Texture2D Array is not supported in WebGL1.0");
|
|
1748
|
-
}
|
|
1749
1556
|
_this = GLTexture1.call(this, rhi, texture2DArray, rhi.gl.TEXTURE_2D_ARRAY) || this;
|
|
1750
|
-
_this._validate(texture2DArray
|
|
1557
|
+
_this._validate(texture2DArray);
|
|
1751
1558
|
var format = texture2DArray.format, width = texture2DArray.width, height = texture2DArray.height, length = texture2DArray.length, mipmapCount = texture2DArray.mipmapCount, isSRGBColorSpace = texture2DArray.isSRGBColorSpace;
|
|
1752
1559
|
_this._bind();
|
|
1753
|
-
_this._formatDetail = GLTexture._getFormatDetail(format, isSRGBColorSpace, _this._gl
|
|
1560
|
+
_this._formatDetail = GLTexture._getFormatDetail(format, isSRGBColorSpace, _this._gl);
|
|
1754
1561
|
_this._gl.texStorage3D(_this._target, mipmapCount, _this._formatDetail.internalFormat, width, height, length);
|
|
1755
1562
|
return _this;
|
|
1756
1563
|
}
|
|
@@ -1798,7 +1605,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1798
1605
|
gl.readPixels(x, y, width, height, formatDetail.baseFormat, formatDetail.dataType, out);
|
|
1799
1606
|
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
1800
1607
|
};
|
|
1801
|
-
_proto._validate = function _validate(texture
|
|
1608
|
+
_proto._validate = function _validate(texture) {
|
|
1802
1609
|
var format = texture.format;
|
|
1803
1610
|
// Validate sRGB format
|
|
1804
1611
|
// @ts-ignore
|
|
@@ -1818,19 +1625,11 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1818
1625
|
_inherits(GLTextureCube, GLTexture1);
|
|
1819
1626
|
function GLTextureCube(rhi, textureCube) {
|
|
1820
1627
|
var _this;
|
|
1821
|
-
_this = GLTexture1.call(this, rhi, textureCube, rhi.gl.TEXTURE_CUBE_MAP) || this
|
|
1822
|
-
|
|
1823
|
-
0,
|
|
1824
|
-
0,
|
|
1825
|
-
0,
|
|
1826
|
-
0,
|
|
1827
|
-
0
|
|
1828
|
-
];
|
|
1829
|
-
_this._validate(textureCube, rhi);
|
|
1628
|
+
_this = GLTexture1.call(this, rhi, textureCube, rhi.gl.TEXTURE_CUBE_MAP) || this;
|
|
1629
|
+
_this._validate(textureCube);
|
|
1830
1630
|
var format = textureCube.format, isSRGBColorSpace = textureCube.isSRGBColorSpace;
|
|
1831
|
-
|
|
1832
|
-
_this.
|
|
1833
|
-
_this._formatDetail.isCompressed && !isWebGL2 || _this._init(true);
|
|
1631
|
+
_this._formatDetail = GLTexture._getFormatDetail(format, isSRGBColorSpace, _this._gl);
|
|
1632
|
+
_this._init(true);
|
|
1834
1633
|
return _this;
|
|
1835
1634
|
}
|
|
1836
1635
|
var _proto = GLTextureCube.prototype;
|
|
@@ -1838,21 +1637,14 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1838
1637
|
* {@inheritDoc IPlatformTextureCube.setPixelBuffer}
|
|
1839
1638
|
*/ _proto.setPixelBuffer = function setPixelBuffer(face, colorBuffer, mipLevel, x, y, width, height) {
|
|
1840
1639
|
var gl = this._gl;
|
|
1841
|
-
var isWebGL2 = this._isWebGL2;
|
|
1842
1640
|
var formatDetail = this._formatDetail;
|
|
1843
|
-
var
|
|
1641
|
+
var baseFormat = formatDetail.baseFormat, dataType = formatDetail.dataType, isCompressed = formatDetail.isCompressed;
|
|
1844
1642
|
var mipSize = Math.max(1, this._texture.width >> mipLevel);
|
|
1845
1643
|
width = width || mipSize - x;
|
|
1846
1644
|
height = height || mipSize - y;
|
|
1847
1645
|
this._bind();
|
|
1848
1646
|
if (isCompressed) {
|
|
1849
|
-
|
|
1850
|
-
if (isWebGL2 || this._compressedFaceFilled[face] & mipBit) {
|
|
1851
|
-
gl.compressedTexSubImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + face, mipLevel, x, y, width, height, internalFormat, colorBuffer);
|
|
1852
|
-
} else {
|
|
1853
|
-
gl.compressedTexImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + face, mipLevel, internalFormat, width, height, 0, colorBuffer);
|
|
1854
|
-
this._compressedFaceFilled[face] |= mipBit;
|
|
1855
|
-
}
|
|
1647
|
+
gl.compressedTexSubImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + face, mipLevel, x, y, width, height, formatDetail.internalFormat, colorBuffer);
|
|
1856
1648
|
} else {
|
|
1857
1649
|
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, 0);
|
|
1858
1650
|
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, 0);
|
|
@@ -2021,15 +1813,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2021
1813
|
}();
|
|
2022
1814
|
|
|
2023
1815
|
/**
|
|
2024
|
-
* WebGL
|
|
2025
|
-
*/ var WebGLMode = /*#__PURE__*/ function(WebGLMode) {
|
|
2026
|
-
/** Auto, use WebGL2.0 if support, or will fallback to WebGL1.0. */ WebGLMode[WebGLMode["Auto"] = 0] = "Auto";
|
|
2027
|
-
/** WebGL2.0. */ WebGLMode[WebGLMode["WebGL2"] = 1] = "WebGL2";
|
|
2028
|
-
/** WebGL1.0, */ WebGLMode[WebGLMode["WebGL1"] = 2] = "WebGL1";
|
|
2029
|
-
return WebGLMode;
|
|
2030
|
-
}({});
|
|
2031
|
-
/**
|
|
2032
|
-
* WebGL graphic device, including WebGL1.0 and WebGL2.0.
|
|
1816
|
+
* WebGL graphic device, using WebGL2.0.
|
|
2033
1817
|
*/ var WebGLGraphicDevice = /*#__PURE__*/ function() {
|
|
2034
1818
|
function WebGLGraphicDevice(initializeOptions) {
|
|
2035
1819
|
if (initializeOptions === void 0) initializeOptions = {};
|
|
@@ -2045,7 +1829,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2045
1829
|
this._lastClearColor = new engineMath.Color(null, null, null, null);
|
|
2046
1830
|
this._scissorEnable = false;
|
|
2047
1831
|
var options = _extends({
|
|
2048
|
-
webGLMode: 0,
|
|
2049
1832
|
_forceFlush: false,
|
|
2050
1833
|
_maxAllowSkinUniformVectorCount: 256,
|
|
2051
1834
|
alpha: true,
|
|
@@ -2088,40 +1871,26 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2088
1871
|
var _proto = WebGLGraphicDevice.prototype;
|
|
2089
1872
|
_proto.init = function init(canvas, onDeviceLost, onDeviceRestored) {
|
|
2090
1873
|
var webCanvas = canvas._webCanvas;
|
|
2091
|
-
var webGLMode = this._options.webGLMode;
|
|
2092
|
-
this._onDeviceLost = onDeviceLost;
|
|
2093
|
-
this._onDeviceRestored = onDeviceRestored;
|
|
2094
|
-
webCanvas.addEventListener("webglcontextlost", this._onWebGLContextLost, false);
|
|
2095
|
-
webCanvas.addEventListener("webglcontextrestored", this._onWebGLContextRestored, false);
|
|
2096
1874
|
webCanvas.addEventListener("webglcontextcreationerror", this._onContextCreationError, false);
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
if (webGLMode == 0 || webGLMode == 1) {
|
|
2101
|
-
gl = webCanvas.getContext("webgl2", webGLOptions);
|
|
1875
|
+
try {
|
|
1876
|
+
var webGLOptions = this._webGLOptions;
|
|
1877
|
+
var gl = webCanvas.getContext("webgl2", webGLOptions);
|
|
2102
1878
|
if (!gl && !canvas._isOffscreenCanvas()) {
|
|
2103
1879
|
gl = webCanvas.getContext("experimental-webgl2", webGLOptions);
|
|
2104
1880
|
}
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
if (gl && !gl.deleteQuery) {
|
|
2108
|
-
this._isWebGL2 = false;
|
|
2109
|
-
}
|
|
2110
|
-
}
|
|
2111
|
-
if (!gl) {
|
|
2112
|
-
if (webGLMode == 0 || webGLMode == 2) {
|
|
2113
|
-
gl = webCanvas.getContext("webgl", webGLOptions);
|
|
2114
|
-
if (!gl && !canvas._isOffscreenCanvas()) {
|
|
2115
|
-
gl = webCanvas.getContext("experimental-webgl", webGLOptions);
|
|
2116
|
-
}
|
|
2117
|
-
this._isWebGL2 = false;
|
|
1881
|
+
if (!gl || !gl.deleteQuery) {
|
|
1882
|
+
throw new Error("WebGL2 is not supported.");
|
|
2118
1883
|
}
|
|
1884
|
+
this._gl = gl;
|
|
1885
|
+
this._initGLState(gl);
|
|
1886
|
+
} finally{
|
|
1887
|
+
webCanvas.removeEventListener("webglcontextcreationerror", this._onContextCreationError, false);
|
|
2119
1888
|
}
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
this.
|
|
2124
|
-
this.
|
|
1889
|
+
this._webCanvas = webCanvas;
|
|
1890
|
+
this._onDeviceLost = onDeviceLost;
|
|
1891
|
+
this._onDeviceRestored = onDeviceRestored;
|
|
1892
|
+
webCanvas.addEventListener("webglcontextlost", this._onWebGLContextLost, false);
|
|
1893
|
+
webCanvas.addEventListener("webglcontextrestored", this._onWebGLContextRestored, false);
|
|
2125
1894
|
};
|
|
2126
1895
|
_proto.createPlatformPrimitive = function createPlatformPrimitive(primitive) {
|
|
2127
1896
|
return new GLPrimitive(this, primitive);
|
|
@@ -2163,18 +1932,14 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2163
1932
|
/**
|
|
2164
1933
|
* Enable GL_RASTERIZER_DISCARD (WebGL2 only).
|
|
2165
1934
|
*/ _proto.enableRasterizerDiscard = function enableRasterizerDiscard() {
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
gl.enable(gl.RASTERIZER_DISCARD);
|
|
2169
|
-
}
|
|
1935
|
+
var gl = this._gl;
|
|
1936
|
+
gl.enable(gl.RASTERIZER_DISCARD);
|
|
2170
1937
|
};
|
|
2171
1938
|
/**
|
|
2172
1939
|
* Disable GL_RASTERIZER_DISCARD (WebGL2 only).
|
|
2173
1940
|
*/ _proto.disableRasterizerDiscard = function disableRasterizerDiscard() {
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
gl.disable(gl.RASTERIZER_DISCARD);
|
|
2177
|
-
}
|
|
1941
|
+
var gl = this._gl;
|
|
1942
|
+
gl.disable(gl.RASTERIZER_DISCARD);
|
|
2178
1943
|
};
|
|
2179
1944
|
/**
|
|
2180
1945
|
* Invalidate the cached shader program state.
|
|
@@ -2298,10 +2063,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2298
2063
|
this.scissor(x, y, width, height);
|
|
2299
2064
|
};
|
|
2300
2065
|
_proto.blitInternalRTByBlitFrameBuffer = function blitInternalRTByBlitFrameBuffer(srcRT, destRT, clearFlags, viewport) {
|
|
2301
|
-
if (!this._isWebGL2) {
|
|
2302
|
-
engineCore.Logger.warn("WebGL1.0 not support blit frame buffer.");
|
|
2303
|
-
return;
|
|
2304
|
-
}
|
|
2305
2066
|
var gl = this._gl;
|
|
2306
2067
|
// @ts-ignore
|
|
2307
2068
|
var srcFrameBuffer = srcRT ? srcRT._platformRenderTarget._frameBuffer : null;
|
|
@@ -2429,13 +2190,10 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2429
2190
|
if (debugRenderInfo != null) {
|
|
2430
2191
|
this._renderer = gl.getParameter(debugRenderInfo.UNMASKED_RENDERER_WEBGL);
|
|
2431
2192
|
}
|
|
2432
|
-
|
|
2433
|
-
this.maxUniformBlockSize = gl.getParameter(gl.MAX_UNIFORM_BLOCK_SIZE);
|
|
2434
|
-
}
|
|
2193
|
+
this.maxUniformBlockSize = gl.getParameter(gl.MAX_UNIFORM_BLOCK_SIZE);
|
|
2435
2194
|
};
|
|
2436
2195
|
_proto.destroy = function destroy() {
|
|
2437
2196
|
var webCanvas = this._webCanvas;
|
|
2438
|
-
webCanvas.removeEventListener("webglcontextcreationerror", this._onContextCreationError, false);
|
|
2439
2197
|
webCanvas.removeEventListener("webglcontextlost", this._onWebGLContextLost, false);
|
|
2440
2198
|
webCanvas.removeEventListener("webglcontextrestored", this._onWebGLContextRestored, false);
|
|
2441
2199
|
};
|
|
@@ -2450,12 +2208,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2450
2208
|
this._onDeviceRestored();
|
|
2451
2209
|
};
|
|
2452
2210
|
_create_class(WebGLGraphicDevice, [
|
|
2453
|
-
{
|
|
2454
|
-
key: "isWebGL2",
|
|
2455
|
-
get: function get() {
|
|
2456
|
-
return this._isWebGL2;
|
|
2457
|
-
}
|
|
2458
|
-
},
|
|
2459
2211
|
{
|
|
2460
2212
|
key: "renderer",
|
|
2461
2213
|
get: function get() {
|
|
@@ -2466,7 +2218,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2466
2218
|
key: "gl",
|
|
2467
2219
|
get: /**
|
|
2468
2220
|
* GL Context
|
|
2469
|
-
* @member {
|
|
2221
|
+
* @member {WebGL2RenderingContext}
|
|
2470
2222
|
*/ function get() {
|
|
2471
2223
|
return this._gl;
|
|
2472
2224
|
}
|
|
@@ -2482,12 +2234,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2482
2234
|
get: function get() {
|
|
2483
2235
|
return this._capability;
|
|
2484
2236
|
}
|
|
2485
|
-
},
|
|
2486
|
-
{
|
|
2487
|
-
key: "canIUseMoreJoints",
|
|
2488
|
-
get: function get() {
|
|
2489
|
-
return this.capability.canIUseMoreJoints;
|
|
2490
|
-
}
|
|
2491
2237
|
}
|
|
2492
2238
|
]);
|
|
2493
2239
|
return WebGLGraphicDevice;
|
|
@@ -2497,5 +2243,4 @@ exports.GLCompressedTextureInternalFormat = GLCompressedTextureInternalFormat;
|
|
|
2497
2243
|
exports.WebCanvas = WebCanvas;
|
|
2498
2244
|
exports.WebGLEngine = WebGLEngine;
|
|
2499
2245
|
exports.WebGLGraphicDevice = WebGLGraphicDevice;
|
|
2500
|
-
exports.WebGLMode = WebGLMode;
|
|
2501
2246
|
//# sourceMappingURL=main.js.map
|