import { IVec2 } from '@gglib/math'; import { TypeToken } from '@gglib/utils'; import { DataType, DataTypeOption, DepthFormatOption, PixelFormat, PixelFormatOption, TextureType, TextureTypeOption, SurfaceFormatOption, SurfaceFormat } from '../enums'; import { Device } from '../Device'; import { SamplerState, SamplerStateParams } from '../states/SamplerState'; import { TextureSource } from './TextureSource'; /** * Type that is accepted by the {@link Texture.setData} method * * @public */ export declare type TextureDataOption = number[] | ArrayBuffer | ArrayBufferView; /** * @public */ export declare type TextureSourceOption = string | TexImageSource | TextureDataOption | TextureSource; /** * Constructor options for {@link Texture} * * @public */ export interface TextureOptions { /** * Whether or not to automatically generate mip maps */ generateMipmap?: boolean; /** * The internal surface format of the texture */ surfaceFormat?: SurfaceFormatOption; /** * The pixel format to be used */ pixelFormat?: PixelFormatOption; /** * The pixel element data type to be used */ pixelType?: DataTypeOption; /** * The texture type */ type?: TextureTypeOption; /** * The texture width * * @remarks * The width is only used if the widht of the {@link source} data can not be determined. * This is the case when {@link source} is an ArrayBuffer or array */ width?: number; /** * The texture height * * @remarks * The width is only used if the height of the {@link source} data can not be determined. * This is the case when {@link source} is an ArrayBuffer or array */ height?: number; /** * The texture source data */ source?: TextureSourceOption; /** * The faces for a Cube Texture */ faces?: Array; /** * The depth format of the depth stencil buffer to use when the texture is used as a render target */ depthFormat?: DepthFormatOption; /** * The sampler state to be used together with this texture */ samplerParams?: SamplerStateParams; /** * Value for the `crossOrigin` attribute to be used when fetching image or video by url * * {@link https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image} * {@link https://blog.chromium.org/2011/07/using-cross-domain-images-in-webgl-and.html} */ crossOrigin?: string; } /** * Describes a texture object. * * @public */ export declare abstract class Texture { /** * A symbol identifying the TextureOptions */ static readonly Options: TypeToken; /** * A symbol identifying the Texture2D class */ static readonly Texture2D: TypeToken; /** * A symbol identifying the TextureCube class */ static readonly TextureCube: TypeToken; /** * Value for the `crossOrigin` attribute to be used when fetching image or video by url * * {@link https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image} * {@link https://blog.chromium.org/2011/07/using-cross-domain-images-in-webgl-and.html} */ static crossOrigin: string; /** * Unique resource id */ uid: string; /** * The device instance */ abstract readonly device: Device; /** * The texture width */ readonly width: number; /** * The texture height */ readonly height: number; /** * Indicates whether texture data has been set * * @remarks * If the texture data must be loaded asynchronously (e.g. image or video URL) this property will be false as long * as the data has not arrived. A shader should not attempt to bind this texture until the property is switched to true. */ readonly ready: boolean; /** * Indicates whether the texture size is a power of two value. */ readonly isPOT: boolean; /** * Indicates whether mip maps should be generated. */ readonly generateMipmap: boolean; /** * Indicates the used pixel format. */ readonly surfaceFormat: SurfaceFormat; /** * Indicates the used pixel format. */ readonly pixelFormat: PixelFormat; /** * Indicates the data type of the pixel elements */ readonly pixelType: DataType; /** * Indicates the texture type */ readonly type: TextureType; /** * The data source for this texture */ readonly source: TextureSource; /** * The faces of a cube texture */ readonly faces: Texture[]; /** * Returns the video element if the {@link source} is an instance of {@link TextureSourceVideo} */ get video(): HTMLVideoElement; /** * The sampler state of this texture. Always reflects current state of this texture. */ readonly sampler: SamplerState; /** * The sampler state params that should always apply to this texture * * @remarks * If this is set, this state parameters will always be used with this texture * when assigning it to a texture unit. Other sampler states defined in a shader or * elsewhere will be ignored. * * Use this if you prefer the original way of handling sampling parameters in opengl. * * Don't use this if you want separate the concerns of texture and samplers. */ samplerParams: SamplerStateParams; /** * Value for the `crossOrigin` attribute to be used when fetching image or video by url * * {@link https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image} * {@link https://blog.chromium.org/2011/07/using-cross-domain-images-in-webgl-and.html} */ readonly crossOrigin: string; /** * The recent video playback timestamp. */ protected videoTime: number; protected depthFormatField: number; /** * Depth stencil format if this is a render target */ get depthFormat(): number; set depthFormat(value: number); /** * Indicates whether this texture is intended to be used as a renter target */ get isRenderTarget(): boolean; /** * Gets the name of {@link Texture.pixelFormat} */ get pixelFormatName(): string; /** * Gets the name of {@link Texture.pixelType} */ get pixelTypeName(): string; /** * Gets the name of {@link Texture."type"} */ get typeName(): string; get isCube(): boolean; get is2D(): boolean; /** * Collection of file extensions that are recognized as video files. */ static videoTypes: string[]; setup(options?: TextureOptions): this; abstract create(): this; /** * Releases all resources and notifies the device that the texture is being destroyed. */ abstract destroy(): this; /** * Binds the texture to the gl context. * * @returns the previously bound texture handle */ abstract bind(): this; /** * Sets the texture source from an url. * * @remarks * The url is checked against the {@link Texture.videoTypes} array to detect * whether the url points to an image or video. */ setUrl(url: string): this; /** * Sets the texture source from an image url */ setImageUrl(url: string, crossOrigin?: string): this; /** * Sets the texture source from a video url */ setVideoUrl(url: string, crossOrigin?: string): this; /** * Sets the texture source from video urls. */ setVideoUrls(options: Array<{ src: string; type: string; }>): this; /** * Sets the texture source from HtmlImageElement */ setSource(value: TexImageSource | TextureSource): this; /** * Sets the texture source from data array or buffer * * @param data - The texture data to be set * @param width - The new texture width * @param height - The new texture height */ abstract setData(data: TextureDataOption, width?: number, height?: number): this; /** * Sets the cubemap faces * * @param faces - The source options for each face */ abstract setFaces(faces: TextureSourceOption[]): this; /** * returns the result of `1 / texture.width` */ get texelX(): number; /** * returns the result of `1 / texture.height` */ get texelY(): number; /** * Returns both {@link Texture.texelX} and {@link Texture.texelY} as IVec2 */ get texel(): IVec2; /** * Updates the texture from current source element. * * @remarks * This method is called automatically from inside the {@link ShaderUniform} * * When loading textures from url or html image/video elements * the texture data might not be available right away because the * resources may still be downloading. * * A call to this method instructs the texture to check the * download state of the resources and when available to update * the texture data. When data has arrived the {@link Texture.ready} * property will be set to `true` */ abstract update(): boolean; /** * Resizes the render target * * @param width - The new width * @param height - The new height */ resize(width: number, height: number): void; protected set(key: K, value: this[K]): void; } //# sourceMappingURL=Texture.d.ts.map