15bd8deadSopenharmony_ciName
25bd8deadSopenharmony_ci
35bd8deadSopenharmony_ci    NV_draw_instanced
45bd8deadSopenharmony_ci
55bd8deadSopenharmony_ciName Strings
65bd8deadSopenharmony_ci
75bd8deadSopenharmony_ci    GL_NV_draw_instanced
85bd8deadSopenharmony_ci
95bd8deadSopenharmony_ciContributors
105bd8deadSopenharmony_ci    Contributors to ARB_draw_instanced and EXT_gpu_shader4
115bd8deadSopenharmony_ci    Mathias Heyer, NVIDIA
125bd8deadSopenharmony_ci    Greg Roth, NVIDIA
135bd8deadSopenharmony_ci
145bd8deadSopenharmony_ciContact
155bd8deadSopenharmony_ci
165bd8deadSopenharmony_ci    Greg Roth, NVIDIA (groth 'at' nvidia 'dot' com)
175bd8deadSopenharmony_ci
185bd8deadSopenharmony_ciStatus
195bd8deadSopenharmony_ci
205bd8deadSopenharmony_ci    Complete
215bd8deadSopenharmony_ci
225bd8deadSopenharmony_ciVersion
235bd8deadSopenharmony_ci
245bd8deadSopenharmony_ci    Last Modified Date:  Aug 28, 2012
255bd8deadSopenharmony_ci    Author Revision: 3
265bd8deadSopenharmony_ci
275bd8deadSopenharmony_ciNumber
285bd8deadSopenharmony_ci
295bd8deadSopenharmony_ci    OpenGL ES Extension #141
305bd8deadSopenharmony_ci
315bd8deadSopenharmony_ciDependencies
325bd8deadSopenharmony_ci
335bd8deadSopenharmony_ci    OpenGL ES 2.0 is required.
345bd8deadSopenharmony_ci
355bd8deadSopenharmony_ci    The extension is written against the OpenGL ES 2.0.25 Specification.
365bd8deadSopenharmony_ci
375bd8deadSopenharmony_ci    Written based on the wording of The OpenGL ES Shading Language
385bd8deadSopenharmony_ci    1.00.14 Specification.
395bd8deadSopenharmony_ci
405bd8deadSopenharmony_ci    OES_element_index_uint affects the definition of this extension.
415bd8deadSopenharmony_ci
425bd8deadSopenharmony_ciOverview
435bd8deadSopenharmony_ci
445bd8deadSopenharmony_ci    A common use case in GL for some applications is to be able to
455bd8deadSopenharmony_ci    draw the same object, or groups of similar objects that share
465bd8deadSopenharmony_ci    vertex data, primitive count and type, multiple times.  This
475bd8deadSopenharmony_ci    extension provides a means of accelerating such use cases while
485bd8deadSopenharmony_ci    limiting the number of required API calls, and keeping the amount
495bd8deadSopenharmony_ci    of duplicate data to a minimum.
505bd8deadSopenharmony_ci
515bd8deadSopenharmony_ci    This extension introduces two draw calls which are conceptually
525bd8deadSopenharmony_ci    equivalent to a series of draw calls.  Each conceptual call in
535bd8deadSopenharmony_ci    this series is considered an "instance" of the actual draw call.
545bd8deadSopenharmony_ci
555bd8deadSopenharmony_ci    This extension also introduces a read-only built-in variable to
565bd8deadSopenharmony_ci    GLSL which contains the "instance ID."  This variable initially
575bd8deadSopenharmony_ci    contains 0, but increases by one after each conceptual draw call.
585bd8deadSopenharmony_ci
595bd8deadSopenharmony_ci    By using the instance ID or multiples thereof as an index into
605bd8deadSopenharmony_ci    a uniform array containing transform data, vertex shaders can
615bd8deadSopenharmony_ci    draw multiple instances of an object with a single draw call.
625bd8deadSopenharmony_ci
635bd8deadSopenharmony_ciNew Procedures and Functions
645bd8deadSopenharmony_ci
655bd8deadSopenharmony_ci    void DrawArraysInstancedNV(enum mode, int first, sizei count,
665bd8deadSopenharmony_ci            sizei primcount);
675bd8deadSopenharmony_ci    void DrawElementsInstancedNV(enum mode, sizei count, enum type,
685bd8deadSopenharmony_ci            const void *indices, sizei primcount);
695bd8deadSopenharmony_ci
705bd8deadSopenharmony_ciNew Tokens
715bd8deadSopenharmony_ci
725bd8deadSopenharmony_ci    None
735bd8deadSopenharmony_ci
745bd8deadSopenharmony_ciAdditions to Chapter 2 of the OpenGL ES 2.0.25 Specification
755bd8deadSopenharmony_ci(OpenGL ES Operation)
765bd8deadSopenharmony_ci
775bd8deadSopenharmony_ci    Modify section 2.8 (Vertex Arrays)
785bd8deadSopenharmony_ci
795bd8deadSopenharmony_ci    (Insert before the final paragraph)
805bd8deadSopenharmony_ci
815bd8deadSopenharmony_ci    The internal counter <instanceID> is a 32-bit integer value which
825bd8deadSopenharmony_ci    may be read by a vertex shader as <gl_InstanceIDNV>, as
835bd8deadSopenharmony_ci    described in section 2.10.5.2.  The value of this counter is
845bd8deadSopenharmony_ci    always zero, except as noted below.
855bd8deadSopenharmony_ci
865bd8deadSopenharmony_ci    The command
875bd8deadSopenharmony_ci
885bd8deadSopenharmony_ci        void DrawArraysInstancedNV(enum mode, int first, sizei count,
895bd8deadSopenharmony_ci                sizei primcount);
905bd8deadSopenharmony_ci
915bd8deadSopenharmony_ci    behaves identically to DrawArrays except that <primcount>
925bd8deadSopenharmony_ci    instances of the range of elements are executed and the value of
935bd8deadSopenharmony_ci    <instanceID> advances for each iteration.  It has the same effect
945bd8deadSopenharmony_ci    as:
955bd8deadSopenharmony_ci
965bd8deadSopenharmony_ci        if (mode, count, or primcount is invalid)
975bd8deadSopenharmony_ci            generate appropriate error
985bd8deadSopenharmony_ci        else {
995bd8deadSopenharmony_ci            for (i = 0; i < primcount; i++) {
1005bd8deadSopenharmony_ci                instanceID = i;
1015bd8deadSopenharmony_ci                DrawArrays(mode, first, count);
1025bd8deadSopenharmony_ci            }
1035bd8deadSopenharmony_ci            instanceID = 0;
1045bd8deadSopenharmony_ci        }
1055bd8deadSopenharmony_ci
1065bd8deadSopenharmony_ci    The command
1075bd8deadSopenharmony_ci
1085bd8deadSopenharmony_ci        void DrawElementsInstancedNV(enum mode, sizei count, enum type,
1095bd8deadSopenharmony_ci                const void *indices, sizei primcount);
1105bd8deadSopenharmony_ci
1115bd8deadSopenharmony_ci    behaves identically to DrawElements except that <primcount>
1125bd8deadSopenharmony_ci    instances of the set of elements are executed, and the value of
1135bd8deadSopenharmony_ci    <instanceID> advances for each iteration.  It has the same effect
1145bd8deadSopenharmony_ci    as:
1155bd8deadSopenharmony_ci
1165bd8deadSopenharmony_ci        if (mode, count, primcount, or type is invalid )
1175bd8deadSopenharmony_ci            generate appropriate error
1185bd8deadSopenharmony_ci        else {
1195bd8deadSopenharmony_ci            for (int i = 0; i < primcount; i++) {
1205bd8deadSopenharmony_ci                instanceID = i;
1215bd8deadSopenharmony_ci                DrawElements(mode, count, type, indices);
1225bd8deadSopenharmony_ci            }
1235bd8deadSopenharmony_ci            instanceID = 0;
1245bd8deadSopenharmony_ci        }
1255bd8deadSopenharmony_ci
1265bd8deadSopenharmony_ci    Add a new section 2.10.5.2 "Shader Inputs" after "Texture Access" in
1275bd8deadSopenharmony_ci    Section 2.10.5 "Shader Execution".
1285bd8deadSopenharmony_ci
1295bd8deadSopenharmony_ci    Besides having access to vertex attributes and uniform variables,
1305bd8deadSopenharmony_ci    vertex shaders can access the read-only built-in variable
1315bd8deadSopenharmony_ci    gl_InstanceIDNV. The variable gl_InstanceIDNV holds the integer
1325bd8deadSopenharmony_ci    index of the current primitive in an instanced draw call.  See also
1335bd8deadSopenharmony_ci    section 7.1 of the OpenGL ES Shading Language Specification.
1345bd8deadSopenharmony_ci
1355bd8deadSopenharmony_ci
1365bd8deadSopenharmony_ciModifications to The OpenGL ES Shading Language Specification, Version
1375bd8deadSopenharmony_ci1.00.14
1385bd8deadSopenharmony_ci
1395bd8deadSopenharmony_ci    Including the following line in a shader can be used to control the
1405bd8deadSopenharmony_ci    language features described in this extension:
1415bd8deadSopenharmony_ci
1425bd8deadSopenharmony_ci      #extension GL_NV_draw_instanced : <behavior>
1435bd8deadSopenharmony_ci
1445bd8deadSopenharmony_ci    where <behavior> is as specified in section 3.4.
1455bd8deadSopenharmony_ci
1465bd8deadSopenharmony_ci    A new preprocessor #define is added to the OpenGL Shading Language:
1475bd8deadSopenharmony_ci
1485bd8deadSopenharmony_ci      #define GL_NV_draw_instanced 1
1495bd8deadSopenharmony_ci
1505bd8deadSopenharmony_ci    Change Section 7.1 "Vertex Shader Special Variables"
1515bd8deadSopenharmony_ci
1525bd8deadSopenharmony_ci    Add the following paragraph after the description of gl_PointSize:
1535bd8deadSopenharmony_ci
1545bd8deadSopenharmony_ci    The variable gl_InstanceIDNV is available as a read-only variable
1555bd8deadSopenharmony_ci    from within vertex shaders and holds the integer index of the
1565bd8deadSopenharmony_ci    current primitive in an instanced draw call (DrawArraysInstancedNV,
1575bd8deadSopenharmony_ci    DrawElementsInstancedNV). If the current primitive does not come
1585bd8deadSopenharmony_ci    from an instanced draw call, the value of gl_InstanceIDNV is zero.
1595bd8deadSopenharmony_ci
1605bd8deadSopenharmony_ci    Add the following definitions to the list of built-in variable definitions:
1615bd8deadSopenharmony_ci
1625bd8deadSopenharmony_ci          int gl_InstanceIDNV; // read-only
1635bd8deadSopenharmony_ci
1645bd8deadSopenharmony_ci
1655bd8deadSopenharmony_ciDependencies on OES_element_index_uint
1665bd8deadSopenharmony_ci
1675bd8deadSopenharmony_ci    If OES_element_index_uint is not supported, removed all references
1685bd8deadSopenharmony_ci    to UNSIGNED_INT indices and the associated GL data type uint in
1695bd8deadSopenharmony_ci    the description of DrawElementsInstancedNV.
1705bd8deadSopenharmony_ci
1715bd8deadSopenharmony_ciErrors
1725bd8deadSopenharmony_ci
1735bd8deadSopenharmony_ci    INVALID_ENUM is generated by DrawElementsInstancedNV if <type> is
1745bd8deadSopenharmony_ci    not one of UNSIGNED_BYTE, UNSIGNED_SHORT or UNSIGNED_INT.
1755bd8deadSopenharmony_ci
1765bd8deadSopenharmony_ci    INVALID_VALUE is generated by DrawArraysInstancedNV if <first>,
1775bd8deadSopenharmony_ci    <count>, or <primcount> is less than zero.
1785bd8deadSopenharmony_ci
1795bd8deadSopenharmony_ci    INVALID_ENUM is generated by DrawArraysInstancedNV or
1805bd8deadSopenharmony_ci    DrawElementsInstancedNV if <mode> is not one of the modes described in
1815bd8deadSopenharmony_ci    section 2.6.1.
1825bd8deadSopenharmony_ci
1835bd8deadSopenharmony_ci    INVALID_VALUE is generated by DrawElementsInstancedNV if <count> or
1845bd8deadSopenharmony_ci    <primcount> is less than zero.
1855bd8deadSopenharmony_ci
1865bd8deadSopenharmony_ciIssues
1875bd8deadSopenharmony_ci
1885bd8deadSopenharmony_ci    1) Should this exist as a separate extension from NV_instanced_arrays?
1895bd8deadSopenharmony_ci
1905bd8deadSopenharmony_ci    Resolved: Yes. Even though these extensions expose similar
1915bd8deadSopenharmony_ci    functionality and together they represent a more cohesive extension
1925bd8deadSopenharmony_ci    with slightly less tricky text in the process, keeping them separate
1935bd8deadSopenharmony_ci    makes the relationship with the desktop extensions clear.
1945bd8deadSopenharmony_ci
1955bd8deadSopenharmony_ciRevision History
1965bd8deadSopenharmony_ci
1975bd8deadSopenharmony_ci    Rev.    Date        Author      Changes
1985bd8deadSopenharmony_ci    ----  ------------- ---------   ----------------------------------------
1995bd8deadSopenharmony_ci     3    28 Aug 2012    groth      Minor copy edits and corrections to spec references
2005bd8deadSopenharmony_ci     2    19 Aug 2012    groth      Correct illustrative code samples
2015bd8deadSopenharmony_ci     1    12 Aug 2012    groth      Initial GLES2 version from ARB_draw_instanced and EXT_gpu_shader4
202