UNPKG

s2maps-gpu

Version:

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

93 lines (92 loc) 3.62 kB
/** CONTEXTS */ import { WebGL2Context, WebGLContext } from './context/index.js'; import type { ColorMode } from 's2/s2Map.js'; import type { GlyphImages } from 'workers/source/glyphSource.js'; import type { MapOptions } from 'ui/s2mapUI.js'; import type { Painter as PainterSpec } from './painter.spec.js'; import type { Projector } from 'ui/camera/projector/index.js'; import type { TileGL as Tile } from 'source/tile.spec.js'; import type TimeCache from 'ui/camera/timeCache.js'; import type { VectorPoint } from 'gis-tools/index.js'; import type { WorkflowKey, WorkflowType, Workflows } from './workflows/workflow.spec.js'; import type { PainterData, SpriteImageMessage } from 'workers/worker.spec.js'; /** * # WebGL(1|2) Painter * * ## Description * A painter for WebGL(1|2) contexts */ export default class Painter implements PainterSpec { context: WebGL2Context | WebGLContext; workflows: Workflows; curWorkflow?: WorkflowKey; dirty: boolean; /** * @param context - a WebGL(1|2) context wrapper * @param type - 1 for WebGL 1, 2 for WebGL 2 * @param options - map options to pull out the options that impact the painter and GPU */ constructor(context: WebGL2RenderingContext | WebGLRenderingContext, type: 1 | 2, options: MapOptions); /** called once to properly prepare the context */ prepare(): Promise<void>; /** * Given a tile, build the feature data associated with it * @param tile - the tile to inject the features into * @param data - the collection of data to sift through and build features */ buildFeatureData(tile: Tile, data: PainterData): void; /** * Build all workflows used by the style layers * @param buildSet - the set of workflows to build */ buildWorkflows(buildSet: Set<WorkflowType>): Promise<void>; /** * Inject frame uniforms. WebGL requires uniforms to be update before each draw * @param matrix - the projection matrix * @param view - the view matrix * @param aspect - the canvas aspect ratio */ injectFrameUniforms(matrix: Float32Array, view: Float32Array, aspect: VectorPoint): void; /** * Inject a time cache for the sensor workflow * @param timeCache - the time cache to inject */ injectTimeCache(timeCache: TimeCache): void; /** * Resize the canvas * @param _width - new width * @param _height - new height */ resize(_width: number, _height: number): void; /** * Paint all the tiles in view * @param projector - the camera and what it currently sees * @param tiles - all the tiles in view to paint */ paint(projector: Projector, tiles: Tile[]): void; /** * Compute the interactive features in current view * @param tiles - current view tiles that we need to sift through for interactive features */ computeInteractive(tiles: Tile[]): void; /** @returns a Uint8ClampedArray of the current screen */ getScreen(): Promise<Uint8ClampedArray>; /** * Inject a glyph image to the GPU * @param maxHeight - the maximum height of the texture * @param images - the glyph images */ injectGlyphImages(maxHeight: number, images: GlyphImages): void; /** * Inject a sprite image to the GPU * @param data - the raw image data of the sprite */ injectSpriteImage(data: SpriteImageMessage): void; /** * Set the colorblind mode * @param mode - colorblind mode to set */ setColorMode(mode: ColorMode): void; /** Delete the GPU and painter instance */ delete(): void; }