(device: GPUDevice, options?: AxisRendererOptions)
| 190 | }; |
| 191 | |
| 192 | export function createAxisRenderer(device: GPUDevice, options?: AxisRendererOptions): AxisRenderer { |
| 193 | let disposed = false; |
| 194 | const targetFormat = options?.targetFormat ?? DEFAULT_TARGET_FORMAT; |
| 195 | |
| 196 | const bindGroupLayout = device.createBindGroupLayout({ |
| 197 | entries: [ |
| 198 | { binding: 0, visibility: GPUShaderStage.VERTEX, buffer: { type: 'uniform' } }, |
| 199 | { binding: 1, visibility: GPUShaderStage.FRAGMENT, buffer: { type: 'uniform' } }, |
| 200 | ], |
| 201 | }); |
| 202 | |
| 203 | const vsUniformBuffer = createUniformBuffer(device, 64, { label: 'axisRenderer/vsUniforms' }); |
| 204 | const fsUniformBufferLine = createUniformBuffer(device, 16, { label: 'axisRenderer/fsUniformsLine' }); |
| 205 | const fsUniformBufferTick = createUniformBuffer(device, 16, { label: 'axisRenderer/fsUniformsTick' }); |
| 206 | |
| 207 | const bindGroupLine = device.createBindGroup({ |
| 208 | layout: bindGroupLayout, |
| 209 | entries: [ |
| 210 | { binding: 0, resource: { buffer: vsUniformBuffer } }, |
| 211 | { binding: 1, resource: { buffer: fsUniformBufferLine } }, |
| 212 | ], |
| 213 | }); |
| 214 | |
| 215 | const bindGroupTick = device.createBindGroup({ |
| 216 | layout: bindGroupLayout, |
| 217 | entries: [ |
| 218 | { binding: 0, resource: { buffer: vsUniformBuffer } }, |
| 219 | { binding: 1, resource: { buffer: fsUniformBufferTick } }, |
| 220 | ], |
| 221 | }); |
| 222 | |
| 223 | const pipeline = createRenderPipeline(device, { |
| 224 | label: 'axisRenderer/pipeline', |
| 225 | bindGroupLayouts: [bindGroupLayout], |
| 226 | vertex: { |
| 227 | code: gridWgsl, |
| 228 | label: 'grid.wgsl', |
| 229 | buffers: [ |
| 230 | { |
| 231 | arrayStride: 8, |
| 232 | stepMode: 'vertex', |
| 233 | attributes: [{ shaderLocation: 0, format: 'float32x2', offset: 0 }], |
| 234 | }, |
| 235 | ], |
| 236 | }, |
| 237 | fragment: { |
| 238 | code: gridWgsl, |
| 239 | label: 'grid.wgsl', |
| 240 | formats: targetFormat, |
| 241 | blend: { |
| 242 | color: { operation: 'add', srcFactor: 'src-alpha', dstFactor: 'one-minus-src-alpha' }, |
| 243 | alpha: { operation: 'add', srcFactor: 'one', dstFactor: 'one-minus-src-alpha' }, |
| 244 | }, |
| 245 | }, |
| 246 | primitive: { topology: 'line-list', cullMode: 'none' }, |
| 247 | multisample: { count: 1 }, |
| 248 | }); |
| 249 |
no test coverage detected