(device: GPUDevice, options?: CandlestickRendererOptions)
| 173 | }; |
| 174 | |
| 175 | export function createCandlestickRenderer(device: GPUDevice, options?: CandlestickRendererOptions): CandlestickRenderer { |
| 176 | let disposed = false; |
| 177 | const targetFormat = options?.targetFormat ?? DEFAULT_TARGET_FORMAT; |
| 178 | |
| 179 | const bindGroupLayout = device.createBindGroupLayout({ |
| 180 | entries: [{ binding: 0, visibility: GPUShaderStage.VERTEX, buffer: { type: 'uniform' } }], |
| 181 | }); |
| 182 | |
| 183 | // VSUniforms: mat4x4 (64 bytes) + wickWidthClip f32 (4 bytes) + pad (12 bytes) = 80 bytes |
| 184 | const vsUniformBuffer = createUniformBuffer(device, 80, { label: 'candlestickRenderer/vsUniforms' }); |
| 185 | writeUniformBuffer(device, vsUniformBuffer, createIdentityMat4Buffer()); // Default to identity |
| 186 | |
| 187 | const vsUniformScratchBuffer = new ArrayBuffer(80); |
| 188 | const vsUniformScratchF32 = new Float32Array(vsUniformScratchBuffer); |
| 189 | |
| 190 | const bindGroup = device.createBindGroup({ |
| 191 | layout: bindGroupLayout, |
| 192 | entries: [{ binding: 0, resource: { buffer: vsUniformBuffer } }], |
| 193 | }); |
| 194 | |
| 195 | const pipeline = createRenderPipeline(device, { |
| 196 | label: 'candlestickRenderer/pipeline', |
| 197 | bindGroupLayouts: [bindGroupLayout], |
| 198 | vertex: { |
| 199 | code: candlestickWgsl, |
| 200 | label: 'candlestick.wgsl', |
| 201 | buffers: [ |
| 202 | { |
| 203 | arrayStride: INSTANCE_STRIDE_BYTES, |
| 204 | stepMode: 'instance', |
| 205 | attributes: [ |
| 206 | { shaderLocation: 0, format: 'float32', offset: 0 }, |
| 207 | { shaderLocation: 1, format: 'float32', offset: 4 }, |
| 208 | { shaderLocation: 2, format: 'float32', offset: 8 }, |
| 209 | { shaderLocation: 3, format: 'float32', offset: 12 }, |
| 210 | { shaderLocation: 4, format: 'float32', offset: 16 }, |
| 211 | { shaderLocation: 5, format: 'float32', offset: 20 }, |
| 212 | { shaderLocation: 6, format: 'float32x4', offset: 24 }, |
| 213 | ], |
| 214 | }, |
| 215 | ], |
| 216 | }, |
| 217 | fragment: { |
| 218 | code: candlestickWgsl, |
| 219 | label: 'candlestick.wgsl', |
| 220 | formats: targetFormat, |
| 221 | blend: { |
| 222 | color: { operation: 'add', srcFactor: 'src-alpha', dstFactor: 'one-minus-src-alpha' }, |
| 223 | alpha: { operation: 'add', srcFactor: 'one', dstFactor: 'one-minus-src-alpha' }, |
| 224 | }, |
| 225 | }, |
| 226 | primitive: { topology: 'triangle-list', cullMode: 'none' }, |
| 227 | multisample: { count: 1 }, |
| 228 | }); |
| 229 | |
| 230 | let instanceBuffer: GPUBuffer | null = null; |
| 231 | let instanceCount = 0; |
| 232 | let cpuInstanceStagingBuffer = new ArrayBuffer(0); |
no test coverage detected