Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting a static worker pool in the ktx2container instead of passing it in the constructor #14991

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions packages/dev/core/src/Misc/khronosTextureContainer2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,13 @@ export class KhronosTextureContainer2 {
wasmZSTDDecoder: null,
};

/**
* If provided, this worker pool will be used instead of creating a new one.
* This is useful when loading the WASM and the js modules on your own and
* you want to use the ktxTextureLoader and not construct this class directly.
*/
public static WorkerPool?: AutoReleaseWorkerPool;

/**
* Default number of workers used to handle data decoding
*/
Expand Down Expand Up @@ -306,8 +313,9 @@ export class KhronosTextureContainer2 {
*/
public constructor(engine: ThinEngine, numWorkersOrOptions: number | IKhronosTextureContainer2Options = KhronosTextureContainer2.DefaultNumWorkers) {
this._engine = engine;
if (typeof numWorkersOrOptions === "object" && numWorkersOrOptions.workerPool) {
KhronosTextureContainer2._WorkerPoolPromise = Promise.resolve(numWorkersOrOptions.workerPool);
const workerPoolOption = (typeof numWorkersOrOptions === "object" && numWorkersOrOptions.workerPool) || KhronosTextureContainer2.WorkerPool;
if (workerPoolOption) {
KhronosTextureContainer2._WorkerPoolPromise = Promise.resolve(workerPoolOption);
} else {
// set the KTX2 decoder module
if (typeof numWorkersOrOptions === "object") {
Expand Down