@thi.ng/shader-ast-js
Version:
Customizable JS codegen, compiler & runtime for @thi.ng/shader-ast
75 lines • 2.96 kB
TypeScript
import type { Fn, UIntArray } from "@thi.ng/api";
import { type IntBuffer } from "@thi.ng/pixel/int";
import type { ReadonlyVec, Vec } from "@thi.ng/vectors";
export interface RenderPixelOpts {
x?: number;
y?: number;
w?: number;
h?: number;
bufW: number;
bufH: number;
offsetX?: number;
offsetY?: number;
imgH?: number;
/**
* Format conversion from float RGBA to packed integer.
*/
fmt: Fn<ReadonlyVec, number>;
}
export declare const rgbaBgra8888: (rgba: ReadonlyVec) => number;
export declare const rgbaRgb565: (rgba: ReadonlyVec) => number;
/**
* Low-level function used by {@link canvasRenderer} and {@link renderBuffer}.
* Applies shader function `fn` to each pixel in the given region of the
* `pixels` buffer (e.g. a `Uint32Array`). The render region is defined via
* options. The top-left `x`, `y` coords and `w`, `h` dimensions. The remaining
* parameters `bufW`, `bufH`, `bufOffsetX`, `bufOffsetY` and `imgH` are used to
* define the actual location of the given buffer in the full image to be
* computed and to support use cases where the target array only defines a
* sub-region of the full image (e.g. when splitting rendering over multiple
* workers, each with their own buffer).
*
* @param fn -
* @param pixels -
* @param opts
*/
export declare const renderPixels: (fn: Fn<ReadonlyVec, Vec>, pixels: UIntArray, { x, y, w, h, bufW, bufH, offsetX, offsetY, imgH, fmt }: RenderPixelOpts) => UIntArray;
/**
* Takes a
* [`IntBuffer`](https://docs.thi.ng/umbrella/pixel/classes/IntBuffer.html)
* pixel buffer from thi.ng/pixel, and options to define a buffer-local render
* region. Applies shader function `fn` to each pixel in that region (or the
* full buffer by default).
*
* @remarks
* In case the buffer only defines a sub-region of a larger image,
* {@link RenderPixelOpts.offsetX}, {@link RenderPixelOpts.offsetY} and
* {@link RenderPixelOpts.imgH} can be given to configure the location and full
* image height.
*
* The default target pixel format is `ABGR8888` using {@link rgbaBgra8888} as
* default {@link RenderPixelOpts.fmt} conversion.
*
* @param fn -
* @param buf -
* @param x -
* @param y -
* @param w -
* @param h -
* @param bufOffsetX -
* @param bufOffsetY -
* @param imgH -
*/
export declare const renderBuffer: (fn: Fn<ReadonlyVec, Vec>, buf: IntBuffer, opts?: Partial<RenderPixelOpts>) => IntBuffer;
/**
* Higher order function accepting an `HTMLCanvasElement` and returning a render
* function which accepts the following parameters:
*
* - `fn` - shader function (compiled via `targetJS().compile(ast)`)
* - `x`, `y`, `w`, `h` - optional args to define a sub-region to be updated
* (default to full image update)
*
* @param canvas -
*/
export declare const canvasRenderer: (canvas: HTMLCanvasElement) => (fn: Fn<ReadonlyVec, Vec>, x?: number, y?: number, w?: number, h?: number) => void;
//# sourceMappingURL=runtime.d.ts.map