@pirireis/webglobeplugins 1.1.23 → 1.1.24

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.23",
3
+ "version": "1.1.24",
4
4
  "main": "index.js",
5
5
  "author": "Toprak Nihat Deniz Ozturk",
6
6
  "license": "MIT",
@@ -4,7 +4,7 @@ import { DemTextureManagerCache, DEM_TEXTURE_BLOCK_STRING } from "../totems/atta
4
4
  import { cartesian3DToGLPosition, mercatorXYToGLPosition, POLE_BY_PI } from "../../util/shaderfunctions/geometrytransformations";
5
5
  import { relativeBBoxPositionRadian } from "../../util/shaderfunctions/geometrytransformations";
6
6
  import { drawArrays } from "../../util/gl-util/draw-options/methods";
7
- import { attributeLoader, resetAttributeDefault, setDefaultAttributeValues } from "../../util/gl-util/buffer/attribute-loader";
7
+ import { AttributeLoader } from "../../util/gl-util/buffer/attribute-loader";
8
8
  import { WORLD_RADIUS_3D } from "../../Math/constants";
9
9
  import { UniformBlockManager } from "../../util/gl-util/uniform-block/manager";
10
10
  // const ESCAPE_VALUE = 0.123456;
@@ -84,7 +84,7 @@ void main() {
84
84
  break;
85
85
  }
86
86
  }
87
- vec3 position = a_position * (elevation + altitude);
87
+ vec3 position = a_position * (elevation + altitude * elevation_scale);
88
88
  gl_Position = cartesian3DToGLPosition(position);
89
89
  } else {
90
90
  vec2 mercatorXY = a_xy * POLE_BY_PI;
@@ -171,21 +171,23 @@ export class TextureDemTriangles {
171
171
  this.demTextureManager = DemTextureManagerCache.get(this.globe);
172
172
  this.demTextureManager.assignBindingPoint(this.program, uniformBindingPoints.dem);
173
173
  }
174
- createVAO(pos3dBufferInfo, longLatBufferInfo, indexBufferInfo, variativeColorBuffer) {
175
- const vao = this.gl.createVertexArray();
176
- this.gl.bindVertexArray(vao);
177
- attributeLoader(this.gl, pos3dBufferInfo, this.locations.attributes.a_position, 3);
178
- attributeLoader(this.gl, longLatBufferInfo, this.locations.attributes.a_xy, 2);
179
- attributeLoader(this.gl, indexBufferInfo, this.locations.attributes.a_index, 1, {
180
- dataType: "uint16",
181
- escapeValues: [IndexAttributeEscapeValue],
182
- });
183
- attributeLoader(this.gl, variativeColorBuffer, this.locations.attributes.a_color, 4, {
184
- dataType: "uint8",
185
- escapeValues: [0, 0, 0, 255]
186
- });
187
- this.gl.bindVertexArray(null);
188
- return vao;
174
+ createAttributeLoader(pos3dBufferInfo, longLatBufferInfo, indexBufferInfo, variativeColorBuffer) {
175
+ return new AttributeLoader(this.gl, [
176
+ { bufferAndReadInfo: pos3dBufferInfo, index: this.locations.attributes.a_position, size: 3, options: {} },
177
+ { bufferAndReadInfo: longLatBufferInfo, index: this.locations.attributes.a_xy, size: 2, options: {} },
178
+ {
179
+ bufferAndReadInfo: indexBufferInfo, index: this.locations.attributes.a_index, size: 1, options: {
180
+ dataType: "uint16",
181
+ escapeValues: [IndexAttributeEscapeValue],
182
+ }
183
+ },
184
+ {
185
+ bufferAndReadInfo: variativeColorBuffer, index: this.locations.attributes.a_color, size: 4, options: {
186
+ dataType: "uint8",
187
+ escapeValues: [0, 0, 0, 255]
188
+ }
189
+ },
190
+ ]);
189
191
  }
190
192
  createUBO(bufferReadType = "STATIC_DRAW") {
191
193
  const ubo = styleBlockManager.createUBO(this.gl, bufferReadType);
@@ -200,12 +202,12 @@ export class TextureDemTriangles {
200
202
  DemTextureManagerCache.release(this.globe);
201
203
  CameraUniformBlockTotemCache.release(this.globe);
202
204
  }
203
- draw(vao, drawOptions, ubo) {
205
+ draw(attributeLoader, drawOptions, ubo) {
204
206
  const gl = this.gl;
205
207
  gl.useProgram(this.program);
206
208
  this.cameraUniformBlock.bind(uniformBindingPoints.camera);
207
209
  this.demTextureManager.bindData(0, uniformBindingPoints.dem);
208
- gl.bindVertexArray(vao);
210
+ attributeLoader.bind();
209
211
  ubo.bind();
210
212
  // This program has two fragment outputs (location 0: color, location 1: index).
211
213
  // When rendering to the default framebuffer (no picking FBO bound), only location 0
@@ -226,24 +228,12 @@ export class TextureDemTriangles {
226
228
  // gl.drawBuffers([gl.BACK]);
227
229
  // }
228
230
  this.demTextureManager.unbindData(0, uniformBindingPoints.dem);
229
- gl.bindVertexArray(null);
231
+ attributeLoader.unbind();
230
232
  gl.bindTexture(gl.TEXTURE_2D_ARRAY, null);
231
233
  gl.useProgram(null);
232
234
  ubo.unbind();
233
235
  this.cameraUniformBlock.unbind(uniformBindingPoints.camera);
234
236
  }
235
- setDefaultDefaultAttributeValues() {
236
- const gl = this.gl;
237
- setDefaultAttributeValues(gl, this.locations.attributes.a_index, 1, [IndexAttributeEscapeValue], "uint16");
238
- setDefaultAttributeValues(gl, this.locations.attributes.a_color, 4, [0, 0, 0, 255], "uint8");
239
- }
240
- resetDefaultAttributeValues() {
241
- const gl = this.gl;
242
- gl.disableVertexAttribArray(this.locations.attributes.a_index);
243
- resetAttributeDefault(gl, this.locations.attributes.a_index);
244
- gl.disableVertexAttribArray(this.locations.attributes.a_color);
245
- resetAttributeDefault(gl, this.locations.attributes.a_color);
246
- }
247
237
  _getUniformBlockOffset(name) {
248
238
  // hardcoded offsets based on std140 layout rules
249
239
  const offsets = {
@@ -8,6 +8,7 @@ layout(std140) uniform DemTextureUniformBlock {
8
8
  vec4 u_textureDataCoverRatio[6]; // 96 bytes
9
9
  vec2 u_textureResolution; // 8 bytes
10
10
  int u_breakLoopIndex; // 4 bytes
11
+ float elevation_scale;
11
12
  };
12
13
  uniform sampler2DArray u_demTexture;
13
14
  `;
@@ -17,8 +18,9 @@ const MAXLAYERS = 6;
17
18
  // CoverRatio: 6 * 16 bytes = 96
18
19
  // Resolution: 8 bytes (offset 192)
19
20
  // BreakLoopIndex: 4 bytes (offset 200)
20
- // Total used: 204 bytes.
21
- // std140 blocks are typically padded to 16 bytes alignment -> 208 bytes.
21
+ // Elevation scale: 4 bytes (offset 204)
22
+ // Total used: 208 bytes.
23
+ // std140 blocks no need for padding -> 208 bytes.
22
24
  // 208 bytes / 4 bytes per float = 52 floats.
23
25
  const uniformBlockData = new Float32Array(52);
24
26
  function drawnedTilesHash(drawnTiles) {
@@ -162,6 +164,7 @@ export class DemTextureManager {
162
164
  uniformBlockData[49] = this.textureHeight;
163
165
  // Set break loop index (offset 200 bytes -> index 50)
164
166
  uniformBlockData[50] = this.mergedData.length;
167
+ uniformBlockData[51] = this._globe.api_GetZScale();
165
168
  // Unbind texture after updating
166
169
  gl.bindTexture(gl.TEXTURE_2D_ARRAY, null);
167
170
  gl.bindBuffer(gl.UNIFORM_BUFFER, this.uniformBuffer);
@@ -41,7 +41,7 @@ export class TerrainPolygonSemiPlugin {
41
41
  _pickIndexBuffer = null;
42
42
  _variativeColorBuffer = null;
43
43
  _mercatorXYBuffer = null;
44
- _vao = null;
44
+ _attributeLoader = null;
45
45
  _uboHandler = null;
46
46
  _uboForRealEdgeArcs = null;
47
47
  _drawPointsRangeIndexParams = {
@@ -132,7 +132,7 @@ export class TerrainPolygonSemiPlugin {
132
132
  if (this._options.variativeColorsOn) {
133
133
  this._variativeColorBuffer = gl.createBuffer();
134
134
  }
135
- this._vao = this._program.createVAO({
135
+ this._attributeLoader = this._program.createAttributeLoader({
136
136
  offset: 0,
137
137
  stride: 0,
138
138
  buffer: this._vec3Buffer
@@ -389,10 +389,9 @@ export class TerrainPolygonSemiPlugin {
389
389
  gl.disable(gl.DEPTH_TEST);
390
390
  gl.enable(gl.BLEND);
391
391
  defaultblendfunction(gl);
392
- this._program.setDefaultDefaultAttributeValues();
393
392
  // drawPoints
394
393
  if (this._options.showTesselationPoints) {
395
- this._program.draw(this._vao, this._drawPointsRangeIndexParams, this._uboHandler);
394
+ this._program.draw(this._attributeLoader, this._drawPointsRangeIndexParams, this._uboHandler);
396
395
  }
397
396
  if (this._pickerDisplayer && !this._options.pickablePause) {
398
397
  this._pickerDisplayer.bindFBO();
@@ -400,7 +399,7 @@ export class TerrainPolygonSemiPlugin {
400
399
  // gl.enable(gl.DEPTH_TEST);
401
400
  }
402
401
  gl.frontFace(gl.CW);
403
- this._program.draw(this._vao, this._drawRangeIndexParams, this._uboHandler);
402
+ this._program.draw(this._attributeLoader, this._drawRangeIndexParams, this._uboHandler);
404
403
  gl.frontFace(gl.CCW);
405
404
  if (this._pickerDisplayer && !this._options.pickablePause) {
406
405
  gl.bindFramebuffer(gl.FRAMEBUFFER, null);
@@ -411,10 +410,9 @@ export class TerrainPolygonSemiPlugin {
411
410
  gl.disable(gl.DEPTH_TEST);
412
411
  // gl.enable(gl.POLYGON_OFFSET_FILL);
413
412
  // gl.polygonOffset(-3.0, -3.0);
414
- this._program.draw(this._vao, this._drawRealEdgeArcs, this._uboForRealEdgeArcs);
413
+ this._program.draw(this._attributeLoader, this._drawRealEdgeArcs, this._uboForRealEdgeArcs);
415
414
  // gl.disable(gl.POLYGON_OFFSET_FILL);
416
415
  }
417
- this._program.resetDefaultAttributeValues();
418
416
  gl.enable(gl.DEPTH_TEST);
419
417
  }
420
418
  free() {
@@ -99,4 +99,46 @@ function resetAttributeDefault(gl, index) {
99
99
  function setDefaultAttributeValues(gl, index, size, escapeValues, typeInfo) {
100
100
  setConstantAttribute(gl, index, size, escapeValues, DATA_TYPE_MAP[typeInfo]);
101
101
  }
102
+ export class AttributeLoader {
103
+ gl;
104
+ meta;
105
+ vao;
106
+ stickyNotes = new Map();
107
+ constructor(gl, meta) {
108
+ this.gl = gl;
109
+ this.meta = meta;
110
+ this.vao = gl.createVertexArray();
111
+ gl.bindVertexArray(this.vao);
112
+ for (const { bufferAndReadInfo, index, size, options } of this.meta) {
113
+ if (bufferAndReadInfo != null && bufferAndReadInfo.buffer != null) {
114
+ attributeLoader(this.gl, bufferAndReadInfo, index, size, options);
115
+ }
116
+ else if (options.escapeValues) {
117
+ const dataType = options.dataType || "float";
118
+ const typeInfo = DATA_TYPE_MAP[dataType];
119
+ this.stickyNotes.set(index, { size, typeInfo, escapeValues: options.escapeValues });
120
+ }
121
+ else {
122
+ throw new Error("Invalid attribute loader configuration");
123
+ }
124
+ }
125
+ gl.bindVertexArray(null);
126
+ }
127
+ bind() {
128
+ const { gl } = this;
129
+ gl.bindVertexArray(this.vao);
130
+ for (const [index, { size, typeInfo, escapeValues }] of this.stickyNotes) {
131
+ setConstantAttribute(gl, index, size, escapeValues, typeInfo);
132
+ }
133
+ }
134
+ unbind() {
135
+ this.gl.bindVertexArray(null);
136
+ for (const index of this.stickyNotes.keys()) {
137
+ resetAttributeDefault(this.gl, index);
138
+ }
139
+ }
140
+ free() {
141
+ this.gl.deleteVertexArray(this.vao);
142
+ }
143
+ }
102
144
  export { attributeLoader, createBufferAndReadInfo, resetAttributeDefault, setDefaultAttributeValues };