()
| 42 | } |
| 43 | |
| 44 | async init() { |
| 45 | const shaderModule = await this.loadShader("hello_texture"); |
| 46 | |
| 47 | this.vertexBuffer = this.createBuffer({ |
| 48 | label: "Vertex Buffer", |
| 49 | data: this.vertices, |
| 50 | usage: GPUBufferUsage.VERTEX, |
| 51 | }); |
| 52 | |
| 53 | this.indexBuffer = this.createBuffer({ |
| 54 | label: "Index Buffer", |
| 55 | data: this.indices, |
| 56 | usage: GPUBufferUsage.INDEX, |
| 57 | }); |
| 58 | |
| 59 | this.texture = this.device.createTexture({ |
| 60 | label: "Tree Texture", |
| 61 | size: { |
| 62 | width: this.textureImage.width, |
| 63 | height: this.textureImage.height, |
| 64 | depthOrArrayLayers: 1, |
| 65 | }, |
| 66 | mipLevelCount: 1, |
| 67 | sampleCount: 1, |
| 68 | dimension: "2d", |
| 69 | format: "rgba8unorm-srgb", |
| 70 | usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST, |
| 71 | }); |
| 72 | |
| 73 | this.device.queue.writeTexture({ |
| 74 | texture: this.texture, |
| 75 | }, this.textureImage.image, { |
| 76 | offset: 0, |
| 77 | bytesPerRow: this.textureImage.width * 4, |
| 78 | rowsPerImage: this.textureImage.height, |
| 79 | }, { |
| 80 | width: this.textureImage.width, |
| 81 | height: this.textureImage.height, |
| 82 | depthOrArrayLayers: 1, |
| 83 | }); |
| 84 | |
| 85 | this.textureView = this.texture.createView(); |
| 86 | this.textureSampler = this.device.createSampler({ |
| 87 | label: "Tree Texture Sampler", |
| 88 | addressModeU: "clamp-to-edge", |
| 89 | addressModeV: "clamp-to-edge", |
| 90 | addressModeW: "clamp-to-edge", |
| 91 | magFilter: "linear", |
| 92 | minFilter: "nearest", |
| 93 | mipmapFilter: "nearest", |
| 94 | }); |
| 95 | |
| 96 | this.texBindGroupLayout = this.device.createBindGroupLayout({ |
| 97 | label: "Texture Bind Group Layout", |
| 98 | entries: [ |
| 99 | { |
| 100 | binding: 0, |
| 101 | visibility: GPUShaderStage.FRAGMENT, |
nothing calls this directly
no test coverage detected