@itwin/core-frontend
Version: 
iTwin.js frontend components
150 lines • 6.44 kB
TypeScript
/** @packageDocumentation
 * @module WebGL
 */
import { Point3d } from "@itwin/core-geometry";
import { QParams2d, QParams3d } from "@itwin/core-common";
import { WebGLDisposable } from "./Disposable";
import { GL } from "./GL";
/** Describes a connection between a BufferHandle and an arbitrary number of attributes associated with that BufferHandle. */
interface BufferHandleLinkage {
    buffer: BufferHandle;
    params: BufferParameters[];
}
/** Provides convenience methods for creating a BufferHandleLinkage interface. */
declare class BufferHandleLinkage {
    private constructor();
    static create(buffer: BufferHandle, params: BufferParameters[]): BufferHandleLinkage;
    static clone(linkage: BufferHandleLinkage): BufferHandleLinkage;
}
/**
 * Describes the binding state of a BufferHandle when added to a BuffersContainer.  See the WebGL function 'vertexAttribPointer'.
 * @internal
 */
export interface BufferParameters {
    /** Index used for binding attribute location for the associated BufferHandle. */
    glAttribLoc: number;
    /** Number of components for the attribute (1, 2, 3, or 4). */
    glSize: number;
    /** Data type of each component. */
    glType: number;
    /** If true, WebGL will normalize integer data values into a certain range (see WebGL specs for details). */
    glNormalized: boolean;
    /** Offset in bytes between the beginning of consecutive vertex attributes. */
    glStride: number;
    /** Offset in bytes of the first component in the vertex attribute array. */
    glOffset: number;
    /** Specifies whether the attribute is instanced.  If so, the WebGL instancing extension function 'vertexAttribDivisor' will be called. */
    glInstanced: boolean;
}
/**
 * Provides convenience methods for creating a BuffersParameter interface.
 * @internal
 */
export declare namespace BufferParameters {
    function create(glAttribLoc: number, glSize: number, glType: number, glNormalized: boolean, glStride: number, glOffset: number, glInstanced: boolean): BufferParameters;
    function clone(params: BufferParameters): BufferParameters;
}
/**
 * An abstract class which specifies an interface for binding and unbinding vertex buffers and their associated state.
 * @internal
 */
export declare class BuffersContainer implements WebGLDisposable {
    readonly linkages: BufferHandleLinkage[];
    protected readonly _vao: VAOHandle;
    private readonly _context;
    static create(): BuffersContainer;
    private constructor();
    /** @deprecated in 5.0 - will not be removed until after 2026-06-13. Use [Symbol.dispose] instead. */
    dispose(): void;
    [Symbol.dispose](): void;
    get isDisposed(): boolean;
    addBuffer(buffer: BufferHandle, params: BufferParameters[]): void;
    appendLinkages(linkages: BufferHandleLinkage[]): void;
    private _bindLinkage;
    bind(): void;
    unbind(): void;
}
/** A handle to a WebGLVertexArrayObjectOES.
 * The WebGLVertexArrayObjectOES is allocated by the constructor and should be freed by a call to dispose().
 * @internal
 */
export declare class VAOHandle implements WebGLDisposable {
    private _context;
    private _arrayObject?;
    /** Allocates the WebGLVertexArrayObjectOES using the supplied context. Free the WebGLVertexArrayObjectOES using dispose() */
    constructor(context: WebGL2RenderingContext);
    get isDisposed(): boolean;
    /** @deprecated in 5.0 - will not be removed until after 2026-06-13. Use [Symbol.dispose] instead. */
    dispose(): void;
    /** Frees the WebGL vertex array object */
    [Symbol.dispose](): void;
    /** Binds this vertex array object */
    bind(): void;
    /** Ensures no vertex array object is bound */
    static unbind(context: WebGL2RenderingContext): void;
}
/**
 * A handle to a WebGLBuffer, such as a vertex or index buffer.
 * The WebGLBuffer is allocated by the constructor and should be freed by a call to dispose().
 * @internal
 */
export declare class BufferHandle implements WebGLDisposable {
    private _target;
    private _glBuffer?;
    private _bytesUsed;
    /** Allocates the WebGLBuffer using the supplied context. Free the WebGLBuffer using dispose() */
    constructor(target: GL.Buffer.Target);
    get isDisposed(): boolean;
    get bytesUsed(): number;
    /** Frees the WebGL buffer */
    [Symbol.dispose](): void;
    /** Binds this buffer to the target specified during construction */
    bind(): void;
    /** Sets the specified target to be bound to no buffer */
    unbind(): void;
    /** Binds this buffer to the target specified at construction and sets the buffer's data store. */
    bindData(data: BufferSource, usage?: GL.Buffer.Usage): void;
    /** Creates a BufferHandle and binds its data */
    static createBuffer(target: GL.Buffer.Target, data: BufferSource, usage?: GL.Buffer.Usage): BufferHandle | undefined;
    /** Creates a BufferHandle and binds its data */
    static createArrayBuffer(data: BufferSource, usage?: GL.Buffer.Usage): BufferHandle | undefined;
    isBound(binding: GL.Buffer.Binding): boolean;
}
/**
 * Converts 2d quantization parameters to a format appropriate for submittal to the GPU.
 * params[0] = origin.x
 * params[1] = origin.y
 * params[2] = scale.x
 * params[3] = scale.y
 * @internal
 */
export declare function qparams2dToArray(params: QParams2d): Float32Array;
/** @internal */
export declare function qorigin3dToArray(qorigin: Point3d): Float32Array;
/** @internal */
export declare function qscale3dToArray(qscale: Point3d): Float32Array;
/** Converts 3d quantization params to a pair of Float32Arrays
 * @internal
 */
export declare function qparams3dToArray(params: QParams3d): {
    origin: Float32Array;
    scale: Float32Array;
};
/** A handle to a WebGLBuffer intended to hold quantized 2d points
 * @internal
 */
export declare class QBufferHandle2d extends BufferHandle {
    readonly params: Float32Array;
    constructor(qParams: QParams2d);
    static create(qParams: QParams2d, data: Uint16Array): QBufferHandle2d | undefined;
}
export declare class QBufferHandle3d extends BufferHandle {
    /** The quantization origin in x, y, and z */
    readonly origin: Float32Array;
    /** The quantization scale in x, y, and z */
    readonly scale: Float32Array;
    constructor(qParams: QParams3d);
    static create(qParams: QParams3d, data: Uint16Array | Uint8Array | Float32Array): QBufferHandle3d | undefined;
}
export {};
//# sourceMappingURL=AttributeBuffers.d.ts.map