@predy-js/render-interface 0.1.61-beta.20 → 0.1.61-beta.22

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.20
5
+ * Version: v0.1.61-beta.22
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;
@@ -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;
@@ -4888,12 +4894,15 @@ var GLVertexArrayObject = /** @class */ (function () {
4888
4894
  return GLVertexArrayObject;
4889
4895
  }());
4890
4896
 
4891
- var _a$1;
4897
+ var _a$1, _b;
4892
4898
  var INDEX_TYPE_MAP = (_a$1 = {},
4893
- _a$1[Uint8Array.BYTES_PER_ELEMENT] = constants.UNSIGNED_BYTE,
4894
4899
  _a$1[Uint16Array.BYTES_PER_ELEMENT] = constants.UNSIGNED_SHORT,
4895
4900
  _a$1[Uint32Array.BYTES_PER_ELEMENT] = constants.UNSIGNED_INT,
4896
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);
4897
4906
  /**
4898
4907
  * GLGeometry对象,保存GLGPUBuffer对象。
4899
4908
  *
@@ -4919,7 +4928,8 @@ var GLGeometry = /** @class */ (function () {
4919
4928
  buffers[name] = new GLGPUBuffer(opt, renderer);
4920
4929
  });
4921
4930
  if (option.index && option.index.data) {
4922
- this._indexBuffer = this.createIndexBuffer(option.index.data, renderer);
4931
+ var ret = this.createIndexBuffer(option.index.data, renderer);
4932
+ this.setIndexBuffer(ret[0], ret[1]);
4923
4933
  }
4924
4934
  }
4925
4935
  this._buffersMap = buffers;
@@ -4941,18 +4951,18 @@ var GLGeometry = /** @class */ (function () {
4941
4951
  (_a = this.vaoMap[name]) === null || _a === void 0 ? void 0 : _a.destroy();
4942
4952
  this.vaoMap[name] = undefined;
4943
4953
  };
4944
- GLGeometry.prototype.setIndexBuffer = function (buffer) {
4954
+ GLGeometry.prototype.setIndexBuffer = function (buffer, indexBufferType) {
4945
4955
  this._indexBuffer = buffer;
4956
+ this.indexBufferType = indexBufferType;
4946
4957
  };
4947
4958
  GLGeometry.prototype.createIndexBuffer = function (data, renderer) {
4948
4959
  var type = INDEX_TYPE_MAP[data.BYTES_PER_ELEMENT];
4949
4960
  var indexOption = {
4950
4961
  data: data,
4951
4962
  target: constants.ELEMENT_ARRAY_BUFFER,
4952
- type: type,
4953
4963
  name: "".concat(this.name, "##index"),
4954
4964
  };
4955
- return new GLGPUBuffer(indexOption, renderer);
4965
+ return [new GLGPUBuffer(indexOption, renderer), type];
4956
4966
  };
4957
4967
  GLGeometry.prototype.getGPUBuffer = function (name) {
4958
4968
  return this._buffersMap[name];
@@ -4994,10 +5004,10 @@ var GLGeometry = /** @class */ (function () {
4994
5004
  if (gl && gpu) {
4995
5005
  var drawCount = this.drawCount;
4996
5006
  if (index) {
4997
- var type = index.type;
5007
+ var type = this.indexBufferType;
4998
5008
  //bind by vao
4999
5009
  //this._indexBuffer?.bind();
5000
- var dc = isNaN(drawCount) ? index.elementCount : drawCount;
5010
+ var dc = isNaN(drawCount) ? index.getElementCount(TYPE_BYTE_MAP[type]) : drawCount;
5001
5011
  if (dc > 0) {
5002
5012
  if (useInstancedDraw) {
5003
5013
  gpu.drawElementsInstanced(gl, this.mode, dc, type, this.drawStart || 0, state.currentMesh.instanceCount);
@@ -5093,7 +5103,6 @@ var MarsGeometry = /** @class */ (function () {
5093
5103
  buffers[name] = {
5094
5104
  data: data,
5095
5105
  usage: usage,
5096
- target: constants.ARRAY_BUFFER,
5097
5106
  name: name,
5098
5107
  };
5099
5108
  var gltype = attributeData2GLType(data);
@@ -5133,6 +5142,9 @@ var MarsGeometry = /** @class */ (function () {
5133
5142
  });
5134
5143
  // 顶点索引
5135
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
+ }
5136
5148
  dirtyFlags['index'] = {
5137
5149
  dirty: true,
5138
5150
  discard: true,
@@ -5247,8 +5259,6 @@ var MarsGeometry = /** @class */ (function () {
5247
5259
  var option = {
5248
5260
  data: data,
5249
5261
  usage: gpuBufferOption.usage,
5250
- target: gpuBufferOption.target,
5251
- elementCount: data.length,
5252
5262
  };
5253
5263
  buffers[gpuBufferName] = option;
5254
5264
  this._dirtyFlags[gpuBufferName].discard = true;
@@ -5348,19 +5358,21 @@ var MarsGeometry = /** @class */ (function () {
5348
5358
  return this._attributesName;
5349
5359
  };
5350
5360
  MarsGeometry.prototype.assignRenderer = function (renderer) {
5351
- var _a;
5352
5361
  if (!this.internal) {
5353
5362
  // 索引缓冲区参数
5354
5363
  var indexBufferOption = undefined;
5355
5364
  if (this._index) {
5356
- var type = INDEX_TYPE_MAP[(_a = this._index) === null || _a === void 0 ? void 0 : _a.BYTES_PER_ELEMENT];
5357
5365
  var data = this._index;
5358
5366
  indexBufferOption = {
5359
- target: constants.ELEMENT_ARRAY_BUFFER,
5360
- type: type,
5361
5367
  data: data,
5362
5368
  usage: constants.STATIC_DRAW,
5363
5369
  };
5370
+ if (data instanceof Uint16Array) {
5371
+ this.indexDataType = constants.SHORT;
5372
+ }
5373
+ else if (data instanceof Uint32Array) {
5374
+ this.indexDataType = constants.INT;
5375
+ }
5364
5376
  }
5365
5377
  // 顶点属性参数
5366
5378
  var options = {
@@ -5371,6 +5383,7 @@ var MarsGeometry = /** @class */ (function () {
5371
5383
  buffers: this._buffers,
5372
5384
  mode: this.mode,
5373
5385
  index: indexBufferOption,
5386
+ indexDataType: this.indexDataType,
5374
5387
  name: this.name,
5375
5388
  };
5376
5389
  //@ts-expect-error safe to set
@@ -5779,7 +5792,8 @@ var MarsSharedGeometry = /** @class */ (function (_super) {
5779
5792
  glgeo.drawStart = this.drawStart;
5780
5793
  glgeo.mode = this.mode;
5781
5794
  if (this._index) {
5782
- glgeo._indexBuffer = glgeo.createIndexBuffer(this._index, renderer.internal);
5795
+ var ret = glgeo.createIndexBuffer(this._index, renderer.internal);
5796
+ glgeo.setIndexBuffer(ret[0], ret[1]);
5783
5797
  }
5784
5798
  //@ts-expect-error safe to assign
5785
5799
  this.internal = glgeo;
@@ -5810,8 +5824,9 @@ var MarsSharedGeometry = /** @class */ (function (_super) {
5810
5824
  return MarsSharedGeometry;
5811
5825
  }(MarsGeometry));
5812
5826
 
5813
- consoleLog('version: ' + "0.1.61-beta.20");
5827
+ consoleLog('version: ' + "0.1.61-beta.22");
5814
5828
 
5829
+ exports.GPUBufferOptionsMemoryShared = GPUBufferOptionsMemoryShared;
5815
5830
  exports.Geometry = MarsGeometry;
5816
5831
  exports.InstancedMesh = MarsInstancedMesh;
5817
5832
  exports.MarsTextureFactory = MarsTextureFactory;