@predy-js/render-interface 0.1.61-beta.1 → 0.1.61-beta.11
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 +136 -59
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +136 -59
- package/dist/index.mjs.map +1 -1
- package/dist/src/render/MarsMaterial.d.ts +2 -3
- package/dist/src/render/MarsMaterialDataBlock.d.ts +12 -3
- package/dist/src/render/MarsRenderer.d.ts +3 -0
- package/dist/src/webgl/GLProgram.d.ts +2 -0
- package/dist/statistic.js +1 -1
- package/dist/types/Material.d.ts +27 -24
- package/dist/types/RenderFrame.d.ts +3 -5
- package/dist/types/RenderPass.d.ts +2 -2
- package/dist/types/Renderer.d.ts +21 -12
- package/dist/types/native/ImageBitmapInternal.d.ts +0 -2
- package/dist/types/native/RenderFrameInternal.d.ts +1 -9
- package/dist/types/native/RendererInternal.d.ts +10 -0
- package/dist/types/native/TextureInternal.d.ts +1 -0
- package/package.json +1 -1
- package/types/Material.ts +37 -31
- package/types/RenderFrame.ts +3 -5
- package/types/RenderPass.ts +2 -2
- package/types/Renderer.ts +24 -13
- package/types/native/ImageBitmapInternal.ts +0 -2
- package/types/native/RenderFrameInternal.ts +1 -9
- package/types/native/RendererInternal.ts +13 -0
- 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.
|
5
|
+
* Version: v0.1.61-beta.11
|
6
6
|
*/
|
7
7
|
|
8
8
|
'use strict';
|
@@ -470,7 +470,7 @@ function renderMeshes(renderer, state) {
|
|
470
470
|
else if (!mesh.hide) {
|
471
471
|
delegate.willRenderMesh && delegate.willRenderMesh(mesh, state);
|
472
472
|
renderMesh(renderer, mesh, state);
|
473
|
-
delegate.
|
473
|
+
delegate.didRenderMesh && delegate.didRenderMesh(mesh, state);
|
474
474
|
}
|
475
475
|
}
|
476
476
|
for (var i = 0; i < sortedMeshes.length; i++) {
|
@@ -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
|
-
|
1813
|
-
|
1814
|
-
|
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
|
-
|
1817
|
-
temArr.add(
|
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
|
1837
|
+
var val;
|
1825
1838
|
for (var i = 0; i < blocks.length; i++) {
|
1826
1839
|
var block = blocks[i];
|
1827
|
-
|
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
|
-
|
1841
|
-
|
1842
|
-
if (
|
1843
|
-
|
1844
|
-
|
1845
|
-
|
1846
|
-
|
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
|
};
|
@@ -4456,24 +4468,29 @@ var GLMaterial = /** @class */ (function () {
|
|
4456
4468
|
}());
|
4457
4469
|
|
4458
4470
|
function isUniformStruct(value) {
|
4459
|
-
return (isObj(value)) && (value.length === undefined)
|
4471
|
+
return (isObj(value)) && (value.length === undefined);
|
4460
4472
|
}
|
4461
4473
|
function isUniformStructArray(value) {
|
4462
4474
|
return (value) && (value.length !== undefined) && isUniformStruct(value[0]);
|
4463
4475
|
}
|
4464
4476
|
var MarsMaterialDataBlock = /** @class */ (function () {
|
4465
4477
|
function MarsMaterialDataBlock(props, renderer) {
|
4478
|
+
var _this = this;
|
4466
4479
|
this._isDestroyed = false;
|
4467
4480
|
this._isDestroyed = false;
|
4468
4481
|
this.name = props.name || 'defDataBlock';
|
4469
4482
|
this._uniformValues = {};
|
4470
4483
|
this._uniformFlags = {};
|
4471
4484
|
this.uboBufferMap = {};
|
4485
|
+
this._uniformTextures = {};
|
4472
4486
|
this._uniformValueRanges = {};
|
4473
4487
|
this._keepUboData = !!props.keepUboData;
|
4488
|
+
this.uniformSemantics = props.uniformSemantics || {};
|
4489
|
+
this._uniformPrivate = {};
|
4474
4490
|
if (props.uniformValues) {
|
4475
4491
|
this.setUniformValues(props.uniformValues);
|
4476
4492
|
}
|
4493
|
+
forEach(props.uniformTextures, function (tex, name) { return _this.setUniformTexture(name, tex); });
|
4477
4494
|
if (renderer) {
|
4478
4495
|
this.assignRenderer(renderer);
|
4479
4496
|
}
|
@@ -4511,6 +4528,20 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4511
4528
|
enumerable: false,
|
4512
4529
|
configurable: true
|
4513
4530
|
});
|
4531
|
+
MarsMaterialDataBlock.prototype.setUniformTexture = function (uniformName, texture) {
|
4532
|
+
if (texture) {
|
4533
|
+
this._uniformTextures[uniformName] = texture;
|
4534
|
+
this._assignUniformValueRenderer(texture, this.renderer);
|
4535
|
+
this._uniformPrivate[uniformName] = true;
|
4536
|
+
}
|
4537
|
+
else {
|
4538
|
+
delete this._uniformTextures[uniformName];
|
4539
|
+
delete this._uniformPrivate[uniformName];
|
4540
|
+
}
|
4541
|
+
};
|
4542
|
+
MarsMaterialDataBlock.prototype.getUniformTexture = function (uniformName) {
|
4543
|
+
return this._uniformTextures[uniformName];
|
4544
|
+
};
|
4514
4545
|
MarsMaterialDataBlock.prototype.assignRenderer = function (renderer) {
|
4515
4546
|
var _this = this;
|
4516
4547
|
if (this.renderer && renderer !== this.renderer) {
|
@@ -4519,7 +4550,7 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4519
4550
|
if (renderer && !this.renderer) {
|
4520
4551
|
// @ts-expect-error safe to assign
|
4521
4552
|
this.renderer = renderer;
|
4522
|
-
forEach(this.
|
4553
|
+
forEach(this._uniformTextures, function (value) {
|
4523
4554
|
_this._assignUniformValueRenderer(value, renderer);
|
4524
4555
|
});
|
4525
4556
|
}
|
@@ -4548,11 +4579,11 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4548
4579
|
this._uniformFlags[name] = true;
|
4549
4580
|
};
|
4550
4581
|
MarsMaterialDataBlock.prototype.hasUniformValue = function (name) {
|
4551
|
-
return
|
4582
|
+
return !!this._uniformPrivate[name];
|
4552
4583
|
};
|
4553
4584
|
MarsMaterialDataBlock.prototype.destroy = function (options) {
|
4554
4585
|
if ((options === null || options === void 0 ? void 0 : options.textures) !== exports.DestroyOptions.keep) {
|
4555
|
-
forEach(this.
|
4586
|
+
forEach(this._uniformTextures, function (uniform) {
|
4556
4587
|
if (uniform instanceof MarsTexture) {
|
4557
4588
|
uniform.destroy();
|
4558
4589
|
}
|
@@ -4565,10 +4596,13 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4565
4596
|
});
|
4566
4597
|
// @ts-expect-error safe to assign
|
4567
4598
|
this.uboBufferMap = {};
|
4599
|
+
this._uniformPrivate = {};
|
4568
4600
|
// @ts-expect-error safe to assign
|
4569
4601
|
this._uniformFlags = {};
|
4570
4602
|
// @ts-expect-error safe to assign
|
4571
4603
|
this._uniformValues = {};
|
4604
|
+
// @ts-expect-error safe to assign
|
4605
|
+
this._uniformTextures = {};
|
4572
4606
|
this.assignRenderer = throwDestroyedError;
|
4573
4607
|
this._isDestroyed = true;
|
4574
4608
|
};
|
@@ -4578,20 +4612,39 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4578
4612
|
MarsMaterialDataBlock.prototype.getUniformValues = function () {
|
4579
4613
|
return this._uniformValues;
|
4580
4614
|
};
|
4581
|
-
MarsMaterialDataBlock.prototype.setUniformValue = function (name, value) {
|
4615
|
+
MarsMaterialDataBlock.prototype.setUniformValue = function (name, value, isSemantic) {
|
4582
4616
|
var _this = this;
|
4583
4617
|
if (value === undefined) {
|
4618
|
+
var originValue = this._uniformValues[name];
|
4619
|
+
if (isUniformStruct(originValue)) {
|
4620
|
+
forEach(originValue, function (data, key) {
|
4621
|
+
var nameInStruct = name + '.' + key;
|
4622
|
+
delete _this._uniformPrivate[nameInStruct];
|
4623
|
+
});
|
4624
|
+
}
|
4625
|
+
else if (isUniformStructArray(originValue)) {
|
4626
|
+
originValue.forEach(function (valueData, i) {
|
4627
|
+
forEach(valueData, function (valueInStruct, key) {
|
4628
|
+
var nameInStruct = name + '[' + i + ']' + '.' + key;
|
4629
|
+
delete _this._uniformPrivate[nameInStruct];
|
4630
|
+
});
|
4631
|
+
});
|
4632
|
+
}
|
4584
4633
|
delete this._uniformValues[name];
|
4585
4634
|
this._uniformFlags[name] = false;
|
4635
|
+
delete this._uniformPrivate[name];
|
4636
|
+
}
|
4637
|
+
else if (value instanceof MarsTexture) {
|
4638
|
+
throw Error('setUniformValue not accept texture:' + name);
|
4586
4639
|
}
|
4587
4640
|
else {
|
4641
|
+
this._uniformPrivate[name] = !isSemantic;
|
4588
4642
|
if (isUniformStruct(value)) {
|
4589
4643
|
forEach(value, function (data, key) {
|
4590
4644
|
var nameInStruct = name + '.' + key;
|
4591
|
-
|
4592
|
-
_this._uniformValues[nameInStruct] = valueInStruct;
|
4645
|
+
_this._uniformValues[nameInStruct] = data;
|
4593
4646
|
_this._uniformFlags[nameInStruct] = true;
|
4594
|
-
_this.
|
4647
|
+
_this._uniformPrivate[nameInStruct] = true;
|
4595
4648
|
});
|
4596
4649
|
// 只是用来保存结构体对象
|
4597
4650
|
this._uniformValues[name] = value;
|
@@ -4603,7 +4656,7 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4603
4656
|
var nameInStruct = name + '[' + i + ']' + '.' + key;
|
4604
4657
|
_this._uniformValues[nameInStruct] = valueInStruct;
|
4605
4658
|
_this._uniformFlags[nameInStruct] = true;
|
4606
|
-
_this.
|
4659
|
+
_this._uniformPrivate[nameInStruct] = true;
|
4607
4660
|
});
|
4608
4661
|
});
|
4609
4662
|
// 只是用来保存结构体对象
|
@@ -4613,7 +4666,6 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4613
4666
|
else {
|
4614
4667
|
this._uniformValues[name] = value;
|
4615
4668
|
this._uniformFlags[name] = true;
|
4616
|
-
this._assignUniformValueRenderer(value, this.renderer);
|
4617
4669
|
}
|
4618
4670
|
}
|
4619
4671
|
return true;
|
@@ -4624,6 +4676,14 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4624
4676
|
_this.setUniformValue(key, val);
|
4625
4677
|
});
|
4626
4678
|
};
|
4679
|
+
MarsMaterialDataBlock.prototype.setUniformSemantic = function (name, semantic) {
|
4680
|
+
if (semantic) {
|
4681
|
+
this.uniformSemantics[name] = semantic;
|
4682
|
+
}
|
4683
|
+
else {
|
4684
|
+
delete this.uniformSemantics[name];
|
4685
|
+
}
|
4686
|
+
};
|
4627
4687
|
MarsMaterialDataBlock.prototype.clone = function (name) {
|
4628
4688
|
return new MarsMaterialDataBlock({
|
4629
4689
|
name: name,
|
@@ -4642,13 +4702,10 @@ var MarsMaterial = /** @class */ (function () {
|
|
4642
4702
|
this.renderType = 0 /* MaterialRenderType.normal */;
|
4643
4703
|
this.states = this.createMaterialStates(options.states);
|
4644
4704
|
this.options = options;
|
4705
|
+
this._dbMap = {};
|
4645
4706
|
if (!this._dataBlocks.length) {
|
4646
|
-
this._dataBlocks[0] = new MarsMaterialDataBlock({ name: '' });
|
4647
|
-
}
|
4648
|
-
if (options.uniformValues) {
|
4649
|
-
this.defaultDataBlock.setUniformValues(options.uniformValues);
|
4707
|
+
this._dataBlocks[0] = new MarsMaterialDataBlock({ name: 'main' });
|
4650
4708
|
}
|
4651
|
-
this.uniformSemantics = Object.assign({}, options.uniformSemantics);
|
4652
4709
|
}
|
4653
4710
|
Object.defineProperty(MarsMaterial.prototype, "isDestroyed", {
|
4654
4711
|
get: function () {
|
@@ -4659,7 +4716,7 @@ var MarsMaterial = /** @class */ (function () {
|
|
4659
4716
|
});
|
4660
4717
|
Object.defineProperty(MarsMaterial.prototype, "dataBlocks", {
|
4661
4718
|
get: function () {
|
4662
|
-
return this._dataBlocks
|
4719
|
+
return this._dataBlocks;
|
4663
4720
|
},
|
4664
4721
|
enumerable: false,
|
4665
4722
|
configurable: true
|
@@ -4731,6 +4788,9 @@ var MarsMaterial = /** @class */ (function () {
|
|
4731
4788
|
return Object.freeze(ret);
|
4732
4789
|
};
|
4733
4790
|
MarsMaterial.prototype.addDataBlock = function (b) {
|
4791
|
+
if (this.getDataBlockByName(b.name)) {
|
4792
|
+
throw Error('dataBlock with same name:' + b.name);
|
4793
|
+
}
|
4734
4794
|
if (arrAdd(this._dataBlocks, b)) {
|
4735
4795
|
b.invalidAllFlags();
|
4736
4796
|
var r = this.renderer;
|
@@ -4739,16 +4799,19 @@ var MarsMaterial = /** @class */ (function () {
|
|
4739
4799
|
}
|
4740
4800
|
}
|
4741
4801
|
};
|
4802
|
+
MarsMaterial.prototype.getDataBlockByName = function (name) {
|
4803
|
+
var cache = this._dbMap[name];
|
4804
|
+
if (!cache) {
|
4805
|
+
var db = this._dataBlocks.find(function (db) { return db.name === name; });
|
4806
|
+
if (db) {
|
4807
|
+
return this._dbMap[name] = db;
|
4808
|
+
}
|
4809
|
+
}
|
4810
|
+
return cache;
|
4811
|
+
};
|
4742
4812
|
MarsMaterial.prototype.removeDataBlock = function (b) {
|
4743
4813
|
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
|
-
}
|
4814
|
+
delete this._dbMap[b.name];
|
4752
4815
|
};
|
4753
4816
|
MarsMaterial.prototype.assignRenderer = function (renderer) {
|
4754
4817
|
if (!this.materialInternal) {
|
@@ -5519,7 +5582,7 @@ var MarsExtWrap = /** @class */ (function () {
|
|
5519
5582
|
fb.viewport[3] = target.height || source.height;
|
5520
5583
|
renderer.internal.resetColorAttachments(fb, [target.internal]);
|
5521
5584
|
var mesh = rp.meshes[0];
|
5522
|
-
mesh.material.defaultDataBlock.
|
5585
|
+
mesh.material.defaultDataBlock.setUniformTexture('uTex', source);
|
5523
5586
|
RenderFrameInternal.renderRenderPass(renderer, rp, { currentFrame: {} });
|
5524
5587
|
}
|
5525
5588
|
}
|
@@ -5664,6 +5727,20 @@ var MarsRenderer = /** @class */ (function () {
|
|
5664
5727
|
}
|
5665
5728
|
}
|
5666
5729
|
};
|
5730
|
+
MarsRenderer.prototype.cancelAnimationFrame = function (id) {
|
5731
|
+
return window.cancelAnimationFrame(id);
|
5732
|
+
};
|
5733
|
+
MarsRenderer.prototype.getErrors = function () {
|
5734
|
+
var gl = this.internal.gl;
|
5735
|
+
var err = gl.getError();
|
5736
|
+
if (err) {
|
5737
|
+
return ['webgl error:' + err];
|
5738
|
+
}
|
5739
|
+
return [];
|
5740
|
+
};
|
5741
|
+
MarsRenderer.prototype.requestAnimationFrame = function (cb) {
|
5742
|
+
return window.requestAnimationFrame(cb);
|
5743
|
+
};
|
5667
5744
|
return MarsRenderer;
|
5668
5745
|
}());
|
5669
5746
|
|
@@ -5730,7 +5807,7 @@ var MarsSharedGeometry = /** @class */ (function (_super) {
|
|
5730
5807
|
return MarsSharedGeometry;
|
5731
5808
|
}(MarsGeometry));
|
5732
5809
|
|
5733
|
-
consoleLog('version: ' + "0.1.61-beta.
|
5810
|
+
consoleLog('version: ' + "0.1.61-beta.11");
|
5734
5811
|
|
5735
5812
|
exports.Geometry = MarsGeometry;
|
5736
5813
|
exports.InstancedMesh = MarsInstancedMesh;
|