Home -> IRenderableNode -> SetInstanceMode

Description

The SetInstanceMode method is used to configure instanced drawing. By default, an IRenderableNode will draw only once. Instanced drawing allows the object to be drawn more than once using a single underlying draw call. Through the use of the BindVertexInstanceAttribute method, additional data can be supplied which varies between each object instance, allowing each instance to be drawn in a different location or with different attributes such as size and colour. Data can also be retrieved from other data sources which varies per instance, by using the inbuilt instance number provided by the shader language as an index for array or texture lookups.

ImportantImportant

In order to set the instanceOffset parameter to a non-zero value, the InstanceOffset feature must be supported on the IGraphicsDevice, and activated when the CreateRenderer method is called.

ImportantImportant

This method can be called at any time after the creation of the IRenderableNode, including when it has already been added to the render tree. Any changes made will not affect any current frame being drawn, and will take effect on the next frame.

Usage

SuccessToken SetInstanceMode(uint32_t instanceCount, uint32_t instanceOffset = 0);

Argument list

instanceCount [uint32_t]
Specifies the number of times to draw this renderable object
instanceOffset [uint32_t]
Specifies a numeric offset to apply to the instance number passed to the shader program. Without an offset, the instance number will begin at 0 for the first instance drawn.

Return value

[SuccessToken]
True if the instance count and offset values were successfully updated, false otherwise. There are currently no circumstances under which this method will fail, however in future updates the supplied values may be validated in debug builds to ensure they meet constraints around instancing on the target device. An assertion will be raised in debug builds if the result isn't tested.

See also