@predy-js/render-interface 0.1.61-beta.2 → 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.
Files changed (42) hide show
  1. package/dist/index.js +231 -136
  2. package/dist/index.js.map +1 -1
  3. package/dist/index.mjs +231 -137
  4. package/dist/index.mjs.map +1 -1
  5. package/dist/src/render/MarsGeometry.d.ts +4 -3
  6. package/dist/src/render/MarsMaterial.d.ts +2 -3
  7. package/dist/src/render/MarsMaterialDataBlock.d.ts +12 -3
  8. package/dist/src/render/MarsRenderer.d.ts +3 -0
  9. package/dist/src/webgl/GLGPUBuffer.d.ts +2 -4
  10. package/dist/src/webgl/GLGPURenderer.d.ts +2 -0
  11. package/dist/src/webgl/GLGeometry.d.ts +6 -2
  12. package/dist/src/webgl/GLProgram.d.ts +2 -0
  13. package/dist/statistic.js +1 -1
  14. package/dist/types/GPUBuffer.d.ts +14 -14
  15. package/dist/types/Geometry.d.ts +9 -4
  16. package/dist/types/Material.d.ts +27 -24
  17. package/dist/types/RenderFrame.d.ts +3 -5
  18. package/dist/types/RenderPass.d.ts +2 -2
  19. package/dist/types/Renderer.d.ts +21 -12
  20. package/dist/types/ShaderLibrary.d.ts +4 -4
  21. package/dist/types/native/DataBlockInternal.d.ts +3 -0
  22. package/dist/types/native/GPUBufferInternal.d.ts +1 -1
  23. package/dist/types/native/ImageBitmapInternal.d.ts +0 -2
  24. package/dist/types/native/MaterialInternal.d.ts +0 -9
  25. package/dist/types/native/RenderFrameInternal.d.ts +3 -7
  26. package/dist/types/native/RendererInternal.d.ts +10 -0
  27. package/dist/types/native/TextureInternal.d.ts +1 -0
  28. package/package.json +1 -1
  29. package/types/GPUBuffer.ts +16 -19
  30. package/types/Geometry.ts +11 -4
  31. package/types/Material.ts +37 -31
  32. package/types/RenderFrame.ts +3 -5
  33. package/types/RenderPass.ts +2 -2
  34. package/types/Renderer.ts +24 -13
  35. package/types/ShaderLibrary.ts +4 -4
  36. package/types/native/DataBlockInternal.ts +5 -0
  37. package/types/native/GPUBufferInternal.ts +1 -2
  38. package/types/native/ImageBitmapInternal.ts +0 -2
  39. package/types/native/MaterialInternal.ts +0 -11
  40. package/types/native/RenderFrameInternal.ts +3 -7
  41. package/types/native/RendererInternal.ts +13 -0
  42. package/types/native/TextureInternal.ts +1 -0
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.2
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
  }
@@ -470,7 +472,7 @@ function renderMeshes(renderer, state) {
470
472
  else if (!mesh.hide) {
471
473
  delegate.willRenderMesh && delegate.willRenderMesh(mesh, state);
472
474
  renderMesh(renderer, mesh, state);
473
- delegate.didiRenderMesh && delegate.didiRenderMesh(mesh, state);
475
+ delegate.didRenderMesh && delegate.didRenderMesh(mesh, state);
474
476
  }
475
477
  }
476
478
  for (var i = 0; i < sortedMeshes.length; i++) {
@@ -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;
@@ -1794,65 +1794,77 @@ var GLProgram = /** @class */ (function () {
1794
1794
  renderer.state.useProgram(this.glHandle);
1795
1795
  }
1796
1796
  };
1797
+ GLProgram.prototype.getSemanticValue = function (state, semanticName) {
1798
+ var renderPassSemantics = state.currentPass.semantics;
1799
+ var renderFrameSemantics = state.currentFrame.semantics;
1800
+ if (renderPassSemantics.hasSemanticValue(semanticName)) {
1801
+ return renderPassSemantics.getSemanticValue(semanticName, state);
1802
+ }
1803
+ else if (renderFrameSemantics.hasSemanticValue(semanticName)) {
1804
+ return renderFrameSemantics.getSemanticValue(semanticName, state);
1805
+ }
1806
+ };
1797
1807
  GLProgram.prototype.setupUniforms = function (state) {
1798
1808
  var _this = this;
1799
1809
  this.bind();
1800
- var frame = state.currentFrame;
1801
1810
  var material = state.currentMesh.material;
1802
1811
  var gl = this.renderer.gl;
1803
1812
  var blocks = material._dataBlocks;
1804
1813
  var shared = this.shared;
1805
- var uniformSemantics = material.uniformSemantics;
1806
- var renderPassSemantics = state.currentPass.semantics;
1807
- var renderFrameSemantics = frame.semantics;
1808
- // semantic {uModel:'MODEL'}
1809
1814
  temArr.clear();
1810
1815
  forEach(this.uniformBlockMap, function (uboInfo, name) {
1811
1816
  if (uboInfo) {
1812
- for (var i = 0; i < blocks.length; i++) {
1813
- var block = blocks[i];
1814
- var uboBuffer = block.createUboBuffer(uboInfo);
1817
+ var block_1 = material.getDataBlockByName(uboInfo.name);
1818
+ if (block_1) {
1819
+ forEach(block_1.uniformSemantics, function (semanticName, uniformName) {
1820
+ if (uniformName in uboInfo.uniforms && !block_1.hasUniformValue(uniformName)) {
1821
+ var val = _this.getSemanticValue(state, semanticName);
1822
+ if (val || val === 0) {
1823
+ block_1.setUniformValue(uniformName, val, true);
1824
+ }
1825
+ }
1826
+ });
1827
+ var uboBuffer = block_1.createUboBuffer(uboInfo);
1815
1828
  if (uboBuffer) {
1816
- block.setUboBuffer(uboBuffer);
1817
- temArr.add(block);
1829
+ block_1.setUboBuffer(uboBuffer);
1830
+ temArr.add(block_1);
1818
1831
  return uboBuffer.bind(gl, _this.glHandle, uboInfo.index);
1819
1832
  }
1820
1833
  }
1821
1834
  }
1822
1835
  });
1823
1836
  forEach(this.uniformInfoMap, function (info, name) {
1824
- var val, hasUniformValue;
1837
+ var val;
1825
1838
  for (var i = 0; i < blocks.length; i++) {
1826
1839
  var block = blocks[i];
1827
- if (temArr.has(block)) {
1840
+ var semanticName = block.uniformSemantics[name];
1841
+ if (info.isTexture) {
1842
+ if (block.hasUniformValue(name)) {
1843
+ val = block.getUniformTexture(name);
1844
+ }
1845
+ else if (semanticName) {
1846
+ val = _this.getSemanticValue(state, semanticName);
1847
+ }
1848
+ }
1849
+ else if (temArr.has(block)) {
1828
1850
  continue;
1829
1851
  }
1830
- if (block.hasUniformValue(name)) {
1852
+ else if (block.hasUniformValue(name)) {
1831
1853
  if (!shared && !block._uniformFlags[name] && info.textureIndex === -1) {
1832
1854
  //not dirty, don't assign
1833
1855
  return;
1834
1856
  }
1835
1857
  val = block.getUniformValue(name);
1836
- hasUniformValue = true;
1837
- break;
1838
1858
  }
1839
- }
1840
- if (!hasUniformValue) {
1841
- var semanticName = uniformSemantics[name];
1842
- if (semanticName) {
1843
- if (renderPassSemantics.hasSemanticValue(semanticName)) {
1844
- val = renderPassSemantics.getSemanticValue(semanticName, state);
1845
- }
1846
- else if (renderFrameSemantics.hasSemanticValue(semanticName)) {
1847
- val = renderFrameSemantics.getSemanticValue(semanticName, state);
1848
- }
1859
+ else if (semanticName) {
1860
+ val = _this.getSemanticValue(state, semanticName);
1861
+ }
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"));
1849
1867
  }
1850
- }
1851
- if (val !== undefined && val !== null) {
1852
- _this.setGLUniformValue(name, val, info, gl);
1853
- }
1854
- else if (!info.isTexture) {
1855
- consoleWarn("mesh ".concat(state.currentMesh.name, " uniform ").concat(name, " value unset"));
1856
1868
  }
1857
1869
  });
1858
1870
  };
@@ -2422,7 +2434,7 @@ function registerCompressedTexture(gl) {
2422
2434
  return 0;
2423
2435
  }
2424
2436
 
2425
- var _a$2, _b;
2437
+ var _a$2, _b$1;
2426
2438
  var flipCanvas;
2427
2439
  var imageBitMapAvailable$1 = typeof ImageBitmap === 'function' && typeof createImageBitmap == 'function';
2428
2440
  var GLTexture = /** @class */ (function () {
@@ -2753,14 +2765,14 @@ var FORMAT_HALF_FLOAT = (_a$2 = {},
2753
2765
  _a$2[constants.LUMINANCE_ALPHA] = 33327,
2754
2766
  _a$2[constants.LUMINANCE] = 33325,
2755
2767
  _a$2);
2756
- var FORMAT_FLOAT = (_b = {},
2757
- _b[constants.RGBA] = 34836,
2758
- _b[constants.RGB] = 34837,
2759
- _b[constants.ALPHA] = 33326,
2760
- _b[constants.RED] = 33326,
2761
- _b[constants.LUMINANCE_ALPHA] = 33328,
2762
- _b[constants.LUMINANCE] = 33326,
2763
- _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);
2764
2776
 
2765
2777
  var GL_LOST_EVENT = 'webglcontextlost';
2766
2778
  var GLGPURenderer = /** @class */ (function () {
@@ -2806,6 +2818,12 @@ var GLGPURenderer = /** @class */ (function () {
2806
2818
  gl.canvas.addEventListener(GL_LOST_EVENT, this.onContextLose);
2807
2819
  }
2808
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
+ };
2809
2827
  Object.defineProperty(GLGPURenderer.prototype, "isDestroyed", {
2810
2828
  get: function () {
2811
2829
  return this._isDestroyed;
@@ -4456,24 +4474,29 @@ var GLMaterial = /** @class */ (function () {
4456
4474
  }());
4457
4475
 
4458
4476
  function isUniformStruct(value) {
4459
- return (isObj(value)) && (value.length === undefined) && value.assignRenderer === undefined;
4477
+ return (isObj(value)) && (value.length === undefined);
4460
4478
  }
4461
4479
  function isUniformStructArray(value) {
4462
4480
  return (value) && (value.length !== undefined) && isUniformStruct(value[0]);
4463
4481
  }
4464
4482
  var MarsMaterialDataBlock = /** @class */ (function () {
4465
4483
  function MarsMaterialDataBlock(props, renderer) {
4484
+ var _this = this;
4466
4485
  this._isDestroyed = false;
4467
4486
  this._isDestroyed = false;
4468
4487
  this.name = props.name || 'defDataBlock';
4469
4488
  this._uniformValues = {};
4470
4489
  this._uniformFlags = {};
4471
4490
  this.uboBufferMap = {};
4491
+ this._uniformTextures = {};
4472
4492
  this._uniformValueRanges = {};
4473
4493
  this._keepUboData = !!props.keepUboData;
4494
+ this.uniformSemantics = props.uniformSemantics || {};
4495
+ this._uniformPrivate = {};
4474
4496
  if (props.uniformValues) {
4475
4497
  this.setUniformValues(props.uniformValues);
4476
4498
  }
4499
+ forEach(props.uniformTextures, function (tex, name) { return _this.setUniformTexture(name, tex); });
4477
4500
  if (renderer) {
4478
4501
  this.assignRenderer(renderer);
4479
4502
  }
@@ -4511,6 +4534,20 @@ var MarsMaterialDataBlock = /** @class */ (function () {
4511
4534
  enumerable: false,
4512
4535
  configurable: true
4513
4536
  });
4537
+ MarsMaterialDataBlock.prototype.setUniformTexture = function (uniformName, texture) {
4538
+ if (texture) {
4539
+ this._uniformTextures[uniformName] = texture;
4540
+ this._assignUniformValueRenderer(texture, this.renderer);
4541
+ this._uniformPrivate[uniformName] = true;
4542
+ }
4543
+ else {
4544
+ delete this._uniformTextures[uniformName];
4545
+ delete this._uniformPrivate[uniformName];
4546
+ }
4547
+ };
4548
+ MarsMaterialDataBlock.prototype.getUniformTexture = function (uniformName) {
4549
+ return this._uniformTextures[uniformName];
4550
+ };
4514
4551
  MarsMaterialDataBlock.prototype.assignRenderer = function (renderer) {
4515
4552
  var _this = this;
4516
4553
  if (this.renderer && renderer !== this.renderer) {
@@ -4519,7 +4556,7 @@ var MarsMaterialDataBlock = /** @class */ (function () {
4519
4556
  if (renderer && !this.renderer) {
4520
4557
  // @ts-expect-error safe to assign
4521
4558
  this.renderer = renderer;
4522
- forEach(this._uniformValues, function (value) {
4559
+ forEach(this._uniformTextures, function (value) {
4523
4560
  _this._assignUniformValueRenderer(value, renderer);
4524
4561
  });
4525
4562
  }
@@ -4548,11 +4585,11 @@ var MarsMaterialDataBlock = /** @class */ (function () {
4548
4585
  this._uniformFlags[name] = true;
4549
4586
  };
4550
4587
  MarsMaterialDataBlock.prototype.hasUniformValue = function (name) {
4551
- return name in this._uniformValues;
4588
+ return !!this._uniformPrivate[name];
4552
4589
  };
4553
4590
  MarsMaterialDataBlock.prototype.destroy = function (options) {
4554
4591
  if ((options === null || options === void 0 ? void 0 : options.textures) !== exports.DestroyOptions.keep) {
4555
- forEach(this._uniformValues, function (uniform) {
4592
+ forEach(this._uniformTextures, function (uniform) {
4556
4593
  if (uniform instanceof MarsTexture) {
4557
4594
  uniform.destroy();
4558
4595
  }
@@ -4565,10 +4602,13 @@ var MarsMaterialDataBlock = /** @class */ (function () {
4565
4602
  });
4566
4603
  // @ts-expect-error safe to assign
4567
4604
  this.uboBufferMap = {};
4605
+ this._uniformPrivate = {};
4568
4606
  // @ts-expect-error safe to assign
4569
4607
  this._uniformFlags = {};
4570
4608
  // @ts-expect-error safe to assign
4571
4609
  this._uniformValues = {};
4610
+ // @ts-expect-error safe to assign
4611
+ this._uniformTextures = {};
4572
4612
  this.assignRenderer = throwDestroyedError;
4573
4613
  this._isDestroyed = true;
4574
4614
  };
@@ -4578,20 +4618,39 @@ var MarsMaterialDataBlock = /** @class */ (function () {
4578
4618
  MarsMaterialDataBlock.prototype.getUniformValues = function () {
4579
4619
  return this._uniformValues;
4580
4620
  };
4581
- MarsMaterialDataBlock.prototype.setUniformValue = function (name, value) {
4621
+ MarsMaterialDataBlock.prototype.setUniformValue = function (name, value, isSemantic) {
4582
4622
  var _this = this;
4583
4623
  if (value === undefined) {
4624
+ var originValue = this._uniformValues[name];
4625
+ if (isUniformStruct(originValue)) {
4626
+ forEach(originValue, function (data, key) {
4627
+ var nameInStruct = name + '.' + key;
4628
+ delete _this._uniformPrivate[nameInStruct];
4629
+ });
4630
+ }
4631
+ else if (isUniformStructArray(originValue)) {
4632
+ originValue.forEach(function (valueData, i) {
4633
+ forEach(valueData, function (valueInStruct, key) {
4634
+ var nameInStruct = name + '[' + i + ']' + '.' + key;
4635
+ delete _this._uniformPrivate[nameInStruct];
4636
+ });
4637
+ });
4638
+ }
4584
4639
  delete this._uniformValues[name];
4585
4640
  this._uniformFlags[name] = false;
4641
+ delete this._uniformPrivate[name];
4642
+ }
4643
+ else if (value instanceof MarsTexture) {
4644
+ throw Error('setUniformValue not accept texture:' + name);
4586
4645
  }
4587
4646
  else {
4647
+ this._uniformPrivate[name] = !isSemantic;
4588
4648
  if (isUniformStruct(value)) {
4589
4649
  forEach(value, function (data, key) {
4590
4650
  var nameInStruct = name + '.' + key;
4591
- var valueInStruct = data;
4592
- _this._uniformValues[nameInStruct] = valueInStruct;
4651
+ _this._uniformValues[nameInStruct] = data;
4593
4652
  _this._uniformFlags[nameInStruct] = true;
4594
- _this._assignUniformValueRenderer(valueInStruct, _this.renderer);
4653
+ _this._uniformPrivate[nameInStruct] = true;
4595
4654
  });
4596
4655
  // 只是用来保存结构体对象
4597
4656
  this._uniformValues[name] = value;
@@ -4603,7 +4662,7 @@ var MarsMaterialDataBlock = /** @class */ (function () {
4603
4662
  var nameInStruct = name + '[' + i + ']' + '.' + key;
4604
4663
  _this._uniformValues[nameInStruct] = valueInStruct;
4605
4664
  _this._uniformFlags[nameInStruct] = true;
4606
- _this._assignUniformValueRenderer(valueInStruct, _this.renderer);
4665
+ _this._uniformPrivate[nameInStruct] = true;
4607
4666
  });
4608
4667
  });
4609
4668
  // 只是用来保存结构体对象
@@ -4613,7 +4672,6 @@ var MarsMaterialDataBlock = /** @class */ (function () {
4613
4672
  else {
4614
4673
  this._uniformValues[name] = value;
4615
4674
  this._uniformFlags[name] = true;
4616
- this._assignUniformValueRenderer(value, this.renderer);
4617
4675
  }
4618
4676
  }
4619
4677
  return true;
@@ -4624,10 +4682,21 @@ var MarsMaterialDataBlock = /** @class */ (function () {
4624
4682
  _this.setUniformValue(key, val);
4625
4683
  });
4626
4684
  };
4685
+ MarsMaterialDataBlock.prototype.setUniformSemantic = function (name, semantic) {
4686
+ if (semantic) {
4687
+ this.uniformSemantics[name] = semantic;
4688
+ }
4689
+ else {
4690
+ delete this.uniformSemantics[name];
4691
+ }
4692
+ };
4627
4693
  MarsMaterialDataBlock.prototype.clone = function (name) {
4628
4694
  return new MarsMaterialDataBlock({
4629
4695
  name: name,
4630
4696
  uniformValues: this._uniformValues,
4697
+ uniformTextures: this._uniformTextures,
4698
+ uniformSemantics: this.uniformSemantics,
4699
+ keepUboData: this._keepUboData,
4631
4700
  }, this.renderer);
4632
4701
  };
4633
4702
  return MarsMaterialDataBlock;
@@ -4642,13 +4711,10 @@ var MarsMaterial = /** @class */ (function () {
4642
4711
  this.renderType = 0 /* MaterialRenderType.normal */;
4643
4712
  this.states = this.createMaterialStates(options.states);
4644
4713
  this.options = options;
4714
+ this._dbMap = {};
4645
4715
  if (!this._dataBlocks.length) {
4646
- this._dataBlocks[0] = new MarsMaterialDataBlock({ name: '' });
4647
- }
4648
- if (options.uniformValues) {
4649
- this.defaultDataBlock.setUniformValues(options.uniformValues);
4716
+ this._dataBlocks[0] = new MarsMaterialDataBlock({ name: 'main' });
4650
4717
  }
4651
- this.uniformSemantics = Object.assign({}, options.uniformSemantics);
4652
4718
  }
4653
4719
  Object.defineProperty(MarsMaterial.prototype, "isDestroyed", {
4654
4720
  get: function () {
@@ -4659,7 +4725,7 @@ var MarsMaterial = /** @class */ (function () {
4659
4725
  });
4660
4726
  Object.defineProperty(MarsMaterial.prototype, "dataBlocks", {
4661
4727
  get: function () {
4662
- return this._dataBlocks.slice();
4728
+ return this._dataBlocks;
4663
4729
  },
4664
4730
  enumerable: false,
4665
4731
  configurable: true
@@ -4731,6 +4797,9 @@ var MarsMaterial = /** @class */ (function () {
4731
4797
  return Object.freeze(ret);
4732
4798
  };
4733
4799
  MarsMaterial.prototype.addDataBlock = function (b) {
4800
+ if (this.getDataBlockByName(b.name)) {
4801
+ throw Error('dataBlock with same name:' + b.name);
4802
+ }
4734
4803
  if (arrAdd(this._dataBlocks, b)) {
4735
4804
  b.invalidAllFlags();
4736
4805
  var r = this.renderer;
@@ -4739,16 +4808,19 @@ var MarsMaterial = /** @class */ (function () {
4739
4808
  }
4740
4809
  }
4741
4810
  };
4811
+ MarsMaterial.prototype.getDataBlockByName = function (name) {
4812
+ var cache = this._dbMap[name];
4813
+ if (!cache) {
4814
+ var db = this._dataBlocks.find(function (db) { return db.name === name; });
4815
+ if (db) {
4816
+ return this._dbMap[name] = db;
4817
+ }
4818
+ }
4819
+ return cache;
4820
+ };
4742
4821
  MarsMaterial.prototype.removeDataBlock = function (b) {
4743
4822
  arrRemove(this._dataBlocks, b);
4744
- };
4745
- MarsMaterial.prototype.setUniformSemantic = function (uniformName, semantic) {
4746
- if (semantic === undefined) {
4747
- delete this.uniformSemantics[uniformName];
4748
- }
4749
- else {
4750
- this.uniformSemantics[uniformName] = semantic;
4751
- }
4823
+ delete this._dbMap[b.name];
4752
4824
  };
4753
4825
  MarsMaterial.prototype.assignRenderer = function (renderer) {
4754
4826
  if (!this.materialInternal) {
@@ -4822,12 +4894,15 @@ var GLVertexArrayObject = /** @class */ (function () {
4822
4894
  return GLVertexArrayObject;
4823
4895
  }());
4824
4896
 
4825
- var _a$1;
4897
+ var _a$1, _b;
4826
4898
  var INDEX_TYPE_MAP = (_a$1 = {},
4827
- _a$1[Uint8Array.BYTES_PER_ELEMENT] = constants.UNSIGNED_BYTE,
4828
4899
  _a$1[Uint16Array.BYTES_PER_ELEMENT] = constants.UNSIGNED_SHORT,
4829
4900
  _a$1[Uint32Array.BYTES_PER_ELEMENT] = constants.UNSIGNED_INT,
4830
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);
4831
4906
  /**
4832
4907
  * GLGeometry对象,保存GLGPUBuffer对象。
4833
4908
  *
@@ -4853,7 +4928,8 @@ var GLGeometry = /** @class */ (function () {
4853
4928
  buffers[name] = new GLGPUBuffer(opt, renderer);
4854
4929
  });
4855
4930
  if (option.index && option.index.data) {
4856
- this._indexBuffer = this.createIndexBuffer(option.index.data, renderer);
4931
+ var ret = this.createIndexBuffer(option.index.data, renderer);
4932
+ this.setIndexBuffer(ret[0], ret[1]);
4857
4933
  }
4858
4934
  }
4859
4935
  this._buffersMap = buffers;
@@ -4875,18 +4951,18 @@ var GLGeometry = /** @class */ (function () {
4875
4951
  (_a = this.vaoMap[name]) === null || _a === void 0 ? void 0 : _a.destroy();
4876
4952
  this.vaoMap[name] = undefined;
4877
4953
  };
4878
- GLGeometry.prototype.setIndexBuffer = function (buffer) {
4954
+ GLGeometry.prototype.setIndexBuffer = function (buffer, indexBufferType) {
4879
4955
  this._indexBuffer = buffer;
4956
+ this.indexBufferType = indexBufferType;
4880
4957
  };
4881
4958
  GLGeometry.prototype.createIndexBuffer = function (data, renderer) {
4882
4959
  var type = INDEX_TYPE_MAP[data.BYTES_PER_ELEMENT];
4883
4960
  var indexOption = {
4884
4961
  data: data,
4885
4962
  target: constants.ELEMENT_ARRAY_BUFFER,
4886
- type: type,
4887
4963
  name: "".concat(this.name, "##index"),
4888
4964
  };
4889
- return new GLGPUBuffer(indexOption, renderer);
4965
+ return [new GLGPUBuffer(indexOption, renderer), type];
4890
4966
  };
4891
4967
  GLGeometry.prototype.getGPUBuffer = function (name) {
4892
4968
  return this._buffersMap[name];
@@ -4928,10 +5004,10 @@ var GLGeometry = /** @class */ (function () {
4928
5004
  if (gl && gpu) {
4929
5005
  var drawCount = this.drawCount;
4930
5006
  if (index) {
4931
- var type = index.type;
5007
+ var type = this.indexBufferType;
4932
5008
  //bind by vao
4933
5009
  //this._indexBuffer?.bind();
4934
- var dc = isNaN(drawCount) ? index.elementCount : drawCount;
5010
+ var dc = isNaN(drawCount) ? index.getElementCount(TYPE_BYTE_MAP[type]) : drawCount;
4935
5011
  if (dc > 0) {
4936
5012
  if (useInstancedDraw) {
4937
5013
  gpu.drawElementsInstanced(gl, this.mode, dc, type, this.drawStart || 0, state.currentMesh.instanceCount);
@@ -5027,7 +5103,6 @@ var MarsGeometry = /** @class */ (function () {
5027
5103
  buffers[name] = {
5028
5104
  data: data,
5029
5105
  usage: usage,
5030
- target: constants.ARRAY_BUFFER,
5031
5106
  name: name,
5032
5107
  };
5033
5108
  var gltype = attributeData2GLType(data);
@@ -5067,6 +5142,9 @@ var MarsGeometry = /** @class */ (function () {
5067
5142
  });
5068
5143
  // 顶点索引
5069
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
+ }
5070
5148
  dirtyFlags['index'] = {
5071
5149
  dirty: true,
5072
5150
  discard: true,
@@ -5181,8 +5259,6 @@ var MarsGeometry = /** @class */ (function () {
5181
5259
  var option = {
5182
5260
  data: data,
5183
5261
  usage: gpuBufferOption.usage,
5184
- target: gpuBufferOption.target,
5185
- elementCount: data.length,
5186
5262
  };
5187
5263
  buffers[gpuBufferName] = option;
5188
5264
  this._dirtyFlags[gpuBufferName].discard = true;
@@ -5282,19 +5358,21 @@ var MarsGeometry = /** @class */ (function () {
5282
5358
  return this._attributesName;
5283
5359
  };
5284
5360
  MarsGeometry.prototype.assignRenderer = function (renderer) {
5285
- var _a;
5286
5361
  if (!this.internal) {
5287
5362
  // 索引缓冲区参数
5288
5363
  var indexBufferOption = undefined;
5289
5364
  if (this._index) {
5290
- var type = INDEX_TYPE_MAP[(_a = this._index) === null || _a === void 0 ? void 0 : _a.BYTES_PER_ELEMENT];
5291
5365
  var data = this._index;
5292
5366
  indexBufferOption = {
5293
- target: constants.ELEMENT_ARRAY_BUFFER,
5294
- type: type,
5295
5367
  data: data,
5296
5368
  usage: constants.STATIC_DRAW,
5297
5369
  };
5370
+ if (data instanceof Uint16Array) {
5371
+ this.indexDataType = constants.SHORT;
5372
+ }
5373
+ else if (data instanceof Uint32Array) {
5374
+ this.indexDataType = constants.INT;
5375
+ }
5298
5376
  }
5299
5377
  // 顶点属性参数
5300
5378
  var options = {
@@ -5305,6 +5383,7 @@ var MarsGeometry = /** @class */ (function () {
5305
5383
  buffers: this._buffers,
5306
5384
  mode: this.mode,
5307
5385
  index: indexBufferOption,
5386
+ indexDataType: this.indexDataType,
5308
5387
  name: this.name,
5309
5388
  };
5310
5389
  //@ts-expect-error safe to set
@@ -5519,7 +5598,7 @@ var MarsExtWrap = /** @class */ (function () {
5519
5598
  fb.viewport[3] = target.height || source.height;
5520
5599
  renderer.internal.resetColorAttachments(fb, [target.internal]);
5521
5600
  var mesh = rp.meshes[0];
5522
- mesh.material.defaultDataBlock.setUniformValue('uTex', source);
5601
+ mesh.material.defaultDataBlock.setUniformTexture('uTex', source);
5523
5602
  RenderFrameInternal.renderRenderPass(renderer, rp, { currentFrame: {} });
5524
5603
  }
5525
5604
  }
@@ -5664,6 +5743,20 @@ var MarsRenderer = /** @class */ (function () {
5664
5743
  }
5665
5744
  }
5666
5745
  };
5746
+ MarsRenderer.prototype.cancelAnimationFrame = function (id) {
5747
+ return window.cancelAnimationFrame(id);
5748
+ };
5749
+ MarsRenderer.prototype.getErrors = function () {
5750
+ var gl = this.internal.gl;
5751
+ var err = gl.getError();
5752
+ if (err) {
5753
+ return ['webgl error:' + err];
5754
+ }
5755
+ return [];
5756
+ };
5757
+ MarsRenderer.prototype.requestAnimationFrame = function (cb) {
5758
+ return window.requestAnimationFrame(cb);
5759
+ };
5667
5760
  return MarsRenderer;
5668
5761
  }());
5669
5762
 
@@ -5699,7 +5792,8 @@ var MarsSharedGeometry = /** @class */ (function (_super) {
5699
5792
  glgeo.drawStart = this.drawStart;
5700
5793
  glgeo.mode = this.mode;
5701
5794
  if (this._index) {
5702
- glgeo._indexBuffer = glgeo.createIndexBuffer(this._index, renderer.internal);
5795
+ var ret = glgeo.createIndexBuffer(this._index, renderer.internal);
5796
+ glgeo.setIndexBuffer(ret[0], ret[1]);
5703
5797
  }
5704
5798
  //@ts-expect-error safe to assign
5705
5799
  this.internal = glgeo;
@@ -5730,8 +5824,9 @@ var MarsSharedGeometry = /** @class */ (function (_super) {
5730
5824
  return MarsSharedGeometry;
5731
5825
  }(MarsGeometry));
5732
5826
 
5733
- consoleLog('version: ' + "0.1.61-beta.2");
5827
+ consoleLog('version: ' + "0.1.61-beta.22");
5734
5828
 
5829
+ exports.GPUBufferOptionsMemoryShared = GPUBufferOptionsMemoryShared;
5735
5830
  exports.Geometry = MarsGeometry;
5736
5831
  exports.InstancedMesh = MarsInstancedMesh;
5737
5832
  exports.MarsTextureFactory = MarsTextureFactory;