webgl-dsl
Version:
Thin functional WebGL wrapper with strong typed GLSL DSL
86 lines (85 loc) • 3.87 kB
TypeScript
import { ProgramSource, SourceConfig, TypeMap } from './dsl';
import { Disposable } from './disposable';
import { Settings } from './settings';
import { BufferUsage, ErrorCode, PixelFormat, PrimitivesType } from './enums';
import { Program } from './program';
import { ElementsBuffer } from './elements-buffer';
import { ArrayBuffer } from './array-buffer';
import { RenderBuffer } from './render-buffer';
import { FrameBuffer } from './frame-buffer';
import { Texture, TextureConfig } from './texture';
import WithoutPrecision = TypeMap.WithoutPrecision;
/**
* The main class of this library. It provides access to WebGL context.
* Use it to create programs, textures, buffers, and change WebGL state.
*/
export declare class Gl implements Disposable {
readonly handle: WebGLRenderingContext;
readonly instancedArraysExtension: ANGLE_instanced_arrays;
private readonly srgbExtension;
private readonly minMaxExtension;
private readonly settingsCache;
constructor(...source: [HTMLCanvasElement, WebGLContextAttributes?] | [WebGLRenderingContext]);
/**
* Get the width of the drawing buffer.
*/
get width(): number;
/**
* Get the height of the drawing buffer.
*/
get height(): number;
isContextLost(): boolean;
getPointSizeRange(): [number, number];
clearColorBuffer(): this;
clearDepthBuffer(): this;
/**
* Clear color and depth buffer
*/
clearBuffers(): this;
/**
* Read pixels from a drawing buffer into an array buffer
*/
read(format?: PixelFormat): Uint8Array;
drawArrays(primitivesType: PrimitivesType, verticesCount: number): this;
drawsElements(primitivesType: PrimitivesType, elementsCount: number): this;
drawInstancedArrays(primitivesType: PrimitivesType, verticesCount: number, instancesCount: number): this;
drawsInstancedElements(primitivesType: PrimitivesType, elementsCount: number, instancesCount: number): this;
/**
* Create an empty settings object
*/
settings(): Settings;
/**
* Create texture with specified parameters
*/
texture(config: TextureConfig): Texture;
/**
* Create depth buffer with specified width and height
* @param width Depth buffer width
* @param height Depth buffer height
*/
renderBuffer(width: number, height: number): RenderBuffer;
/**
* Create a frame buffer that can be used as a render target.
* @param texture The texture to attach to the frame buffer.
* @param renderBuffer Depth buffer to attach to the frame buffer.
*/
frameBuffer(texture: Texture, renderBuffer?: RenderBuffer): FrameBuffer;
arrayBuffer(data?: Float32Array | number[] | null, usage?: BufferUsage): ArrayBuffer;
elementsBuffer(data?: Uint16Array | number[] | null, usage?: BufferUsage): ElementsBuffer;
/**
* Create a program with a specified vertex and fragment shader source
*/
program(vertex: string, fragment: string): Program;
/**
* The main function of this library, creates a command with specified parameters and shaders
* @param primitivesType Type of primitives to draw
* @param configOrSource Description of attributes, uniforms, varyings, and shaders
*/
command<Uniforms extends TypeMap, Attributes extends TypeMap, Instances extends TypeMap, Varyings extends TypeMap = {}>(primitivesType: PrimitivesType, configOrSource: SourceConfig<Uniforms, Attributes, Instances, Varyings> | ProgramSource<WithoutPrecision<Uniforms>, WithoutPrecision<Attributes>, WithoutPrecision<Instances>>): import('./command').Command<TypeMap.WithoutPrecision<Uniforms>, TypeMap.WithoutPrecision<Attributes>, TypeMap.WithoutPrecision<Instances>>;
hasSrgbExtension(): boolean;
getErrorCode(): ErrorCode | number;
/**
* Destroy WebGL context
*/
dispose(): void;
}