UNPKG

s2maps-gpu

Version:

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

148 lines (147 loc) 5.33 kB
import type { ColorMode } from 's2/s2Map.js'; import type Context from '../context/context.js'; import type { TileGL as Tile } from 'source/tile.spec.js'; import type { AttributeLocations, Attributes, FeatureBase, LayerGuides, ShaderSource, Uniforms, Workflow as WorkflowFeature, WorkflowSpec } from './workflow.spec.js'; import type { BBox, VectorPoint } from 'gis-tools/index.js'; /** A Generic Feature that can be drawn to the GPU */ export declare class Feature implements FeatureBase { workflow: WorkflowFeature; tile: Tile; layerGuide: LayerGuides; featureCode: number[]; parent?: Tile | undefined; bounds?: BBox | undefined; /** * @param workflow - the input workflow * @param tile - the tile that the feature is drawn on * @param layerGuide - the layer guide * @param featureCode - the feature code that tells the GPU how to compute it's properties * @param parent - the parent tile if applicable * @param bounds - the bounds of the tile if applicable */ constructor(workflow: WorkflowFeature, tile: Tile, layerGuide: LayerGuides, featureCode?: number[], parent?: Tile | undefined, bounds?: BBox | undefined); /** * Draw the feature to the GPU * @param interactive - whether or not the feature is interactive */ draw(interactive?: boolean): void; /** Destroy the feature */ destroy(): void; } /** Generic Workflow used by most workflows */ export default class Workflow implements WorkflowSpec { vertexShader: WebGLShader; fragmentShader: WebGLShader; radii: boolean; context: Context; gl: WebGLRenderingContext | WebGL2RenderingContext; type: 1 | 2; glProgram: WebGLProgram; updateColorBlindMode: null | ColorMode; updateMatrix: null | Float32Array; updateInputs: null | Float32Array; updateAspect: null | VectorPoint; curLayer: number; curMode: number; curTile: bigint; LCH?: boolean; interactive?: boolean; uniforms: Record<string, WebGLUniformLocation>; /** * @param context - the context to use that tracks the GPU state */ constructor(context: Context); /** * @param vertex - the vertex shader * @param fragment - the fragment shader * @param attributeLocations - the attribute locations */ buildShaders(vertex: ShaderSource, fragment: ShaderSource, attributeLocations?: AttributeLocations): void; /** * Setup the connections to uniforms in the shader * @param uniforms - the mapping of uniform names to shader names */ setupUniforms(uniforms: Uniforms): void; /** * Setup shader attributes, their names and locations * @param attributes - the mapping of attribute names to shader names * @param attributeLocations - the mapping of attribute names to locations */ setupAttributes(attributes: Attributes, attributeLocations: AttributeLocations): void; /** Delete the workflow and it's shaders */ delete(): void; /** Activate this workflow as the current shaders for the GPU */ use(): void; /** * Inject uniforms that are common to the frame * @param matrix - the projection matrix * @param view - the view matrix * @param aspect - the canvas aspect ratio */ injectFrameUniforms(matrix: Float32Array, view: Float32Array, aspect: VectorPoint): void; /** Flush the uniforms to the GPU */ flush(): void; /** * Setup the tile uniforms * @param tile - the tile * @param parent - the parent tile if applicable */ setTileUniforms(tile: Tile, parent?: Tile): void; /** * Set the device pixel ratio uniform * @param ratio - the device pixel ratio */ setDevicePixelRatio(ratio: number): void; /** * Set the colorblind mode uniform * @param colorMode - the colorblind mode */ setColorBlindMode(colorMode: ColorMode): void; /** * Set the current matrix uniform * @param matrix - the matrix */ setMatrix(matrix: Float32Array): void; /** * Setup basic inputs uniform values * @param inputs - the inputs */ setInputs(inputs: Float32Array): void; /** * Set the canvas aspect uniform values * @param aspect - the aspect */ setAspect(aspect: VectorPoint): void; /** * Set the faceST uniform values * @param faceST - the faceST */ setFaceST(faceST: number[]): void; /** * Set the tile position uniform * @param bottomTop - the tile position */ setTilePos(bottomTop: Float32Array): void; /** * Set the layer code uniform data * @param layerIndex - the layer index * @param layerCode - the encoded layer data * @param lch - whether or not the layer is LCH encoded or RGB */ setLayerCode(layerIndex: number, layerCode: number[], lch?: boolean): void; /** * Set the interactive mode uniform * @param interactive - the interactive mode */ setInteractive(interactive: boolean): void; /** * Set the current feature code * @param featureCode - the feature code */ setFeatureCode(featureCode: number[]): void; /** * Set the curent draw mode (uniform used by the shader) * @param mode - the draw mode */ setMode(mode: number): void; }