GPU vertex format array with each element specifying the GPUVertexFormat of teh attribute.
The offset array that is optional. The offset, in bytes, is counted from the beginning of the element to the data
for the attribute. Note that the offset must be a multiple of the minimum of 4 and sizeof the attrib.format.
The stride, in bytes, between elements of the array. This is an optional argument.
The numeric location associated with the attribute, such as position, normal, or uv, which will
correspond with a @location attribute declared in the vertex shader. This is an optional argument.
Generated using TypeDoc
This function sets the
buffersattribute of the vertex state in a render pipeline. In this function, the input argumentformatsis a GPU vertex-format array. It can be specified as'float32','float32x2','float32x3','float32x4', etc., which correspond to the WGSL style in the shaderf32,vec2<f32>,vec3<f32>,vec4<f32>, etc. If the vertex data is stored in a separate buffer for each attribute such as position, normal, and UV, you can simply provide only this input argument like['float32x3', 'float32x3', 'float32x2']and ignore all the other optional arguments. In this case, thesetVertexBuffersfunction will automatically calculate theoffset,arrayStride, andshaderLocationfor each vertex attribute. Note that theshaderLocationis set with an array filled with consecutive numbers like [0, 1, 2], which must match the@locationattribute specified in the vertex shader. Otherwise, you need to manually specify theshaderLocationsarray argument.On the other hand, if you store the vertex data in a single buffer for all attributes (e.g., position, normal, and uv), you will need to provide not only the vertex
formatsarray, but also theoffsetsarray. Here is an example of a single buffer that stores theposition(vec3<f32>),normal(vec3<f32>), anduv(vec2<f32>) data. The correspondingarrayStridewill be 12, 12, and 8, and theoffsetsarray will be [0, 12, 24]. In this case, you can set thebuffersattribute by calling the function like this:const bufs = setVertexBuffers(['float32x3', 'float32x3', 'float32x2'], [0, 12, 24]);The above example assumes that all the vertex attributes (position, normal, and uv) stored in a single buffer are used in the pipeline and vertex shader. What happens if not all the attributes in the buffer are needed. For example, the pipeline and shader only need the
positionanduvdata, but not thenormaldata. In this case, in addition to theformatsandoffsetsarguments, you will also need to specify thetotalArrayStrideargument. ThearrayStrideforposition,normal, anduvis 12, 12, and 8, respectively, so thetotalArrayStride= 12 + 12 + 8 = 32. Thus, we can create thebuffersattribute using the following codeconst bufs = setVertexBuffers(['float32x3', 'float32x2'], [0, 24], 32);Note that the
offsetsarray is set to [0, 24] rather than [0, 12], because theuvdata starts afterpositionandnormaldata, while thenormaldata is still stored in the buffer even though it is not used in this example.Returns
An array of GPU vertex buffer layout.