UNPKG

typegpu

Version:

A thin layer between JS and WebGPU/WGSL that improves development experience and allows for faster iteration.

34 lines (33 loc) 1.2 kB
import {} from "../data/snippet.js"; import { $internal, $resolve, isMarkedInternal } from "../shared/symbols.js"; /** * WARNING: This is an API that touches a lot of internals, and is not stable * (can change between patches). You should probably talk to the TypeGPU team * before using this, maybe we can provide a better public API for your use case. * * Defines additional properties on `value` (mutates it) that makes TypeGPU * understand how it should handle passing this object to the `tgpu.resolve` * API, or just how to generate shader code from it to begin with. * * `value` can in particular be the prototype of a class, meaning all instances * of that class will be resolvable. */ export function makeResolvable(value, options) { if (!isMarkedInternal(value)) { Object.defineProperty(value, $internal, { value: true, writable: true, }); } Object.defineProperty(value, 'toString', { value() { return options.asString.apply(this); }, }); Object.defineProperty(value, $resolve, { value(ctx) { return options.resolve.apply(this, [ctx]); }, }); return value; }