import { BaseFramebuffer } from "./BaseFramebuffer"; import type { IBaseFramebufferParams } from "./BaseFramebuffer"; import { Handler } from "./Handler"; import type { TypedArray } from "../utils/shared"; import type { NumberArray4 } from "../math/Vec4"; export interface ITargetParams { internalFormat?: string; format?: string; type?: string; attachment?: string; filter?: string; readAsync?: boolean; } export interface IFrameBufferParams extends IBaseFramebufferParams { isBare?: boolean; renderbufferTarget?: string; textures?: WebGLTexture[]; targets?: ITargetParams[]; } type TypedArrayConstructor = Uint8ArrayConstructor | Float32ArrayConstructor; interface ITarget { internalFormat: string; format: string; type: string; attachment: string; filter: string; pixelBufferIndex: number; TypeArrayConstructor: TypedArrayConstructor; } interface IPixelBuffer { buffer: WebGLBuffer | null; data: TypedArray | null; glType: number; glAttachment: number; } export declare function clientWaitAsync(gl: WebGL2RenderingContext, sync: WebGLSync, flags: number): Promise; /** * Class represents framebuffer. * @class * @param {Handler} handler - WebGL handler. * @param {IFrameBufferParams} [options] - Framebuffer options: */ export declare class Framebuffer extends BaseFramebuffer { protected _renderbufferTarget: string; protected _targets: ITarget[]; /** * Framebuffer texture. * @public * @type {number} */ textures: WebGLTexture[]; pixelBuffers: IPixelBuffer[]; protected _skipFrame: boolean; constructor(handler: Handler, options?: IFrameBufferParams); static createTargets(targets?: ITargetParams[]): ITarget[]; destroy(): void; /** * Framebuffer initialization. * @public * @override */ init(): void; /** * Check your constructor has targets like this * targets: [{ * internalFormat: "RGBA", * type: "UNSIGNED_BYTE", * attachment: "COLOR_ATTACHMENT", * readAsync: true * }], **/ readPixelBuffersAsync: (callback?: (buf: this) => void) => void; getPixelBufferData(targetIndex?: number): TypedArray | null; protected _createPixelBuffer(target: ITarget): void; /** * Bind buffer texture. * @public * @param {WebGLTexture} texture - Output texture. * @param {number} [glAttachment=0] - color attachment index. */ bindOutputTexture(texture: WebGLTexture, glAttachment?: number): void; /** * Gets pixel RGBA color from framebuffer by coordinates. * @public * @param {TypedArray} res - Normalized x - coordinate. * @param {number} nx - Normalized x - coordinate. * @param {number} ny - Normalized y - coordinate. * @param {number} [w=1] - Normalized width. * @param {number} [h=1] - Normalized height. * @param {number} [index=0] - color attachment index. */ readPixels(res: TypedArray, nx: number, ny: number, index?: number, w?: number, h?: number): void; /** * Reads all pixels(RGBA colors) from framebuffer. * @public * @param {TypedArray} res - Result array. * @param {number} [attachmentIndex=0] - color attachment index. */ readAllPixels(res: TypedArray, attachmentIndex?: number): void; /** * Gets JavaScript image that in the framebuffer. * @public * @returns {HTMLImageElement} - */ getImage(): HTMLImageElement; /** * Reads pixel data from the buffer at the specified normalized coordinates. * * @param {number} nx - Normalized X coordinate in the range [0, 1], multiplied by the buffer width. * @param {number} ny - Normalized Y coordinate in the range [0, 1], multiplied by the buffer height. * @param {NumberArray4 | Float32Array} outData - Output array where the RGBA pixel values will be written. * @param {number} [attachmentIndex=0] - Index of the color attachment (buffer) to read from. * * @returns {void} * * @example * const color = new Float32Array(4); * framebuffer.readData(0.5, 0.5, color); // Reads the color at the center of the buffer */ readData(nx: number, ny: number, outData: NumberArray4 | TypedArray, attachmentIndex?: number): void; } export {};