15bd8deadSopenharmony_ciName
25bd8deadSopenharmony_ci
35bd8deadSopenharmony_ci    ARB_texture_swizzle
45bd8deadSopenharmony_ci
55bd8deadSopenharmony_ciName Strings
65bd8deadSopenharmony_ci
75bd8deadSopenharmony_ci    GL_ARB_texture_swizzle
85bd8deadSopenharmony_ci
95bd8deadSopenharmony_ciContact
105bd8deadSopenharmony_ci
115bd8deadSopenharmony_ci    Jeff Bolz, NVIDIA Corporation (jbolz 'at' nvidia.com)
125bd8deadSopenharmony_ci
135bd8deadSopenharmony_ciContributors
145bd8deadSopenharmony_ci
155bd8deadSopenharmony_ci    Cass Everitt, Id Software
165bd8deadSopenharmony_ci    Brian Harris, Id Software
175bd8deadSopenharmony_ci    Pat Brown, NVIDIA
185bd8deadSopenharmony_ci    Eric Werness, NVIDIA
195bd8deadSopenharmony_ci
205bd8deadSopenharmony_ciNotice
215bd8deadSopenharmony_ci
225bd8deadSopenharmony_ci    Copyright (c) 2010-2013 The Khronos Group Inc. Copyright terms at
235bd8deadSopenharmony_ci        http://www.khronos.org/registry/speccopyright.html
245bd8deadSopenharmony_ci
255bd8deadSopenharmony_ciSpecification Update Policy
265bd8deadSopenharmony_ci
275bd8deadSopenharmony_ci    Khronos-approved extension specifications are updated in response to
285bd8deadSopenharmony_ci    issues and bugs prioritized by the Khronos OpenGL Working Group. For
295bd8deadSopenharmony_ci    extensions which have been promoted to a core Specification, fixes will
305bd8deadSopenharmony_ci    first appear in the latest version of that core Specification, and will
315bd8deadSopenharmony_ci    eventually be backported to the extension document. This policy is
325bd8deadSopenharmony_ci    described in more detail at
335bd8deadSopenharmony_ci        https://www.khronos.org/registry/OpenGL/docs/update_policy.php
345bd8deadSopenharmony_ci
355bd8deadSopenharmony_ciStatus
365bd8deadSopenharmony_ci
375bd8deadSopenharmony_ci    Complete. Approved by the ARB at the 2010/01/22 F2F meeting.
385bd8deadSopenharmony_ci    Approved by the Khronos Board of Promoters on March 10, 2010.
395bd8deadSopenharmony_ci
405bd8deadSopenharmony_ciVersion
415bd8deadSopenharmony_ci
425bd8deadSopenharmony_ci    Last Modified Date: December 7, 2009
435bd8deadSopenharmony_ci    Author Revision: 1.0
445bd8deadSopenharmony_ci
455bd8deadSopenharmony_ciNumber
465bd8deadSopenharmony_ci
475bd8deadSopenharmony_ci    ARB Extension #84
485bd8deadSopenharmony_ci
495bd8deadSopenharmony_ciDependencies
505bd8deadSopenharmony_ci
515bd8deadSopenharmony_ci     Written based on the wording of the OpenGL 2.1 specification.
525bd8deadSopenharmony_ci
535bd8deadSopenharmony_ciOverview
545bd8deadSopenharmony_ci
555bd8deadSopenharmony_ci    Classic OpenGL texture formats conflate texture storage and
565bd8deadSopenharmony_ci    interpretation, and assume that textures represent color. In 
575bd8deadSopenharmony_ci    modern applications, a significant quantity of textures don't
585bd8deadSopenharmony_ci    represent color, but rather data like shadow maps, normal maps,
595bd8deadSopenharmony_ci    page tables, occlusion data, etc.. For the latter class of data,
605bd8deadSopenharmony_ci    calling the data "RGBA" is just a convenient mapping of what the
615bd8deadSopenharmony_ci    data is onto the current model, but isn't an accurate reflection
625bd8deadSopenharmony_ci    of the reality of the data.
635bd8deadSopenharmony_ci
645bd8deadSopenharmony_ci    The existing texture formats provide an almost orthogonal set of
655bd8deadSopenharmony_ci    data types, sizes, and number of components, but the mappings of 
665bd8deadSopenharmony_ci    this storage into what the shader or fixed-function pipeline 
675bd8deadSopenharmony_ci    fetches is very much non-orthogonal. Previous extensions have
685bd8deadSopenharmony_ci    added some of the most demanded missing formats, but the problem
695bd8deadSopenharmony_ci    has not been solved once and for all.
705bd8deadSopenharmony_ci
715bd8deadSopenharmony_ci    This extension provides a mechanism to swizzle the components 
725bd8deadSopenharmony_ci    of a texture before they are applied according to the texture
735bd8deadSopenharmony_ci    environment in fixed-function or as they are returned to the 
745bd8deadSopenharmony_ci    shader.
755bd8deadSopenharmony_ci
765bd8deadSopenharmony_ciIP Status
775bd8deadSopenharmony_ci
785bd8deadSopenharmony_ci    No known IP claims.
795bd8deadSopenharmony_ci
805bd8deadSopenharmony_ciNew Procedures and Functions
815bd8deadSopenharmony_ci
825bd8deadSopenharmony_ci    None
835bd8deadSopenharmony_ci
845bd8deadSopenharmony_ciNew Tokens
855bd8deadSopenharmony_ci
865bd8deadSopenharmony_ci    Accepted by the <pname> parameters of TexParameteri,
875bd8deadSopenharmony_ci    TexParameterf, TexParameteriv, TexParameterfv,
885bd8deadSopenharmony_ci    GetTexParameterfv, and GetTexParameteriv:
895bd8deadSopenharmony_ci
905bd8deadSopenharmony_ci    TEXTURE_SWIZZLE_R                   0x8E42
915bd8deadSopenharmony_ci    TEXTURE_SWIZZLE_G                   0x8E43
925bd8deadSopenharmony_ci    TEXTURE_SWIZZLE_B                   0x8E44
935bd8deadSopenharmony_ci    TEXTURE_SWIZZLE_A                   0x8E45
945bd8deadSopenharmony_ci
955bd8deadSopenharmony_ci    Accepted by the <pname> parameters of TexParameteriv, 
965bd8deadSopenharmony_ci    TexParameterfv, GetTexParameterfv, and GetTexParameteriv:
975bd8deadSopenharmony_ci
985bd8deadSopenharmony_ci    TEXTURE_SWIZZLE_RGBA                0x8E46
995bd8deadSopenharmony_ci
1005bd8deadSopenharmony_ci
1015bd8deadSopenharmony_ciAdditions to Chapter 2 of the OpenGL 2.1 Specification (OpenGL Operation)
1025bd8deadSopenharmony_ci
1035bd8deadSopenharmony_ci    Modify Section 2.15.4 (Shader Execution), p. 84:
1045bd8deadSopenharmony_ci
1055bd8deadSopenharmony_ci    Texture Access
1065bd8deadSopenharmony_ci    
1075bd8deadSopenharmony_ci    ...and converts it to a texture source color Cs according to table 
1085bd8deadSopenharmony_ci    3.20 (section 3.8.13), followed by application of the texture swizzle
1095bd8deadSopenharmony_ci    as described in section 3.8.13. A four-component vector (Rs,Gs,Bs,As)
1105bd8deadSopenharmony_ci    is returned to the vertex shader.
1115bd8deadSopenharmony_ci
1125bd8deadSopenharmony_ciAdditions to Chapter 3 of the OpenGL 2.1 Specification (Rasterization)
1135bd8deadSopenharmony_ci
1145bd8deadSopenharmony_ci    Modify Section 3.8.4 (Texture Parameters), p. 168:
1155bd8deadSopenharmony_ci
1165bd8deadSopenharmony_ci    (modify table 3.18, p. 169)
1175bd8deadSopenharmony_ci    Name                   Type         Legal Values
1185bd8deadSopenharmony_ci    ----                   ----         ------------
1195bd8deadSopenharmony_ci    TEXTURE_SWIZZLE_R      enum         RED, GREEN, BLUE, ALPHA, ZERO, ONE
1205bd8deadSopenharmony_ci    TEXTURE_SWIZZLE_G      enum         RED, GREEN, BLUE, ALPHA, ZERO, ONE
1215bd8deadSopenharmony_ci    TEXTURE_SWIZZLE_B      enum         RED, GREEN, BLUE, ALPHA, ZERO, ONE
1225bd8deadSopenharmony_ci    TEXTURE_SWIZZLE_A      enum         RED, GREEN, BLUE, ALPHA, ZERO, ONE
1235bd8deadSopenharmony_ci
1245bd8deadSopenharmony_ci    (append to section 3.8.4, p. 170)
1255bd8deadSopenharmony_ci
1265bd8deadSopenharmony_ci    TEXTURE_SWIZZLE_RGBA sets the same state as the R, G, B, A enums in a 
1275bd8deadSopenharmony_ci    single call.
1285bd8deadSopenharmony_ci
1295bd8deadSopenharmony_ci    (append to section 3.8.13, p. 184)
1305bd8deadSopenharmony_ci    The values of the texture parameters TEXTURE_SWIZZLE_R, 
1315bd8deadSopenharmony_ci    TEXTURE_SWIZZLE_G, TEXTURE_SWIZZLE_B, and TEXTURE_SWIZZLE_A, are applied
1325bd8deadSopenharmony_ci    after the swizzling described in Table 3.20 (p. 186). The swizzle 
1335bd8deadSopenharmony_ci    parameter TEXTURE_SWIZZLE_R affects the first component of Cs as:
1345bd8deadSopenharmony_ci
1355bd8deadSopenharmony_ci    if (TEXTURE_SWIZZLE_R == RED) {
1365bd8deadSopenharmony_ci        Cs'[0] = Cs[0];
1375bd8deadSopenharmony_ci    } else if (TEXTURE_SWIZZLE_R == GREEN) {
1385bd8deadSopenharmony_ci        Cs'[0] = Cs[1];
1395bd8deadSopenharmony_ci    } else if (TEXTURE_SWIZZLE_R == BLUE) {
1405bd8deadSopenharmony_ci        Cs'[0] = Cs[2];
1415bd8deadSopenharmony_ci    } else if (TEXTURE_SWIZZLE_R == ALPHA) {
1425bd8deadSopenharmony_ci        Cs'[0] = As;
1435bd8deadSopenharmony_ci    } else if (TEXTURE_SWIZZLE_R == ZERO) {
1445bd8deadSopenharmony_ci        Cs'[0] = 0;
1455bd8deadSopenharmony_ci    } else if (TEXTURE_SWIZZLE_R == ONE) {
1465bd8deadSopenharmony_ci        Cs'[0] = 1; // float or int depending on texture component type
1475bd8deadSopenharmony_ci    }
1485bd8deadSopenharmony_ci
1495bd8deadSopenharmony_ci    and similarly for Cs'[1], Cs'[2], and As'.
1505bd8deadSopenharmony_ci
1515bd8deadSopenharmony_ci    Modify Section 3.11.2 (Shader Execution), p. 197:
1525bd8deadSopenharmony_ci
1535bd8deadSopenharmony_ci    Texture Access
1545bd8deadSopenharmony_ci    
1555bd8deadSopenharmony_ci    ...and converts it to a texture source color Cs according to table 
1565bd8deadSopenharmony_ci    3.20 (section 3.8.13), followed by application of the texture swizzle
1575bd8deadSopenharmony_ci    as described in section 3.8.13. The GL returns a four-component 
1585bd8deadSopenharmony_ci    vector (Rs,Gs,Bs,As) to the fragment shader...
1595bd8deadSopenharmony_ci
1605bd8deadSopenharmony_ciAdditions to the AGL/EGL/GLX/WGL Specifications
1615bd8deadSopenharmony_ci
1625bd8deadSopenharmony_ci    None
1635bd8deadSopenharmony_ci
1645bd8deadSopenharmony_ciErrors
1655bd8deadSopenharmony_ci
1665bd8deadSopenharmony_ci    The error INVALID_OPERATION is generated if TexParameteri,
1675bd8deadSopenharmony_ci    TexParameterf, TexParameteriv, or TexParameterfv, parameter <pname> 
1685bd8deadSopenharmony_ci    is TEXTURE_SWIZZLE_R, TEXTURE_SWIZZLE_G,  TEXTURE_SWIZZLE_B, 
1695bd8deadSopenharmony_ci    or TEXTURE_SWIZZLE_A, and <param> is not RED, GREEN, BLUE, ALPHA, 
1705bd8deadSopenharmony_ci    ZERO, or ONE.
1715bd8deadSopenharmony_ci
1725bd8deadSopenharmony_ci    The error INVALID_OPERATION is generated if TexParameteriv, or 
1735bd8deadSopenharmony_ci    TexParameterfv, parameter <pname> TEXTURE_SWIZZLE_RGBA, and the four 
1745bd8deadSopenharmony_ci    consecutive values pointed to by <param> are not all RED, GREEN, BLUE,
1755bd8deadSopenharmony_ci    ALPHA, ZERO, or ONE.
1765bd8deadSopenharmony_ci
1775bd8deadSopenharmony_ciNew State
1785bd8deadSopenharmony_ci
1795bd8deadSopenharmony_ci    Changes to table 6.16, p. 277 (Texture, state per texture object)
1805bd8deadSopenharmony_ci
1815bd8deadSopenharmony_ci                                                   Initial
1825bd8deadSopenharmony_ci    Get Value              Type   Get Command      Value    Description  Sec.      Attribute
1835bd8deadSopenharmony_ci    ---------              ----   -----------      -------  -----------  ----      ---------
1845bd8deadSopenharmony_ci    TEXTURE_SWIZZLE_R      Z      GetTexParameter  RED      Red          3.8.4     texture
1855bd8deadSopenharmony_ci                                                            component swizzle
1865bd8deadSopenharmony_ci    TEXTURE_SWIZZLE_G      Z      GetTexParameter  GREEN    Green        3.8.4     texture
1875bd8deadSopenharmony_ci                                                            component swizzle
1885bd8deadSopenharmony_ci    TEXTURE_SWIZZLE_B      Z      GetTexParameter  BLUE     Blue         3.8.4     texture
1895bd8deadSopenharmony_ci                                                            component swizzle
1905bd8deadSopenharmony_ci    TEXTURE_SWIZZLE_A      Z      GetTexParameter  ALPHA    Alpha        3.8.4     texture
1915bd8deadSopenharmony_ci                                                            component swizzle
1925bd8deadSopenharmony_ci
1935bd8deadSopenharmony_ciIssues
1945bd8deadSopenharmony_ci
1955bd8deadSopenharmony_ci    1) Why not add more new formats instead?
1965bd8deadSopenharmony_ci
1975bd8deadSopenharmony_ci    RESOLVED: Adding new formats is more implementation burden than
1985bd8deadSopenharmony_ci    one might expect. New formats need to be added to the pixel path,
1995bd8deadSopenharmony_ci    must be considered for FBO support, etc.. This extension avoids 
2005bd8deadSopenharmony_ci    those issues by solely affecting the result of a texture fetch.
2015bd8deadSopenharmony_ci
2025bd8deadSopenharmony_ci    2) What is the demand for this extension?
2035bd8deadSopenharmony_ci
2045bd8deadSopenharmony_ci    RESOLVED: There are several independent demands for this, 
2055bd8deadSopenharmony_ci    including:
2065bd8deadSopenharmony_ci    - OpenGL 3.0 deprecated support for ALPHA, LUMINANCE, 
2075bd8deadSopenharmony_ci      LUMINANCE_ALPHA, and INTENSITY formats. This extension provides
2085bd8deadSopenharmony_ci      a simple porting path for legacy applications that used these
2095bd8deadSopenharmony_ci      formats.
2105bd8deadSopenharmony_ci
2115bd8deadSopenharmony_ci    - There have been specific requests for (1,1,1,a), or "white alpha"
2125bd8deadSopenharmony_ci      formats that allow a "decal" texture to be used in the same shader
2135bd8deadSopenharmony_ci      as an RGBA texture. This can be accomplished with an OpenGL 2.1 
2145bd8deadSopenharmony_ci      ALPHA texture by doing
2155bd8deadSopenharmony_ci
2165bd8deadSopenharmony_ci        TexParameteri(target, TEXTURE_SWIZZLE_R, ONE);
2175bd8deadSopenharmony_ci        TexParameteri(target, TEXTURE_SWIZZLE_G, ONE);
2185bd8deadSopenharmony_ci        TexParameteri(target, TEXTURE_SWIZZLE_B, ONE);
2195bd8deadSopenharmony_ci        // TEXTURE_SWIZZLE_A is already ALPHA
2205bd8deadSopenharmony_ci      or equivalently
2215bd8deadSopenharmony_ci        GLint swiz[4] = {ONE, ONE, ONE, ALPHA};
2225bd8deadSopenharmony_ci        TexParameteriv(target, TEXTURE_SWIZZLE_RGBA, swiz);
2235bd8deadSopenharmony_ci
2245bd8deadSopenharmony_ci      or in OpenGL 3.0 "preview" contexts where ALPHA internal formats 
2255bd8deadSopenharmony_ci      are deprecated by using a RED texture:
2265bd8deadSopenharmony_ci        TexParameteri(target, TEXTURE_SWIZZLE_R, ONE);
2275bd8deadSopenharmony_ci        TexParameteri(target, TEXTURE_SWIZZLE_G, ONE);
2285bd8deadSopenharmony_ci        TexParameteri(target, TEXTURE_SWIZZLE_B, ONE);
2295bd8deadSopenharmony_ci        TexParameteri(target, TEXTURE_SWIZZLE_A, RED);
2305bd8deadSopenharmony_ci      or equivalently
2315bd8deadSopenharmony_ci        GLint swiz[4] = {ONE, ONE, ONE, RED};
2325bd8deadSopenharmony_ci        TexParameteriv(target, TEXTURE_SWIZZLE_RGBA, swiz);
2335bd8deadSopenharmony_ci
2345bd8deadSopenharmony_ci    - This functionality is available on Sony PlayStation 3 and can
2355bd8deadSopenharmony_ci      simplify porting those applications to OpenGL.
2365bd8deadSopenharmony_ci
2375bd8deadSopenharmony_ci    3) What names should be used for the components, in both the "source"
2385bd8deadSopenharmony_ci       (<param>) and "destination" (<pname>) enums? RGBA? XYZW? 0123?
2395bd8deadSopenharmony_ci
2405bd8deadSopenharmony_ci    RESOLVED: RGBA for both source and destination. 0123 could cause 
2415bd8deadSopenharmony_ci    confusion with ZERO and ONE. RGBA is a natural choice for source,
2425bd8deadSopenharmony_ci    because the spec describes the values returned by textures as "Color"
2435bd8deadSopenharmony_ci    and "Alpha." There's no particular precedent for destination to be 
2445bd8deadSopenharmony_ci    XYZW as this is still part of texture and not the shader, so RGBA 
2455bd8deadSopenharmony_ci    it is.
2465bd8deadSopenharmony_ci
2475bd8deadSopenharmony_ci    4) How does this interact with depth component textures?
2485bd8deadSopenharmony_ci
2495bd8deadSopenharmony_ci    RESOLVED: The swizzle is applied after the DEPTH_TEXTURE_MODE. This 
2505bd8deadSopenharmony_ci    naturally falls out of specifying the swizzle in terms of Table 3.20.
2515bd8deadSopenharmony_ci
2525bd8deadSopenharmony_ci    5) How does this interact with sRGB?
2535bd8deadSopenharmony_ci
2545bd8deadSopenharmony_ci    RESOLVED: The swizzle is applied after sRGB conversion.
2555bd8deadSopenharmony_ci
2565bd8deadSopenharmony_ci    6) How does this interact with NV_register_combiners, 
2575bd8deadSopenharmony_ci       NV_texture_shader, and other old "shading" extensions that
2585bd8deadSopenharmony_ci       predate NV/ARB_fragment_program and define their own "interesting"
2595bd8deadSopenharmony_ci       swizzles?
2605bd8deadSopenharmony_ci
2615bd8deadSopenharmony_ci    RESOLVED: Undefined. Core fixed-function shading (texture_env/combine)
2625bd8deadSopenharmony_ci    are fully supported, but old proprietary "configurable shading" 
2635bd8deadSopenharmony_ci    extensions are not.
2645bd8deadSopenharmony_ci
2655bd8deadSopenharmony_ci    7) How does the swizzle interact with the fixed-function texture 
2665bd8deadSopenharmony_ci       environment referencing the base format?
2675bd8deadSopenharmony_ci
2685bd8deadSopenharmony_ci    RESOLVED: Note that, by virtue of being defined in terms of Table 3.20,
2695bd8deadSopenharmony_ci    the swizzling occurs *before* the texture environment functions 
2705bd8deadSopenharmony_ci    (Table 3.21 and 3.22) are applied. So if you used the first example 
2715bd8deadSopenharmony_ci    under Issue (2) with fixed-function, the primary color would "pass 
2725bd8deadSopenharmony_ci    through" because the ALPHA base format environment function would 
2735bd8deadSopenharmony_ci    still apply. In order to effectively swizzle all four components, an 
2745bd8deadSopenharmony_ci    INTENSITY format would give the desired result with the same storage
2755bd8deadSopenharmony_ci    requirements.
2765bd8deadSopenharmony_ci
2775bd8deadSopenharmony_ciRevision History
2785bd8deadSopenharmony_ci
2795bd8deadSopenharmony_ci    Revision 1, 2008/08/21
2805bd8deadSopenharmony_ci     - Initial draft
2815bd8deadSopenharmony_ci    Revision 2, 2009/01/28
2825bd8deadSopenharmony_ci     - Add edits to fragment/vertex shader sections to clarify that the 
2835bd8deadSopenharmony_ci       swizzle is applied in both.
2845bd8deadSopenharmony_ci    Revision 3, 2009/12/07
2855bd8deadSopenharmony_ci     - Rename EXT->ARB
286