UNPKG

s2maps-gpu

Version:

S2 Maps GPU - An open source, high-performance, and GPU-accelerated map engine for rendering large-scale, interactive maps.

128 lines (127 loc) 5.72 kB
import type { BBox } from 'gis-tools/index.js'; import type { GlyphData } from 'workers/worker.spec.js'; import type { TileGPU as Tile } from 'source/tile.spec.js'; import type { WebGPUContext } from '../context/index.js'; import type { GlyphDefinition, GlyphStyle, GlyphWorkflowLayerGuideGPU, LayerDefinitionBase } from 'style/style.spec.js'; import type { GlyphFeature as GlyphFeatureSpec, GlyphSource, GlyphWorkflow as GlyphWorkflowSpec } from './workflow.spec.js'; /** Glyph Feature is a standalone glyph render storage unit that can be drawn to the GPU */ export declare class GlyphFeature implements GlyphFeatureSpec { #private; workflow: GlyphWorkflowSpec; source: GlyphSource; tile: Tile; layerGuide: GlyphWorkflowLayerGuideGPU; count: number; offset: number; filterCount: number; filterOffset: number; isPath: boolean; isIcon: boolean; featureCode: number[]; glyphUniformBuffer: GPUBuffer; glyphBoundsBuffer: GPUBuffer; glyphAttributeBuffer: GPUBuffer; glyphAttributeNoStrokeBuffer: GPUBuffer; featureCodeBuffer: GPUBuffer; parent?: Tile | undefined; type: "glyph"; bindGroup: GPUBindGroup; glyphBindGroup: GPUBindGroup; glyphStrokeBindGroup: GPUBindGroup; glyphFilterBindGroup: GPUBindGroup; glyphInteractiveBindGroup: GPUBindGroup; /** * @param workflow - the glyph workflow * @param source - the glyph source * @param tile - the tile this feature is drawn on * @param layerGuide - the layer guide for this feature * @param count - the number of glyphs * @param offset - the offset of the glyphs * @param filterCount - the number of filter glyphs * @param filterOffset - the offset of the filter glyphs * @param isPath - whether the feature is a path or a point * @param isIcon - whether the feature is an icon or a standard glyph * @param featureCode - the encoded feature code * @param glyphUniformBuffer - the glyph uniform buffer * @param glyphBoundsBuffer - the glyph bounds buffer * @param glyphAttributeBuffer - the glyph attribute buffer * @param glyphAttributeNoStrokeBuffer - the glyph attribute buffer * @param featureCodeBuffer - the encoded feature code that tells the GPU how to compute it's properties * @param parent - the parent tile if applicable */ constructor(workflow: GlyphWorkflowSpec, source: GlyphSource, tile: Tile, layerGuide: GlyphWorkflowLayerGuideGPU, count: number, offset: number, filterCount: number, filterOffset: number, isPath: boolean, isIcon: boolean, featureCode: number[], glyphUniformBuffer: GPUBuffer, glyphBoundsBuffer: GPUBuffer, glyphAttributeBuffer: GPUBuffer, glyphAttributeNoStrokeBuffer: GPUBuffer, featureCodeBuffer: GPUBuffer, parent?: Tile | undefined); /** Draw this feature */ draw(): void; /** Compute the feature's interactivity with the mouse */ compute(): void; /** Update the shared texture's bind groups */ updateSharedTexture(): void; /** Destroy and cleanup the feature */ destroy(): void; /** * Duplicate the feature * @param tile - the tile this feature is drawn on * @param parent - the parent tile if applicable * @param bounds - the bounds of the tile if applicable * @returns the duplicated feature */ duplicate(tile: Tile, parent?: Tile, bounds?: BBox): GlyphFeature; } /** Glyph Workflow */ export default class GlyphWorkflow implements GlyphWorkflowSpec { #private; context: WebGPUContext; module: GPUShaderModule; layerGuides: Map<number, GlyphWorkflowLayerGuideGPU>; pipeline: GPURenderPipeline; pipelineC: GPURenderPipeline; testRenderPipeline: GPURenderPipeline; testCircleRenderPipeline: GPURenderPipeline; bboxPipeline: GPUComputePipeline; circlePipeline: GPUComputePipeline; testFiltersPipeline: GPUComputePipeline; testCirclePipeline: GPUComputePipeline; interactivePipeline: GPUComputePipeline; glyphBindGroupLayout: GPUBindGroupLayout; glyphPipelineLayout: GPUPipelineLayout; glyphFilterBindGroupLayout: GPUBindGroupLayout; glyphFilterPipelineLayout: GPUPipelineLayout; glyphInteractiveBindGroupLayout: GPUBindGroupLayout; glyphInteractivePiplineLayout: GPUPipelineLayout; glyphBBoxesBuffer: GPUBuffer; glyphFilterResultBuffer: GPUBuffer; /** @param context - The WebGPU context */ constructor(context: WebGPUContext); /** Setup the workflow */ setup(): Promise<void>; /** Destroy and cleanup the workflow */ destroy(): void; /** * Build the layer definition for this workflow * @param layerBase - the common layer attributes * @param layer - the user defined layer attributes * @returns a built layer definition that's ready to describe how to render a feature */ buildLayerDefinition(layerBase: LayerDefinitionBase, layer: GlyphStyle): GlyphDefinition; /** * Build the source glyph data into glyph features * @param glyphData - the input glyph data * @param tile - the tile we are building the features for */ buildSource(glyphData: GlyphData, tile: Tile): void; /** * Compute the glyph filters to see which glyphs to render * @param features - the glyphs filter data to compute */ computeFilters(features: GlyphFeatureSpec[]): void; /** * Compute the interactive glyph features to see which ones interact with the mouse * @param feature - glyph feature guide */ computeInteractive(feature: GlyphFeatureSpec): void; /** * Draw the glyph feature * @param feature - glyph feature guide */ draw(feature: GlyphFeatureSpec): void; }