15bd8deadSopenharmony_ciName
25bd8deadSopenharmony_ci
35bd8deadSopenharmony_ci    EXT_texture_shared_exponent
45bd8deadSopenharmony_ci
55bd8deadSopenharmony_ciName Strings
65bd8deadSopenharmony_ci
75bd8deadSopenharmony_ci    GL_EXT_texture_shared_exponent
85bd8deadSopenharmony_ci
95bd8deadSopenharmony_ciContact
105bd8deadSopenharmony_ci
115bd8deadSopenharmony_ci    Mark J. Kilgard, NVIDIA Corporation (mjk 'at' nvidia.com)
125bd8deadSopenharmony_ci
135bd8deadSopenharmony_ciContributors
145bd8deadSopenharmony_ci
155bd8deadSopenharmony_ci    Pat Brown, NVIDIA
165bd8deadSopenharmony_ci    Jon Leech
175bd8deadSopenharmony_ci    Bruce Merry, ARM
185bd8deadSopenharmony_ci
195bd8deadSopenharmony_ciStatus
205bd8deadSopenharmony_ci
215bd8deadSopenharmony_ci    Shipping
225bd8deadSopenharmony_ci
235bd8deadSopenharmony_ciVersion
245bd8deadSopenharmony_ci
255bd8deadSopenharmony_ci    Date: July 18, 2008
265bd8deadSopenharmony_ci    Revision: 1.0
275bd8deadSopenharmony_ci
285bd8deadSopenharmony_ciNumber
295bd8deadSopenharmony_ci
305bd8deadSopenharmony_ci    333
315bd8deadSopenharmony_ci
325bd8deadSopenharmony_ciDependencies
335bd8deadSopenharmony_ci
345bd8deadSopenharmony_ci    OpenGL 1.1 required
355bd8deadSopenharmony_ci
365bd8deadSopenharmony_ci    ARB_color_buffer_float affects this extension.
375bd8deadSopenharmony_ci
385bd8deadSopenharmony_ci    EXT_framebuffer_object affects this extension.
395bd8deadSopenharmony_ci
405bd8deadSopenharmony_ci    This extension is written against the OpenGL 2.0 (September 7,
415bd8deadSopenharmony_ci    2004) specification.
425bd8deadSopenharmony_ci
435bd8deadSopenharmony_ciOverview
445bd8deadSopenharmony_ci
455bd8deadSopenharmony_ci    Existing texture formats provide either fixed-point formats with
465bd8deadSopenharmony_ci    limited range and precision but with compact encodings (allowing 32
475bd8deadSopenharmony_ci    or fewer bits per multi-component texel), or floating-point formats
485bd8deadSopenharmony_ci    with tremendous range and precision but without compact encodings
495bd8deadSopenharmony_ci    (typically 16 or 32 bits per component).
505bd8deadSopenharmony_ci
515bd8deadSopenharmony_ci    This extension adds a new packed format and new internal texture
525bd8deadSopenharmony_ci    format for encoding 3-component vectors (typically RGB colors) with
535bd8deadSopenharmony_ci    a single 5-bit exponent (biased up by 15) and three 9-bit mantissas
545bd8deadSopenharmony_ci    for each respective component.  There is no sign bit so all three
555bd8deadSopenharmony_ci    components must be non-negative.  The fractional mantissas are
565bd8deadSopenharmony_ci    stored without an implied 1 to the left of the decimal point.
575bd8deadSopenharmony_ci    Neither infinity nor not-a-number (NaN) are representable in this
585bd8deadSopenharmony_ci    shared exponent format.
595bd8deadSopenharmony_ci
605bd8deadSopenharmony_ci    This 32 bits/texel shared exponent format is particularly well-suited
615bd8deadSopenharmony_ci    to high dynamic range (HDR) applications where light intensity is
625bd8deadSopenharmony_ci    typically stored as non-negative red, green, and blue components
635bd8deadSopenharmony_ci    with considerable range.
645bd8deadSopenharmony_ci
655bd8deadSopenharmony_ciNew Procedures and Functions
665bd8deadSopenharmony_ci
675bd8deadSopenharmony_ci    None
685bd8deadSopenharmony_ci
695bd8deadSopenharmony_ciNew Tokens
705bd8deadSopenharmony_ci
715bd8deadSopenharmony_ci    Accepted by the <internalformat> parameter of TexImage1D,
725bd8deadSopenharmony_ci    TexImage2D, TexImage3D, CopyTexImage1D, CopyTexImage2D, and
735bd8deadSopenharmony_ci    RenderbufferStorageEXT:
745bd8deadSopenharmony_ci
755bd8deadSopenharmony_ci        RGB9_E5_EXT                                    0x8C3D
765bd8deadSopenharmony_ci
775bd8deadSopenharmony_ci    Accepted by the <type> parameter of DrawPixels, ReadPixels,
785bd8deadSopenharmony_ci    TexImage1D, TexImage2D, GetTexImage, TexImage3D, TexSubImage1D,
795bd8deadSopenharmony_ci    TexSubImage2D, TexSubImage3D, GetHistogram, GetMinmax,
805bd8deadSopenharmony_ci    ConvolutionFilter1D, ConvolutionFilter2D, ConvolutionFilter3D,
815bd8deadSopenharmony_ci    GetConvolutionFilter, SeparableFilter2D, GetSeparableFilter,
825bd8deadSopenharmony_ci    ColorTable, ColorSubTable, and GetColorTable:
835bd8deadSopenharmony_ci
845bd8deadSopenharmony_ci        UNSIGNED_INT_5_9_9_9_REV_EXT                  0x8C3E
855bd8deadSopenharmony_ci
865bd8deadSopenharmony_ci    Accepted by the <pname> parameter of GetTexLevelParameterfv and
875bd8deadSopenharmony_ci    GetTexLevelParameteriv:
885bd8deadSopenharmony_ci
895bd8deadSopenharmony_ci        TEXTURE_SHARED_SIZE_EXT                        0x8C3F
905bd8deadSopenharmony_ci
915bd8deadSopenharmony_ciAdditions to Chapter 2 of the 2.0 Specification (OpenGL Operation)
925bd8deadSopenharmony_ci
935bd8deadSopenharmony_ci    None
945bd8deadSopenharmony_ci
955bd8deadSopenharmony_ciAdditions to Chapter 3 of the 2.0 Specification (Rasterization)
965bd8deadSopenharmony_ci
975bd8deadSopenharmony_ci -- Section 3.6.4, Rasterization of Pixel Rectangles
985bd8deadSopenharmony_ci
995bd8deadSopenharmony_ci    Add a new row to Table 3.5 (page 128):
1005bd8deadSopenharmony_ci
1015bd8deadSopenharmony_ci        type Parameter                 Corresponding  Special
1025bd8deadSopenharmony_ci        Token Name                     GL Data Type   Interpretation
1035bd8deadSopenharmony_ci        -----------------------------  -------------  --------------
1045bd8deadSopenharmony_ci        UNSIGNED_INT_5_9_9_9_REV_EXT   uint           yes
1055bd8deadSopenharmony_ci
1065bd8deadSopenharmony_ci    Add a new row to table 3.8: Packed pixel formats (page 132):
1075bd8deadSopenharmony_ci
1085bd8deadSopenharmony_ci        type Parameter                 GL Data  Number of   Matching
1095bd8deadSopenharmony_ci        Token Name                     Type     Components  Pixel Formats
1105bd8deadSopenharmony_ci        -----------------------------  -------  ----------  -------------
1115bd8deadSopenharmony_ci        UNSIGNED_INT_5_9_9_9_REV_EXT   uint     4           RGB
1125bd8deadSopenharmony_ci
1135bd8deadSopenharmony_ci    Add a new entry to table 3.11: UNSIGNED_INT formats (page 134):
1145bd8deadSopenharmony_ci
1155bd8deadSopenharmony_ci        UNSIGNED_INT_5_9_9_9_REV_EXT:
1165bd8deadSopenharmony_ci
1175bd8deadSopenharmony_ci        31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
1185bd8deadSopenharmony_ci        +-------------+--------------------------+---------------------------+--------------------------+
1195bd8deadSopenharmony_ci        |  4th        |          3rd             |        2nd                |           1st            |
1205bd8deadSopenharmony_ci        +-------------+--------------------------+---------------------------+--------------------------+
1215bd8deadSopenharmony_ci
1225bd8deadSopenharmony_ci    Add to the end of the 2nd paragraph starting "Pixels are draw using":
1235bd8deadSopenharmony_ci
1245bd8deadSopenharmony_ci    "If type is UNSIGNED_INT_5_9_9_9_REV_EXT and format is not RGB then
1255bd8deadSopenharmony_ci    the error INVALID_ENUM occurs."
1265bd8deadSopenharmony_ci
1275bd8deadSopenharmony_ci    Add UNSIGNED_INT_5_9_9_9_REV_EXT to the list of packed formats in
1285bd8deadSopenharmony_ci    the 10th paragraph after the "Packing" subsection (page 130).
1295bd8deadSopenharmony_ci
1305bd8deadSopenharmony_ci    Add before the 3rd paragraph (page 135, starting "Calling DrawPixels
1315bd8deadSopenharmony_ci    with a type of BITMAP...") from the end of the "Packing" subsection:
1325bd8deadSopenharmony_ci
1335bd8deadSopenharmony_ci    "Calling DrawPixels with a type of UNSIGNED_INT_5_9_9_9_REV_EXT and
1345bd8deadSopenharmony_ci    format of RGB is a special case in which the data are a series of GL
1355bd8deadSopenharmony_ci    uint values.  Each uint value specifies 4 packed components as shown
1365bd8deadSopenharmony_ci    in table 3.11.  The 1st, 2nd, 3rd, and 4th components are called
1375bd8deadSopenharmony_ci    p_red, p_green, p_blue, and p_exp respectively and are treated as
1385bd8deadSopenharmony_ci    unsigned integers.  These are then used to compute floating-point
1395bd8deadSopenharmony_ci    RGB components (ignoring the "Conversion to floating-point" section
1405bd8deadSopenharmony_ci    below in this case) as follows:
1415bd8deadSopenharmony_ci
1425bd8deadSopenharmony_ci       red   = p_red   * 2^(p_exp - B - N)
1435bd8deadSopenharmony_ci       green = p_green * 2^(p_exp - B - N)
1445bd8deadSopenharmony_ci       blue  = p_blue  * 2^(p_exp - B - N)
1455bd8deadSopenharmony_ci
1465bd8deadSopenharmony_ci    where B is 15 (the exponent bias) and N is 9 (the number of mantissa
1475bd8deadSopenharmony_ci    bits)."
1485bd8deadSopenharmony_ci
1495bd8deadSopenharmony_ci -- Section 3.8.1, Texture Image Specification:
1505bd8deadSopenharmony_ci
1515bd8deadSopenharmony_ci    "Alternatively if the internalformat is RGB9_E5_EXT, the red, green,
1525bd8deadSopenharmony_ci    and blue bits are converted to a shared exponent format according
1535bd8deadSopenharmony_ci    to the following procedure:
1545bd8deadSopenharmony_ci
1555bd8deadSopenharmony_ci    Components red, green, and blue are first clamped (in the process,
1565bd8deadSopenharmony_ci    mapping NaN to zero) so:
1575bd8deadSopenharmony_ci
1585bd8deadSopenharmony_ci        red_c   = max(0, min(sharedexp_max, red))
1595bd8deadSopenharmony_ci        green_c = max(0, min(sharedexp_max, green))
1605bd8deadSopenharmony_ci        blue_c  = max(0, min(sharedexp_max, blue))
1615bd8deadSopenharmony_ci
1625bd8deadSopenharmony_ci    where sharedexp_max is (2^N-1)/2^N * 2^(Emax-B), N is the number
1635bd8deadSopenharmony_ci    of mantissa bits per component, Emax is the maximum allowed biased
1645bd8deadSopenharmony_ci    exponent value (careful: not necessarily 2^E-1 when E is the number of
1655bd8deadSopenharmony_ci    exponent bits), bits, and B is the exponent bias.  For the RGB9_E5_EXT
1665bd8deadSopenharmony_ci    format, N=9, Emax=31, and B=15.
1675bd8deadSopenharmony_ci
1685bd8deadSopenharmony_ci    The largest clamped component, max_c, is determined:
1695bd8deadSopenharmony_ci
1705bd8deadSopenharmony_ci        max_c = max(red_c, green_c, blue_c)
1715bd8deadSopenharmony_ci
1725bd8deadSopenharmony_ci    A preliminary shared exponent is computed:
1735bd8deadSopenharmony_ci
1745bd8deadSopenharmony_ci        exp_shared_p = max(-B-1, floor(log2(max_c))) + 1 + B
1755bd8deadSopenharmony_ci
1765bd8deadSopenharmony_ci    A refined shared exponent is then computed as:
1775bd8deadSopenharmony_ci
1785bd8deadSopenharmony_ci        max_s   = floor(max_c   / 2^(exp_shared_p - B - N) + 0.5)
1795bd8deadSopenharmony_ci
1805bd8deadSopenharmony_ci                     { exp_shared_p,    0 <= max_s <  2^N
1815bd8deadSopenharmony_ci        exp_shared = {
1825bd8deadSopenharmony_ci                     { exp_shared_p+1,       max_s == 2^N
1835bd8deadSopenharmony_ci
1845bd8deadSopenharmony_ci    These integers values in the range 0 to 2^N-1 are then computed:
1855bd8deadSopenharmony_ci
1865bd8deadSopenharmony_ci        red_s   = floor(red_c   / 2^(exp_shared - B - N) + 0.5)
1875bd8deadSopenharmony_ci        green_s = floor(green_c / 2^(exp_shared - B - N) + 0.5)
1885bd8deadSopenharmony_ci        blue_s  = floor(blue_c  / 2^(exp_shared - B - N) + 0.5)
1895bd8deadSopenharmony_ci
1905bd8deadSopenharmony_ci    Then red_s, green_s, and blue_s are stored along with exp_shared in
1915bd8deadSopenharmony_ci    the red, green, blue, and shared bits respectively of the texture
1925bd8deadSopenharmony_ci    image.
1935bd8deadSopenharmony_ci
1945bd8deadSopenharmony_ci    An implementation accepting pixel data of type
1955bd8deadSopenharmony_ci    UNSIGNED_INT_5_9_9_9_REV_EXT with a format of RGB is allowed to store
1965bd8deadSopenharmony_ci    the components "as is" if the implementation can determine the current
1975bd8deadSopenharmony_ci    pixel transfer state act as an identity transform on the components."
1985bd8deadSopenharmony_ci
1995bd8deadSopenharmony_ci    Add a new row and the "shared bits" column (blank for all existing
2005bd8deadSopenharmony_ci    rows) to Table 3.16 (page 154).
2015bd8deadSopenharmony_ci
2025bd8deadSopenharmony_ci        Sized                  Base             R     G     B     A     L     I     D     shared
2035bd8deadSopenharmony_ci        Internal Format        Internal Format  bits  bits  bits  bits  bits  bits  bits  bits
2045bd8deadSopenharmony_ci        ---------------------  ---------------  ----  ----  ----  ----  ----  ----  ----  ------
2055bd8deadSopenharmony_ci        RGB9_E5_EXT            RGB              9     9     9                             5
2065bd8deadSopenharmony_ci
2075bd8deadSopenharmony_ci -- Section 3.8.x, Shared Exponent Texture Color Conversion
2085bd8deadSopenharmony_ci
2095bd8deadSopenharmony_ci    Insert this section AFTER section 3.8.14 Texture Comparison Modes
2105bd8deadSopenharmony_ci    and BEFORE section 3.8.15 Texture Application (and after the "sRGB
2115bd8deadSopenharmony_ci    Texture Color Conversion" if EXT_texture_sRGB is supported).
2125bd8deadSopenharmony_ci
2135bd8deadSopenharmony_ci    "If the currently bound texture's internal format is RGB9_E5_EXT, the
2145bd8deadSopenharmony_ci    red, green, blue, and shared bits are converted to color components
2155bd8deadSopenharmony_ci    (prior to filtering) using the following shared exponent decoding.
2165bd8deadSopenharmony_ci
2175bd8deadSopenharmony_ci    The components red_s, green_s, blue_s, and exp_shared values (see
2185bd8deadSopenharmony_ci    section 3.8.1) are treated as unsigned integers and are converted
2195bd8deadSopenharmony_ci    to red, green, blue as follows:
2205bd8deadSopenharmony_ci
2215bd8deadSopenharmony_ci       red   = red_s   * 2^(exp_shared - B)
2225bd8deadSopenharmony_ci       green = green_s * 2^(exp_shared - B)
2235bd8deadSopenharmony_ci       blue  = blue_s  * 2^(exp_shared - B)"
2245bd8deadSopenharmony_ci
2255bd8deadSopenharmony_ciAdditions to Chapter 4 of the 2.0 Specification (Per-Fragment Operations
2265bd8deadSopenharmony_ciand the Frame Buffer)
2275bd8deadSopenharmony_ci
2285bd8deadSopenharmony_ci -- Section 4.3.2, Reading Pixels
2295bd8deadSopenharmony_ci
2305bd8deadSopenharmony_ci    Add a row to table 4.7 (page 224);
2315bd8deadSopenharmony_ci
2325bd8deadSopenharmony_ci                                                 Component
2335bd8deadSopenharmony_ci    type Parameter                 GL Data Type  Conversion Formula
2345bd8deadSopenharmony_ci    -----------------------------  ------------  ------------------
2355bd8deadSopenharmony_ci    UNSIGNED_INT_5_9_9_9_REV_EXT   uint          special
2365bd8deadSopenharmony_ci
2375bd8deadSopenharmony_ci    Replace second paragraph of "Final Conversion" (page 222) to read:
2385bd8deadSopenharmony_ci
2395bd8deadSopenharmony_ci    For an RGBA color, if <type> is not FLOAT or
2405bd8deadSopenharmony_ci    UNSIGNED_INT_5_9_9_9_REV_EXT, or if the CLAMP_READ_COLOR_ARB is
2415bd8deadSopenharmony_ci    TRUE, or CLAMP_READ_COLOR_ARB is FIXED_ONLY_ARB and the selected
2425bd8deadSopenharmony_ci    color (or texture) buffer is a fixed-point buffer, each component
2435bd8deadSopenharmony_ci    is first clamped to [0,1].  Then the appropriate conversion formula
2445bd8deadSopenharmony_ci    from table 4.7 is applied the component.
2455bd8deadSopenharmony_ci
2465bd8deadSopenharmony_ci    In the special case when calling ReadPixels with a type of
2475bd8deadSopenharmony_ci    UNSIGNED_INT_5_9_9_9_REV_EXT and format of RGB, the conversion
2485bd8deadSopenharmony_ci    is done as follows:  The returned data are packed into a series of
2495bd8deadSopenharmony_ci    GL uint values. The red, green, and blue components are converted
2505bd8deadSopenharmony_ci    to red_s, green_s, blue_s, and exp_shared integers as described in
2515bd8deadSopenharmony_ci    section 3.8.1 when the internalformat is RGB9_E5_EXT.  The red_s,
2525bd8deadSopenharmony_ci    green_s, blue_s, and exp_shared are then packed as the 1st, 2nd,
2535bd8deadSopenharmony_ci    3rd, and 4th components of the UNSIGNED_INT_5_9_9_9_REV_EXT format
2545bd8deadSopenharmony_ci    as shown in table 3.11."
2555bd8deadSopenharmony_ci
2565bd8deadSopenharmony_ciAdditions to Chapter 5 of the 2.0 Specification (Special Functions)
2575bd8deadSopenharmony_ci
2585bd8deadSopenharmony_ci    None
2595bd8deadSopenharmony_ci
2605bd8deadSopenharmony_ciAdditions to Chapter 6 of the 2.0 Specification (State and State Requests)
2615bd8deadSopenharmony_ci
2625bd8deadSopenharmony_ci -- Section 6.1.3, Enumerated Queries
2635bd8deadSopenharmony_ci
2645bd8deadSopenharmony_ci    Add TEXTURE_SHARED_SIZE_EXT to the list of queries in the first
2655bd8deadSopenharmony_ci    sentence of the fifth paragraph (page 247) so it reads:
2665bd8deadSopenharmony_ci
2675bd8deadSopenharmony_ci    "For texture images with uncompressed internal formats, queries of
2685bd8deadSopenharmony_ci    value of TEXTURE_RED_SIZE, TEXTURE_GREEN_SIZE, TEXTURE_BLUE_SIZE,
2695bd8deadSopenharmony_ci    TEXTURE_ALPHA_SIZE, TEXTURE_LUMINANCE_SIZE, TEXTURE_DEPTH_SIZE,
2705bd8deadSopenharmony_ci    TEXTURE_SHARED_SIZE_EXTT, and TEXTURE_INTENSITY_SIZE return the
2715bd8deadSopenharmony_ci    actual resolutions of the stored image array components, not the
2725bd8deadSopenharmony_ci    resolutions specified when the image array was defined."
2735bd8deadSopenharmony_ci
2745bd8deadSopenharmony_ciAdditions to the OpenGL Shading Language specification
2755bd8deadSopenharmony_ci
2765bd8deadSopenharmony_ci    None
2775bd8deadSopenharmony_ci
2785bd8deadSopenharmony_ciAdditions to the GLX Specification
2795bd8deadSopenharmony_ci
2805bd8deadSopenharmony_ci    None
2815bd8deadSopenharmony_ci
2825bd8deadSopenharmony_ciGLX Protocol
2835bd8deadSopenharmony_ci
2845bd8deadSopenharmony_ci    None.
2855bd8deadSopenharmony_ci
2865bd8deadSopenharmony_ciDependencies on ARB_color_buffer_float
2875bd8deadSopenharmony_ci
2885bd8deadSopenharmony_ci    If ARB_color_buffer_float is not supported, replace this amended
2895bd8deadSopenharmony_ci    sentence from 4.3.2 above
2905bd8deadSopenharmony_ci
2915bd8deadSopenharmony_ci    "For an RGBA color, if <type> is not FLOAT or
2925bd8deadSopenharmony_ci    UNSIGNED_INT_5_9_9_9_REV_EXT, or if the CLAMP_READ_COLOR_ARB is TRUE, or
2935bd8deadSopenharmony_ci    CLAMP_READ_COLOR_ARB is FIXED_ONLY_ARB and the selected color buffer
2945bd8deadSopenharmony_ci    (or texture image for GetTexImage) is a fixed-point buffer (or texture
2955bd8deadSopenharmony_ci    image for GetTexImage), each component is first clamped to [0,1]."
2965bd8deadSopenharmony_ci
2975bd8deadSopenharmony_ci    with
2985bd8deadSopenharmony_ci
2995bd8deadSopenharmony_ci    "For an RGBA color, if <type> is not FLOAT or
3005bd8deadSopenharmony_ci    UNSIGNED_INT_5_9_9_9_REV_EXT and the selected color buffer (or
3015bd8deadSopenharmony_ci    texture image for GetTexImage) is a fixed-point buffer (or texture
3025bd8deadSopenharmony_ci    image for GetTexImage), each component is first clamped to [0,1]."
3035bd8deadSopenharmony_ci
3045bd8deadSopenharmony_ciDependencies on EXT_framebuffer_object
3055bd8deadSopenharmony_ci
3065bd8deadSopenharmony_ci    If EXT_framebuffer_object is not supported, then
3075bd8deadSopenharmony_ci    RenderbufferStorageEXT is not supported and the RGB9_E5_EXT
3085bd8deadSopenharmony_ci    internalformat is therefore not supported by RenderbufferStorageEXT.
3095bd8deadSopenharmony_ci
3105bd8deadSopenharmony_ciErrors
3115bd8deadSopenharmony_ci
3125bd8deadSopenharmony_ci    Relaxation of INVALID_ENUM errors
3135bd8deadSopenharmony_ci    ---------------------------------
3145bd8deadSopenharmony_ci
3155bd8deadSopenharmony_ci    TexImage1D, TexImage2D, TexImage3D, CopyTexImage1D, CopyTexImage2D,
3165bd8deadSopenharmony_ci    and RenderbufferStorageEXT accept the new RGB9_E5_EXT token for
3175bd8deadSopenharmony_ci    internalformat.
3185bd8deadSopenharmony_ci
3195bd8deadSopenharmony_ci    DrawPixels, ReadPixels, TexImage1D, TexImage2D, GetTexImage,
3205bd8deadSopenharmony_ci    TexImage3D, TexSubImage1D, TexSubImage2D, TexSubImage3D,
3215bd8deadSopenharmony_ci    GetHistogram, GetMinmax, ConvolutionFilter1D, ConvolutionFilter2D,
3225bd8deadSopenharmony_ci    ConvolutionFilter3D, GetConvolutionFilter, SeparableFilter2D,
3235bd8deadSopenharmony_ci    GetSeparableFilter, ColorTable, ColorSubTable, and GetColorTable
3245bd8deadSopenharmony_ci    accept the new UNSIGNED_INT_5_9_9_9_REV_EXT token for type.
3255bd8deadSopenharmony_ci
3265bd8deadSopenharmony_ci    GetTexLevelParameterfv and GetTexLevelParameteriv accept the new
3275bd8deadSopenharmony_ci    TEXTURE_SHARED_SIZE_EXT token for <pname>.
3285bd8deadSopenharmony_ci
3295bd8deadSopenharmony_ci    New errors
3305bd8deadSopenharmony_ci    ----------
3315bd8deadSopenharmony_ci
3325bd8deadSopenharmony_ci    INVALID_OPERATION is generated by DrawPixels, ReadPixels, TexImage1D,
3335bd8deadSopenharmony_ci    TexImage2D, GetTexImage, TexImage3D, TexSubImage1D, TexSubImage2D,
3345bd8deadSopenharmony_ci    TexSubImage3D, GetHistogram, GetMinmax, ConvolutionFilter1D,
3355bd8deadSopenharmony_ci    ConvolutionFilter2D, ConvolutionFilter3D, GetConvolutionFilter,
3365bd8deadSopenharmony_ci    SeparableFilter2D, GetSeparableFilter, ColorTable, ColorSubTable,
3375bd8deadSopenharmony_ci    and GetColorTable if <type> is UNSIGNED_INT_5_9_9_9_REV_EXT
3385bd8deadSopenharmony_ci    and <format> is not RGB.
3395bd8deadSopenharmony_ci
3405bd8deadSopenharmony_ciNew State
3415bd8deadSopenharmony_ci
3425bd8deadSopenharmony_ci    In table 6.17, Textures (page 278), increment the 42 in "n x Z42*"
3435bd8deadSopenharmony_ci    by 1 for the RGB9_E5_EXT format.
3445bd8deadSopenharmony_ci
3455bd8deadSopenharmony_ci    [NOTE: The OpenGL 2.0 specification actually should read "n x Z48*"
3465bd8deadSopenharmony_ci    because of the 6 generic compressed internal formats in table 3.18.]
3475bd8deadSopenharmony_ci    
3485bd8deadSopenharmony_ci    Add the following entry to table 6.17:
3495bd8deadSopenharmony_ci
3505bd8deadSopenharmony_ciGet Value                Type    Get Command            Value   Description                           Sec.  Attribute
3515bd8deadSopenharmony_ci-----------------------  ------  --------------------  -------  ------------------------------------  ----  ---------
3525bd8deadSopenharmony_ciTEXTURE_SHARED_SIZE_EXT  n x Z+  GetTexLevelParameter  0        xD texture image i's shared exponent  3.8   -
3535bd8deadSopenharmony_ci                                                                field size
3545bd8deadSopenharmony_ci
3555bd8deadSopenharmony_ciNew Implementation Dependent State
3565bd8deadSopenharmony_ci
3575bd8deadSopenharmony_ci    None
3585bd8deadSopenharmony_ci
3595bd8deadSopenharmony_ciAppendix
3605bd8deadSopenharmony_ci
3615bd8deadSopenharmony_ci    This source code provides ANSI C routines.  It assumes the C "float"
3625bd8deadSopenharmony_ci    data type is stored with the IEEE 754 32-bit floating-point format.
3635bd8deadSopenharmony_ci    Make sure you define __LITTLE_ENDIAN or __BIG_ENDIAN appropriate
3645bd8deadSopenharmony_ci    for your target system.
3655bd8deadSopenharmony_ci
3665bd8deadSopenharmony_ci    XXX: code below not tested on big-endian platform...
3675bd8deadSopenharmony_ci
3685bd8deadSopenharmony_ci------------------- start of source code ------------------------
3695bd8deadSopenharmony_ci
3705bd8deadSopenharmony_ci#include <assert.h>
3715bd8deadSopenharmony_ci#include <math.h>
3725bd8deadSopenharmony_ci#include <stdio.h>
3735bd8deadSopenharmony_ci#include <stdlib.h>
3745bd8deadSopenharmony_ci
3755bd8deadSopenharmony_ci#define __LITTLE_ENDIAN  1
3765bd8deadSopenharmony_ci#define __BIG_ENDIAN     2
3775bd8deadSopenharmony_ci
3785bd8deadSopenharmony_ci#ifdef _WIN32
3795bd8deadSopenharmony_ci#define __BYTE_ORDER __LITTLE_ENDIAN
3805bd8deadSopenharmony_ci#endif
3815bd8deadSopenharmony_ci
3825bd8deadSopenharmony_ci#define RGB9E5_EXPONENT_BITS          5
3835bd8deadSopenharmony_ci#define RGB9E5_MANTISSA_BITS          9
3845bd8deadSopenharmony_ci#define RGB9E5_EXP_BIAS               15
3855bd8deadSopenharmony_ci#define RGB9E5_MAX_VALID_BIASED_EXP   31
3865bd8deadSopenharmony_ci
3875bd8deadSopenharmony_ci#define MAX_RGB9E5_EXP               (RGB9E5_MAX_VALID_BIASED_EXP - RGB9E5_EXP_BIAS)
3885bd8deadSopenharmony_ci#define RGB9E5_MANTISSA_VALUES       (1<<RGB9E5_MANTISSA_BITS)
3895bd8deadSopenharmony_ci#define MAX_RGB9E5_MANTISSA          (RGB9E5_MANTISSA_VALUES-1)
3905bd8deadSopenharmony_ci#define MAX_RGB9E5                   (((float)MAX_RGB9E5_MANTISSA)/RGB9E5_MANTISSA_VALUES * (1<<MAX_RGB9E5_EXP))
3915bd8deadSopenharmony_ci#define EPSILON_RGB9E5               ((1.0/RGB9E5_MANTISSA_VALUES) / (1<<RGB9E5_EXP_BIAS))
3925bd8deadSopenharmony_ci
3935bd8deadSopenharmony_citypedef struct {
3945bd8deadSopenharmony_ci#ifdef __BYTE_ORDER
3955bd8deadSopenharmony_ci#if __BYTE_ORDER == __BIG_ENDIAN
3965bd8deadSopenharmony_ci  unsigned int negative:1;
3975bd8deadSopenharmony_ci  unsigned int biasedexponent:8;
3985bd8deadSopenharmony_ci  unsigned int mantissa:23;
3995bd8deadSopenharmony_ci#elif __BYTE_ORDER == __LITTLE_ENDIAN
4005bd8deadSopenharmony_ci  unsigned int mantissa:23;
4015bd8deadSopenharmony_ci  unsigned int biasedexponent:8;
4025bd8deadSopenharmony_ci  unsigned int negative:1;
4035bd8deadSopenharmony_ci#endif
4045bd8deadSopenharmony_ci#endif
4055bd8deadSopenharmony_ci} BitsOfIEEE754;
4065bd8deadSopenharmony_ci
4075bd8deadSopenharmony_citypedef union {
4085bd8deadSopenharmony_ci  unsigned int raw;
4095bd8deadSopenharmony_ci  float value;
4105bd8deadSopenharmony_ci  BitsOfIEEE754 field;
4115bd8deadSopenharmony_ci} float754;
4125bd8deadSopenharmony_ci
4135bd8deadSopenharmony_citypedef struct {
4145bd8deadSopenharmony_ci#ifdef __BYTE_ORDER
4155bd8deadSopenharmony_ci#if __BYTE_ORDER == __BIG_ENDIAN
4165bd8deadSopenharmony_ci  unsigned int biasedexponent:RGB9E5_EXPONENT_BITS;
4175bd8deadSopenharmony_ci  unsigned int b:RGB9E5_MANTISSA_BITS;
4185bd8deadSopenharmony_ci  unsigned int g:RGB9E5_MANTISSA_BITS;
4195bd8deadSopenharmony_ci  unsigned int r:RGB9E5_MANTISSA_BITS;
4205bd8deadSopenharmony_ci#elif __BYTE_ORDER == __LITTLE_ENDIAN
4215bd8deadSopenharmony_ci  unsigned int r:RGB9E5_MANTISSA_BITS;
4225bd8deadSopenharmony_ci  unsigned int g:RGB9E5_MANTISSA_BITS;
4235bd8deadSopenharmony_ci  unsigned int b:RGB9E5_MANTISSA_BITS;
4245bd8deadSopenharmony_ci  unsigned int biasedexponent:RGB9E5_EXPONENT_BITS;
4255bd8deadSopenharmony_ci#endif
4265bd8deadSopenharmony_ci#endif
4275bd8deadSopenharmony_ci} BitsOfRGB9E5;
4285bd8deadSopenharmony_ci
4295bd8deadSopenharmony_citypedef union {
4305bd8deadSopenharmony_ci  unsigned int raw;
4315bd8deadSopenharmony_ci  BitsOfRGB9E5 field;
4325bd8deadSopenharmony_ci} rgb9e5;
4335bd8deadSopenharmony_ci
4345bd8deadSopenharmony_cifloat ClampRange_for_rgb9e5(float x)
4355bd8deadSopenharmony_ci{
4365bd8deadSopenharmony_ci  if (x > 0.0) {
4375bd8deadSopenharmony_ci    if (x >= MAX_RGB9E5) {
4385bd8deadSopenharmony_ci      return MAX_RGB9E5;
4395bd8deadSopenharmony_ci    } else {
4405bd8deadSopenharmony_ci      return x;
4415bd8deadSopenharmony_ci    }
4425bd8deadSopenharmony_ci  } else {
4435bd8deadSopenharmony_ci    /* NaN gets here too since comparisons with NaN always fail! */
4445bd8deadSopenharmony_ci    return 0.0;
4455bd8deadSopenharmony_ci  }
4465bd8deadSopenharmony_ci}
4475bd8deadSopenharmony_ci
4485bd8deadSopenharmony_cifloat MaxOf3(float x, float y, float z)
4495bd8deadSopenharmony_ci{
4505bd8deadSopenharmony_ci  if (x > y) {
4515bd8deadSopenharmony_ci    if (x > z) {
4525bd8deadSopenharmony_ci      return x;
4535bd8deadSopenharmony_ci    } else {
4545bd8deadSopenharmony_ci      return z;
4555bd8deadSopenharmony_ci    }
4565bd8deadSopenharmony_ci  } else {
4575bd8deadSopenharmony_ci    if (y > z) {
4585bd8deadSopenharmony_ci      return y;
4595bd8deadSopenharmony_ci    } else {
4605bd8deadSopenharmony_ci      return z;
4615bd8deadSopenharmony_ci    }
4625bd8deadSopenharmony_ci  }
4635bd8deadSopenharmony_ci}
4645bd8deadSopenharmony_ci
4655bd8deadSopenharmony_ci/* Ok, FloorLog2 is not correct for the denorm and zero values, but we
4665bd8deadSopenharmony_ci   are going to do a max of this value with the minimum rgb9e5 exponent
4675bd8deadSopenharmony_ci   that will hide these problem cases. */
4685bd8deadSopenharmony_ciint FloorLog2(float x)
4695bd8deadSopenharmony_ci{
4705bd8deadSopenharmony_ci  float754 f;
4715bd8deadSopenharmony_ci
4725bd8deadSopenharmony_ci  f.value = x;
4735bd8deadSopenharmony_ci  return (f.field.biasedexponent - 127);
4745bd8deadSopenharmony_ci}
4755bd8deadSopenharmony_ci
4765bd8deadSopenharmony_ciint Max(int x, int y)
4775bd8deadSopenharmony_ci{
4785bd8deadSopenharmony_ci  if (x > y) {
4795bd8deadSopenharmony_ci    return x;
4805bd8deadSopenharmony_ci  } else {
4815bd8deadSopenharmony_ci    return y;
4825bd8deadSopenharmony_ci  }
4835bd8deadSopenharmony_ci}
4845bd8deadSopenharmony_ci
4855bd8deadSopenharmony_cirgb9e5 float3_to_rgb9e5(const float rgb[3])
4865bd8deadSopenharmony_ci{
4875bd8deadSopenharmony_ci  rgb9e5 retval;
4885bd8deadSopenharmony_ci  float maxrgb;
4895bd8deadSopenharmony_ci  int rm, gm, bm;
4905bd8deadSopenharmony_ci  float rc, gc, bc;
4915bd8deadSopenharmony_ci  int exp_shared;
4925bd8deadSopenharmony_ci  double denom;
4935bd8deadSopenharmony_ci
4945bd8deadSopenharmony_ci  rc = ClampRange_for_rgb9e5(rgb[0]);
4955bd8deadSopenharmony_ci  gc = ClampRange_for_rgb9e5(rgb[1]);
4965bd8deadSopenharmony_ci  bc = ClampRange_for_rgb9e5(rgb[2]);
4975bd8deadSopenharmony_ci
4985bd8deadSopenharmony_ci  maxrgb = MaxOf3(rc, gc, bc);
4995bd8deadSopenharmony_ci  exp_shared = Max(-RGB9E5_EXP_BIAS-1, FloorLog2(maxrgb)) + 1 + RGB9E5_EXP_BIAS;
5005bd8deadSopenharmony_ci  assert(exp_shared <= RGB9E5_MAX_VALID_BIASED_EXP);
5015bd8deadSopenharmony_ci  assert(exp_shared >= 0);
5025bd8deadSopenharmony_ci  /* This pow function could be replaced by a table. */
5035bd8deadSopenharmony_ci  denom = pow(2, exp_shared - RGB9E5_EXP_BIAS - RGB9E5_MANTISSA_BITS);
5045bd8deadSopenharmony_ci
5055bd8deadSopenharmony_ci  maxm = (int) floor(maxrgb / denom + 0.5);
5065bd8deadSopenharmony_ci  if (maxm == MAX_RGB9E5_MANTISSA+1) {
5075bd8deadSopenharmony_ci    denom *= 2;
5085bd8deadSopenharmony_ci    exp_shared += 1;
5095bd8deadSopenharmony_ci    assert(exp_shared <= RGB9E5_MAX_VALID_BIASED_EXP);
5105bd8deadSopenharmony_ci  } else {
5115bd8deadSopenharmony_ci    assert(maxm <= MAX_RGB9E5_MANTISSA);
5125bd8deadSopenharmony_ci  }
5135bd8deadSopenharmony_ci
5145bd8deadSopenharmony_ci  rm = (int) floor(rc / denom + 0.5);
5155bd8deadSopenharmony_ci  gm = (int) floor(gc / denom + 0.5);
5165bd8deadSopenharmony_ci  bm = (int) floor(bc / denom + 0.5);
5175bd8deadSopenharmony_ci
5185bd8deadSopenharmony_ci  assert(rm <= MAX_RGB9E5_MANTISSA);
5195bd8deadSopenharmony_ci  assert(gm <= MAX_RGB9E5_MANTISSA);
5205bd8deadSopenharmony_ci  assert(bm <= MAX_RGB9E5_MANTISSA);
5215bd8deadSopenharmony_ci  assert(rm >= 0);
5225bd8deadSopenharmony_ci  assert(gm >= 0);
5235bd8deadSopenharmony_ci  assert(bm >= 0);
5245bd8deadSopenharmony_ci
5255bd8deadSopenharmony_ci  retval.field.r = rm;
5265bd8deadSopenharmony_ci  retval.field.g = gm;
5275bd8deadSopenharmony_ci  retval.field.b = bm;
5285bd8deadSopenharmony_ci  retval.field.biasedexponent = exp_shared;
5295bd8deadSopenharmony_ci
5305bd8deadSopenharmony_ci  return retval;
5315bd8deadSopenharmony_ci}
5325bd8deadSopenharmony_ci
5335bd8deadSopenharmony_civoid rgb9e5_to_float3(rgb9e5 v, float retval[3])
5345bd8deadSopenharmony_ci{
5355bd8deadSopenharmony_ci  int exponent = v.field.biasedexponent - RGB9E5_EXP_BIAS - RGB9E5_MANTISSA_BITS;
5365bd8deadSopenharmony_ci  float scale = (float) pow(2, exponent);
5375bd8deadSopenharmony_ci
5385bd8deadSopenharmony_ci  retval[0] = v.field.r * scale;
5395bd8deadSopenharmony_ci  retval[1] = v.field.g * scale;
5405bd8deadSopenharmony_ci  retval[2] = v.field.b * scale;
5415bd8deadSopenharmony_ci}
5425bd8deadSopenharmony_ci
5435bd8deadSopenharmony_ci------------------- end of source code ------------------------
5445bd8deadSopenharmony_ci
5455bd8deadSopenharmony_ciIssues
5465bd8deadSopenharmony_ci
5475bd8deadSopenharmony_ci    1)  What should this extension be called?
5485bd8deadSopenharmony_ci
5495bd8deadSopenharmony_ci        RESOLVED: EXT_texture_shared_exponent
5505bd8deadSopenharmony_ci
5515bd8deadSopenharmony_ci        The "EXT_texture" part indicates the extension is in the texture
5525bd8deadSopenharmony_ci        domain and "shared_exponent" indicates the extension is adding
5535bd8deadSopenharmony_ci        a new shared exponent formats.
5545bd8deadSopenharmony_ci
5555bd8deadSopenharmony_ci        EXT_texture_rgb9e5 was considered but there's no precedent for
5565bd8deadSopenharmony_ci        extension names to be so explicit (or cryptic?) about format
5575bd8deadSopenharmony_ci        specifics in the extension name.
5585bd8deadSopenharmony_ci
5595bd8deadSopenharmony_ci    2)  There are many possible encodings for a shared exponent format.
5605bd8deadSopenharmony_ci        Which encoding does this extension specify?
5615bd8deadSopenharmony_ci
5625bd8deadSopenharmony_ci        RESOLVED:  A single 5-bit exponent stored as an unsigned
5635bd8deadSopenharmony_ci        value biased by 15 and three 9-bit mantissas for each of 3
5645bd8deadSopenharmony_ci        components.  There are no sign bits so all three components
5655bd8deadSopenharmony_ci        must be non-negative.  The fractional mantissas assume an implied
5665bd8deadSopenharmony_ci        0 left of the decimal point because having an implied leading
5675bd8deadSopenharmony_ci        1 is inconsistent with sharing the exponent.  Neither Infinity
5685bd8deadSopenharmony_ci        nor Not-a-Number (NaN) are representable in this shared exponent
5695bd8deadSopenharmony_ci        format.
5705bd8deadSopenharmony_ci
5715bd8deadSopenharmony_ci        We chose this format because it closely matches the range and
5725bd8deadSopenharmony_ci        precision of the s10e5 half-precision floating-point described
5735bd8deadSopenharmony_ci        in the ARB_half_float_pixel and ARB_texture_float specifications.
5745bd8deadSopenharmony_ci
5755bd8deadSopenharmony_ci    3)  Why not an 8-bit shared exponent?
5765bd8deadSopenharmony_ci
5775bd8deadSopenharmony_ci        RESOLVED:  Greg Ward's RGBE shared exponent encoding uses an
5785bd8deadSopenharmony_ci        8-bit exponent (same as a single-precision IEEE value) but we
5795bd8deadSopenharmony_ci        believe the rgb9e5 is more generally useful than rgb8e8.
5805bd8deadSopenharmony_ci
5815bd8deadSopenharmony_ci        An 8-bit exponent provides far more range than is typically
5825bd8deadSopenharmony_ci        required for graphics applications.  However, an extra bit
5835bd8deadSopenharmony_ci        of precision for each component helps in situations where a
5845bd8deadSopenharmony_ci        high magnitude component dominates a low magnitude component.
5855bd8deadSopenharmony_ci        Having an 8-bit shared exponent and 8-bit mantissas are amenable
5865bd8deadSopenharmony_ci        to CPUs that facilitate 8-bit sized reads and writes over non-byte
5875bd8deadSopenharmony_ci        aligned fields, but GPUs do not suffer from this issue.
5885bd8deadSopenharmony_ci
5895bd8deadSopenharmony_ci        Indeed GPUs with s10e5 texture filtering can use that same
5905bd8deadSopenharmony_ci        filtering hardware for rgb9e5 textures.
5915bd8deadSopenharmony_ci
5925bd8deadSopenharmony_ci        However, future extensions could add other shared exponent formats
5935bd8deadSopenharmony_ci        so we name the tokens to indicate the 
5945bd8deadSopenharmony_ci
5955bd8deadSopenharmony_ci    4)  Should there be an external format and type for rgb9e5?
5965bd8deadSopenharmony_ci
5975bd8deadSopenharmony_ci        RESOLVED:  Yes, hence the external format GL_RGB9_E5_EXT and
5985bd8deadSopenharmony_ci        type GL_UNSIGNED_INT_5_9_9_9_REV_EXT.  This makes it fast to load
5995bd8deadSopenharmony_ci        GL_RGB9_E5_EXT textures without any translation by the driver.
6005bd8deadSopenharmony_ci
6015bd8deadSopenharmony_ci    5)  Why is the exponent bias 15?
6025bd8deadSopenharmony_ci
6035bd8deadSopenharmony_ci        RESOLVED:  The best technical choice of 15.  Hopefully, this
6045bd8deadSopenharmony_ci        discussion sheds insight into the numerics of the shared exponent
6055bd8deadSopenharmony_ci        format in general.
6065bd8deadSopenharmony_ci
6075bd8deadSopenharmony_ci        With conventional floating-point formats, the number corresponding
6085bd8deadSopenharmony_ci        to a finite, non-denorm, non-zero floating-point value is
6095bd8deadSopenharmony_ci
6105bd8deadSopenharmony_ci            value = -1^sgn * 2^(exp-bias) * 1.frac
6115bd8deadSopenharmony_ci
6125bd8deadSopenharmony_ci        where sgn is the sign bit (so 1 for sgn negative because -1^-1
6135bd8deadSopenharmony_ci        == -1 and 0 means positive because -1^0 == +1), exp is an
6145bd8deadSopenharmony_ci        (unsigned) BIASED exponent and bias is the format's constant bias
6155bd8deadSopenharmony_ci        to subtract to get the unbiased (possibly negative) exponent;
6165bd8deadSopenharmony_ci        and frac is the fractional portion of the mantissa with the
6175bd8deadSopenharmony_ci        "1." indicating an implied leading 1.
6185bd8deadSopenharmony_ci
6195bd8deadSopenharmony_ci        An exp value of zero indicates so-called denormalized values
6205bd8deadSopenharmony_ci        (denorms).  With conventional floating-point formats, the number
6215bd8deadSopenharmony_ci        corresponding to a denorm floating-point value is
6225bd8deadSopenharmony_ci
6235bd8deadSopenharmony_ci            value = -1^sgn * 2^(exp-bias+1) * 0.frac
6245bd8deadSopenharmony_ci
6255bd8deadSopenharmony_ci        where the only difference between the denorm and non-denorm case
6265bd8deadSopenharmony_ci        is the bias is one greater in the denorm case and the implied
6275bd8deadSopenharmony_ci        leading digit is a zero instead of a one.
6285bd8deadSopenharmony_ci
6295bd8deadSopenharmony_ci        Ideally, the rgb9e5 shared exponent format would represent
6305bd8deadSopenharmony_ci        roughly the same range of finite values as the s10e5 format
6315bd8deadSopenharmony_ci        specified by the ARB_texture_float extension.  The s10e5 format
6325bd8deadSopenharmony_ci        has an exponent bias of 15.
6335bd8deadSopenharmony_ci
6345bd8deadSopenharmony_ci        While conventional floating-point formats cleverly use an implied
6355bd8deadSopenharmony_ci        leading 1 for non-denorm, finite values, a shared exponent format
6365bd8deadSopenharmony_ci        cannot use an implied leading 1 because each component may have
6375bd8deadSopenharmony_ci        a different magnitude for its most-significant binary digit.
6385bd8deadSopenharmony_ci        The implied leading 1 assumes we have the flexibility to adjust
6395bd8deadSopenharmony_ci        the mantissa and exponent together to ensure an implied leading 1.
6405bd8deadSopenharmony_ci        That flexibility is not present when the exponent is shared.
6415bd8deadSopenharmony_ci
6425bd8deadSopenharmony_ci        So the rgb9e5 format cannot assume an implied leading one.
6435bd8deadSopenharmony_ci        Instead, an implied leading zero is assumed (much like the
6445bd8deadSopenharmony_ci        conventional denorm case).
6455bd8deadSopenharmony_ci
6465bd8deadSopenharmony_ci        The rgb9e5 format eliminate support representing negative,
6475bd8deadSopenharmony_ci        Infinite, not-a-number (NaN), and denorm values.
6485bd8deadSopenharmony_ci
6495bd8deadSopenharmony_ci        We've already discussed how the BIASED zero exponent is used to
6505bd8deadSopenharmony_ci        encode denorm values (and zero) with conventional floating-point
6515bd8deadSopenharmony_ci        formats.  The largest BIASED exponent (31 for s10e5, 127 for
6525bd8deadSopenharmony_ci        s23e8) for conventional floating-point fomats indicates Infinity
6535bd8deadSopenharmony_ci        and NaN values.  This means these two extrema exponent values are
6545bd8deadSopenharmony_ci        "off limits" for run-of-the-mill values.
6555bd8deadSopenharmony_ci
6565bd8deadSopenharmony_ci        The numbers corresponding to a shared exponent format value are:
6575bd8deadSopenharmony_ci
6585bd8deadSopenharmony_ci            value_r = 2^(exp-bias) * 0.frac_r
6595bd8deadSopenharmony_ci            value_g = 2^(exp-bias) * 0.frac_g
6605bd8deadSopenharmony_ci            value_b = 2^(exp-bias) * 0.frac_b
6615bd8deadSopenharmony_ci
6625bd8deadSopenharmony_ci        where there is no sgn since all values are non-negative, exp is
6635bd8deadSopenharmony_ci        the (unsigned) BIASED exponent and bias is the format's constant
6645bd8deadSopenharmony_ci        bias to subtract to get the unbiased (possibly negative) exponent;
6655bd8deadSopenharmony_ci        and frac_r, frac_g, and frac_b are the fractional portion of
6665bd8deadSopenharmony_ci        the mantissas of the r, g, and b components respectively with
6675bd8deadSopenharmony_ci        "0." indicating an implied leading 0.
6685bd8deadSopenharmony_ci
6695bd8deadSopenharmony_ci        There should be no "off limits" exponents for the shared exponent
6705bd8deadSopenharmony_ci        format since there is no requirement for representing Infinity
6715bd8deadSopenharmony_ci        or NaN values and denorm is not a special case.  Because of
6725bd8deadSopenharmony_ci        the implied leading zero, any component with all zeros for its
6735bd8deadSopenharmony_ci        mantissa is zero, no matter the shared exponent's value.
6745bd8deadSopenharmony_ci
6755bd8deadSopenharmony_ci        So the run-of-the-mill BIASED range of exponents for s10e5 is
6765bd8deadSopenharmony_ci        1 to 30.  But the rgb9e5 shared exponent format consistently
6775bd8deadSopenharmony_ci        uses the same rule for all exponents from 0 to 31.
6785bd8deadSopenharmony_ci
6795bd8deadSopenharmony_ci        What exponent bias best allows us to represent the range of
6805bd8deadSopenharmony_ci        s10e5 with the rgb9e5 format?  15.
6815bd8deadSopenharmony_ci
6825bd8deadSopenharmony_ci        Consider the maximum representable finite s10e5 magnitude.
6835bd8deadSopenharmony_ci        The exponent would be 30 (31 would encode an Infinite or NaN
6845bd8deadSopenharmony_ci        value) and the binary mantissa would be 1 followed by ten
6855bd8deadSopenharmony_ci        fractional 1's.  Effectively:
6865bd8deadSopenharmony_ci
6875bd8deadSopenharmony_ci            s10e5_max  =  1.1111111111 * 2^(30-15)
6885bd8deadSopenharmony_ci                       =  1.1111111111 * 2^15
6895bd8deadSopenharmony_ci
6905bd8deadSopenharmony_ci        For an rgb9e5 value with a bias of 15, the largest representable
6915bd8deadSopenharmony_ci        value is:
6925bd8deadSopenharmony_ci
6935bd8deadSopenharmony_ci            rgb9e5_max =  0.111111111  * 2^(31-15)
6945bd8deadSopenharmony_ci                       =  0.111111111  * 2^16
6955bd8deadSopenharmony_ci                       =  1.11111111   * 2^15
6965bd8deadSopenharmony_ci
6975bd8deadSopenharmony_ci        If you ignore two LSBs, these values are nearly identical.
6985bd8deadSopenharmony_ci        The rgb9e5_max value is exactly representable as an s10e5 value.
6995bd8deadSopenharmony_ci
7005bd8deadSopenharmony_ci        For an rgb9e5 value with a bias of 15, the smallest non-zero
7015bd8deadSopenharmony_ci        representable value is:
7025bd8deadSopenharmony_ci
7035bd8deadSopenharmony_ci            rgb9e5_min =  0.000000001  * 2^(0-15)
7045bd8deadSopenharmony_ci            rgb9e5_min =  0.000000001  * 2^-15
7055bd8deadSopenharmony_ci            rgb9e5_min =  0.0000000001 * 2^-14
7065bd8deadSopenharmony_ci
7075bd8deadSopenharmony_ci        So the s10e5_min and rgb9e5_min values exactly match (of course,
7085bd8deadSopenharmony_ci        this assumes the shared exponent bias is 15 which might not be
7095bd8deadSopenharmony_ci        the case if other components demand higher exponents).
7105bd8deadSopenharmony_ci
7115bd8deadSopenharmony_ci    8)  Should there be an rgb9e5 framebuffer format?
7125bd8deadSopenharmony_ci
7135bd8deadSopenharmony_ci        RESOLVED:  No.  Rendering to rgb9e5 is better left to another
7145bd8deadSopenharmony_ci        extension and would require the hardware to convert from a
7155bd8deadSopenharmony_ci        (floating-point) RGBA value into an rgb9e5 encoding.
7165bd8deadSopenharmony_ci
7175bd8deadSopenharmony_ci        Interactions with EXT_framebuffer_object are specified,
7185bd8deadSopenharmony_ci        but the expectation is this is not a renderable
7195bd8deadSopenharmony_ci        format and glCheckFramebufferStatusEXT would return
7205bd8deadSopenharmony_ci        GL_FRAMEBUFFER_UNSUPPORTED_EXT.
7215bd8deadSopenharmony_ci
7225bd8deadSopenharmony_ci        An implementation certainly could make this texture internal
7235bd8deadSopenharmony_ci        format renderable when used with a framebuffer object.  Note that
7245bd8deadSopenharmony_ci        the shared exponent means masked components may be lossy in
7255bd8deadSopenharmony_ci        their masking.  For example, a very small but non-zero value in
7265bd8deadSopenharmony_ci        a masked component could get flushed to zero if a large enough
7275bd8deadSopenharmony_ci        value is written into an unmasked component.
7285bd8deadSopenharmony_ci
7295bd8deadSopenharmony_ci    9)  Should automatic mipmap generation be supported for rgb9e5
7305bd8deadSopenharmony_ci        textures?
7315bd8deadSopenharmony_ci
7325bd8deadSopenharmony_ci        RESOLVED:  Yes.
7335bd8deadSopenharmony_ci
7345bd8deadSopenharmony_ci    10) Should non-texture and non-framebuffer commands for loading
7355bd8deadSopenharmony_ci        pixel data accept the GL_UNSIGNED_INT_5_9_9_9_REV_EXT type?
7365bd8deadSopenharmony_ci
7375bd8deadSopenharmony_ci        RESOLVED:  Yes.
7385bd8deadSopenharmony_ci
7395bd8deadSopenharmony_ci        Once the pixel path has to support the new type/format combination
7405bd8deadSopenharmony_ci        of GL_UNSIGNED_INT_5_9_9_9_REV_EXT / GL_RGB for specifying and
7415bd8deadSopenharmony_ci        querying texture images, it might as well be supported for all
7425bd8deadSopenharmony_ci        commands that pack and unpack RGB pixel data.
7435bd8deadSopenharmony_ci
7445bd8deadSopenharmony_ci        The specification is written such that the glDrawPixels
7455bd8deadSopenharmony_ci        type/format parameters are accepted by glReadPixels,
7465bd8deadSopenharmony_ci        glTexGetImage, glTexImage2D, and other commands that are specified
7475bd8deadSopenharmony_ci        in terms of glDrawPixels.
7485bd8deadSopenharmony_ci
7495bd8deadSopenharmony_ci    11) Should non-texture internal formats (such as for color tables,
7505bd8deadSopenharmony_ci        convolution kernels, histogram bins, and min/max tables) accept
7515bd8deadSopenharmony_ci        GL_RGB9_E5_EXT format?
7525bd8deadSopenharmony_ci
7535bd8deadSopenharmony_ci        RESOLVED:  No.
7545bd8deadSopenharmony_ci
7555bd8deadSopenharmony_ci        That's pointless.  No hardware is ever likely to support
7565bd8deadSopenharmony_ci        GL_RGB9_E5_EXT internalformats for anything other than textures
7575bd8deadSopenharmony_ci        and maybe color buffers in the future.  This format is not
7585bd8deadSopenharmony_ci        interesting for color tables, convolution kernels, etc.
7595bd8deadSopenharmony_ci
7605bd8deadSopenharmony_ci    12) Should a format be supported with sign bits for each component?
7615bd8deadSopenharmony_ci
7625bd8deadSopenharmony_ci        RESOLVED:  No.
7635bd8deadSopenharmony_ci
7645bd8deadSopenharmony_ci        An srgb8e5 format with a sign bit per component could be useful
7655bd8deadSopenharmony_ci        but is better left to another extension.
7665bd8deadSopenharmony_ci
7675bd8deadSopenharmony_ci    13) The rgb9e5 allows two 32-bit values encoded as rgb9e5 to
7685bd8deadSopenharmony_ci        correspond to the exact same 3 components when expanded to
7695bd8deadSopenharmony_ci        floating-point.  Is this a problem?
7705bd8deadSopenharmony_ci
7715bd8deadSopenharmony_ci        RESOLVED:  No, there's no problem here.
7725bd8deadSopenharmony_ci
7735bd8deadSopenharmony_ci        An encoder is likely to always pack components so at least
7745bd8deadSopenharmony_ci        one mantissa will have an explicit leading one, but there's no
7755bd8deadSopenharmony_ci        requirement for that.
7765bd8deadSopenharmony_ci
7775bd8deadSopenharmony_ci        Applications might be able to take advantage of this by quickly
7785bd8deadSopenharmony_ci        dividing all three components by a power-of-two by simply
7795bd8deadSopenharmony_ci        subtracting log2 of the power-of-two from the shared exponent (as
7805bd8deadSopenharmony_ci        long as the exponent is greater than zero prior to the subtract).
7815bd8deadSopenharmony_ci
7825bd8deadSopenharmony_ci        Arguably, the shared exponent format could maintain a slight
7835bd8deadSopenharmony_ci        amount of extra precision (one bit per mantissa) if the format
7845bd8deadSopenharmony_ci        said if the most significant bits of all three mantissas are
7855bd8deadSopenharmony_ci        either all one or all zero and the biased shared exponent was not
7865bd8deadSopenharmony_ci        zero, then an implied leading 1 should be assumed and the shared
7875bd8deadSopenharmony_ci        exponent should be treated as one smaller than it really is.
7885bd8deadSopenharmony_ci        While this would preserve an extra least-significant bit of
7895bd8deadSopenharmony_ci        mantissa precision for components of approximately the same
7905bd8deadSopenharmony_ci        magnitude, it would complicate the encoding and decoding of
7915bd8deadSopenharmony_ci        shared exponent values.
7925bd8deadSopenharmony_ci
7935bd8deadSopenharmony_ci    14) Can you provide some C code for encoding three floating-point
7945bd8deadSopenharmony_ci        values into the rgb9e5 format?
7955bd8deadSopenharmony_ci
7965bd8deadSopenharmony_ci        RESOLVED:  Sure.  See the Appendix.
7975bd8deadSopenharmony_ci
7985bd8deadSopenharmony_ci    15) Should we support a non-REV version of the
7995bd8deadSopenharmony_ci        GL_UNSIGNED_INT_5_9_9_9_REV_EXT token?
8005bd8deadSopenharmony_ci
8015bd8deadSopenharmony_ci        RESOLVED:  No.  The shared exponent is always the 5 most
8025bd8deadSopenharmony_ci        significant bits of the 32 bit word.  The first (red) mantissa
8035bd8deadSopenharmony_ci        is in the least significant 9 bits, followed by 9 bits for the
8045bd8deadSopenharmony_ci        second (green) mantissa, followed by 9 bits for the third (blue)
8055bd8deadSopenharmony_ci        mantissa.  We don't want to promote different arrangements of
8065bd8deadSopenharmony_ci        the bitfields for rgb9e5 values.
8075bd8deadSopenharmony_ci
8085bd8deadSopenharmony_ci    16) Can you use the GL_UNSIGNED_INT_5_9_9_9_REV_EXT format with
8095bd8deadSopenharmony_ci        just any format?
8105bd8deadSopenharmony_ci
8115bd8deadSopenharmony_ci        RESOLVED:  You can only use the GL_UNSIGNED_INT_5_9_9_9_REV_EXT
8125bd8deadSopenharmony_ci        format with GL_RGB.  Otherwise, the GL generates
8135bd8deadSopenharmony_ci        a GL_INVALID_OPERATION error.  Conceptually,
8145bd8deadSopenharmony_ci        GL_UNSIGNED_INT_5_9_9_9_REV_EXT is a 3-component format
8155bd8deadSopenharmony_ci        that just happens to have 5 shared bits too.  Just as the
8165bd8deadSopenharmony_ci        GL_UNSIGNED_BYTE_3_3_2 format just works with GL_RGB (or else
8175bd8deadSopenharmony_ci        the GL generates a GL_INVALID_OPERATION error), so should
8185bd8deadSopenharmony_ci        GL_UNSIGNED_INT_5_9_9_9_REV_EXT.
8195bd8deadSopenharmony_ci
8205bd8deadSopenharmony_ci    17) What should GL_TEXTURE_SHARED_SIZE_EXT return when queried with
8215bd8deadSopenharmony_ci        GetTexLevelParameter?
8225bd8deadSopenharmony_ci
8235bd8deadSopenharmony_ci        RESOLVED:  Return 5 for the RGB9_E5_EXT internal format and 0
8245bd8deadSopenharmony_ci        for all other existing formats.
8255bd8deadSopenharmony_ci
8265bd8deadSopenharmony_ci        This is a count of the number of bits in the shared exponent.
8275bd8deadSopenharmony_ci
8285bd8deadSopenharmony_ci    18) What should GL_TEXTURE_RED_SIZE, GL_TEXTURE_GREEN_SIZE, and
8295bd8deadSopenharmony_ci        GL_TEXTURE_BLUE_SIZE return when queried with GetTexLevelParameter
8305bd8deadSopenharmony_ci        for a GL_RGB9_E5_EXT texture?
8315bd8deadSopenharmony_ci
8325bd8deadSopenharmony_ci        RESOLVED:  Return 9 for each.
8335bd8deadSopenharmony_ci
8345bd8deadSopenharmony_ciRevision History
8355bd8deadSopenharmony_ci
8365bd8deadSopenharmony_ci    Rev.    Date    Author    Changes
8375bd8deadSopenharmony_ci    ----  --------  --------  --------------------------------------------
8385bd8deadSopenharmony_ci    0.5   02/18/07  mjk       Initial public version
8395bd8deadSopenharmony_ci    1.0   07/18/08  mjk       correct significant errors in spec language
8405bd8deadSopenharmony_ci                              and C code
841