Create a new TransformFeedback instance.
The input vertex buffer, or an array of buffer descriptors when more than one buffer takes part. Each descriptor gives a buffer one of three roles:
{ input, output } - read by the shader and written by transform feedback. The pair is
swapped after each step, so input always holds the freshest data.{ input } - read by the shader only. Suitable for per-item data which never changes, and
which would otherwise have to be copied through transform feedback every step.{ output } - written by transform feedback only. Suitable for data which only a later
pass consumes, such as a stream feeding instanced rendering.Descriptors with an output are assigned transform feedback buffer indices in the order they
appear, skipping those without one, and so must match the order of the captured varyings.
OptionaloutputBuffer: VertexBuffer
The optional output buffer, when a single input buffer is specified. If omitted, a buffer with parameters matching the input buffer is created.
Optionalusage: number = BUFFER_GPUDYNAMIC
The optional usage type of the created output vertex buffer. Can be:
Defaults to BUFFER_GPUDYNAMIC (which is recommended for continuous update).
// a simulation writing its state back to itself, plus a stream consumed by instancing
const tf = new TransformFeedback([
{ input: positions, output: positionsOut }, // read and written, swapped each step
{ input: constants }, // read only, never modified
{ output: instances } // written only, for the render pass
]);
The current input buffer. When multiple input buffers are used, this is the first one - see TransformFeedback#inputBuffers.
The buffers read by the shader, in the order they were supplied.
The current output buffer. When multiple output buffers are used, this is the first one - see TransformFeedback#outputBuffers.
The buffers written by transform feedback, in the order of the captured varyings.
Destroys the transform feedback helper object.
Runs the specified shader on the input buffer, writes results into the new buffer, then optionally swaps input/output.
A vertex shader to run. Should be created with TransformFeedback.createShader.
Optionalswap: boolean = true
Swap input/output buffer data. Useful for continuous buffer processing. Default is true.
StaticcreateCreates a transform feedback ready vertex shader from code.
The graphics device used by the renderer.
Vertex shader code. Should contain output variables starting with "out_" or feedbackVaryings.
Unique name for caching the shader.
OptionalfeedbackVaryings: string[]
A list of shader output variable names that will be captured.
OptionalfeedbackVaryingsMode: number = TRANSFORM_FEEDBACK_INTERLEAVED
Specifies how transform feedback varyings are written into GPU buffers. Use TRANSFORM_FEEDBACK_INTERLEAVED to pack all captured varyings into a single buffer, or TRANSFORM_FEEDBACK_SEPARATE to store each varying in its own buffer. This setting is only effective when useTransformFeedback property is enabled. Defaults to TRANSFORM_FEEDBACK_INTERLEAVED.
A shader to use in the process() function.
This object allows you to configure and use the transform feedback feature (WebGL2 only). How to use:
out vec3 out_vertex_position, note that there must be out_ in the name. You can then simply assign values to these outputs in VS. The order and size of shader outputs must match the output buffer layout.TransformFeedback.createShader(device, vsCode, yourShaderName).const tf = new TransformFeedback(inputBuffer). This object will internally create an output buffer.tf.process(shader). Shader will take the input buffer, process it and write to the output buffer, then the input/output buffers will be automatically swapped, so you'll immediately see the result.