@xeokit/xeokit-sdk 2.4.2-beta-49 → 2.5.0-beta
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/package.json
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @private
|
|
3
|
+
*/
|
|
4
|
+
export class BindableDataTexture {
|
|
5
|
+
|
|
6
|
+
constructor(gl, texture, textureWidth, textureHeight, textureData = null) {
|
|
7
|
+
this._gl = gl;
|
|
8
|
+
this._texture = texture;
|
|
9
|
+
this._textureWidth = textureWidth;
|
|
10
|
+
this._textureHeight = textureHeight;
|
|
11
|
+
this._textureData = textureData;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
bindTexture(glProgram, shaderName, glTextureUnit) {
|
|
15
|
+
return glProgram.bindTexture(shaderName, this, glTextureUnit);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
bind(unit) {
|
|
19
|
+
this._gl.activeTexture(this._gl["TEXTURE" + unit]);
|
|
20
|
+
this._gl.bindTexture(this._gl.TEXTURE_2D, this._texture);
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
unbind(unit) {
|
|
25
|
+
// This `unbind` method is ignored at the moment to allow avoiding
|
|
26
|
+
// to rebind same texture already bound to a texture unit.
|
|
27
|
+
|
|
28
|
+
// this._gl.activeTexture(this.state.gl["TEXTURE" + unit]);
|
|
29
|
+
// this._gl.bindTexture(this.state.gl.TEXTURE_2D, null);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {BindableDataTexture} from "./BindableDataTexture.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @private
|
|
5
|
+
*/
|
|
6
|
+
export class DataTextureGenerator {
|
|
7
|
+
|
|
8
|
+
disableBindedTextureFiltering(gl) {
|
|
9
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
10
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
11
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
12
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
generateTextureForInstancingMatrices(gl, instanceMatrices) {
|
|
16
|
+
const numMatrices = instanceMatrices.length;
|
|
17
|
+
if (numMatrices === 0) {
|
|
18
|
+
throw "num instance matrices===0";
|
|
19
|
+
}
|
|
20
|
+
// in one row we can fit 512 matrices
|
|
21
|
+
const textureWidth = 512 * 4;
|
|
22
|
+
const textureHeight = Math.ceil(numMatrices / (textureWidth / 4));
|
|
23
|
+
const texArray = new Float32Array(4 * textureWidth * textureHeight);
|
|
24
|
+
for (let i = 0; i < instanceMatrices.length; i++) { // 4x4 values
|
|
25
|
+
texArray.set(instanceMatrices[i], i * 16);
|
|
26
|
+
}
|
|
27
|
+
const texture = gl.createTexture();
|
|
28
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
29
|
+
gl.texStorage2D(gl.TEXTURE_2D, 1, gl.RGBA32F, textureWidth, textureHeight);
|
|
30
|
+
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, textureWidth, textureHeight, gl.RGBA, gl.FLOAT, texArray, 0);
|
|
31
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
32
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
33
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
34
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
35
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
36
|
+
return new BindableDataTexture(gl, texture, textureWidth, textureHeight, texArray);
|
|
37
|
+
}
|
|
38
|
+
}
|