Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. GPURenderPassEncoder
  4. setVertexBuffer()

GPURenderPassEncoder: setVertexBuffer() method

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Secure context: This feature is available only insecure contexts (HTTPS), in some or allsupporting browsers.

Note: This feature is available inWeb Workers.

ThesetVertexBuffer() method of theGPURenderPassEncoder interface sets or unsets the currentGPUBuffer for the given slot that will provide vertex data for subsequent drawing commands.

Syntax

js
setVertexBuffer(slot, buffer, offset, size)

Parameters

slot

A number referencing the vertex buffer slot to set the vertex buffer for.

buffer

AGPUBuffer representing the buffer containing the vertex data to use for subsequent drawing commands, ornull, in which case any previously-set buffer in the given slot is unset.

offsetOptional

A number representing the offset, in bytes, intobuffer where the vertex data begins. If omitted,offset defaults to 0.

sizeOptional

A number representing the size, in bytes, of the vertex data contained inbuffer. If omitted,size defaults to thebuffer'sGPUBuffer.size -offset.

Return value

None (Undefined).

Validation

The following criteria must be met when callingsetVertexBuffer(), otherwise aGPUValidationError is generated and theGPURenderPassEncoder becomes invalid:

Examples

Set vertex buffer

In ourbasic render demo, several commands are recorded via aGPUCommandEncoder. Most of these commands originate from theGPURenderPassEncoder created viaGPUCommandEncoder.beginRenderPass().setVertexBuffer() is used as appropriate to set the source of vertex data.

js
// …const renderPipeline = device.createRenderPipeline(pipelineDescriptor);// Create GPUCommandEncoder to issue commands to the GPU// Note: render pass descriptor, command encoder, etc. are destroyed after use, fresh one needed for each frame.const commandEncoder = device.createCommandEncoder();// Create GPURenderPassDescriptor to tell WebGPU which texture to draw into, then initiate render passconst renderPassDescriptor = {  colorAttachments: [    {      clearValue: clearColor,      loadOp: "clear",      storeOp: "store",      view: context.getCurrentTexture().createView(),    },  ],};const passEncoder = commandEncoder.beginRenderPass(renderPassDescriptor);// Draw the trianglepassEncoder.setPipeline(renderPipeline);passEncoder.setVertexBuffer(0, vertexBuffer);passEncoder.draw(3);// End the render passpassEncoder.end();// End frame by passing array of command buffers to command queue for executiondevice.queue.submit([commandEncoder.finish()]);// …

Unset vertex buffer

js
// Set vertex buffer in slot 0passEncoder.setVertexBuffer(0, vertexBuffer);// Later, unset vertex buffer in slot 0passEncoder.setVertexBuffer(0, null);

Specifications

Specification
WebGPU
# dom-gpurendercommandsmixin-setvertexbuffer

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp