MCPcopy
hub / github.com/processing/p5.js / _ensurePixelReadBuffer

Method _ensurePixelReadBuffer

src/webgpu/p5.RendererWebGPU.js:3215–3234  ·  view source on GitHub ↗
(requiredSize)

Source from the content-addressed store, hash-verified

3213 //////////////////////////////////////////////
3214
3215 _ensurePixelReadBuffer(requiredSize) {
3216 // Create or resize staging buffer if needed
3217 if (!this.pixelReadBuffer || this.pixelReadBufferSize < requiredSize) {
3218 // Clean up old buffer
3219 if (this.pixelReadBuffer) {
3220 this.flushDraw();
3221 this.pixelReadBuffer.destroy();
3222 }
3223
3224 // Create new buffer with padding to avoid frequent recreations
3225 // Scale by 2 to ensure integer size and reasonable headroom
3226 const bufferSize = Math.max(requiredSize, this.pixelReadBufferSize * 2);
3227 this.pixelReadBuffer = this.device.createBuffer({
3228 size: bufferSize,
3229 usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ,
3230 });
3231 this.pixelReadBufferSize = bufferSize;
3232 }
3233 return this.pixelReadBuffer;
3234 }
3235
3236 _alignBytesPerRow(bytesPerRow) {
3237 // WebGPU requires bytesPerRow to be a multiple of 256 bytes for texture-to-buffer copies

Callers 2

readFramebufferPixelMethod · 0.95
readFramebufferRegionMethod · 0.95

Calls 1

flushDrawMethod · 0.95

Tested by

no test coverage detected