(x, y, gridArea, renderOptions)
| 315 | }; |
| 316 | |
| 317 | const prepare: CrosshairRenderer['prepare'] = (x, y, gridArea, renderOptions) => { |
| 318 | assertNotDisposed(); |
| 319 | |
| 320 | // Validate options up-front for deterministic behavior. |
| 321 | if (typeof renderOptions.showX !== 'boolean' || typeof renderOptions.showY !== 'boolean') { |
| 322 | throw new Error('CrosshairRenderer.prepare: showX/showY must be boolean.'); |
| 323 | } |
| 324 | if (typeof renderOptions.color !== 'string') { |
| 325 | throw new Error('CrosshairRenderer.prepare: color must be a string.'); |
| 326 | } |
| 327 | if (!Number.isFinite(renderOptions.lineWidth) || renderOptions.lineWidth < 0) { |
| 328 | throw new Error('CrosshairRenderer.prepare: lineWidth must be a finite non-negative number.'); |
| 329 | } |
| 330 | |
| 331 | const { vertices, scissor } = generateCrosshairVertices(x, y, gridArea, renderOptions); |
| 332 | if (vertices.byteLength === 0) { |
| 333 | vertexCount = 0; |
| 334 | } else { |
| 335 | stream.write(vertices); |
| 336 | vertexCount = stream.getVertexCount(); |
| 337 | } |
| 338 | |
| 339 | // Identity transform (vertices are already in clip-space). |
| 340 | writeUniformBuffer(device, vsUniformBuffer, createIdentityMat4Buffer()); |
| 341 | |
| 342 | // Color. |
| 343 | const rgba = parseCssColorToRgba01(renderOptions.color) ?? DEFAULT_CROSSHAIR_RGBA; |
| 344 | const colorBuffer = new ArrayBuffer(4 * 4); |
| 345 | new Float32Array(colorBuffer).set([rgba[0], rgba[1], rgba[2], rgba[3]]); |
| 346 | writeUniformBuffer(device, fsUniformBuffer, colorBuffer); |
| 347 | |
| 348 | lastCanvasWidth = gridArea.canvasWidth; |
| 349 | lastCanvasHeight = gridArea.canvasHeight; |
| 350 | lastScissor = scissor; |
| 351 | }; |
| 352 | |
| 353 | const render: CrosshairRenderer['render'] = (passEncoder) => { |
| 354 | assertNotDisposed(); |
nothing calls this directly
no test coverage detected