@galacean/engine-rhi-webgl 2.0.0-alpha.57 → 2.0.0-alpha.59
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 +68 -39
- package/dist/main.js.map +1 -1
- package/dist/module.js +69 -40
- package/dist/module.js.map +1 -1
- package/package.json +3 -6
- package/types/GLCapability.d.ts +11 -2
- package/types/GLPrimitive.d.ts +1 -3
- package/types/GLRenderTarget.d.ts +1 -0
- package/types/GLTexture.d.ts +0 -4
- package/types/GLTransformFeedbackPrimitive.d.ts +1 -2
- package/types/WebGLGraphicDevice.d.ts +9 -8
package/dist/module.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Canvas,
|
|
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
2
|
import { MathUtil, Vector4, Color } from '@galacean/engine-math';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -244,11 +244,7 @@ function _create_class(Constructor, protoProps, staticProps) {
|
|
|
244
244
|
var webGLGraphicDevice = new WebGLGraphicDevice(configuration.graphicDeviceOptions);
|
|
245
245
|
var engine = new WebGLEngine(webCanvas, webGLGraphicDevice, configuration);
|
|
246
246
|
webCanvas.setAutoResolution();
|
|
247
|
-
|
|
248
|
-
return promise.then(function() {
|
|
249
|
-
engine.sceneManager.addScene(new Scene(engine, "DefaultScene"));
|
|
250
|
-
return engine;
|
|
251
|
-
});
|
|
247
|
+
return engine._initialize(configuration);
|
|
252
248
|
};
|
|
253
249
|
_create_class(WebGLEngine, [
|
|
254
250
|
{
|
|
@@ -410,6 +406,45 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
410
406
|
return false;
|
|
411
407
|
};
|
|
412
408
|
/**
|
|
409
|
+
* Check whether the given texture format is supported.
|
|
410
|
+
*/ _proto.supportsTextureFormat = function supportsTextureFormat(format) {
|
|
411
|
+
switch(format){
|
|
412
|
+
case TextureFormat.R16G16B16A16:
|
|
413
|
+
return this.canIUse(GLCapabilityType.textureHalfFloat);
|
|
414
|
+
case TextureFormat.R32G32B32A32:
|
|
415
|
+
return this.canIUse(GLCapabilityType.textureFloat);
|
|
416
|
+
case TextureFormat.Depth16:
|
|
417
|
+
case TextureFormat.Depth24Stencil8:
|
|
418
|
+
case TextureFormat.Depth:
|
|
419
|
+
case TextureFormat.DepthStencil:
|
|
420
|
+
return this.canIUse(GLCapabilityType.depthTexture);
|
|
421
|
+
case TextureFormat.R11G11B10_UFloat:
|
|
422
|
+
case TextureFormat.R32G32B32A32_UInt:
|
|
423
|
+
case TextureFormat.Depth24:
|
|
424
|
+
case TextureFormat.Depth32:
|
|
425
|
+
case TextureFormat.Depth32Stencil8:
|
|
426
|
+
case TextureFormat.R8:
|
|
427
|
+
case TextureFormat.R8G8:
|
|
428
|
+
return this.rhi.isWebGL2;
|
|
429
|
+
default:
|
|
430
|
+
return true;
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
/**
|
|
434
|
+
* Check whether the given texture format can be rendered to as a color attachment.
|
|
435
|
+
*/ _proto.supportsRenderTargetColorFormat = function supportsRenderTargetColorFormat(format) {
|
|
436
|
+
switch(format){
|
|
437
|
+
case TextureFormat.R16G16B16A16:
|
|
438
|
+
return this.canIUse(GLCapabilityType.colorBufferHalfFloat) && this.canIUse(GLCapabilityType.textureHalfFloat);
|
|
439
|
+
case TextureFormat.R32G32B32A32:
|
|
440
|
+
return this.canIUse(GLCapabilityType.colorBufferFloat) && this.canIUse(GLCapabilityType.textureFloat);
|
|
441
|
+
case TextureFormat.R11G11B10_UFloat:
|
|
442
|
+
return this.rhi.isWebGL2 && this.canIUse(GLCapabilityType.colorBufferFloat);
|
|
443
|
+
default:
|
|
444
|
+
return this.supportsTextureFormat(format);
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
/**
|
|
413
448
|
* Init capabilities.
|
|
414
449
|
*/ _proto._init = function _init() {
|
|
415
450
|
var cap = this.capabilityList;
|
|
@@ -530,6 +565,12 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
530
565
|
return this.rhi.renderStates.getParameter(this.rhi.gl.MAX_TEXTURE_SIZE);
|
|
531
566
|
}
|
|
532
567
|
},
|
|
568
|
+
{
|
|
569
|
+
key: "maxVertexUniformVectors",
|
|
570
|
+
get: function get() {
|
|
571
|
+
return this.rhi.renderStates.getParameter(this.rhi.gl.MAX_VERTEX_UNIFORM_VECTORS);
|
|
572
|
+
}
|
|
573
|
+
},
|
|
533
574
|
{
|
|
534
575
|
key: "canUseFloatTextureBlendShape",
|
|
535
576
|
get: function get() {
|
|
@@ -829,6 +870,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
829
870
|
/**
|
|
830
871
|
* @internal
|
|
831
872
|
*/ _proto.setUseDepthCompareMode = function setUseDepthCompareMode(value) {
|
|
873
|
+
if (!this._isWebGL2) return;
|
|
832
874
|
var gl = this._gl;
|
|
833
875
|
gl.texParameteri(this._target, gl.TEXTURE_COMPARE_MODE, value ? gl.COMPARE_REF_TO_TEXTURE : gl.NONE);
|
|
834
876
|
};
|
|
@@ -1299,33 +1341,6 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1299
1341
|
};
|
|
1300
1342
|
/**
|
|
1301
1343
|
* @internal
|
|
1302
|
-
*/ GLTexture._supportRenderBufferColorFormat = function _supportRenderBufferColorFormat(format, rhi) {
|
|
1303
|
-
var isSupported = true;
|
|
1304
|
-
switch(format){
|
|
1305
|
-
case TextureFormat.R16G16B16A16:
|
|
1306
|
-
{
|
|
1307
|
-
if (!rhi.canIUse(GLCapabilityType.colorBufferHalfFloat) || !rhi.canIUse(GLCapabilityType.textureHalfFloat)) {
|
|
1308
|
-
isSupported = false;
|
|
1309
|
-
}
|
|
1310
|
-
}
|
|
1311
|
-
break;
|
|
1312
|
-
case TextureFormat.R32G32B32A32:
|
|
1313
|
-
{
|
|
1314
|
-
if (!rhi.canIUse(GLCapabilityType.colorBufferFloat) || !rhi.canIUse(GLCapabilityType.textureFloat)) {
|
|
1315
|
-
isSupported = false;
|
|
1316
|
-
}
|
|
1317
|
-
}
|
|
1318
|
-
break;
|
|
1319
|
-
case TextureFormat.R11G11B10_UFloat:
|
|
1320
|
-
{
|
|
1321
|
-
isSupported = rhi.isWebGL2;
|
|
1322
|
-
}
|
|
1323
|
-
break;
|
|
1324
|
-
}
|
|
1325
|
-
return isSupported;
|
|
1326
|
-
};
|
|
1327
|
-
/**
|
|
1328
|
-
* @internal
|
|
1329
1344
|
*/ GLTexture._supportRenderBufferDepthFormat = function _supportRenderBufferDepthFormat(format, rhi) {
|
|
1330
1345
|
if (!rhi.isWebGL2) {
|
|
1331
1346
|
switch(format){
|
|
@@ -1388,12 +1403,13 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1388
1403
|
*/ function set(value) {
|
|
1389
1404
|
var gl = this._gl;
|
|
1390
1405
|
this._bind();
|
|
1391
|
-
gl.texParameterf(this._target, gl.TEXTURE_MAX_ANISOTROPY_EXT, value);
|
|
1406
|
+
gl.texParameterf(this._target, gl.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(value, this._rhi.capability.maxAnisoLevel));
|
|
1392
1407
|
}
|
|
1393
1408
|
},
|
|
1394
1409
|
{
|
|
1395
1410
|
key: "depthCompareFunction",
|
|
1396
1411
|
set: function set(value) {
|
|
1412
|
+
if (!this._isWebGL2 || value === undefined) return;
|
|
1397
1413
|
this._bind();
|
|
1398
1414
|
var gl = this._gl;
|
|
1399
1415
|
switch(value){
|
|
@@ -1438,6 +1454,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1438
1454
|
this._gl = rhi.gl;
|
|
1439
1455
|
this._isWebGL2 = rhi.isWebGL2;
|
|
1440
1456
|
this._target = target;
|
|
1457
|
+
this._antiAliasing = Math.min(target.antiAliasing, rhi.capability.maxAntiAliasing);
|
|
1441
1458
|
/** @ts-ignore */ var _colorTextures = target._colorTextures, _depth = target._depth, width = target.width, height = target.height;
|
|
1442
1459
|
var isDepthTexture = _instanceof(_depth, Texture);
|
|
1443
1460
|
/** todo
|
|
@@ -1445,7 +1462,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1445
1462
|
* MRT + MSAA
|
|
1446
1463
|
*/ for(var i = 0, n = _colorTextures.length; i < n; i++){
|
|
1447
1464
|
var _colorTextures_i = _colorTextures[i], format = _colorTextures_i.format, isSRGBColorSpace = _colorTextures_i.isSRGBColorSpace;
|
|
1448
|
-
if (!
|
|
1465
|
+
if (!rhi.supportsRenderTargetColorFormat(format)) {
|
|
1449
1466
|
throw new Error("TextureFormat is not supported:" + TextureFormat[format] + " in RenderTarget");
|
|
1450
1467
|
}
|
|
1451
1468
|
if (isSRGBColorSpace && format === TextureFormat.R8G8B8) {
|
|
@@ -1476,7 +1493,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1476
1493
|
// bind main FBO
|
|
1477
1494
|
this._bindMainFBO();
|
|
1478
1495
|
// bind MSAA FBO
|
|
1479
|
-
if (
|
|
1496
|
+
if (this._antiAliasing > 1) {
|
|
1480
1497
|
this._MSAAFrameBuffer = this._gl.createFramebuffer();
|
|
1481
1498
|
this._bindMSAAFBO();
|
|
1482
1499
|
}
|
|
@@ -1580,7 +1597,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1580
1597
|
var platformTexture = _depth._platformTexture;
|
|
1581
1598
|
gl.framebufferTexture2D(gl.FRAMEBUFFER, platformTexture._formatDetail.attachment, gl.TEXTURE_2D, platformTexture._glTexture, 0);
|
|
1582
1599
|
}
|
|
1583
|
-
} else if (this.
|
|
1600
|
+
} else if (this._antiAliasing <= 1) {
|
|
1584
1601
|
var _GLTexture__getRenderBufferDepthFormatDetail = GLTexture._getRenderBufferDepthFormatDetail(_depth, gl, isWebGL2), internalFormat = _GLTexture__getRenderBufferDepthFormatDetail.internalFormat, attachment1 = _GLTexture__getRenderBufferDepthFormatDetail.attachment;
|
|
1585
1602
|
this._depthRenderBuffer = this._createRenderBuffer(internalFormat, attachment1);
|
|
1586
1603
|
}
|
|
@@ -1612,7 +1629,8 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1612
1629
|
};
|
|
1613
1630
|
_proto._createRenderBuffer = function _createRenderBuffer(internalFormat, attachment) {
|
|
1614
1631
|
var gl = this._gl;
|
|
1615
|
-
var _this__target = this._target, width = _this__target.width, height = _this__target.height
|
|
1632
|
+
var _this__target = this._target, width = _this__target.width, height = _this__target.height;
|
|
1633
|
+
var antiAliasing = this._antiAliasing;
|
|
1616
1634
|
var renderBuffer = gl.createRenderbuffer();
|
|
1617
1635
|
gl.bindRenderbuffer(gl.RENDERBUFFER, renderBuffer);
|
|
1618
1636
|
if (antiAliasing > 1) {
|
|
@@ -1721,6 +1739,9 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
1721
1739
|
_inherits(GLTexture2DArray, GLTexture1);
|
|
1722
1740
|
function GLTexture2DArray(rhi, texture2DArray) {
|
|
1723
1741
|
var _this;
|
|
1742
|
+
if (!rhi.isWebGL2) {
|
|
1743
|
+
throw new Error("Texture2D Array is not supported in WebGL1.0");
|
|
1744
|
+
}
|
|
1724
1745
|
_this = GLTexture1.call(this, rhi, texture2DArray, rhi.gl.TEXTURE_2D_ARRAY) || this;
|
|
1725
1746
|
_this._validate(texture2DArray, rhi);
|
|
1726
1747
|
var format = texture2DArray.format, width = texture2DArray.width, height = texture2DArray.height, length = texture2DArray.length, mipmapCount = texture2DArray.mipmapCount, isSRGBColorSpace = texture2DArray.isSRGBColorSpace;
|
|
@@ -2008,6 +2029,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2008
2029
|
*/ var WebGLGraphicDevice = /*#__PURE__*/ function() {
|
|
2009
2030
|
function WebGLGraphicDevice(initializeOptions) {
|
|
2010
2031
|
if (initializeOptions === void 0) initializeOptions = {};
|
|
2032
|
+
this.supportsRendering = true;
|
|
2011
2033
|
/** @internal */ this._readFrameBuffer = null;
|
|
2012
2034
|
/** @internal */ this._mainFrameBuffer = null;
|
|
2013
2035
|
/** @internal */ this._mainFrameWidth = 0;
|
|
@@ -2168,6 +2190,12 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2168
2190
|
_proto.canIUseCompressedTextureInternalFormat = function canIUseCompressedTextureInternalFormat(type) {
|
|
2169
2191
|
return this.capability.canIUseCompressedTextureInternalFormat(type);
|
|
2170
2192
|
};
|
|
2193
|
+
_proto.supportsTextureFormat = function supportsTextureFormat(format) {
|
|
2194
|
+
return this.capability.supportsTextureFormat(format);
|
|
2195
|
+
};
|
|
2196
|
+
_proto.supportsRenderTargetColorFormat = function supportsRenderTargetColorFormat(format) {
|
|
2197
|
+
return this.capability.supportsRenderTargetColorFormat(format);
|
|
2198
|
+
};
|
|
2171
2199
|
_proto.viewport = function viewport(x, y, width, height) {
|
|
2172
2200
|
var _this = this, gl = _this._gl, lastViewport = _this._lastViewport;
|
|
2173
2201
|
if (x !== lastViewport.x || y !== lastViewport.y || width !== lastViewport.z || height !== lastViewport.w) {
|
|
@@ -2232,7 +2260,7 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2232
2260
|
};
|
|
2233
2261
|
_proto.drawPrimitive = function drawPrimitive(primitive, subPrimitive, shaderProgram) {
|
|
2234
2262
|
// todo: VAO not support morph animation
|
|
2235
|
-
if (primitive) {
|
|
2263
|
+
if (primitive && subPrimitive) {
|
|
2236
2264
|
primitive.draw(shaderProgram, subPrimitive);
|
|
2237
2265
|
} else {
|
|
2238
2266
|
Logger.error("draw primitive failed.");
|
|
@@ -2336,7 +2364,8 @@ var GLBuffer = /*#__PURE__*/ function() {
|
|
|
2336
2364
|
this._activeTextureID = textureID;
|
|
2337
2365
|
}
|
|
2338
2366
|
};
|
|
2339
|
-
_proto.bindTexture = function bindTexture(
|
|
2367
|
+
_proto.bindTexture = function bindTexture(platformTexture) {
|
|
2368
|
+
var texture = platformTexture;
|
|
2340
2369
|
var index = this._activeTextureID - this._gl.TEXTURE0;
|
|
2341
2370
|
if (this._activeTextures[index] !== texture) {
|
|
2342
2371
|
this._gl.bindTexture(texture._target, texture._glTexture);
|