@pirireis/webglobeplugins 1.1.14 → 1.1.15

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pirireis/webglobeplugins",
3
- "version": "1.1.14",
3
+ "version": "1.1.15",
4
4
  "main": "index.js",
5
5
  "author": "Toprak Nihat Deniz Ozturk",
6
6
  "license": "MIT",
@@ -15,7 +15,7 @@ const uniformBindingPoints = {
15
15
  selection: 3,
16
16
  };
17
17
  // last value of uint16 is 65535
18
- export const IndexAttributeEscapeValue = 65535;
18
+ export const IndexAttributeEscapeValue = -1;
19
19
  const styleBlockManager = new UniformBlockManager('Style', [
20
20
  { name: "defaultColor", type: "vec4", value: new Float32Array([0.0, 0.0, 0.0, 0.0]) },
21
21
  { name: "pickedColor", type: "vec4", value: new Float32Array([0, 0, 0, 0]) },
@@ -40,7 +40,7 @@ ${DEM_TEXTURE_BLOCK_STRING}
40
40
 
41
41
  in vec3 a_position;
42
42
  in vec2 a_xy;
43
- in uint a_index;
43
+ in float a_index;
44
44
  in uvec4 a_color;
45
45
 
46
46
  ${styleBlockManager.glslCode()}
@@ -55,6 +55,8 @@ void main() {
55
55
  float elevation = ${WORLD_RADIUS_3D};
56
56
  float altitude = 0.0;
57
57
 
58
+ // Always define v_index to avoid undefined varyings when picking is disabled.
59
+
58
60
  vec4 decodedColor = vec4(
59
61
  float(a_color.r) / 255.0,
60
62
  float(a_color.g) / 255.0,
@@ -89,10 +91,12 @@ void main() {
89
91
  }
90
92
 
91
93
  if (private_isPickedOn == true){
92
- if (a_index == private_pickedIndex) {
94
+ if (a_index == float(private_pickedIndex)) {
93
95
  v_color = pickedColor;
94
96
  }
95
- v_index = a_index;
97
+ v_index = uint(a_index);
98
+ } else {
99
+ v_index = 0u;
96
100
  }
97
101
 
98
102
 
@@ -119,10 +123,6 @@ void main() {
119
123
  outIndex = v_index;
120
124
  }
121
125
  `;
122
- function resCalculation(sourceResolution, mergeCount) {
123
- return sourceResolution + (mergeCount - 1) * (sourceResolution - 1);
124
- }
125
- const RESOLUTION = resCalculation(5, 20); // 5 is tile dimension length, 12 is merge count
126
126
  export class TextureDemTriangles {
127
127
  globe;
128
128
  gl;
@@ -178,7 +178,7 @@ export class TextureDemTriangles {
178
178
  attributeLoader(this.gl, pos3dBufferInfo, this.locations.attributes.a_position, 3);
179
179
  attributeLoader(this.gl, longLatBufferInfo, this.locations.attributes.a_xy, 2);
180
180
  attributeLoader(this.gl, indexBufferInfo, this.locations.attributes.a_index, 1, {
181
- dataType: "uint16",
181
+ // dataType: "uint32",
182
182
  escapeValues: [IndexAttributeEscapeValue],
183
183
  });
184
184
  attributeLoader(this.gl, variativeColorBuffer, this.locations.attributes.a_color, 4, {
@@ -208,13 +208,24 @@ export class TextureDemTriangles {
208
208
  this.demTextureManager.bindData(0, uniformBindingPoints.dem);
209
209
  gl.bindVertexArray(vao);
210
210
  ubo.bind();
211
- if (this.globe.api_GetCurrentLODWithDecimal() < 14.5) {
212
- drawOnTopBegin(gl);
213
- }
211
+ // This program has two fragment outputs (location 0: color, location 1: index).
212
+ // When rendering to the default framebuffer (no picking FBO bound), only location 0
213
+ // is valid; explicitly discard location 1 to avoid GL_INVALID_OPERATION.
214
+ // const boundFbo = gl.getParameter(gl.FRAMEBUFFER_BINDING) as WebGLFramebuffer | null;
215
+ // if (boundFbo == null) {
216
+ // gl.drawBuffers([gl.BACK, gl.NONE]);
217
+ // // }
218
+ // if (this.globe.api_GetCurrentLODWithDecimal() < 14.5) {
219
+ // drawOnTopBegin(gl);
220
+ // }
214
221
  drawArrays(gl, drawOptions.drawMode ?? gl.TRIANGLES, drawOptions);
215
- if (this.globe.api_GetCurrentLODWithDecimal() < 14.5) {
216
- drawOnTopEnd(gl);
217
- }
222
+ // if (this.globe.api_GetCurrentLODWithDecimal() < 14.5) {
223
+ // drawOnTopEnd(gl);
224
+ // }
225
+ // if (boundFbo == null) {
226
+ // // Restore the default draw buffer mapping for subsequent draws.
227
+ // gl.drawBuffers([gl.BACK]);
228
+ // }
218
229
  this.demTextureManager.unbindData(0, uniformBindingPoints.dem);
219
230
  gl.bindVertexArray(null);
220
231
  gl.bindTexture(gl.TEXTURE_2D_ARRAY, null);
@@ -95,7 +95,7 @@ function mergeAndSendResults() {
95
95
  indices: new Uint32Array(totalIndices),
96
96
  longLats: new Float32Array(totalLongLats),
97
97
  realEdgeArcIndices: _arcState && totalRealEdgeArcIndices > 0 ? new Uint32Array(totalRealEdgeArcIndices) : null,
98
- pickIndices: totalPickIndices > 0 ? new Uint16Array(totalPickIndices) : null,
98
+ pickIndices: totalPickIndices > 0 ? new Float32Array(totalPickIndices) : null,
99
99
  variativeColors: totalVariativeColors > 0 ? new Uint8Array(totalVariativeColors) : null,
100
100
  };
101
101
  // Sentinel/header (as in master-worker.js)
@@ -106,7 +106,7 @@ self.onmessage = (event) => {
106
106
  longLats: new Float32Array((counter / 3) * 2),
107
107
  indices: new Uint32Array(indexCounter),
108
108
  realEdgeArcIndices: _arcState ? new Uint32Array(totalArcCount) : null,
109
- pickIndices: _pickableState ? new Uint16Array(counter / 3) : null,
109
+ pickIndices: _pickableState ? new Float32Array(counter / 3) : null,
110
110
  variativeColors: _variativeColorsOnState ? new Uint8Array((counter / 3) * 4) : null,
111
111
  };
112
112
  let currentVertexOffset = 0;
@@ -114,11 +114,15 @@ export class TerrainPolygonSemiPlugin {
114
114
  this._uboHandler.updateSingle("private_isPickedOn", new Float32Array([1.0]));
115
115
  this._uboHandler.updateSingle("pickedColor", new Float32Array(this._options.polygonStyle.pickedColor));
116
116
  }
117
+ else {
118
+ this._uboHandler.updateSingle("private_isPickedOn", new Float32Array([0.0]));
119
+ }
117
120
  if (this._options.drawEdges) {
118
121
  this._uboForRealEdgeArcs = this._program.createUBO();
119
122
  this._uboForRealEdgeArcs.updateSingle("defaultColor", new Float32Array(this._options.edgeStyle.defaultColor));
120
123
  this._uboForRealEdgeArcs.updateSingle("useDefaultColor", new Float32Array([1]));
121
124
  this._uboForRealEdgeArcs.updateSingle("opacity", this._effectiveOpacity("edgeArc"));
125
+ this._uboForRealEdgeArcs.updateSingle("private_isPickedOn", new Float32Array([0.0]));
122
126
  this._drawRealEdgeArcs.elementBuffer = gl.createBuffer();
123
127
  }
124
128
  if (this._options.variativeColorsOn) {
@@ -8,10 +8,25 @@ const DATA_TYPE_MAP = {
8
8
  uint32: { getGLType: (gl) => gl.UNSIGNED_INT, useIntegerPointer: true, isSigned: false },
9
9
  };
10
10
  const attributeLoader = (gl, bufferAndReadInfo, index, size, { divisor = null, dataType = null, escapeValues = null, normalized = false, } = {}) => {
11
+ // WebGL returns -1 for inactive attributes (optimized out). Treat as a no-op.
12
+ // This also avoids accidentally mutating global generic attribute state.
13
+ if (index < 0) {
14
+ return;
15
+ }
11
16
  const typeInfo = dataType ? DATA_TYPE_MAP[dataType] : DATA_TYPE_MAP.float;
12
17
  if (bufferAndReadInfo == null || bufferAndReadInfo.buffer == null) {
13
- if (escapeValues)
14
- constantFunction(gl, index, size, escapeValues, typeInfo);
18
+ // Disable array and set constant value
19
+ gl.disableVertexAttribArray(index);
20
+ // If the shader expects an integer attribute (in uint/int/ivec*/uvec*),
21
+ // WebGL requires the constant to be set via vertexAttribI4i/vertexAttribI4ui.
22
+ // Otherwise you'll hit: "Vertex shader input type does not match...".
23
+ if (escapeValues != null) {
24
+ setConstantAttribute(gl, index, size, escapeValues, typeInfo);
25
+ }
26
+ else if (typeInfo.useIntegerPointer) {
27
+ // Default constant for integer attributes when not provided.
28
+ setConstantAttribute(gl, index, size, [0, 0, 0, 0], typeInfo);
29
+ }
15
30
  return;
16
31
  }
17
32
  const { buffer, stride, offset } = bufferAndReadInfo;
@@ -49,16 +64,34 @@ const createBufferAndReadInfo = (buffer, stride = 0, offset = 0) => {
49
64
  return null;
50
65
  return { buffer, stride, offset };
51
66
  };
52
- const constantFunction = (gl, index, size, escapeValues, typeInfo) => {
53
- if (!typeInfo.useIntegerPointer) {
54
- const func = `vertexAttrib${size}f`;
67
+ const setConstantAttribute = (gl, index, size, values, typeInfo) => {
68
+ // Array should already be disabled by caller
69
+ if (size < 1 || size > 4) {
70
+ throw new Error(`Attribute size must be between 1 and 4. Got ${size}.`);
71
+ }
72
+ if (typeInfo.useIntegerPointer) {
73
+ return;
74
+ gl.vertexAttrib4f(index, 0, 0, 0, 1);
75
+ // Integer attributes: WebGL2 ONLY supports vertexAttribI4i/I4ui for constants.
76
+ const intValues = values.map((v) => Math.trunc(v));
77
+ while (intValues.length < 4)
78
+ intValues.push(0);
79
+ const func = typeInfo.isSigned ? "vertexAttribI4i" : "vertexAttribI4ui";
55
80
  // @ts-ignore
56
- gl[func](index, ...escapeValues);
81
+ gl[func](index, intValues[0], intValues[1], intValues[2], intValues[3]);
57
82
  return;
58
83
  }
59
- const values = escapeValues.map((v) => Math.trunc(v));
60
- const func = typeInfo.isSigned ? `vertexAttribI${size}i` : `vertexAttribI${size}ui`;
61
- // @ts-ignore
62
- gl[func](index, ...values);
84
+ // Float attributes: use vertexAttrib{1..4}f.
85
+ const v = values.slice(0, 4);
86
+ while (v.length < 4)
87
+ v.push(size === 4 ? 0 : (v.length === 3 ? 1 : 0));
88
+ if (size === 1)
89
+ gl.vertexAttrib1f(index, v[0]);
90
+ else if (size === 2)
91
+ gl.vertexAttrib2f(index, v[0], v[1]);
92
+ else if (size === 3)
93
+ gl.vertexAttrib3f(index, v[0], v[1], v[2]);
94
+ else
95
+ gl.vertexAttrib4f(index, v[0], v[1], v[2], v[3]);
63
96
  };
64
97
  export { attributeLoader, createBufferAndReadInfo };