Skip to content

Commit f2b1cf8

Browse files
committed
allow init deno without dimension
1 parent b9607e6 commit f2b1cf8

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

deno.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Lil as Lil_ } from "./src/Lil.ts"
66
import { initDeno } from "./src/DenoGpuWrapper.ts"
77

88
export abstract class Lil extends Lil_ {
9-
async init(width: number, height: number) {
9+
async init(width?: number, height?: number) {
1010
const wrapper = await initDeno<this["layout"]>({
1111
...this,
1212
width,

src/DenoGpuWrapper.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class DenoGpuWrapper<T extends Layout> extends GpuWrapper<T> {
1717
constructor(
1818
root: TgpuRoot,
1919
info: GpuWrapperInfo<T> & { width?: number, height?: number },
20-
outputBuffer: GPUBuffer,
20+
outputBuffer?: GPUBuffer,
2121
) {
2222
super(root, info)
2323
this.outputBuffer = outputBuffer
@@ -28,7 +28,7 @@ export class DenoGpuWrapper<T extends Layout> extends GpuWrapper<T> {
2828
}
2929

3030
override beforeDrawFinish(commandEncoder: GPUCommandEncoder) {
31-
if (!this.getTexture || !this.dimension) {
31+
if (!this.getTexture || !this.dimension || !this.outputBuffer) {
3232
throw new Error("No texture provided")
3333
}
3434
copyToBuffer(
@@ -39,7 +39,7 @@ export class DenoGpuWrapper<T extends Layout> extends GpuWrapper<T> {
3939
)
4040
}
4141
async getImage() {
42-
if (!this.dimension) {
42+
if (!this.dimension || !this.outputBuffer) {
4343
throw new Error("No texture provided")
4444
}
4545
return await createPng(
@@ -50,8 +50,16 @@ export class DenoGpuWrapper<T extends Layout> extends GpuWrapper<T> {
5050
}
5151

5252
export async function initDeno<T extends Layout>
53-
(info: Omit<GpuWrapperInfo<T>, "getTexture"> & { width: number, height: number }) {
53+
(info: Omit<GpuWrapperInfo<T>, "getTexture"> & { width?: number, height?: number }) {
5454
const root = await tgpu.init()
55+
56+
if (!info.width || !info.height) {
57+
return new DenoGpuWrapper(
58+
root,
59+
info,
60+
)
61+
}
62+
5563
const { texture, outputBuffer } = createCapture(
5664
root.device,
5765
info.width,

0 commit comments

Comments
 (0)