UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

187 lines 5.51 kB
/** * A high-level rendering architecture system that manages render passes and their resource dependencies. * This class schedules frame execution by building a directed graph of resources (textures, buffers) and the passes that read or write to them. * * By deferring execution until after the graph is compiled, it automatically handles complex tasks such as: * - Culling unreferenced resources and passes (dead code elimination for rendering). * - Automatic resource lifetime management (allocating transient resources just-in-time and destroying them immediately after their last use). * - Visualizing the rendering pipeline via GraphViz DOT exports. * * @source Based on the Frostbite's GDC paper "FrameGraph: Extensible Rendering Architecture in Frostbite" by Yuriy O'Donnell * @example * const graph = new FrameGraph("My Graph"); * * const pass_data = {}; * const pass = graph.add("GBuffer Pass", pass_data, (data, resources, context) => { * * context.beginRenderPass({ * depth_attachment: resources.get(data.depth), * color_attachments:[ * resources.get(data.normal), * resources.get(data.albedo), * ] * }); * * for (const renderable in renderables){ * drawMesh(context, renderable.mesh, renderable.material); * } * * context.endRenderPass(); * * }); * * pass_data.depth = pass.create("depth", {...}); * pass_data.albedo = pass.create("albedo", {...}); * pass_data.normal = pass.create("normal", {...}); * * graph.compile(); * graph.execute(context); * */ export class FrameGraph { /** * * @param {string} name */ constructor(name?: string); /** * Human-readable name, used for debugging and UI primarily. * There is no uniqueness guarantee * @type {string} */ name: string; /** * * @type {Signal<IFrameGraphContext,this>} */ onExecuted: Signal<IFrameGraphContext, this>; /** * * @type {FramePassNode[]} * @private */ private __pass_nodes; /** * * @type {ResourceNode[]} * @private */ private __resource_nodes; /** * * @type {ResourceEntry[]} * @private */ private __resource_registry; /** * * @param {number} id Resource Node ID * @returns {ResourceEntry} */ getResourceEntry(id: number): ResourceEntry<any>; /** * * @param {number} id * @returns {ResourceNode} */ getResourceNode(id: number): ResourceNode<any>; /** * @template T * @param {number} id resource ID * @returns {T} */ getDescriptor<T>(id: number): T; /** * @template T * @param {string} name * @param {T} descriptor * @returns {number} */ create_resource<T_1>(name: string, descriptor: T_1): number; /** * @template T * @param {T} descriptor * @return {ResourceEntry} * @private */ private _createResourceEntry; /** * * @param {string} name * @param {number} resource_id * @return {ResourceNode} * @private */ private _createResourceNode; /** * * @param {number} node_id * @returns {number} ID of the cloned resource node */ clone_resource(node_id: number): number; /** * @template T * @param {string} name * @param {ResourceDescriptor<T>} description * @param {T} resource * @returns {number} */ import_resource<T_2>(name: string, description: ResourceDescriptor<T_2>, resource: T_2): number; /** * @returns {boolean} * @param id */ is_valid_resource(id: any): boolean; /** * Add a new pass to the graph. * @template T * @param {string} name * @param {T} data * @param {function(data:T, resources: FramePassResources, context:IFrameGraphContext):void} execute * @returns {FramePassBuilder} */ add<T_3>(name: string, data: T_3, execute: any): FramePassBuilder; /** * Perform validation, useful for debugging * Typically done before compilation * @param {function(problem:string):*} problem_consumer * @param {*} [problem_consumer_context] thisArg for `problem_consumer` * @returns {boolean} */ validate(problem_consumer: any, problem_consumer_context?: any): boolean; compile(): void; /** * * @param {IFrameGraphContext} context */ execute(context: IFrameGraphContext): void; /** * Should only call after {@link compile} * * Can be visualized with this tool: https://skaarj1989.github.io/FrameGraph/ * * @see https://github.com/skaarj1989/FrameGraph/blob/viewer/JsonWriter.hpp * @return {{passes: [], resources: []}} */ exportToJson(): { passes: []; resources: []; }; /** * Export the graph diagram in GraphViz DOT format. * Useful for debugging. * @see https://en.wikipedia.org/wiki/DOT_(graph_description_language) * @return {string} */ exportToDot(): string; /** * Type check shortcut. * @readonly * @type {boolean} */ readonly isFrameGraph: boolean; } import { ResourceEntry } from "./ResourceEntry.js"; import { ResourceNode } from "./ResourceNode.js"; import { FramePassBuilder } from "./FramePassBuilder.js"; //# sourceMappingURL=FrameGraph.d.ts.map