gl-react
Version:
Universal React library, write and compose WebGL shaders, implement complex effects using a descriptive paradigm
146 lines • 4.62 kB
TypeScript
import React, { Component } from "react";
import Bus from "./Bus";
import type { Shader } from "gl-shader";
import type { NDArray } from "ndarray";
import type { ShaderIdentifier, ShaderInfo, ShaderDefinition } from "./Shaders";
import type { Surface, SurfaceContext } from "./createSurface";
declare const blendFuncAliases: {
[key: string]: string;
};
type Interpolation = "linear" | "nearest";
type WrapMode = "clamp to edge" | "repeat" | "mirrored repeat";
type TextureOptions = {
interpolation: Interpolation;
wrap: [WrapMode, WrapMode] | WrapMode;
};
type BlendFunc = keyof typeof blendFuncAliases;
type BlendFuncSrcDst = {
src: BlendFunc;
dst: BlendFunc;
};
type Vec4 = [number, number, number, number];
type Clear = {
color: Vec4;
};
type Uniforms = {
[key: string]: any;
};
type UniformsOptions = {
[key: string]: Partial<TextureOptions> | null | undefined;
};
type Props = {
shader: ShaderIdentifier | ShaderDefinition;
uniformsOptions: UniformsOptions;
uniforms: Uniforms;
ignoreUnusedUniforms?: Array<string> | boolean;
sync?: boolean;
width?: number;
height?: number;
children?: any;
backbuffering?: boolean;
blendFunc: BlendFuncSrcDst;
clear: Clear | null;
onDraw?: () => void;
};
type Framebuffer = {
handle: WebGLFramebuffer;
color: WebGLTexture;
bind: () => void;
dispose: () => void;
syncSize: (w: number, h: number) => void;
};
/**
* `<Node>` is the primitive that renders a shader program into a Framebuffer.
* It can be composed with other `Node` via using a sampler2D uniforms.
*/
export default class Node extends Component<Props, any> {
drawProps: Props;
context: SurfaceContext;
framebuffer?: Framebuffer;
backbuffer?: Framebuffer;
_needsRedraw: boolean;
capturePixelsArray?: Uint8Array;
id: number;
uniformsBus: {
[key: string]: Array<Bus | null>;
};
dependencies: Array<Node | Bus>;
dependents: Array<Node | Surface>;
static propTypes: {
shader: any;
uniformsOptions: any;
uniforms: any;
ignoreUnusedUniforms: any;
sync: any;
width: any;
height: any;
children: any;
backbuffering: any;
blendFunc: any;
clear: any;
onDraw: any;
};
static defaultProps: {
uniformsOptions: {};
uniforms: {};
blendFunc: {
src: string;
dst: string;
};
clear: {
color: Vec4;
};
};
static contextType: React.Context<{
glParent: any;
glSurface: any;
glSizable: any;
}>;
componentDidMount(): void;
componentWillUnmount(): void;
_syncNextDrawProps(nextProps: Props, nextContext: any): void;
_resolveElement: (uniform: string, value: any, index: number) => React.ReactElement | undefined;
_renderUniformElement: (key: string) => React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>>[];
render(): import("react/jsx-runtime").JSX.Element;
componentDidUpdate(): void;
getGLShortName(): string;
getGLName(): string;
getGLSize(): [number, number];
getGLOutput(): WebGLTexture;
getGLBackbufferOutput(): WebGLTexture;
/**
* Imperatively set the props with a partial subset of props to apply.
*/
setDrawProps(patch: Partial<Props>): void;
/**
* Capture the node pixels.
*/
capture(x?: number, y?: number, w?: number, h?: number): NDArray;
/**
* Schedule a redraw of this node and all dependent nodes.
*/
redraw: () => void;
/**
* Force the redraw (if any) to happen now, synchronously.
*/
flush: () => void;
_destroyGLObjects(): void;
_prepareGLObjects(gl: WebGLRenderingContext): void;
_onContextLost(): void;
_onContextRestored(gl: WebGLRenderingContext): void;
_addGLNodeChild(node: Node): void;
_removeGLNodeChild(node: Node): void;
_addUniformBus(uniformBus: Bus, uniformName: string, index: number): void;
_removeUniformBus(uniformBus: Bus, uniformName: string, index: number): void;
_addDependent(node: Node | Surface): void;
_removeDependent(node: Node | Surface): void;
_syncDependencies(newdeps: Array<Node | Bus>): [Array<Bus | Node>, Array<Bus | Node>];
_bind(): void;
_captureAlloc(size: number): Uint8Array;
_latestShaderInfo?: ShaderInfo;
_shader?: Shader;
_getShader(shaderProp: any): Shader;
_draw(): void;
}
export {};
//# sourceMappingURL=Node.d.ts.map