@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,241 @@
|
|
|
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 VertexData from './vertex_data';
|
|
8
|
+
import hashString from '../utils/hash';
|
|
9
|
+
import type {VertexFormat} from '@luma.gl/core';
|
|
10
|
+
import type {VertexAttribute, AddVertexFunction, VertexAttributeProgram, VertexAttributeContext, VertexBufferLayout} from './vertex-types';
|
|
11
|
+
type VertexComponent = {type: number; shift: number; offset: number; index: number};
|
|
12
|
+
|
|
13
|
+
// Describes a vertex layout that can be used with many different GL programs.
|
|
14
|
+
export default class VertexLayout {
|
|
15
|
+
static enabled_attribs: Record<string, VertexAttributeProgram> = {};
|
|
16
|
+
static add_vertex_funcs: Record<number, AddVertexFunction> = {};
|
|
17
|
+
attribs: VertexAttribute[];
|
|
18
|
+
dynamic_attribs: VertexAttribute[];
|
|
19
|
+
static_attribs: VertexAttribute[];
|
|
20
|
+
components: VertexComponent[];
|
|
21
|
+
index: Record<string, number>;
|
|
22
|
+
offset: Record<string, number>;
|
|
23
|
+
stride: number;
|
|
24
|
+
addVertex?: AddVertexFunction;
|
|
25
|
+
// Attribs are an array, in layout order, of: name, size, type, normalized
|
|
26
|
+
// ex: { name: 'position', size: 3, type: gl.FLOAT, normalized: false }
|
|
27
|
+
constructor (attribs: VertexAttribute[]) {
|
|
28
|
+
this.attribs = attribs; // array of attributes, specified as standard GL attrib options
|
|
29
|
+
this.dynamic_attribs = this.attribs.filter(x => x.static == null); // attributes with per-vertex values, used to build VBOs
|
|
30
|
+
this.static_attribs = this.attribs.filter(x => x.static != null); // attributes with fixed values
|
|
31
|
+
this.components = []; // list of type and offset info about each attribute component
|
|
32
|
+
this.index = {}; // JS buffer index of each attribute component, e.g. this.index.position
|
|
33
|
+
this.offset = {}; // VBO buffer byte offset of each attribute component, e.g. this.offset.color
|
|
34
|
+
this.stride = 0; // byte stride of a single vertex
|
|
35
|
+
|
|
36
|
+
let index = 0, count = 0;
|
|
37
|
+
for (let a=0; a < this.attribs.length; a++) {
|
|
38
|
+
let attrib = this.attribs[a];
|
|
39
|
+
// Dynamic attribute
|
|
40
|
+
if (attrib.static == null) {
|
|
41
|
+
attrib.offset = this.stride;
|
|
42
|
+
attrib.byte_size = attrib.size;
|
|
43
|
+
let shift = 0;
|
|
44
|
+
|
|
45
|
+
switch (attrib.type) {
|
|
46
|
+
case gl.FLOAT:
|
|
47
|
+
case gl.INT:
|
|
48
|
+
case gl.UNSIGNED_INT:
|
|
49
|
+
attrib.byte_size *= 4;
|
|
50
|
+
shift = 2;
|
|
51
|
+
break;
|
|
52
|
+
case gl.SHORT:
|
|
53
|
+
case gl.UNSIGNED_SHORT:
|
|
54
|
+
attrib.byte_size *= 2;
|
|
55
|
+
shift = 1;
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Force 4-byte alignment on attributes
|
|
60
|
+
if (attrib.byte_size & 3) { // pad to multiple of 4 bytes
|
|
61
|
+
attrib.byte_size += 4 - (attrib.byte_size & 3);
|
|
62
|
+
}
|
|
63
|
+
this.stride += attrib.byte_size;
|
|
64
|
+
|
|
65
|
+
// Add info to list of attribute components (e.g. float is 1 component, vec3 is 3 separate components)
|
|
66
|
+
// Used to map plain JS array to typed arrays
|
|
67
|
+
let offset_typed = attrib.offset >> shift;
|
|
68
|
+
for (let s=0; s < attrib.size; s++) {
|
|
69
|
+
this.components.push({
|
|
70
|
+
type: attrib.type,
|
|
71
|
+
shift,
|
|
72
|
+
offset: offset_typed++,
|
|
73
|
+
index: count++
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Provide an index into the vertex data buffer for each attribute by name
|
|
78
|
+
this.index[attrib.name] = index;
|
|
79
|
+
index += attrib.size;
|
|
80
|
+
|
|
81
|
+
// Store byte offset of each attribute by name
|
|
82
|
+
this.offset[attrib.name] = attrib.offset;
|
|
83
|
+
}
|
|
84
|
+
// Static attribute
|
|
85
|
+
else {
|
|
86
|
+
attrib.static = Array.isArray(attrib.static) ? attrib.static : [attrib.static]; // convert single value to array
|
|
87
|
+
const size = attrib.static.length;
|
|
88
|
+
if (size !== 1 && size !== 2 && size !== 3 && size !== 4) throw new Error('Static vertex attributes require one to four components');
|
|
89
|
+
attrib.method = `vertexAttrib${size}fv`;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Enables dynamic (array-based) attributes for a given GL program
|
|
95
|
+
// Assumes that the desired vertex buffer (VBO) is already bound
|
|
96
|
+
// If the program doesn't include all attributes, it can still use the vertex layout
|
|
97
|
+
// to read those attribs that it does recognize, using the attrib offsets to skip others.
|
|
98
|
+
enableDynamicAttributes (gl: VertexAttributeContext, program: VertexAttributeProgram): void {
|
|
99
|
+
// Disable all attributes
|
|
100
|
+
for (const location in VertexLayout.enabled_attribs) {
|
|
101
|
+
// Object keys are numeric strings; WebGL performs the existing numeric coercion.
|
|
102
|
+
gl.disableVertexAttribArray(location as unknown as number);
|
|
103
|
+
}
|
|
104
|
+
VertexLayout.enabled_attribs = {};
|
|
105
|
+
|
|
106
|
+
// Enable dynamic attributes for this layout
|
|
107
|
+
this.dynamic_attribs.forEach(attrib => {
|
|
108
|
+
const location = program.attribute(attrib.name)?.location ?? -1;
|
|
109
|
+
if (location !== -1) {
|
|
110
|
+
gl.enableVertexAttribArray(location);
|
|
111
|
+
gl.vertexAttribPointer(location, attrib.size, attrib.type, attrib.normalized!, this.stride, attrib.offset!);
|
|
112
|
+
VertexLayout.enabled_attribs[location] = program;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Enable static attributes for this layout. Since these aren't captured as part of Vertex Array Object state,
|
|
118
|
+
// they are enabled separately.
|
|
119
|
+
enableStaticAttributes (gl: VertexAttributeContext, program: VertexAttributeProgram): void {
|
|
120
|
+
this.static_attribs.forEach(attrib => {
|
|
121
|
+
const location = program.attribute(attrib.name)?.location ?? -1;
|
|
122
|
+
if (location !== -1 && gl[attrib.method!] instanceof Function) {
|
|
123
|
+
// N.B.: Safari appears to require an explicit array enable to set vertex attribute as "active"
|
|
124
|
+
// (the static attribute value method does not work without it). So the attribute is temporarily
|
|
125
|
+
// enabled as an array, then disabled.
|
|
126
|
+
gl.enableVertexAttribArray(location);
|
|
127
|
+
gl[attrib.method!]!(location, attrib.static as number[]);
|
|
128
|
+
gl.disableVertexAttribArray(location);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
createVertexData (): VertexData {
|
|
134
|
+
return new VertexData(this);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Return a luma.gl-compatible description of the interleaved vertex buffer.
|
|
138
|
+
// Static attributes are omitted because they are supplied independently of the buffer.
|
|
139
|
+
getBufferLayout (name = 'vertices'): VertexBufferLayout {
|
|
140
|
+
return {
|
|
141
|
+
name,
|
|
142
|
+
byteStride: this.stride,
|
|
143
|
+
attributes: this.dynamic_attribs.map(attrib => ({
|
|
144
|
+
attribute: attrib.name,
|
|
145
|
+
format: getVertexFormat(attrib),
|
|
146
|
+
byteOffset: attrib.offset!
|
|
147
|
+
}))
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Return constant vertex attributes for renderers that don't use Tangram's VAO wrapper.
|
|
152
|
+
getStaticAttributes (): {attribute: string; value: number[]}[] {
|
|
153
|
+
return this.static_attribs.map(attrib => ({
|
|
154
|
+
attribute: attrib.name,
|
|
155
|
+
value: (attrib.static as number[]).slice()
|
|
156
|
+
}));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Lazily create the add vertex function
|
|
160
|
+
getAddVertexFunction (): AddVertexFunction {
|
|
161
|
+
if (this.addVertex == null) {
|
|
162
|
+
this.createAddVertexFunction();
|
|
163
|
+
}
|
|
164
|
+
return this.addVertex!;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Dynamically compile a function to add a plain JS vertex array to this layout's typed VBO arrays
|
|
168
|
+
createAddVertexFunction () {
|
|
169
|
+
const key = hashString(JSON.stringify(this.attribs));
|
|
170
|
+
if (VertexLayout.add_vertex_funcs[key] == null) {
|
|
171
|
+
// `t` = current typed array to write to
|
|
172
|
+
// `o` = current offset into VBO, in current type size (e.g. divide 2 for shorts, divide by 4 for floats, etc.)
|
|
173
|
+
// `v` = plain JS array containing vertex data
|
|
174
|
+
// `vs` = typed arrays (one per GL type needed for this vertex layout)
|
|
175
|
+
// `off` = current offset into VBO, in bytes
|
|
176
|
+
let src: string[] | string = ['var t, o;'];
|
|
177
|
+
|
|
178
|
+
// Sort by array type to reduce redundant array look-up and offset calculation
|
|
179
|
+
let last_type;
|
|
180
|
+
let components = [...this.components];
|
|
181
|
+
components.sort((a, b) => (a.type !== b.type) ? (a.type - b.type) : (a.index - b.index));
|
|
182
|
+
|
|
183
|
+
for (let c=0; c < components.length; c++) {
|
|
184
|
+
let component = components[c];
|
|
185
|
+
|
|
186
|
+
if (last_type !== component.type) {
|
|
187
|
+
src.push(`t = vs[${component.type}];`);
|
|
188
|
+
src.push(`o = off${component.shift ? ' >> ' + component.shift : ''};`);
|
|
189
|
+
last_type = component.type;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
src.push(`t[o + ${component.offset}] = v[${component.index}];`);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
src = src.join('\n');
|
|
196
|
+
const func = new Function('v', 'vs', 'off', src) as AddVertexFunction; // Generated writer follows the component layout above.
|
|
197
|
+
VertexLayout.add_vertex_funcs[key] = func;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
this.addVertex = VertexLayout.add_vertex_funcs[key];
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function getVertexFormat(attrib: VertexAttribute): VertexFormat {
|
|
205
|
+
let type: string;
|
|
206
|
+
switch (attrib.type) {
|
|
207
|
+
case gl.BYTE:
|
|
208
|
+
type = attrib.normalized ? 'snorm8' : 'sint8';
|
|
209
|
+
break;
|
|
210
|
+
case gl.UNSIGNED_BYTE:
|
|
211
|
+
type = attrib.normalized ? 'unorm8' : 'uint8';
|
|
212
|
+
break;
|
|
213
|
+
case gl.SHORT:
|
|
214
|
+
type = attrib.normalized ? 'snorm16' : 'sint16';
|
|
215
|
+
break;
|
|
216
|
+
case gl.UNSIGNED_SHORT:
|
|
217
|
+
type = attrib.normalized ? 'unorm16' : 'uint16';
|
|
218
|
+
break;
|
|
219
|
+
case gl.INT:
|
|
220
|
+
type = 'sint32';
|
|
221
|
+
break;
|
|
222
|
+
case gl.UNSIGNED_INT:
|
|
223
|
+
type = 'uint32';
|
|
224
|
+
break;
|
|
225
|
+
case gl.FLOAT:
|
|
226
|
+
type = 'float32';
|
|
227
|
+
break;
|
|
228
|
+
default:
|
|
229
|
+
throw new Error(`VertexLayout: unsupported attribute type ${attrib.type}`);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (attrib.size === 1) {
|
|
233
|
+
return type as VertexFormat; // The switch restricts the scalar format to luma's supported GL types.
|
|
234
|
+
}
|
|
235
|
+
if (attrib.size < 2 || attrib.size > 4) {
|
|
236
|
+
throw new Error(`VertexLayout: unsupported attribute size ${attrib.size}`);
|
|
237
|
+
}
|
|
238
|
+
const webgl_only = attrib.size === 3 && attrib.type !== gl.FLOAT &&
|
|
239
|
+
attrib.type !== gl.INT && attrib.type !== gl.UNSIGNED_INT;
|
|
240
|
+
return `${type}x${attrib.size}${webgl_only ? '-webgl' : ''}` as VertexFormat; // Validated component size/type above.
|
|
241
|
+
}
|
package/src/glsl.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// tangram-layers
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
declare module '*.glsl' {
|
|
6
|
+
const source: string;
|
|
7
|
+
export default source;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** Vite raw shader assets used by the real-device conformance tests. */
|
|
11
|
+
declare module '*.glsl?raw' {
|
|
12
|
+
const source: string;
|
|
13
|
+
export default source;
|
|
14
|
+
}
|