@predy-js/render-interface 0.1.61-beta.9 → 0.1.62-beta.1

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/index.js CHANGED
@@ -2,11 +2,13 @@
2
2
  * Name: @predy-js/render-interface
3
3
  * Description: undefined
4
4
  * Author: undefined
5
- * Version: v0.1.61-beta.9
5
+ * Version: v0.1.62-beta.1
6
6
  */
7
7
 
8
8
  'use strict';
9
9
 
10
+ Object.defineProperty(exports, '__esModule', { value: true });
11
+
10
12
  /******************************************************************************
11
13
  Copyright (c) Microsoft Corporation.
12
14
 
@@ -151,7 +153,9 @@ exports.TextureSourceType = void 0;
151
153
  TextureSourceType[TextureSourceType["mipmaps"] = 7] = "mipmaps";
152
154
  })(exports.TextureSourceType || (exports.TextureSourceType = {}));
153
155
 
154
- var _a$6, _b$2;
156
+ var GPUBufferOptionsMemoryShared = 1 << 1;
157
+
158
+ var _a$6, _b$3;
155
159
  // @ts-expect-error safe to assign
156
160
  var constants = {};
157
161
  {
@@ -190,11 +194,11 @@ function getBytesPerElementByGLType(type) {
190
194
  var _a;
191
195
  return ((_a = map[type]) === null || _a === void 0 ? void 0 : _a.BYTES_PER_ELEMENT) || 0;
192
196
  }
193
- var MatAttrLocPairMap = (_b$2 = {},
194
- _b$2[constants.FLOAT_MAT2] = [2, 2],
195
- _b$2[constants.FLOAT_MAT3] = [3, 3],
196
- _b$2[constants.FLOAT_MAT4] = [4, 4],
197
- _b$2);
197
+ var MatAttrLocPairMap = (_b$3 = {},
198
+ _b$3[constants.FLOAT_MAT2] = [2, 2],
199
+ _b$3[constants.FLOAT_MAT3] = [3, 3],
200
+ _b$3[constants.FLOAT_MAT4] = [4, 4],
201
+ _b$3);
198
202
  function getMatAttrLocPair(type) {
199
203
  return MatAttrLocPairMap[type] || [1, 1];
200
204
  }
@@ -676,19 +680,17 @@ var GPUCapabilityEmpty = /** @class */ (function () {
676
680
  var GLGPUBuffer = /** @class */ (function () {
677
681
  function GLGPUBuffer(options, renderer) {
678
682
  this._isDestroyed = false;
679
- this.target = options.target || constants.ARRAY_BUFFER;
680
- this.type = options.type || constants.FLOAT;
681
683
  this.renderer = renderer;
682
684
  this.glBuffer = renderer.createGLBuffer(this, options.name);
683
685
  this.usage = options.usage || constants.STATIC_DRAW;
684
- this.bytesPerElement = getBytesPerElementByGLType(this.type);
685
686
  this._byteLength = 0;
686
687
  this.name = options.name || '';
688
+ this.target = options.target || constants.ARRAY_BUFFER;
687
689
  if (options.data) {
688
690
  this.bufferData(options.data);
689
691
  }
690
- else if (options.elementCount) {
691
- this.bufferData(getBytesPerElementByGLType(this.type) * options.elementCount);
692
+ else if (options.byteLength) {
693
+ this.bufferData(options.byteLength);
692
694
  }
693
695
  }
694
696
  Object.defineProperty(GLGPUBuffer.prototype, "byteLength", {
@@ -705,13 +707,6 @@ var GLGPUBuffer = /** @class */ (function () {
705
707
  enumerable: false,
706
708
  configurable: true
707
709
  });
708
- Object.defineProperty(GLGPUBuffer.prototype, "elementCount", {
709
- get: function () {
710
- return (this.byteLength / this.bytesPerElement);
711
- },
712
- enumerable: false,
713
- configurable: true
714
- });
715
710
  Object.defineProperty(GLGPUBuffer.prototype, "level", {
716
711
  get: function () {
717
712
  var _a;
@@ -749,6 +744,7 @@ var GLGPUBuffer = /** @class */ (function () {
749
744
  gl.bufferSubData(target, 0, typedArray);
750
745
  }
751
746
  }
747
+ gl.bindBuffer(target, null);
752
748
  }
753
749
  else {
754
750
  this._byteLength = 0;
@@ -758,7 +754,7 @@ var GLGPUBuffer = /** @class */ (function () {
758
754
  if (this.renderer) {
759
755
  var gl = this.renderer.gl;
760
756
  var target = this.target;
761
- var byteOffset = elementOffset * this.bytesPerElement;
757
+ var byteOffset = elementOffset * typedArray.BYTES_PER_ELEMENT;
762
758
  gl.bindBuffer(target, this.glBuffer);
763
759
  var byteLength = byteOffset + typedArray.byteLength;
764
760
  if (byteLength > this._byteLength) {
@@ -766,6 +762,7 @@ var GLGPUBuffer = /** @class */ (function () {
766
762
  gl.bufferData(target, byteLength, this.usage);
767
763
  }
768
764
  gl.bufferSubData(target, byteOffset, typedArray);
765
+ gl.bindBuffer(target, null);
769
766
  }
770
767
  else {
771
768
  this._byteLength = 0;
@@ -782,13 +779,19 @@ var GLGPUBuffer = /** @class */ (function () {
782
779
  var _a;
783
780
  if (this.level === 2) {
784
781
  var gl = (_a = this.renderer) === null || _a === void 0 ? void 0 : _a.gl;
782
+ var target = this.target;
785
783
  if (gl) {
786
- gl.getBufferSubData(this.target, elementOffset * this.bytesPerElement, typedArray);
784
+ gl.bindBuffer(target, this.glBuffer);
785
+ gl.getBufferSubData(target, elementOffset * typedArray.BYTES_PER_ELEMENT, typedArray);
786
+ gl.bindBuffer(target, null);
787
787
  return true;
788
788
  }
789
789
  }
790
790
  return false;
791
791
  };
792
+ GLGPUBuffer.prototype.getElementCount = function (bytePerElement) {
793
+ return this._byteLength / bytePerElement;
794
+ };
792
795
  GLGPUBuffer.prototype.assignRenderer = function (renderer) {
793
796
  if (!this.renderer) {
794
797
  // @ts-expect-error safe to assign
@@ -1450,7 +1453,7 @@ function assignTextureLoc(gl, info, value, renderer, index) {
1450
1453
  }
1451
1454
  }
1452
1455
 
1453
- var _a$4, _b$1;
1456
+ var _a$4, _b$2;
1454
1457
  var BlockUniformInfoOffset = 1;
1455
1458
  var BlockUniformInfoByteLength = 8;
1456
1459
  var BlockUniformInfoType = 0;
@@ -1592,43 +1595,42 @@ var MemorySetter = (_a$4 = {},
1592
1595
  _a$4[constants.BOOL_VEC3] = setUInt8Array,
1593
1596
  _a$4[constants.BOOL_VEC4] = setUInt8Array,
1594
1597
  _a$4);
1595
- var ItemPerValueMap = (_b$1 = {},
1596
- _b$1[constants.FLOAT] = 1,
1597
- _b$1[constants.INT] = 1,
1598
- _b$1[constants.UNSIGNED_INT] = 1,
1599
- _b$1[constants.SHORT] = 1,
1600
- _b$1[constants.BOOL] = 1,
1601
- _b$1[constants.UNSIGNED_SHORT] = 1,
1602
- _b$1[constants.FLOAT_VEC2] = 2,
1603
- _b$1[constants.FLOAT_VEC3] = 3,
1604
- _b$1[constants.FLOAT_VEC4] = 4,
1605
- _b$1[constants.FLOAT_MAT2] = 4,
1606
- _b$1[constants.FLOAT_MAT3] = 9,
1607
- _b$1[constants.FLOAT_MAT4] = 16,
1608
- _b$1[constants.FLOAT_MAT2x3] = 6,
1609
- _b$1[constants.FLOAT_MAT2x4] = 8,
1610
- _b$1[constants.FLOAT_MAT4x3] = 12,
1611
- _b$1[constants.FLOAT_MAT4x2] = 8,
1612
- _b$1[constants.FLOAT_MAT3x4] = 12,
1613
- _b$1[constants.FLOAT_MAT3x2] = 6,
1614
- _b$1[constants.INT_VEC2] = 2,
1615
- _b$1[constants.INT_VEC3] = 3,
1616
- _b$1[constants.INT_VEC4] = 4,
1617
- _b$1[constants.UNSIGNED_INT_VEC2] = 2,
1618
- _b$1[constants.UNSIGNED_INT_VEC3] = 3,
1619
- _b$1[constants.UNSIGNED_INT_VEC4] = 4,
1620
- _b$1[constants.BOOL_VEC2] = 2,
1621
- _b$1[constants.BOOL_VEC3] = 3,
1622
- _b$1[constants.BOOL_VEC4] = 4,
1623
- _b$1);
1598
+ var ItemPerValueMap = (_b$2 = {},
1599
+ _b$2[constants.FLOAT] = 1,
1600
+ _b$2[constants.INT] = 1,
1601
+ _b$2[constants.UNSIGNED_INT] = 1,
1602
+ _b$2[constants.SHORT] = 1,
1603
+ _b$2[constants.BOOL] = 1,
1604
+ _b$2[constants.UNSIGNED_SHORT] = 1,
1605
+ _b$2[constants.FLOAT_VEC2] = 2,
1606
+ _b$2[constants.FLOAT_VEC3] = 3,
1607
+ _b$2[constants.FLOAT_VEC4] = 4,
1608
+ _b$2[constants.FLOAT_MAT2] = 4,
1609
+ _b$2[constants.FLOAT_MAT3] = 9,
1610
+ _b$2[constants.FLOAT_MAT4] = 16,
1611
+ _b$2[constants.FLOAT_MAT2x3] = 6,
1612
+ _b$2[constants.FLOAT_MAT2x4] = 8,
1613
+ _b$2[constants.FLOAT_MAT4x3] = 12,
1614
+ _b$2[constants.FLOAT_MAT4x2] = 8,
1615
+ _b$2[constants.FLOAT_MAT3x4] = 12,
1616
+ _b$2[constants.FLOAT_MAT3x2] = 6,
1617
+ _b$2[constants.INT_VEC2] = 2,
1618
+ _b$2[constants.INT_VEC3] = 3,
1619
+ _b$2[constants.INT_VEC4] = 4,
1620
+ _b$2[constants.UNSIGNED_INT_VEC2] = 2,
1621
+ _b$2[constants.UNSIGNED_INT_VEC3] = 3,
1622
+ _b$2[constants.UNSIGNED_INT_VEC4] = 4,
1623
+ _b$2[constants.BOOL_VEC2] = 2,
1624
+ _b$2[constants.BOOL_VEC3] = 3,
1625
+ _b$2[constants.BOOL_VEC4] = 4,
1626
+ _b$2);
1624
1627
  var fullRange = [0, 0];
1625
1628
  var UniformBlockBuffer = /** @class */ (function () {
1626
1629
  function UniformBlockBuffer(renderer, info) {
1627
1630
  this.buffer = new GLGPUBuffer({
1628
1631
  target: constants.UNIFORM_BUFFER,
1629
1632
  name: info.name,
1630
- type: constants.BYTE,
1631
- elementCount: info.size,
1633
+ byteLength: info.size,
1632
1634
  }, renderer);
1633
1635
  this.dirtyFlags = {};
1634
1636
  this.info = info;
@@ -1858,12 +1860,12 @@ var GLProgram = /** @class */ (function () {
1858
1860
  val = _this.getSemanticValue(state, semanticName);
1859
1861
  }
1860
1862
  if (val !== undefined && val !== null) {
1861
- _this.setGLUniformValue(name, val, info, gl);
1862
- }
1863
- else if (!info.isTexture) {
1864
- consoleWarn("mesh ".concat(state.currentMesh.name, " uniform ").concat(name, " value unset"));
1863
+ return _this.setGLUniformValue(name, val, info, gl);
1865
1864
  }
1866
1865
  }
1866
+ if (!info.isTexture) {
1867
+ consoleWarn("mesh ".concat(state.currentMesh.name, " uniform ").concat(name, " value unset"));
1868
+ }
1867
1869
  });
1868
1870
  };
1869
1871
  GLProgram.prototype.setGLUniformValue = function (name, value, info, gl) {
@@ -2432,7 +2434,7 @@ function registerCompressedTexture(gl) {
2432
2434
  return 0;
2433
2435
  }
2434
2436
 
2435
- var _a$2, _b;
2437
+ var _a$2, _b$1;
2436
2438
  var flipCanvas;
2437
2439
  var imageBitMapAvailable$1 = typeof ImageBitmap === 'function' && typeof createImageBitmap == 'function';
2438
2440
  var GLTexture = /** @class */ (function () {
@@ -2763,14 +2765,14 @@ var FORMAT_HALF_FLOAT = (_a$2 = {},
2763
2765
  _a$2[constants.LUMINANCE_ALPHA] = 33327,
2764
2766
  _a$2[constants.LUMINANCE] = 33325,
2765
2767
  _a$2);
2766
- var FORMAT_FLOAT = (_b = {},
2767
- _b[constants.RGBA] = 34836,
2768
- _b[constants.RGB] = 34837,
2769
- _b[constants.ALPHA] = 33326,
2770
- _b[constants.RED] = 33326,
2771
- _b[constants.LUMINANCE_ALPHA] = 33328,
2772
- _b[constants.LUMINANCE] = 33326,
2773
- _b);
2768
+ var FORMAT_FLOAT = (_b$1 = {},
2769
+ _b$1[constants.RGBA] = 34836,
2770
+ _b$1[constants.RGB] = 34837,
2771
+ _b$1[constants.ALPHA] = 33326,
2772
+ _b$1[constants.RED] = 33326,
2773
+ _b$1[constants.LUMINANCE_ALPHA] = 33328,
2774
+ _b$1[constants.LUMINANCE] = 33326,
2775
+ _b$1);
2774
2776
 
2775
2777
  var GL_LOST_EVENT = 'webglcontextlost';
2776
2778
  var GLGPURenderer = /** @class */ (function () {
@@ -2816,6 +2818,12 @@ var GLGPURenderer = /** @class */ (function () {
2816
2818
  gl.canvas.addEventListener(GL_LOST_EVENT, this.onContextLose);
2817
2819
  }
2818
2820
  }
2821
+ GLGPURenderer.prototype.requestAnimationFrame = function (cb) {
2822
+ return window.requestAnimationFrame(cb);
2823
+ };
2824
+ GLGPURenderer.prototype.cancelAnimationFrame = function (id) {
2825
+ return window.cancelAnimationFrame(id);
2826
+ };
2819
2827
  Object.defineProperty(GLGPURenderer.prototype, "isDestroyed", {
2820
2828
  get: function () {
2821
2829
  return this._isDestroyed;
@@ -4686,6 +4694,9 @@ var MarsMaterialDataBlock = /** @class */ (function () {
4686
4694
  return new MarsMaterialDataBlock({
4687
4695
  name: name,
4688
4696
  uniformValues: this._uniformValues,
4697
+ uniformTextures: this._uniformTextures,
4698
+ uniformSemantics: this.uniformSemantics,
4699
+ keepUboData: this._keepUboData,
4689
4700
  }, this.renderer);
4690
4701
  };
4691
4702
  return MarsMaterialDataBlock;
@@ -4809,6 +4820,7 @@ var MarsMaterial = /** @class */ (function () {
4809
4820
  };
4810
4821
  MarsMaterial.prototype.removeDataBlock = function (b) {
4811
4822
  arrRemove(this._dataBlocks, b);
4823
+ delete this._dbMap[b.name];
4812
4824
  };
4813
4825
  MarsMaterial.prototype.assignRenderer = function (renderer) {
4814
4826
  if (!this.materialInternal) {
@@ -4882,12 +4894,15 @@ var GLVertexArrayObject = /** @class */ (function () {
4882
4894
  return GLVertexArrayObject;
4883
4895
  }());
4884
4896
 
4885
- var _a$1;
4897
+ var _a$1, _b;
4886
4898
  var INDEX_TYPE_MAP = (_a$1 = {},
4887
- _a$1[Uint8Array.BYTES_PER_ELEMENT] = constants.UNSIGNED_BYTE,
4888
4899
  _a$1[Uint16Array.BYTES_PER_ELEMENT] = constants.UNSIGNED_SHORT,
4889
4900
  _a$1[Uint32Array.BYTES_PER_ELEMENT] = constants.UNSIGNED_INT,
4890
4901
  _a$1);
4902
+ var TYPE_BYTE_MAP = (_b = {},
4903
+ _b[constants.UNSIGNED_SHORT] = Uint16Array.BYTES_PER_ELEMENT,
4904
+ _b[constants.UNSIGNED_INT] = Uint32Array.BYTES_PER_ELEMENT,
4905
+ _b);
4891
4906
  /**
4892
4907
  * GLGeometry对象,保存GLGPUBuffer对象。
4893
4908
  *
@@ -4913,7 +4928,8 @@ var GLGeometry = /** @class */ (function () {
4913
4928
  buffers[name] = new GLGPUBuffer(opt, renderer);
4914
4929
  });
4915
4930
  if (option.index && option.index.data) {
4916
- this._indexBuffer = this.createIndexBuffer(option.index.data, renderer);
4931
+ var ret = this.createIndexBuffer(option.index.data, renderer);
4932
+ this.setIndexBuffer(ret[0], ret[1]);
4917
4933
  }
4918
4934
  }
4919
4935
  this._buffersMap = buffers;
@@ -4935,18 +4951,18 @@ var GLGeometry = /** @class */ (function () {
4935
4951
  (_a = this.vaoMap[name]) === null || _a === void 0 ? void 0 : _a.destroy();
4936
4952
  this.vaoMap[name] = undefined;
4937
4953
  };
4938
- GLGeometry.prototype.setIndexBuffer = function (buffer) {
4954
+ GLGeometry.prototype.setIndexBuffer = function (buffer, indexBufferType) {
4939
4955
  this._indexBuffer = buffer;
4956
+ this.indexBufferType = indexBufferType;
4940
4957
  };
4941
4958
  GLGeometry.prototype.createIndexBuffer = function (data, renderer) {
4942
4959
  var type = INDEX_TYPE_MAP[data.BYTES_PER_ELEMENT];
4943
4960
  var indexOption = {
4944
4961
  data: data,
4945
4962
  target: constants.ELEMENT_ARRAY_BUFFER,
4946
- type: type,
4947
4963
  name: "".concat(this.name, "##index"),
4948
4964
  };
4949
- return new GLGPUBuffer(indexOption, renderer);
4965
+ return [new GLGPUBuffer(indexOption, renderer), type];
4950
4966
  };
4951
4967
  GLGeometry.prototype.getGPUBuffer = function (name) {
4952
4968
  return this._buffersMap[name];
@@ -4988,10 +5004,10 @@ var GLGeometry = /** @class */ (function () {
4988
5004
  if (gl && gpu) {
4989
5005
  var drawCount = this.drawCount;
4990
5006
  if (index) {
4991
- var type = index.type;
5007
+ var type = this.indexBufferType;
4992
5008
  //bind by vao
4993
5009
  //this._indexBuffer?.bind();
4994
- var dc = isNaN(drawCount) ? index.elementCount : drawCount;
5010
+ var dc = isNaN(drawCount) ? index.getElementCount(TYPE_BYTE_MAP[type]) : drawCount;
4995
5011
  if (dc > 0) {
4996
5012
  if (useInstancedDraw) {
4997
5013
  gpu.drawElementsInstanced(gl, this.mode, dc, type, this.drawStart || 0, state.currentMesh.instanceCount);
@@ -5087,7 +5103,6 @@ var MarsGeometry = /** @class */ (function () {
5087
5103
  buffers[name] = {
5088
5104
  data: data,
5089
5105
  usage: usage,
5090
- target: constants.ARRAY_BUFFER,
5091
5106
  name: name,
5092
5107
  };
5093
5108
  var gltype = attributeData2GLType(data);
@@ -5127,6 +5142,9 @@ var MarsGeometry = /** @class */ (function () {
5127
5142
  });
5128
5143
  // 顶点索引
5129
5144
  this._index = (_a = option.index) === null || _a === void 0 ? void 0 : _a.data;
5145
+ if (this._index instanceof Uint8Array) {
5146
+ throw Error('Uint8 Index not support');
5147
+ }
5130
5148
  dirtyFlags['index'] = {
5131
5149
  dirty: true,
5132
5150
  discard: true,
@@ -5242,7 +5260,6 @@ var MarsGeometry = /** @class */ (function () {
5242
5260
  data: data,
5243
5261
  usage: gpuBufferOption.usage,
5244
5262
  target: gpuBufferOption.target,
5245
- elementCount: data.length,
5246
5263
  };
5247
5264
  buffers[gpuBufferName] = option;
5248
5265
  this._dirtyFlags[gpuBufferName].discard = true;
@@ -5342,19 +5359,21 @@ var MarsGeometry = /** @class */ (function () {
5342
5359
  return this._attributesName;
5343
5360
  };
5344
5361
  MarsGeometry.prototype.assignRenderer = function (renderer) {
5345
- var _a;
5346
5362
  if (!this.internal) {
5347
5363
  // 索引缓冲区参数
5348
5364
  var indexBufferOption = undefined;
5349
5365
  if (this._index) {
5350
- var type = INDEX_TYPE_MAP[(_a = this._index) === null || _a === void 0 ? void 0 : _a.BYTES_PER_ELEMENT];
5351
5366
  var data = this._index;
5352
5367
  indexBufferOption = {
5353
- target: constants.ELEMENT_ARRAY_BUFFER,
5354
- type: type,
5355
5368
  data: data,
5356
5369
  usage: constants.STATIC_DRAW,
5357
5370
  };
5371
+ if (data instanceof Uint16Array) {
5372
+ this.indexDataType = constants.UNSIGNED_SHORT;
5373
+ }
5374
+ else if (data instanceof Uint32Array) {
5375
+ this.indexDataType = constants.UNSIGNED_INT;
5376
+ }
5358
5377
  }
5359
5378
  // 顶点属性参数
5360
5379
  var options = {
@@ -5365,6 +5384,7 @@ var MarsGeometry = /** @class */ (function () {
5365
5384
  buffers: this._buffers,
5366
5385
  mode: this.mode,
5367
5386
  index: indexBufferOption,
5387
+ indexDataType: this.indexDataType,
5368
5388
  name: this.name,
5369
5389
  };
5370
5390
  //@ts-expect-error safe to set
@@ -5773,7 +5793,8 @@ var MarsSharedGeometry = /** @class */ (function (_super) {
5773
5793
  glgeo.drawStart = this.drawStart;
5774
5794
  glgeo.mode = this.mode;
5775
5795
  if (this._index) {
5776
- glgeo._indexBuffer = glgeo.createIndexBuffer(this._index, renderer.internal);
5796
+ var ret = glgeo.createIndexBuffer(this._index, renderer.internal);
5797
+ glgeo.setIndexBuffer(ret[0], ret[1]);
5777
5798
  }
5778
5799
  //@ts-expect-error safe to assign
5779
5800
  this.internal = glgeo;
@@ -5804,8 +5825,9 @@ var MarsSharedGeometry = /** @class */ (function (_super) {
5804
5825
  return MarsSharedGeometry;
5805
5826
  }(MarsGeometry));
5806
5827
 
5807
- consoleLog('version: ' + "0.1.61-beta.9");
5828
+ consoleLog('version: ' + "0.1.62-beta.1");
5808
5829
 
5830
+ exports.GPUBufferOptionsMemoryShared = GPUBufferOptionsMemoryShared;
5809
5831
  exports.Geometry = MarsGeometry;
5810
5832
  exports.InstancedMesh = MarsInstancedMesh;
5811
5833
  exports.MarsTextureFactory = MarsTextureFactory;