Name EXT_draw_instanced Name Strings GL_EXT_draw_instanced Contact Michael Gold, NVIDIA Corporation (gold 'at' nvidia.com) Status Shipping for GeForce 8 Series (November 2006) Version Last Modified Date: May 9, 2008 Author Revision: 1.5 Number 327 Dependencies OpenGL 2.0 is required. EXT_gpu_shader4 or NV_vertex_shader4 is required. Overview This extension provides the means to render multiple instances of an object with a single draw call, and an "instance ID" variable which can be used by the vertex program to compute per-instance values, typically an object's transform. New Tokens None New Procedures and Functions void DrawArraysInstancedEXT(enum mode, int first, sizei count, sizei primcount); void DrawElementsInstancedEXT(enum mode, sizei count, enum type, const void *indices, sizei primcount); Additions to Chapter 2 of the OpenGL 2.0 Specification (OpenGL Operation) Modify section 2.8 (Vertex Arrays), p. 23 (insert before the final paragraph, p. 30) The internal counter is a 32-bit integer value which may be read by a vertex program as , as described in section 2.X.3.2, or vertex shader as , as described in section 2.15.4.2. The value of this counter is always zero, except as noted below. The command void DrawArraysInstancedEXT(enum mode, int first, sizei count, sizei primcount); behaves identically to DrawArrays except that instances of the range of elements are executed and the value of advances for each iteration. It has the same effect as: if (mode or count is invalid) generate appropriate error else { for (i = 0; i < primcount; i++) { instanceID = i; DrawArrays(mode, first, count); } instanceID = 0; } The command void DrawElementsInstancedEXT(enum mode, sizei count, enum type, const void *indices, sizei primcount); behaves identically to DrawElements except that instances of the set of elements are executed, and the value of advances for each iteration. It has the same effect as: if (mode, count, or type is invalid ) generate appropriate error else { for (int i = 0; i < primcount; i++) { instanceID = i; DrawElements(mode, count, type, indices); } instanceID = 0; } Additions to Chapter 5 of the OpenGL 2.0 Specification (Special Functions) The error INVALID_OPERATION is generated if DrawArraysInstancedEXT or DrawElementsInstancedEXT is called during display list compilation. Dependencies on NV_vertex_program4 If NV_vertex_program4 is not supported, all references to vertex.instance are deleted. Dependencies on EXT_gpu_shader4 If EXT_gpu_shader4 is not supported, all references to gl_InstanceID are deleted. Errors INVALID_ENUM is generated by DrawElementsInstancedEXT if is not one of UNSIGNED_BYTE, UNSIGNED_SHORT or UNSIGNED_INT. INVALID_VALUE is generated by DrawArraysInstancedEXT if is less than zero. Issues (1) Should instanceID be provided by this extension, or should it be provided by EXT_gpu_shader4, thus creating a dependence on that spec? Resolved: While this extension could stand alone, its utility would be limited without the additional functionality provided by EXT_gpu_shader4; also, the spec language is cleaner if EXT_gpu_shader4 assumes instanceID is always available, even if its value is always zero without this extension. (2) Should MultiDrawArrays and MultiDrawElements affect the value of instanceID? Resolved: No, this may cause implementation difficulties and is considered unlikely to provide any real benefit. (3) Should DrawArraysInstanced and DrawElementsInstanced be compiled into display lists? Resolved: No, calling these during display list compilation generate INVALID_OPERATION. Revision History Rev. Date Author Changes ---- -------- -------- ----------------------------------------- 1.5 05/09/08 gold Removed extraneous parameters to DrawArrays and DrawElements in chapter 2 pseudocode