@tangram.gl/tangram-renderer 0.0.0-stage → 0.0.1
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/README.md +60 -2
- package/dist/core.js +36923 -0
- package/dist/core.js.map +6 -0
- package/dist/index.js +32 -0
- package/dist/loaders-gl-worker.js +82 -0
- package/dist/loaders-gl-worker.js.map +6 -0
- package/dist/map-logic.js +2 -0
- package/dist/map-logic.js.map +6 -0
- package/dist/projected-basemaps-worker.js +3 -0
- package/dist/projected-basemaps-worker.js.map +6 -0
- package/dist/shader-modules.js +141 -0
- package/dist/shader-modules.js.map +6 -0
- package/dist/style-schema.js +126 -0
- package/dist/style-schema.js.map +6 -0
- package/dist/tangram-style.schema.json +882 -0
- package/dist/tangram.debug.mjs +37139 -0
- package/dist/tangram.debug.mjs.map +6 -0
- package/dist/tangram.min.mjs +4950 -0
- package/dist/types/builders/earcut.d.ts +15 -0
- package/dist/types/core.d.ts +29 -0
- package/dist/types/gl/constants.d.ts +2 -0
- package/dist/types/gl/globe_mesh.d.ts +48 -0
- package/dist/types/gl/glsl.d.ts +17 -0
- package/dist/types/gl/vertex-constants.d.ts +4 -0
- package/dist/types/gl/vertex-types.d.ts +34 -0
- package/dist/types/gl/vertex_data.d.ts +32 -0
- package/dist/types/gl/vertex_elements.d.ts +8 -0
- package/dist/types/gl/vertex_layout.d.ts +32 -0
- package/dist/types/glsl.d.ts +14 -0
- package/dist/types/gpu/luma_device_renderer.d.ts +66 -0
- package/dist/types/gpu/resource_lifecycle.d.ts +4 -0
- package/dist/types/gpu/tangram_gpu_backend.d.ts +151 -0
- package/dist/types/index.d.ts +155 -0
- package/dist/types/lights/light-definitions.d.ts +121 -0
- package/dist/types/map-logic/draped-terrain-bounds.d.ts +41 -0
- package/dist/types/map-logic/globe-terrain-preparation.d.ts +85 -0
- package/dist/types/map-logic/globe-terrain.d.ts +54 -0
- package/dist/types/map-logic/index.d.ts +33 -0
- package/dist/types/map-logic/label-identity.d.ts +22 -0
- package/dist/types/map-logic/label-placement.d.ts +32 -0
- package/dist/types/map-logic/screen-bounds.d.ts +15 -0
- package/dist/types/map-logic/terrain-data.d.ts +55 -0
- package/dist/types/map-logic/terrain-error.d.ts +51 -0
- package/dist/types/map-logic/terrain-ground-topology.d.ts +26 -0
- package/dist/types/map-logic/terrain-height-field.d.ts +59 -0
- package/dist/types/map-logic/terrain-navigation.d.ts +27 -0
- package/dist/types/map-logic/terrain-neighborhood.d.ts +5 -0
- package/dist/types/map-logic/terrain-query.d.ts +33 -0
- package/dist/types/map-logic/terrain-resource-budget.d.ts +51 -0
- package/dist/types/map-logic/terrain-transition-topology.d.ts +23 -0
- package/dist/types/map-logic/tile-build-queue.d.ts +51 -0
- package/dist/types/map-logic/tile-cache-policy.d.ts +46 -0
- package/dist/types/map-logic/tile-residency.d.ts +17 -0
- package/dist/types/map-logic/triangle-query-index.d.ts +87 -0
- package/dist/types/procedures/js-yaml.d.ts +15 -0
- package/dist/types/procedures/mesh-projector.d.ts +107 -0
- package/dist/types/procedures/mvt-dependencies.d.ts +20 -0
- package/dist/types/procedures/projected-coordinate-transform.d.ts +27 -0
- package/dist/types/procedures/projection-batch-executor.d.ts +53 -0
- package/dist/types/procedures/scene-yaml-legacy.d.ts +6 -0
- package/dist/types/procedures/terrain-draping.d.ts +165 -0
- package/dist/types/procedures/terrain-globe.d.ts +6 -0
- package/dist/types/procedures/terrain-styled-topology.d.ts +34 -0
- package/dist/types/procedures/web-mercator-legacy.d.ts +4 -0
- package/dist/types/procedures/web-mercator-math.d.ts +4 -0
- package/dist/types/scene/globals.d.ts +11 -0
- package/dist/types/scene/ground_footprint.d.ts +16 -0
- package/dist/types/scene/host_frame.d.ts +54 -0
- package/dist/types/scene/projection_math.d.ts +52 -0
- package/dist/types/scene/scene-resource-types.d.ts +177 -0
- package/dist/types/scene/scene_bundle.d.ts +69 -0
- package/dist/types/scene/visibility_adapter.d.ts +106 -0
- package/dist/types/selection/draped-terrain-surface.d.ts +78 -0
- package/dist/types/selection/terrain_surface.d.ts +149 -0
- package/dist/types/shader-modules/globe-horizon.d.ts +15 -0
- package/dist/types/shader-modules/height-decode.d.ts +13 -0
- package/dist/types/shader-modules/hillshade.d.ts +13 -0
- package/dist/types/shader-modules/index.d.ts +6 -0
- package/dist/types/shader-modules/planar.d.ts +12 -0
- package/dist/types/shader-modules/sphere-map.d.ts +13 -0
- package/dist/types/shader-modules/triplanar.d.ts +15 -0
- package/dist/types/sources/decoded_tile_store.d.ts +95 -0
- package/dist/types/sources/tile_source_metadata.d.ts +32 -0
- package/dist/types/styles/text/fontfaceobserver.d.ts +10 -0
- package/dist/types/tile/tile_id.d.ts +37 -0
- package/dist/types/tile/tile_traversal_adapter.d.ts +63 -0
- package/dist/types/types.d.ts +293 -0
- package/dist/types/utils/geo.d.ts +57 -0
- package/dist/types/utils/hash.d.ts +1 -0
- package/dist/types/utils/log.d.ts +27 -0
- package/dist/types/utils/props.d.ts +6 -0
- package/dist/types/utils/subscribe.d.ts +10 -0
- package/dist/types/utils/thread.d.ts +6 -0
- package/dist/types/utils/urls.d.ts +26 -0
- package/dist/types/utils/utils.d.ts +26 -0
- package/dist/types/utils/version.d.ts +2 -0
- package/dist/types/utils/worker-types.d.ts +68 -0
- package/dist/types/utils/worker_broker.d.ts +3 -0
- package/package.json +103 -3
- package/src/builders/common.ts +41 -0
- package/src/builders/earcut.d.ts +15 -0
- package/src/builders/geometry-types.ts +60 -0
- package/src/builders/points.ts +115 -0
- package/src/builders/polygons.ts +225 -0
- package/src/builders/polylines.ts +682 -0
- package/src/builders/wireframe.ts +31 -0
- package/src/core.d.ts +29 -0
- package/src/core.ts +33 -0
- package/src/experimental/loaders-gl-worker.ts +19 -0
- package/src/experimental/projected-basemaps-worker.ts +13 -0
- package/src/experimental/projected-mesh-cache.ts +137 -0
- package/src/experimental/projected-mesh-domain.ts +110 -0
- package/src/experimental/projected-mesh-refinement.ts +193 -0
- package/src/experimental/projected-mesh.ts +399 -0
- package/src/experimental/projected-normal.ts +26 -0
- package/src/experimental/projected-symbol-mesh.ts +74 -0
- package/src/gl/constants.ts +18 -0
- package/src/gl/context.ts +103 -0
- package/src/gl/extensions.ts +30 -0
- package/src/gl/globe_mesh.ts +285 -0
- package/src/gl/glsl.ts +257 -0
- package/src/gl/mesh-types.ts +56 -0
- package/src/gl/render_state.ts +111 -0
- package/src/gl/shader_program.ts +1310 -0
- package/src/gl/texture.ts +814 -0
- package/src/gl/uniform_buffer.ts +340 -0
- package/src/gl/vao.ts +154 -0
- package/src/gl/vbo_mesh.ts +349 -0
- package/src/gl/vertex-constants.ts +19 -0
- package/src/gl/vertex-types.ts +35 -0
- package/src/gl/vertex_data.ts +126 -0
- package/src/gl/vertex_elements.ts +54 -0
- package/src/gl/vertex_layout.ts +241 -0
- package/src/glsl.d.ts +14 -0
- package/src/gpu/luma_device_renderer.ts +579 -0
- package/src/gpu/pixel_readback.ts +51 -0
- package/src/gpu/resource_lifecycle.ts +32 -0
- package/src/gpu/tangram_gpu_backend.ts +195 -0
- package/src/index.d.ts +155 -0
- package/src/index.ts +105 -0
- package/src/labels/collision-types.ts +94 -0
- package/src/labels/collision.ts +273 -0
- package/src/labels/collision_grid.ts +61 -0
- package/src/labels/intersect.ts +30 -0
- package/src/labels/label-types.ts +91 -0
- package/src/labels/label.ts +207 -0
- package/src/labels/label_line.ts +801 -0
- package/src/labels/label_point.ts +131 -0
- package/src/labels/main-pass-types.ts +73 -0
- package/src/labels/main_pass.ts +221 -0
- package/src/labels/point_anchor.ts +100 -0
- package/src/labels/point_placement.ts +150 -0
- package/src/labels/projected-pass.ts +259 -0
- package/src/labels/repeat_group.ts +72 -0
- package/src/lights/ambient_light.glsl +18 -0
- package/src/lights/directional_light.glsl +39 -0
- package/src/lights/geographic-lights.ts +21 -0
- package/src/lights/light-definitions.ts +285 -0
- package/src/lights/light.ts +590 -0
- package/src/lights/lighting-uniforms.ts +80 -0
- package/src/lights/lighting-wgsl.ts +116 -0
- package/src/lights/material.glsl +237 -0
- package/src/lights/material.ts +145 -0
- package/src/lights/native-falloff.ts +37 -0
- package/src/lights/point_light.glsl +96 -0
- package/src/lights/spot_light.glsl +111 -0
- package/src/map-logic/draped-terrain-bounds.ts +71 -0
- package/src/map-logic/globe-terrain-preparation.ts +217 -0
- package/src/map-logic/globe-terrain.ts +296 -0
- package/src/map-logic/index.ts +37 -0
- package/src/map-logic/label-identity.ts +36 -0
- package/src/map-logic/label-placement.ts +117 -0
- package/src/map-logic/screen-bounds.ts +34 -0
- package/src/map-logic/terrain-data.ts +107 -0
- package/src/map-logic/terrain-error.ts +134 -0
- package/src/map-logic/terrain-ground-topology.ts +164 -0
- package/src/map-logic/terrain-height-field.ts +254 -0
- package/src/map-logic/terrain-navigation.ts +50 -0
- package/src/map-logic/terrain-neighborhood.ts +43 -0
- package/src/map-logic/terrain-query.ts +51 -0
- package/src/map-logic/terrain-resource-budget.ts +124 -0
- package/src/map-logic/terrain-transition-topology.ts +164 -0
- package/src/map-logic/tile-build-queue.ts +110 -0
- package/src/map-logic/tile-cache-policy.ts +89 -0
- package/src/map-logic/tile-residency.ts +50 -0
- package/src/map-logic/triangle-query-index.ts +265 -0
- package/src/procedures/js-yaml.d.ts +15 -0
- package/src/procedures/mesh-projector.ts +191 -0
- package/src/procedures/mlt-loaders.ts +55 -0
- package/src/procedures/mvt-dependencies.d.ts +20 -0
- package/src/procedures/mvt-legacy.ts +150 -0
- package/src/procedures/mvt-loaders.ts +53 -0
- package/src/procedures/mvt-parser.ts +48 -0
- package/src/procedures/mvt-properties.ts +36 -0
- package/src/procedures/mvt-tile-provider.ts +72 -0
- package/src/procedures/pmtiles-loader.ts +75 -0
- package/src/procedures/projected-coordinate-transform.ts +79 -0
- package/src/procedures/projection-batch-executor.ts +140 -0
- package/src/procedures/scene-yaml-legacy.ts +16 -0
- package/src/procedures/scene-yaml-loaders.ts +10 -0
- package/src/procedures/terrain-draping.ts +713 -0
- package/src/procedures/terrain-globe.ts +32 -0
- package/src/procedures/terrain-styled-topology.ts +184 -0
- package/src/procedures/web-mercator-legacy.ts +24 -0
- package/src/procedures/web-mercator-math.ts +50 -0
- package/src/scene/camera.ts +298 -0
- package/src/scene/camera_base.ts +116 -0
- package/src/scene/classic_scene.ts +20 -0
- package/src/scene/external_camera.ts +101 -0
- package/src/scene/globals.ts +120 -0
- package/src/scene/ground_footprint.ts +139 -0
- package/src/scene/host_frame.ts +326 -0
- package/src/scene/projected_tile_lod.ts +125 -0
- package/src/scene/projection_math.ts +142 -0
- package/src/scene/projection_shaders.ts +183 -0
- package/src/scene/renderer.ts +516 -0
- package/src/scene/scene-resource-types.ts +174 -0
- package/src/scene/scene.ts +2378 -0
- package/src/scene/scene_bundle.ts +304 -0
- package/src/scene/scene_debug.ts +129 -0
- package/src/scene/scene_loader.ts +402 -0
- package/src/scene/scene_worker.ts +528 -0
- package/src/scene/view.ts +683 -0
- package/src/scene/visibility_adapter.ts +319 -0
- package/src/scene/worker_url.ts +15 -0
- package/src/selection/draped-terrain-surface.ts +377 -0
- package/src/selection/selection-types.ts +79 -0
- package/src/selection/selection.ts +542 -0
- package/src/selection/selection_fragment.glsl +18 -0
- package/src/selection/selection_globals.glsl +9 -0
- package/src/selection/selection_pixels.ts +59 -0
- package/src/selection/selection_vertex.glsl +15 -0
- package/src/selection/terrain_surface.ts +298 -0
- package/src/shader-modules/globe-horizon.ts +52 -0
- package/src/shader-modules/height-decode.ts +41 -0
- package/src/shader-modules/hillshade.ts +70 -0
- package/src/shader-modules/index.ts +10 -0
- package/src/shader-modules/planar.ts +24 -0
- package/src/shader-modules/sphere-map.ts +38 -0
- package/src/shader-modules/triplanar.ts +45 -0
- package/src/sources/aligned_tile_source.ts +122 -0
- package/src/sources/data_source.ts +655 -0
- package/src/sources/decoded_tile_store.ts +245 -0
- package/src/sources/geojson.ts +300 -0
- package/src/sources/mvt.ts +247 -0
- package/src/sources/raster.ts +341 -0
- package/src/sources/shared_tile_source_adapter.ts +117 -0
- package/src/sources/sources.ts +10 -0
- package/src/sources/tile_source_adapter.ts +84 -0
- package/src/sources/tile_source_metadata.ts +65 -0
- package/src/sources/tile_source_state.ts +112 -0
- package/src/sources/topojson.ts +90 -0
- package/src/styles/feature_annotations.ts +16 -0
- package/src/styles/filter.ts +190 -0
- package/src/styles/geometry-style-types.ts +209 -0
- package/src/styles/globe_visibility_wgsl.ts +22 -0
- package/src/styles/layer-types.ts +45 -0
- package/src/styles/layer.ts +586 -0
- package/src/styles/lines/dasharray.ts +49 -0
- package/src/styles/lines/lines.ts +707 -0
- package/src/styles/lines/lines_wgsl.ts +224 -0
- package/src/styles/points/point-runtime-types.ts +125 -0
- package/src/styles/points/points.ts +1079 -0
- package/src/styles/points/points_fragment.glsl +126 -0
- package/src/styles/points/points_vertex.glsl +230 -0
- package/src/styles/points/points_wgsl.ts +189 -0
- package/src/styles/polygons/polygons.ts +268 -0
- package/src/styles/polygons/polygons_fragment.glsl +173 -0
- package/src/styles/polygons/polygons_vertex.glsl +213 -0
- package/src/styles/polygons/polygons_wgsl.ts +127 -0
- package/src/styles/property-types.ts +125 -0
- package/src/styles/raster/raster.ts +33 -0
- package/src/styles/raster/raster_globals.glsl +46 -0
- package/src/styles/style-mixing-types.ts +101 -0
- package/src/styles/style-runtime-types.ts +220 -0
- package/src/styles/style-schema.ts +133 -0
- package/src/styles/style.ts +1033 -0
- package/src/styles/style_globals.glsl +69 -0
- package/src/styles/style_manager.ts +464 -0
- package/src/styles/style_parser.ts +620 -0
- package/src/styles/text/font_manager.ts +180 -0
- package/src/styles/text/fontfaceobserver.d.ts +10 -0
- package/src/styles/text/text-types.ts +220 -0
- package/src/styles/text/text.ts +378 -0
- package/src/styles/text/text_canvas.ts +773 -0
- package/src/styles/text/text_labels.ts +436 -0
- package/src/styles/text/text_segments.ts +142 -0
- package/src/styles/text/text_settings.ts +228 -0
- package/src/styles/text/text_wgsl.ts +159 -0
- package/src/styles/text/text_wrap.ts +194 -0
- package/src/tile/globe_tile_preload.ts +40 -0
- package/src/tile/tangram_tileset_2d.ts +108 -0
- package/src/tile/tile-build-types.ts +155 -0
- package/src/tile/tile.ts +807 -0
- package/src/tile/tile_id.ts +172 -0
- package/src/tile/tile_manager.ts +889 -0
- package/src/tile/tile_pyramid.ts +119 -0
- package/src/tile/tile_resource_cache.ts +91 -0
- package/src/tile/tile_traversal_adapter.ts +132 -0
- package/src/types.ts +332 -0
- package/src/utils/debounce.ts +17 -0
- package/src/utils/debug_settings.ts +43 -0
- package/src/utils/errors.ts +12 -0
- package/src/utils/functions.ts +95 -0
- package/src/utils/geo.ts +364 -0
- package/src/utils/hash.ts +14 -0
- package/src/utils/log.ts +108 -0
- package/src/utils/media_capture.ts +193 -0
- package/src/utils/merge.ts +44 -0
- package/src/utils/obb.ts +134 -0
- package/src/utils/props.ts +43 -0
- package/src/utils/slice.ts +14 -0
- package/src/utils/subscribe.ts +58 -0
- package/src/utils/task.ts +154 -0
- package/src/utils/thread.ts +26 -0
- package/src/utils/urls.ts +223 -0
- package/src/utils/utils.ts +310 -0
- package/src/utils/vector.ts +197 -0
- package/src/utils/version.ts +8 -0
- package/src/utils/worker-types.ts +79 -0
- package/src/utils/worker_broker.ts +523 -0
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
// Tangram
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) 2013-2016 Brett Camper and Mapzen
|
|
4
|
+
// Copyright (c) 2026 vis.gl contributors
|
|
5
|
+
|
|
6
|
+
// Manage rendering for primitives
|
|
7
|
+
import type {Buffer, PrimitiveTopology} from '@luma.gl/core';
|
|
8
|
+
import type {TangramMeshBufferOptions, TangramMeshDrawDescriptor} from '../gpu/tangram_gpu_backend';
|
|
9
|
+
import type {MeshContext, MeshVertexData, MeshElementData, MeshVertexLayout, MeshOptions, MeshProgram, MeshRenderOptions, MeshVertexArrays} from './mesh-types';
|
|
10
|
+
import ShaderProgram from './shader_program';
|
|
11
|
+
import VertexArrayObject from './vao';
|
|
12
|
+
import Texture from './texture';
|
|
13
|
+
import {refineGlobeMesh, type GlobeMeshOptions} from './globe_mesh';
|
|
14
|
+
import {notifyGPUResourceDisposal} from '../gpu/resource_lifecycle';
|
|
15
|
+
|
|
16
|
+
// A single mesh/VBO, described by a vertex layout, that can be drawn with one or more programs
|
|
17
|
+
export default class VBOMesh {
|
|
18
|
+
/** Worker variant policy attached by the tile uploader without changing constructor ownership. */
|
|
19
|
+
declare variant: import('../tile/tile-build-types').TileMeshVariant;
|
|
20
|
+
/** Optional worker annotation ranges attached during upload. */
|
|
21
|
+
declare labels?: Record<string, import('../labels/main-pass-types').MeshLabel>;
|
|
22
|
+
/** Exact ground query channels transferred with the final worker draw mesh. */
|
|
23
|
+
terrainQueryMesh?: import('../selection/draped-terrain-surface').DrapedTerrainQueryMesh;
|
|
24
|
+
/** One admitted terrain generation's shared transition origin. */
|
|
25
|
+
terrainVisibleAt?: number;
|
|
26
|
+
/** Display blend saved for exact terrain query snapshots. */
|
|
27
|
+
declare terrainBlend?: number;
|
|
28
|
+
/** Next automatically assigned mesh identifier. */
|
|
29
|
+
declare static id: number;
|
|
30
|
+
declare gl: MeshContext | null;
|
|
31
|
+
declare vertex_data?: MeshVertexData;
|
|
32
|
+
declare element_data?: MeshElementData;
|
|
33
|
+
declare vertex_layout: MeshVertexLayout;
|
|
34
|
+
declare id: string | number;
|
|
35
|
+
declare buffer_factory: MeshOptions['bufferFactory'];
|
|
36
|
+
declare vertex_buffer_resource: Buffer | null;
|
|
37
|
+
declare element_buffer_resource?: Buffer | null;
|
|
38
|
+
declare vertex_buffer: Buffer | WebGLBuffer | null;
|
|
39
|
+
declare element_buffer?: Buffer | WebGLBuffer | null;
|
|
40
|
+
declare draw_mode: number;
|
|
41
|
+
declare data_usage: number | null;
|
|
42
|
+
declare vertices_per_geometry: number;
|
|
43
|
+
declare uniforms: MeshOptions['uniforms'];
|
|
44
|
+
declare textures: MeshOptions['textures'];
|
|
45
|
+
declare retain: boolean;
|
|
46
|
+
declare fade_in_time: number;
|
|
47
|
+
declare globe_refinement_error: string | undefined;
|
|
48
|
+
declare vertex_count: number;
|
|
49
|
+
declare element_count: number;
|
|
50
|
+
declare element_type: number;
|
|
51
|
+
declare vaos: MeshVertexArrays;
|
|
52
|
+
declare toggle_element_array: boolean;
|
|
53
|
+
declare valid: boolean;
|
|
54
|
+
|
|
55
|
+
/** Vertex/index allocation bytes, excluding textures and projection-specific child meshes. */
|
|
56
|
+
declare buffer_size: number;
|
|
57
|
+
|
|
58
|
+
/** Triangle count of the original planar mesh. */
|
|
59
|
+
geometry_count: number;
|
|
60
|
+
/** Shared fade origin for planar and globe variants. */
|
|
61
|
+
created_at: number;
|
|
62
|
+
/** Lazily allocated globe buffers, owned by this mesh. */
|
|
63
|
+
globe_mesh?: VBOMesh | null;
|
|
64
|
+
/** Immutable coarse tile data, released once refinement completes. */
|
|
65
|
+
globe_source?: {
|
|
66
|
+
vertices: MeshVertexData;
|
|
67
|
+
indices: MeshElementData;
|
|
68
|
+
options: MeshOptions & {globeRefinement: GlobeMeshOptions};
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
constructor(gl: MeshContext | null, vertex_data: MeshVertexData, element_data: MeshElementData, vertex_layout: MeshVertexLayout, options?: MeshOptions) {
|
|
72
|
+
options = options || {};
|
|
73
|
+
|
|
74
|
+
this.gl = gl;
|
|
75
|
+
this.vertex_data = vertex_data; // typed array
|
|
76
|
+
this.element_data = element_data; // typed array
|
|
77
|
+
this.vertex_layout = vertex_layout;
|
|
78
|
+
this.id = options.id != null ? options.id : VBOMesh.id++;
|
|
79
|
+
this.buffer_factory = options.bufferFactory;
|
|
80
|
+
this.vertex_buffer_resource = createBufferResource(this.buffer_factory, {
|
|
81
|
+
id: `mesh-${this.id}-vertices`,
|
|
82
|
+
usage: 'vertex',
|
|
83
|
+
data: this.vertex_data
|
|
84
|
+
});
|
|
85
|
+
this.vertex_buffer = this.vertex_buffer_resource || this.gl!.createBuffer();
|
|
86
|
+
this.buffer_size = this.vertex_data.byteLength;
|
|
87
|
+
this.draw_mode = options.draw_mode || 0x0004;
|
|
88
|
+
this.data_usage = options.data_usage || (this.vertex_buffer_resource ? null : this.gl!.STATIC_DRAW);
|
|
89
|
+
this.vertices_per_geometry = 3; // TODO: support lines, strip, fan, etc.
|
|
90
|
+
this.uniforms = options.uniforms;
|
|
91
|
+
this.textures = options.textures; // any textures owned by this mesh
|
|
92
|
+
this.retain = options.retain || false; // whether to retain mesh data in CPU after uploading to GPU
|
|
93
|
+
this.created_at = +new Date();
|
|
94
|
+
this.fade_in_time = options.fade_in_time || 0; // optional time to fade in mesh
|
|
95
|
+
this.globe_refinement_error = options.globeRefinementError;
|
|
96
|
+
// Only coarse, immutable triangle meshes need a second projection-specific buffer.
|
|
97
|
+
if (options.globeRefinement && options.globeRefinement.tileZoom < 7 &&
|
|
98
|
+
this.draw_mode === 0x0004 && !this.retain) {
|
|
99
|
+
this.globe_source = {vertices: vertex_data, indices: element_data, options: options as MeshOptions & {globeRefinement: GlobeMeshOptions}};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
this.vertex_count = this.vertex_data.byteLength / this.vertex_layout.stride;
|
|
103
|
+
this.element_count = 0;
|
|
104
|
+
this.vaos = {}; // map of VertexArrayObjects, keyed by program
|
|
105
|
+
|
|
106
|
+
this.toggle_element_array = false;
|
|
107
|
+
if (this.element_data) {
|
|
108
|
+
this.toggle_element_array = true;
|
|
109
|
+
this.element_count = this.element_data.length;
|
|
110
|
+
this.geometry_count = this.element_count / this.vertices_per_geometry;
|
|
111
|
+
this.element_type = (this.element_data.constructor === Uint16Array) ? 0x1403 : 0x1405;
|
|
112
|
+
try {
|
|
113
|
+
this.element_buffer_resource = createBufferResource(this.buffer_factory, {
|
|
114
|
+
id: `mesh-${this.id}-indices`,
|
|
115
|
+
usage: 'index',
|
|
116
|
+
indexType: this.element_data.constructor === Uint16Array ? 'uint16' : 'uint32',
|
|
117
|
+
data: this.element_data
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
if (this.vertex_buffer_resource) {
|
|
122
|
+
this.vertex_buffer_resource.destroy();
|
|
123
|
+
this.vertex_buffer_resource = null;
|
|
124
|
+
}
|
|
125
|
+
throw error;
|
|
126
|
+
}
|
|
127
|
+
this.element_buffer = this.element_buffer_resource || this.gl!.createBuffer();
|
|
128
|
+
this.buffer_size += this.element_data.byteLength;
|
|
129
|
+
if (!this.element_buffer_resource) {
|
|
130
|
+
this.gl!.bindBuffer(this.gl!.ELEMENT_ARRAY_BUFFER, this.element_buffer as WebGLBuffer | null);
|
|
131
|
+
this.gl!.bufferData(this.gl!.ELEMENT_ARRAY_BUFFER, this.element_data, this.data_usage!);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
this.geometry_count = this.vertex_count / this.vertices_per_geometry;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (!this.vertex_buffer_resource) {
|
|
139
|
+
this.upload();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (!this.retain) {
|
|
143
|
+
delete this.vertex_data;
|
|
144
|
+
delete this.element_data;
|
|
145
|
+
}
|
|
146
|
+
this.valid = true;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Render, by default with currently bound program, or otherwise with optionally provided one
|
|
150
|
+
// Returns true if mesh requests a render on next frame (e.g. for fade animations)
|
|
151
|
+
render(options: MeshRenderOptions = {}): boolean {
|
|
152
|
+
if (!this.valid) {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (options.projection === 'globe') {
|
|
157
|
+
if (this.globe_refinement_error) {
|
|
158
|
+
throw new Error(this.globe_refinement_error);
|
|
159
|
+
}
|
|
160
|
+
if (this.globe_source && this.globe_mesh === undefined) {
|
|
161
|
+
const {vertices, indices, options: meshOptions} = this.globe_source;
|
|
162
|
+
const refined = refineGlobeMesh(vertices as Uint8Array, indices as Uint16Array | Uint32Array | false,
|
|
163
|
+
this.vertex_layout as MeshVertexLayout & {dynamic_attribs: NonNullable<MeshVertexLayout['dynamic_attribs']>}, meshOptions.globeRefinement);
|
|
164
|
+
this.globe_mesh = refined.vertices === vertices ? null : new VBOMesh(
|
|
165
|
+
this.gl, refined.vertices, refined.indices, this.vertex_layout,
|
|
166
|
+
{...meshOptions, id: undefined, globeRefinement: undefined, textures: undefined}
|
|
167
|
+
);
|
|
168
|
+
if (this.globe_mesh) {
|
|
169
|
+
this.globe_mesh.created_at = this.created_at;
|
|
170
|
+
}
|
|
171
|
+
// A completed refinement no longer needs the duplicate CPU data.
|
|
172
|
+
delete this.globe_source;
|
|
173
|
+
}
|
|
174
|
+
if (this.globe_mesh) {
|
|
175
|
+
return this.globe_mesh.render(options);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
var program: MeshProgram = (options.program || ShaderProgram.current)!;
|
|
180
|
+
let visible_time = (+new Date() - this.created_at) / 1000;
|
|
181
|
+
if (options.meshRenderer && typeof options.meshRenderer.drawMesh === 'function') {
|
|
182
|
+
const needs_redraw = options.meshRenderer.drawMesh({
|
|
183
|
+
mesh: this,
|
|
184
|
+
program,
|
|
185
|
+
renderPass: options.renderPass!,
|
|
186
|
+
renderState: options.renderState,
|
|
187
|
+
visibleTime: visible_time
|
|
188
|
+
});
|
|
189
|
+
if (needs_redraw !== null) {
|
|
190
|
+
return Boolean(needs_redraw) || visible_time < this.fade_in_time;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
program.use(options.meshRenderer ? { bindUniformBlocks: true } : undefined);
|
|
195
|
+
|
|
196
|
+
if (this.uniforms) {
|
|
197
|
+
program.saveUniforms(this.uniforms);
|
|
198
|
+
program.setUniforms(this.uniforms, false); // don't reset texture unit
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
program.uniform('1f', 'u_visible_time', visible_time);
|
|
202
|
+
|
|
203
|
+
this.bind(program);
|
|
204
|
+
|
|
205
|
+
if (this.toggle_element_array){
|
|
206
|
+
this.gl!.drawElements(this.draw_mode, this.element_count, this.element_type, 0);
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
this.gl!.drawArrays(this.draw_mode, 0, this.vertex_count);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
VertexArrayObject.bind(this.gl!, null);
|
|
213
|
+
|
|
214
|
+
if (this.uniforms) {
|
|
215
|
+
program.restoreUniforms(this.uniforms);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Request next render if mesh is fading in
|
|
219
|
+
return (visible_time < this.fade_in_time);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// Return the renderer-independent resources and draw parameters for this mesh.
|
|
223
|
+
getDrawDescriptor(): TangramMeshDrawDescriptor & {indexType: 'uint16' | 'uint32' | null} {
|
|
224
|
+
return {
|
|
225
|
+
topology: getTopology(this.draw_mode),
|
|
226
|
+
vertexCount: this.vertex_count,
|
|
227
|
+
indexCount: this.element_count,
|
|
228
|
+
indexType: this.toggle_element_array ?
|
|
229
|
+
(this.element_type === 0x1403 ? 'uint16' : 'uint32') : null,
|
|
230
|
+
vertexBuffer: this.vertex_buffer_resource,
|
|
231
|
+
indexBuffer: this.element_buffer_resource || null,
|
|
232
|
+
bufferLayout: this.vertex_layout.getBufferLayout(),
|
|
233
|
+
staticAttributes: this.vertex_layout.getStaticAttributes()
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// Bind buffers and vertex attributes to prepare for rendering
|
|
238
|
+
bind(program: MeshProgram): void {
|
|
239
|
+
// Bind VAO for this progam, or create one
|
|
240
|
+
let vao = this.vaos[program.id];
|
|
241
|
+
if (vao) {
|
|
242
|
+
VertexArrayObject.bind(this.gl!, vao);
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
this.vaos[program.id] = VertexArrayObject.create(this.gl!, () => {
|
|
246
|
+
this.gl!.bindBuffer(this.gl!.ARRAY_BUFFER, this.vertex_buffer as WebGLBuffer | null);
|
|
247
|
+
if (this.toggle_element_array) {
|
|
248
|
+
this.gl!.bindBuffer(this.gl!.ELEMENT_ARRAY_BUFFER, this.element_buffer as WebGLBuffer | null);
|
|
249
|
+
}
|
|
250
|
+
this.vertex_layout.enableDynamicAttributes!(this.gl!, program);
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
this.vertex_layout.enableStaticAttributes!(this.gl!, program);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// Upload buffer data to GPU
|
|
258
|
+
upload(): void {
|
|
259
|
+
if (this.vertex_buffer_resource) {
|
|
260
|
+
if (typeof this.vertex_buffer_resource.write !== 'function') {
|
|
261
|
+
throw new Error('VBOMesh: portable vertex buffers must support write');
|
|
262
|
+
}
|
|
263
|
+
this.vertex_buffer_resource.write(this.vertex_data!);
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
this.gl!.bindBuffer(this.gl!.ARRAY_BUFFER, this.vertex_buffer as WebGLBuffer | null);
|
|
267
|
+
this.gl!.bufferData(this.gl!.ARRAY_BUFFER, this.vertex_data!, this.data_usage!);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
destroy(): boolean {
|
|
271
|
+
this.terrainQueryMesh = undefined;
|
|
272
|
+
if (!this.valid) {
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
this.valid = false;
|
|
276
|
+
try {
|
|
277
|
+
notifyGPUResourceDisposal(this);
|
|
278
|
+
}
|
|
279
|
+
finally {
|
|
280
|
+
this.globe_mesh?.destroy();
|
|
281
|
+
this.globe_mesh = null;
|
|
282
|
+
delete this.globe_source;
|
|
283
|
+
|
|
284
|
+
for (let v in this.vaos) {
|
|
285
|
+
VertexArrayObject.destroy(this.gl!, this.vaos[v]);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
if (this.vertex_buffer_resource) {
|
|
289
|
+
this.vertex_buffer_resource.destroy();
|
|
290
|
+
this.vertex_buffer_resource = null;
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
this.gl!.deleteBuffer(this.vertex_buffer as WebGLBuffer | null);
|
|
294
|
+
}
|
|
295
|
+
this.vertex_buffer = null;
|
|
296
|
+
|
|
297
|
+
if (this.element_buffer) {
|
|
298
|
+
if (this.element_buffer_resource) {
|
|
299
|
+
this.element_buffer_resource.destroy();
|
|
300
|
+
this.element_buffer_resource = null;
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
this.gl!.deleteBuffer(this.element_buffer as WebGLBuffer | null);
|
|
304
|
+
}
|
|
305
|
+
this.element_buffer = null;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
delete this.vertex_data;
|
|
309
|
+
delete this.element_data;
|
|
310
|
+
|
|
311
|
+
if (this.textures) {
|
|
312
|
+
this.textures.forEach(t => Texture.release(t));
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
return true;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
VBOMesh.id = 0;
|
|
322
|
+
|
|
323
|
+
function createBufferResource(buffer_factory: MeshOptions['bufferFactory'], options: TangramMeshBufferOptions): Buffer | null {
|
|
324
|
+
if (typeof buffer_factory !== 'function') {
|
|
325
|
+
return null;
|
|
326
|
+
}
|
|
327
|
+
const resource = buffer_factory(options);
|
|
328
|
+
if (!resource || typeof resource.destroy !== 'function') {
|
|
329
|
+
throw new Error('VBOMesh: bufferFactory must return a GPU resource with destroy');
|
|
330
|
+
}
|
|
331
|
+
return resource;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function getTopology(draw_mode: number): PrimitiveTopology {
|
|
335
|
+
switch (draw_mode) {
|
|
336
|
+
case 0x0000:
|
|
337
|
+
return 'point-list';
|
|
338
|
+
case 0x0001:
|
|
339
|
+
return 'line-list';
|
|
340
|
+
case 0x0003:
|
|
341
|
+
return 'line-strip';
|
|
342
|
+
case 0x0004:
|
|
343
|
+
return 'triangle-list';
|
|
344
|
+
case 0x0005:
|
|
345
|
+
return 'triangle-strip';
|
|
346
|
+
default:
|
|
347
|
+
throw new Error(`VBOMesh: unsupported draw mode ${draw_mode}`);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// tangram-layers
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
/** Packed signed-short height units per physical meter, shared by builders and optional projection workers. */
|
|
6
|
+
export const PACKED_HEIGHT_SCALE = 16;
|
|
7
|
+
|
|
8
|
+
/** Validate physical annotation meters before signed-short storage can silently wrap. */
|
|
9
|
+
export function packProjectedAnnotationHeight(height: unknown, allowElevation = false): number {
|
|
10
|
+
const meters = height ?? 0;
|
|
11
|
+
if (typeof meters !== 'number' || !Number.isFinite(meters)) {
|
|
12
|
+
throw new Error('Projected annotation height must be finite meters');
|
|
13
|
+
}
|
|
14
|
+
if (meters !== 0 && !allowElevation) throw new Error('Projected symbols require ground anchors unless allowElevation is enabled');
|
|
15
|
+
if (meters < -32768 / PACKED_HEIGHT_SCALE || meters > 32767 / PACKED_HEIGHT_SCALE) {
|
|
16
|
+
throw new Error('Projected annotation height exceeds signed-short storage');
|
|
17
|
+
}
|
|
18
|
+
return Math.trunc(meters * PACKED_HEIGHT_SCALE);
|
|
19
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// tangram-layers
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {BufferLayout, VertexFormat} from '@luma.gl/core';
|
|
6
|
+
|
|
7
|
+
/** Numeric views used to pack Tangram's heterogeneous interleaved vertex data. */
|
|
8
|
+
export type VertexArray = Float32Array | Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array;
|
|
9
|
+
/** Views of the same backing allocation indexed by legacy GL component type. */
|
|
10
|
+
export type VertexBufferViews = Record<number, VertexArray>;
|
|
11
|
+
/** Generated writer preserving component offsets and packed conversion semantics. */
|
|
12
|
+
export type AddVertexFunction = (vertex: number[], views: VertexBufferViews, offset: number) => void;
|
|
13
|
+
/** Authored attribute plus the offsets populated by VertexLayout construction. */
|
|
14
|
+
export interface VertexAttribute {
|
|
15
|
+
name: string;
|
|
16
|
+
size: number;
|
|
17
|
+
type: number;
|
|
18
|
+
normalized?: boolean;
|
|
19
|
+
static?: number | number[] | null;
|
|
20
|
+
offset?: number;
|
|
21
|
+
byte_size?: number;
|
|
22
|
+
method?: `vertexAttrib${1 | 2 | 3 | 4}fv`;
|
|
23
|
+
}
|
|
24
|
+
/** Portable layout returned after all dynamic attribute offsets are assigned. */
|
|
25
|
+
export type VertexBufferLayout = BufferLayout & {
|
|
26
|
+
attributes: {attribute: string; format: VertexFormat; byteOffset: number}[];
|
|
27
|
+
};
|
|
28
|
+
/** Shader-side attribute lookup consumed by the classic binding path. */
|
|
29
|
+
export interface VertexAttributeProgram {
|
|
30
|
+
attribute(name: string): {location: number} | undefined;
|
|
31
|
+
}
|
|
32
|
+
/** Classic WebGL operations consumed by layouts; portable devices bypass this surface. */
|
|
33
|
+
export type VertexAttributeContext = Pick<WebGLRenderingContext,
|
|
34
|
+
'enableVertexAttribArray' | 'disableVertexAttribArray' | 'vertexAttribPointer'> &
|
|
35
|
+
Partial<Record<`vertexAttrib${1 | 2 | 3 | 4}fv`, (location: number, value: number[]) => void>>;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// Tangram
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) 2013-2016 Brett Camper and Mapzen
|
|
4
|
+
// Copyright (c) 2026 vis.gl contributors
|
|
5
|
+
|
|
6
|
+
import gl from './constants'; // web workers don't have access to GL context, so import all GL constants
|
|
7
|
+
import log from '../utils/log';
|
|
8
|
+
import VertexElements from './vertex_elements';
|
|
9
|
+
import type {VertexAttribute, AddVertexFunction, VertexBufferViews} from './vertex-types';
|
|
10
|
+
|
|
11
|
+
type VertexLayoutLike = {
|
|
12
|
+
stride: number;
|
|
13
|
+
index: Record<string, number>;
|
|
14
|
+
dynamic_attribs: VertexAttribute[];
|
|
15
|
+
getAddVertexFunction(): AddVertexFunction;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// Maps GL types to JS array types
|
|
19
|
+
let array_types = {
|
|
20
|
+
[gl.FLOAT]: Float32Array,
|
|
21
|
+
[gl.BYTE]: Int8Array,
|
|
22
|
+
[gl.UNSIGNED_BYTE]: Uint8Array,
|
|
23
|
+
[gl.INT]: Int32Array,
|
|
24
|
+
[gl.UNSIGNED_INT]: Uint32Array,
|
|
25
|
+
[gl.SHORT]: Int16Array,
|
|
26
|
+
[gl.UNSIGNED_SHORT]: Uint16Array
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// An intermediary object that holds vertex data in typed arrays, according to a given vertex layout
|
|
30
|
+
// Used to construct a mesh/VBO for rendering
|
|
31
|
+
export default class VertexData {
|
|
32
|
+
|
|
33
|
+
static array_pool: Uint8Array[] = [];
|
|
34
|
+
vertex_layout: VertexLayoutLike;
|
|
35
|
+
vertex_elements: VertexElements;
|
|
36
|
+
stride: number;
|
|
37
|
+
vertex_buffer: Uint8Array;
|
|
38
|
+
element_buffer!: Uint16Array | Uint32Array | false;
|
|
39
|
+
byte_length: number;
|
|
40
|
+
size: number;
|
|
41
|
+
offset: number;
|
|
42
|
+
vertex_count: number;
|
|
43
|
+
realloc_count: number;
|
|
44
|
+
views!: VertexBufferViews;
|
|
45
|
+
vertexLayoutAddVertex!: AddVertexFunction;
|
|
46
|
+
|
|
47
|
+
constructor (vertex_layout: VertexLayoutLike, { prealloc = 500 }: {prealloc?: number} = {}) {
|
|
48
|
+
this.vertex_layout = vertex_layout;
|
|
49
|
+
this.vertex_elements = new VertexElements();
|
|
50
|
+
this.stride = this.vertex_layout.stride;
|
|
51
|
+
|
|
52
|
+
if (VertexData.array_pool.length > 0) {
|
|
53
|
+
this.vertex_buffer = VertexData.array_pool.pop()!;
|
|
54
|
+
this.byte_length = this.vertex_buffer.byteLength;
|
|
55
|
+
this.size = Math.floor(this.byte_length / this.stride);
|
|
56
|
+
log('trace', `VertexData: reused buffer of bytes ${this.byte_length}, ${this.size} vertices`);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
this.size = prealloc; // # of vertices to allocate
|
|
60
|
+
this.byte_length = this.stride * this.size;
|
|
61
|
+
this.vertex_buffer = new Uint8Array(this.byte_length);
|
|
62
|
+
}
|
|
63
|
+
this.offset = 0; // byte offset into currently allocated buffer
|
|
64
|
+
|
|
65
|
+
this.vertex_count = 0;
|
|
66
|
+
this.realloc_count = 0;
|
|
67
|
+
this.setBufferViews();
|
|
68
|
+
this.setAddVertexFunction();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// (Re-)allocate typed views into the main buffer - only create the types we need for this layout
|
|
72
|
+
setBufferViews (): void {
|
|
73
|
+
this.views = {};
|
|
74
|
+
this.views[gl.UNSIGNED_BYTE] = this.vertex_buffer;
|
|
75
|
+
this.vertex_layout.dynamic_attribs.forEach(attrib => {
|
|
76
|
+
// Need view for this type?
|
|
77
|
+
if (this.views[attrib.type] == null) {
|
|
78
|
+
const arrayType = array_types[attrib.type];
|
|
79
|
+
this.views[attrib.type] = new arrayType(this.vertex_buffer.buffer as ArrayBuffer);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Check allocated buffer size, expand/realloc buffer if needed
|
|
85
|
+
checkBufferSize (): void {
|
|
86
|
+
if ((this.offset + this.stride) > this.byte_length) {
|
|
87
|
+
this.size = Math.floor(this.size * 1.5);
|
|
88
|
+
this.size -= this.size % 4;
|
|
89
|
+
this.byte_length = this.stride * this.size;
|
|
90
|
+
var new_view = new Uint8Array(this.byte_length);
|
|
91
|
+
new_view.set(this.vertex_buffer); // copy existing data to new buffer
|
|
92
|
+
VertexData.array_pool.push(this.vertex_buffer); // save previous buffer for use by next tile
|
|
93
|
+
this.vertex_buffer = new_view;
|
|
94
|
+
this.setBufferViews();
|
|
95
|
+
this.realloc_count++;
|
|
96
|
+
// log('info', `VertexData: expanded vertex block to ${this.size} vertices`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Initialize the add vertex function (lazily compiled by vertex layout)
|
|
101
|
+
setAddVertexFunction (): void {
|
|
102
|
+
this.vertexLayoutAddVertex = this.vertex_layout.getAddVertexFunction();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Add a vertex, copied from a plain JS array of elements matching the order of the vertex layout
|
|
106
|
+
addVertex (vertex: number[]): void {
|
|
107
|
+
this.checkBufferSize();
|
|
108
|
+
this.vertexLayoutAddVertex(vertex, this.views, this.offset);
|
|
109
|
+
this.offset += this.stride;
|
|
110
|
+
this.vertex_count++;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Finalize vertex buffer for use in constructing a mesh
|
|
114
|
+
end (): this {
|
|
115
|
+
// Clip the buffer to size used for this VBO
|
|
116
|
+
this.vertex_buffer = this.vertex_buffer.subarray(0, this.offset);
|
|
117
|
+
this.element_buffer = this.vertex_elements.end();
|
|
118
|
+
|
|
119
|
+
log('trace', `VertexData: ${this.size} vertices total, realloc count ${this.realloc_count}`);
|
|
120
|
+
|
|
121
|
+
return this;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Pool of currently available (previously used) buffers (uint8).
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Tangram
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) 2013-2016 Brett Camper and Mapzen
|
|
4
|
+
// Copyright (c) 2026 vis.gl contributors
|
|
5
|
+
|
|
6
|
+
let MAX_VALUE = Math.pow(2, 16) - 1;
|
|
7
|
+
let has_element_index_uint = false;
|
|
8
|
+
|
|
9
|
+
export default class VertexElements {
|
|
10
|
+
static setElementIndexUint: (flag: boolean) => void;
|
|
11
|
+
array: number[];
|
|
12
|
+
has_overflown: boolean;
|
|
13
|
+
|
|
14
|
+
constructor () {
|
|
15
|
+
this.array = [];
|
|
16
|
+
this.has_overflown = false;
|
|
17
|
+
}
|
|
18
|
+
push (value: number): void {
|
|
19
|
+
// If values have overflown and no Uint32 option is available, do not push values
|
|
20
|
+
if (this.has_overflown && !has_element_index_uint) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Trigger overflow if value is greater than Uint16 max
|
|
25
|
+
if (value > MAX_VALUE) {
|
|
26
|
+
this.has_overflown = true;
|
|
27
|
+
if (!has_element_index_uint) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
this.array.push(value);
|
|
33
|
+
}
|
|
34
|
+
end (): Uint16Array | Uint32Array | false {
|
|
35
|
+
if (this.array.length){
|
|
36
|
+
let buffer = createBuffer(this.array, this.has_overflown);
|
|
37
|
+
this.array = [];
|
|
38
|
+
this.has_overflown = false;
|
|
39
|
+
return buffer;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
VertexElements.setElementIndexUint = function(flag: boolean): void {
|
|
48
|
+
has_element_index_uint = flag;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
function createBuffer(array: number[], overflown: boolean): Uint16Array | Uint32Array {
|
|
52
|
+
var typedArray = (overflown && has_element_index_uint) ? Uint32Array : Uint16Array;
|
|
53
|
+
return new typedArray(array);
|
|
54
|
+
}
|