15bd8deadSopenharmony_ciName
25bd8deadSopenharmony_ci
35bd8deadSopenharmony_ci    ARB_draw_instanced
45bd8deadSopenharmony_ci
55bd8deadSopenharmony_ciName Strings
65bd8deadSopenharmony_ci
75bd8deadSopenharmony_ci    GL_ARB_draw_instanced
85bd8deadSopenharmony_ci
95bd8deadSopenharmony_ciContributors
105bd8deadSopenharmony_ci    Michael Gold, NVIDIA
115bd8deadSopenharmony_ci    James Helferty, TransGaming Inc.
125bd8deadSopenharmony_ci    Daniel Koch, TransGaming Inc.
135bd8deadSopenharmony_ci
145bd8deadSopenharmony_ciContact
155bd8deadSopenharmony_ci
165bd8deadSopenharmony_ci    James Helferty, TransGaming Inc. (james 'at' transgaming.com)
175bd8deadSopenharmony_ci    Daniel Koch, TransGaming Inc. (daniel 'at' transgaming.com)
185bd8deadSopenharmony_ci
195bd8deadSopenharmony_ciNotice
205bd8deadSopenharmony_ci
215bd8deadSopenharmony_ci    Copyright (c) 2008-2013 The Khronos Group Inc. Copyright terms at
225bd8deadSopenharmony_ci        http://www.khronos.org/registry/speccopyright.html
235bd8deadSopenharmony_ci
245bd8deadSopenharmony_ciSpecification Update Policy
255bd8deadSopenharmony_ci
265bd8deadSopenharmony_ci    Khronos-approved extension specifications are updated in response to
275bd8deadSopenharmony_ci    issues and bugs prioritized by the Khronos OpenGL Working Group. For
285bd8deadSopenharmony_ci    extensions which have been promoted to a core Specification, fixes will
295bd8deadSopenharmony_ci    first appear in the latest version of that core Specification, and will
305bd8deadSopenharmony_ci    eventually be backported to the extension document. This policy is
315bd8deadSopenharmony_ci    described in more detail at
325bd8deadSopenharmony_ci        https://www.khronos.org/registry/OpenGL/docs/update_policy.php
335bd8deadSopenharmony_ci
345bd8deadSopenharmony_ciIP Status
355bd8deadSopenharmony_ci
365bd8deadSopenharmony_ci    Unknown
375bd8deadSopenharmony_ci
385bd8deadSopenharmony_ciStatus
395bd8deadSopenharmony_ci
405bd8deadSopenharmony_ci    Approved by the ARB on July 11, 2008
415bd8deadSopenharmony_ci
425bd8deadSopenharmony_ciVersion
435bd8deadSopenharmony_ci
445bd8deadSopenharmony_ci    Last Modified Date:  April 8, 2011
455bd8deadSopenharmony_ci    Author Revision: 5
465bd8deadSopenharmony_ci
475bd8deadSopenharmony_ciNumber
485bd8deadSopenharmony_ci
495bd8deadSopenharmony_ci    ARB Extension #44
505bd8deadSopenharmony_ci
515bd8deadSopenharmony_ciDependencies
525bd8deadSopenharmony_ci
535bd8deadSopenharmony_ci    OpenGL 2.0 is required.
545bd8deadSopenharmony_ci
555bd8deadSopenharmony_ci    The extension is written against the OpenGL 2.1 Specification.
565bd8deadSopenharmony_ci
575bd8deadSopenharmony_ci    EXT_gpu_shader4 or NV_vertex_program4 or OpenGL 3.0 is required.
585bd8deadSopenharmony_ci
595bd8deadSopenharmony_ciOverview
605bd8deadSopenharmony_ci
615bd8deadSopenharmony_ci    A common use case in GL for some applications is to be able to
625bd8deadSopenharmony_ci    draw the same object, or groups of similar objects that share
635bd8deadSopenharmony_ci    vertex data, primitive count and type, multiple times.  This 
645bd8deadSopenharmony_ci    extension provides a means of accelerating such use cases while 
655bd8deadSopenharmony_ci    restricting the number of API calls, and keeping the amount of 
665bd8deadSopenharmony_ci    duplicate data to a minimum.
675bd8deadSopenharmony_ci    
685bd8deadSopenharmony_ci    This extension introduces two draw calls which are conceptually
695bd8deadSopenharmony_ci    equivalent to a series of draw calls.  Each conceptual call in
705bd8deadSopenharmony_ci    this series is considered an "instance" of the actual draw call.
715bd8deadSopenharmony_ci    
725bd8deadSopenharmony_ci    This extension also introduces a read-only built-in variable to
735bd8deadSopenharmony_ci    GLSL which contains the "instance ID."  This variable initially
745bd8deadSopenharmony_ci    contains 0, but increases by one after each conceptual draw call.
755bd8deadSopenharmony_ci
765bd8deadSopenharmony_ci    By using the instance ID or multiples thereof as an index into
775bd8deadSopenharmony_ci    a uniform array containing transform data, vertex shaders can 
785bd8deadSopenharmony_ci    draw multiple instances of an object with a single draw call.
795bd8deadSopenharmony_ci
805bd8deadSopenharmony_ciNew Tokens
815bd8deadSopenharmony_ci
825bd8deadSopenharmony_ci    None
835bd8deadSopenharmony_ci
845bd8deadSopenharmony_ciNew Procedures and Functions
855bd8deadSopenharmony_ci
865bd8deadSopenharmony_ci    void DrawArraysInstancedARB(enum mode, int first, sizei count,
875bd8deadSopenharmony_ci            sizei primcount);
885bd8deadSopenharmony_ci    void DrawElementsInstancedARB(enum mode, sizei count, enum type,
895bd8deadSopenharmony_ci            const void *indices, sizei primcount);
905bd8deadSopenharmony_ci
915bd8deadSopenharmony_ciAdditions to Chapter 2 of the OpenGL 2.1 Specification
925bd8deadSopenharmony_ci(OpenGL Operation)
935bd8deadSopenharmony_ci
945bd8deadSopenharmony_ci    Modify section 2.8 (Vertex Arrays), p. 23
955bd8deadSopenharmony_ci
965bd8deadSopenharmony_ci    (insert before the final paragraph, p. 30)
975bd8deadSopenharmony_ci
985bd8deadSopenharmony_ci    The internal counter <instanceID> is a 32-bit integer value which
995bd8deadSopenharmony_ci    may be read by a vertex program as <vertex.instance>, as described
1005bd8deadSopenharmony_ci    in section 2.X.3.2, or vertex shader as <gl_InstanceIDARB>, as
1015bd8deadSopenharmony_ci    described in section 2.15.4.2.  The value of this counter is
1025bd8deadSopenharmony_ci    always zero, except as noted below.
1035bd8deadSopenharmony_ci
1045bd8deadSopenharmony_ci    The command
1055bd8deadSopenharmony_ci
1065bd8deadSopenharmony_ci        void DrawArraysInstancedARB(enum mode, int first, sizei count,
1075bd8deadSopenharmony_ci                sizei primcount);
1085bd8deadSopenharmony_ci
1095bd8deadSopenharmony_ci    behaves identically to DrawArrays except that <primcount>
1105bd8deadSopenharmony_ci    instances of the range of elements are executed and the value of
1115bd8deadSopenharmony_ci    <instanceID> advances for each iteration.  It has the same effect
1125bd8deadSopenharmony_ci    as:
1135bd8deadSopenharmony_ci
1145bd8deadSopenharmony_ci        if (mode or count is invalid)
1155bd8deadSopenharmony_ci            generate appropriate error
1165bd8deadSopenharmony_ci        else {
1175bd8deadSopenharmony_ci            for (i = 0; i < primcount; i++) {
1185bd8deadSopenharmony_ci                instanceID = i;
1195bd8deadSopenharmony_ci                DrawArrays(mode, first, count, i);
1205bd8deadSopenharmony_ci            }
1215bd8deadSopenharmony_ci            instanceID = 0;
1225bd8deadSopenharmony_ci        }
1235bd8deadSopenharmony_ci
1245bd8deadSopenharmony_ci    The command
1255bd8deadSopenharmony_ci
1265bd8deadSopenharmony_ci        void DrawElementsInstancedARB(enum mode, sizei count, enum type,
1275bd8deadSopenharmony_ci                const void *indices, sizei primcount);
1285bd8deadSopenharmony_ci
1295bd8deadSopenharmony_ci    behaves identically to DrawElements except that <primcount>
1305bd8deadSopenharmony_ci    instances of the set of elements are executed, and the value of
1315bd8deadSopenharmony_ci    <instanceID> advances for each iteration.  It has the same effect
1325bd8deadSopenharmony_ci    as:
1335bd8deadSopenharmony_ci
1345bd8deadSopenharmony_ci        if (mode, count, or type is invalid )
1355bd8deadSopenharmony_ci            generate appropriate error
1365bd8deadSopenharmony_ci        else {
1375bd8deadSopenharmony_ci            for (int i = 0; i < primcount; i++) {
1385bd8deadSopenharmony_ci                instanceID = i;
1395bd8deadSopenharmony_ci                DrawElements(mode, count, type, indices, i);
1405bd8deadSopenharmony_ci            }
1415bd8deadSopenharmony_ci            instanceID = 0;
1425bd8deadSopenharmony_ci        }
1435bd8deadSopenharmony_ci
1445bd8deadSopenharmony_ci    Add a new section "2.15.4.2 Shader Inputs" before "Position
1455bd8deadSopenharmony_ci    Invariance"
1465bd8deadSopenharmony_ci
1475bd8deadSopenharmony_ci    Besides having access to vertex attributes and uniform variables, vertex
1485bd8deadSopenharmony_ci    shaders can access the read-only built-in variable gl_InstanceIDARB or
1495bd8deadSopenharmony_ci    gl_InstanceID. The variables gl_InstanceIDARB and gl_InstanceID hold the
1505bd8deadSopenharmony_ci    integer index of the current primitive in an instanced draw call.  See
1515bd8deadSopenharmony_ci    also section 7.1 of the OpenGL Shading Language Specification.
1525bd8deadSopenharmony_ci
1535bd8deadSopenharmony_ciAdditions to Chapter 5 of the OpenGL 2.1 Specification
1545bd8deadSopenharmony_ci(Special Functions)
1555bd8deadSopenharmony_ci
1565bd8deadSopenharmony_ci    The error INVALID_OPERATION is generated if DrawArraysInstancedARB
1575bd8deadSopenharmony_ci    or DrawElementsInstancedARB is called during display list
1585bd8deadSopenharmony_ci    compilation.
1595bd8deadSopenharmony_ci
1605bd8deadSopenharmony_ciDependencies on NV_vertex_program4
1615bd8deadSopenharmony_ci
1625bd8deadSopenharmony_ci    If NV_vertex_program4 is not supported, all references to
1635bd8deadSopenharmony_ci    vertex.instance are deleted.
1645bd8deadSopenharmony_ci
1655bd8deadSopenharmony_ciErrors
1665bd8deadSopenharmony_ci
1675bd8deadSopenharmony_ci    INVALID_ENUM is generated by DrawElementsInstancedARB if <type> is
1685bd8deadSopenharmony_ci    not one of UNSIGNED_BYTE, UNSIGNED_SHORT or UNSIGNED_INT.
1695bd8deadSopenharmony_ci
1705bd8deadSopenharmony_ci    INVALID_VALUE is generated by DrawArraysInstancedARB if <first> is
1715bd8deadSopenharmony_ci    less than zero.
1725bd8deadSopenharmony_ci
1735bd8deadSopenharmony_ciModifications to The OpenGL Shading Language Specification, Version 1.10.59
1745bd8deadSopenharmony_ci
1755bd8deadSopenharmony_ci    Including the following line in a shader can be used to control the
1765bd8deadSopenharmony_ci    language features described in this extension:
1775bd8deadSopenharmony_ci
1785bd8deadSopenharmony_ci      #extension GL_ARB_draw_instanced : <behavior>
1795bd8deadSopenharmony_ci
1805bd8deadSopenharmony_ci    where <behavior> is as specified in section 3.3.
1815bd8deadSopenharmony_ci
1825bd8deadSopenharmony_ci    A new preprocessor #define is added to the OpenGL Shading Language:
1835bd8deadSopenharmony_ci
1845bd8deadSopenharmony_ci      #define GL_ARB_draw_instanced 1
1855bd8deadSopenharmony_ci
1865bd8deadSopenharmony_ci    Change Section 7.1 "Vertex Shader Special Variables"
1875bd8deadSopenharmony_ci
1885bd8deadSopenharmony_ci    Add the following definitions to the list of built-in variable definitions:
1895bd8deadSopenharmony_ci
1905bd8deadSopenharmony_ci          int gl_InstanceIDARB; // read-only
1915bd8deadSopenharmony_ci          int gl_InstanceID;    // read-only
1925bd8deadSopenharmony_ci
1935bd8deadSopenharmony_ci    Add the following paragraph at the end of the section:
1945bd8deadSopenharmony_ci
1955bd8deadSopenharmony_ci    The variables gl_InstanceIDARB and gl_InstanceID are available as a
1965bd8deadSopenharmony_ci    read-only variables from within vertex shaders and hold the integer index
1975bd8deadSopenharmony_ci    of the current primitive in an instanced draw call
1985bd8deadSopenharmony_ci    (DrawArraysInstancedARB, DrawElementsInstancedARB). If the current
1995bd8deadSopenharmony_ci    primitive does not come from an instanced draw call, the values of
2005bd8deadSopenharmony_ci    gl_InstanceIDARB and gl_InstanceID are zero.
2015bd8deadSopenharmony_ci
2025bd8deadSopenharmony_ci
2035bd8deadSopenharmony_ciIssues
2045bd8deadSopenharmony_ci
2055bd8deadSopenharmony_ci  (1) Should instanceID be provided by this extension, or should it be
2065bd8deadSopenharmony_ci      provided by the core OpenGL 3.0 (similarly to how it was done with
2075bd8deadSopenharmony_ci      EXT_gpu_shader4)?
2085bd8deadSopenharmony_ci      
2095bd8deadSopenharmony_ci        Resolved: Provide both instanceID and instanceIDARB.  The original
2105bd8deadSopenharmony_ci        intention was that instanceID and other language changes should be
2115bd8deadSopenharmony_ci        provided by this extension and properly decorated with the ARB suffix.
2125bd8deadSopenharmony_ci        However, many vendors shipped implementations that supported both, and
2135bd8deadSopenharmony_ci        some applications came to depend on this out-of-spec behavior.  It
2145bd8deadSopenharmony_ci        appears that the EXT_gpu_shader4 incorrectly neglected to specify the
2155bd8deadSopenharmony_ci        suffix EXT suffix for gl_InstanceID.
2165bd8deadSopenharmony_ci
2175bd8deadSopenharmony_ci  (2) Should MultiDrawArrays and MultiDrawElements affect the value of
2185bd8deadSopenharmony_ci      instanceID?
2195bd8deadSopenharmony_ci
2205bd8deadSopenharmony_ci        Resolved: No, this may cause implementation difficulties and
2215bd8deadSopenharmony_ci        is considered unlikely to provide any real benefit.
2225bd8deadSopenharmony_ci
2235bd8deadSopenharmony_ci  (3) Should DrawArraysInstanced and DrawElementsInstanced be compiled
2245bd8deadSopenharmony_ci      into display lists?
2255bd8deadSopenharmony_ci
2265bd8deadSopenharmony_ci        Resolved: No, calling these during display list compilation
2275bd8deadSopenharmony_ci        generate INVALID_OPERATION.
2285bd8deadSopenharmony_ci
2295bd8deadSopenharmony_ci
2305bd8deadSopenharmony_ciRevision History
2315bd8deadSopenharmony_ci
2325bd8deadSopenharmony_ci    #5 April 8, 2011, Ian Romanick
2335bd8deadSopenharmony_ci        - Fix typo "holds holds"
2345bd8deadSopenharmony_ci        - Make both gl_InstanceID and gl_InstanceIDARB available to reflect
2355bd8deadSopenharmony_ci          what vendors actually ship.
2365bd8deadSopenharmony_ci        - Existence of gl_InstanceID and gl_InstanceIDARB do not depend on
2375bd8deadSopenharmony_ci          OpenGL 3.0 or GL_EXT_gpu_shader4.
2385bd8deadSopenharmony_ci    #4 July 8, 2008, jhelferty
2395bd8deadSopenharmony_ci        - corrected dependency typo
2405bd8deadSopenharmony_ci        - expanded Overview
2415bd8deadSopenharmony_ci    #3 June 4, 2008, dgkoch
2425bd8deadSopenharmony_ci        - merged instanceID and relevant language from the EXT_gpu_shader4
2435bd8deadSopenharmony_ci          extension revision 13.
2445bd8deadSopenharmony_ci        - renamed to InstanceID_ARB to properly follow conventions
2455bd8deadSopenharmony_ci        - merged issues 1 & 4
2465bd8deadSopenharmony_ci    #2 May 14 2008, jlheferty
2475bd8deadSopenharmony_ci        - added contact, contributer information.
2485bd8deadSopenharmony_ci        - bumped OpenGL spec written against to 2.1
2495bd8deadSopenharmony_ci        - added issue 4
2505bd8deadSopenharmony_ci    #1 May 12 2008, dgkoch
2515bd8deadSopenharmony_ci        - initial conversion from EXT to ARB
252