@predy-js/render-interface 0.1.61-beta.7 → 0.1.61-beta.9
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 -62
- 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,13 +2,11 @@
|
|
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.9
|
6
6
|
*/
|
7
7
|
|
8
8
|
'use strict';
|
9
9
|
|
10
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
11
|
-
|
12
10
|
/******************************************************************************
|
13
11
|
Copyright (c) Microsoft Corporation.
|
14
12
|
|
@@ -470,7 +468,7 @@ function renderMeshes(renderer, state) {
|
|
470
468
|
else if (!mesh.hide) {
|
471
469
|
delegate.willRenderMesh && delegate.willRenderMesh(mesh, state);
|
472
470
|
renderMesh(renderer, mesh, state);
|
473
|
-
delegate.
|
471
|
+
delegate.didRenderMesh && delegate.didRenderMesh(mesh, state);
|
474
472
|
}
|
475
473
|
}
|
476
474
|
for (var i = 0; i < sortedMeshes.length; i++) {
|
@@ -1794,65 +1792,77 @@ var GLProgram = /** @class */ (function () {
|
|
1794
1792
|
renderer.state.useProgram(this.glHandle);
|
1795
1793
|
}
|
1796
1794
|
};
|
1795
|
+
GLProgram.prototype.getSemanticValue = function (state, semanticName) {
|
1796
|
+
var renderPassSemantics = state.currentPass.semantics;
|
1797
|
+
var renderFrameSemantics = state.currentFrame.semantics;
|
1798
|
+
if (renderPassSemantics.hasSemanticValue(semanticName)) {
|
1799
|
+
return renderPassSemantics.getSemanticValue(semanticName, state);
|
1800
|
+
}
|
1801
|
+
else if (renderFrameSemantics.hasSemanticValue(semanticName)) {
|
1802
|
+
return renderFrameSemantics.getSemanticValue(semanticName, state);
|
1803
|
+
}
|
1804
|
+
};
|
1797
1805
|
GLProgram.prototype.setupUniforms = function (state) {
|
1798
1806
|
var _this = this;
|
1799
1807
|
this.bind();
|
1800
|
-
var frame = state.currentFrame;
|
1801
1808
|
var material = state.currentMesh.material;
|
1802
1809
|
var gl = this.renderer.gl;
|
1803
1810
|
var blocks = material._dataBlocks;
|
1804
1811
|
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
1812
|
temArr.clear();
|
1810
1813
|
forEach(this.uniformBlockMap, function (uboInfo, name) {
|
1811
1814
|
if (uboInfo) {
|
1812
|
-
|
1813
|
-
|
1814
|
-
|
1815
|
+
var block_1 = material.getDataBlockByName(uboInfo.name);
|
1816
|
+
if (block_1) {
|
1817
|
+
forEach(block_1.uniformSemantics, function (semanticName, uniformName) {
|
1818
|
+
if (uniformName in uboInfo.uniforms && !block_1.hasUniformValue(uniformName)) {
|
1819
|
+
var val = _this.getSemanticValue(state, semanticName);
|
1820
|
+
if (val || val === 0) {
|
1821
|
+
block_1.setUniformValue(uniformName, val, true);
|
1822
|
+
}
|
1823
|
+
}
|
1824
|
+
});
|
1825
|
+
var uboBuffer = block_1.createUboBuffer(uboInfo);
|
1815
1826
|
if (uboBuffer) {
|
1816
|
-
|
1817
|
-
temArr.add(
|
1827
|
+
block_1.setUboBuffer(uboBuffer);
|
1828
|
+
temArr.add(block_1);
|
1818
1829
|
return uboBuffer.bind(gl, _this.glHandle, uboInfo.index);
|
1819
1830
|
}
|
1820
1831
|
}
|
1821
1832
|
}
|
1822
1833
|
});
|
1823
1834
|
forEach(this.uniformInfoMap, function (info, name) {
|
1824
|
-
var val
|
1835
|
+
var val;
|
1825
1836
|
for (var i = 0; i < blocks.length; i++) {
|
1826
1837
|
var block = blocks[i];
|
1827
|
-
|
1838
|
+
var semanticName = block.uniformSemantics[name];
|
1839
|
+
if (info.isTexture) {
|
1840
|
+
if (block.hasUniformValue(name)) {
|
1841
|
+
val = block.getUniformTexture(name);
|
1842
|
+
}
|
1843
|
+
else if (semanticName) {
|
1844
|
+
val = _this.getSemanticValue(state, semanticName);
|
1845
|
+
}
|
1846
|
+
}
|
1847
|
+
else if (temArr.has(block)) {
|
1828
1848
|
continue;
|
1829
1849
|
}
|
1830
|
-
if (block.hasUniformValue(name)) {
|
1850
|
+
else if (block.hasUniformValue(name)) {
|
1831
1851
|
if (!shared && !block._uniformFlags[name] && info.textureIndex === -1) {
|
1832
1852
|
//not dirty, don't assign
|
1833
1853
|
return;
|
1834
1854
|
}
|
1835
1855
|
val = block.getUniformValue(name);
|
1836
|
-
hasUniformValue = true;
|
1837
|
-
break;
|
1838
1856
|
}
|
1839
|
-
|
1840
|
-
|
1841
|
-
|
1842
|
-
if (
|
1843
|
-
|
1844
|
-
|
1845
|
-
|
1846
|
-
|
1847
|
-
val = renderFrameSemantics.getSemanticValue(semanticName, state);
|
1848
|
-
}
|
1857
|
+
else if (semanticName) {
|
1858
|
+
val = _this.getSemanticValue(state, semanticName);
|
1859
|
+
}
|
1860
|
+
if (val !== undefined && val !== null) {
|
1861
|
+
_this.setGLUniformValue(name, val, info, gl);
|
1862
|
+
}
|
1863
|
+
else if (!info.isTexture) {
|
1864
|
+
consoleWarn("mesh ".concat(state.currentMesh.name, " uniform ").concat(name, " value unset"));
|
1849
1865
|
}
|
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
1866
|
}
|
1857
1867
|
});
|
1858
1868
|
};
|
@@ -4456,25 +4466,29 @@ var GLMaterial = /** @class */ (function () {
|
|
4456
4466
|
}());
|
4457
4467
|
|
4458
4468
|
function isUniformStruct(value) {
|
4459
|
-
return (isObj(value)) && (value.length === undefined)
|
4469
|
+
return (isObj(value)) && (value.length === undefined);
|
4460
4470
|
}
|
4461
4471
|
function isUniformStructArray(value) {
|
4462
4472
|
return (value) && (value.length !== undefined) && isUniformStruct(value[0]);
|
4463
4473
|
}
|
4464
4474
|
var MarsMaterialDataBlock = /** @class */ (function () {
|
4465
4475
|
function MarsMaterialDataBlock(props, renderer) {
|
4476
|
+
var _this = this;
|
4466
4477
|
this._isDestroyed = false;
|
4467
4478
|
this._isDestroyed = false;
|
4468
4479
|
this.name = props.name || 'defDataBlock';
|
4469
4480
|
this._uniformValues = {};
|
4470
4481
|
this._uniformFlags = {};
|
4471
4482
|
this.uboBufferMap = {};
|
4483
|
+
this._uniformTextures = {};
|
4472
4484
|
this._uniformValueRanges = {};
|
4473
4485
|
this._keepUboData = !!props.keepUboData;
|
4474
|
-
this.uniformSemantics = props.uniformSemantics;
|
4486
|
+
this.uniformSemantics = props.uniformSemantics || {};
|
4487
|
+
this._uniformPrivate = {};
|
4475
4488
|
if (props.uniformValues) {
|
4476
4489
|
this.setUniformValues(props.uniformValues);
|
4477
4490
|
}
|
4491
|
+
forEach(props.uniformTextures, function (tex, name) { return _this.setUniformTexture(name, tex); });
|
4478
4492
|
if (renderer) {
|
4479
4493
|
this.assignRenderer(renderer);
|
4480
4494
|
}
|
@@ -4512,6 +4526,20 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4512
4526
|
enumerable: false,
|
4513
4527
|
configurable: true
|
4514
4528
|
});
|
4529
|
+
MarsMaterialDataBlock.prototype.setUniformTexture = function (uniformName, texture) {
|
4530
|
+
if (texture) {
|
4531
|
+
this._uniformTextures[uniformName] = texture;
|
4532
|
+
this._assignUniformValueRenderer(texture, this.renderer);
|
4533
|
+
this._uniformPrivate[uniformName] = true;
|
4534
|
+
}
|
4535
|
+
else {
|
4536
|
+
delete this._uniformTextures[uniformName];
|
4537
|
+
delete this._uniformPrivate[uniformName];
|
4538
|
+
}
|
4539
|
+
};
|
4540
|
+
MarsMaterialDataBlock.prototype.getUniformTexture = function (uniformName) {
|
4541
|
+
return this._uniformTextures[uniformName];
|
4542
|
+
};
|
4515
4543
|
MarsMaterialDataBlock.prototype.assignRenderer = function (renderer) {
|
4516
4544
|
var _this = this;
|
4517
4545
|
if (this.renderer && renderer !== this.renderer) {
|
@@ -4520,7 +4548,7 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4520
4548
|
if (renderer && !this.renderer) {
|
4521
4549
|
// @ts-expect-error safe to assign
|
4522
4550
|
this.renderer = renderer;
|
4523
|
-
forEach(this.
|
4551
|
+
forEach(this._uniformTextures, function (value) {
|
4524
4552
|
_this._assignUniformValueRenderer(value, renderer);
|
4525
4553
|
});
|
4526
4554
|
}
|
@@ -4549,11 +4577,11 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4549
4577
|
this._uniformFlags[name] = true;
|
4550
4578
|
};
|
4551
4579
|
MarsMaterialDataBlock.prototype.hasUniformValue = function (name) {
|
4552
|
-
return
|
4580
|
+
return !!this._uniformPrivate[name];
|
4553
4581
|
};
|
4554
4582
|
MarsMaterialDataBlock.prototype.destroy = function (options) {
|
4555
4583
|
if ((options === null || options === void 0 ? void 0 : options.textures) !== exports.DestroyOptions.keep) {
|
4556
|
-
forEach(this.
|
4584
|
+
forEach(this._uniformTextures, function (uniform) {
|
4557
4585
|
if (uniform instanceof MarsTexture) {
|
4558
4586
|
uniform.destroy();
|
4559
4587
|
}
|
@@ -4566,10 +4594,13 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4566
4594
|
});
|
4567
4595
|
// @ts-expect-error safe to assign
|
4568
4596
|
this.uboBufferMap = {};
|
4597
|
+
this._uniformPrivate = {};
|
4569
4598
|
// @ts-expect-error safe to assign
|
4570
4599
|
this._uniformFlags = {};
|
4571
4600
|
// @ts-expect-error safe to assign
|
4572
4601
|
this._uniformValues = {};
|
4602
|
+
// @ts-expect-error safe to assign
|
4603
|
+
this._uniformTextures = {};
|
4573
4604
|
this.assignRenderer = throwDestroyedError;
|
4574
4605
|
this._isDestroyed = true;
|
4575
4606
|
};
|
@@ -4579,20 +4610,39 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4579
4610
|
MarsMaterialDataBlock.prototype.getUniformValues = function () {
|
4580
4611
|
return this._uniformValues;
|
4581
4612
|
};
|
4582
|
-
MarsMaterialDataBlock.prototype.setUniformValue = function (name, value) {
|
4613
|
+
MarsMaterialDataBlock.prototype.setUniformValue = function (name, value, isSemantic) {
|
4583
4614
|
var _this = this;
|
4584
4615
|
if (value === undefined) {
|
4616
|
+
var originValue = this._uniformValues[name];
|
4617
|
+
if (isUniformStruct(originValue)) {
|
4618
|
+
forEach(originValue, function (data, key) {
|
4619
|
+
var nameInStruct = name + '.' + key;
|
4620
|
+
delete _this._uniformPrivate[nameInStruct];
|
4621
|
+
});
|
4622
|
+
}
|
4623
|
+
else if (isUniformStructArray(originValue)) {
|
4624
|
+
originValue.forEach(function (valueData, i) {
|
4625
|
+
forEach(valueData, function (valueInStruct, key) {
|
4626
|
+
var nameInStruct = name + '[' + i + ']' + '.' + key;
|
4627
|
+
delete _this._uniformPrivate[nameInStruct];
|
4628
|
+
});
|
4629
|
+
});
|
4630
|
+
}
|
4585
4631
|
delete this._uniformValues[name];
|
4586
4632
|
this._uniformFlags[name] = false;
|
4633
|
+
delete this._uniformPrivate[name];
|
4634
|
+
}
|
4635
|
+
else if (value instanceof MarsTexture) {
|
4636
|
+
throw Error('setUniformValue not accept texture:' + name);
|
4587
4637
|
}
|
4588
4638
|
else {
|
4639
|
+
this._uniformPrivate[name] = !isSemantic;
|
4589
4640
|
if (isUniformStruct(value)) {
|
4590
4641
|
forEach(value, function (data, key) {
|
4591
4642
|
var nameInStruct = name + '.' + key;
|
4592
|
-
|
4593
|
-
_this._uniformValues[nameInStruct] = valueInStruct;
|
4643
|
+
_this._uniformValues[nameInStruct] = data;
|
4594
4644
|
_this._uniformFlags[nameInStruct] = true;
|
4595
|
-
_this.
|
4645
|
+
_this._uniformPrivate[nameInStruct] = true;
|
4596
4646
|
});
|
4597
4647
|
// 只是用来保存结构体对象
|
4598
4648
|
this._uniformValues[name] = value;
|
@@ -4604,7 +4654,7 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4604
4654
|
var nameInStruct = name + '[' + i + ']' + '.' + key;
|
4605
4655
|
_this._uniformValues[nameInStruct] = valueInStruct;
|
4606
4656
|
_this._uniformFlags[nameInStruct] = true;
|
4607
|
-
_this.
|
4657
|
+
_this._uniformPrivate[nameInStruct] = true;
|
4608
4658
|
});
|
4609
4659
|
});
|
4610
4660
|
// 只是用来保存结构体对象
|
@@ -4614,7 +4664,6 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4614
4664
|
else {
|
4615
4665
|
this._uniformValues[name] = value;
|
4616
4666
|
this._uniformFlags[name] = true;
|
4617
|
-
this._assignUniformValueRenderer(value, this.renderer);
|
4618
4667
|
}
|
4619
4668
|
}
|
4620
4669
|
return true;
|
@@ -4625,6 +4674,14 @@ var MarsMaterialDataBlock = /** @class */ (function () {
|
|
4625
4674
|
_this.setUniformValue(key, val);
|
4626
4675
|
});
|
4627
4676
|
};
|
4677
|
+
MarsMaterialDataBlock.prototype.setUniformSemantic = function (name, semantic) {
|
4678
|
+
if (semantic) {
|
4679
|
+
this.uniformSemantics[name] = semantic;
|
4680
|
+
}
|
4681
|
+
else {
|
4682
|
+
delete this.uniformSemantics[name];
|
4683
|
+
}
|
4684
|
+
};
|
4628
4685
|
MarsMaterialDataBlock.prototype.clone = function (name) {
|
4629
4686
|
return new MarsMaterialDataBlock({
|
4630
4687
|
name: name,
|
@@ -4643,13 +4700,10 @@ var MarsMaterial = /** @class */ (function () {
|
|
4643
4700
|
this.renderType = 0 /* MaterialRenderType.normal */;
|
4644
4701
|
this.states = this.createMaterialStates(options.states);
|
4645
4702
|
this.options = options;
|
4703
|
+
this._dbMap = {};
|
4646
4704
|
if (!this._dataBlocks.length) {
|
4647
|
-
this._dataBlocks[0] = new MarsMaterialDataBlock({ name: '' });
|
4648
|
-
}
|
4649
|
-
if (options.uniformValues) {
|
4650
|
-
this.defaultDataBlock.setUniformValues(options.uniformValues);
|
4705
|
+
this._dataBlocks[0] = new MarsMaterialDataBlock({ name: 'main' });
|
4651
4706
|
}
|
4652
|
-
this.uniformSemantics = Object.assign({}, options.uniformSemantics);
|
4653
4707
|
}
|
4654
4708
|
Object.defineProperty(MarsMaterial.prototype, "isDestroyed", {
|
4655
4709
|
get: function () {
|
@@ -4660,7 +4714,7 @@ var MarsMaterial = /** @class */ (function () {
|
|
4660
4714
|
});
|
4661
4715
|
Object.defineProperty(MarsMaterial.prototype, "dataBlocks", {
|
4662
4716
|
get: function () {
|
4663
|
-
return this._dataBlocks
|
4717
|
+
return this._dataBlocks;
|
4664
4718
|
},
|
4665
4719
|
enumerable: false,
|
4666
4720
|
configurable: true
|
@@ -4732,6 +4786,9 @@ var MarsMaterial = /** @class */ (function () {
|
|
4732
4786
|
return Object.freeze(ret);
|
4733
4787
|
};
|
4734
4788
|
MarsMaterial.prototype.addDataBlock = function (b) {
|
4789
|
+
if (this.getDataBlockByName(b.name)) {
|
4790
|
+
throw Error('dataBlock with same name:' + b.name);
|
4791
|
+
}
|
4735
4792
|
if (arrAdd(this._dataBlocks, b)) {
|
4736
4793
|
b.invalidAllFlags();
|
4737
4794
|
var r = this.renderer;
|
@@ -4740,17 +4797,19 @@ var MarsMaterial = /** @class */ (function () {
|
|
4740
4797
|
}
|
4741
4798
|
}
|
4742
4799
|
};
|
4800
|
+
MarsMaterial.prototype.getDataBlockByName = function (name) {
|
4801
|
+
var cache = this._dbMap[name];
|
4802
|
+
if (!cache) {
|
4803
|
+
var db = this._dataBlocks.find(function (db) { return db.name === name; });
|
4804
|
+
if (db) {
|
4805
|
+
return this._dbMap[name] = db;
|
4806
|
+
}
|
4807
|
+
}
|
4808
|
+
return cache;
|
4809
|
+
};
|
4743
4810
|
MarsMaterial.prototype.removeDataBlock = function (b) {
|
4744
4811
|
arrRemove(this._dataBlocks, b);
|
4745
4812
|
};
|
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
4813
|
MarsMaterial.prototype.assignRenderer = function (renderer) {
|
4755
4814
|
if (!this.materialInternal) {
|
4756
4815
|
var shader = this.options.shader;
|
@@ -5520,7 +5579,7 @@ var MarsExtWrap = /** @class */ (function () {
|
|
5520
5579
|
fb.viewport[3] = target.height || source.height;
|
5521
5580
|
renderer.internal.resetColorAttachments(fb, [target.internal]);
|
5522
5581
|
var mesh = rp.meshes[0];
|
5523
|
-
mesh.material.defaultDataBlock.
|
5582
|
+
mesh.material.defaultDataBlock.setUniformTexture('uTex', source);
|
5524
5583
|
RenderFrameInternal.renderRenderPass(renderer, rp, { currentFrame: {} });
|
5525
5584
|
}
|
5526
5585
|
}
|
@@ -5665,6 +5724,20 @@ var MarsRenderer = /** @class */ (function () {
|
|
5665
5724
|
}
|
5666
5725
|
}
|
5667
5726
|
};
|
5727
|
+
MarsRenderer.prototype.cancelAnimationFrame = function (id) {
|
5728
|
+
return window.cancelAnimationFrame(id);
|
5729
|
+
};
|
5730
|
+
MarsRenderer.prototype.getErrors = function () {
|
5731
|
+
var gl = this.internal.gl;
|
5732
|
+
var err = gl.getError();
|
5733
|
+
if (err) {
|
5734
|
+
return ['webgl error:' + err];
|
5735
|
+
}
|
5736
|
+
return [];
|
5737
|
+
};
|
5738
|
+
MarsRenderer.prototype.requestAnimationFrame = function (cb) {
|
5739
|
+
return window.requestAnimationFrame(cb);
|
5740
|
+
};
|
5668
5741
|
return MarsRenderer;
|
5669
5742
|
}());
|
5670
5743
|
|
@@ -5731,7 +5804,7 @@ var MarsSharedGeometry = /** @class */ (function (_super) {
|
|
5731
5804
|
return MarsSharedGeometry;
|
5732
5805
|
}(MarsGeometry));
|
5733
5806
|
|
5734
|
-
consoleLog('version: ' + "0.1.61-beta.
|
5807
|
+
consoleLog('version: ' + "0.1.61-beta.9");
|
5735
5808
|
|
5736
5809
|
exports.Geometry = MarsGeometry;
|
5737
5810
|
exports.InstancedMesh = MarsInstancedMesh;
|