Skip to content

Commit c3368c7

Browse files
committed
fix: getTexture
1 parent 9637b05 commit c3368c7

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/DenoGpuWrapper.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import {
22
GpuWrapper,
33
GpuWrapperInfo,
4-
Layout,
5-
} from "../mod.ts"
4+
} from "./GpuWrapper.ts"
5+
6+
import { Layout } from "./types.ts"
67

78
import tgpu, { TgpuRoot } from "https://esm.sh/typegpu@0.3.2"
89

@@ -29,7 +30,7 @@ export class DenoGpuWrapper<T extends Layout> extends GpuWrapper<T> {
2930
override beforeDrawFinish(commandEncoder: GPUCommandEncoder) {
3031
copyToBuffer(
3132
commandEncoder,
32-
this.texture,
33+
this.getTexture(),
3334
this.outputBuffer,
3435
this.dimension,
3536
)
@@ -54,7 +55,7 @@ export async function initDeno<T extends Layout>
5455
root,
5556
{
5657
...info,
57-
texture,
58+
getTexture: () => texture,
5859
format: "rgba8unorm-srgb",
5960
},
6061
outputBuffer,

src/GpuWrapper.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from "./types.ts"
1111

1212
export interface GpuWrapperInfo<T extends Layout> {
13-
texture: GPUTexture,
13+
getTexture(): GPUTexture,
1414
format?: GPUTextureFormat,
1515
vertShader: string,
1616
fragShader: string,
@@ -19,7 +19,7 @@ export interface GpuWrapperInfo<T extends Layout> {
1919

2020
export class GpuWrapper<T extends Layout> {
2121
root
22-
texture
22+
getTexture
2323
format
2424
pipeline
2525
bindGroup
@@ -28,15 +28,15 @@ export class GpuWrapper<T extends Layout> {
2828
constructor(
2929
root: TgpuRoot,
3030
{
31-
texture,
31+
getTexture,
3232
format,
3333
vertShader,
3434
fragShader,
3535
layout,
3636
}: GpuWrapperInfo<T>,
3737
) {
3838
this.root = root
39-
this.texture = texture
39+
this.getTexture = getTexture
4040
this.format = format || navigator.gpu.getPreferredCanvasFormat()
4141

4242
const device = this.root.device
@@ -93,7 +93,7 @@ export class GpuWrapper<T extends Layout> {
9393
}
9494
beforeDrawFinish(commandEncoder: GPUCommandEncoder) {}
9595
draw(...params: Parameters<GPURenderPassEncoder["draw"]>) {
96-
const textureView = this.texture.createView()
96+
const textureView = this.getTexture().createView()
9797
const renderPassDescriptor: GPURenderPassDescriptor = {
9898
colorAttachments: [
9999
{
@@ -133,7 +133,7 @@ export async function initCanvas<T extends Layout>
133133
root,
134134
{
135135
...info,
136-
texture: ctx.getCurrentTexture(),
136+
getTexture: ctx.getCurrentTexture,
137137
},
138138
)
139139
}

0 commit comments

Comments
 (0)