@predy-js/render-interface 0.1.61-beta.10 → 0.1.61-beta.12
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 +138 -60
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +136 -60
- package/dist/index.mjs.map +1 -1
- package/dist/src/render/MarsMaterial.d.ts +2 -3
- package/dist/src/render/MarsMaterialDataBlock.d.ts +10 -4
- 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 +21 -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/ShaderLibrary.d.ts +4 -4
- 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/package.json +1 -1
- package/types/Material.ts +34 -31
- package/types/RenderFrame.ts +3 -5
- package/types/RenderPass.ts +2 -2
- package/types/Renderer.ts +24 -13
- package/types/ShaderLibrary.ts +4 -4
- package/types/native/ImageBitmapInternal.ts +0 -2
- package/types/native/RenderFrameInternal.ts +1 -9
- package/types/native/RendererInternal.ts +13 -0
package/dist/index.mjs
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.12
|
6
6
|
*/
|
7
7
|
|
8
8
|
/******************************************************************************
|
@@ -466,7 +466,7 @@ function renderMeshes(renderer, state) {
|
|
466
466
|
else if (!mesh.hide) {
|
467
467
|
delegate.willRenderMesh && delegate.willRenderMesh(mesh, state);
|
468
468
|
renderMesh(renderer, mesh, state);
|
469
|
-
delegate.
|
469
|
+
delegate.didRenderMesh && delegate.didRenderMesh(mesh, state);
|
470
470
|
}
|
471
471
|
}
|
472
472
|
for (var i = 0; i < sortedMeshes.length; i++) {
|
@@ -1790,65 +1790,77 @@ var GLProgram = /** @class */ (function () {
|
|
1790
1790
|
renderer.state.useProgram(this.glHandle);
|
1791
1791
|
}
|
1792
1792
|
};
|
1793
|
+
GLProgram.prototype.getSemanticValue = function (state, semanticName) {
|
1794
|
+
var renderPassSemantics = state.currentPass.semantics;
|
1795
|
+
var renderFrameSemantics = state.currentFrame.semantics;
|
1796
|
+
if (renderPassSemantics.hasSemanticValue(semanticName)) {
|
1797
|
+
return renderPassSemantics.getSemanticValue(semanticName, state);
|
1798
|
+
}
|
1799
|
+
else if (renderFrameSemantics.hasSemanticValue(semanticName)) {
|
1800
|
+
return renderFrameSemantics.getSemanticValue(semanticName, state);
|
1801
|
+
}
|
1802
|
+
};
|
1793
1803
|
GLProgram.prototype.setupUniforms = function (state) {
|
1794
1804
|
var _this = this;
|
1795
1805
|
this.bind();
|
1796
|
-
var frame = state.currentFrame;
|
1797
1806
|
var material = state.currentMesh.material;
|
1798
1807
|
var gl = this.renderer.gl;
|
1799
1808
|
var blocks = material._dataBlocks;
|
1800
1809
|
var shared = this.shared;
|
1801
|
-
var uniformSemantics = material.uniformSemantics;
|
1802
|
-
var renderPassSemantics = state.currentPass.semantics;
|
1803
|
-
var renderFrameSemantics = frame.semantics;
|
1804
|
-
// semantic {uModel:'MODEL'}
|
1805
1810
|
temArr.clear();
|
1806
1811
|
forEach(this.uniformBlockMap, function (uboInfo, name) {
|
1807
1812
|
if (uboInfo) {
|
1808
|
-
|
1809
|
-
|
1810
|
-
|
1813
|
+
var block_1 = material.getDataBlockByName(uboInfo.name);
|
1814
|
+
if (block_1) {
|
1815
|
+
forEach(block_1.uniformSemantics, function (semanticName, uniformName) {
|
1816
|
+
if (uniformName in uboInfo.uniforms && !block_1.hasUniformValue(uniformName)) {
|
1817
|
+
var val = _this.getSemanticValue(state, semanticName);
|
1818
|
+
if (val || val === 0) {
|
1819
|
+
block_1.setUniformValue(uniformName, val, true);
|
1820
|
+
}
|
1821
|
+
}
|
1822
|
+
});
|
1823
|
+
var uboBuffer = block_1.createUboBuffer(uboInfo);
|
1811
1824
|
if (uboBuffer) {
|
1812
|
-
|
1813
|
-
temArr.add(
|
1825
|
+
block_1.setUboBuffer(uboBuffer);
|
1826
|
+
temArr.add(block_1);
|
1814
1827
|
return uboBuffer.bind(gl, _this.glHandle, uboInfo.index);
|
1815
1828
|
}
|
1816
1829
|
}
|
1817
1830
|
}
|
1818
1831
|
});
|
1819
1832
|
forEach(this.uniformInfoMap, function (info, name) {
|
1820
|
-
var val
|
1833
|
+
var val;
|
1821
1834
|
for (var i = 0; i < blocks.length; i++) {
|
1822
1835
|
var block = blocks[i];
|
1823
|
-
|
1836
|
+
var semanticName = block.uniformSemantics[name];
|
1837
|
+
if (info.isTexture) {
|
1838
|
+
if (block.hasUniformValue(name)) {
|
1839
|
+
val = block.getUniformTexture(name);
|
1840
|
+
}
|
1841
|
+
else if (semanticName) {
|
1842
|
+
val = _this.getSemanticValue(state, semanticName);
|
1843
|
+
}
|
1844
|
+
}
|
1845
|
+
else if (temArr.has(block)) {
|
1824
1846
|
continue;
|
1825
1847
|
}
|
1826
|
-
if (block.hasUniformValue(name)) {
|
1848
|
+
else if (block.hasUniformValue(name)) {
|
1827
1849
|
if (!shared && !block._uniformFlags[name] && info.textureIndex === -1) {
|
1828
1850
|
//not dirty, don't assign
|
1829
1851
|
return;
|
1830
1852
|
}
|
1831
1853
|
val = block.getUniformValue(name);
|
1832
|
-
hasUniformValue = true;
|
1833
|
-
break;
|
1834
1854
|
}
|
1835
|
-
|
1836
|
-
|
1837
|
-
|
1838
|
-
if (
|
1839
|
-
|
1840
|
-
|
1841
|
-
|
1842
|
-
|
1843
|
-
val = renderFrameSemantics.getSemanticValue(semanticName, state);
|
1844
|
-
}
|
1855
|
+
else if (semanticName) {
|
1856
|
+
val = _this.getSemanticValue(state, semanticName);
|
1857
|
+
}
|
1858
|
+
if (val !== undefined && val !== null) {
|
1859
|
+
_this.setGLUniformValue(name, val, info, gl);
|
1860
|
+
}
|
1861
|
+
else if (!info.isTexture) {
|
1862
|
+
consoleWarn("mesh ".concat(state.currentMesh.name, " uniform ").concat(name, " value unset"));
|
1845
1863
|
}
|
1846
|
-
}
|
1847
|
-
if (val !== undefined && val !== null) {
|
1848
|
-
_this.setGLUniformValue(name, val, info, gl);
|
1849
|
-
}
|
1850
|
-
else if (!info.isTexture) {
|
1851
|
-
consoleWarn("mesh ".concat(state.currentMesh.name, " uniform ").concat(name, " value unset"));
|
1852
1864
|
}
|
1853
1865
|
});
|
1854
1866
|
};
|
@@ -4452,25 +4464,29 @@ var GLMaterial = /** @class */ (function () {
|
|
4452
4464
|
}());
|
4453
4465
|
|
4454
4466
|
function isUniformStruct(value) {
|
4455
|
-
return (isObj(value)) && (value.length === undefined)
|
4467
|
+
return (isObj(value)) && (value.length === undefined);
|
4456
4468
|
}
|
4457
4469
|
function isUniformStructArray(value) {
|
4458
4470
|
return (value) && (value.length !== undefined) && isUniformStruct(value[0]);
|
4459
4471
|
}
|
4460
4472
|
var MarsMaterialDataBlock = /** @class */ (function () {
|
4461
4473
|
function MarsMaterialDataBlock(props, renderer) {
|
4474
|
+
var _this = this;
|
4462
4475
|
this._isDestroyed = false;
|
4463
4476
|
this._isDestroyed = false;
|
4464
4477
|
this.name = props.name || 'defDataBlock';
|
4465
4478
|
this._uniformValues = {};
|
4466
4479
|
this._uniformFlags = {};
|
4467
4480
|
this.uboBufferMap = {};
|
4481
|
+
this._uniformTextures = {};
|
4468
4482
|
this._uniformValueRanges = {};
|
4469
4483
|
this._keepUboData = !!props.keepUboData;
|
4470
|
-
this.uniformSemantics = props.uniformSemantics;
|
4484
|
+
this.uniformSemantics = props.uniformSemantics || {};
|
4485
|
+
this._uniformPrivate = {};
|
4471
4486
|
if (props.uniformValues) {
|
4472
4487
|
this.setUniformValues(props.uniformValues);
|
4473
4488
|
}
|
4489
|
+
forEach(props.uniformTextures, function (tex, name) { return _this.setUniformTexture(name, tex); });
|
4474
4490
|
if (renderer) {
|
4475
4491
|
this.assignRenderer(renderer);
|
4476
4492
|
}
|
@@ -4508,6 +4524,20 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4508
4524
|
enumerable: false,
|
4509
4525
|
configurable: true
|
4510
4526
|
});
|
4527
|
+
MarsMaterialDataBlock.prototype.setUniformTexture = function (uniformName, texture) {
|
4528
|
+
if (texture) {
|
4529
|
+
this._uniformTextures[uniformName] = texture;
|
4530
|
+
this._assignUniformValueRenderer(texture, this.renderer);
|
4531
|
+
this._uniformPrivate[uniformName] = true;
|
4532
|
+
}
|
4533
|
+
else {
|
4534
|
+
delete this._uniformTextures[uniformName];
|
4535
|
+
delete this._uniformPrivate[uniformName];
|
4536
|
+
}
|
4537
|
+
};
|
4538
|
+
MarsMaterialDataBlock.prototype.getUniformTexture = function (uniformName) {
|
4539
|
+
return this._uniformTextures[uniformName];
|
4540
|
+
};
|
4511
4541
|
MarsMaterialDataBlock.prototype.assignRenderer = function (renderer) {
|
4512
4542
|
var _this = this;
|
4513
4543
|
if (this.renderer && renderer !== this.renderer) {
|
@@ -4516,7 +4546,7 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4516
4546
|
if (renderer && !this.renderer) {
|
4517
4547
|
// @ts-expect-error safe to assign
|
4518
4548
|
this.renderer = renderer;
|
4519
|
-
forEach(this.
|
4549
|
+
forEach(this._uniformTextures, function (value) {
|
4520
4550
|
_this._assignUniformValueRenderer(value, renderer);
|
4521
4551
|
});
|
4522
4552
|
}
|
@@ -4545,11 +4575,11 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4545
4575
|
this._uniformFlags[name] = true;
|
4546
4576
|
};
|
4547
4577
|
MarsMaterialDataBlock.prototype.hasUniformValue = function (name) {
|
4548
|
-
return
|
4578
|
+
return !!this._uniformPrivate[name];
|
4549
4579
|
};
|
4550
4580
|
MarsMaterialDataBlock.prototype.destroy = function (options) {
|
4551
4581
|
if ((options === null || options === void 0 ? void 0 : options.textures) !== DestroyOptions.keep) {
|
4552
|
-
forEach(this.
|
4582
|
+
forEach(this._uniformTextures, function (uniform) {
|
4553
4583
|
if (uniform instanceof MarsTexture) {
|
4554
4584
|
uniform.destroy();
|
4555
4585
|
}
|
@@ -4562,10 +4592,13 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4562
4592
|
});
|
4563
4593
|
// @ts-expect-error safe to assign
|
4564
4594
|
this.uboBufferMap = {};
|
4595
|
+
this._uniformPrivate = {};
|
4565
4596
|
// @ts-expect-error safe to assign
|
4566
4597
|
this._uniformFlags = {};
|
4567
4598
|
// @ts-expect-error safe to assign
|
4568
4599
|
this._uniformValues = {};
|
4600
|
+
// @ts-expect-error safe to assign
|
4601
|
+
this._uniformTextures = {};
|
4569
4602
|
this.assignRenderer = throwDestroyedError;
|
4570
4603
|
this._isDestroyed = true;
|
4571
4604
|
};
|
@@ -4575,20 +4608,39 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4575
4608
|
MarsMaterialDataBlock.prototype.getUniformValues = function () {
|
4576
4609
|
return this._uniformValues;
|
4577
4610
|
};
|
4578
|
-
MarsMaterialDataBlock.prototype.setUniformValue = function (name, value) {
|
4611
|
+
MarsMaterialDataBlock.prototype.setUniformValue = function (name, value, isSemantic) {
|
4579
4612
|
var _this = this;
|
4580
4613
|
if (value === undefined) {
|
4614
|
+
var originValue = this._uniformValues[name];
|
4615
|
+
if (isUniformStruct(originValue)) {
|
4616
|
+
forEach(originValue, function (data, key) {
|
4617
|
+
var nameInStruct = name + '.' + key;
|
4618
|
+
delete _this._uniformPrivate[nameInStruct];
|
4619
|
+
});
|
4620
|
+
}
|
4621
|
+
else if (isUniformStructArray(originValue)) {
|
4622
|
+
originValue.forEach(function (valueData, i) {
|
4623
|
+
forEach(valueData, function (valueInStruct, key) {
|
4624
|
+
var nameInStruct = name + '[' + i + ']' + '.' + key;
|
4625
|
+
delete _this._uniformPrivate[nameInStruct];
|
4626
|
+
});
|
4627
|
+
});
|
4628
|
+
}
|
4581
4629
|
delete this._uniformValues[name];
|
4582
4630
|
this._uniformFlags[name] = false;
|
4631
|
+
delete this._uniformPrivate[name];
|
4632
|
+
}
|
4633
|
+
else if (value instanceof MarsTexture) {
|
4634
|
+
throw Error('setUniformValue not accept texture:' + name);
|
4583
4635
|
}
|
4584
4636
|
else {
|
4637
|
+
this._uniformPrivate[name] = !isSemantic;
|
4585
4638
|
if (isUniformStruct(value)) {
|
4586
4639
|
forEach(value, function (data, key) {
|
4587
4640
|
var nameInStruct = name + '.' + key;
|
4588
|
-
|
4589
|
-
_this._uniformValues[nameInStruct] = valueInStruct;
|
4641
|
+
_this._uniformValues[nameInStruct] = data;
|
4590
4642
|
_this._uniformFlags[nameInStruct] = true;
|
4591
|
-
_this.
|
4643
|
+
_this._uniformPrivate[nameInStruct] = true;
|
4592
4644
|
});
|
4593
4645
|
// 只是用来保存结构体对象
|
4594
4646
|
this._uniformValues[name] = value;
|
@@ -4600,7 +4652,7 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4600
4652
|
var nameInStruct = name + '[' + i + ']' + '.' + key;
|
4601
4653
|
_this._uniformValues[nameInStruct] = valueInStruct;
|
4602
4654
|
_this._uniformFlags[nameInStruct] = true;
|
4603
|
-
_this.
|
4655
|
+
_this._uniformPrivate[nameInStruct] = true;
|
4604
4656
|
});
|
4605
4657
|
});
|
4606
4658
|
// 只是用来保存结构体对象
|
@@ -4610,7 +4662,6 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4610
4662
|
else {
|
4611
4663
|
this._uniformValues[name] = value;
|
4612
4664
|
this._uniformFlags[name] = true;
|
4613
|
-
this._assignUniformValueRenderer(value, this.renderer);
|
4614
4665
|
}
|
4615
4666
|
}
|
4616
4667
|
return true;
|
@@ -4621,6 +4672,14 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4621
4672
|
_this.setUniformValue(key, val);
|
4622
4673
|
});
|
4623
4674
|
};
|
4675
|
+
MarsMaterialDataBlock.prototype.setUniformSemantic = function (name, semantic) {
|
4676
|
+
if (semantic) {
|
4677
|
+
this.uniformSemantics[name] = semantic;
|
4678
|
+
}
|
4679
|
+
else {
|
4680
|
+
delete this.uniformSemantics[name];
|
4681
|
+
}
|
4682
|
+
};
|
4624
4683
|
MarsMaterialDataBlock.prototype.clone = function (name) {
|
4625
4684
|
return new MarsMaterialDataBlock({
|
4626
4685
|
name: name,
|
@@ -4639,13 +4698,10 @@ var MarsMaterial = /** @class */ (function () {
|
|
4639
4698
|
this.renderType = 0 /* MaterialRenderType.normal */;
|
4640
4699
|
this.states = this.createMaterialStates(options.states);
|
4641
4700
|
this.options = options;
|
4701
|
+
this._dbMap = {};
|
4642
4702
|
if (!this._dataBlocks.length) {
|
4643
|
-
this._dataBlocks[0] = new MarsMaterialDataBlock({ name: '' });
|
4644
|
-
}
|
4645
|
-
if (options.uniformValues) {
|
4646
|
-
this.defaultDataBlock.setUniformValues(options.uniformValues);
|
4703
|
+
this._dataBlocks[0] = new MarsMaterialDataBlock({ name: 'main' });
|
4647
4704
|
}
|
4648
|
-
this.uniformSemantics = Object.assign({}, options.uniformSemantics);
|
4649
4705
|
}
|
4650
4706
|
Object.defineProperty(MarsMaterial.prototype, "isDestroyed", {
|
4651
4707
|
get: function () {
|
@@ -4656,7 +4712,7 @@ var MarsMaterial = /** @class */ (function () {
|
|
4656
4712
|
});
|
4657
4713
|
Object.defineProperty(MarsMaterial.prototype, "dataBlocks", {
|
4658
4714
|
get: function () {
|
4659
|
-
return this._dataBlocks
|
4715
|
+
return this._dataBlocks;
|
4660
4716
|
},
|
4661
4717
|
enumerable: false,
|
4662
4718
|
configurable: true
|
@@ -4728,6 +4784,9 @@ var MarsMaterial = /** @class */ (function () {
|
|
4728
4784
|
return Object.freeze(ret);
|
4729
4785
|
};
|
4730
4786
|
MarsMaterial.prototype.addDataBlock = function (b) {
|
4787
|
+
if (this.getDataBlockByName(b.name)) {
|
4788
|
+
throw Error('dataBlock with same name:' + b.name);
|
4789
|
+
}
|
4731
4790
|
if (arrAdd(this._dataBlocks, b)) {
|
4732
4791
|
b.invalidAllFlags();
|
4733
4792
|
var r = this.renderer;
|
@@ -4736,16 +4795,19 @@ var MarsMaterial = /** @class */ (function () {
|
|
4736
4795
|
}
|
4737
4796
|
}
|
4738
4797
|
};
|
4798
|
+
MarsMaterial.prototype.getDataBlockByName = function (name) {
|
4799
|
+
var cache = this._dbMap[name];
|
4800
|
+
if (!cache) {
|
4801
|
+
var db = this._dataBlocks.find(function (db) { return db.name === name; });
|
4802
|
+
if (db) {
|
4803
|
+
return this._dbMap[name] = db;
|
4804
|
+
}
|
4805
|
+
}
|
4806
|
+
return cache;
|
4807
|
+
};
|
4739
4808
|
MarsMaterial.prototype.removeDataBlock = function (b) {
|
4740
4809
|
arrRemove(this._dataBlocks, b);
|
4741
|
-
|
4742
|
-
MarsMaterial.prototype.setUniformSemantic = function (uniformName, semantic) {
|
4743
|
-
if (semantic === undefined) {
|
4744
|
-
delete this.uniformSemantics[uniformName];
|
4745
|
-
}
|
4746
|
-
else {
|
4747
|
-
this.uniformSemantics[uniformName] = semantic;
|
4748
|
-
}
|
4810
|
+
delete this._dbMap[b.name];
|
4749
4811
|
};
|
4750
4812
|
MarsMaterial.prototype.assignRenderer = function (renderer) {
|
4751
4813
|
if (!this.materialInternal) {
|
@@ -5516,7 +5578,7 @@ var MarsExtWrap = /** @class */ (function () {
|
|
5516
5578
|
fb.viewport[3] = target.height || source.height;
|
5517
5579
|
renderer.internal.resetColorAttachments(fb, [target.internal]);
|
5518
5580
|
var mesh = rp.meshes[0];
|
5519
|
-
mesh.material.defaultDataBlock.
|
5581
|
+
mesh.material.defaultDataBlock.setUniformTexture('uTex', source);
|
5520
5582
|
RenderFrameInternal.renderRenderPass(renderer, rp, { currentFrame: {} });
|
5521
5583
|
}
|
5522
5584
|
}
|
@@ -5661,6 +5723,20 @@ var MarsRenderer = /** @class */ (function () {
|
|
5661
5723
|
}
|
5662
5724
|
}
|
5663
5725
|
};
|
5726
|
+
MarsRenderer.prototype.cancelAnimationFrame = function (id) {
|
5727
|
+
return window.cancelAnimationFrame(id);
|
5728
|
+
};
|
5729
|
+
MarsRenderer.prototype.getErrors = function () {
|
5730
|
+
var gl = this.internal.gl;
|
5731
|
+
var err = gl.getError();
|
5732
|
+
if (err) {
|
5733
|
+
return ['webgl error:' + err];
|
5734
|
+
}
|
5735
|
+
return [];
|
5736
|
+
};
|
5737
|
+
MarsRenderer.prototype.requestAnimationFrame = function (cb) {
|
5738
|
+
return window.requestAnimationFrame(cb);
|
5739
|
+
};
|
5664
5740
|
return MarsRenderer;
|
5665
5741
|
}());
|
5666
5742
|
|
@@ -5727,7 +5803,7 @@ var MarsSharedGeometry = /** @class */ (function (_super) {
|
|
5727
5803
|
return MarsSharedGeometry;
|
5728
5804
|
}(MarsGeometry));
|
5729
5805
|
|
5730
|
-
consoleLog('version: ' + "0.1.61-beta.
|
5806
|
+
consoleLog('version: ' + "0.1.61-beta.12");
|
5731
5807
|
|
5732
5808
|
export { DestroyOptions, MarsGeometry as Geometry, MarsInstancedMesh as InstancedMesh, MarsTextureFactory, MarsMaterial as Material, MarsMaterialDataBlock as MaterialDataBlock, MarsMesh as Mesh, MarsRenderFrame as RenderFrame, MarsRenderPass as RenderPass, RenderPassAttachmentStorageType, RenderPassDestroyAttachmentType, RenderPassMeshOrder, RenderPassPriorityNormal, RenderPassPriorityPostprocess, RenderPassPriorityPrepare, MarsRenderer as Renderer, ShaderCompileResultStatus, ShaderLibraryEmpty, MarsSharedGeometry as SharedGeometry, MarsTexture as Texture, TextureLoadAction, TextureSourceType, TextureStoreAction, constants, getDefaultGPUCapability, getDefaultTextureFactory, setDefaultTextureFactory };
|
5733
5809
|
//# sourceMappingURL=index.mjs.map
|