UNPKG

@itwin/core-frontend

Version:
203 lines • 10.5 kB
/** @packageDocumentation * @module WebGL */ import { BeEvent, Id64String } from "@itwin/core-bentley"; import { ImageBuffer, ImageSourceFormat, RenderTexture, TextureData, TextureTransparency } from "@itwin/core-common"; import { IModelConnection } from "../../../IModelConnection"; import { WebGLDisposable } from "./Disposable"; import { GL } from "./GL"; import { UniformHandle } from "./UniformHandle"; import { TextureUnit } from "./RenderFlags"; import { TextureOwnership } from "../../../render/CreateTextureArgs"; import { OvrFlags } from "../../../common/internal/render/OvrFlags"; /** @internal */ export type Texture2DData = Uint8Array | Float32Array; type TextureFlag = true | undefined; type TextureAnisotropicFilter = number | undefined; type Load2DImageData = (handle: TextureHandle, params: Texture2DCreateParams) => void; /** @internal */ export interface TextureParams { type: RenderTexture.Type; ownership?: TextureOwnership; transparency: TextureTransparency; handle: TextureHandle; } /** Wrapper class for a WebGL texture handle and parameters specific to an individual texture. * @internal */ export declare class Texture extends RenderTexture implements WebGLDisposable { readonly texture: TextureHandle; readonly ownership?: TextureOwnership; transparency: TextureTransparency; get bytesUsed(): number; get hasOwner(): boolean; get key(): string | undefined; constructor(params: TextureParams); get isDisposed(): boolean; /** Free this object in the WebGL wrapper. */ dispose(): void; } /** Parameters used internally to define how to create a texture for use with WebGL. */ declare class Texture2DCreateParams { width: number; height: number; format: GL.Texture.Format; dataType: GL.Texture.DataType; wrapMode: GL.Texture.WrapMode; loadImageData: Load2DImageData; useMipMaps?: TextureFlag; interpolate?: TextureFlag; anisotropicFilter?: TextureAnisotropicFilter; dataBytes?: Uint8Array | undefined; private constructor(); static createForData(width: number, height: number, data: Texture2DData, preserveData?: boolean, wrapMode?: GL.Texture.WrapMode, format?: GL.Texture.Format): Texture2DCreateParams; static createForImageBuffer(image: ImageBuffer, type: RenderTexture.Type): Texture2DCreateParams; static createForAttachment(width: number, height: number, format: GL.Texture.Format, dataType: GL.Texture.DataType): Texture2DCreateParams; static createForImage(image: HTMLImageElement, type: RenderTexture.Type): Texture2DCreateParams; static createForImageBitmap(image: ImageBitmap, type: RenderTexture.Type): Texture2DCreateParams; private static getImageProperties; static readonly placeholderParams: Texture2DCreateParams; } /** Wraps a WebGLTextureHandle * @internal */ export declare abstract class TextureHandle implements WebGLDisposable { protected _glTexture?: WebGLTexture; protected _bytesUsed: number; abstract get width(): number; abstract get height(): number; abstract get format(): GL.Texture.Format; abstract get dataType(): GL.Texture.DataType; abstract get dataBytes(): Uint8Array | undefined; get bytesUsed(): number; set bytesUsed(bytesUsed: number); /** Get the WebGLTexture for this TextureHandle. */ getHandle(): WebGLTexture | undefined; /** Bind texture handle (if available) associated with an instantiation of this class to specified texture unit. */ abstract bind(_texUnit: TextureUnit): boolean; /** Bind this texture to a uniform sampler. */ abstract bindSampler(_uniform: UniformHandle, _unit: TextureUnit): void; get isDisposed(): boolean; [Symbol.dispose](): void; /** Create a 2D texture for use as a color attachment for rendering */ static createForAttachment(width: number, height: number, format: GL.Texture.Format, dataType: GL.Texture.DataType): Texture2DHandle | undefined; /** Create a 2D texture to hold non-image data */ static createForData(width: number, height: number, data: Texture2DData, wantPreserveData?: boolean, wrapMode?: GL.Texture.WrapMode, format?: GL.Texture.Format): Texture2DHandle | undefined; /** Create a 2D texture from a bitmap */ static createForImageBuffer(image: ImageBuffer, type: RenderTexture.Type): Texture2DHandle | undefined; /** Create a 2D texture from an HTMLImageElement. */ static createForImage(image: HTMLImageElement, type: RenderTexture.Type): Texture2DHandle | undefined; /** Create a 2D texture from an ImageBitmap. */ static createForImageBitmap(image: ImageBitmap, type: RenderTexture.Type): Texture2DHandle | undefined; /** Create a cube map texture from six HTMLImageElement objects. */ static createForCubeImages(posX: HTMLImageElement, negX: HTMLImageElement, posY: HTMLImageElement, negY: HTMLImageElement, posZ: HTMLImageElement, negZ: HTMLImageElement): TextureHandle | undefined; static createForElement(id: Id64String, imodel: IModelConnection, type: RenderTexture.Type, format: ImageSourceFormat, onLoaded: ExternalTextureLoadCallback): Texture2DHandle | undefined; protected constructor(glTexture: WebGLTexture); /** For debugging purposes, open a new window containing this texture as an image. */ showDebugImage(): void; } /** @internal */ export declare class Texture2DHandle extends TextureHandle { private _width; private _height; private _format; private _dataType; private _dataBytes?; get width(): number; get height(): number; get format(): GL.Texture.Format; get dataType(): GL.Texture.DataType; get dataBytes(): Uint8Array | undefined; /** Bind specified texture handle to specified texture unit. */ static bindTexture(texUnit: TextureUnit, glTex: WebGLTexture | undefined): void; /** Bind the specified texture to a uniform sampler2D */ static bindSampler(uniform: UniformHandle, tex: WebGLTexture, unit: TextureUnit): void; /** Bind texture handle (if available) associated with an instantiation of this class to specified texture unit. */ bind(texUnit: TextureUnit): boolean; /** Bind this texture to a uniform sampler2D */ bindSampler(uniform: UniformHandle, unit: TextureUnit): void; /** Update the 2D texture contents. */ update(updater: Texture2DDataUpdater): boolean; /** Replace the 2D texture contents. */ replaceTextureData(data: Texture2DData): boolean; private static create; /** Create a texture for use as a color attachment for rendering */ static createForAttachment(width: number, height: number, format: GL.Texture.Format, dataType: GL.Texture.DataType): Texture2DHandle | undefined; /** Create a texture to hold non-image data */ static createForData(width: number, height: number, data: Texture2DData, wantPreserveData?: boolean, wrapMode?: GL.Texture.WrapMode, format?: GL.Texture.Format): Texture2DHandle | undefined; /** Create a texture from a bitmap */ static createForImageBuffer(image: ImageBuffer, type: RenderTexture.Type): Texture2DHandle | undefined; /** Create a 2D texture from an HTMLImageElement. */ static createForImage(image: HTMLImageElement, type: RenderTexture.Type): Texture2DHandle | undefined; /** Create a 2D texture from an ImageBitmap. */ static createForImageBitmap(image: ImageBitmap, type: RenderTexture.Type): Texture2DHandle | undefined; private static _placeHolderTextureData; static createForElement(id: Id64String, imodel: IModelConnection, type: RenderTexture.Type, format: ImageSourceFormat, onLoaded: ExternalTextureLoadCallback): Texture2DHandle | undefined; reload(params: Texture2DCreateParams): void; private constructor(); } /** @internal */ export type ExternalTextureLoadCallback = (req: ExternalTextureRequest, data: TextureData) => void; /** @internal */ export interface ExternalTextureRequest { handle: Texture2DHandle; name: Id64String; imodel: IModelConnection; type: RenderTexture.Type; format: ImageSourceFormat; onLoaded?: ExternalTextureLoadCallback; } /** @internal */ export declare class ExternalTextureLoader { static readonly instance: ExternalTextureLoader; readonly onTexturesLoaded: BeEvent<() => void>; private readonly _maxActiveRequests; private _activeRequests; private _pendingRequests; private _convertRequests; private _convertPending; get numActiveRequests(): number; get numPendingRequests(): number; get maxActiveRequests(): number; private constructor(); private _nextRequest; private _activateRequest; private _convertTexture; private _requestExists; loadTexture(handle: Texture2DHandle, name: Id64String, imodel: IModelConnection, type: RenderTexture.Type, format: ImageSourceFormat, onLoaded?: ExternalTextureLoadCallback): void; } /** @internal */ export declare class TextureCubeHandle extends TextureHandle { private _dim; private _format; private _dataType; get width(): number; get height(): number; get format(): GL.Texture.Format; get dataType(): GL.Texture.DataType; get dataBytes(): Uint8Array | undefined; /** Bind specified cubemap texture handle to specified texture unit. */ static bindTexture(texUnit: TextureUnit, glTex: WebGLTexture | undefined): void; /** Bind the specified texture to a uniform sampler2D */ static bindSampler(uniform: UniformHandle, tex: WebGLTexture, unit: TextureUnit): void; /** Bind texture handle (if available) associated with an instantiation of this class to specified texture unit. */ bind(texUnit: TextureUnit): boolean; /** Bind this texture to a uniform sampler2D */ bindSampler(uniform: UniformHandle, unit: TextureUnit): void; private static create; /** Create a cube map texture from six HTMLImageElement objects. */ static createForCubeImages(posX: HTMLImageElement, negX: HTMLImageElement, posY: HTMLImageElement, negY: HTMLImageElement, posZ: HTMLImageElement, negZ: HTMLImageElement): TextureHandle | undefined; private constructor(); } /** @internal */ export declare class Texture2DDataUpdater { data: Uint8Array; modified: boolean; constructor(data: Uint8Array); setByteAtIndex(index: number, byte: number): void; setOvrFlagsAtIndex(index: number, value: OvrFlags): void; getByteAtIndex(index: number): number; getOvrFlagsAtIndex(index: number): OvrFlags; } export {}; //# sourceMappingURL=Texture.d.ts.map