(framebuffer, x, y)
| 3833 | } |
| 3834 | |
| 3835 | async readFramebufferPixel(framebuffer, x, y) { |
| 3836 | this.flushDraw(); |
| 3837 | // await this.finishDraw(); |
| 3838 | // Ensure all pending GPU work is complete before reading pixels |
| 3839 | // await this.queue.onSubmittedWorkDone(); |
| 3840 | |
| 3841 | const bytesPerPixel = 4; |
| 3842 | const alignedBytesPerRow = this._alignBytesPerRow(bytesPerPixel); |
| 3843 | const bufferSize = alignedBytesPerRow; |
| 3844 | |
| 3845 | const stagingBuffer = this._ensurePixelReadBuffer(bufferSize); |
| 3846 | |
| 3847 | const commandEncoder = this.device.createCommandEncoder(); |
| 3848 | commandEncoder.copyTextureToBuffer( |
| 3849 | { |
| 3850 | texture: framebuffer.colorTexture, |
| 3851 | origin: { x, y, z: 0 } |
| 3852 | }, |
| 3853 | { buffer: stagingBuffer, bytesPerRow: alignedBytesPerRow }, |
| 3854 | { width: 1, height: 1, depthOrArrayLayers: 1 } |
| 3855 | ); |
| 3856 | |
| 3857 | this.device.queue.submit([commandEncoder.finish()]); |
| 3858 | |
| 3859 | await stagingBuffer.mapAsync(GPUMapMode.READ, 0, bufferSize); |
| 3860 | const mappedRange = stagingBuffer.getMappedRange(0, bufferSize); |
| 3861 | const pixelData = new Uint8Array(mappedRange); |
| 3862 | const result = [pixelData[0], pixelData[1], pixelData[2], pixelData[3]]; |
| 3863 | |
| 3864 | |
| 3865 | this._ensurePixelsAreRGBA(framebuffer, result); |
| 3866 | |
| 3867 | stagingBuffer.unmap(); |
| 3868 | return result; |
| 3869 | } |
| 3870 | |
| 3871 | async readFramebufferRegion(framebuffer, x, y, w, h) { |
| 3872 | this.flushDraw(); |
nothing calls this directly
no test coverage detected