@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 CHANGED
@@ -248,11 +248,7 @@ function _create_class(Constructor, protoProps, staticProps) {
248
248
  var webGLGraphicDevice = new WebGLGraphicDevice(configuration.graphicDeviceOptions);
249
249
  var engine = new WebGLEngine(webCanvas, webGLGraphicDevice, configuration);
250
250
  webCanvas.setAutoResolution();
251
- var promise = engine._initialize(configuration);
252
- return promise.then(function() {
253
- engine.sceneManager.addScene(new engineCore.Scene(engine, "DefaultScene"));
254
- return engine;
255
- });
251
+ return engine._initialize(configuration);
256
252
  };
257
253
  _create_class(WebGLEngine, [
258
254
  {
@@ -414,6 +410,45 @@ var GLBuffer = /*#__PURE__*/ function() {
414
410
  return false;
415
411
  };
416
412
  /**
413
+ * Check whether the given texture format is supported.
414
+ */ _proto.supportsTextureFormat = function supportsTextureFormat(format) {
415
+ switch(format){
416
+ case engineCore.TextureFormat.R16G16B16A16:
417
+ return this.canIUse(engineCore.GLCapabilityType.textureHalfFloat);
418
+ case engineCore.TextureFormat.R32G32B32A32:
419
+ return this.canIUse(engineCore.GLCapabilityType.textureFloat);
420
+ case engineCore.TextureFormat.Depth16:
421
+ case engineCore.TextureFormat.Depth24Stencil8:
422
+ case engineCore.TextureFormat.Depth:
423
+ case engineCore.TextureFormat.DepthStencil:
424
+ return this.canIUse(engineCore.GLCapabilityType.depthTexture);
425
+ case engineCore.TextureFormat.R11G11B10_UFloat:
426
+ case engineCore.TextureFormat.R32G32B32A32_UInt:
427
+ case engineCore.TextureFormat.Depth24:
428
+ case engineCore.TextureFormat.Depth32:
429
+ case engineCore.TextureFormat.Depth32Stencil8:
430
+ case engineCore.TextureFormat.R8:
431
+ case engineCore.TextureFormat.R8G8:
432
+ return this.rhi.isWebGL2;
433
+ default:
434
+ return true;
435
+ }
436
+ };
437
+ /**
438
+ * Check whether the given texture format can be rendered to as a color attachment.
439
+ */ _proto.supportsRenderTargetColorFormat = function supportsRenderTargetColorFormat(format) {
440
+ switch(format){
441
+ case engineCore.TextureFormat.R16G16B16A16:
442
+ return this.canIUse(engineCore.GLCapabilityType.colorBufferHalfFloat) && this.canIUse(engineCore.GLCapabilityType.textureHalfFloat);
443
+ case engineCore.TextureFormat.R32G32B32A32:
444
+ return this.canIUse(engineCore.GLCapabilityType.colorBufferFloat) && this.canIUse(engineCore.GLCapabilityType.textureFloat);
445
+ case engineCore.TextureFormat.R11G11B10_UFloat:
446
+ return this.rhi.isWebGL2 && this.canIUse(engineCore.GLCapabilityType.colorBufferFloat);
447
+ default:
448
+ return this.supportsTextureFormat(format);
449
+ }
450
+ };
451
+ /**
417
452
  * Init capabilities.
418
453
  */ _proto._init = function _init() {
419
454
  var cap = this.capabilityList;
@@ -534,6 +569,12 @@ var GLBuffer = /*#__PURE__*/ function() {
534
569
  return this.rhi.renderStates.getParameter(this.rhi.gl.MAX_TEXTURE_SIZE);
535
570
  }
536
571
  },
572
+ {
573
+ key: "maxVertexUniformVectors",
574
+ get: function get() {
575
+ return this.rhi.renderStates.getParameter(this.rhi.gl.MAX_VERTEX_UNIFORM_VECTORS);
576
+ }
577
+ },
537
578
  {
538
579
  key: "canUseFloatTextureBlendShape",
539
580
  get: function get() {
@@ -833,6 +874,7 @@ var GLBuffer = /*#__PURE__*/ function() {
833
874
  /**
834
875
  * @internal
835
876
  */ _proto.setUseDepthCompareMode = function setUseDepthCompareMode(value) {
877
+ if (!this._isWebGL2) return;
836
878
  var gl = this._gl;
837
879
  gl.texParameteri(this._target, gl.TEXTURE_COMPARE_MODE, value ? gl.COMPARE_REF_TO_TEXTURE : gl.NONE);
838
880
  };
@@ -1303,33 +1345,6 @@ var GLBuffer = /*#__PURE__*/ function() {
1303
1345
  };
1304
1346
  /**
1305
1347
  * @internal
1306
- */ GLTexture._supportRenderBufferColorFormat = function _supportRenderBufferColorFormat(format, rhi) {
1307
- var isSupported = true;
1308
- switch(format){
1309
- case engineCore.TextureFormat.R16G16B16A16:
1310
- {
1311
- if (!rhi.canIUse(engineCore.GLCapabilityType.colorBufferHalfFloat) || !rhi.canIUse(engineCore.GLCapabilityType.textureHalfFloat)) {
1312
- isSupported = false;
1313
- }
1314
- }
1315
- break;
1316
- case engineCore.TextureFormat.R32G32B32A32:
1317
- {
1318
- if (!rhi.canIUse(engineCore.GLCapabilityType.colorBufferFloat) || !rhi.canIUse(engineCore.GLCapabilityType.textureFloat)) {
1319
- isSupported = false;
1320
- }
1321
- }
1322
- break;
1323
- case engineCore.TextureFormat.R11G11B10_UFloat:
1324
- {
1325
- isSupported = rhi.isWebGL2;
1326
- }
1327
- break;
1328
- }
1329
- return isSupported;
1330
- };
1331
- /**
1332
- * @internal
1333
1348
  */ GLTexture._supportRenderBufferDepthFormat = function _supportRenderBufferDepthFormat(format, rhi) {
1334
1349
  if (!rhi.isWebGL2) {
1335
1350
  switch(format){
@@ -1392,12 +1407,13 @@ var GLBuffer = /*#__PURE__*/ function() {
1392
1407
  */ function set(value) {
1393
1408
  var gl = this._gl;
1394
1409
  this._bind();
1395
- gl.texParameterf(this._target, gl.TEXTURE_MAX_ANISOTROPY_EXT, value);
1410
+ gl.texParameterf(this._target, gl.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(value, this._rhi.capability.maxAnisoLevel));
1396
1411
  }
1397
1412
  },
1398
1413
  {
1399
1414
  key: "depthCompareFunction",
1400
1415
  set: function set(value) {
1416
+ if (!this._isWebGL2 || value === undefined) return;
1401
1417
  this._bind();
1402
1418
  var gl = this._gl;
1403
1419
  switch(value){
@@ -1442,6 +1458,7 @@ var GLBuffer = /*#__PURE__*/ function() {
1442
1458
  this._gl = rhi.gl;
1443
1459
  this._isWebGL2 = rhi.isWebGL2;
1444
1460
  this._target = target;
1461
+ this._antiAliasing = Math.min(target.antiAliasing, rhi.capability.maxAntiAliasing);
1445
1462
  /** @ts-ignore */ var _colorTextures = target._colorTextures, _depth = target._depth, width = target.width, height = target.height;
1446
1463
  var isDepthTexture = _instanceof(_depth, engineCore.Texture);
1447
1464
  /** todo
@@ -1449,7 +1466,7 @@ var GLBuffer = /*#__PURE__*/ function() {
1449
1466
  * MRT + MSAA
1450
1467
  */ for(var i = 0, n = _colorTextures.length; i < n; i++){
1451
1468
  var _colorTextures_i = _colorTextures[i], format = _colorTextures_i.format, isSRGBColorSpace = _colorTextures_i.isSRGBColorSpace;
1452
- if (!GLTexture._supportRenderBufferColorFormat(format, rhi)) {
1469
+ if (!rhi.supportsRenderTargetColorFormat(format)) {
1453
1470
  throw new Error("TextureFormat is not supported:" + engineCore.TextureFormat[format] + " in RenderTarget");
1454
1471
  }
1455
1472
  if (isSRGBColorSpace && format === engineCore.TextureFormat.R8G8B8) {
@@ -1480,7 +1497,7 @@ var GLBuffer = /*#__PURE__*/ function() {
1480
1497
  // bind main FBO
1481
1498
  this._bindMainFBO();
1482
1499
  // bind MSAA FBO
1483
- if (target.antiAliasing > 1) {
1500
+ if (this._antiAliasing > 1) {
1484
1501
  this._MSAAFrameBuffer = this._gl.createFramebuffer();
1485
1502
  this._bindMSAAFBO();
1486
1503
  }
@@ -1584,7 +1601,7 @@ var GLBuffer = /*#__PURE__*/ function() {
1584
1601
  var platformTexture = _depth._platformTexture;
1585
1602
  gl.framebufferTexture2D(gl.FRAMEBUFFER, platformTexture._formatDetail.attachment, gl.TEXTURE_2D, platformTexture._glTexture, 0);
1586
1603
  }
1587
- } else if (this._target.antiAliasing <= 1) {
1604
+ } else if (this._antiAliasing <= 1) {
1588
1605
  var _GLTexture__getRenderBufferDepthFormatDetail = GLTexture._getRenderBufferDepthFormatDetail(_depth, gl, isWebGL2), internalFormat = _GLTexture__getRenderBufferDepthFormatDetail.internalFormat, attachment1 = _GLTexture__getRenderBufferDepthFormatDetail.attachment;
1589
1606
  this._depthRenderBuffer = this._createRenderBuffer(internalFormat, attachment1);
1590
1607
  }
@@ -1616,7 +1633,8 @@ var GLBuffer = /*#__PURE__*/ function() {
1616
1633
  };
1617
1634
  _proto._createRenderBuffer = function _createRenderBuffer(internalFormat, attachment) {
1618
1635
  var gl = this._gl;
1619
- var _this__target = this._target, width = _this__target.width, height = _this__target.height, antiAliasing = _this__target.antiAliasing;
1636
+ var _this__target = this._target, width = _this__target.width, height = _this__target.height;
1637
+ var antiAliasing = this._antiAliasing;
1620
1638
  var renderBuffer = gl.createRenderbuffer();
1621
1639
  gl.bindRenderbuffer(gl.RENDERBUFFER, renderBuffer);
1622
1640
  if (antiAliasing > 1) {
@@ -1725,6 +1743,9 @@ var GLBuffer = /*#__PURE__*/ function() {
1725
1743
  _inherits(GLTexture2DArray, GLTexture1);
1726
1744
  function GLTexture2DArray(rhi, texture2DArray) {
1727
1745
  var _this;
1746
+ if (!rhi.isWebGL2) {
1747
+ throw new Error("Texture2D Array is not supported in WebGL1.0");
1748
+ }
1728
1749
  _this = GLTexture1.call(this, rhi, texture2DArray, rhi.gl.TEXTURE_2D_ARRAY) || this;
1729
1750
  _this._validate(texture2DArray, rhi);
1730
1751
  var format = texture2DArray.format, width = texture2DArray.width, height = texture2DArray.height, length = texture2DArray.length, mipmapCount = texture2DArray.mipmapCount, isSRGBColorSpace = texture2DArray.isSRGBColorSpace;
@@ -2012,6 +2033,7 @@ var GLBuffer = /*#__PURE__*/ function() {
2012
2033
  */ var WebGLGraphicDevice = /*#__PURE__*/ function() {
2013
2034
  function WebGLGraphicDevice(initializeOptions) {
2014
2035
  if (initializeOptions === void 0) initializeOptions = {};
2036
+ this.supportsRendering = true;
2015
2037
  /** @internal */ this._readFrameBuffer = null;
2016
2038
  /** @internal */ this._mainFrameBuffer = null;
2017
2039
  /** @internal */ this._mainFrameWidth = 0;
@@ -2172,6 +2194,12 @@ var GLBuffer = /*#__PURE__*/ function() {
2172
2194
  _proto.canIUseCompressedTextureInternalFormat = function canIUseCompressedTextureInternalFormat(type) {
2173
2195
  return this.capability.canIUseCompressedTextureInternalFormat(type);
2174
2196
  };
2197
+ _proto.supportsTextureFormat = function supportsTextureFormat(format) {
2198
+ return this.capability.supportsTextureFormat(format);
2199
+ };
2200
+ _proto.supportsRenderTargetColorFormat = function supportsRenderTargetColorFormat(format) {
2201
+ return this.capability.supportsRenderTargetColorFormat(format);
2202
+ };
2175
2203
  _proto.viewport = function viewport(x, y, width, height) {
2176
2204
  var _this = this, gl = _this._gl, lastViewport = _this._lastViewport;
2177
2205
  if (x !== lastViewport.x || y !== lastViewport.y || width !== lastViewport.z || height !== lastViewport.w) {
@@ -2236,7 +2264,7 @@ var GLBuffer = /*#__PURE__*/ function() {
2236
2264
  };
2237
2265
  _proto.drawPrimitive = function drawPrimitive(primitive, subPrimitive, shaderProgram) {
2238
2266
  // todo: VAO not support morph animation
2239
- if (primitive) {
2267
+ if (primitive && subPrimitive) {
2240
2268
  primitive.draw(shaderProgram, subPrimitive);
2241
2269
  } else {
2242
2270
  engineCore.Logger.error("draw primitive failed.");
@@ -2340,7 +2368,8 @@ var GLBuffer = /*#__PURE__*/ function() {
2340
2368
  this._activeTextureID = textureID;
2341
2369
  }
2342
2370
  };
2343
- _proto.bindTexture = function bindTexture(texture) {
2371
+ _proto.bindTexture = function bindTexture(platformTexture) {
2372
+ var texture = platformTexture;
2344
2373
  var index = this._activeTextureID - this._gl.TEXTURE0;
2345
2374
  if (this._activeTextures[index] !== texture) {
2346
2375
  this._gl.bindTexture(texture._target, texture._glTexture);