@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.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.11
|
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,24 +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;
|
4484
|
+
this.uniformSemantics = props.uniformSemantics || {};
|
4485
|
+
this._uniformPrivate = {};
|
4470
4486
|
if (props.uniformValues) {
|
4471
4487
|
this.setUniformValues(props.uniformValues);
|
4472
4488
|
}
|
4489
|
+
forEach(props.uniformTextures, function (tex, name) { return _this.setUniformTexture(name, tex); });
|
4473
4490
|
if (renderer) {
|
4474
4491
|
this.assignRenderer(renderer);
|
4475
4492
|
}
|
@@ -4507,6 +4524,20 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4507
4524
|
enumerable: false,
|
4508
4525
|
configurable: true
|
4509
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
|
+
};
|
4510
4541
|
MarsMaterialDataBlock.prototype.assignRenderer = function (renderer) {
|
4511
4542
|
var _this = this;
|
4512
4543
|
if (this.renderer && renderer !== this.renderer) {
|
@@ -4515,7 +4546,7 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4515
4546
|
if (renderer && !this.renderer) {
|
4516
4547
|
// @ts-expect-error safe to assign
|
4517
4548
|
this.renderer = renderer;
|
4518
|
-
forEach(this.
|
4549
|
+
forEach(this._uniformTextures, function (value) {
|
4519
4550
|
_this._assignUniformValueRenderer(value, renderer);
|
4520
4551
|
});
|
4521
4552
|
}
|
@@ -4544,11 +4575,11 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4544
4575
|
this._uniformFlags[name] = true;
|
4545
4576
|
};
|
4546
4577
|
MarsMaterialDataBlock.prototype.hasUniformValue = function (name) {
|
4547
|
-
return
|
4578
|
+
return !!this._uniformPrivate[name];
|
4548
4579
|
};
|
4549
4580
|
MarsMaterialDataBlock.prototype.destroy = function (options) {
|
4550
4581
|
if ((options === null || options === void 0 ? void 0 : options.textures) !== DestroyOptions.keep) {
|
4551
|
-
forEach(this.
|
4582
|
+
forEach(this._uniformTextures, function (uniform) {
|
4552
4583
|
if (uniform instanceof MarsTexture) {
|
4553
4584
|
uniform.destroy();
|
4554
4585
|
}
|
@@ -4561,10 +4592,13 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4561
4592
|
});
|
4562
4593
|
// @ts-expect-error safe to assign
|
4563
4594
|
this.uboBufferMap = {};
|
4595
|
+
this._uniformPrivate = {};
|
4564
4596
|
// @ts-expect-error safe to assign
|
4565
4597
|
this._uniformFlags = {};
|
4566
4598
|
// @ts-expect-error safe to assign
|
4567
4599
|
this._uniformValues = {};
|
4600
|
+
// @ts-expect-error safe to assign
|
4601
|
+
this._uniformTextures = {};
|
4568
4602
|
this.assignRenderer = throwDestroyedError;
|
4569
4603
|
this._isDestroyed = true;
|
4570
4604
|
};
|
@@ -4574,20 +4608,39 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4574
4608
|
MarsMaterialDataBlock.prototype.getUniformValues = function () {
|
4575
4609
|
return this._uniformValues;
|
4576
4610
|
};
|
4577
|
-
MarsMaterialDataBlock.prototype.setUniformValue = function (name, value) {
|
4611
|
+
MarsMaterialDataBlock.prototype.setUniformValue = function (name, value, isSemantic) {
|
4578
4612
|
var _this = this;
|
4579
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
|
+
}
|
4580
4629
|
delete this._uniformValues[name];
|
4581
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);
|
4582
4635
|
}
|
4583
4636
|
else {
|
4637
|
+
this._uniformPrivate[name] = !isSemantic;
|
4584
4638
|
if (isUniformStruct(value)) {
|
4585
4639
|
forEach(value, function (data, key) {
|
4586
4640
|
var nameInStruct = name + '.' + key;
|
4587
|
-
|
4588
|
-
_this._uniformValues[nameInStruct] = valueInStruct;
|
4641
|
+
_this._uniformValues[nameInStruct] = data;
|
4589
4642
|
_this._uniformFlags[nameInStruct] = true;
|
4590
|
-
_this.
|
4643
|
+
_this._uniformPrivate[nameInStruct] = true;
|
4591
4644
|
});
|
4592
4645
|
// 只是用来保存结构体对象
|
4593
4646
|
this._uniformValues[name] = value;
|
@@ -4599,7 +4652,7 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4599
4652
|
var nameInStruct = name + '[' + i + ']' + '.' + key;
|
4600
4653
|
_this._uniformValues[nameInStruct] = valueInStruct;
|
4601
4654
|
_this._uniformFlags[nameInStruct] = true;
|
4602
|
-
_this.
|
4655
|
+
_this._uniformPrivate[nameInStruct] = true;
|
4603
4656
|
});
|
4604
4657
|
});
|
4605
4658
|
// 只是用来保存结构体对象
|
@@ -4609,7 +4662,6 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4609
4662
|
else {
|
4610
4663
|
this._uniformValues[name] = value;
|
4611
4664
|
this._uniformFlags[name] = true;
|
4612
|
-
this._assignUniformValueRenderer(value, this.renderer);
|
4613
4665
|
}
|
4614
4666
|
}
|
4615
4667
|
return true;
|
@@ -4620,6 +4672,14 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4620
4672
|
_this.setUniformValue(key, val);
|
4621
4673
|
});
|
4622
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
|
+
};
|
4623
4683
|
MarsMaterialDataBlock.prototype.clone = function (name) {
|
4624
4684
|
return new MarsMaterialDataBlock({
|
4625
4685
|
name: name,
|
@@ -4638,13 +4698,10 @@ var MarsMaterial = /** @class */ (function () {
|
|
4638
4698
|
this.renderType = 0 /* MaterialRenderType.normal */;
|
4639
4699
|
this.states = this.createMaterialStates(options.states);
|
4640
4700
|
this.options = options;
|
4701
|
+
this._dbMap = {};
|
4641
4702
|
if (!this._dataBlocks.length) {
|
4642
|
-
this._dataBlocks[0] = new MarsMaterialDataBlock({ name: '' });
|
4643
|
-
}
|
4644
|
-
if (options.uniformValues) {
|
4645
|
-
this.defaultDataBlock.setUniformValues(options.uniformValues);
|
4703
|
+
this._dataBlocks[0] = new MarsMaterialDataBlock({ name: 'main' });
|
4646
4704
|
}
|
4647
|
-
this.uniformSemantics = Object.assign({}, options.uniformSemantics);
|
4648
4705
|
}
|
4649
4706
|
Object.defineProperty(MarsMaterial.prototype, "isDestroyed", {
|
4650
4707
|
get: function () {
|
@@ -4655,7 +4712,7 @@ var MarsMaterial = /** @class */ (function () {
|
|
4655
4712
|
});
|
4656
4713
|
Object.defineProperty(MarsMaterial.prototype, "dataBlocks", {
|
4657
4714
|
get: function () {
|
4658
|
-
return this._dataBlocks
|
4715
|
+
return this._dataBlocks;
|
4659
4716
|
},
|
4660
4717
|
enumerable: false,
|
4661
4718
|
configurable: true
|
@@ -4727,6 +4784,9 @@ var MarsMaterial = /** @class */ (function () {
|
|
4727
4784
|
return Object.freeze(ret);
|
4728
4785
|
};
|
4729
4786
|
MarsMaterial.prototype.addDataBlock = function (b) {
|
4787
|
+
if (this.getDataBlockByName(b.name)) {
|
4788
|
+
throw Error('dataBlock with same name:' + b.name);
|
4789
|
+
}
|
4730
4790
|
if (arrAdd(this._dataBlocks, b)) {
|
4731
4791
|
b.invalidAllFlags();
|
4732
4792
|
var r = this.renderer;
|
@@ -4735,16 +4795,19 @@ var MarsMaterial = /** @class */ (function () {
|
|
4735
4795
|
}
|
4736
4796
|
}
|
4737
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
|
+
};
|
4738
4808
|
MarsMaterial.prototype.removeDataBlock = function (b) {
|
4739
4809
|
arrRemove(this._dataBlocks, b);
|
4740
|
-
|
4741
|
-
MarsMaterial.prototype.setUniformSemantic = function (uniformName, semantic) {
|
4742
|
-
if (semantic === undefined) {
|
4743
|
-
delete this.uniformSemantics[uniformName];
|
4744
|
-
}
|
4745
|
-
else {
|
4746
|
-
this.uniformSemantics[uniformName] = semantic;
|
4747
|
-
}
|
4810
|
+
delete this._dbMap[b.name];
|
4748
4811
|
};
|
4749
4812
|
MarsMaterial.prototype.assignRenderer = function (renderer) {
|
4750
4813
|
if (!this.materialInternal) {
|
@@ -5515,7 +5578,7 @@ var MarsExtWrap = /** @class */ (function () {
|
|
5515
5578
|
fb.viewport[3] = target.height || source.height;
|
5516
5579
|
renderer.internal.resetColorAttachments(fb, [target.internal]);
|
5517
5580
|
var mesh = rp.meshes[0];
|
5518
|
-
mesh.material.defaultDataBlock.
|
5581
|
+
mesh.material.defaultDataBlock.setUniformTexture('uTex', source);
|
5519
5582
|
RenderFrameInternal.renderRenderPass(renderer, rp, { currentFrame: {} });
|
5520
5583
|
}
|
5521
5584
|
}
|
@@ -5660,6 +5723,20 @@ var MarsRenderer = /** @class */ (function () {
|
|
5660
5723
|
}
|
5661
5724
|
}
|
5662
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
|
+
};
|
5663
5740
|
return MarsRenderer;
|
5664
5741
|
}());
|
5665
5742
|
|
@@ -5726,7 +5803,7 @@ var MarsSharedGeometry = /** @class */ (function (_super) {
|
|
5726
5803
|
return MarsSharedGeometry;
|
5727
5804
|
}(MarsGeometry));
|
5728
5805
|
|
5729
|
-
consoleLog('version: ' + "0.1.61-beta.
|
5806
|
+
consoleLog('version: ' + "0.1.61-beta.11");
|
5730
5807
|
|
5731
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 };
|
5732
5809
|
//# sourceMappingURL=index.mjs.map
|