@predy-js/render-interface 0.1.61-beta.10 → 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 +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.js
CHANGED
@@ -2,11 +2,13 @@
|
|
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';
|
9
9
|
|
10
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
11
|
+
|
10
12
|
/******************************************************************************
|
11
13
|
Copyright (c) Microsoft Corporation.
|
12
14
|
|
@@ -468,7 +470,7 @@ function renderMeshes(renderer, state) {
|
|
468
470
|
else if (!mesh.hide) {
|
469
471
|
delegate.willRenderMesh && delegate.willRenderMesh(mesh, state);
|
470
472
|
renderMesh(renderer, mesh, state);
|
471
|
-
delegate.
|
473
|
+
delegate.didRenderMesh && delegate.didRenderMesh(mesh, state);
|
472
474
|
}
|
473
475
|
}
|
474
476
|
for (var i = 0; i < sortedMeshes.length; i++) {
|
@@ -1792,65 +1794,77 @@ var GLProgram = /** @class */ (function () {
|
|
1792
1794
|
renderer.state.useProgram(this.glHandle);
|
1793
1795
|
}
|
1794
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
|
+
};
|
1795
1807
|
GLProgram.prototype.setupUniforms = function (state) {
|
1796
1808
|
var _this = this;
|
1797
1809
|
this.bind();
|
1798
|
-
var frame = state.currentFrame;
|
1799
1810
|
var material = state.currentMesh.material;
|
1800
1811
|
var gl = this.renderer.gl;
|
1801
1812
|
var blocks = material._dataBlocks;
|
1802
1813
|
var shared = this.shared;
|
1803
|
-
var uniformSemantics = material.uniformSemantics;
|
1804
|
-
var renderPassSemantics = state.currentPass.semantics;
|
1805
|
-
var renderFrameSemantics = frame.semantics;
|
1806
|
-
// semantic {uModel:'MODEL'}
|
1807
1814
|
temArr.clear();
|
1808
1815
|
forEach(this.uniformBlockMap, function (uboInfo, name) {
|
1809
1816
|
if (uboInfo) {
|
1810
|
-
|
1811
|
-
|
1812
|
-
|
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);
|
1813
1828
|
if (uboBuffer) {
|
1814
|
-
|
1815
|
-
temArr.add(
|
1829
|
+
block_1.setUboBuffer(uboBuffer);
|
1830
|
+
temArr.add(block_1);
|
1816
1831
|
return uboBuffer.bind(gl, _this.glHandle, uboInfo.index);
|
1817
1832
|
}
|
1818
1833
|
}
|
1819
1834
|
}
|
1820
1835
|
});
|
1821
1836
|
forEach(this.uniformInfoMap, function (info, name) {
|
1822
|
-
var val
|
1837
|
+
var val;
|
1823
1838
|
for (var i = 0; i < blocks.length; i++) {
|
1824
1839
|
var block = blocks[i];
|
1825
|
-
|
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)) {
|
1826
1850
|
continue;
|
1827
1851
|
}
|
1828
|
-
if (block.hasUniformValue(name)) {
|
1852
|
+
else if (block.hasUniformValue(name)) {
|
1829
1853
|
if (!shared && !block._uniformFlags[name] && info.textureIndex === -1) {
|
1830
1854
|
//not dirty, don't assign
|
1831
1855
|
return;
|
1832
1856
|
}
|
1833
1857
|
val = block.getUniformValue(name);
|
1834
|
-
hasUniformValue = true;
|
1835
|
-
break;
|
1836
1858
|
}
|
1837
|
-
|
1838
|
-
|
1839
|
-
|
1840
|
-
if (
|
1841
|
-
|
1842
|
-
|
1843
|
-
|
1844
|
-
|
1845
|
-
val = renderFrameSemantics.getSemanticValue(semanticName, state);
|
1846
|
-
}
|
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"));
|
1847
1867
|
}
|
1848
|
-
}
|
1849
|
-
if (val !== undefined && val !== null) {
|
1850
|
-
_this.setGLUniformValue(name, val, info, gl);
|
1851
|
-
}
|
1852
|
-
else if (!info.isTexture) {
|
1853
|
-
consoleWarn("mesh ".concat(state.currentMesh.name, " uniform ").concat(name, " value unset"));
|
1854
1868
|
}
|
1855
1869
|
});
|
1856
1870
|
};
|
@@ -4454,25 +4468,29 @@ var GLMaterial = /** @class */ (function () {
|
|
4454
4468
|
}());
|
4455
4469
|
|
4456
4470
|
function isUniformStruct(value) {
|
4457
|
-
return (isObj(value)) && (value.length === undefined)
|
4471
|
+
return (isObj(value)) && (value.length === undefined);
|
4458
4472
|
}
|
4459
4473
|
function isUniformStructArray(value) {
|
4460
4474
|
return (value) && (value.length !== undefined) && isUniformStruct(value[0]);
|
4461
4475
|
}
|
4462
4476
|
var MarsMaterialDataBlock = /** @class */ (function () {
|
4463
4477
|
function MarsMaterialDataBlock(props, renderer) {
|
4478
|
+
var _this = this;
|
4464
4479
|
this._isDestroyed = false;
|
4465
4480
|
this._isDestroyed = false;
|
4466
4481
|
this.name = props.name || 'defDataBlock';
|
4467
4482
|
this._uniformValues = {};
|
4468
4483
|
this._uniformFlags = {};
|
4469
4484
|
this.uboBufferMap = {};
|
4485
|
+
this._uniformTextures = {};
|
4470
4486
|
this._uniformValueRanges = {};
|
4471
4487
|
this._keepUboData = !!props.keepUboData;
|
4472
|
-
this.uniformSemantics = props.uniformSemantics;
|
4488
|
+
this.uniformSemantics = props.uniformSemantics || {};
|
4489
|
+
this._uniformPrivate = {};
|
4473
4490
|
if (props.uniformValues) {
|
4474
4491
|
this.setUniformValues(props.uniformValues);
|
4475
4492
|
}
|
4493
|
+
forEach(props.uniformTextures, function (tex, name) { return _this.setUniformTexture(name, tex); });
|
4476
4494
|
if (renderer) {
|
4477
4495
|
this.assignRenderer(renderer);
|
4478
4496
|
}
|
@@ -4510,6 +4528,20 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4510
4528
|
enumerable: false,
|
4511
4529
|
configurable: true
|
4512
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
|
+
};
|
4513
4545
|
MarsMaterialDataBlock.prototype.assignRenderer = function (renderer) {
|
4514
4546
|
var _this = this;
|
4515
4547
|
if (this.renderer && renderer !== this.renderer) {
|
@@ -4518,7 +4550,7 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4518
4550
|
if (renderer && !this.renderer) {
|
4519
4551
|
// @ts-expect-error safe to assign
|
4520
4552
|
this.renderer = renderer;
|
4521
|
-
forEach(this.
|
4553
|
+
forEach(this._uniformTextures, function (value) {
|
4522
4554
|
_this._assignUniformValueRenderer(value, renderer);
|
4523
4555
|
});
|
4524
4556
|
}
|
@@ -4547,11 +4579,11 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4547
4579
|
this._uniformFlags[name] = true;
|
4548
4580
|
};
|
4549
4581
|
MarsMaterialDataBlock.prototype.hasUniformValue = function (name) {
|
4550
|
-
return
|
4582
|
+
return !!this._uniformPrivate[name];
|
4551
4583
|
};
|
4552
4584
|
MarsMaterialDataBlock.prototype.destroy = function (options) {
|
4553
4585
|
if ((options === null || options === void 0 ? void 0 : options.textures) !== exports.DestroyOptions.keep) {
|
4554
|
-
forEach(this.
|
4586
|
+
forEach(this._uniformTextures, function (uniform) {
|
4555
4587
|
if (uniform instanceof MarsTexture) {
|
4556
4588
|
uniform.destroy();
|
4557
4589
|
}
|
@@ -4564,10 +4596,13 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4564
4596
|
});
|
4565
4597
|
// @ts-expect-error safe to assign
|
4566
4598
|
this.uboBufferMap = {};
|
4599
|
+
this._uniformPrivate = {};
|
4567
4600
|
// @ts-expect-error safe to assign
|
4568
4601
|
this._uniformFlags = {};
|
4569
4602
|
// @ts-expect-error safe to assign
|
4570
4603
|
this._uniformValues = {};
|
4604
|
+
// @ts-expect-error safe to assign
|
4605
|
+
this._uniformTextures = {};
|
4571
4606
|
this.assignRenderer = throwDestroyedError;
|
4572
4607
|
this._isDestroyed = true;
|
4573
4608
|
};
|
@@ -4577,20 +4612,39 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4577
4612
|
MarsMaterialDataBlock.prototype.getUniformValues = function () {
|
4578
4613
|
return this._uniformValues;
|
4579
4614
|
};
|
4580
|
-
MarsMaterialDataBlock.prototype.setUniformValue = function (name, value) {
|
4615
|
+
MarsMaterialDataBlock.prototype.setUniformValue = function (name, value, isSemantic) {
|
4581
4616
|
var _this = this;
|
4582
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
|
+
}
|
4583
4633
|
delete this._uniformValues[name];
|
4584
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);
|
4585
4639
|
}
|
4586
4640
|
else {
|
4641
|
+
this._uniformPrivate[name] = !isSemantic;
|
4587
4642
|
if (isUniformStruct(value)) {
|
4588
4643
|
forEach(value, function (data, key) {
|
4589
4644
|
var nameInStruct = name + '.' + key;
|
4590
|
-
|
4591
|
-
_this._uniformValues[nameInStruct] = valueInStruct;
|
4645
|
+
_this._uniformValues[nameInStruct] = data;
|
4592
4646
|
_this._uniformFlags[nameInStruct] = true;
|
4593
|
-
_this.
|
4647
|
+
_this._uniformPrivate[nameInStruct] = true;
|
4594
4648
|
});
|
4595
4649
|
// 只是用来保存结构体对象
|
4596
4650
|
this._uniformValues[name] = value;
|
@@ -4602,7 +4656,7 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4602
4656
|
var nameInStruct = name + '[' + i + ']' + '.' + key;
|
4603
4657
|
_this._uniformValues[nameInStruct] = valueInStruct;
|
4604
4658
|
_this._uniformFlags[nameInStruct] = true;
|
4605
|
-
_this.
|
4659
|
+
_this._uniformPrivate[nameInStruct] = true;
|
4606
4660
|
});
|
4607
4661
|
});
|
4608
4662
|
// 只是用来保存结构体对象
|
@@ -4612,7 +4666,6 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4612
4666
|
else {
|
4613
4667
|
this._uniformValues[name] = value;
|
4614
4668
|
this._uniformFlags[name] = true;
|
4615
|
-
this._assignUniformValueRenderer(value, this.renderer);
|
4616
4669
|
}
|
4617
4670
|
}
|
4618
4671
|
return true;
|
@@ -4623,6 +4676,14 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4623
4676
|
_this.setUniformValue(key, val);
|
4624
4677
|
});
|
4625
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
|
+
};
|
4626
4687
|
MarsMaterialDataBlock.prototype.clone = function (name) {
|
4627
4688
|
return new MarsMaterialDataBlock({
|
4628
4689
|
name: name,
|
@@ -4641,13 +4702,10 @@ var MarsMaterial = /** @class */ (function () {
|
|
4641
4702
|
this.renderType = 0 /* MaterialRenderType.normal */;
|
4642
4703
|
this.states = this.createMaterialStates(options.states);
|
4643
4704
|
this.options = options;
|
4705
|
+
this._dbMap = {};
|
4644
4706
|
if (!this._dataBlocks.length) {
|
4645
|
-
this._dataBlocks[0] = new MarsMaterialDataBlock({ name: '' });
|
4646
|
-
}
|
4647
|
-
if (options.uniformValues) {
|
4648
|
-
this.defaultDataBlock.setUniformValues(options.uniformValues);
|
4707
|
+
this._dataBlocks[0] = new MarsMaterialDataBlock({ name: 'main' });
|
4649
4708
|
}
|
4650
|
-
this.uniformSemantics = Object.assign({}, options.uniformSemantics);
|
4651
4709
|
}
|
4652
4710
|
Object.defineProperty(MarsMaterial.prototype, "isDestroyed", {
|
4653
4711
|
get: function () {
|
@@ -4658,7 +4716,7 @@ var MarsMaterial = /** @class */ (function () {
|
|
4658
4716
|
});
|
4659
4717
|
Object.defineProperty(MarsMaterial.prototype, "dataBlocks", {
|
4660
4718
|
get: function () {
|
4661
|
-
return this._dataBlocks
|
4719
|
+
return this._dataBlocks;
|
4662
4720
|
},
|
4663
4721
|
enumerable: false,
|
4664
4722
|
configurable: true
|
@@ -4730,6 +4788,9 @@ var MarsMaterial = /** @class */ (function () {
|
|
4730
4788
|
return Object.freeze(ret);
|
4731
4789
|
};
|
4732
4790
|
MarsMaterial.prototype.addDataBlock = function (b) {
|
4791
|
+
if (this.getDataBlockByName(b.name)) {
|
4792
|
+
throw Error('dataBlock with same name:' + b.name);
|
4793
|
+
}
|
4733
4794
|
if (arrAdd(this._dataBlocks, b)) {
|
4734
4795
|
b.invalidAllFlags();
|
4735
4796
|
var r = this.renderer;
|
@@ -4738,16 +4799,19 @@ var MarsMaterial = /** @class */ (function () {
|
|
4738
4799
|
}
|
4739
4800
|
}
|
4740
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
|
+
};
|
4741
4812
|
MarsMaterial.prototype.removeDataBlock = function (b) {
|
4742
4813
|
arrRemove(this._dataBlocks, b);
|
4743
|
-
|
4744
|
-
MarsMaterial.prototype.setUniformSemantic = function (uniformName, semantic) {
|
4745
|
-
if (semantic === undefined) {
|
4746
|
-
delete this.uniformSemantics[uniformName];
|
4747
|
-
}
|
4748
|
-
else {
|
4749
|
-
this.uniformSemantics[uniformName] = semantic;
|
4750
|
-
}
|
4814
|
+
delete this._dbMap[b.name];
|
4751
4815
|
};
|
4752
4816
|
MarsMaterial.prototype.assignRenderer = function (renderer) {
|
4753
4817
|
if (!this.materialInternal) {
|
@@ -5518,7 +5582,7 @@ var MarsExtWrap = /** @class */ (function () {
|
|
5518
5582
|
fb.viewport[3] = target.height || source.height;
|
5519
5583
|
renderer.internal.resetColorAttachments(fb, [target.internal]);
|
5520
5584
|
var mesh = rp.meshes[0];
|
5521
|
-
mesh.material.defaultDataBlock.
|
5585
|
+
mesh.material.defaultDataBlock.setUniformTexture('uTex', source);
|
5522
5586
|
RenderFrameInternal.renderRenderPass(renderer, rp, { currentFrame: {} });
|
5523
5587
|
}
|
5524
5588
|
}
|
@@ -5663,6 +5727,20 @@ var MarsRenderer = /** @class */ (function () {
|
|
5663
5727
|
}
|
5664
5728
|
}
|
5665
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
|
+
};
|
5666
5744
|
return MarsRenderer;
|
5667
5745
|
}());
|
5668
5746
|
|
@@ -5729,7 +5807,7 @@ var MarsSharedGeometry = /** @class */ (function (_super) {
|
|
5729
5807
|
return MarsSharedGeometry;
|
5730
5808
|
}(MarsGeometry));
|
5731
5809
|
|
5732
|
-
consoleLog('version: ' + "0.1.61-beta.
|
5810
|
+
consoleLog('version: ' + "0.1.61-beta.11");
|
5733
5811
|
|
5734
5812
|
exports.Geometry = MarsGeometry;
|
5735
5813
|
exports.InstancedMesh = MarsInstancedMesh;
|