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