@predy-js/render-interface 0.1.61-beta.8 → 0.1.61

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