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

Method _drawBuffers

src/webgpu/p5.RendererWebGPU.js:1854–1899  ·  view source on GitHub ↗
(geometry, { mode = constants.TRIANGLES, count = 1 })

Source from the content-addressed store, hash-verified

1852 //////////////////////////////////////////////
1853
1854 _drawBuffers(geometry, { mode = constants.TRIANGLES, count = 1 }) {
1855 const buffers = this.geometryBufferCache.getCached(geometry);
1856 if (!buffers) return;
1857
1858 // If PENDING and no custom framebuffer, regular draw means PROMOTE
1859 if (this._frameState === FRAME_STATE.PENDING && !this.activeFramebuffer()) {
1860 this._promoteToFramebufferWithoutCopy();
1861 }
1862
1863 this._beginActiveRenderPass();
1864 const passEncoder = this.activeRenderPass;
1865
1866 const currentShader = this._curShader;
1867 this.setupShaderBindGroups(currentShader, passEncoder, { mode, buffers });
1868 // Bind vertex buffers
1869 for (const buffer of currentShader._vertexBuffers || this._getVertexBuffers(currentShader)) {
1870 const location = currentShader.attributes[buffer.attr].location;
1871 const gpuBuffer = buffers[buffer.dst];
1872 passEncoder.setVertexBuffer(location, gpuBuffer, 0);
1873 }
1874
1875 if (currentShader.shaderType === "fill") {
1876 // Bind index buffer and issue draw
1877 if (buffers.indexBuffer) {
1878 const indexFormat = buffers.indexFormat || "uint16";
1879 passEncoder.setIndexBuffer(buffers.indexBuffer, indexFormat);
1880 passEncoder.drawIndexed(geometry.faces.length * 3, count, 0, 0, 0);
1881 } else {
1882 passEncoder.draw(geometry.vertices.length, count, 0, 0);
1883 }
1884 } else if (currentShader.shaderType === "text") {
1885 if (!buffers.indexBuffer) {
1886 throw new Error("Text geometry must have an index buffer");
1887 }
1888 const indexFormat = buffers.indexFormat || "uint16";
1889 passEncoder.setIndexBuffer(buffers.indexBuffer, indexFormat);
1890 passEncoder.drawIndexed(geometry.faces.length * 3, count, 0, 0, 0);
1891 }
1892
1893 if (buffers.lineVerticesBuffer && currentShader.shaderType === "stroke") {
1894 passEncoder.draw(geometry.lineVertices.length / 3, count, 0, 0);
1895 }
1896
1897 // Mark that we have pending draws that need submission
1898 this._hasPendingDraws = true;
1899 }
1900
1901 setupShaderBindGroups(currentShader, passEncoder, shaderOptionsParams) {
1902 const shaderOptions = this._shaderOptions(shaderOptionsParams);

Callers

nothing calls this directly

Calls 7

setupShaderBindGroupsMethod · 0.95
_getVertexBuffersMethod · 0.95
getCachedMethod · 0.80
activeFramebufferMethod · 0.80
drawMethod · 0.45

Tested by

no test coverage detected