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,4 @@
import type { Container } from '../../../scene/container/Container';
import type { View } from './view/View';
export interface Renderable extends Container, View {
}

View File

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

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,40 @@
import { ExtensionType } from '../../../extensions/Extensions';
import type { System } from './system/System';
/**
* The SchedulerSystem manages scheduled tasks with specific intervals.
* @memberof rendering
*/
export declare class SchedulerSystem implements System<null> {
/** @ignore */
static extension: {
readonly type: readonly [ExtensionType.WebGLSystem, ExtensionType.WebGPUSystem, ExtensionType.CanvasSystem];
readonly name: "scheduler";
readonly priority: 0;
};
private readonly _tasks;
/** Initializes the scheduler system and starts the ticker. */
init(): void;
/**
* Schedules a repeating task.
* @param func - The function to execute.
* @param duration - The interval duration in milliseconds.
* @returns The unique identifier for the scheduled task.
*/
repeat(func: (elapsed: number) => void, duration: number): number;
/**
* Cancels a scheduled task.
* @param id - The unique identifier of the task to cancel.
*/
cancel(id: number): void;
/**
* Updates and executes the scheduled tasks.
* @private
*/
private _update;
/**
* Destroys the scheduler system and removes all tasks.
* @internal
* @ignore
*/
destroy(): void;
}

View File

@@ -0,0 +1,83 @@
'use strict';
var Extensions = require('../../../extensions/Extensions.js');
var Ticker = require('../../../ticker/Ticker.js');
"use strict";
let uid = 1;
class SchedulerSystem {
constructor() {
this._tasks = [];
}
/** Initializes the scheduler system and starts the ticker. */
init() {
Ticker.Ticker.system.add(this._update, this);
}
/**
* Schedules a repeating task.
* @param func - The function to execute.
* @param duration - The interval duration in milliseconds.
* @returns The unique identifier for the scheduled task.
*/
repeat(func, duration) {
const id = uid++;
this._tasks.push({
func,
duration,
start: performance.now(),
last: performance.now(),
repeat: true,
id
});
return id;
}
/**
* Cancels a scheduled task.
* @param id - The unique identifier of the task to cancel.
*/
cancel(id) {
for (let i = 0; i < this._tasks.length; i++) {
if (this._tasks[i].id === id) {
this._tasks.splice(i, 1);
return;
}
}
}
/**
* Updates and executes the scheduled tasks.
* @private
*/
_update() {
const now = performance.now();
for (let i = 0; i < this._tasks.length; i++) {
const task = this._tasks[i];
if (now - task.last >= task.duration) {
const elapsed = now - task.start;
task.func(elapsed);
task.last = now;
}
}
}
/**
* Destroys the scheduler system and removes all tasks.
* @internal
* @ignore
*/
destroy() {
Ticker.Ticker.system.remove(this._update, this);
this._tasks.length = 0;
}
}
/** @ignore */
SchedulerSystem.extension = {
type: [
Extensions.ExtensionType.WebGLSystem,
Extensions.ExtensionType.WebGPUSystem,
Extensions.ExtensionType.CanvasSystem
],
name: "scheduler",
priority: 0
};
exports.SchedulerSystem = SchedulerSystem;
//# sourceMappingURL=SchedulerSystem.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"SchedulerSystem.js","sources":["../../../../src/rendering/renderers/shared/SchedulerSystem.ts"],"sourcesContent":["import { ExtensionType } from '../../../extensions/Extensions';\nimport { Ticker } from '../../../ticker/Ticker';\n\nimport type { System } from './system/System';\n\n// start at one too keep it positive!\nlet uid = 1;\n\n/**\n * The SchedulerSystem manages scheduled tasks with specific intervals.\n * @memberof rendering\n */\nexport class SchedulerSystem implements System<null>\n{\n /** @ignore */\n public static extension = {\n type: [\n ExtensionType.WebGLSystem,\n ExtensionType.WebGPUSystem,\n ExtensionType.CanvasSystem,\n ],\n name: 'scheduler',\n priority: 0,\n } as const;\n\n private readonly _tasks: {\n func: (elapsed: number) => void;\n duration: number;\n start: number;\n last: number;\n repeat: boolean;\n id: number;\n }[] = [];\n\n /** Initializes the scheduler system and starts the ticker. */\n public init(): void\n {\n Ticker.system.add(this._update, this);\n }\n\n /**\n * Schedules a repeating task.\n * @param func - The function to execute.\n * @param duration - The interval duration in milliseconds.\n * @returns The unique identifier for the scheduled task.\n */\n public repeat(func: (elapsed: number) => void, duration: number): number\n {\n const id = uid++;\n\n this._tasks.push({\n func,\n duration,\n start: performance.now(),\n last: performance.now(),\n repeat: true,\n id\n });\n\n return id;\n }\n\n /**\n * Cancels a scheduled task.\n * @param id - The unique identifier of the task to cancel.\n */\n public cancel(id: number): void\n {\n for (let i = 0; i < this._tasks.length; i++)\n {\n if (this._tasks[i].id === id)\n {\n this._tasks.splice(i, 1);\n\n return;\n }\n }\n }\n\n /**\n * Updates and executes the scheduled tasks.\n * @private\n */\n private _update(): void\n {\n const now = performance.now();\n\n for (let i = 0; i < this._tasks.length; i++)\n {\n const task = this._tasks[i];\n\n if (now - task.last >= task.duration)\n {\n const elapsed = now - task.start;\n\n task.func(elapsed);\n task.last = now;\n }\n }\n }\n\n /**\n * Destroys the scheduler system and removes all tasks.\n * @internal\n * @ignore\n */\n public destroy(): void\n {\n Ticker.system.remove(this._update, this);\n\n this._tasks.length = 0;\n }\n}\n"],"names":["Ticker","ExtensionType"],"mappings":";;;;;;AAMA,IAAI,GAAM,GAAA,CAAA,CAAA;AAMH,MAAM,eACb,CAAA;AAAA,EADO,WAAA,GAAA;AAaH,IAAA,IAAA,CAAiB,SAOX,EAAC,CAAA;AAAA,GAAA;AAAA;AAAA,EAGA,IACP,GAAA;AACI,IAAAA,aAAA,CAAO,MAAO,CAAA,GAAA,CAAI,IAAK,CAAA,OAAA,EAAS,IAAI,CAAA,CAAA;AAAA,GACxC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQO,MAAA,CAAO,MAAiC,QAC/C,EAAA;AACI,IAAA,MAAM,EAAK,GAAA,GAAA,EAAA,CAAA;AAEX,IAAA,IAAA,CAAK,OAAO,IAAK,CAAA;AAAA,MACb,IAAA;AAAA,MACA,QAAA;AAAA,MACA,KAAA,EAAO,YAAY,GAAI,EAAA;AAAA,MACvB,IAAA,EAAM,YAAY,GAAI,EAAA;AAAA,MACtB,MAAQ,EAAA,IAAA;AAAA,MACR,EAAA;AAAA,KACH,CAAA,CAAA;AAED,IAAO,OAAA,EAAA,CAAA;AAAA,GACX;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,OAAO,EACd,EAAA;AACI,IAAA,KAAA,IAAS,IAAI,CAAG,EAAA,CAAA,GAAI,IAAK,CAAA,MAAA,CAAO,QAAQ,CACxC,EAAA,EAAA;AACI,MAAA,IAAI,IAAK,CAAA,MAAA,CAAO,CAAC,CAAA,CAAE,OAAO,EAC1B,EAAA;AACI,QAAK,IAAA,CAAA,MAAA,CAAO,MAAO,CAAA,CAAA,EAAG,CAAC,CAAA,CAAA;AAEvB,QAAA,OAAA;AAAA,OACJ;AAAA,KACJ;AAAA,GACJ;AAAA;AAAA;AAAA;AAAA;AAAA,EAMQ,OACR,GAAA;AACI,IAAM,MAAA,GAAA,GAAM,YAAY,GAAI,EAAA,CAAA;AAE5B,IAAA,KAAA,IAAS,IAAI,CAAG,EAAA,CAAA,GAAI,IAAK,CAAA,MAAA,CAAO,QAAQ,CACxC,EAAA,EAAA;AACI,MAAM,MAAA,IAAA,GAAO,IAAK,CAAA,MAAA,CAAO,CAAC,CAAA,CAAA;AAE1B,MAAA,IAAI,GAAM,GAAA,IAAA,CAAK,IAAQ,IAAA,IAAA,CAAK,QAC5B,EAAA;AACI,QAAM,MAAA,OAAA,GAAU,MAAM,IAAK,CAAA,KAAA,CAAA;AAE3B,QAAA,IAAA,CAAK,KAAK,OAAO,CAAA,CAAA;AACjB,QAAA,IAAA,CAAK,IAAO,GAAA,GAAA,CAAA;AAAA,OAChB;AAAA,KACJ;AAAA,GACJ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,OACP,GAAA;AACI,IAAAA,aAAA,CAAO,MAAO,CAAA,MAAA,CAAO,IAAK,CAAA,OAAA,EAAS,IAAI,CAAA,CAAA;AAEvC,IAAA,IAAA,CAAK,OAAO,MAAS,GAAA,CAAA,CAAA;AAAA,GACzB;AACJ,CAAA;AAAA;AApGa,eAAA,CAGK,SAAY,GAAA;AAAA,EACtB,IAAM,EAAA;AAAA,IACFC,wBAAc,CAAA,WAAA;AAAA,IACdA,wBAAc,CAAA,YAAA;AAAA,IACdA,wBAAc,CAAA,YAAA;AAAA,GAClB;AAAA,EACA,IAAM,EAAA,WAAA;AAAA,EACN,QAAU,EAAA,CAAA;AACd,CAAA;;;;"}

View File

@@ -0,0 +1,81 @@
import { ExtensionType } from '../../../extensions/Extensions.mjs';
import { Ticker } from '../../../ticker/Ticker.mjs';
"use strict";
let uid = 1;
class SchedulerSystem {
constructor() {
this._tasks = [];
}
/** Initializes the scheduler system and starts the ticker. */
init() {
Ticker.system.add(this._update, this);
}
/**
* Schedules a repeating task.
* @param func - The function to execute.
* @param duration - The interval duration in milliseconds.
* @returns The unique identifier for the scheduled task.
*/
repeat(func, duration) {
const id = uid++;
this._tasks.push({
func,
duration,
start: performance.now(),
last: performance.now(),
repeat: true,
id
});
return id;
}
/**
* Cancels a scheduled task.
* @param id - The unique identifier of the task to cancel.
*/
cancel(id) {
for (let i = 0; i < this._tasks.length; i++) {
if (this._tasks[i].id === id) {
this._tasks.splice(i, 1);
return;
}
}
}
/**
* Updates and executes the scheduled tasks.
* @private
*/
_update() {
const now = performance.now();
for (let i = 0; i < this._tasks.length; i++) {
const task = this._tasks[i];
if (now - task.last >= task.duration) {
const elapsed = now - task.start;
task.func(elapsed);
task.last = now;
}
}
}
/**
* Destroys the scheduler system and removes all tasks.
* @internal
* @ignore
*/
destroy() {
Ticker.system.remove(this._update, this);
this._tasks.length = 0;
}
}
/** @ignore */
SchedulerSystem.extension = {
type: [
ExtensionType.WebGLSystem,
ExtensionType.WebGPUSystem,
ExtensionType.CanvasSystem
],
name: "scheduler",
priority: 0
};
export { SchedulerSystem };
//# sourceMappingURL=SchedulerSystem.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"SchedulerSystem.mjs","sources":["../../../../src/rendering/renderers/shared/SchedulerSystem.ts"],"sourcesContent":["import { ExtensionType } from '../../../extensions/Extensions';\nimport { Ticker } from '../../../ticker/Ticker';\n\nimport type { System } from './system/System';\n\n// start at one too keep it positive!\nlet uid = 1;\n\n/**\n * The SchedulerSystem manages scheduled tasks with specific intervals.\n * @memberof rendering\n */\nexport class SchedulerSystem implements System<null>\n{\n /** @ignore */\n public static extension = {\n type: [\n ExtensionType.WebGLSystem,\n ExtensionType.WebGPUSystem,\n ExtensionType.CanvasSystem,\n ],\n name: 'scheduler',\n priority: 0,\n } as const;\n\n private readonly _tasks: {\n func: (elapsed: number) => void;\n duration: number;\n start: number;\n last: number;\n repeat: boolean;\n id: number;\n }[] = [];\n\n /** Initializes the scheduler system and starts the ticker. */\n public init(): void\n {\n Ticker.system.add(this._update, this);\n }\n\n /**\n * Schedules a repeating task.\n * @param func - The function to execute.\n * @param duration - The interval duration in milliseconds.\n * @returns The unique identifier for the scheduled task.\n */\n public repeat(func: (elapsed: number) => void, duration: number): number\n {\n const id = uid++;\n\n this._tasks.push({\n func,\n duration,\n start: performance.now(),\n last: performance.now(),\n repeat: true,\n id\n });\n\n return id;\n }\n\n /**\n * Cancels a scheduled task.\n * @param id - The unique identifier of the task to cancel.\n */\n public cancel(id: number): void\n {\n for (let i = 0; i < this._tasks.length; i++)\n {\n if (this._tasks[i].id === id)\n {\n this._tasks.splice(i, 1);\n\n return;\n }\n }\n }\n\n /**\n * Updates and executes the scheduled tasks.\n * @private\n */\n private _update(): void\n {\n const now = performance.now();\n\n for (let i = 0; i < this._tasks.length; i++)\n {\n const task = this._tasks[i];\n\n if (now - task.last >= task.duration)\n {\n const elapsed = now - task.start;\n\n task.func(elapsed);\n task.last = now;\n }\n }\n }\n\n /**\n * Destroys the scheduler system and removes all tasks.\n * @internal\n * @ignore\n */\n public destroy(): void\n {\n Ticker.system.remove(this._update, this);\n\n this._tasks.length = 0;\n }\n}\n"],"names":[],"mappings":";;;;AAMA,IAAI,GAAM,GAAA,CAAA,CAAA;AAMH,MAAM,eACb,CAAA;AAAA,EADO,WAAA,GAAA;AAaH,IAAA,IAAA,CAAiB,SAOX,EAAC,CAAA;AAAA,GAAA;AAAA;AAAA,EAGA,IACP,GAAA;AACI,IAAA,MAAA,CAAO,MAAO,CAAA,GAAA,CAAI,IAAK,CAAA,OAAA,EAAS,IAAI,CAAA,CAAA;AAAA,GACxC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQO,MAAA,CAAO,MAAiC,QAC/C,EAAA;AACI,IAAA,MAAM,EAAK,GAAA,GAAA,EAAA,CAAA;AAEX,IAAA,IAAA,CAAK,OAAO,IAAK,CAAA;AAAA,MACb,IAAA;AAAA,MACA,QAAA;AAAA,MACA,KAAA,EAAO,YAAY,GAAI,EAAA;AAAA,MACvB,IAAA,EAAM,YAAY,GAAI,EAAA;AAAA,MACtB,MAAQ,EAAA,IAAA;AAAA,MACR,EAAA;AAAA,KACH,CAAA,CAAA;AAED,IAAO,OAAA,EAAA,CAAA;AAAA,GACX;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,OAAO,EACd,EAAA;AACI,IAAA,KAAA,IAAS,IAAI,CAAG,EAAA,CAAA,GAAI,IAAK,CAAA,MAAA,CAAO,QAAQ,CACxC,EAAA,EAAA;AACI,MAAA,IAAI,IAAK,CAAA,MAAA,CAAO,CAAC,CAAA,CAAE,OAAO,EAC1B,EAAA;AACI,QAAK,IAAA,CAAA,MAAA,CAAO,MAAO,CAAA,CAAA,EAAG,CAAC,CAAA,CAAA;AAEvB,QAAA,OAAA;AAAA,OACJ;AAAA,KACJ;AAAA,GACJ;AAAA;AAAA;AAAA;AAAA;AAAA,EAMQ,OACR,GAAA;AACI,IAAM,MAAA,GAAA,GAAM,YAAY,GAAI,EAAA,CAAA;AAE5B,IAAA,KAAA,IAAS,IAAI,CAAG,EAAA,CAAA,GAAI,IAAK,CAAA,MAAA,CAAO,QAAQ,CACxC,EAAA,EAAA;AACI,MAAM,MAAA,IAAA,GAAO,IAAK,CAAA,MAAA,CAAO,CAAC,CAAA,CAAA;AAE1B,MAAA,IAAI,GAAM,GAAA,IAAA,CAAK,IAAQ,IAAA,IAAA,CAAK,QAC5B,EAAA;AACI,QAAM,MAAA,OAAA,GAAU,MAAM,IAAK,CAAA,KAAA,CAAA;AAE3B,QAAA,IAAA,CAAK,KAAK,OAAO,CAAA,CAAA;AACjB,QAAA,IAAA,CAAK,IAAO,GAAA,GAAA,CAAA;AAAA,OAChB;AAAA,KACJ;AAAA,GACJ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,OACP,GAAA;AACI,IAAA,MAAA,CAAO,MAAO,CAAA,MAAA,CAAO,IAAK,CAAA,OAAA,EAAS,IAAI,CAAA,CAAA;AAEvC,IAAA,IAAA,CAAK,OAAO,MAAS,GAAA,CAAA,CAAA;AAAA,GACzB;AACJ,CAAA;AAAA;AApGa,eAAA,CAGK,SAAY,GAAA;AAAA,EACtB,IAAM,EAAA;AAAA,IACF,aAAc,CAAA,WAAA;AAAA,IACd,aAAc,CAAA,YAAA;AAAA,IACd,aAAc,CAAA,YAAA;AAAA,GAClB;AAAA,EACA,IAAM,EAAA,WAAA;AAAA,EACN,QAAU,EAAA,CAAA;AACd,CAAA;;;;"}

View File

@@ -0,0 +1,82 @@
import { Color } from '../../../../color/Color';
import { ExtensionType } from '../../../../extensions/Extensions';
import type { ColorSource, RgbaArray } from '../../../../color/Color';
import type { System } from '../system/System';
/**
* Options for the background system.
* @property {ColorSource} [backgroundColor='black']
* The background color used to clear the canvas. See {@link ColorSource} for accepted color values.
* @property {ColorSource} [background] - Alias for backgroundColor
* @property {number} [backgroundAlpha=1] -
* Transparency of the background color, value from `0` (fully transparent) to `1` (fully opaque).
* @property {boolean} [clearBeforeRender=true] - Whether to clear the canvas before new render passes.
* @memberof rendering
*/
export interface BackgroundSystemOptions {
/**
* The background color used to clear the canvas. See {@link ColorSource} for accepted color values.
* @memberof rendering.SharedRendererOptions
* @default 'black'
*/
backgroundColor: ColorSource;
/**
* Alias for backgroundColor
* @memberof rendering.SharedRendererOptions
*/
background?: ColorSource;
/**
* Transparency of the background color, value from `0` (fully transparent) to `1` (fully opaque).
* @memberof rendering.SharedRendererOptions
* @default 1
*/
backgroundAlpha: number;
/**
* Whether to clear the canvas before new render passes.
* @memberof rendering.SharedRendererOptions
* @default true
*/
clearBeforeRender: boolean;
}
/**
* The background system manages the background color and alpha of the main view.
* @memberof rendering
*/
export declare class BackgroundSystem implements System<BackgroundSystemOptions> {
/** @ignore */
static extension: {
readonly type: readonly [ExtensionType.WebGLSystem, ExtensionType.WebGPUSystem, ExtensionType.CanvasSystem];
readonly name: "background";
readonly priority: 0;
};
/** default options used by the system */
static defaultOptions: BackgroundSystemOptions;
/**
* This sets if the CanvasRenderer will clear the canvas or not before the new render pass.
* If the scene is NOT transparent PixiJS will use a canvas sized fillRect operation every
* frame to set the canvas background color. If the scene is transparent PixiJS will use clearRect
* to clear the canvas every frame. Disable this by setting this to false. For example, if
* your game has a canvas filling background image you often don't need this set.
*/
clearBeforeRender: boolean;
private readonly _backgroundColor;
constructor();
/**
* initiates the background system
* @param options - the options for the background colors
*/
init(options: BackgroundSystemOptions): void;
/** The background color to fill if not transparent */
get color(): Color;
set color(value: ColorSource);
/** The background color alpha. Setting this to 0 will make the canvas transparent. */
get alpha(): number;
set alpha(value: number);
/** The background color as an [R, G, B, A] array. */
get colorRgba(): RgbaArray;
/**
* destroys the background system
* @internal
* @ignore
*/
destroy(): void;
}

View File

@@ -0,0 +1,82 @@
'use strict';
var Color = require('../../../../color/Color.js');
var Extensions = require('../../../../extensions/Extensions.js');
"use strict";
const _BackgroundSystem = class _BackgroundSystem {
constructor() {
this.clearBeforeRender = true;
this._backgroundColor = new Color.Color(0);
this.color = this._backgroundColor;
this.alpha = 1;
}
/**
* initiates the background system
* @param options - the options for the background colors
*/
init(options) {
options = { ..._BackgroundSystem.defaultOptions, ...options };
this.clearBeforeRender = options.clearBeforeRender;
this.color = options.background || options.backgroundColor || this._backgroundColor;
this.alpha = options.backgroundAlpha;
this._backgroundColor.setAlpha(options.backgroundAlpha);
}
/** The background color to fill if not transparent */
get color() {
return this._backgroundColor;
}
set color(value) {
this._backgroundColor.setValue(value);
}
/** The background color alpha. Setting this to 0 will make the canvas transparent. */
get alpha() {
return this._backgroundColor.alpha;
}
set alpha(value) {
this._backgroundColor.setAlpha(value);
}
/** The background color as an [R, G, B, A] array. */
get colorRgba() {
return this._backgroundColor.toArray();
}
/**
* destroys the background system
* @internal
* @ignore
*/
destroy() {
}
};
/** @ignore */
_BackgroundSystem.extension = {
type: [
Extensions.ExtensionType.WebGLSystem,
Extensions.ExtensionType.WebGPUSystem,
Extensions.ExtensionType.CanvasSystem
],
name: "background",
priority: 0
};
/** default options used by the system */
_BackgroundSystem.defaultOptions = {
/**
* {@link WebGLOptions.backgroundAlpha}
* @default 1
*/
backgroundAlpha: 1,
/**
* {@link WebGLOptions.backgroundColor}
* @default 0x000000
*/
backgroundColor: 0,
/**
* {@link WebGLOptions.clearBeforeRender}
* @default true
*/
clearBeforeRender: true
};
let BackgroundSystem = _BackgroundSystem;
exports.BackgroundSystem = BackgroundSystem;
//# sourceMappingURL=BackgroundSystem.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,80 @@
import { Color } from '../../../../color/Color.mjs';
import { ExtensionType } from '../../../../extensions/Extensions.mjs';
"use strict";
const _BackgroundSystem = class _BackgroundSystem {
constructor() {
this.clearBeforeRender = true;
this._backgroundColor = new Color(0);
this.color = this._backgroundColor;
this.alpha = 1;
}
/**
* initiates the background system
* @param options - the options for the background colors
*/
init(options) {
options = { ..._BackgroundSystem.defaultOptions, ...options };
this.clearBeforeRender = options.clearBeforeRender;
this.color = options.background || options.backgroundColor || this._backgroundColor;
this.alpha = options.backgroundAlpha;
this._backgroundColor.setAlpha(options.backgroundAlpha);
}
/** The background color to fill if not transparent */
get color() {
return this._backgroundColor;
}
set color(value) {
this._backgroundColor.setValue(value);
}
/** The background color alpha. Setting this to 0 will make the canvas transparent. */
get alpha() {
return this._backgroundColor.alpha;
}
set alpha(value) {
this._backgroundColor.setAlpha(value);
}
/** The background color as an [R, G, B, A] array. */
get colorRgba() {
return this._backgroundColor.toArray();
}
/**
* destroys the background system
* @internal
* @ignore
*/
destroy() {
}
};
/** @ignore */
_BackgroundSystem.extension = {
type: [
ExtensionType.WebGLSystem,
ExtensionType.WebGPUSystem,
ExtensionType.CanvasSystem
],
name: "background",
priority: 0
};
/** default options used by the system */
_BackgroundSystem.defaultOptions = {
/**
* {@link WebGLOptions.backgroundAlpha}
* @default 1
*/
backgroundAlpha: 1,
/**
* {@link WebGLOptions.backgroundColor}
* @default 0x000000
*/
backgroundColor: 0,
/**
* {@link WebGLOptions.clearBeforeRender}
* @default true
*/
clearBeforeRender: true
};
let BackgroundSystem = _BackgroundSystem;
export { BackgroundSystem };
//# sourceMappingURL=BackgroundSystem.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,66 @@
import { ExtensionType } from '../../../../extensions/Extensions';
import type { Renderer } from '../../types';
import type { Instruction } from '../instructions/Instruction';
import type { InstructionSet } from '../instructions/InstructionSet';
import type { InstructionPipe } from '../instructions/RenderPipe';
import type { Renderable } from '../Renderable';
import type { BLEND_MODES } from '../state/const';
interface AdvancedBlendInstruction extends Instruction {
renderPipeId: 'blendMode';
blendMode: BLEND_MODES;
activeBlend: Renderable[];
}
/**
* This Pipe handles the blend mode switching of the renderer.
* It will insert instructions into the {@link renderers.InstructionSet} to switch the blend mode according to the
* blend modes of the scene graph.
*
* This pipe is were wwe handle Advanced blend modes. Advanced blend modes essentially wrap the renderables
* in a filter that applies the blend mode.
*
* You only need to use this class if you are building your own render instruction set rather than letting PixiJS build
* the instruction set for you by traversing the scene graph
* @memberof rendering
*/
export declare class BlendModePipe implements InstructionPipe<AdvancedBlendInstruction> {
/** @ignore */
static extension: {
readonly type: readonly [ExtensionType.WebGLPipes, ExtensionType.WebGPUPipes, ExtensionType.CanvasPipes];
readonly name: "blendMode";
};
private _renderer;
private _renderableList;
private _activeBlendMode;
private _isAdvanced;
private _filterHash;
constructor(renderer: Renderer);
/**
* This ensures that a blendMode switch is added to the instruction set if the blend mode has changed.
* @param renderable - The renderable we are adding to the instruction set
* @param blendMode - The blend mode of the renderable
* @param instructionSet - The instruction set we are adding to
*/
setBlendMode(renderable: Renderable, blendMode: BLEND_MODES, instructionSet: InstructionSet): void;
private _beginAdvancedBlendMode;
private _endAdvancedBlendMode;
/**
* called when the instruction build process is starting this will reset internally to the default blend mode
* @internal
* @ignore
*/
buildStart(): void;
/**
* called when the instruction build process is finished, ensuring that if there is an advanced blend mode
* active, we add the final render instructions added to the instruction set
* @param instructionSet - The instruction set we are adding to
* @internal
* @ignore
*/
buildEnd(instructionSet: InstructionSet): void;
/**
* @internal
* @ignore
*/
destroy(): void;
}
export {};

View File

@@ -0,0 +1,120 @@
'use strict';
var Extensions = require('../../../../extensions/Extensions.js');
var FilterEffect = require('../../../../filters/FilterEffect.js');
var warn = require('../../../../utils/logging/warn.js');
"use strict";
const BLEND_MODE_FILTERS = {};
Extensions.extensions.handle(Extensions.ExtensionType.BlendMode, (value) => {
if (!value.name) {
throw new Error("BlendMode extension must have a name property");
}
BLEND_MODE_FILTERS[value.name] = value.ref;
}, (value) => {
delete BLEND_MODE_FILTERS[value.name];
});
class BlendModePipe {
constructor(renderer) {
this._isAdvanced = false;
this._filterHash = /* @__PURE__ */ Object.create(null);
this._renderer = renderer;
}
/**
* This ensures that a blendMode switch is added to the instruction set if the blend mode has changed.
* @param renderable - The renderable we are adding to the instruction set
* @param blendMode - The blend mode of the renderable
* @param instructionSet - The instruction set we are adding to
*/
setBlendMode(renderable, blendMode, instructionSet) {
if (this._activeBlendMode === blendMode) {
if (this._isAdvanced)
this._renderableList.push(renderable);
return;
}
this._activeBlendMode = blendMode;
if (this._isAdvanced) {
this._endAdvancedBlendMode(instructionSet);
}
this._isAdvanced = !!BLEND_MODE_FILTERS[blendMode];
if (this._isAdvanced) {
this._beginAdvancedBlendMode(instructionSet);
this._renderableList.push(renderable);
}
}
_beginAdvancedBlendMode(instructionSet) {
this._renderer.renderPipes.batch.break(instructionSet);
const blendMode = this._activeBlendMode;
if (!BLEND_MODE_FILTERS[blendMode]) {
warn.warn(`Unable to assign BlendMode: '${blendMode}'. You may want to include: import 'pixi.js/advanced-blend-modes'`);
return;
}
let filterEffect = this._filterHash[blendMode];
if (!filterEffect) {
filterEffect = this._filterHash[blendMode] = new FilterEffect.FilterEffect();
filterEffect.filters = [new BLEND_MODE_FILTERS[blendMode]()];
}
const instruction = {
renderPipeId: "filter",
action: "pushFilter",
renderables: [],
filterEffect,
canBundle: false
};
this._renderableList = instruction.renderables;
instructionSet.add(instruction);
}
_endAdvancedBlendMode(instructionSet) {
this._renderableList = null;
this._renderer.renderPipes.batch.break(instructionSet);
instructionSet.add({
renderPipeId: "filter",
action: "popFilter",
canBundle: false
});
}
/**
* called when the instruction build process is starting this will reset internally to the default blend mode
* @internal
* @ignore
*/
buildStart() {
this._isAdvanced = false;
}
/**
* called when the instruction build process is finished, ensuring that if there is an advanced blend mode
* active, we add the final render instructions added to the instruction set
* @param instructionSet - The instruction set we are adding to
* @internal
* @ignore
*/
buildEnd(instructionSet) {
if (this._isAdvanced) {
this._endAdvancedBlendMode(instructionSet);
}
}
/**
* @internal
* @ignore
*/
destroy() {
this._renderer = null;
this._renderableList = null;
for (const i in this._filterHash) {
this._filterHash[i].destroy();
}
this._filterHash = null;
}
}
/** @ignore */
BlendModePipe.extension = {
type: [
Extensions.ExtensionType.WebGLPipes,
Extensions.ExtensionType.WebGPUPipes,
Extensions.ExtensionType.CanvasPipes
],
name: "blendMode"
};
exports.BlendModePipe = BlendModePipe;
//# sourceMappingURL=BlendModePipe.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,118 @@
import { extensions, ExtensionType } from '../../../../extensions/Extensions.mjs';
import { FilterEffect } from '../../../../filters/FilterEffect.mjs';
import { warn } from '../../../../utils/logging/warn.mjs';
"use strict";
const BLEND_MODE_FILTERS = {};
extensions.handle(ExtensionType.BlendMode, (value) => {
if (!value.name) {
throw new Error("BlendMode extension must have a name property");
}
BLEND_MODE_FILTERS[value.name] = value.ref;
}, (value) => {
delete BLEND_MODE_FILTERS[value.name];
});
class BlendModePipe {
constructor(renderer) {
this._isAdvanced = false;
this._filterHash = /* @__PURE__ */ Object.create(null);
this._renderer = renderer;
}
/**
* This ensures that a blendMode switch is added to the instruction set if the blend mode has changed.
* @param renderable - The renderable we are adding to the instruction set
* @param blendMode - The blend mode of the renderable
* @param instructionSet - The instruction set we are adding to
*/
setBlendMode(renderable, blendMode, instructionSet) {
if (this._activeBlendMode === blendMode) {
if (this._isAdvanced)
this._renderableList.push(renderable);
return;
}
this._activeBlendMode = blendMode;
if (this._isAdvanced) {
this._endAdvancedBlendMode(instructionSet);
}
this._isAdvanced = !!BLEND_MODE_FILTERS[blendMode];
if (this._isAdvanced) {
this._beginAdvancedBlendMode(instructionSet);
this._renderableList.push(renderable);
}
}
_beginAdvancedBlendMode(instructionSet) {
this._renderer.renderPipes.batch.break(instructionSet);
const blendMode = this._activeBlendMode;
if (!BLEND_MODE_FILTERS[blendMode]) {
warn(`Unable to assign BlendMode: '${blendMode}'. You may want to include: import 'pixi.js/advanced-blend-modes'`);
return;
}
let filterEffect = this._filterHash[blendMode];
if (!filterEffect) {
filterEffect = this._filterHash[blendMode] = new FilterEffect();
filterEffect.filters = [new BLEND_MODE_FILTERS[blendMode]()];
}
const instruction = {
renderPipeId: "filter",
action: "pushFilter",
renderables: [],
filterEffect,
canBundle: false
};
this._renderableList = instruction.renderables;
instructionSet.add(instruction);
}
_endAdvancedBlendMode(instructionSet) {
this._renderableList = null;
this._renderer.renderPipes.batch.break(instructionSet);
instructionSet.add({
renderPipeId: "filter",
action: "popFilter",
canBundle: false
});
}
/**
* called when the instruction build process is starting this will reset internally to the default blend mode
* @internal
* @ignore
*/
buildStart() {
this._isAdvanced = false;
}
/**
* called when the instruction build process is finished, ensuring that if there is an advanced blend mode
* active, we add the final render instructions added to the instruction set
* @param instructionSet - The instruction set we are adding to
* @internal
* @ignore
*/
buildEnd(instructionSet) {
if (this._isAdvanced) {
this._endAdvancedBlendMode(instructionSet);
}
}
/**
* @internal
* @ignore
*/
destroy() {
this._renderer = null;
this._renderableList = null;
for (const i in this._filterHash) {
this._filterHash[i].destroy();
}
this._filterHash = null;
}
}
/** @ignore */
BlendModePipe.extension = {
type: [
ExtensionType.WebGLPipes,
ExtensionType.WebGPUPipes,
ExtensionType.CanvasPipes
],
name: "blendMode"
};
export { BlendModePipe };
//# sourceMappingURL=BlendModePipe.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,165 @@
/// <reference types="@webgpu/types" />
import EventEmitter from 'eventemitter3';
import { BufferUsage } from './const';
import type { BindResource } from '../../gpu/shader/BindResource';
/** All the various typed arrays that exist in js */
export type TypedArray = Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array;
/** Options for creating a buffer */
export interface BufferOptions {
/**
* the data to initialize the buffer with, this can be a typed array,
* or a regular number array. If it is a number array, it will be converted to a Float32Array
*/
data?: TypedArray | number[];
/** the size of the buffer in bytes, if not supplied, it will be inferred from the data */
size?: number;
/** the usage of the buffer, see {@link rendering.BufferUsage} */
usage: number;
/** a label for the buffer, this is useful for debugging */
label?: string;
/**
* should the GPU buffer be shrunk when the data becomes smaller?
* changing this will cause the buffer to be destroyed and a new one created on the GPU
* this can be expensive, especially if the buffer is already big enough!
* setting this to false will prevent the buffer from being shrunk. This will yield better performance
* if you are constantly setting data that is changing size often.
* @default true
*/
shrinkToFit?: boolean;
}
export interface BufferDescriptor {
label?: string;
size: GPUSize64;
usage: BufferUsage;
mappedAtCreation?: boolean;
}
/**
* A wrapper for a WebGPU/WebGL Buffer.
* In PixiJS, the Buffer class is used to manage the data that is sent to the GPU rendering pipeline.
* It abstracts away the underlying GPU buffer and provides an interface for uploading typed arrays or other data to the GPU,
* They are used in the following places:
* <br><br>
* .1. {@link Geometry} as attribute data or index data for geometry
* <br>
* .2. {@link UniformGroup} as an underlying buffer for uniform data
* <br>
* .3. {@link BufferResource} as an underlying part of a buffer used directly by the GPU program
* <br>
*
* It is important to note that you must provide a usage type when creating a buffer. This is because
* the underlying GPU buffer needs to know how it will be used. For example, if you are creating a buffer
* to hold vertex data, you would use `BufferUsage.VERTEX`. This will tell the GPU that this buffer will be
* used as a vertex buffer. This is important because it will affect how you can use the buffer.
*
* Buffers are updated by calling the {@link Buffer.update} method. This immediately updates the buffer on the GPU.
* Be mindful of calling this more often than you need to. It is recommended to update buffers only when needed.
*
* In WebGPU, a GPU buffer cannot resized. This limitation is abstracted away, but know that resizing a buffer means
* creating a brand new one and destroying the old, so it is best to limit this if possible.
* @example
*
* const buffer = new Buffer({
* data: new Float32Array([1, 2, 3, 4]),
* usage: BufferUsage.VERTEX,
* });
* @memberof rendering
*/
export declare class Buffer extends EventEmitter<{
change: BindResource;
update: Buffer;
destroy: Buffer;
}> implements BindResource {
/**
* emits when the underlying buffer has changed shape (i.e. resized)
* letting the renderer know that it needs to discard the old buffer on the GPU and create a new one
* @event change
*/
/**
* emits when the underlying buffer data has been updated. letting the renderer know
* that it needs to update the buffer on the GPU
* @event update
*/
/**
* emits when the buffer is destroyed. letting the renderer know that it needs to destroy the buffer on the GPU
* @event destroy
*/
/** a unique id for this uniform group used through the renderer */
readonly uid: number;
/**
* a resource type, used to identify how to handle it when its in a bind group / shader resource
* @internal
* @ignore
*/
readonly _resourceType = "buffer";
/**
* the resource id used internally by the renderer to build bind group keys
* @internal
* @ignore
*/
_resourceId: number;
/**
* used internally to know if a uniform group was used in the last render pass
* @internal
* @ignore
*/
_touched: number;
/**
* a description of the buffer and how it should be set up on the GPU
* @internal
* @ignore
*/
readonly descriptor: BufferDescriptor;
/**
* @internal
* @ignore
*/
_updateID: number;
/**
* @internal
* @ignore
*/
_updateSize: number;
private _data;
/**
* should the GPU buffer be shrunk when the data becomes smaller?
* changing this will cause the buffer to be destroyed and a new one created on the GPU
* this can be expensive, especially if the buffer is already big enough!
* setting this to false will prevent the buffer from being shrunk. This will yield better performance
* if you are constantly setting data that is changing size often.
* @default true
*/
shrinkToFit: boolean;
/**
* Has the buffer been destroyed?
* @readonly
*/
destroyed: boolean;
/**
* Creates a new Buffer with the given options
* @param options - the options for the buffer
*/
constructor(options: BufferOptions);
/** the data in the buffer */
get data(): TypedArray;
set data(value: TypedArray);
/** whether the buffer is static or not */
get static(): boolean;
set static(value: boolean);
/**
* Sets the data in the buffer to the given value. This will immediately update the buffer on the GPU.
* If you only want to update a subset of the buffer, you can pass in the size of the data.
* @param value - the data to set
* @param size - the size of the data in bytes
* @param syncGPU - should the buffer be updated on the GPU immediately?
*/
setDataWithSize(value: TypedArray, size: number, syncGPU: boolean): void;
/**
* updates the buffer on the GPU to reflect the data in the buffer.
* By default it will update the entire buffer. If you only want to update a subset of the buffer,
* you can pass in the size of the buffer to update.
* @param sizeInBytes - the new size of the buffer in bytes
*/
update(sizeInBytes?: number): void;
/** Destroys the buffer */
destroy(): void;
}

View File

@@ -0,0 +1,156 @@
'use strict';
var EventEmitter = require('eventemitter3');
var uid = require('../../../../utils/data/uid.js');
var _const = require('./const.js');
"use strict";
class Buffer extends EventEmitter {
/**
* Creates a new Buffer with the given options
* @param options - the options for the buffer
*/
constructor(options) {
let { data, size } = options;
const { usage, label, shrinkToFit } = options;
super();
/**
* emits when the underlying buffer has changed shape (i.e. resized)
* letting the renderer know that it needs to discard the old buffer on the GPU and create a new one
* @event change
*/
/**
* emits when the underlying buffer data has been updated. letting the renderer know
* that it needs to update the buffer on the GPU
* @event update
*/
/**
* emits when the buffer is destroyed. letting the renderer know that it needs to destroy the buffer on the GPU
* @event destroy
*/
/** a unique id for this uniform group used through the renderer */
this.uid = uid.uid("buffer");
/**
* a resource type, used to identify how to handle it when its in a bind group / shader resource
* @internal
* @ignore
*/
this._resourceType = "buffer";
/**
* the resource id used internally by the renderer to build bind group keys
* @internal
* @ignore
*/
this._resourceId = uid.uid("resource");
/**
* used internally to know if a uniform group was used in the last render pass
* @internal
* @ignore
*/
this._touched = 0;
/**
* @internal
* @ignore
*/
this._updateID = 1;
/**
* should the GPU buffer be shrunk when the data becomes smaller?
* changing this will cause the buffer to be destroyed and a new one created on the GPU
* this can be expensive, especially if the buffer is already big enough!
* setting this to false will prevent the buffer from being shrunk. This will yield better performance
* if you are constantly setting data that is changing size often.
* @default true
*/
this.shrinkToFit = true;
/**
* Has the buffer been destroyed?
* @readonly
*/
this.destroyed = false;
if (data instanceof Array) {
data = new Float32Array(data);
}
this._data = data;
size = size ?? data?.byteLength;
const mappedAtCreation = !!data;
this.descriptor = {
size,
usage,
mappedAtCreation,
label
};
this.shrinkToFit = shrinkToFit ?? true;
}
/** the data in the buffer */
get data() {
return this._data;
}
set data(value) {
this.setDataWithSize(value, value.length, true);
}
/** whether the buffer is static or not */
get static() {
return !!(this.descriptor.usage & _const.BufferUsage.STATIC);
}
set static(value) {
if (value) {
this.descriptor.usage |= _const.BufferUsage.STATIC;
} else {
this.descriptor.usage &= ~_const.BufferUsage.STATIC;
}
}
/**
* Sets the data in the buffer to the given value. This will immediately update the buffer on the GPU.
* If you only want to update a subset of the buffer, you can pass in the size of the data.
* @param value - the data to set
* @param size - the size of the data in bytes
* @param syncGPU - should the buffer be updated on the GPU immediately?
*/
setDataWithSize(value, size, syncGPU) {
this._updateID++;
this._updateSize = size * value.BYTES_PER_ELEMENT;
if (this._data === value) {
if (syncGPU)
this.emit("update", this);
return;
}
const oldData = this._data;
this._data = value;
if (oldData.length !== value.length) {
if (!this.shrinkToFit && value.byteLength < oldData.byteLength) {
if (syncGPU)
this.emit("update", this);
} else {
this.descriptor.size = value.byteLength;
this._resourceId = uid.uid("resource");
this.emit("change", this);
}
return;
}
if (syncGPU)
this.emit("update", this);
}
/**
* updates the buffer on the GPU to reflect the data in the buffer.
* By default it will update the entire buffer. If you only want to update a subset of the buffer,
* you can pass in the size of the buffer to update.
* @param sizeInBytes - the new size of the buffer in bytes
*/
update(sizeInBytes) {
this._updateSize = sizeInBytes ?? this._updateSize;
this._updateID++;
this.emit("update", this);
}
/** Destroys the buffer */
destroy() {
this.destroyed = true;
this.emit("destroy", this);
this.emit("change", this);
this._data = null;
this.descriptor = null;
this.removeAllListeners();
}
}
exports.Buffer = Buffer;
//# sourceMappingURL=Buffer.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,154 @@
import EventEmitter from 'eventemitter3';
import { uid } from '../../../../utils/data/uid.mjs';
import { BufferUsage } from './const.mjs';
"use strict";
class Buffer extends EventEmitter {
/**
* Creates a new Buffer with the given options
* @param options - the options for the buffer
*/
constructor(options) {
let { data, size } = options;
const { usage, label, shrinkToFit } = options;
super();
/**
* emits when the underlying buffer has changed shape (i.e. resized)
* letting the renderer know that it needs to discard the old buffer on the GPU and create a new one
* @event change
*/
/**
* emits when the underlying buffer data has been updated. letting the renderer know
* that it needs to update the buffer on the GPU
* @event update
*/
/**
* emits when the buffer is destroyed. letting the renderer know that it needs to destroy the buffer on the GPU
* @event destroy
*/
/** a unique id for this uniform group used through the renderer */
this.uid = uid("buffer");
/**
* a resource type, used to identify how to handle it when its in a bind group / shader resource
* @internal
* @ignore
*/
this._resourceType = "buffer";
/**
* the resource id used internally by the renderer to build bind group keys
* @internal
* @ignore
*/
this._resourceId = uid("resource");
/**
* used internally to know if a uniform group was used in the last render pass
* @internal
* @ignore
*/
this._touched = 0;
/**
* @internal
* @ignore
*/
this._updateID = 1;
/**
* should the GPU buffer be shrunk when the data becomes smaller?
* changing this will cause the buffer to be destroyed and a new one created on the GPU
* this can be expensive, especially if the buffer is already big enough!
* setting this to false will prevent the buffer from being shrunk. This will yield better performance
* if you are constantly setting data that is changing size often.
* @default true
*/
this.shrinkToFit = true;
/**
* Has the buffer been destroyed?
* @readonly
*/
this.destroyed = false;
if (data instanceof Array) {
data = new Float32Array(data);
}
this._data = data;
size = size ?? data?.byteLength;
const mappedAtCreation = !!data;
this.descriptor = {
size,
usage,
mappedAtCreation,
label
};
this.shrinkToFit = shrinkToFit ?? true;
}
/** the data in the buffer */
get data() {
return this._data;
}
set data(value) {
this.setDataWithSize(value, value.length, true);
}
/** whether the buffer is static or not */
get static() {
return !!(this.descriptor.usage & BufferUsage.STATIC);
}
set static(value) {
if (value) {
this.descriptor.usage |= BufferUsage.STATIC;
} else {
this.descriptor.usage &= ~BufferUsage.STATIC;
}
}
/**
* Sets the data in the buffer to the given value. This will immediately update the buffer on the GPU.
* If you only want to update a subset of the buffer, you can pass in the size of the data.
* @param value - the data to set
* @param size - the size of the data in bytes
* @param syncGPU - should the buffer be updated on the GPU immediately?
*/
setDataWithSize(value, size, syncGPU) {
this._updateID++;
this._updateSize = size * value.BYTES_PER_ELEMENT;
if (this._data === value) {
if (syncGPU)
this.emit("update", this);
return;
}
const oldData = this._data;
this._data = value;
if (oldData.length !== value.length) {
if (!this.shrinkToFit && value.byteLength < oldData.byteLength) {
if (syncGPU)
this.emit("update", this);
} else {
this.descriptor.size = value.byteLength;
this._resourceId = uid("resource");
this.emit("change", this);
}
return;
}
if (syncGPU)
this.emit("update", this);
}
/**
* updates the buffer on the GPU to reflect the data in the buffer.
* By default it will update the entire buffer. If you only want to update a subset of the buffer,
* you can pass in the size of the buffer to update.
* @param sizeInBytes - the new size of the buffer in bytes
*/
update(sizeInBytes) {
this._updateSize = sizeInBytes ?? this._updateSize;
this._updateID++;
this.emit("update", this);
}
/** Destroys the buffer */
destroy() {
this.destroyed = true;
this.emit("destroy", this);
this.emit("change", this);
this._data = null;
this.descriptor = null;
this.removeAllListeners();
}
}
export { Buffer };
//# sourceMappingURL=Buffer.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,90 @@
import EventEmitter from 'eventemitter3';
import type { BindResource } from '../../gpu/shader/BindResource';
import type { Buffer } from './Buffer';
/**
* A resource that can be bound to a bind group and used in a shader.
* Whilst a buffer can be used as a resource, this class allows you to specify an offset and size of the buffer to use.
* This is useful if you have a large buffer and only part of it is used in a shader.
*
* This resource, will listen for changes on the underlying buffer and emit a itself if the buffer changes shape.
* @example
*
* const buffer = new Buffer({
* data: new Float32Array(1000),
* usage: BufferUsage.UNIFORM,
* });
* // Create a buffer resource that uses the first 100 bytes of a buffer
* const bufferResource = new BufferResource({
* buffer,
* offset: 0,
* size: 100,
* });
* @memberof rendering
*/
export declare class BufferResource extends EventEmitter<{
change: BindResource;
}> implements BindResource {
/**
* emits when the underlying buffer has changed shape (i.e. resized)
* letting the renderer know that it needs to discard the old buffer on the GPU and create a new one
* @event change
*/
/** a unique id for this uniform group used through the renderer */
readonly uid: number;
/**
* a resource type, used to identify how to handle it when its in a bind group / shader resource
* @internal
* @ignore
*/
readonly _resourceType = "bufferResource";
/**
* used internally to know if a uniform group was used in the last render pass
* @internal
* @ignore
*/
_touched: number;
/**
* the resource id used internally by the renderer to build bind group keys
* @internal
* @ignore
*/
_resourceId: number;
/** the underlying buffer that this resource is using */
buffer: Buffer;
/** the offset of the buffer this resource is using. If not provided, then it will use the offset of the buffer. */
readonly offset: number;
/** the size of the buffer this resource is using. If not provided, then it will use the size of the buffer. */
readonly size: number;
/**
* A cheeky hint to the GL renderer to let it know this is a BufferResource
* @internal
* @ignore
*/
readonly _bufferResource = true;
/**
* Has the Buffer resource been destroyed?
* @readonly
*/
destroyed: boolean;
/**
* Create a new Buffer Resource.
* @param options - The options for the buffer resource
* @param options.buffer - The underlying buffer that this resource is using
* @param options.offset - The offset of the buffer this resource is using.
* If not provided, then it will use the offset of the buffer.
* @param options.size - The size of the buffer this resource is using.
* If not provided, then it will use the size of the buffer.
*/
constructor({ buffer, offset, size }: {
buffer: Buffer;
offset?: number;
size?: number;
});
protected onBufferChange(): void;
/**
* Destroys this resource. Make sure the underlying buffer is not used anywhere else
* if you want to destroy it as well, or code will explode
* @param destroyBuffer - Should the underlying buffer be destroyed as well?
*/
destroy(destroyBuffer?: boolean): void;
}

View File

@@ -0,0 +1,80 @@
'use strict';
var EventEmitter = require('eventemitter3');
var uid = require('../../../../utils/data/uid.js');
"use strict";
class BufferResource extends EventEmitter {
/**
* Create a new Buffer Resource.
* @param options - The options for the buffer resource
* @param options.buffer - The underlying buffer that this resource is using
* @param options.offset - The offset of the buffer this resource is using.
* If not provided, then it will use the offset of the buffer.
* @param options.size - The size of the buffer this resource is using.
* If not provided, then it will use the size of the buffer.
*/
constructor({ buffer, offset, size }) {
super();
/**
* emits when the underlying buffer has changed shape (i.e. resized)
* letting the renderer know that it needs to discard the old buffer on the GPU and create a new one
* @event change
*/
/** a unique id for this uniform group used through the renderer */
this.uid = uid.uid("buffer");
/**
* a resource type, used to identify how to handle it when its in a bind group / shader resource
* @internal
* @ignore
*/
this._resourceType = "bufferResource";
/**
* used internally to know if a uniform group was used in the last render pass
* @internal
* @ignore
*/
this._touched = 0;
/**
* the resource id used internally by the renderer to build bind group keys
* @internal
* @ignore
*/
this._resourceId = uid.uid("resource");
/**
* A cheeky hint to the GL renderer to let it know this is a BufferResource
* @internal
* @ignore
*/
this._bufferResource = true;
/**
* Has the Buffer resource been destroyed?
* @readonly
*/
this.destroyed = false;
this.buffer = buffer;
this.offset = offset | 0;
this.size = size;
this.buffer.on("change", this.onBufferChange, this);
}
onBufferChange() {
this._resourceId = uid.uid("resource");
this.emit("change", this);
}
/**
* Destroys this resource. Make sure the underlying buffer is not used anywhere else
* if you want to destroy it as well, or code will explode
* @param destroyBuffer - Should the underlying buffer be destroyed as well?
*/
destroy(destroyBuffer = false) {
this.destroyed = true;
if (destroyBuffer) {
this.buffer.destroy();
}
this.emit("change", this);
this.buffer = null;
}
}
exports.BufferResource = BufferResource;
//# sourceMappingURL=BufferResource.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,78 @@
import EventEmitter from 'eventemitter3';
import { uid } from '../../../../utils/data/uid.mjs';
"use strict";
class BufferResource extends EventEmitter {
/**
* Create a new Buffer Resource.
* @param options - The options for the buffer resource
* @param options.buffer - The underlying buffer that this resource is using
* @param options.offset - The offset of the buffer this resource is using.
* If not provided, then it will use the offset of the buffer.
* @param options.size - The size of the buffer this resource is using.
* If not provided, then it will use the size of the buffer.
*/
constructor({ buffer, offset, size }) {
super();
/**
* emits when the underlying buffer has changed shape (i.e. resized)
* letting the renderer know that it needs to discard the old buffer on the GPU and create a new one
* @event change
*/
/** a unique id for this uniform group used through the renderer */
this.uid = uid("buffer");
/**
* a resource type, used to identify how to handle it when its in a bind group / shader resource
* @internal
* @ignore
*/
this._resourceType = "bufferResource";
/**
* used internally to know if a uniform group was used in the last render pass
* @internal
* @ignore
*/
this._touched = 0;
/**
* the resource id used internally by the renderer to build bind group keys
* @internal
* @ignore
*/
this._resourceId = uid("resource");
/**
* A cheeky hint to the GL renderer to let it know this is a BufferResource
* @internal
* @ignore
*/
this._bufferResource = true;
/**
* Has the Buffer resource been destroyed?
* @readonly
*/
this.destroyed = false;
this.buffer = buffer;
this.offset = offset | 0;
this.size = size;
this.buffer.on("change", this.onBufferChange, this);
}
onBufferChange() {
this._resourceId = uid("resource");
this.emit("change", this);
}
/**
* Destroys this resource. Make sure the underlying buffer is not used anywhere else
* if you want to destroy it as well, or code will explode
* @param destroyBuffer - Should the underlying buffer be destroyed as well?
*/
destroy(destroyBuffer = false) {
this.destroyed = true;
if (destroyBuffer) {
this.buffer.destroy();
}
this.emit("change", this);
this.buffer = null;
}
}
export { BufferResource };
//# sourceMappingURL=BufferResource.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,54 @@
/**
* Buffer usage flags. they can be combined using the bitwise OR operator
* eg : BufferUsage.VERTEX | BufferUsage.INDEX
* @memberof rendering
*/
export declare enum BufferUsage {
/**
* The buffer can be mapped for reading. (Example: calling mapAsync() with GPUMapMode.READ)
* May only be combined with COPY_DST.
*/
MAP_READ = 1,
/**
* The buffer can be mapped for writing. (Example: calling mapAsync() with GPUMapMode.WRITE)
* May only be combined with COPY_SRC.
*/
MAP_WRITE = 2,
/**
* The buffer can be used as the source of a copy operation.
* (Examples: as the source argument of a copyBufferToBuffer() or copyBufferToTexture() call.)
*/
COPY_SRC = 4,
/**
* The buffer can be used as the destination of a copy or write operation.
* (Examples: as the destination argument of a copyBufferToBuffer() or
* copyTextureToBuffer() call, or as the target of a writeBuffer() call.)
*/
COPY_DST = 8,
/** The buffer can be used as an index buffer. (Example: passed to setIndexBuffer().) */
INDEX = 16,
/** The buffer can be used as a vertex buffer. (Example: passed to setVertexBuffer().) */
VERTEX = 32,
/**
* The buffer can be used as a uniform buffer.
* (Example: as a bind group entry for a GPUBufferBindingLayout with a buffer.type of "uniform".)
*/
UNIFORM = 64,
/**
* The buffer can be used as a storage buffer.
* (Example: as a bind group entry for a GPUBufferBindingLayout with a buffer.type of "storage" or "read-only-storage".)
*/
STORAGE = 128,
/**
* The buffer can be used as to store indirect command arguments.
* (Examples: as the indirectBuffer argument of a drawIndirect() or dispatchWorkgroupsIndirect() call.)
*/
INDIRECT = 256,
/**
* The buffer can be used to capture query results.
* (Example: as the destination argument of a resolveQuerySet() call.)
*/
QUERY_RESOLVE = 512,
/** the buffer will not be updated frequently */
STATIC = 1024
}

View File

@@ -0,0 +1,20 @@
'use strict';
"use strict";
var BufferUsage = /* @__PURE__ */ ((BufferUsage2) => {
BufferUsage2[BufferUsage2["MAP_READ"] = 1] = "MAP_READ";
BufferUsage2[BufferUsage2["MAP_WRITE"] = 2] = "MAP_WRITE";
BufferUsage2[BufferUsage2["COPY_SRC"] = 4] = "COPY_SRC";
BufferUsage2[BufferUsage2["COPY_DST"] = 8] = "COPY_DST";
BufferUsage2[BufferUsage2["INDEX"] = 16] = "INDEX";
BufferUsage2[BufferUsage2["VERTEX"] = 32] = "VERTEX";
BufferUsage2[BufferUsage2["UNIFORM"] = 64] = "UNIFORM";
BufferUsage2[BufferUsage2["STORAGE"] = 128] = "STORAGE";
BufferUsage2[BufferUsage2["INDIRECT"] = 256] = "INDIRECT";
BufferUsage2[BufferUsage2["QUERY_RESOLVE"] = 512] = "QUERY_RESOLVE";
BufferUsage2[BufferUsage2["STATIC"] = 1024] = "STATIC";
return BufferUsage2;
})(BufferUsage || {});
exports.BufferUsage = BufferUsage;
//# sourceMappingURL=const.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"const.js","sources":["../../../../../src/rendering/renderers/shared/buffer/const.ts"],"sourcesContent":["/**\n * Buffer usage flags. they can be combined using the bitwise OR operator\n * eg : BufferUsage.VERTEX | BufferUsage.INDEX\n * @memberof rendering\n */\nexport enum BufferUsage\n// eslint-disable-next-line @typescript-eslint/indent\n{\n /**\n * The buffer can be mapped for reading. (Example: calling mapAsync() with GPUMapMode.READ)\n * May only be combined with COPY_DST.\n */\n MAP_READ = 0x0001,\n /**\n * The buffer can be mapped for writing. (Example: calling mapAsync() with GPUMapMode.WRITE)\n * May only be combined with COPY_SRC.\n */\n MAP_WRITE = 0x0002,\n /**\n * The buffer can be used as the source of a copy operation.\n * (Examples: as the source argument of a copyBufferToBuffer() or copyBufferToTexture() call.)\n */\n COPY_SRC = 0x0004,\n /**\n * The buffer can be used as the destination of a copy or write operation.\n * (Examples: as the destination argument of a copyBufferToBuffer() or\n * copyTextureToBuffer() call, or as the target of a writeBuffer() call.)\n */\n COPY_DST = 0x0008,\n /** The buffer can be used as an index buffer. (Example: passed to setIndexBuffer().) */\n INDEX = 0x0010,\n /** The buffer can be used as a vertex buffer. (Example: passed to setVertexBuffer().) */\n VERTEX = 0x0020,\n /**\n * The buffer can be used as a uniform buffer.\n * (Example: as a bind group entry for a GPUBufferBindingLayout with a buffer.type of \"uniform\".)\n */\n UNIFORM = 0x0040,\n /**\n * The buffer can be used as a storage buffer.\n * (Example: as a bind group entry for a GPUBufferBindingLayout with a buffer.type of \"storage\" or \"read-only-storage\".)\n */\n STORAGE = 0x0080,\n /**\n * The buffer can be used as to store indirect command arguments.\n * (Examples: as the indirectBuffer argument of a drawIndirect() or dispatchWorkgroupsIndirect() call.)\n */\n INDIRECT = 0x0100,\n /**\n * The buffer can be used to capture query results.\n * (Example: as the destination argument of a resolveQuerySet() call.)\n */\n QUERY_RESOLVE = 0x0200,\n /** the buffer will not be updated frequently */\n STATIC = 0x0400\n}\n"],"names":["BufferUsage"],"mappings":";;;AAKY,IAAA,WAAA,qBAAAA,YAAL,KAAA;AAOH,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,cAAW,CAAX,CAAA,GAAA,UAAA,CAAA;AAKA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,eAAY,CAAZ,CAAA,GAAA,WAAA,CAAA;AAKA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,cAAW,CAAX,CAAA,GAAA,UAAA,CAAA;AAMA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,cAAW,CAAX,CAAA,GAAA,UAAA,CAAA;AAEA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,WAAQ,EAAR,CAAA,GAAA,OAAA,CAAA;AAEA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,YAAS,EAAT,CAAA,GAAA,QAAA,CAAA;AAKA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,aAAU,EAAV,CAAA,GAAA,SAAA,CAAA;AAKA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,aAAU,GAAV,CAAA,GAAA,SAAA,CAAA;AAKA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,cAAW,GAAX,CAAA,GAAA,UAAA,CAAA;AAKA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,mBAAgB,GAAhB,CAAA,GAAA,eAAA,CAAA;AAEA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,YAAS,IAAT,CAAA,GAAA,QAAA,CAAA;AAjDQ,EAAAA,OAAAA,YAAAA,CAAAA;AAAA,CAAA,EAAA,WAAA,IAAA,EAAA;;;;"}

View File

@@ -0,0 +1,18 @@
"use strict";
var BufferUsage = /* @__PURE__ */ ((BufferUsage2) => {
BufferUsage2[BufferUsage2["MAP_READ"] = 1] = "MAP_READ";
BufferUsage2[BufferUsage2["MAP_WRITE"] = 2] = "MAP_WRITE";
BufferUsage2[BufferUsage2["COPY_SRC"] = 4] = "COPY_SRC";
BufferUsage2[BufferUsage2["COPY_DST"] = 8] = "COPY_DST";
BufferUsage2[BufferUsage2["INDEX"] = 16] = "INDEX";
BufferUsage2[BufferUsage2["VERTEX"] = 32] = "VERTEX";
BufferUsage2[BufferUsage2["UNIFORM"] = 64] = "UNIFORM";
BufferUsage2[BufferUsage2["STORAGE"] = 128] = "STORAGE";
BufferUsage2[BufferUsage2["INDIRECT"] = 256] = "INDIRECT";
BufferUsage2[BufferUsage2["QUERY_RESOLVE"] = 512] = "QUERY_RESOLVE";
BufferUsage2[BufferUsage2["STATIC"] = 1024] = "STATIC";
return BufferUsage2;
})(BufferUsage || {});
export { BufferUsage };
//# sourceMappingURL=const.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"const.mjs","sources":["../../../../../src/rendering/renderers/shared/buffer/const.ts"],"sourcesContent":["/**\n * Buffer usage flags. they can be combined using the bitwise OR operator\n * eg : BufferUsage.VERTEX | BufferUsage.INDEX\n * @memberof rendering\n */\nexport enum BufferUsage\n// eslint-disable-next-line @typescript-eslint/indent\n{\n /**\n * The buffer can be mapped for reading. (Example: calling mapAsync() with GPUMapMode.READ)\n * May only be combined with COPY_DST.\n */\n MAP_READ = 0x0001,\n /**\n * The buffer can be mapped for writing. (Example: calling mapAsync() with GPUMapMode.WRITE)\n * May only be combined with COPY_SRC.\n */\n MAP_WRITE = 0x0002,\n /**\n * The buffer can be used as the source of a copy operation.\n * (Examples: as the source argument of a copyBufferToBuffer() or copyBufferToTexture() call.)\n */\n COPY_SRC = 0x0004,\n /**\n * The buffer can be used as the destination of a copy or write operation.\n * (Examples: as the destination argument of a copyBufferToBuffer() or\n * copyTextureToBuffer() call, or as the target of a writeBuffer() call.)\n */\n COPY_DST = 0x0008,\n /** The buffer can be used as an index buffer. (Example: passed to setIndexBuffer().) */\n INDEX = 0x0010,\n /** The buffer can be used as a vertex buffer. (Example: passed to setVertexBuffer().) */\n VERTEX = 0x0020,\n /**\n * The buffer can be used as a uniform buffer.\n * (Example: as a bind group entry for a GPUBufferBindingLayout with a buffer.type of \"uniform\".)\n */\n UNIFORM = 0x0040,\n /**\n * The buffer can be used as a storage buffer.\n * (Example: as a bind group entry for a GPUBufferBindingLayout with a buffer.type of \"storage\" or \"read-only-storage\".)\n */\n STORAGE = 0x0080,\n /**\n * The buffer can be used as to store indirect command arguments.\n * (Examples: as the indirectBuffer argument of a drawIndirect() or dispatchWorkgroupsIndirect() call.)\n */\n INDIRECT = 0x0100,\n /**\n * The buffer can be used to capture query results.\n * (Example: as the destination argument of a resolveQuerySet() call.)\n */\n QUERY_RESOLVE = 0x0200,\n /** the buffer will not be updated frequently */\n STATIC = 0x0400\n}\n"],"names":["BufferUsage"],"mappings":";AAKY,IAAA,WAAA,qBAAAA,YAAL,KAAA;AAOH,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,cAAW,CAAX,CAAA,GAAA,UAAA,CAAA;AAKA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,eAAY,CAAZ,CAAA,GAAA,WAAA,CAAA;AAKA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,cAAW,CAAX,CAAA,GAAA,UAAA,CAAA;AAMA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,cAAW,CAAX,CAAA,GAAA,UAAA,CAAA;AAEA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,WAAQ,EAAR,CAAA,GAAA,OAAA,CAAA;AAEA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,YAAS,EAAT,CAAA,GAAA,QAAA,CAAA;AAKA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,aAAU,EAAV,CAAA,GAAA,SAAA,CAAA;AAKA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,aAAU,GAAV,CAAA,GAAA,SAAA,CAAA;AAKA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,cAAW,GAAX,CAAA,GAAA,UAAA,CAAA;AAKA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,mBAAgB,GAAhB,CAAA,GAAA,eAAA,CAAA;AAEA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,YAAS,IAAT,CAAA,GAAA,QAAA,CAAA;AAjDQ,EAAAA,OAAAA,YAAAA,CAAAA;AAAA,CAAA,EAAA,WAAA,IAAA,EAAA;;;;"}

View File

@@ -0,0 +1,9 @@
/**
* Copies from one buffer to another.
* This is an optimised function that will use `Float64Array` window.
* This means it can copy twice as fast!
* @param sourceBuffer - the array buffer to copy from
* @param destinationBuffer - the array buffer to copy to
* @private
*/
export declare function fastCopy(sourceBuffer: ArrayBuffer, destinationBuffer: ArrayBuffer): void;

View File

@@ -0,0 +1,18 @@
'use strict';
"use strict";
function fastCopy(sourceBuffer, destinationBuffer) {
const lengthDouble = sourceBuffer.byteLength / 8 | 0;
const sourceFloat64View = new Float64Array(sourceBuffer, 0, lengthDouble);
const destinationFloat64View = new Float64Array(destinationBuffer, 0, lengthDouble);
destinationFloat64View.set(sourceFloat64View);
const remainingBytes = sourceBuffer.byteLength - lengthDouble * 8;
if (remainingBytes > 0) {
const sourceUint8View = new Uint8Array(sourceBuffer, lengthDouble * 8, remainingBytes);
const destinationUint8View = new Uint8Array(destinationBuffer, lengthDouble * 8, remainingBytes);
destinationUint8View.set(sourceUint8View);
}
}
exports.fastCopy = fastCopy;
//# sourceMappingURL=fastCopy.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"fastCopy.js","sources":["../../../../../../src/rendering/renderers/shared/buffer/utils/fastCopy.ts"],"sourcesContent":["/**\n * Copies from one buffer to another.\n * This is an optimised function that will use `Float64Array` window.\n * This means it can copy twice as fast!\n * @param sourceBuffer - the array buffer to copy from\n * @param destinationBuffer - the array buffer to copy to\n * @private\n */\nexport function fastCopy(sourceBuffer: ArrayBuffer, destinationBuffer: ArrayBuffer): void\n{\n const lengthDouble = (sourceBuffer.byteLength / 8) | 0;\n\n const sourceFloat64View = new Float64Array(sourceBuffer, 0, lengthDouble);\n const destinationFloat64View = new Float64Array(destinationBuffer, 0, lengthDouble);\n\n // Use set for faster copying\n destinationFloat64View.set(sourceFloat64View);\n\n // copying over the remaining bytes\n const remainingBytes = sourceBuffer.byteLength - (lengthDouble * 8);\n\n if (remainingBytes > 0)\n {\n const sourceUint8View = new Uint8Array(sourceBuffer, lengthDouble * 8, remainingBytes);\n const destinationUint8View = new Uint8Array(destinationBuffer, lengthDouble * 8, remainingBytes);\n\n // Direct copy for remaining bytes\n destinationUint8View.set(sourceUint8View);\n }\n}\n"],"names":[],"mappings":";;;AAQgB,SAAA,QAAA,CAAS,cAA2B,iBACpD,EAAA;AACI,EAAM,MAAA,YAAA,GAAgB,YAAa,CAAA,UAAA,GAAa,CAAK,GAAA,CAAA,CAAA;AAErD,EAAA,MAAM,iBAAoB,GAAA,IAAI,YAAa,CAAA,YAAA,EAAc,GAAG,YAAY,CAAA,CAAA;AACxE,EAAA,MAAM,sBAAyB,GAAA,IAAI,YAAa,CAAA,iBAAA,EAAmB,GAAG,YAAY,CAAA,CAAA;AAGlF,EAAA,sBAAA,CAAuB,IAAI,iBAAiB,CAAA,CAAA;AAG5C,EAAM,MAAA,cAAA,GAAiB,YAAa,CAAA,UAAA,GAAc,YAAe,GAAA,CAAA,CAAA;AAEjE,EAAA,IAAI,iBAAiB,CACrB,EAAA;AACI,IAAA,MAAM,kBAAkB,IAAI,UAAA,CAAW,YAAc,EAAA,YAAA,GAAe,GAAG,cAAc,CAAA,CAAA;AACrF,IAAA,MAAM,uBAAuB,IAAI,UAAA,CAAW,iBAAmB,EAAA,YAAA,GAAe,GAAG,cAAc,CAAA,CAAA;AAG/F,IAAA,oBAAA,CAAqB,IAAI,eAAe,CAAA,CAAA;AAAA,GAC5C;AACJ;;;;"}

View File

@@ -0,0 +1,16 @@
"use strict";
function fastCopy(sourceBuffer, destinationBuffer) {
const lengthDouble = sourceBuffer.byteLength / 8 | 0;
const sourceFloat64View = new Float64Array(sourceBuffer, 0, lengthDouble);
const destinationFloat64View = new Float64Array(destinationBuffer, 0, lengthDouble);
destinationFloat64View.set(sourceFloat64View);
const remainingBytes = sourceBuffer.byteLength - lengthDouble * 8;
if (remainingBytes > 0) {
const sourceUint8View = new Uint8Array(sourceBuffer, lengthDouble * 8, remainingBytes);
const destinationUint8View = new Uint8Array(destinationBuffer, lengthDouble * 8, remainingBytes);
destinationUint8View.set(sourceUint8View);
}
}
export { fastCopy };
//# sourceMappingURL=fastCopy.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"fastCopy.mjs","sources":["../../../../../../src/rendering/renderers/shared/buffer/utils/fastCopy.ts"],"sourcesContent":["/**\n * Copies from one buffer to another.\n * This is an optimised function that will use `Float64Array` window.\n * This means it can copy twice as fast!\n * @param sourceBuffer - the array buffer to copy from\n * @param destinationBuffer - the array buffer to copy to\n * @private\n */\nexport function fastCopy(sourceBuffer: ArrayBuffer, destinationBuffer: ArrayBuffer): void\n{\n const lengthDouble = (sourceBuffer.byteLength / 8) | 0;\n\n const sourceFloat64View = new Float64Array(sourceBuffer, 0, lengthDouble);\n const destinationFloat64View = new Float64Array(destinationBuffer, 0, lengthDouble);\n\n // Use set for faster copying\n destinationFloat64View.set(sourceFloat64View);\n\n // copying over the remaining bytes\n const remainingBytes = sourceBuffer.byteLength - (lengthDouble * 8);\n\n if (remainingBytes > 0)\n {\n const sourceUint8View = new Uint8Array(sourceBuffer, lengthDouble * 8, remainingBytes);\n const destinationUint8View = new Uint8Array(destinationBuffer, lengthDouble * 8, remainingBytes);\n\n // Direct copy for remaining bytes\n destinationUint8View.set(sourceUint8View);\n }\n}\n"],"names":[],"mappings":";AAQgB,SAAA,QAAA,CAAS,cAA2B,iBACpD,EAAA;AACI,EAAM,MAAA,YAAA,GAAgB,YAAa,CAAA,UAAA,GAAa,CAAK,GAAA,CAAA,CAAA;AAErD,EAAA,MAAM,iBAAoB,GAAA,IAAI,YAAa,CAAA,YAAA,EAAc,GAAG,YAAY,CAAA,CAAA;AACxE,EAAA,MAAM,sBAAyB,GAAA,IAAI,YAAa,CAAA,iBAAA,EAAmB,GAAG,YAAY,CAAA,CAAA;AAGlF,EAAA,sBAAA,CAAuB,IAAI,iBAAiB,CAAA,CAAA;AAG5C,EAAM,MAAA,cAAA,GAAiB,YAAa,CAAA,UAAA,GAAc,YAAe,GAAA,CAAA,CAAA;AAEjE,EAAA,IAAI,iBAAiB,CACrB,EAAA;AACI,IAAA,MAAM,kBAAkB,IAAI,UAAA,CAAW,YAAc,EAAA,YAAA,GAAe,GAAG,cAAc,CAAA,CAAA;AACrF,IAAA,MAAM,uBAAuB,IAAI,UAAA,CAAW,iBAAmB,EAAA,YAAA,GAAe,GAAG,cAAc,CAAA,CAAA;AAG/F,IAAA,oBAAA,CAAqB,IAAI,eAAe,CAAA,CAAA;AAAA,GAC5C;AACJ;;;;"}

View File

@@ -0,0 +1,139 @@
import { ExtensionType } from '../../../../extensions/Extensions';
import { Container } from '../../../../scene/container/Container';
import { Texture } from '../texture/Texture';
import type { ColorSource } from '../../../../color/Color';
import type { ICanvas } from '../../../../environment/canvas/ICanvas';
import type { Rectangle } from '../../../../maths/shapes/Rectangle';
import type { Renderer } from '../../types';
import type { System } from '../system/System';
import type { GetPixelsOutput } from '../texture/GenerateCanvas';
declare const imageTypes: {
png: string;
jpg: string;
webp: string;
};
type Formats = keyof typeof imageTypes;
/**
* Options for creating an image from a renderer.
* @memberof rendering
*/
export interface ImageOptions {
/** The format of the image. */
format?: Formats;
/** The quality of the image. */
quality?: number;
}
/**
* Options for extracting content from a renderer.
* @memberof rendering
*/
export interface BaseExtractOptions {
/** The target to extract. */
target: Container | Texture;
/** The region of the target to extract. */
frame?: Rectangle;
/** The resolution of the extracted content. */
resolution?: number;
/** The color used to clear the extracted content. */
clearColor?: ColorSource;
/** Whether to enable anti-aliasing. This may affect performance. */
antialias?: boolean;
}
/**
* Options for extracting an HTMLImage from the renderer.
* @memberof rendering
*/
export type ExtractImageOptions = BaseExtractOptions & ImageOptions;
/**
* Options for extracting and downloading content from a renderer.
* @memberof rendering
*/
export type ExtractDownloadOptions = BaseExtractOptions & {
/** The filename to use when downloading the content. */
filename: string;
};
/**
* Options for extracting content from a renderer.
* @memberof rendering
*/
export type ExtractOptions = BaseExtractOptions | ExtractImageOptions | ExtractDownloadOptions;
/**
* This class provides renderer-specific plugins for exporting content from a renderer.
* For instance, these plugins can be used for saving an Image, Canvas element or for exporting the raw image data (pixels).
*
* Do not instantiate these plugins directly. It is available from the `renderer.extract` property.
* @example
* import { Application, Graphics } from 'pixi.js';
*
* // Create a new application (extract will be auto-added to renderer)
* const app = new Application();
* await app.init();
*
* // Draw a red circle
* const graphics = new Graphics()
* .circle(0, 0, 50);
* .fill(0xFF0000)
*
* // Render the graphics as an HTMLImageElement
* const image = await app.renderer.extract.image(graphics);
* document.body.appendChild(image);
* @memberof rendering
*/
export declare class ExtractSystem implements System {
/** @ignore */
static extension: {
readonly type: readonly [ExtensionType.WebGLSystem, ExtensionType.WebGPUSystem];
readonly name: "extract";
};
/** Default options for creating an image. */
static defaultImageOptions: ImageOptions;
private _renderer;
/** @param renderer - The renderer this System works for. */
constructor(renderer: Renderer);
private _normalizeOptions;
/**
* Will return a HTML Image of the target
* @param options - The options for creating the image, or the target to extract
* @returns - HTML Image of the target
*/
image(options: ExtractImageOptions | Container | Texture): Promise<HTMLImageElement>;
/**
* Will return a base64 encoded string of this target. It works by calling
* `Extract.canvas` and then running toDataURL on that.
* @param options - The options for creating the image, or the target to extract
*/
base64(options: ExtractImageOptions | Container | Texture): Promise<string>;
/**
* Creates a Canvas element, renders this target to it and then returns it.
* @param options - The options for creating the canvas, or the target to extract
* @returns - A Canvas element with the texture rendered on.
*/
canvas(options: ExtractOptions | Container | Texture): ICanvas;
/**
* Will return a one-dimensional array containing the pixel data of the entire texture in RGBA
* order, with integer values between 0 and 255 (included).
* @param options - The options for extracting the image, or the target to extract
* @returns - One-dimensional array containing the pixel data of the entire texture
*/
pixels(options: ExtractOptions | Container | Texture): GetPixelsOutput;
/**
* Will return a texture of the target
* @param options - The options for creating the texture, or the target to extract
* @returns - A texture of the target
*/
texture(options: ExtractOptions | Container | Texture): Texture;
/**
* Will extract a HTMLImage of the target and download it
* @param options - The options for downloading and extracting the image, or the target to extract
*/
download(options: ExtractDownloadOptions | Container | Texture): void;
/**
* Logs the target to the console as an image. This is a useful way to debug what's happening in the renderer.
* @param options - The options for logging the image, or the target to log
*/
log(options: (ExtractOptions & {
width?: number;
}) | Container | Texture): void;
destroy(): void;
}
export {};

View File

@@ -0,0 +1,179 @@
'use strict';
var Extensions = require('../../../../extensions/Extensions.js');
var Container = require('../../../../scene/container/Container.js');
var Texture = require('../texture/Texture.js');
"use strict";
const imageTypes = {
png: "image/png",
jpg: "image/jpeg",
webp: "image/webp"
};
const _ExtractSystem = class _ExtractSystem {
/** @param renderer - The renderer this System works for. */
constructor(renderer) {
this._renderer = renderer;
}
_normalizeOptions(options, defaults = {}) {
if (options instanceof Container.Container || options instanceof Texture.Texture) {
return {
target: options,
...defaults
};
}
return {
...defaults,
...options
};
}
/**
* Will return a HTML Image of the target
* @param options - The options for creating the image, or the target to extract
* @returns - HTML Image of the target
*/
async image(options) {
const image = new Image();
image.src = await this.base64(options);
return image;
}
/**
* Will return a base64 encoded string of this target. It works by calling
* `Extract.canvas` and then running toDataURL on that.
* @param options - The options for creating the image, or the target to extract
*/
async base64(options) {
options = this._normalizeOptions(
options,
_ExtractSystem.defaultImageOptions
);
const { format, quality } = options;
const canvas = this.canvas(options);
if (canvas.toBlob !== void 0) {
return new Promise((resolve, reject) => {
canvas.toBlob((blob) => {
if (!blob) {
reject(new Error("ICanvas.toBlob failed!"));
return;
}
const reader = new FileReader();
reader.onload = () => resolve(reader.result);
reader.onerror = reject;
reader.readAsDataURL(blob);
}, imageTypes[format], quality);
});
}
if (canvas.toDataURL !== void 0) {
return canvas.toDataURL(imageTypes[format], quality);
}
if (canvas.convertToBlob !== void 0) {
const blob = await canvas.convertToBlob({ type: imageTypes[format], quality });
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => resolve(reader.result);
reader.onerror = reject;
reader.readAsDataURL(blob);
});
}
throw new Error("Extract.base64() requires ICanvas.toDataURL, ICanvas.toBlob, or ICanvas.convertToBlob to be implemented");
}
/**
* Creates a Canvas element, renders this target to it and then returns it.
* @param options - The options for creating the canvas, or the target to extract
* @returns - A Canvas element with the texture rendered on.
*/
canvas(options) {
options = this._normalizeOptions(options);
const target = options.target;
const renderer = this._renderer;
if (target instanceof Texture.Texture) {
return renderer.texture.generateCanvas(target);
}
const texture = renderer.textureGenerator.generateTexture(options);
const canvas = renderer.texture.generateCanvas(texture);
texture.destroy();
return canvas;
}
/**
* Will return a one-dimensional array containing the pixel data of the entire texture in RGBA
* order, with integer values between 0 and 255 (included).
* @param options - The options for extracting the image, or the target to extract
* @returns - One-dimensional array containing the pixel data of the entire texture
*/
pixels(options) {
options = this._normalizeOptions(options);
const target = options.target;
const renderer = this._renderer;
const texture = target instanceof Texture.Texture ? target : renderer.textureGenerator.generateTexture(options);
const pixelInfo = renderer.texture.getPixels(texture);
if (target instanceof Container.Container) {
texture.destroy();
}
return pixelInfo;
}
/**
* Will return a texture of the target
* @param options - The options for creating the texture, or the target to extract
* @returns - A texture of the target
*/
texture(options) {
options = this._normalizeOptions(options);
if (options.target instanceof Texture.Texture)
return options.target;
return this._renderer.textureGenerator.generateTexture(options);
}
/**
* Will extract a HTMLImage of the target and download it
* @param options - The options for downloading and extracting the image, or the target to extract
*/
download(options) {
options = this._normalizeOptions(options);
const canvas = this.canvas(options);
const link = document.createElement("a");
link.download = options.filename ?? "image.png";
link.href = canvas.toDataURL("image/png");
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
/**
* Logs the target to the console as an image. This is a useful way to debug what's happening in the renderer.
* @param options - The options for logging the image, or the target to log
*/
log(options) {
const width = options.width ?? 200;
options = this._normalizeOptions(options);
const canvas = this.canvas(options);
const base64 = canvas.toDataURL();
console.log(`[Pixi Texture] ${canvas.width}px ${canvas.height}px`);
const style = [
"font-size: 1px;",
`padding: ${width}px ${300}px;`,
`background: url(${base64}) no-repeat;`,
"background-size: contain;"
].join(" ");
console.log("%c ", style);
}
destroy() {
this._renderer = null;
}
};
/** @ignore */
_ExtractSystem.extension = {
type: [
Extensions.ExtensionType.WebGLSystem,
Extensions.ExtensionType.WebGPUSystem
],
name: "extract"
};
/** Default options for creating an image. */
_ExtractSystem.defaultImageOptions = {
/** The format of the image. */
format: "png",
/** The quality of the image. */
quality: 1
};
let ExtractSystem = _ExtractSystem;
exports.ExtractSystem = ExtractSystem;
//# sourceMappingURL=ExtractSystem.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,177 @@
import { ExtensionType } from '../../../../extensions/Extensions.mjs';
import { Container } from '../../../../scene/container/Container.mjs';
import { Texture } from '../texture/Texture.mjs';
"use strict";
const imageTypes = {
png: "image/png",
jpg: "image/jpeg",
webp: "image/webp"
};
const _ExtractSystem = class _ExtractSystem {
/** @param renderer - The renderer this System works for. */
constructor(renderer) {
this._renderer = renderer;
}
_normalizeOptions(options, defaults = {}) {
if (options instanceof Container || options instanceof Texture) {
return {
target: options,
...defaults
};
}
return {
...defaults,
...options
};
}
/**
* Will return a HTML Image of the target
* @param options - The options for creating the image, or the target to extract
* @returns - HTML Image of the target
*/
async image(options) {
const image = new Image();
image.src = await this.base64(options);
return image;
}
/**
* Will return a base64 encoded string of this target. It works by calling
* `Extract.canvas` and then running toDataURL on that.
* @param options - The options for creating the image, or the target to extract
*/
async base64(options) {
options = this._normalizeOptions(
options,
_ExtractSystem.defaultImageOptions
);
const { format, quality } = options;
const canvas = this.canvas(options);
if (canvas.toBlob !== void 0) {
return new Promise((resolve, reject) => {
canvas.toBlob((blob) => {
if (!blob) {
reject(new Error("ICanvas.toBlob failed!"));
return;
}
const reader = new FileReader();
reader.onload = () => resolve(reader.result);
reader.onerror = reject;
reader.readAsDataURL(blob);
}, imageTypes[format], quality);
});
}
if (canvas.toDataURL !== void 0) {
return canvas.toDataURL(imageTypes[format], quality);
}
if (canvas.convertToBlob !== void 0) {
const blob = await canvas.convertToBlob({ type: imageTypes[format], quality });
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => resolve(reader.result);
reader.onerror = reject;
reader.readAsDataURL(blob);
});
}
throw new Error("Extract.base64() requires ICanvas.toDataURL, ICanvas.toBlob, or ICanvas.convertToBlob to be implemented");
}
/**
* Creates a Canvas element, renders this target to it and then returns it.
* @param options - The options for creating the canvas, or the target to extract
* @returns - A Canvas element with the texture rendered on.
*/
canvas(options) {
options = this._normalizeOptions(options);
const target = options.target;
const renderer = this._renderer;
if (target instanceof Texture) {
return renderer.texture.generateCanvas(target);
}
const texture = renderer.textureGenerator.generateTexture(options);
const canvas = renderer.texture.generateCanvas(texture);
texture.destroy();
return canvas;
}
/**
* Will return a one-dimensional array containing the pixel data of the entire texture in RGBA
* order, with integer values between 0 and 255 (included).
* @param options - The options for extracting the image, or the target to extract
* @returns - One-dimensional array containing the pixel data of the entire texture
*/
pixels(options) {
options = this._normalizeOptions(options);
const target = options.target;
const renderer = this._renderer;
const texture = target instanceof Texture ? target : renderer.textureGenerator.generateTexture(options);
const pixelInfo = renderer.texture.getPixels(texture);
if (target instanceof Container) {
texture.destroy();
}
return pixelInfo;
}
/**
* Will return a texture of the target
* @param options - The options for creating the texture, or the target to extract
* @returns - A texture of the target
*/
texture(options) {
options = this._normalizeOptions(options);
if (options.target instanceof Texture)
return options.target;
return this._renderer.textureGenerator.generateTexture(options);
}
/**
* Will extract a HTMLImage of the target and download it
* @param options - The options for downloading and extracting the image, or the target to extract
*/
download(options) {
options = this._normalizeOptions(options);
const canvas = this.canvas(options);
const link = document.createElement("a");
link.download = options.filename ?? "image.png";
link.href = canvas.toDataURL("image/png");
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
/**
* Logs the target to the console as an image. This is a useful way to debug what's happening in the renderer.
* @param options - The options for logging the image, or the target to log
*/
log(options) {
const width = options.width ?? 200;
options = this._normalizeOptions(options);
const canvas = this.canvas(options);
const base64 = canvas.toDataURL();
console.log(`[Pixi Texture] ${canvas.width}px ${canvas.height}px`);
const style = [
"font-size: 1px;",
`padding: ${width}px ${300}px;`,
`background: url(${base64}) no-repeat;`,
"background-size: contain;"
].join(" ");
console.log("%c ", style);
}
destroy() {
this._renderer = null;
}
};
/** @ignore */
_ExtractSystem.extension = {
type: [
ExtensionType.WebGLSystem,
ExtensionType.WebGPUSystem
],
name: "extract"
};
/** Default options for creating an image. */
_ExtractSystem.defaultImageOptions = {
/** The format of the image. */
format: "png",
/** The quality of the image. */
quality: 1
};
let ExtractSystem = _ExtractSystem;
export { ExtractSystem };
//# sourceMappingURL=ExtractSystem.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,59 @@
import { type ColorSource } from '../../../../color/Color';
import { ExtensionType } from '../../../../extensions/Extensions';
import { Rectangle } from '../../../../maths/shapes/Rectangle';
import { Container } from '../../../../scene/container/Container';
import { RenderTexture } from '../texture/RenderTexture';
import type { Renderer } from '../../types';
import type { System } from '../system/System';
import type { TextureSourceOptions } from '../texture/sources/TextureSource';
export type GenerateTextureSourceOptions = Omit<TextureSourceOptions, 'resource' | 'width' | 'height' | 'resolution'>;
/**
* Options for generating a texture from a container.
* @memberof rendering
*/
export type GenerateTextureOptions = {
/** The container to generate the texture from */
target: Container;
/**
* The region of the container, that shall be rendered,
* if no region is specified, defaults to the local bounds of the container.
*/
frame?: Rectangle;
/** The resolution of the texture being generated. */
resolution?: number;
/** The color used to clear the texture. */
clearColor?: ColorSource;
/** Whether to enable anti-aliasing. This may affect performance. */
antialias?: boolean;
/** The options passed to the texture source. */
textureSourceOptions?: GenerateTextureSourceOptions;
};
/**
* System that manages the generation of textures from the renderer
*
*
* Do not instantiate these plugins directly. It is available from the `renderer.textureGenerator` property.
* @memberof rendering
*/
export declare class GenerateTextureSystem implements System {
/** @ignore */
static extension: {
readonly type: readonly [ExtensionType.WebGLSystem, ExtensionType.WebGPUSystem];
readonly name: "textureGenerator";
};
private readonly _renderer;
constructor(renderer: Renderer);
/**
* A Useful function that returns a texture of the display object that can then be used to create sprites
* This can be quite useful if your container is complicated and needs to be reused multiple times.
* @param {GenerateTextureOptions | Container} options - Generate texture options.
* @param {Container} [options.container] - If not given, the renderer's resolution is used.
* @param {Rectangle} options.region - The region of the container, that shall be rendered,
* @param {number} [options.resolution] - The resolution of the texture being generated.
* if no region is specified, defaults to the local bounds of the container.
* @param {GenerateTextureSourceOptions} [options.textureSourceOptions] - Texture options for GPU.
* @returns a shiny new texture of the container passed in
*/
generateTexture(options: GenerateTextureOptions | Container): RenderTexture;
destroy(): void;
}

View File

@@ -0,0 +1,84 @@
'use strict';
var Color = require('../../../../color/Color.js');
var Extensions = require('../../../../extensions/Extensions.js');
var Matrix = require('../../../../maths/matrix/Matrix.js');
var Rectangle = require('../../../../maths/shapes/Rectangle.js');
var Bounds = require('../../../../scene/container/bounds/Bounds.js');
var getLocalBounds = require('../../../../scene/container/bounds/getLocalBounds.js');
var Container = require('../../../../scene/container/Container.js');
var RenderTexture = require('../texture/RenderTexture.js');
"use strict";
const tempRect = new Rectangle.Rectangle();
const tempBounds = new Bounds.Bounds();
const noColor = [0, 0, 0, 0];
class GenerateTextureSystem {
constructor(renderer) {
this._renderer = renderer;
}
/**
* A Useful function that returns a texture of the display object that can then be used to create sprites
* This can be quite useful if your container is complicated and needs to be reused multiple times.
* @param {GenerateTextureOptions | Container} options - Generate texture options.
* @param {Container} [options.container] - If not given, the renderer's resolution is used.
* @param {Rectangle} options.region - The region of the container, that shall be rendered,
* @param {number} [options.resolution] - The resolution of the texture being generated.
* if no region is specified, defaults to the local bounds of the container.
* @param {GenerateTextureSourceOptions} [options.textureSourceOptions] - Texture options for GPU.
* @returns a shiny new texture of the container passed in
*/
generateTexture(options) {
if (options instanceof Container.Container) {
options = {
target: options,
frame: void 0,
textureSourceOptions: {},
resolution: void 0
};
}
const resolution = options.resolution || this._renderer.resolution;
const antialias = options.antialias || this._renderer.view.antialias;
const container = options.target;
let clearColor = options.clearColor;
if (clearColor) {
const isRGBAArray = Array.isArray(clearColor) && clearColor.length === 4;
clearColor = isRGBAArray ? clearColor : Color.Color.shared.setValue(clearColor).toArray();
} else {
clearColor = noColor;
}
const region = options.frame?.copyTo(tempRect) || getLocalBounds.getLocalBounds(container, tempBounds).rectangle;
region.width = Math.max(region.width, 1 / resolution) | 0;
region.height = Math.max(region.height, 1 / resolution) | 0;
const target = RenderTexture.RenderTexture.create({
...options.textureSourceOptions,
width: region.width,
height: region.height,
resolution,
antialias
});
const transform = Matrix.Matrix.shared.translate(-region.x, -region.y);
this._renderer.render({
container,
transform,
target,
clearColor
});
target.source.updateMipmaps();
return target;
}
destroy() {
this._renderer = null;
}
}
/** @ignore */
GenerateTextureSystem.extension = {
type: [
Extensions.ExtensionType.WebGLSystem,
Extensions.ExtensionType.WebGPUSystem
],
name: "textureGenerator"
};
exports.GenerateTextureSystem = GenerateTextureSystem;
//# sourceMappingURL=GenerateTextureSystem.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,82 @@
import { Color } from '../../../../color/Color.mjs';
import { ExtensionType } from '../../../../extensions/Extensions.mjs';
import { Matrix } from '../../../../maths/matrix/Matrix.mjs';
import { Rectangle } from '../../../../maths/shapes/Rectangle.mjs';
import { Bounds } from '../../../../scene/container/bounds/Bounds.mjs';
import { getLocalBounds } from '../../../../scene/container/bounds/getLocalBounds.mjs';
import { Container } from '../../../../scene/container/Container.mjs';
import { RenderTexture } from '../texture/RenderTexture.mjs';
"use strict";
const tempRect = new Rectangle();
const tempBounds = new Bounds();
const noColor = [0, 0, 0, 0];
class GenerateTextureSystem {
constructor(renderer) {
this._renderer = renderer;
}
/**
* A Useful function that returns a texture of the display object that can then be used to create sprites
* This can be quite useful if your container is complicated and needs to be reused multiple times.
* @param {GenerateTextureOptions | Container} options - Generate texture options.
* @param {Container} [options.container] - If not given, the renderer's resolution is used.
* @param {Rectangle} options.region - The region of the container, that shall be rendered,
* @param {number} [options.resolution] - The resolution of the texture being generated.
* if no region is specified, defaults to the local bounds of the container.
* @param {GenerateTextureSourceOptions} [options.textureSourceOptions] - Texture options for GPU.
* @returns a shiny new texture of the container passed in
*/
generateTexture(options) {
if (options instanceof Container) {
options = {
target: options,
frame: void 0,
textureSourceOptions: {},
resolution: void 0
};
}
const resolution = options.resolution || this._renderer.resolution;
const antialias = options.antialias || this._renderer.view.antialias;
const container = options.target;
let clearColor = options.clearColor;
if (clearColor) {
const isRGBAArray = Array.isArray(clearColor) && clearColor.length === 4;
clearColor = isRGBAArray ? clearColor : Color.shared.setValue(clearColor).toArray();
} else {
clearColor = noColor;
}
const region = options.frame?.copyTo(tempRect) || getLocalBounds(container, tempBounds).rectangle;
region.width = Math.max(region.width, 1 / resolution) | 0;
region.height = Math.max(region.height, 1 / resolution) | 0;
const target = RenderTexture.create({
...options.textureSourceOptions,
width: region.width,
height: region.height,
resolution,
antialias
});
const transform = Matrix.shared.translate(-region.x, -region.y);
this._renderer.render({
container,
transform,
target,
clearColor
});
target.source.updateMipmaps();
return target;
}
destroy() {
this._renderer = null;
}
}
/** @ignore */
GenerateTextureSystem.extension = {
type: [
ExtensionType.WebGLSystem,
ExtensionType.WebGPUSystem
],
name: "textureGenerator"
};
export { GenerateTextureSystem };
//# sourceMappingURL=GenerateTextureSystem.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,155 @@
import EventEmitter from 'eventemitter3';
import { Bounds } from '../../../../scene/container/bounds/Bounds';
import { Buffer } from '../buffer/Buffer';
import type { TypedArray } from '../buffer/Buffer';
import type { Topology, VertexFormat } from './const';
export type IndexBufferArray = Uint16Array | Uint32Array;
/**
* The attribute data for a geometries attributes
* @memberof rendering
*/
export interface Attribute {
/** the buffer that this attributes data belongs to */
buffer: Buffer;
/** the format of the attribute */
format?: VertexFormat;
/** the stride of the data in the buffer*/
stride?: number;
/** the offset of the attribute from the buffer, defaults to 0 */
offset?: number;
/** is this an instanced buffer? (defaults to false) */
instance?: boolean;
/** the number of elements to be rendered. If not specified, all vertices after the starting vertex will be drawn. */
size?: number;
/** the type of attribute */
type?: number;
/**
* the starting vertex in the geometry to start drawing from. If not specified,
* drawing will start from the first vertex.
*/
start?: number;
/**
* attribute divisor for instanced rendering. Note: this is a **WebGL-only** feature, the WebGPU renderer will
* issue a warning if one of the attributes has divisor set.
*/
divisor?: number;
}
/**
* The attribute options used by the constructor for adding geometries attributes
* extends {@link rendering.Attribute} but allows for the buffer to be a typed or number array
* @memberof rendering
*/
type AttributeOption = Omit<Attribute, 'buffer'> & {
buffer: Buffer | TypedArray | number[];
} | Buffer | TypedArray | number[];
export type AttributeOptions = Record<string, AttributeOption>;
/**
* the interface that describes the structure of the geometry
* @memberof rendering
*/
export interface GeometryDescriptor {
/** an optional label to easily identify the geometry */
label?: string;
/** the attributes that make up the geometry */
attributes: AttributeOptions;
/** optional index buffer for this geometry */
indexBuffer?: Buffer | TypedArray | number[];
/** the topology of the geometry, defaults to 'triangle-list' */
topology?: Topology;
instanceCount?: number;
}
/**
* A Geometry is a low-level object that represents the structure of 2D shapes in terms of vertices and attributes.
* It's a crucial component for rendering as it describes the shape and format of the data that will go through the shaders.
* Essentially, a Geometry object holds the data you'd send to a GPU buffer.
*
* A geometry is basically made of two components:
* <br>
* <b>Attributes</b>: These are essentially arrays that define properties of the vertices like position, color,
* texture coordinates, etc. They map directly to attributes in your vertex shaders.
* <br>
* <b>Indices</b>: An optional array that describes how the vertices are connected.
* If not provided, vertices will be interpreted in the sequence they're given.
* @example
*
* const geometry = new Geometry({
* attributes: {
* aPosition: [ // add some positions
* 0, 0,
* 0, 100,
* 100, 100,
* 100, 0,
* ],
* aUv: [ // add some uvs
* 0, 0,
* 0, 1,
* 1, 1,
* 1, 0,
* ]
* }
* });
* @memberof rendering
* @class
*/
export declare class Geometry extends EventEmitter<{
update: Geometry;
destroy: Geometry;
}> {
/** The topology of the geometry. */
topology: Topology;
/** The unique id of the geometry. */
readonly uid: number;
/** A record of the attributes of the geometry. */
readonly attributes: Record<string, Attribute>;
/** The buffers that the attributes use */
readonly buffers: Buffer[];
/** The index buffer of the geometry */
readonly indexBuffer: Buffer;
/**
* the layout key will be generated by WebGPU all geometries that have the same structure
* will have the same layout key. This is used to cache the pipeline layout
* @internal
* @ignore
*/
_layoutKey: number;
/** the instance count of the geometry to draw */
instanceCount: number;
private readonly _bounds;
private _boundsDirty;
/**
* Create a new instance of a geometry
* @param options - The options for the geometry.
*/
constructor(options: GeometryDescriptor);
protected onBufferUpdate(): void;
/**
* Returns the requested attribute.
* @param id - The name of the attribute required
* @returns - The attribute requested.
*/
getAttribute(id: string): Attribute;
/**
* Returns the index buffer
* @returns - The index buffer.
*/
getIndex(): Buffer;
/**
* Returns the requested buffer.
* @param id - The name of the buffer required.
* @returns - The buffer requested.
*/
getBuffer(id: string): Buffer;
/**
* Used to figure out how many vertices there are in this geometry
* @returns the number of vertices in the geometry
*/
getSize(): number;
/** Returns the bounds of the geometry. */
get bounds(): Bounds;
/**
* destroys the geometry.
* @param destroyBuffers - destroy the buffers associated with this geometry
*/
destroy(destroyBuffers?: boolean): void;
}
export {};

View File

@@ -0,0 +1,123 @@
'use strict';
var EventEmitter = require('eventemitter3');
var Bounds = require('../../../../scene/container/bounds/Bounds.js');
var uid = require('../../../../utils/data/uid.js');
var Buffer = require('../buffer/Buffer.js');
var ensureIsBuffer = require('./utils/ensureIsBuffer.js');
var getGeometryBounds = require('./utils/getGeometryBounds.js');
"use strict";
function ensureIsAttribute(attribute) {
if (attribute instanceof Buffer.Buffer || Array.isArray(attribute) || attribute.BYTES_PER_ELEMENT) {
attribute = {
buffer: attribute
};
}
attribute.buffer = ensureIsBuffer.ensureIsBuffer(attribute.buffer, false);
return attribute;
}
class Geometry extends EventEmitter {
/**
* Create a new instance of a geometry
* @param options - The options for the geometry.
*/
constructor(options) {
const { attributes, indexBuffer, topology } = options;
super();
/** The unique id of the geometry. */
this.uid = uid.uid("geometry");
/**
* the layout key will be generated by WebGPU all geometries that have the same structure
* will have the same layout key. This is used to cache the pipeline layout
* @internal
* @ignore
*/
this._layoutKey = 0;
/** the instance count of the geometry to draw */
this.instanceCount = 1;
this._bounds = new Bounds.Bounds();
this._boundsDirty = true;
this.attributes = attributes;
this.buffers = [];
this.instanceCount = options.instanceCount || 1;
for (const i in attributes) {
const attribute = attributes[i] = ensureIsAttribute(attributes[i]);
const bufferIndex = this.buffers.indexOf(attribute.buffer);
if (bufferIndex === -1) {
this.buffers.push(attribute.buffer);
attribute.buffer.on("update", this.onBufferUpdate, this);
attribute.buffer.on("change", this.onBufferUpdate, this);
}
}
if (indexBuffer) {
this.indexBuffer = ensureIsBuffer.ensureIsBuffer(indexBuffer, true);
this.buffers.push(this.indexBuffer);
}
this.topology = topology || "triangle-list";
}
onBufferUpdate() {
this._boundsDirty = true;
this.emit("update", this);
}
/**
* Returns the requested attribute.
* @param id - The name of the attribute required
* @returns - The attribute requested.
*/
getAttribute(id) {
return this.attributes[id];
}
/**
* Returns the index buffer
* @returns - The index buffer.
*/
getIndex() {
return this.indexBuffer;
}
/**
* Returns the requested buffer.
* @param id - The name of the buffer required.
* @returns - The buffer requested.
*/
getBuffer(id) {
return this.getAttribute(id).buffer;
}
/**
* Used to figure out how many vertices there are in this geometry
* @returns the number of vertices in the geometry
*/
getSize() {
for (const i in this.attributes) {
const attribute = this.attributes[i];
const buffer = attribute.buffer;
return buffer.data.length / (attribute.stride / 4 || attribute.size);
}
return 0;
}
/** Returns the bounds of the geometry. */
get bounds() {
if (!this._boundsDirty)
return this._bounds;
this._boundsDirty = false;
return getGeometryBounds.getGeometryBounds(this, "aPosition", this._bounds);
}
/**
* destroys the geometry.
* @param destroyBuffers - destroy the buffers associated with this geometry
*/
destroy(destroyBuffers = false) {
this.emit("destroy", this);
this.removeAllListeners();
if (destroyBuffers) {
this.buffers.forEach((buffer) => buffer.destroy());
}
this.attributes = null;
this.buffers = null;
this.indexBuffer = null;
this._bounds = null;
}
}
exports.Geometry = Geometry;
//# sourceMappingURL=Geometry.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,121 @@
import EventEmitter from 'eventemitter3';
import { Bounds } from '../../../../scene/container/bounds/Bounds.mjs';
import { uid } from '../../../../utils/data/uid.mjs';
import { Buffer } from '../buffer/Buffer.mjs';
import { ensureIsBuffer } from './utils/ensureIsBuffer.mjs';
import { getGeometryBounds } from './utils/getGeometryBounds.mjs';
"use strict";
function ensureIsAttribute(attribute) {
if (attribute instanceof Buffer || Array.isArray(attribute) || attribute.BYTES_PER_ELEMENT) {
attribute = {
buffer: attribute
};
}
attribute.buffer = ensureIsBuffer(attribute.buffer, false);
return attribute;
}
class Geometry extends EventEmitter {
/**
* Create a new instance of a geometry
* @param options - The options for the geometry.
*/
constructor(options) {
const { attributes, indexBuffer, topology } = options;
super();
/** The unique id of the geometry. */
this.uid = uid("geometry");
/**
* the layout key will be generated by WebGPU all geometries that have the same structure
* will have the same layout key. This is used to cache the pipeline layout
* @internal
* @ignore
*/
this._layoutKey = 0;
/** the instance count of the geometry to draw */
this.instanceCount = 1;
this._bounds = new Bounds();
this._boundsDirty = true;
this.attributes = attributes;
this.buffers = [];
this.instanceCount = options.instanceCount || 1;
for (const i in attributes) {
const attribute = attributes[i] = ensureIsAttribute(attributes[i]);
const bufferIndex = this.buffers.indexOf(attribute.buffer);
if (bufferIndex === -1) {
this.buffers.push(attribute.buffer);
attribute.buffer.on("update", this.onBufferUpdate, this);
attribute.buffer.on("change", this.onBufferUpdate, this);
}
}
if (indexBuffer) {
this.indexBuffer = ensureIsBuffer(indexBuffer, true);
this.buffers.push(this.indexBuffer);
}
this.topology = topology || "triangle-list";
}
onBufferUpdate() {
this._boundsDirty = true;
this.emit("update", this);
}
/**
* Returns the requested attribute.
* @param id - The name of the attribute required
* @returns - The attribute requested.
*/
getAttribute(id) {
return this.attributes[id];
}
/**
* Returns the index buffer
* @returns - The index buffer.
*/
getIndex() {
return this.indexBuffer;
}
/**
* Returns the requested buffer.
* @param id - The name of the buffer required.
* @returns - The buffer requested.
*/
getBuffer(id) {
return this.getAttribute(id).buffer;
}
/**
* Used to figure out how many vertices there are in this geometry
* @returns the number of vertices in the geometry
*/
getSize() {
for (const i in this.attributes) {
const attribute = this.attributes[i];
const buffer = attribute.buffer;
return buffer.data.length / (attribute.stride / 4 || attribute.size);
}
return 0;
}
/** Returns the bounds of the geometry. */
get bounds() {
if (!this._boundsDirty)
return this._bounds;
this._boundsDirty = false;
return getGeometryBounds(this, "aPosition", this._bounds);
}
/**
* destroys the geometry.
* @param destroyBuffers - destroy the buffers associated with this geometry
*/
destroy(destroyBuffers = false) {
this.emit("destroy", this);
this.removeAllListeners();
if (destroyBuffers) {
this.buffers.forEach((buffer) => buffer.destroy());
}
this.attributes = null;
this.buffers = null;
this.indexBuffer = null;
this._bounds = null;
}
}
export { Geometry };
//# sourceMappingURL=Geometry.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,18 @@
/**
* The different topology types supported by the renderer used to describe how the geometry should be renderer
* @memberof rendering
*/
export type Topology = 'point-list' | 'line-list' | 'line-strip' | 'triangle-list' | 'triangle-strip';
/** @deprecated since 8.0.0 */
export declare const DRAW_MODES: {
POINTS: string;
LINES: string;
LINE_STRIP: string;
TRIANGLES: string;
TRIANGLE_STRIP: string;
};
/**
* The different types of vertex formats supported by the renderer
* @memberof rendering
*/
export type VertexFormat = 'uint8x2' | 'uint8x4' | 'sint8x2' | 'sint8x4' | 'unorm8x2' | 'unorm8x4' | 'snorm8x2' | 'snorm8x4' | 'uint16x2' | 'uint16x4' | 'sint16x2' | 'sint16x4' | 'unorm16x2' | 'unorm16x4' | 'snorm16x2' | 'snorm16x4' | 'float16x2' | 'float16x4' | 'float32' | 'float32x2' | 'float32x3' | 'float32x4' | 'uint32' | 'uint32x2' | 'uint32x3' | 'uint32x4' | 'sint32' | 'sint32x2' | 'sint32x3' | 'sint32x4';

View File

@@ -0,0 +1,21 @@
'use strict';
var deprecation = require('../../../../utils/logging/deprecation.js');
"use strict";
const DEPRECATED_DRAW_MODES = {
POINTS: "point-list",
LINES: "line-list",
LINE_STRIP: "line-strip",
TRIANGLES: "triangle-list",
TRIANGLE_STRIP: "triangle-strip"
};
const DRAW_MODES = new Proxy(DEPRECATED_DRAW_MODES, {
get(target, prop) {
deprecation.deprecation(deprecation.v8_0_0, `DRAW_MODES.${prop} is deprecated, use '${DEPRECATED_DRAW_MODES[prop]}' instead`);
return target[prop];
}
});
exports.DRAW_MODES = DRAW_MODES;
//# sourceMappingURL=const.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"const.js","sources":["../../../../../src/rendering/renderers/shared/geometry/const.ts"],"sourcesContent":["import { deprecation, v8_0_0 } from '../../../../utils/logging/deprecation';\n\n/**\n * The different topology types supported by the renderer used to describe how the geometry should be renderer\n * @memberof rendering\n */\nexport type Topology =\n 'point-list'\n | 'line-list'\n | 'line-strip'\n | 'triangle-list'\n | 'triangle-strip';\n\nconst DEPRECATED_DRAW_MODES = {\n POINTS: 'point-list',\n LINES: 'line-list',\n LINE_STRIP: 'line-strip',\n TRIANGLES: 'triangle-list',\n TRIANGLE_STRIP: 'triangle-strip',\n};\n\n/** @deprecated since 8.0.0 */\nexport const DRAW_MODES = new Proxy(DEPRECATED_DRAW_MODES, {\n get(target, prop: keyof typeof DEPRECATED_DRAW_MODES)\n {\n // #if _DEBUG\n deprecation(v8_0_0, `DRAW_MODES.${prop} is deprecated, use '${DEPRECATED_DRAW_MODES[prop]}' instead`);\n // #endif\n\n return target[prop];\n },\n});\n\n/**\n * The different types of vertex formats supported by the renderer\n * @memberof rendering\n */\nexport type VertexFormat =\n | 'uint8x2'\n | 'uint8x4'\n | 'sint8x2'\n | 'sint8x4'\n | 'unorm8x2'\n | 'unorm8x4'\n | 'snorm8x2'\n | 'snorm8x4'\n | 'uint16x2'\n | 'uint16x4'\n | 'sint16x2'\n | 'sint16x4'\n | 'unorm16x2'\n | 'unorm16x4'\n | 'snorm16x2'\n | 'snorm16x4'\n | 'float16x2'\n | 'float16x4'\n | 'float32'\n | 'float32x2'\n | 'float32x3'\n | 'float32x4'\n | 'uint32'\n | 'uint32x2'\n | 'uint32x3'\n | 'uint32x4'\n | 'sint32'\n | 'sint32x2'\n | 'sint32x3'\n | 'sint32x4';\n\n"],"names":["deprecation","v8_0_0"],"mappings":";;;;;AAaA,MAAM,qBAAwB,GAAA;AAAA,EAC1B,MAAQ,EAAA,YAAA;AAAA,EACR,KAAO,EAAA,WAAA;AAAA,EACP,UAAY,EAAA,YAAA;AAAA,EACZ,SAAW,EAAA,eAAA;AAAA,EACX,cAAgB,EAAA,gBAAA;AACpB,CAAA,CAAA;AAGa,MAAA,UAAA,GAAa,IAAI,KAAA,CAAM,qBAAuB,EAAA;AAAA,EACvD,GAAA,CAAI,QAAQ,IACZ,EAAA;AAEI,IAAAA,uBAAA,CAAYC,oBAAQ,CAAc,WAAA,EAAA,IAAI,wBAAwB,qBAAsB,CAAA,IAAI,CAAC,CAAW,SAAA,CAAA,CAAA,CAAA;AAGpG,IAAA,OAAO,OAAO,IAAI,CAAA,CAAA;AAAA,GACtB;AACJ,CAAC;;;;"}

View File

@@ -0,0 +1,19 @@
import { deprecation, v8_0_0 } from '../../../../utils/logging/deprecation.mjs';
"use strict";
const DEPRECATED_DRAW_MODES = {
POINTS: "point-list",
LINES: "line-list",
LINE_STRIP: "line-strip",
TRIANGLES: "triangle-list",
TRIANGLE_STRIP: "triangle-strip"
};
const DRAW_MODES = new Proxy(DEPRECATED_DRAW_MODES, {
get(target, prop) {
deprecation(v8_0_0, `DRAW_MODES.${prop} is deprecated, use '${DEPRECATED_DRAW_MODES[prop]}' instead`);
return target[prop];
}
});
export { DRAW_MODES };
//# sourceMappingURL=const.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"const.mjs","sources":["../../../../../src/rendering/renderers/shared/geometry/const.ts"],"sourcesContent":["import { deprecation, v8_0_0 } from '../../../../utils/logging/deprecation';\n\n/**\n * The different topology types supported by the renderer used to describe how the geometry should be renderer\n * @memberof rendering\n */\nexport type Topology =\n 'point-list'\n | 'line-list'\n | 'line-strip'\n | 'triangle-list'\n | 'triangle-strip';\n\nconst DEPRECATED_DRAW_MODES = {\n POINTS: 'point-list',\n LINES: 'line-list',\n LINE_STRIP: 'line-strip',\n TRIANGLES: 'triangle-list',\n TRIANGLE_STRIP: 'triangle-strip',\n};\n\n/** @deprecated since 8.0.0 */\nexport const DRAW_MODES = new Proxy(DEPRECATED_DRAW_MODES, {\n get(target, prop: keyof typeof DEPRECATED_DRAW_MODES)\n {\n // #if _DEBUG\n deprecation(v8_0_0, `DRAW_MODES.${prop} is deprecated, use '${DEPRECATED_DRAW_MODES[prop]}' instead`);\n // #endif\n\n return target[prop];\n },\n});\n\n/**\n * The different types of vertex formats supported by the renderer\n * @memberof rendering\n */\nexport type VertexFormat =\n | 'uint8x2'\n | 'uint8x4'\n | 'sint8x2'\n | 'sint8x4'\n | 'unorm8x2'\n | 'unorm8x4'\n | 'snorm8x2'\n | 'snorm8x4'\n | 'uint16x2'\n | 'uint16x4'\n | 'sint16x2'\n | 'sint16x4'\n | 'unorm16x2'\n | 'unorm16x4'\n | 'snorm16x2'\n | 'snorm16x4'\n | 'float16x2'\n | 'float16x4'\n | 'float32'\n | 'float32x2'\n | 'float32x3'\n | 'float32x4'\n | 'uint32'\n | 'uint32x2'\n | 'uint32x3'\n | 'uint32x4'\n | 'sint32'\n | 'sint32x2'\n | 'sint32x3'\n | 'sint32x4';\n\n"],"names":[],"mappings":";;;AAaA,MAAM,qBAAwB,GAAA;AAAA,EAC1B,MAAQ,EAAA,YAAA;AAAA,EACR,KAAO,EAAA,WAAA;AAAA,EACP,UAAY,EAAA,YAAA;AAAA,EACZ,SAAW,EAAA,eAAA;AAAA,EACX,cAAgB,EAAA,gBAAA;AACpB,CAAA,CAAA;AAGa,MAAA,UAAA,GAAa,IAAI,KAAA,CAAM,qBAAuB,EAAA;AAAA,EACvD,GAAA,CAAI,QAAQ,IACZ,EAAA;AAEI,IAAA,WAAA,CAAY,QAAQ,CAAc,WAAA,EAAA,IAAI,wBAAwB,qBAAsB,CAAA,IAAI,CAAC,CAAW,SAAA,CAAA,CAAA,CAAA;AAGpG,IAAA,OAAO,OAAO,IAAI,CAAA,CAAA;AAAA,GACtB;AACJ,CAAC;;;;"}

View File

@@ -0,0 +1,16 @@
import type { Matrix } from '../../../../../maths/matrix/Matrix';
/**
* Takes a vertices array and a matrix and transforms the vertices based on the matrix.
* this out put is written to the uvs array
* @param vertices - the vertices to calculate uvs from
* @param verticesStride - the stride of the vertice
* @param verticesOffset - the offset of the vertices
* @param uvs - the uvs to fill
* @param uvsOffset - the offset of the uvs
* @param uvsStride - the stride of the uvs
* @param size - the size of the vertices
* @param matrix - the matrix to apply to the uvs
* @memberof rendering
*/
export declare function buildUvs(vertices: number[], verticesStride: number, verticesOffset: number, uvs: number[], uvsOffset: number, uvsStride: number, size: number, matrix?: Matrix): void;
export declare function buildSimpleUvs(uvs: number[], uvsOffset: number, uvsStride: number, size: number): void;

View File

@@ -0,0 +1,37 @@
'use strict';
"use strict";
function buildUvs(vertices, verticesStride, verticesOffset, uvs, uvsOffset, uvsStride, size, matrix = null) {
let index = 0;
verticesOffset *= verticesStride;
uvsOffset *= uvsStride;
const a = matrix.a;
const b = matrix.b;
const c = matrix.c;
const d = matrix.d;
const tx = matrix.tx;
const ty = matrix.ty;
while (index < size) {
const x = vertices[verticesOffset];
const y = vertices[verticesOffset + 1];
uvs[uvsOffset] = a * x + c * y + tx;
uvs[uvsOffset + 1] = b * x + d * y + ty;
uvsOffset += uvsStride;
verticesOffset += verticesStride;
index++;
}
}
function buildSimpleUvs(uvs, uvsOffset, uvsStride, size) {
let index = 0;
uvsOffset *= uvsStride;
while (index < size) {
uvs[uvsOffset] = 0;
uvs[uvsOffset + 1] = 0;
uvsOffset += uvsStride;
index++;
}
}
exports.buildSimpleUvs = buildSimpleUvs;
exports.buildUvs = buildUvs;
//# sourceMappingURL=buildUvs.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"buildUvs.js","sources":["../../../../../../src/rendering/renderers/shared/geometry/utils/buildUvs.ts"],"sourcesContent":["import type { Matrix } from '../../../../../maths/matrix/Matrix';\n\n/**\n * Takes a vertices array and a matrix and transforms the vertices based on the matrix.\n * this out put is written to the uvs array\n * @param vertices - the vertices to calculate uvs from\n * @param verticesStride - the stride of the vertice\n * @param verticesOffset - the offset of the vertices\n * @param uvs - the uvs to fill\n * @param uvsOffset - the offset of the uvs\n * @param uvsStride - the stride of the uvs\n * @param size - the size of the vertices\n * @param matrix - the matrix to apply to the uvs\n * @memberof rendering\n */\nexport function buildUvs(\n vertices: number[],\n verticesStride: number,\n verticesOffset: number,\n\n uvs: number[],\n uvsOffset: number,\n uvsStride: number,\n\n size: number,\n matrix: Matrix = null\n): void\n{\n let index = 0;\n\n verticesOffset *= verticesStride;\n uvsOffset *= uvsStride;\n\n const a = matrix.a;\n const b = matrix.b;\n const c = matrix.c;\n const d = matrix.d;\n const tx = matrix.tx;\n const ty = matrix.ty;\n\n while (index < size)\n {\n const x = vertices[verticesOffset];\n const y = vertices[verticesOffset + 1];\n\n uvs[uvsOffset] = (a * x) + (c * y) + tx;\n uvs[uvsOffset + 1] = (b * x) + (d * y) + ty;\n\n uvsOffset += uvsStride;\n\n verticesOffset += verticesStride;\n\n index++;\n }\n}\n\nexport function buildSimpleUvs(\n uvs: number[],\n uvsOffset: number,\n uvsStride: number,\n size: number,\n)\n{\n let index = 0;\n\n uvsOffset *= uvsStride;\n\n while (index < size)\n {\n uvs[uvsOffset] = 0;\n uvs[uvsOffset + 1] = 0;\n\n uvsOffset += uvsStride;\n\n index++;\n }\n}\n"],"names":[],"mappings":";;;AAegB,SAAA,QAAA,CACZ,UACA,cACA,EAAA,cAAA,EAEA,KACA,SACA,EAAA,SAAA,EAEA,IACA,EAAA,MAAA,GAAiB,IAErB,EAAA;AACI,EAAA,IAAI,KAAQ,GAAA,CAAA,CAAA;AAEZ,EAAkB,cAAA,IAAA,cAAA,CAAA;AAClB,EAAa,SAAA,IAAA,SAAA,CAAA;AAEb,EAAA,MAAM,IAAI,MAAO,CAAA,CAAA,CAAA;AACjB,EAAA,MAAM,IAAI,MAAO,CAAA,CAAA,CAAA;AACjB,EAAA,MAAM,IAAI,MAAO,CAAA,CAAA,CAAA;AACjB,EAAA,MAAM,IAAI,MAAO,CAAA,CAAA,CAAA;AACjB,EAAA,MAAM,KAAK,MAAO,CAAA,EAAA,CAAA;AAClB,EAAA,MAAM,KAAK,MAAO,CAAA,EAAA,CAAA;AAElB,EAAA,OAAO,QAAQ,IACf,EAAA;AACI,IAAM,MAAA,CAAA,GAAI,SAAS,cAAc,CAAA,CAAA;AACjC,IAAM,MAAA,CAAA,GAAI,QAAS,CAAA,cAAA,GAAiB,CAAC,CAAA,CAAA;AAErC,IAAA,GAAA,CAAI,SAAS,CAAA,GAAK,CAAI,GAAA,CAAA,GAAM,IAAI,CAAK,GAAA,EAAA,CAAA;AACrC,IAAA,GAAA,CAAI,YAAY,CAAC,CAAA,GAAK,CAAI,GAAA,CAAA,GAAM,IAAI,CAAK,GAAA,EAAA,CAAA;AAEzC,IAAa,SAAA,IAAA,SAAA,CAAA;AAEb,IAAkB,cAAA,IAAA,cAAA,CAAA;AAElB,IAAA,KAAA,EAAA,CAAA;AAAA,GACJ;AACJ,CAAA;AAEO,SAAS,cACZ,CAAA,GAAA,EACA,SACA,EAAA,SAAA,EACA,IAEJ,EAAA;AACI,EAAA,IAAI,KAAQ,GAAA,CAAA,CAAA;AAEZ,EAAa,SAAA,IAAA,SAAA,CAAA;AAEb,EAAA,OAAO,QAAQ,IACf,EAAA;AACI,IAAA,GAAA,CAAI,SAAS,CAAI,GAAA,CAAA,CAAA;AACjB,IAAI,GAAA,CAAA,SAAA,GAAY,CAAC,CAAI,GAAA,CAAA,CAAA;AAErB,IAAa,SAAA,IAAA,SAAA,CAAA;AAEb,IAAA,KAAA,EAAA,CAAA;AAAA,GACJ;AACJ;;;;;"}

View File

@@ -0,0 +1,34 @@
"use strict";
function buildUvs(vertices, verticesStride, verticesOffset, uvs, uvsOffset, uvsStride, size, matrix = null) {
let index = 0;
verticesOffset *= verticesStride;
uvsOffset *= uvsStride;
const a = matrix.a;
const b = matrix.b;
const c = matrix.c;
const d = matrix.d;
const tx = matrix.tx;
const ty = matrix.ty;
while (index < size) {
const x = vertices[verticesOffset];
const y = vertices[verticesOffset + 1];
uvs[uvsOffset] = a * x + c * y + tx;
uvs[uvsOffset + 1] = b * x + d * y + ty;
uvsOffset += uvsStride;
verticesOffset += verticesStride;
index++;
}
}
function buildSimpleUvs(uvs, uvsOffset, uvsStride, size) {
let index = 0;
uvsOffset *= uvsStride;
while (index < size) {
uvs[uvsOffset] = 0;
uvs[uvsOffset + 1] = 0;
uvsOffset += uvsStride;
index++;
}
}
export { buildSimpleUvs, buildUvs };
//# sourceMappingURL=buildUvs.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"buildUvs.mjs","sources":["../../../../../../src/rendering/renderers/shared/geometry/utils/buildUvs.ts"],"sourcesContent":["import type { Matrix } from '../../../../../maths/matrix/Matrix';\n\n/**\n * Takes a vertices array and a matrix and transforms the vertices based on the matrix.\n * this out put is written to the uvs array\n * @param vertices - the vertices to calculate uvs from\n * @param verticesStride - the stride of the vertice\n * @param verticesOffset - the offset of the vertices\n * @param uvs - the uvs to fill\n * @param uvsOffset - the offset of the uvs\n * @param uvsStride - the stride of the uvs\n * @param size - the size of the vertices\n * @param matrix - the matrix to apply to the uvs\n * @memberof rendering\n */\nexport function buildUvs(\n vertices: number[],\n verticesStride: number,\n verticesOffset: number,\n\n uvs: number[],\n uvsOffset: number,\n uvsStride: number,\n\n size: number,\n matrix: Matrix = null\n): void\n{\n let index = 0;\n\n verticesOffset *= verticesStride;\n uvsOffset *= uvsStride;\n\n const a = matrix.a;\n const b = matrix.b;\n const c = matrix.c;\n const d = matrix.d;\n const tx = matrix.tx;\n const ty = matrix.ty;\n\n while (index < size)\n {\n const x = vertices[verticesOffset];\n const y = vertices[verticesOffset + 1];\n\n uvs[uvsOffset] = (a * x) + (c * y) + tx;\n uvs[uvsOffset + 1] = (b * x) + (d * y) + ty;\n\n uvsOffset += uvsStride;\n\n verticesOffset += verticesStride;\n\n index++;\n }\n}\n\nexport function buildSimpleUvs(\n uvs: number[],\n uvsOffset: number,\n uvsStride: number,\n size: number,\n)\n{\n let index = 0;\n\n uvsOffset *= uvsStride;\n\n while (index < size)\n {\n uvs[uvsOffset] = 0;\n uvs[uvsOffset + 1] = 0;\n\n uvsOffset += uvsStride;\n\n index++;\n }\n}\n"],"names":[],"mappings":";AAegB,SAAA,QAAA,CACZ,UACA,cACA,EAAA,cAAA,EAEA,KACA,SACA,EAAA,SAAA,EAEA,IACA,EAAA,MAAA,GAAiB,IAErB,EAAA;AACI,EAAA,IAAI,KAAQ,GAAA,CAAA,CAAA;AAEZ,EAAkB,cAAA,IAAA,cAAA,CAAA;AAClB,EAAa,SAAA,IAAA,SAAA,CAAA;AAEb,EAAA,MAAM,IAAI,MAAO,CAAA,CAAA,CAAA;AACjB,EAAA,MAAM,IAAI,MAAO,CAAA,CAAA,CAAA;AACjB,EAAA,MAAM,IAAI,MAAO,CAAA,CAAA,CAAA;AACjB,EAAA,MAAM,IAAI,MAAO,CAAA,CAAA,CAAA;AACjB,EAAA,MAAM,KAAK,MAAO,CAAA,EAAA,CAAA;AAClB,EAAA,MAAM,KAAK,MAAO,CAAA,EAAA,CAAA;AAElB,EAAA,OAAO,QAAQ,IACf,EAAA;AACI,IAAM,MAAA,CAAA,GAAI,SAAS,cAAc,CAAA,CAAA;AACjC,IAAM,MAAA,CAAA,GAAI,QAAS,CAAA,cAAA,GAAiB,CAAC,CAAA,CAAA;AAErC,IAAA,GAAA,CAAI,SAAS,CAAA,GAAK,CAAI,GAAA,CAAA,GAAM,IAAI,CAAK,GAAA,EAAA,CAAA;AACrC,IAAA,GAAA,CAAI,YAAY,CAAC,CAAA,GAAK,CAAI,GAAA,CAAA,GAAM,IAAI,CAAK,GAAA,EAAA,CAAA;AAEzC,IAAa,SAAA,IAAA,SAAA,CAAA;AAEb,IAAkB,cAAA,IAAA,cAAA,CAAA;AAElB,IAAA,KAAA,EAAA,CAAA;AAAA,GACJ;AACJ,CAAA;AAEO,SAAS,cACZ,CAAA,GAAA,EACA,SACA,EAAA,SAAA,EACA,IAEJ,EAAA;AACI,EAAA,IAAI,KAAQ,GAAA,CAAA,CAAA;AAEZ,EAAa,SAAA,IAAA,SAAA,CAAA;AAEb,EAAA,OAAO,QAAQ,IACf,EAAA;AACI,IAAA,GAAA,CAAI,SAAS,CAAI,GAAA,CAAA,CAAA;AACjB,IAAI,GAAA,CAAA,SAAA,GAAY,CAAC,CAAI,GAAA,CAAA,CAAA;AAErB,IAAa,SAAA,IAAA,SAAA,CAAA;AAEb,IAAA,KAAA,EAAA,CAAA;AAAA,GACJ;AACJ;;;;"}

View File

@@ -0,0 +1,12 @@
import { Buffer } from '../../buffer/Buffer';
import type { TypedArray } from '../../buffer/Buffer';
/**
* Converts something into a buffer. If it is already a buffer it will pass it through
* if it is a number array it will convert it to a float32 array before being passed into a buffer
* the buffer will be created with the correct usage flags for geometry attributes
* @param buffer - number array
* @param index - is this an index buffer?
* @returns a buffer
* @memberof rendering
*/
export declare function ensureIsBuffer(buffer: Buffer | TypedArray | number[], index: boolean): Buffer;

View File

@@ -0,0 +1,29 @@
'use strict';
var Buffer = require('../../buffer/Buffer.js');
var _const = require('../../buffer/const.js');
"use strict";
function ensureIsBuffer(buffer, index) {
if (!(buffer instanceof Buffer.Buffer)) {
let usage = index ? _const.BufferUsage.INDEX : _const.BufferUsage.VERTEX;
if (buffer instanceof Array) {
if (index) {
buffer = new Uint32Array(buffer);
usage = _const.BufferUsage.INDEX | _const.BufferUsage.COPY_DST;
} else {
buffer = new Float32Array(buffer);
usage = _const.BufferUsage.VERTEX | _const.BufferUsage.COPY_DST;
}
}
buffer = new Buffer.Buffer({
data: buffer,
label: index ? "index-mesh-buffer" : "vertex-mesh-buffer",
usage
});
}
return buffer;
}
exports.ensureIsBuffer = ensureIsBuffer;
//# sourceMappingURL=ensureIsBuffer.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"ensureIsBuffer.js","sources":["../../../../../../src/rendering/renderers/shared/geometry/utils/ensureIsBuffer.ts"],"sourcesContent":["import { Buffer } from '../../buffer/Buffer';\nimport { BufferUsage } from '../../buffer/const';\n\nimport type { TypedArray } from '../../buffer/Buffer';\n\n/**\n * Converts something into a buffer. If it is already a buffer it will pass it through\n * if it is a number array it will convert it to a float32 array before being passed into a buffer\n * the buffer will be created with the correct usage flags for geometry attributes\n * @param buffer - number array\n * @param index - is this an index buffer?\n * @returns a buffer\n * @memberof rendering\n */\nexport function ensureIsBuffer(buffer: Buffer | TypedArray | number[], index: boolean): Buffer\n{\n if (!(buffer instanceof Buffer))\n {\n let usage: number = index ? BufferUsage.INDEX : BufferUsage.VERTEX;\n\n // its an array!\n if (buffer instanceof Array)\n {\n if (index)\n {\n buffer = new Uint32Array(buffer);\n usage = BufferUsage.INDEX | BufferUsage.COPY_DST;\n }\n\n else\n {\n buffer = new Float32Array(buffer);\n usage = BufferUsage.VERTEX | BufferUsage.COPY_DST;\n }\n }\n\n buffer = new Buffer({\n data: buffer,\n label: index ? 'index-mesh-buffer' : 'vertex-mesh-buffer',\n usage\n });\n }\n\n return buffer;\n}\n"],"names":["Buffer","BufferUsage"],"mappings":";;;;;;AAcgB,SAAA,cAAA,CAAe,QAAwC,KACvE,EAAA;AACI,EAAI,IAAA,EAAE,kBAAkBA,aACxB,CAAA,EAAA;AACI,IAAA,IAAI,KAAgB,GAAA,KAAA,GAAQC,kBAAY,CAAA,KAAA,GAAQA,kBAAY,CAAA,MAAA,CAAA;AAG5D,IAAA,IAAI,kBAAkB,KACtB,EAAA;AACI,MAAA,IAAI,KACJ,EAAA;AACI,QAAS,MAAA,GAAA,IAAI,YAAY,MAAM,CAAA,CAAA;AAC/B,QAAQ,KAAA,GAAAA,kBAAA,CAAY,QAAQA,kBAAY,CAAA,QAAA,CAAA;AAAA,OAI5C,MAAA;AACI,QAAS,MAAA,GAAA,IAAI,aAAa,MAAM,CAAA,CAAA;AAChC,QAAQ,KAAA,GAAAA,kBAAA,CAAY,SAASA,kBAAY,CAAA,QAAA,CAAA;AAAA,OAC7C;AAAA,KACJ;AAEA,IAAA,MAAA,GAAS,IAAID,aAAO,CAAA;AAAA,MAChB,IAAM,EAAA,MAAA;AAAA,MACN,KAAA,EAAO,QAAQ,mBAAsB,GAAA,oBAAA;AAAA,MACrC,KAAA;AAAA,KACH,CAAA,CAAA;AAAA,GACL;AAEA,EAAO,OAAA,MAAA,CAAA;AACX;;;;"}

View File

@@ -0,0 +1,27 @@
import { Buffer } from '../../buffer/Buffer.mjs';
import { BufferUsage } from '../../buffer/const.mjs';
"use strict";
function ensureIsBuffer(buffer, index) {
if (!(buffer instanceof Buffer)) {
let usage = index ? BufferUsage.INDEX : BufferUsage.VERTEX;
if (buffer instanceof Array) {
if (index) {
buffer = new Uint32Array(buffer);
usage = BufferUsage.INDEX | BufferUsage.COPY_DST;
} else {
buffer = new Float32Array(buffer);
usage = BufferUsage.VERTEX | BufferUsage.COPY_DST;
}
}
buffer = new Buffer({
data: buffer,
label: index ? "index-mesh-buffer" : "vertex-mesh-buffer",
usage
});
}
return buffer;
}
export { ensureIsBuffer };
//# sourceMappingURL=ensureIsBuffer.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"ensureIsBuffer.mjs","sources":["../../../../../../src/rendering/renderers/shared/geometry/utils/ensureIsBuffer.ts"],"sourcesContent":["import { Buffer } from '../../buffer/Buffer';\nimport { BufferUsage } from '../../buffer/const';\n\nimport type { TypedArray } from '../../buffer/Buffer';\n\n/**\n * Converts something into a buffer. If it is already a buffer it will pass it through\n * if it is a number array it will convert it to a float32 array before being passed into a buffer\n * the buffer will be created with the correct usage flags for geometry attributes\n * @param buffer - number array\n * @param index - is this an index buffer?\n * @returns a buffer\n * @memberof rendering\n */\nexport function ensureIsBuffer(buffer: Buffer | TypedArray | number[], index: boolean): Buffer\n{\n if (!(buffer instanceof Buffer))\n {\n let usage: number = index ? BufferUsage.INDEX : BufferUsage.VERTEX;\n\n // its an array!\n if (buffer instanceof Array)\n {\n if (index)\n {\n buffer = new Uint32Array(buffer);\n usage = BufferUsage.INDEX | BufferUsage.COPY_DST;\n }\n\n else\n {\n buffer = new Float32Array(buffer);\n usage = BufferUsage.VERTEX | BufferUsage.COPY_DST;\n }\n }\n\n buffer = new Buffer({\n data: buffer,\n label: index ? 'index-mesh-buffer' : 'vertex-mesh-buffer',\n usage\n });\n }\n\n return buffer;\n}\n"],"names":[],"mappings":";;;;AAcgB,SAAA,cAAA,CAAe,QAAwC,KACvE,EAAA;AACI,EAAI,IAAA,EAAE,kBAAkB,MACxB,CAAA,EAAA;AACI,IAAA,IAAI,KAAgB,GAAA,KAAA,GAAQ,WAAY,CAAA,KAAA,GAAQ,WAAY,CAAA,MAAA,CAAA;AAG5D,IAAA,IAAI,kBAAkB,KACtB,EAAA;AACI,MAAA,IAAI,KACJ,EAAA;AACI,QAAS,MAAA,GAAA,IAAI,YAAY,MAAM,CAAA,CAAA;AAC/B,QAAQ,KAAA,GAAA,WAAA,CAAY,QAAQ,WAAY,CAAA,QAAA,CAAA;AAAA,OAI5C,MAAA;AACI,QAAS,MAAA,GAAA,IAAI,aAAa,MAAM,CAAA,CAAA;AAChC,QAAQ,KAAA,GAAA,WAAA,CAAY,SAAS,WAAY,CAAA,QAAA,CAAA;AAAA,OAC7C;AAAA,KACJ;AAEA,IAAA,MAAA,GAAS,IAAI,MAAO,CAAA;AAAA,MAChB,IAAM,EAAA,MAAA;AAAA,MACN,KAAA,EAAO,QAAQ,mBAAsB,GAAA,oBAAA;AAAA,MACrC,KAAA;AAAA,KACH,CAAA,CAAA;AAAA,GACL;AAEA,EAAO,OAAA,MAAA,CAAA;AACX;;;;"}

View File

@@ -0,0 +1,6 @@
import type { VertexFormat } from '../const';
export declare function getAttributeInfoFromFormat(format: VertexFormat): {
size: number;
stride: number;
normalised: boolean;
};

View File

@@ -0,0 +1,41 @@
'use strict';
"use strict";
const attributeFormatData = {
uint8x2: { size: 2, stride: 2, normalised: false },
uint8x4: { size: 4, stride: 4, normalised: false },
sint8x2: { size: 2, stride: 2, normalised: false },
sint8x4: { size: 4, stride: 4, normalised: false },
unorm8x2: { size: 2, stride: 2, normalised: true },
unorm8x4: { size: 4, stride: 4, normalised: true },
snorm8x2: { size: 2, stride: 2, normalised: true },
snorm8x4: { size: 4, stride: 4, normalised: true },
uint16x2: { size: 2, stride: 4, normalised: false },
uint16x4: { size: 4, stride: 8, normalised: false },
sint16x2: { size: 2, stride: 4, normalised: false },
sint16x4: { size: 4, stride: 8, normalised: false },
unorm16x2: { size: 2, stride: 4, normalised: true },
unorm16x4: { size: 4, stride: 8, normalised: true },
snorm16x2: { size: 2, stride: 4, normalised: true },
snorm16x4: { size: 4, stride: 8, normalised: true },
float16x2: { size: 2, stride: 4, normalised: false },
float16x4: { size: 4, stride: 8, normalised: false },
float32: { size: 1, stride: 4, normalised: false },
float32x2: { size: 2, stride: 8, normalised: false },
float32x3: { size: 3, stride: 12, normalised: false },
float32x4: { size: 4, stride: 16, normalised: false },
uint32: { size: 1, stride: 4, normalised: false },
uint32x2: { size: 2, stride: 8, normalised: false },
uint32x3: { size: 3, stride: 12, normalised: false },
uint32x4: { size: 4, stride: 16, normalised: false },
sint32: { size: 1, stride: 4, normalised: false },
sint32x2: { size: 2, stride: 8, normalised: false },
sint32x3: { size: 3, stride: 12, normalised: false },
sint32x4: { size: 4, stride: 16, normalised: false }
};
function getAttributeInfoFromFormat(format) {
return attributeFormatData[format] ?? attributeFormatData.float32;
}
exports.getAttributeInfoFromFormat = getAttributeInfoFromFormat;
//# sourceMappingURL=getAttributeInfoFromFormat.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"getAttributeInfoFromFormat.js","sources":["../../../../../../src/rendering/renderers/shared/geometry/utils/getAttributeInfoFromFormat.ts"],"sourcesContent":["import type { VertexFormat } from '../const';\n\nconst attributeFormatData = {\n uint8x2: { size: 2, stride: 2, normalised: false },\n uint8x4: { size: 4, stride: 4, normalised: false },\n sint8x2: { size: 2, stride: 2, normalised: false },\n sint8x4: { size: 4, stride: 4, normalised: false },\n unorm8x2: { size: 2, stride: 2, normalised: true },\n unorm8x4: { size: 4, stride: 4, normalised: true },\n snorm8x2: { size: 2, stride: 2, normalised: true },\n snorm8x4: { size: 4, stride: 4, normalised: true },\n uint16x2: { size: 2, stride: 4, normalised: false },\n uint16x4: { size: 4, stride: 8, normalised: false },\n sint16x2: { size: 2, stride: 4, normalised: false },\n sint16x4: { size: 4, stride: 8, normalised: false },\n unorm16x2: { size: 2, stride: 4, normalised: true },\n unorm16x4: { size: 4, stride: 8, normalised: true },\n snorm16x2: { size: 2, stride: 4, normalised: true },\n snorm16x4: { size: 4, stride: 8, normalised: true },\n float16x2: { size: 2, stride: 4, normalised: false },\n float16x4: { size: 4, stride: 8, normalised: false },\n float32: { size: 1, stride: 4, normalised: false },\n float32x2: { size: 2, stride: 8, normalised: false },\n float32x3: { size: 3, stride: 12, normalised: false },\n float32x4: { size: 4, stride: 16, normalised: false },\n uint32: { size: 1, stride: 4, normalised: false },\n uint32x2: { size: 2, stride: 8, normalised: false },\n uint32x3: { size: 3, stride: 12, normalised: false },\n uint32x4: { size: 4, stride: 16, normalised: false },\n sint32: { size: 1, stride: 4, normalised: false },\n sint32x2: { size: 2, stride: 8, normalised: false },\n sint32x3: { size: 3, stride: 12, normalised: false },\n sint32x4: { size: 4, stride: 16, normalised: false },\n};\n\nexport function getAttributeInfoFromFormat(format: VertexFormat): { size: number; stride: number; normalised: boolean }\n{\n return attributeFormatData[format] ?? attributeFormatData.float32;\n}\n"],"names":[],"mappings":";;;AAEA,MAAM,mBAAsB,GAAA;AAAA,EACxB,SAAS,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,KAAM,EAAA;AAAA,EACjD,SAAS,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,KAAM,EAAA;AAAA,EACjD,SAAS,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,KAAM,EAAA;AAAA,EACjD,SAAS,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,KAAM,EAAA;AAAA,EACjD,UAAU,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,IAAK,EAAA;AAAA,EACjD,UAAU,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,IAAK,EAAA;AAAA,EACjD,UAAU,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,IAAK,EAAA;AAAA,EACjD,UAAU,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,IAAK,EAAA;AAAA,EACjD,UAAU,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,KAAM,EAAA;AAAA,EAClD,UAAU,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,KAAM,EAAA;AAAA,EAClD,UAAU,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,KAAM,EAAA;AAAA,EAClD,UAAU,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,KAAM,EAAA;AAAA,EAClD,WAAW,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,IAAK,EAAA;AAAA,EAClD,WAAW,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,IAAK,EAAA;AAAA,EAClD,WAAW,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,IAAK,EAAA;AAAA,EAClD,WAAW,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,IAAK,EAAA;AAAA,EAClD,WAAW,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,KAAM,EAAA;AAAA,EACnD,WAAW,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,KAAM,EAAA;AAAA,EACnD,SAAS,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,KAAM,EAAA;AAAA,EACjD,WAAW,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,KAAM,EAAA;AAAA,EACnD,WAAW,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,EAAA,EAAI,YAAY,KAAM,EAAA;AAAA,EACpD,WAAW,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,EAAA,EAAI,YAAY,KAAM,EAAA;AAAA,EACpD,QAAQ,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,KAAM,EAAA;AAAA,EAChD,UAAU,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,KAAM,EAAA;AAAA,EAClD,UAAU,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,EAAA,EAAI,YAAY,KAAM,EAAA;AAAA,EACnD,UAAU,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,EAAA,EAAI,YAAY,KAAM,EAAA;AAAA,EACnD,QAAQ,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,KAAM,EAAA;AAAA,EAChD,UAAU,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,KAAM,EAAA;AAAA,EAClD,UAAU,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,EAAA,EAAI,YAAY,KAAM,EAAA;AAAA,EACnD,UAAU,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,EAAA,EAAI,YAAY,KAAM,EAAA;AACvD,CAAA,CAAA;AAEO,SAAS,2BAA2B,MAC3C,EAAA;AACI,EAAO,OAAA,mBAAA,CAAoB,MAAM,CAAA,IAAK,mBAAoB,CAAA,OAAA,CAAA;AAC9D;;;;"}

View File

@@ -0,0 +1,39 @@
"use strict";
const attributeFormatData = {
uint8x2: { size: 2, stride: 2, normalised: false },
uint8x4: { size: 4, stride: 4, normalised: false },
sint8x2: { size: 2, stride: 2, normalised: false },
sint8x4: { size: 4, stride: 4, normalised: false },
unorm8x2: { size: 2, stride: 2, normalised: true },
unorm8x4: { size: 4, stride: 4, normalised: true },
snorm8x2: { size: 2, stride: 2, normalised: true },
snorm8x4: { size: 4, stride: 4, normalised: true },
uint16x2: { size: 2, stride: 4, normalised: false },
uint16x4: { size: 4, stride: 8, normalised: false },
sint16x2: { size: 2, stride: 4, normalised: false },
sint16x4: { size: 4, stride: 8, normalised: false },
unorm16x2: { size: 2, stride: 4, normalised: true },
unorm16x4: { size: 4, stride: 8, normalised: true },
snorm16x2: { size: 2, stride: 4, normalised: true },
snorm16x4: { size: 4, stride: 8, normalised: true },
float16x2: { size: 2, stride: 4, normalised: false },
float16x4: { size: 4, stride: 8, normalised: false },
float32: { size: 1, stride: 4, normalised: false },
float32x2: { size: 2, stride: 8, normalised: false },
float32x3: { size: 3, stride: 12, normalised: false },
float32x4: { size: 4, stride: 16, normalised: false },
uint32: { size: 1, stride: 4, normalised: false },
uint32x2: { size: 2, stride: 8, normalised: false },
uint32x3: { size: 3, stride: 12, normalised: false },
uint32x4: { size: 4, stride: 16, normalised: false },
sint32: { size: 1, stride: 4, normalised: false },
sint32x2: { size: 2, stride: 8, normalised: false },
sint32x3: { size: 3, stride: 12, normalised: false },
sint32x4: { size: 4, stride: 16, normalised: false }
};
function getAttributeInfoFromFormat(format) {
return attributeFormatData[format] ?? attributeFormatData.float32;
}
export { getAttributeInfoFromFormat };
//# sourceMappingURL=getAttributeInfoFromFormat.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"getAttributeInfoFromFormat.mjs","sources":["../../../../../../src/rendering/renderers/shared/geometry/utils/getAttributeInfoFromFormat.ts"],"sourcesContent":["import type { VertexFormat } from '../const';\n\nconst attributeFormatData = {\n uint8x2: { size: 2, stride: 2, normalised: false },\n uint8x4: { size: 4, stride: 4, normalised: false },\n sint8x2: { size: 2, stride: 2, normalised: false },\n sint8x4: { size: 4, stride: 4, normalised: false },\n unorm8x2: { size: 2, stride: 2, normalised: true },\n unorm8x4: { size: 4, stride: 4, normalised: true },\n snorm8x2: { size: 2, stride: 2, normalised: true },\n snorm8x4: { size: 4, stride: 4, normalised: true },\n uint16x2: { size: 2, stride: 4, normalised: false },\n uint16x4: { size: 4, stride: 8, normalised: false },\n sint16x2: { size: 2, stride: 4, normalised: false },\n sint16x4: { size: 4, stride: 8, normalised: false },\n unorm16x2: { size: 2, stride: 4, normalised: true },\n unorm16x4: { size: 4, stride: 8, normalised: true },\n snorm16x2: { size: 2, stride: 4, normalised: true },\n snorm16x4: { size: 4, stride: 8, normalised: true },\n float16x2: { size: 2, stride: 4, normalised: false },\n float16x4: { size: 4, stride: 8, normalised: false },\n float32: { size: 1, stride: 4, normalised: false },\n float32x2: { size: 2, stride: 8, normalised: false },\n float32x3: { size: 3, stride: 12, normalised: false },\n float32x4: { size: 4, stride: 16, normalised: false },\n uint32: { size: 1, stride: 4, normalised: false },\n uint32x2: { size: 2, stride: 8, normalised: false },\n uint32x3: { size: 3, stride: 12, normalised: false },\n uint32x4: { size: 4, stride: 16, normalised: false },\n sint32: { size: 1, stride: 4, normalised: false },\n sint32x2: { size: 2, stride: 8, normalised: false },\n sint32x3: { size: 3, stride: 12, normalised: false },\n sint32x4: { size: 4, stride: 16, normalised: false },\n};\n\nexport function getAttributeInfoFromFormat(format: VertexFormat): { size: number; stride: number; normalised: boolean }\n{\n return attributeFormatData[format] ?? attributeFormatData.float32;\n}\n"],"names":[],"mappings":";AAEA,MAAM,mBAAsB,GAAA;AAAA,EACxB,SAAS,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,KAAM,EAAA;AAAA,EACjD,SAAS,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,KAAM,EAAA;AAAA,EACjD,SAAS,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,KAAM,EAAA;AAAA,EACjD,SAAS,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,KAAM,EAAA;AAAA,EACjD,UAAU,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,IAAK,EAAA;AAAA,EACjD,UAAU,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,IAAK,EAAA;AAAA,EACjD,UAAU,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,IAAK,EAAA;AAAA,EACjD,UAAU,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,IAAK,EAAA;AAAA,EACjD,UAAU,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,KAAM,EAAA;AAAA,EAClD,UAAU,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,KAAM,EAAA;AAAA,EAClD,UAAU,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,KAAM,EAAA;AAAA,EAClD,UAAU,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,KAAM,EAAA;AAAA,EAClD,WAAW,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,IAAK,EAAA;AAAA,EAClD,WAAW,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,IAAK,EAAA;AAAA,EAClD,WAAW,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,IAAK,EAAA;AAAA,EAClD,WAAW,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,IAAK,EAAA;AAAA,EAClD,WAAW,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,KAAM,EAAA;AAAA,EACnD,WAAW,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,KAAM,EAAA;AAAA,EACnD,SAAS,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,KAAM,EAAA;AAAA,EACjD,WAAW,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,KAAM,EAAA;AAAA,EACnD,WAAW,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,EAAA,EAAI,YAAY,KAAM,EAAA;AAAA,EACpD,WAAW,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,EAAA,EAAI,YAAY,KAAM,EAAA;AAAA,EACpD,QAAQ,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,KAAM,EAAA;AAAA,EAChD,UAAU,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,KAAM,EAAA;AAAA,EAClD,UAAU,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,EAAA,EAAI,YAAY,KAAM,EAAA;AAAA,EACnD,UAAU,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,EAAA,EAAI,YAAY,KAAM,EAAA;AAAA,EACnD,QAAQ,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,KAAM,EAAA;AAAA,EAChD,UAAU,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,CAAA,EAAG,YAAY,KAAM,EAAA;AAAA,EAClD,UAAU,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,EAAA,EAAI,YAAY,KAAM,EAAA;AAAA,EACnD,UAAU,EAAE,IAAA,EAAM,GAAG,MAAQ,EAAA,EAAA,EAAI,YAAY,KAAM,EAAA;AACvD,CAAA,CAAA;AAEO,SAAS,2BAA2B,MAC3C,EAAA;AACI,EAAO,OAAA,mBAAA,CAAoB,MAAM,CAAA,IAAK,mBAAoB,CAAA,OAAA,CAAA;AAC9D;;;;"}

View File

@@ -0,0 +1,10 @@
import type { Bounds } from '../../../../../scene/container/bounds/Bounds';
import type { Geometry } from '../Geometry';
/**
* Gets the 2D bounds of a geometry, based on a specific attribute.
* @param geometry - Geometry to to measure
* @param attributeId - AttributeId that contains the x,y data
* @param bounds - Bounds to store the result in
* @returns the bounds
*/
export declare function getGeometryBounds(geometry: Geometry, attributeId: string, bounds: Bounds): Bounds;

View File

@@ -0,0 +1,41 @@
'use strict';
"use strict";
function getGeometryBounds(geometry, attributeId, bounds) {
const attribute = geometry.getAttribute(attributeId);
if (!attribute) {
bounds.minX = 0;
bounds.minY = 0;
bounds.maxX = 0;
bounds.maxY = 0;
return bounds;
}
const data = attribute.buffer.data;
let minX = Infinity;
let minY = Infinity;
let maxX = -Infinity;
let maxY = -Infinity;
const byteSize = data.BYTES_PER_ELEMENT;
const offset = (attribute.offset || 0) / byteSize;
const stride = (attribute.stride || 2 * 4) / byteSize;
for (let i = offset; i < data.length; i += stride) {
const x = data[i];
const y = data[i + 1];
if (x > maxX)
maxX = x;
if (y > maxY)
maxY = y;
if (x < minX)
minX = x;
if (y < minY)
minY = y;
}
bounds.minX = minX;
bounds.minY = minY;
bounds.maxX = maxX;
bounds.maxY = maxY;
return bounds;
}
exports.getGeometryBounds = getGeometryBounds;
//# sourceMappingURL=getGeometryBounds.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"getGeometryBounds.js","sources":["../../../../../../src/rendering/renderers/shared/geometry/utils/getGeometryBounds.ts"],"sourcesContent":["import type { Bounds } from '../../../../../scene/container/bounds/Bounds';\nimport type { Geometry } from '../Geometry';\n\n/**\n * Gets the 2D bounds of a geometry, based on a specific attribute.\n * @param geometry - Geometry to to measure\n * @param attributeId - AttributeId that contains the x,y data\n * @param bounds - Bounds to store the result in\n * @returns the bounds\n */\nexport function getGeometryBounds(geometry: Geometry, attributeId: string, bounds: Bounds): Bounds\n{\n const attribute = geometry.getAttribute(attributeId);\n\n if (!attribute)\n {\n bounds.minX = 0;\n bounds.minY = 0;\n bounds.maxX = 0;\n bounds.maxY = 0;\n\n return bounds;\n }\n\n const data = attribute.buffer.data as Float32Array;\n\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n\n const byteSize = data.BYTES_PER_ELEMENT;\n\n // stride and offset MAY have not been calculated yet.. so go with assumed defaults\n const offset = (attribute.offset || 0) / byteSize;\n const stride = (attribute.stride || (2 * 4)) / byteSize;\n\n for (let i = offset; i < data.length; i += stride)\n {\n const x = data[i];\n const y = data[i + 1];\n\n if (x > maxX)maxX = x;\n if (y > maxY)maxY = y;\n if (x < minX)minX = x;\n if (y < minY)minY = y;\n }\n\n bounds.minX = minX;\n bounds.minY = minY;\n bounds.maxX = maxX;\n bounds.maxY = maxY;\n\n return bounds;\n}\n"],"names":[],"mappings":";;;AAUgB,SAAA,iBAAA,CAAkB,QAAoB,EAAA,WAAA,EAAqB,MAC3E,EAAA;AACI,EAAM,MAAA,SAAA,GAAY,QAAS,CAAA,YAAA,CAAa,WAAW,CAAA,CAAA;AAEnD,EAAA,IAAI,CAAC,SACL,EAAA;AACI,IAAA,MAAA,CAAO,IAAO,GAAA,CAAA,CAAA;AACd,IAAA,MAAA,CAAO,IAAO,GAAA,CAAA,CAAA;AACd,IAAA,MAAA,CAAO,IAAO,GAAA,CAAA,CAAA;AACd,IAAA,MAAA,CAAO,IAAO,GAAA,CAAA,CAAA;AAEd,IAAO,OAAA,MAAA,CAAA;AAAA,GACX;AAEA,EAAM,MAAA,IAAA,GAAO,UAAU,MAAO,CAAA,IAAA,CAAA;AAE9B,EAAA,IAAI,IAAO,GAAA,QAAA,CAAA;AACX,EAAA,IAAI,IAAO,GAAA,QAAA,CAAA;AACX,EAAA,IAAI,IAAO,GAAA,CAAA,QAAA,CAAA;AACX,EAAA,IAAI,IAAO,GAAA,CAAA,QAAA,CAAA;AAEX,EAAA,MAAM,WAAW,IAAK,CAAA,iBAAA,CAAA;AAGtB,EAAM,MAAA,MAAA,GAAA,CAAU,SAAU,CAAA,MAAA,IAAU,CAAK,IAAA,QAAA,CAAA;AACzC,EAAA,MAAM,MAAU,GAAA,CAAA,SAAA,CAAU,MAAW,IAAA,CAAA,GAAI,CAAM,IAAA,QAAA,CAAA;AAE/C,EAAA,KAAA,IAAS,IAAI,MAAQ,EAAA,CAAA,GAAI,IAAK,CAAA,MAAA,EAAQ,KAAK,MAC3C,EAAA;AACI,IAAM,MAAA,CAAA,GAAI,KAAK,CAAC,CAAA,CAAA;AAChB,IAAM,MAAA,CAAA,GAAI,IAAK,CAAA,CAAA,GAAI,CAAC,CAAA,CAAA;AAEpB,IAAA,IAAI,CAAI,GAAA,IAAA;AAAK,MAAO,IAAA,GAAA,CAAA,CAAA;AACpB,IAAA,IAAI,CAAI,GAAA,IAAA;AAAK,MAAO,IAAA,GAAA,CAAA,CAAA;AACpB,IAAA,IAAI,CAAI,GAAA,IAAA;AAAK,MAAO,IAAA,GAAA,CAAA,CAAA;AACpB,IAAA,IAAI,CAAI,GAAA,IAAA;AAAK,MAAO,IAAA,GAAA,CAAA,CAAA;AAAA,GACxB;AAEA,EAAA,MAAA,CAAO,IAAO,GAAA,IAAA,CAAA;AACd,EAAA,MAAA,CAAO,IAAO,GAAA,IAAA,CAAA;AACd,EAAA,MAAA,CAAO,IAAO,GAAA,IAAA,CAAA;AACd,EAAA,MAAA,CAAO,IAAO,GAAA,IAAA,CAAA;AAEd,EAAO,OAAA,MAAA,CAAA;AACX;;;;"}

View File

@@ -0,0 +1,39 @@
"use strict";
function getGeometryBounds(geometry, attributeId, bounds) {
const attribute = geometry.getAttribute(attributeId);
if (!attribute) {
bounds.minX = 0;
bounds.minY = 0;
bounds.maxX = 0;
bounds.maxY = 0;
return bounds;
}
const data = attribute.buffer.data;
let minX = Infinity;
let minY = Infinity;
let maxX = -Infinity;
let maxY = -Infinity;
const byteSize = data.BYTES_PER_ELEMENT;
const offset = (attribute.offset || 0) / byteSize;
const stride = (attribute.stride || 2 * 4) / byteSize;
for (let i = offset; i < data.length; i += stride) {
const x = data[i];
const y = data[i + 1];
if (x > maxX)
maxX = x;
if (y > maxY)
maxY = y;
if (x < minX)
minX = x;
if (y < minY)
minY = y;
}
bounds.minX = minX;
bounds.minY = minY;
bounds.maxX = maxX;
bounds.maxY = maxY;
return bounds;
}
export { getGeometryBounds };
//# sourceMappingURL=getGeometryBounds.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"getGeometryBounds.mjs","sources":["../../../../../../src/rendering/renderers/shared/geometry/utils/getGeometryBounds.ts"],"sourcesContent":["import type { Bounds } from '../../../../../scene/container/bounds/Bounds';\nimport type { Geometry } from '../Geometry';\n\n/**\n * Gets the 2D bounds of a geometry, based on a specific attribute.\n * @param geometry - Geometry to to measure\n * @param attributeId - AttributeId that contains the x,y data\n * @param bounds - Bounds to store the result in\n * @returns the bounds\n */\nexport function getGeometryBounds(geometry: Geometry, attributeId: string, bounds: Bounds): Bounds\n{\n const attribute = geometry.getAttribute(attributeId);\n\n if (!attribute)\n {\n bounds.minX = 0;\n bounds.minY = 0;\n bounds.maxX = 0;\n bounds.maxY = 0;\n\n return bounds;\n }\n\n const data = attribute.buffer.data as Float32Array;\n\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n\n const byteSize = data.BYTES_PER_ELEMENT;\n\n // stride and offset MAY have not been calculated yet.. so go with assumed defaults\n const offset = (attribute.offset || 0) / byteSize;\n const stride = (attribute.stride || (2 * 4)) / byteSize;\n\n for (let i = offset; i < data.length; i += stride)\n {\n const x = data[i];\n const y = data[i + 1];\n\n if (x > maxX)maxX = x;\n if (y > maxY)maxY = y;\n if (x < minX)minX = x;\n if (y < minY)minY = y;\n }\n\n bounds.minX = minX;\n bounds.minY = minY;\n bounds.maxX = maxX;\n bounds.maxY = maxY;\n\n return bounds;\n}\n"],"names":[],"mappings":";AAUgB,SAAA,iBAAA,CAAkB,QAAoB,EAAA,WAAA,EAAqB,MAC3E,EAAA;AACI,EAAM,MAAA,SAAA,GAAY,QAAS,CAAA,YAAA,CAAa,WAAW,CAAA,CAAA;AAEnD,EAAA,IAAI,CAAC,SACL,EAAA;AACI,IAAA,MAAA,CAAO,IAAO,GAAA,CAAA,CAAA;AACd,IAAA,MAAA,CAAO,IAAO,GAAA,CAAA,CAAA;AACd,IAAA,MAAA,CAAO,IAAO,GAAA,CAAA,CAAA;AACd,IAAA,MAAA,CAAO,IAAO,GAAA,CAAA,CAAA;AAEd,IAAO,OAAA,MAAA,CAAA;AAAA,GACX;AAEA,EAAM,MAAA,IAAA,GAAO,UAAU,MAAO,CAAA,IAAA,CAAA;AAE9B,EAAA,IAAI,IAAO,GAAA,QAAA,CAAA;AACX,EAAA,IAAI,IAAO,GAAA,QAAA,CAAA;AACX,EAAA,IAAI,IAAO,GAAA,CAAA,QAAA,CAAA;AACX,EAAA,IAAI,IAAO,GAAA,CAAA,QAAA,CAAA;AAEX,EAAA,MAAM,WAAW,IAAK,CAAA,iBAAA,CAAA;AAGtB,EAAM,MAAA,MAAA,GAAA,CAAU,SAAU,CAAA,MAAA,IAAU,CAAK,IAAA,QAAA,CAAA;AACzC,EAAA,MAAM,MAAU,GAAA,CAAA,SAAA,CAAU,MAAW,IAAA,CAAA,GAAI,CAAM,IAAA,QAAA,CAAA;AAE/C,EAAA,KAAA,IAAS,IAAI,MAAQ,EAAA,CAAA,GAAI,IAAK,CAAA,MAAA,EAAQ,KAAK,MAC3C,EAAA;AACI,IAAM,MAAA,CAAA,GAAI,KAAK,CAAC,CAAA,CAAA;AAChB,IAAM,MAAA,CAAA,GAAI,IAAK,CAAA,CAAA,GAAI,CAAC,CAAA,CAAA;AAEpB,IAAA,IAAI,CAAI,GAAA,IAAA;AAAK,MAAO,IAAA,GAAA,CAAA,CAAA;AACpB,IAAA,IAAI,CAAI,GAAA,IAAA;AAAK,MAAO,IAAA,GAAA,CAAA,CAAA;AACpB,IAAA,IAAI,CAAI,GAAA,IAAA;AAAK,MAAO,IAAA,GAAA,CAAA,CAAA;AACpB,IAAA,IAAI,CAAI,GAAA,IAAA;AAAK,MAAO,IAAA,GAAA,CAAA,CAAA;AAAA,GACxB;AAEA,EAAA,MAAA,CAAO,IAAO,GAAA,IAAA,CAAA;AACd,EAAA,MAAA,CAAO,IAAO,GAAA,IAAA,CAAA;AACd,EAAA,MAAA,CAAO,IAAO,GAAA,IAAA,CAAA;AACd,EAAA,MAAA,CAAO,IAAO,GAAA,IAAA,CAAA;AAEd,EAAO,OAAA,MAAA,CAAA;AACX;;;;"}

View File

@@ -0,0 +1,11 @@
import type { Matrix } from '../../../../../maths/matrix/Matrix';
/**
* Transforms the vertices in an array with the given matrix.
* @param vertices - the vertices to transform
* @param m - the matrix to apply to the vertices
* @param offset - the offset of the vertices (defaults to 0)
* @param stride - the stride of the vertices (defaults to 2)
* @param size - the size of the vertices (defaults to vertices.length / stride - offset)
* @memberof rendering
*/
export declare function transformVertices(vertices: number[], m: Matrix, offset?: number, stride?: number, size?: number): void;

View File

@@ -0,0 +1,25 @@
'use strict';
"use strict";
function transformVertices(vertices, m, offset, stride, size) {
const a = m.a;
const b = m.b;
const c = m.c;
const d = m.d;
const tx = m.tx;
const ty = m.ty;
offset = offset || 0;
stride = stride || 2;
size = size || vertices.length / stride - offset;
let index = offset * stride;
for (let i = 0; i < size; i++) {
const x = vertices[index];
const y = vertices[index + 1];
vertices[index] = a * x + c * y + tx;
vertices[index + 1] = b * x + d * y + ty;
index += stride;
}
}
exports.transformVertices = transformVertices;
//# sourceMappingURL=transformVertices.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"transformVertices.js","sources":["../../../../../../src/rendering/renderers/shared/geometry/utils/transformVertices.ts"],"sourcesContent":["import type { Matrix } from '../../../../../maths/matrix/Matrix';\n\n/**\n * Transforms the vertices in an array with the given matrix.\n * @param vertices - the vertices to transform\n * @param m - the matrix to apply to the vertices\n * @param offset - the offset of the vertices (defaults to 0)\n * @param stride - the stride of the vertices (defaults to 2)\n * @param size - the size of the vertices (defaults to vertices.length / stride - offset)\n * @memberof rendering\n */\nexport function transformVertices(vertices: number[], m: Matrix, offset?: number, stride?: number, size?: number)\n{\n const a = m.a;\n const b = m.b;\n const c = m.c;\n const d = m.d;\n const tx = m.tx;\n const ty = m.ty;\n\n offset = offset || 0;\n stride = stride || 2;\n size = size || (vertices.length / stride) - offset;\n\n let index = offset * stride;\n\n for (let i = 0; i < size; i++)\n {\n const x = vertices[index];\n const y = vertices[index + 1];\n\n vertices[index] = (a * x) + (c * y) + tx;\n vertices[index + 1] = (b * x) + (d * y) + ty;\n\n index += stride;\n }\n}\n"],"names":[],"mappings":";;;AAWO,SAAS,iBAAkB,CAAA,QAAA,EAAoB,CAAW,EAAA,MAAA,EAAiB,QAAiB,IACnG,EAAA;AACI,EAAA,MAAM,IAAI,CAAE,CAAA,CAAA,CAAA;AACZ,EAAA,MAAM,IAAI,CAAE,CAAA,CAAA,CAAA;AACZ,EAAA,MAAM,IAAI,CAAE,CAAA,CAAA,CAAA;AACZ,EAAA,MAAM,IAAI,CAAE,CAAA,CAAA,CAAA;AACZ,EAAA,MAAM,KAAK,CAAE,CAAA,EAAA,CAAA;AACb,EAAA,MAAM,KAAK,CAAE,CAAA,EAAA,CAAA;AAEb,EAAA,MAAA,GAAS,MAAU,IAAA,CAAA,CAAA;AACnB,EAAA,MAAA,GAAS,MAAU,IAAA,CAAA,CAAA;AACnB,EAAO,IAAA,GAAA,IAAA,IAAS,QAAS,CAAA,MAAA,GAAS,MAAU,GAAA,MAAA,CAAA;AAE5C,EAAA,IAAI,QAAQ,MAAS,GAAA,MAAA,CAAA;AAErB,EAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,IAAA,EAAM,CAC1B,EAAA,EAAA;AACI,IAAM,MAAA,CAAA,GAAI,SAAS,KAAK,CAAA,CAAA;AACxB,IAAM,MAAA,CAAA,GAAI,QAAS,CAAA,KAAA,GAAQ,CAAC,CAAA,CAAA;AAE5B,IAAA,QAAA,CAAS,KAAK,CAAA,GAAK,CAAI,GAAA,CAAA,GAAM,IAAI,CAAK,GAAA,EAAA,CAAA;AACtC,IAAA,QAAA,CAAS,QAAQ,CAAC,CAAA,GAAK,CAAI,GAAA,CAAA,GAAM,IAAI,CAAK,GAAA,EAAA,CAAA;AAE1C,IAAS,KAAA,IAAA,MAAA,CAAA;AAAA,GACb;AACJ;;;;"}

View File

@@ -0,0 +1,23 @@
"use strict";
function transformVertices(vertices, m, offset, stride, size) {
const a = m.a;
const b = m.b;
const c = m.c;
const d = m.d;
const tx = m.tx;
const ty = m.ty;
offset = offset || 0;
stride = stride || 2;
size = size || vertices.length / stride - offset;
let index = offset * stride;
for (let i = 0; i < size; i++) {
const x = vertices[index];
const y = vertices[index + 1];
vertices[index] = a * x + c * y + tx;
vertices[index + 1] = b * x + d * y + ty;
index += stride;
}
}
export { transformVertices };
//# sourceMappingURL=transformVertices.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"transformVertices.mjs","sources":["../../../../../../src/rendering/renderers/shared/geometry/utils/transformVertices.ts"],"sourcesContent":["import type { Matrix } from '../../../../../maths/matrix/Matrix';\n\n/**\n * Transforms the vertices in an array with the given matrix.\n * @param vertices - the vertices to transform\n * @param m - the matrix to apply to the vertices\n * @param offset - the offset of the vertices (defaults to 0)\n * @param stride - the stride of the vertices (defaults to 2)\n * @param size - the size of the vertices (defaults to vertices.length / stride - offset)\n * @memberof rendering\n */\nexport function transformVertices(vertices: number[], m: Matrix, offset?: number, stride?: number, size?: number)\n{\n const a = m.a;\n const b = m.b;\n const c = m.c;\n const d = m.d;\n const tx = m.tx;\n const ty = m.ty;\n\n offset = offset || 0;\n stride = stride || 2;\n size = size || (vertices.length / stride) - offset;\n\n let index = offset * stride;\n\n for (let i = 0; i < size; i++)\n {\n const x = vertices[index];\n const y = vertices[index + 1];\n\n vertices[index] = (a * x) + (c * y) + tx;\n vertices[index + 1] = (b * x) + (d * y) + ty;\n\n index += stride;\n }\n}\n"],"names":[],"mappings":";AAWO,SAAS,iBAAkB,CAAA,QAAA,EAAoB,CAAW,EAAA,MAAA,EAAiB,QAAiB,IACnG,EAAA;AACI,EAAA,MAAM,IAAI,CAAE,CAAA,CAAA,CAAA;AACZ,EAAA,MAAM,IAAI,CAAE,CAAA,CAAA,CAAA;AACZ,EAAA,MAAM,IAAI,CAAE,CAAA,CAAA,CAAA;AACZ,EAAA,MAAM,IAAI,CAAE,CAAA,CAAA,CAAA;AACZ,EAAA,MAAM,KAAK,CAAE,CAAA,EAAA,CAAA;AACb,EAAA,MAAM,KAAK,CAAE,CAAA,EAAA,CAAA;AAEb,EAAA,MAAA,GAAS,MAAU,IAAA,CAAA,CAAA;AACnB,EAAA,MAAA,GAAS,MAAU,IAAA,CAAA,CAAA;AACnB,EAAO,IAAA,GAAA,IAAA,IAAS,QAAS,CAAA,MAAA,GAAS,MAAU,GAAA,MAAA,CAAA;AAE5C,EAAA,IAAI,QAAQ,MAAS,GAAA,MAAA,CAAA;AAErB,EAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,IAAA,EAAM,CAC1B,EAAA,EAAA;AACI,IAAM,MAAA,CAAA,GAAI,SAAS,KAAK,CAAA,CAAA;AACxB,IAAM,MAAA,CAAA,GAAI,QAAS,CAAA,KAAA,GAAQ,CAAC,CAAA,CAAA;AAE5B,IAAA,QAAA,CAAS,KAAK,CAAA,GAAK,CAAI,GAAA,CAAA,GAAM,IAAI,CAAK,GAAA,EAAA,CAAA;AACtC,IAAA,QAAA,CAAS,QAAQ,CAAC,CAAA,GAAK,CAAI,GAAA,CAAA,GAAM,IAAI,CAAK,GAAA,EAAA,CAAA;AAE1C,IAAS,KAAA,IAAA,MAAA,CAAA;AAAA,GACb;AACJ;;;;"}

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":""}

Some files were not shown because too many files have changed in this diff Show More