@predy-js/render-interface 0.1.61-beta.7 → 0.1.61-beta.8
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 +135 -60
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +135 -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 -1
- package/dist/types/native/TextureInternal.d.ts +0 -1
- 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 +12 -1
- package/types/native/TextureInternal.ts +0 -1
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.8
|
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,25 +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;
|
4474
|
-
this.uniformSemantics = props.uniformSemantics;
|
4488
|
+
this.uniformSemantics = props.uniformSemantics || {};
|
4489
|
+
this._uniformPrivate = {};
|
4475
4490
|
if (props.uniformValues) {
|
4476
4491
|
this.setUniformValues(props.uniformValues);
|
4477
4492
|
}
|
4493
|
+
forEach(props.uniformTextures, function (tex, name) { return _this.setUniformTexture(name, tex); });
|
4478
4494
|
if (renderer) {
|
4479
4495
|
this.assignRenderer(renderer);
|
4480
4496
|
}
|
@@ -4512,6 +4528,20 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4512
4528
|
enumerable: false,
|
4513
4529
|
configurable: true
|
4514
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
|
+
};
|
4515
4545
|
MarsMaterialDataBlock.prototype.assignRenderer = function (renderer) {
|
4516
4546
|
var _this = this;
|
4517
4547
|
if (this.renderer && renderer !== this.renderer) {
|
@@ -4520,7 +4550,7 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4520
4550
|
if (renderer && !this.renderer) {
|
4521
4551
|
// @ts-expect-error safe to assign
|
4522
4552
|
this.renderer = renderer;
|
4523
|
-
forEach(this.
|
4553
|
+
forEach(this._uniformTextures, function (value) {
|
4524
4554
|
_this._assignUniformValueRenderer(value, renderer);
|
4525
4555
|
});
|
4526
4556
|
}
|
@@ -4549,11 +4579,11 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4549
4579
|
this._uniformFlags[name] = true;
|
4550
4580
|
};
|
4551
4581
|
MarsMaterialDataBlock.prototype.hasUniformValue = function (name) {
|
4552
|
-
return
|
4582
|
+
return !!this._uniformPrivate[name];
|
4553
4583
|
};
|
4554
4584
|
MarsMaterialDataBlock.prototype.destroy = function (options) {
|
4555
4585
|
if ((options === null || options === void 0 ? void 0 : options.textures) !== exports.DestroyOptions.keep) {
|
4556
|
-
forEach(this.
|
4586
|
+
forEach(this._uniformTextures, function (uniform) {
|
4557
4587
|
if (uniform instanceof MarsTexture) {
|
4558
4588
|
uniform.destroy();
|
4559
4589
|
}
|
@@ -4566,10 +4596,13 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4566
4596
|
});
|
4567
4597
|
// @ts-expect-error safe to assign
|
4568
4598
|
this.uboBufferMap = {};
|
4599
|
+
this._uniformPrivate = {};
|
4569
4600
|
// @ts-expect-error safe to assign
|
4570
4601
|
this._uniformFlags = {};
|
4571
4602
|
// @ts-expect-error safe to assign
|
4572
4603
|
this._uniformValues = {};
|
4604
|
+
// @ts-expect-error safe to assign
|
4605
|
+
this._uniformTextures = {};
|
4573
4606
|
this.assignRenderer = throwDestroyedError;
|
4574
4607
|
this._isDestroyed = true;
|
4575
4608
|
};
|
@@ -4579,20 +4612,39 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4579
4612
|
MarsMaterialDataBlock.prototype.getUniformValues = function () {
|
4580
4613
|
return this._uniformValues;
|
4581
4614
|
};
|
4582
|
-
MarsMaterialDataBlock.prototype.setUniformValue = function (name, value) {
|
4615
|
+
MarsMaterialDataBlock.prototype.setUniformValue = function (name, value, isSemantic) {
|
4583
4616
|
var _this = this;
|
4584
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
|
+
}
|
4585
4633
|
delete this._uniformValues[name];
|
4586
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);
|
4587
4639
|
}
|
4588
4640
|
else {
|
4641
|
+
this._uniformPrivate[name] = !isSemantic;
|
4589
4642
|
if (isUniformStruct(value)) {
|
4590
4643
|
forEach(value, function (data, key) {
|
4591
4644
|
var nameInStruct = name + '.' + key;
|
4592
|
-
|
4593
|
-
_this._uniformValues[nameInStruct] = valueInStruct;
|
4645
|
+
_this._uniformValues[nameInStruct] = data;
|
4594
4646
|
_this._uniformFlags[nameInStruct] = true;
|
4595
|
-
_this.
|
4647
|
+
_this._uniformPrivate[nameInStruct] = true;
|
4596
4648
|
});
|
4597
4649
|
// 只是用来保存结构体对象
|
4598
4650
|
this._uniformValues[name] = value;
|
@@ -4604,7 +4656,7 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4604
4656
|
var nameInStruct = name + '[' + i + ']' + '.' + key;
|
4605
4657
|
_this._uniformValues[nameInStruct] = valueInStruct;
|
4606
4658
|
_this._uniformFlags[nameInStruct] = true;
|
4607
|
-
_this.
|
4659
|
+
_this._uniformPrivate[nameInStruct] = true;
|
4608
4660
|
});
|
4609
4661
|
});
|
4610
4662
|
// 只是用来保存结构体对象
|
@@ -4614,7 +4666,6 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4614
4666
|
else {
|
4615
4667
|
this._uniformValues[name] = value;
|
4616
4668
|
this._uniformFlags[name] = true;
|
4617
|
-
this._assignUniformValueRenderer(value, this.renderer);
|
4618
4669
|
}
|
4619
4670
|
}
|
4620
4671
|
return true;
|
@@ -4625,6 +4676,14 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4625
4676
|
_this.setUniformValue(key, val);
|
4626
4677
|
});
|
4627
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
|
+
};
|
4628
4687
|
MarsMaterialDataBlock.prototype.clone = function (name) {
|
4629
4688
|
return new MarsMaterialDataBlock({
|
4630
4689
|
name: name,
|
@@ -4643,13 +4702,10 @@ var MarsMaterial = /** @class */ (function () {
|
|
4643
4702
|
this.renderType = 0 /* MaterialRenderType.normal */;
|
4644
4703
|
this.states = this.createMaterialStates(options.states);
|
4645
4704
|
this.options = options;
|
4705
|
+
this._dbMap = {};
|
4646
4706
|
if (!this._dataBlocks.length) {
|
4647
|
-
this._dataBlocks[0] = new MarsMaterialDataBlock({ name: '' });
|
4648
|
-
}
|
4649
|
-
if (options.uniformValues) {
|
4650
|
-
this.defaultDataBlock.setUniformValues(options.uniformValues);
|
4707
|
+
this._dataBlocks[0] = new MarsMaterialDataBlock({ name: 'main' });
|
4651
4708
|
}
|
4652
|
-
this.uniformSemantics = Object.assign({}, options.uniformSemantics);
|
4653
4709
|
}
|
4654
4710
|
Object.defineProperty(MarsMaterial.prototype, "isDestroyed", {
|
4655
4711
|
get: function () {
|
@@ -4660,7 +4716,7 @@ var MarsMaterial = /** @class */ (function () {
|
|
4660
4716
|
});
|
4661
4717
|
Object.defineProperty(MarsMaterial.prototype, "dataBlocks", {
|
4662
4718
|
get: function () {
|
4663
|
-
return this._dataBlocks
|
4719
|
+
return this._dataBlocks;
|
4664
4720
|
},
|
4665
4721
|
enumerable: false,
|
4666
4722
|
configurable: true
|
@@ -4732,6 +4788,9 @@ var MarsMaterial = /** @class */ (function () {
|
|
4732
4788
|
return Object.freeze(ret);
|
4733
4789
|
};
|
4734
4790
|
MarsMaterial.prototype.addDataBlock = function (b) {
|
4791
|
+
if (this.getDataBlockByName(b.name)) {
|
4792
|
+
throw Error('dataBlock with same name:' + b.name);
|
4793
|
+
}
|
4735
4794
|
if (arrAdd(this._dataBlocks, b)) {
|
4736
4795
|
b.invalidAllFlags();
|
4737
4796
|
var r = this.renderer;
|
@@ -4740,17 +4799,19 @@ var MarsMaterial = /** @class */ (function () {
|
|
4740
4799
|
}
|
4741
4800
|
}
|
4742
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
|
+
};
|
4743
4812
|
MarsMaterial.prototype.removeDataBlock = function (b) {
|
4744
4813
|
arrRemove(this._dataBlocks, b);
|
4745
4814
|
};
|
4746
|
-
MarsMaterial.prototype.setUniformSemantic = function (uniformName, semantic) {
|
4747
|
-
if (semantic === undefined) {
|
4748
|
-
delete this.uniformSemantics[uniformName];
|
4749
|
-
}
|
4750
|
-
else {
|
4751
|
-
this.uniformSemantics[uniformName] = semantic;
|
4752
|
-
}
|
4753
|
-
};
|
4754
4815
|
MarsMaterial.prototype.assignRenderer = function (renderer) {
|
4755
4816
|
if (!this.materialInternal) {
|
4756
4817
|
var shader = this.options.shader;
|
@@ -5520,7 +5581,7 @@ var MarsExtWrap = /** @class */ (function () {
|
|
5520
5581
|
fb.viewport[3] = target.height || source.height;
|
5521
5582
|
renderer.internal.resetColorAttachments(fb, [target.internal]);
|
5522
5583
|
var mesh = rp.meshes[0];
|
5523
|
-
mesh.material.defaultDataBlock.
|
5584
|
+
mesh.material.defaultDataBlock.setUniformTexture('uTex', source);
|
5524
5585
|
RenderFrameInternal.renderRenderPass(renderer, rp, { currentFrame: {} });
|
5525
5586
|
}
|
5526
5587
|
}
|
@@ -5665,6 +5726,20 @@ var MarsRenderer = /** @class */ (function () {
|
|
5665
5726
|
}
|
5666
5727
|
}
|
5667
5728
|
};
|
5729
|
+
MarsRenderer.prototype.cancelAnimationFrame = function (id) {
|
5730
|
+
return window.cancelAnimationFrame(id);
|
5731
|
+
};
|
5732
|
+
MarsRenderer.prototype.getErrors = function () {
|
5733
|
+
var gl = this.internal.gl;
|
5734
|
+
var err = gl.getError();
|
5735
|
+
if (err) {
|
5736
|
+
return ['webgl error:' + err];
|
5737
|
+
}
|
5738
|
+
return [];
|
5739
|
+
};
|
5740
|
+
MarsRenderer.prototype.requestAnimationFrame = function (cb) {
|
5741
|
+
return window.requestAnimationFrame(cb);
|
5742
|
+
};
|
5668
5743
|
return MarsRenderer;
|
5669
5744
|
}());
|
5670
5745
|
|
@@ -5731,7 +5806,7 @@ var MarsSharedGeometry = /** @class */ (function (_super) {
|
|
5731
5806
|
return MarsSharedGeometry;
|
5732
5807
|
}(MarsGeometry));
|
5733
5808
|
|
5734
|
-
consoleLog('version: ' + "0.1.61-beta.
|
5809
|
+
consoleLog('version: ' + "0.1.61-beta.8");
|
5735
5810
|
|
5736
5811
|
exports.Geometry = MarsGeometry;
|
5737
5812
|
exports.InstancedMesh = MarsInstancedMesh;
|