wgsl-renderer 0.1.8 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +32 -7
- package/dist/esm/index.d.ts +27 -3
- package/dist/esm/index.js +32 -7
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -341,6 +341,12 @@ var TextureManager = class {
|
|
|
341
341
|
});
|
|
342
342
|
this.textures.clear();
|
|
343
343
|
}
|
|
344
|
+
/**
|
|
345
|
+
* Store a texture in the manager
|
|
346
|
+
*/
|
|
347
|
+
setTexture(name, texture) {
|
|
348
|
+
this.textures.set(name, texture);
|
|
349
|
+
}
|
|
344
350
|
destroy() {
|
|
345
351
|
this.textures.forEach((texture) => texture.destroy());
|
|
346
352
|
this.textures.clear();
|
|
@@ -359,8 +365,10 @@ const PASS_TEXTURE_REF_SYMBOL = Symbol("PassTextureRef");
|
|
|
359
365
|
var PassTextureRef = class PassTextureRef {
|
|
360
366
|
[PASS_TEXTURE_REF_SYMBOL] = true;
|
|
361
367
|
passName;
|
|
362
|
-
|
|
368
|
+
options;
|
|
369
|
+
constructor(passName, options) {
|
|
363
370
|
this.passName = passName;
|
|
371
|
+
this.options = options;
|
|
364
372
|
}
|
|
365
373
|
static is(obj) {
|
|
366
374
|
return obj && typeof obj === "object" && PASS_TEXTURE_REF_SYMBOL in obj;
|
|
@@ -369,8 +377,8 @@ var PassTextureRef = class PassTextureRef {
|
|
|
369
377
|
if (this.is(resource)) return resource;
|
|
370
378
|
return null;
|
|
371
379
|
}
|
|
372
|
-
static create(passName) {
|
|
373
|
-
return new PassTextureRef(passName);
|
|
380
|
+
static create(passName, options) {
|
|
381
|
+
return new PassTextureRef(passName, options);
|
|
374
382
|
}
|
|
375
383
|
};
|
|
376
384
|
function isPassTextureRef(obj) {
|
|
@@ -432,10 +440,13 @@ var WGSLRenderer = class {
|
|
|
432
440
|
/**
|
|
433
441
|
* Get texture reference by pass name
|
|
434
442
|
* Returns a PassTextureRef that will resolve to the actual texture at render time
|
|
443
|
+
*
|
|
444
|
+
* @param passName Name of the pass to reference
|
|
445
|
+
* @param options Optional texture creation options for when the texture needs to be created
|
|
435
446
|
*/
|
|
436
|
-
getPassTexture(passName) {
|
|
447
|
+
getPassTexture(passName, options) {
|
|
437
448
|
if (!this.passes.find((pass) => pass.name === passName)) throw new Error(`Cannot find pass named '${passName}'. Available passes: [${this.passes.map((p) => p.name).join(", ")}]`);
|
|
438
|
-
return PassTextureRef.create(passName);
|
|
449
|
+
return PassTextureRef.create(passName, options);
|
|
439
450
|
}
|
|
440
451
|
/**
|
|
441
452
|
* Resolve a PassTextureRef to actual GPUTextureView with validation
|
|
@@ -446,8 +457,22 @@ var WGSLRenderer = class {
|
|
|
446
457
|
if (targetPass.view) return targetPass.view;
|
|
447
458
|
const textureName = `pass_${this.passes.indexOf(targetPass)}_output`;
|
|
448
459
|
let texture = this.textureManager.getTexture(textureName);
|
|
449
|
-
if (!texture)
|
|
450
|
-
|
|
460
|
+
if (!texture) {
|
|
461
|
+
const format = ref.options?.format || this.format;
|
|
462
|
+
const usage = ref.options?.usage || GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.RENDER_ATTACHMENT;
|
|
463
|
+
const size = this.textureManager.getPixelSize();
|
|
464
|
+
texture = this.device.createTexture({
|
|
465
|
+
size: [size.width, size.height],
|
|
466
|
+
format,
|
|
467
|
+
usage,
|
|
468
|
+
sampleCount: ref.options?.sampleCount || 1
|
|
469
|
+
});
|
|
470
|
+
this.textureManager.setTexture(textureName, texture);
|
|
471
|
+
}
|
|
472
|
+
return texture.createView({
|
|
473
|
+
baseMipLevel: 0,
|
|
474
|
+
mipLevelCount: ref.options?.mipmaps ? texture.mipLevelCount : 1
|
|
475
|
+
});
|
|
451
476
|
}
|
|
452
477
|
/**
|
|
453
478
|
* Get pass by name
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -3,10 +3,26 @@ declare const PASS_TEXTURE_REF_SYMBOL: unique symbol;
|
|
|
3
3
|
declare class PassTextureRef {
|
|
4
4
|
readonly [PASS_TEXTURE_REF_SYMBOL] = true;
|
|
5
5
|
readonly passName: string;
|
|
6
|
-
|
|
6
|
+
readonly options?: {
|
|
7
|
+
format?: GPUTextureFormat;
|
|
8
|
+
mipmaps?: boolean;
|
|
9
|
+
sampleCount?: number;
|
|
10
|
+
usage?: GPUTextureUsageFlags;
|
|
11
|
+
};
|
|
12
|
+
constructor(passName: string, options?: {
|
|
13
|
+
format?: GPUTextureFormat;
|
|
14
|
+
mipmaps?: boolean;
|
|
15
|
+
sampleCount?: number;
|
|
16
|
+
usage?: GPUTextureUsageFlags;
|
|
17
|
+
});
|
|
7
18
|
static is(obj: any): obj is PassTextureRef;
|
|
8
19
|
static fromGPUBindingResource(resource: GPUBindingResource): PassTextureRef | null;
|
|
9
|
-
static create(passName: string
|
|
20
|
+
static create(passName: string, options?: {
|
|
21
|
+
format?: GPUTextureFormat;
|
|
22
|
+
mipmaps?: boolean;
|
|
23
|
+
sampleCount?: number;
|
|
24
|
+
usage?: GPUTextureUsageFlags;
|
|
25
|
+
}): PassTextureRef;
|
|
10
26
|
}
|
|
11
27
|
//#endregion
|
|
12
28
|
//#region src/RenderPass.d.ts
|
|
@@ -140,8 +156,16 @@ declare class WGSLRenderer {
|
|
|
140
156
|
/**
|
|
141
157
|
* Get texture reference by pass name
|
|
142
158
|
* Returns a PassTextureRef that will resolve to the actual texture at render time
|
|
159
|
+
*
|
|
160
|
+
* @param passName Name of the pass to reference
|
|
161
|
+
* @param options Optional texture creation options for when the texture needs to be created
|
|
143
162
|
*/
|
|
144
|
-
getPassTexture(passName: string
|
|
163
|
+
getPassTexture(passName: string, options?: {
|
|
164
|
+
format?: GPUTextureFormat;
|
|
165
|
+
mipmaps?: boolean;
|
|
166
|
+
sampleCount?: number;
|
|
167
|
+
usage?: GPUTextureUsageFlags;
|
|
168
|
+
}): PassTextureRef;
|
|
145
169
|
/**
|
|
146
170
|
* Resolve a PassTextureRef to actual GPUTextureView with validation
|
|
147
171
|
*/
|
package/dist/esm/index.js
CHANGED
|
@@ -340,6 +340,12 @@ var TextureManager = class {
|
|
|
340
340
|
});
|
|
341
341
|
this.textures.clear();
|
|
342
342
|
}
|
|
343
|
+
/**
|
|
344
|
+
* Store a texture in the manager
|
|
345
|
+
*/
|
|
346
|
+
setTexture(name, texture) {
|
|
347
|
+
this.textures.set(name, texture);
|
|
348
|
+
}
|
|
343
349
|
destroy() {
|
|
344
350
|
this.textures.forEach((texture) => texture.destroy());
|
|
345
351
|
this.textures.clear();
|
|
@@ -358,8 +364,10 @@ const PASS_TEXTURE_REF_SYMBOL = Symbol("PassTextureRef");
|
|
|
358
364
|
var PassTextureRef = class PassTextureRef {
|
|
359
365
|
[PASS_TEXTURE_REF_SYMBOL] = true;
|
|
360
366
|
passName;
|
|
361
|
-
|
|
367
|
+
options;
|
|
368
|
+
constructor(passName, options) {
|
|
362
369
|
this.passName = passName;
|
|
370
|
+
this.options = options;
|
|
363
371
|
}
|
|
364
372
|
static is(obj) {
|
|
365
373
|
return obj && typeof obj === "object" && PASS_TEXTURE_REF_SYMBOL in obj;
|
|
@@ -368,8 +376,8 @@ var PassTextureRef = class PassTextureRef {
|
|
|
368
376
|
if (this.is(resource)) return resource;
|
|
369
377
|
return null;
|
|
370
378
|
}
|
|
371
|
-
static create(passName) {
|
|
372
|
-
return new PassTextureRef(passName);
|
|
379
|
+
static create(passName, options) {
|
|
380
|
+
return new PassTextureRef(passName, options);
|
|
373
381
|
}
|
|
374
382
|
};
|
|
375
383
|
function isPassTextureRef(obj) {
|
|
@@ -431,10 +439,13 @@ var WGSLRenderer = class {
|
|
|
431
439
|
/**
|
|
432
440
|
* Get texture reference by pass name
|
|
433
441
|
* Returns a PassTextureRef that will resolve to the actual texture at render time
|
|
442
|
+
*
|
|
443
|
+
* @param passName Name of the pass to reference
|
|
444
|
+
* @param options Optional texture creation options for when the texture needs to be created
|
|
434
445
|
*/
|
|
435
|
-
getPassTexture(passName) {
|
|
446
|
+
getPassTexture(passName, options) {
|
|
436
447
|
if (!this.passes.find((pass) => pass.name === passName)) throw new Error(`Cannot find pass named '${passName}'. Available passes: [${this.passes.map((p) => p.name).join(", ")}]`);
|
|
437
|
-
return PassTextureRef.create(passName);
|
|
448
|
+
return PassTextureRef.create(passName, options);
|
|
438
449
|
}
|
|
439
450
|
/**
|
|
440
451
|
* Resolve a PassTextureRef to actual GPUTextureView with validation
|
|
@@ -445,8 +456,22 @@ var WGSLRenderer = class {
|
|
|
445
456
|
if (targetPass.view) return targetPass.view;
|
|
446
457
|
const textureName = `pass_${this.passes.indexOf(targetPass)}_output`;
|
|
447
458
|
let texture = this.textureManager.getTexture(textureName);
|
|
448
|
-
if (!texture)
|
|
449
|
-
|
|
459
|
+
if (!texture) {
|
|
460
|
+
const format = ref.options?.format || this.format;
|
|
461
|
+
const usage = ref.options?.usage || GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.RENDER_ATTACHMENT;
|
|
462
|
+
const size = this.textureManager.getPixelSize();
|
|
463
|
+
texture = this.device.createTexture({
|
|
464
|
+
size: [size.width, size.height],
|
|
465
|
+
format,
|
|
466
|
+
usage,
|
|
467
|
+
sampleCount: ref.options?.sampleCount || 1
|
|
468
|
+
});
|
|
469
|
+
this.textureManager.setTexture(textureName, texture);
|
|
470
|
+
}
|
|
471
|
+
return texture.createView({
|
|
472
|
+
baseMipLevel: 0,
|
|
473
|
+
mipLevelCount: ref.options?.mipmaps ? texture.mipLevelCount : 1
|
|
474
|
+
});
|
|
450
475
|
}
|
|
451
476
|
/**
|
|
452
477
|
* Get pass by name
|