This commit is contained in:
Akko
2025-08-04 18:57:35 +02:00
parent 8cf6e78a79
commit 9495868c2e
5030 changed files with 518594 additions and 17609 deletions

View File

@@ -0,0 +1,12 @@
/**
* An instruction that can be executed by the renderer
* @memberof rendering
*/
export interface Instruction {
/** a the id of the render pipe that can run this instruction */
renderPipeId: string;
/** the name of the instruction */
action?: string;
/** true if this instruction can be compiled into a WebGPU bundle */
canBundle: boolean;
}

View File

@@ -0,0 +1,4 @@
'use strict';
"use strict";
//# sourceMappingURL=Instruction.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"Instruction.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}

View File

@@ -0,0 +1,2 @@
"use strict";
//# sourceMappingURL=Instruction.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"Instruction.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}

View File

@@ -0,0 +1,37 @@
import type { Renderable } from '../Renderable';
import type { Instruction } from './Instruction';
/**
* A set of instructions that can be executed by the renderer.
* Basically wraps an array, but with some extra properties that help the renderer
* to keep things nice and optimised.
*
* Note:
* InstructionSet.instructions contains all the instructions, but does not resize (for performance).
* So for the true length of the instructions you need to use InstructionSet.instructionSize
* @memberof rendering
*/
export declare class InstructionSet {
/** a unique id for this instruction set used through the renderer */
readonly uid: number;
/** the array of instructions */
readonly instructions: Instruction[];
/** the actual size of the array (any instructions passed this should be ignored) */
instructionSize: number;
/** allows for access to the render pipes of the renderer */
renderPipes: any;
renderables: Renderable[];
tick: number;
/** reset the instruction set so it can be reused set size back to 0 */
reset(): void;
/**
* Add an instruction to the set
* @param instruction - add an instruction to the set
*/
add(instruction: Instruction): void;
/**
* Log the instructions to the console (for debugging)
* @internal
* @ignore
*/
log(): void;
}

View File

@@ -0,0 +1,42 @@
'use strict';
var uid = require('../../../../utils/data/uid.js');
"use strict";
let _tick = 0;
class InstructionSet {
constructor() {
/** a unique id for this instruction set used through the renderer */
this.uid = uid.uid("instructionSet");
/** the array of instructions */
this.instructions = [];
/** the actual size of the array (any instructions passed this should be ignored) */
this.instructionSize = 0;
this.renderables = [];
this.tick = 0;
}
/** reset the instruction set so it can be reused set size back to 0 */
reset() {
this.instructionSize = 0;
this.tick = _tick++;
}
/**
* Add an instruction to the set
* @param instruction - add an instruction to the set
*/
add(instruction) {
this.instructions[this.instructionSize++] = instruction;
}
/**
* Log the instructions to the console (for debugging)
* @internal
* @ignore
*/
log() {
this.instructions.length = this.instructionSize;
console.table(this.instructions, ["type", "action"]);
}
}
exports.InstructionSet = InstructionSet;
//# sourceMappingURL=InstructionSet.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"InstructionSet.js","sources":["../../../../../src/rendering/renderers/shared/instructions/InstructionSet.ts"],"sourcesContent":["import { uid } from '../../../../utils/data/uid';\n\nimport type { Renderable } from '../Renderable';\nimport type { Instruction } from './Instruction';\n\nlet _tick = 0;\n\n/**\n * A set of instructions that can be executed by the renderer.\n * Basically wraps an array, but with some extra properties that help the renderer\n * to keep things nice and optimised.\n *\n * Note:\n * InstructionSet.instructions contains all the instructions, but does not resize (for performance).\n * So for the true length of the instructions you need to use InstructionSet.instructionSize\n * @memberof rendering\n */\nexport class InstructionSet\n{\n /** a unique id for this instruction set used through the renderer */\n public readonly uid: number = uid('instructionSet');\n /** the array of instructions */\n public readonly instructions: Instruction[] = [];\n /** the actual size of the array (any instructions passed this should be ignored) */\n public instructionSize = 0;\n /** allows for access to the render pipes of the renderer */\n public renderPipes: any;\n\n public renderables: Renderable[] = [];\n public tick = 0;\n\n /** reset the instruction set so it can be reused set size back to 0 */\n public reset()\n {\n this.instructionSize = 0;\n this.tick = _tick++;\n }\n\n /**\n * Add an instruction to the set\n * @param instruction - add an instruction to the set\n */\n public add(instruction: Instruction)\n {\n this.instructions[this.instructionSize++] = instruction;\n }\n\n /**\n * Log the instructions to the console (for debugging)\n * @internal\n * @ignore\n */\n public log()\n {\n this.instructions.length = this.instructionSize;\n // eslint-disable-next-line no-console\n console.table(this.instructions, ['type', 'action']);\n }\n}\n"],"names":["uid"],"mappings":";;;;;AAKA,IAAI,KAAQ,GAAA,CAAA,CAAA;AAYL,MAAM,cACb,CAAA;AAAA,EADO,WAAA,GAAA;AAGH;AAAA,IAAgB,IAAA,CAAA,GAAA,GAAcA,QAAI,gBAAgB,CAAA,CAAA;AAElD;AAAA,IAAA,IAAA,CAAgB,eAA8B,EAAC,CAAA;AAE/C;AAAA,IAAA,IAAA,CAAO,eAAkB,GAAA,CAAA,CAAA;AAIzB,IAAA,IAAA,CAAO,cAA4B,EAAC,CAAA;AACpC,IAAA,IAAA,CAAO,IAAO,GAAA,CAAA,CAAA;AAAA,GAAA;AAAA;AAAA,EAGP,KACP,GAAA;AACI,IAAA,IAAA,CAAK,eAAkB,GAAA,CAAA,CAAA;AACvB,IAAA,IAAA,CAAK,IAAO,GAAA,KAAA,EAAA,CAAA;AAAA,GAChB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,IAAI,WACX,EAAA;AACI,IAAK,IAAA,CAAA,YAAA,CAAa,IAAK,CAAA,eAAA,EAAiB,CAAI,GAAA,WAAA,CAAA;AAAA,GAChD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,GACP,GAAA;AACI,IAAK,IAAA,CAAA,YAAA,CAAa,SAAS,IAAK,CAAA,eAAA,CAAA;AAEhC,IAAA,OAAA,CAAQ,MAAM,IAAK,CAAA,YAAA,EAAc,CAAC,MAAA,EAAQ,QAAQ,CAAC,CAAA,CAAA;AAAA,GACvD;AACJ;;;;"}

View File

@@ -0,0 +1,40 @@
import { uid } from '../../../../utils/data/uid.mjs';
"use strict";
let _tick = 0;
class InstructionSet {
constructor() {
/** a unique id for this instruction set used through the renderer */
this.uid = uid("instructionSet");
/** the array of instructions */
this.instructions = [];
/** the actual size of the array (any instructions passed this should be ignored) */
this.instructionSize = 0;
this.renderables = [];
this.tick = 0;
}
/** reset the instruction set so it can be reused set size back to 0 */
reset() {
this.instructionSize = 0;
this.tick = _tick++;
}
/**
* Add an instruction to the set
* @param instruction - add an instruction to the set
*/
add(instruction) {
this.instructions[this.instructionSize++] = instruction;
}
/**
* Log the instructions to the console (for debugging)
* @internal
* @ignore
*/
log() {
this.instructions.length = this.instructionSize;
console.table(this.instructions, ["type", "action"]);
}
}
export { InstructionSet };
//# sourceMappingURL=InstructionSet.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"InstructionSet.mjs","sources":["../../../../../src/rendering/renderers/shared/instructions/InstructionSet.ts"],"sourcesContent":["import { uid } from '../../../../utils/data/uid';\n\nimport type { Renderable } from '../Renderable';\nimport type { Instruction } from './Instruction';\n\nlet _tick = 0;\n\n/**\n * A set of instructions that can be executed by the renderer.\n * Basically wraps an array, but with some extra properties that help the renderer\n * to keep things nice and optimised.\n *\n * Note:\n * InstructionSet.instructions contains all the instructions, but does not resize (for performance).\n * So for the true length of the instructions you need to use InstructionSet.instructionSize\n * @memberof rendering\n */\nexport class InstructionSet\n{\n /** a unique id for this instruction set used through the renderer */\n public readonly uid: number = uid('instructionSet');\n /** the array of instructions */\n public readonly instructions: Instruction[] = [];\n /** the actual size of the array (any instructions passed this should be ignored) */\n public instructionSize = 0;\n /** allows for access to the render pipes of the renderer */\n public renderPipes: any;\n\n public renderables: Renderable[] = [];\n public tick = 0;\n\n /** reset the instruction set so it can be reused set size back to 0 */\n public reset()\n {\n this.instructionSize = 0;\n this.tick = _tick++;\n }\n\n /**\n * Add an instruction to the set\n * @param instruction - add an instruction to the set\n */\n public add(instruction: Instruction)\n {\n this.instructions[this.instructionSize++] = instruction;\n }\n\n /**\n * Log the instructions to the console (for debugging)\n * @internal\n * @ignore\n */\n public log()\n {\n this.instructions.length = this.instructionSize;\n // eslint-disable-next-line no-console\n console.table(this.instructions, ['type', 'action']);\n }\n}\n"],"names":[],"mappings":";;;AAKA,IAAI,KAAQ,GAAA,CAAA,CAAA;AAYL,MAAM,cACb,CAAA;AAAA,EADO,WAAA,GAAA;AAGH;AAAA,IAAgB,IAAA,CAAA,GAAA,GAAc,IAAI,gBAAgB,CAAA,CAAA;AAElD;AAAA,IAAA,IAAA,CAAgB,eAA8B,EAAC,CAAA;AAE/C;AAAA,IAAA,IAAA,CAAO,eAAkB,GAAA,CAAA,CAAA;AAIzB,IAAA,IAAA,CAAO,cAA4B,EAAC,CAAA;AACpC,IAAA,IAAA,CAAO,IAAO,GAAA,CAAA,CAAA;AAAA,GAAA;AAAA;AAAA,EAGP,KACP,GAAA;AACI,IAAA,IAAA,CAAK,eAAkB,GAAA,CAAA,CAAA;AACvB,IAAA,IAAA,CAAK,IAAO,GAAA,KAAA,EAAA,CAAA;AAAA,GAChB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,IAAI,WACX,EAAA;AACI,IAAK,IAAA,CAAA,YAAA,CAAa,IAAK,CAAA,eAAA,EAAiB,CAAI,GAAA,WAAA,CAAA;AAAA,GAChD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,GACP,GAAA;AACI,IAAK,IAAA,CAAA,YAAA,CAAa,SAAS,IAAK,CAAA,eAAA,CAAA;AAEhC,IAAA,OAAA,CAAQ,MAAM,IAAK,CAAA,YAAA,EAAc,CAAC,MAAA,EAAQ,QAAQ,CAAC,CAAA,CAAA;AAAA,GACvD;AACJ;;;;"}

View File

@@ -0,0 +1,113 @@
import type { Container } from '../../../../scene/container/Container';
import type { Effect } from '../../../../scene/container/Effect';
import type { BatchableElement } from '../../../batcher/shared/Batcher';
import type { Renderer } from '../../types';
import type { Renderable } from '../Renderable';
import type { Instruction } from './Instruction';
import type { InstructionSet } from './InstructionSet';
/**
* An interface for a pipe that can be used to build instructions for the renderer.
* InstructionPipes are specifically used to manage the state of the renderer.
* For example, the BlendModePipe is used to set the blend mode of the renderer.
* @memberof rendering
*/
export interface InstructionPipe<INSTRUCTION extends Instruction> {
/**
* called just before we execute the draw calls , this is where the pipes have an opportunity to
* upload data to the GPU. This is only called if data changes.
* @param instructionSet - the instruction set currently being built
*/
upload?: (instructionSet: InstructionSet) => void;
/**
* this is where the actual instruction is executed - eg make the draw call
* activate a filter. Any instructions that have the same renderPipeId have their
* execute method called
* @param instruction - the instruction to execute
*/
execute?: (instruction: INSTRUCTION) => void;
buildReset?: (instructionSet: InstructionSet) => void;
buildStart?: (instructionSet: InstructionSet) => void;
buildEnd?: (instructionSet: InstructionSet) => void;
/** Called just after the render ends giving the RenderPipes a chance to do any cleanup */
renderEnd?: () => void;
/** Called just before the render starts giving the RenderPipes a chance to do any setup */
renderStart?: () => void;
/**
* Used by the effect pipes push and pop effects to the renderer. A push effect allows
* the renderer to change its state to support the effect. A pop effect allows the renderer
* to return to its previous state. An example of this would be the filter effect.
* @param effect - the effect to push
* @param targetContainer - the container that the effect is being applied to
* @param instructionSet - the instruction set currently being built
*/
push?: (effect: Effect, targetContainer: Container, instructionSet: InstructionSet) => void;
/**
* Used by effect pipes to pop effects from the renderer.
* @param effect - the effect to pop
* @param targetContainer - the container that the effect is being applied to
* @param instructionSet - the instruction set currently being built
*/
pop?: (effect: Effect, targetContainer: Container, instructionSet: InstructionSet) => void;
}
/**
* An interface for a pipe that can be used to build instructions for the renderer.
* RenderPipes are specifically used to render Renderables like a Mesh.
* @memberof rendering
*/
export interface RenderPipe<RENDERABLE = Renderable> {
/**
* This is where the renderable is added to the instruction set. This is called once per renderable.
* For instance, a MeshRenderPipe could be used to enqueue a 'draw mesh' command
* to the rendering instruction set, catering to the rendering of mesh geometry.
* In more complex scenarios, such as the SpritePipe, this seamlessly coordinates
* with a batchPipe to efficiently batch and add batch instructions to the instructions set
*
* Add is called when the instructions set is being built.
* @param renderable - the renderable that needs to be rendered
* @param instructionSet - the instruction set currently being built
*/
addRenderable: (renderable: RENDERABLE, instructionSet: InstructionSet) => void;
/**
* Called whenever a renderable has been been updated, eg its position has changed.
* This is only called in the render loop if the instructions set is being reused
* from the last frame. Otherwise addRenderable is called.
* @param renderable - the renderable that needs to be rendered
*/
updateRenderable: (renderable: RENDERABLE) => void;
/**
* Called whenever a renderable is destroyed, often the pipes keep a webGL / webGPU specific representation
* of the renderable that needs to be tidied up when the renderable is destroyed.
* @param renderable - the renderable that needs to be rendered
*/
destroyRenderable: (renderable: RENDERABLE) => void;
/**
* This function is called when the renderer is determining if it can use the same instruction set again to
* improve performance. If this function returns true, the renderer will rebuild the whole instruction set
* for the scene. This is only called if the scene has not its changed its structure .
* @param renderable
* @returns {boolean}
*/
validateRenderable: (renderable: RENDERABLE) => boolean;
}
/**
* An interface for a pipe that can be used to build instructions for the renderer.
* BatchPipes are specifically used to build and render Batches.
*/
export interface BatchPipe {
/**
* Add a add a batchable object to the batch.
* @param renderable - a batchable object that can be added to the batch
* @param instructionSet - the instruction set currently being built
*/
addToBatch: (renderable: BatchableElement, instructionSet: InstructionSet) => void;
/**
* Forces the batch to break. This can happen if for example you need to render everything and then
* change the render target.
* @param instructionSet - the instruction set currently being built
*/
break: (instructionSet: InstructionSet) => void;
}
/** A helpful type that can be used to create a new RenderPipe, BatchPipe or InstructionPipe */
export interface PipeConstructor {
new (renderer: Renderer, adaptor?: any): RenderPipe | BatchPipe | InstructionPipe<any>;
}

View File

@@ -0,0 +1,4 @@
'use strict';
"use strict";
//# sourceMappingURL=RenderPipe.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"RenderPipe.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}

View File

@@ -0,0 +1,2 @@
"use strict";
//# sourceMappingURL=RenderPipe.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"RenderPipe.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}