@itwin/core-frontend
Version:
iTwin.js frontend components
216 lines • 14.7 kB
TypeScript
/** @packageDocumentation
* @module WebGL
*/
import { Dictionary, Id64String } from "@itwin/core-bentley";
import { ElementAlignedBox3d, Frustum, Gradient, ImageSourceFormat, RenderFeatureTable, RenderMaterial, RenderMaterialParams, RenderTexture, RenderTextureParams } from "@itwin/core-common";
import { ClipVector, Point3d, Transform } from "@itwin/core-geometry";
import { Capabilities, WebGLContext } from "@itwin/webgl-compatibility";
import { IModelConnection } from "../../../IModelConnection";
import { MapTileTreeReference, TileTreeReference } from "../../../tile/internal";
import { MeshParams } from "../../../common/internal/render/MeshParams";
import { PointStringParams } from "../../../common/internal/render/PointStringParams";
import { PolylineParams } from "../../../common/internal/render/PolylineParams";
import { TextureCacheKey } from "../../../common/render/TextureParams";
import { ViewRect } from "../../../common/ViewRect";
import { GraphicBranch, GraphicBranchOptions } from "../../../render/GraphicBranch";
import { CustomGraphicBuilderOptions, GraphicBuilder, ViewportGraphicBuilderOptions } from "../../../render/GraphicBuilder";
import { InstancedGraphicParams, PatternGraphicParams } from "../../../common/render/InstancedGraphicParams";
import { MeshMapLayerGraphicParams } from "../MeshMapLayerGraphicParams";
import { PointCloudArgs } from "../../../common/internal/render/PointCloudPrimitive";
import { RenderClipVolume } from "../../../render/RenderClipVolume";
import { RenderGraphic, RenderGraphicOwner } from "../../../render/RenderGraphic";
import { CreateRenderMaterialArgs } from "../../../render/CreateRenderMaterialArgs";
import { RenderMemory } from "../../../render/RenderMemory";
import { RealityMeshParams } from "../../../render/RealityMeshParams";
import { CreateGraphicFromTemplateArgs, PlanarGridProps, RenderInstances, RenderSystem } from "../../../render/RenderSystem";
import { DebugShaderFile, GLTimerResultCallback, RenderDiagnostics, RenderSystemDebugControl } from "../RenderSystemDebugControl";
import { RenderTarget } from "../../../render/RenderTarget";
import { CreateTextureArgs, CreateTextureFromSourceArgs } from "../../../render/CreateTextureArgs";
import { ScreenSpaceEffectBuilder, ScreenSpaceEffectBuilderParams } from "../../../render/ScreenSpaceEffectBuilder";
import { BackgroundMapDrape } from "./BackgroundMapDrape";
import { WebGLDisposable } from "./Disposable";
import { DepthBuffer, FrameBufferStack } from "./FrameBuffer";
import { GL } from "./GL";
import { GLTimer } from "./GLTimer";
import { InstanceBuffers, PatternBuffers } from "./InstancedGeometry";
import { Layer, LayerContainer } from "./Layer";
import { MeshRenderGeometry } from "./Mesh";
import { PointCloudGeometry } from "./PointCloud";
import { PointStringGeometry } from "./PointString";
import { PolylineGeometry } from "./Polyline";
import { RealityMeshGeometry } from "./RealityMesh";
import { TextureUnit } from "./RenderFlags";
import { RenderState } from "./RenderState";
import { ScreenSpaceEffects } from "./ScreenSpaceEffect";
import { Techniques } from "./Technique";
import { TextureHandle } from "./Texture";
import { UniformHandle } from "./UniformHandle";
import { BatchOptions } from "../../../common/render/BatchOptions";
import { RenderGeometry } from "../../../internal/render/RenderGeometry";
import { RenderInstancesParams } from "../../../common/render/RenderInstancesParams";
import { RenderSkyBoxParams } from "../RenderSkyBoxParams";
import { RenderAreaPattern } from "../RenderAreaPattern";
/** @internal */
export declare const enum ContextState {
Uninitialized = 0,
Success = 1,
Error = 2
}
/** Id map holds key value pairs for both materials and textures, useful for caching such objects.
* @internal
*/
export declare class IdMap implements WebGLDisposable {
private readonly _iModel;
/** Mapping of materials by their key values. */
readonly materials: Map<string, RenderMaterial>;
/** Mapping of textures by their key values. */
readonly textures: Map<string, RenderTexture>;
/** Mapping of textures using gradient symbology. */
readonly gradients: Dictionary<Gradient.Symb, RenderTexture>;
/** Pending promises to create a texture from an ImageSource. This prevents us from decoding the same ImageSource multiple times */
readonly texturesFromImageSources: Map<string, Promise<RenderTexture | undefined>>;
constructor(iModel: IModelConnection);
get isDisposed(): boolean;
[Symbol.dispose](): void;
/** Add a material to this IdMap, given that it has a valid key. */
addMaterial(material: RenderMaterial): void;
/** Add a texture to this IdMap, given that it has a valid string key. If specified, it will instead use the key parameter, which could also be a gradient symb. */
addTexture(texture: RenderTexture, key?: TextureCacheKey): void;
/** Add a texture to this IdMap using gradient symbology. */
addGradient(gradientSymb: Gradient.Symb, texture: RenderTexture): void;
/** Find a cached material using its key. If not found, returns undefined. */
findMaterial(key: string): RenderMaterial | undefined;
/** Find a cached gradient using the gradient symbology. If not found, returns undefined. */
findGradient(symb: Gradient.Symb): RenderTexture | undefined;
/** Find or create a new material given material parameters. This will cache the material if its key is valid. */
getMaterial(params: RenderMaterialParams): RenderMaterial;
findTexture(key?: string | Gradient.Symb): RenderTexture | undefined;
getTextureFromElement(key: Id64String, iModel: IModelConnection, params: RenderTextureParams, format: ImageSourceFormat): RenderTexture | undefined;
getTextureFromImageSource(args: CreateTextureFromSourceArgs, key: string): Promise<RenderTexture | undefined>;
createTextureFromImageSource(args: CreateTextureFromSourceArgs, key: string): Promise<RenderTexture | undefined>;
getTextureFromCubeImages(posX: HTMLImageElement, negX: HTMLImageElement, posY: HTMLImageElement, negY: HTMLImageElement, posZ: HTMLImageElement, negZ: HTMLImageElement, params: RenderTextureParams): RenderTexture | undefined;
collectStatistics(stats: RenderMemory.Statistics): void;
}
export type TextureBinding = WebGLTexture | undefined;
/** @internal */
export declare class System extends RenderSystem implements RenderSystemDebugControl, RenderMemory.Consumer, WebGLDisposable {
readonly canvas: HTMLCanvasElement;
readonly currentRenderState: RenderState;
readonly context: WebGL2RenderingContext;
readonly frameBufferStack: FrameBufferStack;
private readonly _capabilities;
readonly resourceCache: Map<IModelConnection, IdMap>;
readonly glTimer: GLTimer;
private readonly _textureBindings;
private _removeEventListener?;
private readonly _curVertexAttribStates;
private readonly _nextVertexAttribStates;
private _lineCodeTexture?;
private _noiseTexture?;
private _techniques?;
private _screenSpaceEffects?;
readonly debugShaderFiles: DebugShaderFile[];
static get instance(): System;
get isValid(): boolean;
get lineCodeTexture(): TextureHandle | undefined;
get noiseTexture(): TextureHandle | undefined;
get techniques(): Techniques;
get screenSpaceEffects(): ScreenSpaceEffects;
get maxTextureSize(): number;
get supportsCreateImageBitmap(): boolean;
get maxRenderType(): import("@itwin/webgl-compatibility").RenderType;
get fragDepthDoesNotDisableEarlyZ(): true | undefined;
get maxAntialiasSamples(): number;
get supportsNonPowerOf2Textures(): boolean;
get maxTexSizeAllow(): number;
get disjointTimerQuery(): any;
get isMobile(): boolean;
setDrawBuffers(attachments: GLenum[]): void;
doIdleWork(): boolean;
/** Return a Promise which when resolved indicates that all pending external textures have finished loading from the backend. */
waitForAllExternalTextures(): Promise<void>;
get hasExternalTextureRequests(): boolean;
/** Attempt to create a WebGLRenderingContext, returning undefined if unsuccessful. */
static createContext(canvas: HTMLCanvasElement, useWebGL2: boolean, inputContextAttributes?: WebGLContextAttributes): WebGLContext | undefined;
static create(optionsIn?: RenderSystem.Options): System;
get isDisposed(): boolean;
dispose(): void;
onInitialized(): void;
createTarget(canvas: HTMLCanvasElement): RenderTarget;
createOffscreenTarget(rect: ViewRect): RenderTarget;
createGraphic(options: CustomGraphicBuilderOptions | ViewportGraphicBuilderOptions): GraphicBuilder;
createPlanarGrid(frustum: Frustum, grid: PlanarGridProps): RenderGraphic | undefined;
createTerrainMesh(params: RealityMeshParams, transform?: Transform, disableTextureDisposal?: boolean): RealityMeshGeometry | undefined;
createRealityMeshGraphic(params: MeshMapLayerGraphicParams, disableTextureDisposal?: boolean): RenderGraphic | undefined;
createRealityMeshGeometry(realityMesh: RealityMeshParams, disableTextureDisposal?: boolean): RealityMeshGeometry | undefined;
createMeshGeometry(params: MeshParams, viOrigin?: Point3d): MeshRenderGeometry | undefined;
createPolylineGeometry(params: PolylineParams, viOrigin?: Point3d): PolylineGeometry | undefined;
createPointStringGeometry(params: PointStringParams, viOrigin?: Point3d): PointStringGeometry | undefined;
createAreaPattern(params: PatternGraphicParams): PatternBuffers | undefined;
createRenderInstances(params: RenderInstancesParams): RenderInstances | undefined;
private createInstancedGraphic;
createGraphicFromTemplate(args: CreateGraphicFromTemplateArgs): RenderGraphic;
createRenderGraphic(geometry: RenderGeometry, instances?: InstancedGraphicParams | RenderAreaPattern | InstanceBuffers): RenderGraphic | undefined;
createPointCloudGeometry(args: PointCloudArgs): PointCloudGeometry;
createGraphicList(primitives: RenderGraphic[]): RenderGraphic;
createGraphicBranch(branch: GraphicBranch, transform: Transform, options?: GraphicBranchOptions): RenderGraphic;
createAnimationTransformNode(graphic: RenderGraphic, nodeId: number): RenderGraphic;
createBatch(graphic: RenderGraphic, features: RenderFeatureTable, range: ElementAlignedBox3d, options?: BatchOptions): RenderGraphic;
createGraphicOwner(owned: RenderGraphic): RenderGraphicOwner;
createGraphicLayer(graphic: RenderGraphic, layerId: string): Layer;
createGraphicLayerContainer(graphic: RenderGraphic, drawAsOverlay: boolean, transparency: number, elevation: number): LayerContainer;
createSkyBox(params: RenderSkyBoxParams): RenderGraphic | undefined;
createScreenSpaceEffectBuilder(params: ScreenSpaceEffectBuilderParams): ScreenSpaceEffectBuilder;
applyRenderState(newState: RenderState): void;
createDepthBuffer(width: number, height: number, numSamples?: number): DepthBuffer | undefined;
/** Returns the corresponding IdMap for an IModelConnection. Creates a new one if it doesn't exist. */
createIModelMap(imodel: IModelConnection): IdMap;
/** Removes an IModelConnection-IdMap pairing from the system's resource cache. */
private removeIModelMap;
createRenderMaterial(args: CreateRenderMaterialArgs): RenderMaterial | undefined;
/** Using its key, search for an existing material of an open iModel. */
findMaterial(key: string, imodel: IModelConnection): RenderMaterial | undefined;
private getTextureCacheInfo;
createTexture(args: CreateTextureArgs): RenderTexture | undefined;
createTextureFromSource(args: CreateTextureFromSourceArgs): Promise<RenderTexture | undefined>;
createTextureFromElement(id: Id64String, imodel: IModelConnection, params: RenderTextureParams, format: ImageSourceFormat): RenderTexture | undefined;
createTextureFromCubeImages(posX: HTMLImageElement, negX: HTMLImageElement, posY: HTMLImageElement, negY: HTMLImageElement, posZ: HTMLImageElement, negZ: HTMLImageElement, imodel: IModelConnection, params: RenderTextureParams): RenderTexture | undefined;
/** Attempt to create a texture using gradient symbology. */
getGradientTexture(symb: Gradient.Symb, iModel?: IModelConnection): RenderTexture | undefined;
/** Using its key, search for an existing texture of an open iModel. */
findTexture(key: TextureCacheKey, imodel: IModelConnection): RenderTexture | undefined;
createClipVolume(clipVector: ClipVector): RenderClipVolume | undefined;
createBackgroundMapDrape(drapedTree: TileTreeReference, mapTree: MapTileTreeReference): BackgroundMapDrape;
protected constructor(canvas: HTMLCanvasElement, context: WebGL2RenderingContext, capabilities: Capabilities, options: RenderSystem.Options);
/** Exposed strictly for tests. */
getIdMap(imodel: IModelConnection): IdMap;
private bindTexture;
/** Bind the specified texture to the specified unit. This may *or may not* make the texture *active* */
bindTexture2d(unit: TextureUnit, texture: TextureBinding): void;
/** Bind the specified texture to the specified unit. This may *or may not* make the texture *active* */
bindTextureCubeMap(unit: TextureUnit, texture: TextureBinding): void;
/** Bind the specified texture to the specified unit. This *always* makes the texture *active* */
activateTexture2d(unit: TextureUnit, texture: TextureBinding): void;
/** Bind the specified texture to the specified unit. This *always* makes the texture *active* */
activateTextureCubeMap(unit: TextureUnit, texture: TextureBinding): void;
ensureSamplerBound(uniform: UniformHandle, unit: TextureUnit): void;
get maxRealityImageryLayers(): number;
disposeTexture(texture: WebGLTexture): void;
enableVertexAttribArray(id: number, instanced: boolean): void;
updateVertexAttribArrays(): void;
vertexAttribDivisor(index: number, divisor: number): void;
drawArrays(type: GL.PrimitiveType, first: number, count: number, numInstances: number): void;
invalidateFrameBuffer(attachments: number[]): void;
enableDiagnostics(enable: RenderDiagnostics | undefined): void;
get debugControl(): RenderSystemDebugControl;
private _dpiAwareLOD?;
get dpiAwareLOD(): boolean;
set dpiAwareLOD(dpiAware: boolean);
loseContext(): boolean;
compileAllShaders(): boolean;
get isGLTimerSupported(): boolean;
set resultsCallback(callback: GLTimerResultCallback | undefined);
collectStatistics(stats: RenderMemory.Statistics): void;
setMaxAnisotropy(max: number | undefined): void;
}
//# sourceMappingURL=System.d.ts.map