15bd8deadSopenharmony_ciName
25bd8deadSopenharmony_ci
35bd8deadSopenharmony_ci    IMG_framebuffer_downsample
45bd8deadSopenharmony_ci
55bd8deadSopenharmony_ciName Strings
65bd8deadSopenharmony_ci
75bd8deadSopenharmony_ci    GL_IMG_framebuffer_downsample
85bd8deadSopenharmony_ci
95bd8deadSopenharmony_ciContributors
105bd8deadSopenharmony_ci
115bd8deadSopenharmony_ci    Tobias Hector, Imagination Technologies (tobias.hector 'at' imgtec.com)
125bd8deadSopenharmony_ci
135bd8deadSopenharmony_ciContact
145bd8deadSopenharmony_ci
155bd8deadSopenharmony_ci    Tobias Hector (tobias.hector 'at' imgtec.com)
165bd8deadSopenharmony_ci
175bd8deadSopenharmony_ciStatus
185bd8deadSopenharmony_ci
195bd8deadSopenharmony_ci    Complete
205bd8deadSopenharmony_ci
215bd8deadSopenharmony_ciVersion
225bd8deadSopenharmony_ci
235bd8deadSopenharmony_ci    Last Modified Date: August 20, 2015
245bd8deadSopenharmony_ci    Revision: 11
255bd8deadSopenharmony_ci
265bd8deadSopenharmony_ciNumber
275bd8deadSopenharmony_ci
285bd8deadSopenharmony_ci    OpenGL ES Extension #255
295bd8deadSopenharmony_ci
305bd8deadSopenharmony_ciDependencies
315bd8deadSopenharmony_ci
325bd8deadSopenharmony_ci    OpenGL ES 2.0 or OES_framebuffer_object are required.
335bd8deadSopenharmony_ci
345bd8deadSopenharmony_ci    This extension is written against the OpenGL ES 3.0.4 Specification
355bd8deadSopenharmony_ci    (August 27, 2014).
365bd8deadSopenharmony_ci
375bd8deadSopenharmony_ci    This extension has interactions with GL_EXT_multisampled_render_to_texture.
385bd8deadSopenharmony_ci
395bd8deadSopenharmony_ci    This extension has interactions with OpenGL ES 3.1.
405bd8deadSopenharmony_ci
415bd8deadSopenharmony_ci    This extension has interactions with GL_EXT_color_buffer_float.
425bd8deadSopenharmony_ci
435bd8deadSopenharmony_ci    This extension has interactions with GL_EXT_color_buffer_half_float.
445bd8deadSopenharmony_ci
455bd8deadSopenharmony_ciOverview
465bd8deadSopenharmony_ci
475bd8deadSopenharmony_ci    This extension introduces the ability to attach color buffers to a
485bd8deadSopenharmony_ci    framebuffer that are at a lower resolution than the framebuffer itself, with
495bd8deadSopenharmony_ci    the GPU automatically downsampling the color attachment to fit.
505bd8deadSopenharmony_ci
515bd8deadSopenharmony_ci    This can be useful for various post-process rendering techniques where it is
525bd8deadSopenharmony_ci    desirable to generate downsampled images in an efficient manner, or for a
535bd8deadSopenharmony_ci    lower resolution post-process technique.
545bd8deadSopenharmony_ci
555bd8deadSopenharmony_ci    This extension exposes at least a 2 x 2 downscale. Other downsampling modes
565bd8deadSopenharmony_ci    may be exposed on the system and this can be queried.
575bd8deadSopenharmony_ci
585bd8deadSopenharmony_ciIP Status
595bd8deadSopenharmony_ci
605bd8deadSopenharmony_ci    No known IP claims.
615bd8deadSopenharmony_ci
625bd8deadSopenharmony_ciNew Procedures and Functions
635bd8deadSopenharmony_ci
645bd8deadSopenharmony_ci    void FramebufferTexture2DDownsampleIMG(
655bd8deadSopenharmony_ci            enum target, enum attachment,
665bd8deadSopenharmony_ci            enum textarget, uint texture,
675bd8deadSopenharmony_ci            int level, int xscale, int yscale);
685bd8deadSopenharmony_ci
695bd8deadSopenharmony_ci    void FramebufferTextureLayerDownsampleIMG(
705bd8deadSopenharmony_ci            enum target, enum attachment,
715bd8deadSopenharmony_ci            uint texture, int level,
725bd8deadSopenharmony_ci            int layer, int xscale, int yscale);
735bd8deadSopenharmony_ci
745bd8deadSopenharmony_ciNew Tokens
755bd8deadSopenharmony_ci
765bd8deadSopenharmony_ci    Returned by CheckFramebufferStatus:
775bd8deadSopenharmony_ci
785bd8deadSopenharmony_ci        FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_AND_DOWNSAMPLE_IMG 0x913C
795bd8deadSopenharmony_ci
805bd8deadSopenharmony_ci    Accepted by the <pname> parameter of GetBooleanv, GetIntegerv, GetFloatv,
815bd8deadSopenharmony_ci    GetInteger64v, and GetInternalFormativ:
825bd8deadSopenharmony_ci
835bd8deadSopenharmony_ci        NUM_DOWNSAMPLE_SCALES_IMG                             0x913D
845bd8deadSopenharmony_ci
855bd8deadSopenharmony_ci    Accepted by the <target> parameter of GetIntegerv, GetInteger64v,
865bd8deadSopenharmony_ci    GetIntegeri_v, GetInteger64i_v and GetInternalFormativ:
875bd8deadSopenharmony_ci
885bd8deadSopenharmony_ci        DOWNSAMPLE_SCALES_IMG                                 0x913E
895bd8deadSopenharmony_ci
905bd8deadSopenharmony_ci    Accepted by the <pname> parameter of GetFramebufferAttachmentParameteriv:
915bd8deadSopenharmony_ci
925bd8deadSopenharmony_ci        FRAMEBUFFER_ATTACHMENT_TEXTURE_SCALE_IMG              0x913F
935bd8deadSopenharmony_ci
945bd8deadSopenharmony_ciAdditions to Chapter 4 of the OpenGL ES 3.0 Specification:
955bd8deadSopenharmony_ci
965bd8deadSopenharmony_ci    Modify figure 4.1, "Per-Fragment Operations.", to add an additional box
975bd8deadSopenharmony_ci    "Downscaling" after "Additional Multisample Fragment Operations".
985bd8deadSopenharmony_ci
995bd8deadSopenharmony_ci    Add a new section 4.1.11, "Downscaling":
1005bd8deadSopenharmony_ci
1015bd8deadSopenharmony_ci        If no multisampling was performed, and downscaling is enabled, fragment
1025bd8deadSopenharmony_ci        outputs may be optionally downscaled in a similar way to how multiple
1035bd8deadSopenharmony_ci        samples are resolved. If the value of FRAMEBUFFER_ATTACHMENT_TEXTURE_-
1045bd8deadSopenharmony_ci        SCALE_IMG is not {1,1}, fragment values are written to an intermediate
1055bd8deadSopenharmony_ci        buffer. After all other fragment operations have completed, they are
1065bd8deadSopenharmony_ci        then combined to a produce a single color value, and that value is
1075bd8deadSopenharmony_ci        written into the corresponding color buffer selected by DrawBuffers. An
1085bd8deadSopenharmony_ci        implementation may defer the writing of color buffers until a later
1095bd8deadSopenharmony_ci        time, but the state of the framebuffer must behave as if the color
1105bd8deadSopenharmony_ci        buffers were updated as each fragment is processed. The method of
1115bd8deadSopenharmony_ci        combination is not specified. If the framebuffer contains sRGB values,
1125bd8deadSopenharmony_ci        then it is recommended that an average of samples is computed in a
1135bd8deadSopenharmony_ci        linearized space, as for blending (see section 4.1.7). Otherwise, a
1145bd8deadSopenharmony_ci        simple average computed independently for each color component is
1155bd8deadSopenharmony_ci        recommended.
1165bd8deadSopenharmony_ci
1175bd8deadSopenharmony_ci    Add the following to Section 4.4.2 "Attaching Images to Framebuffer Objects"
1185bd8deadSopenharmony_ci    after the paragraph describing FramebufferTexture2D:
1195bd8deadSopenharmony_ci
1205bd8deadSopenharmony_ci        The command
1215bd8deadSopenharmony_ci
1225bd8deadSopenharmony_ci            void FramebufferTexture2DDownsampleIMG(
1235bd8deadSopenharmony_ci                    enum target, enum attachment,
1245bd8deadSopenharmony_ci                    enum textarget, uint texture,
1255bd8deadSopenharmony_ci                    int level, uint xscale, uint yscale);
1265bd8deadSopenharmony_ci
1275bd8deadSopenharmony_ci        allows a rendering into the image of a texture object that has a lower
1285bd8deadSopenharmony_ci        resolution than the framebuffer.
1295bd8deadSopenharmony_ci
1305bd8deadSopenharmony_ci        target, textarget, texture, and level correspond to the same
1315bd8deadSopenharmony_ci        parameters for FramebufferTexture2D and have the same restrictions.
1325bd8deadSopenharmony_ci
1335bd8deadSopenharmony_ci        attachment corresponds to the same parameter for FramebufferTexture2D,
1345bd8deadSopenharmony_ci        but must be COLOR_ATTACHMENTn.
1355bd8deadSopenharmony_ci
1365bd8deadSopenharmony_ci        xscale and yscale are multiplied by texture's width and height,
1375bd8deadSopenharmony_ci        respectively, to produce the effective size of the attachment when
1385bd8deadSopenharmony_ci        rendering. For example, a texture width of 128 with an xscale of 2 would
1395bd8deadSopenharmony_ci        produce a color attachment with the effective width of 256. xscale and
1405bd8deadSopenharmony_ci        yscale must be one of the value pairs in DOWNSAMPLE_SCALES_IMG. If the
1415bd8deadSopenharmony_ci        xscale and yscale value pair is not available on the implementation,
1425bd8deadSopenharmony_ci        then the error INVALID_VALUE is generated.
1435bd8deadSopenharmony_ci
1445bd8deadSopenharmony_ci        The implementation allocates an implicit color buffer for the same
1455bd8deadSopenharmony_ci        internalformat as the specified texture, and widths and heights from the
1465bd8deadSopenharmony_ci        specified texture level, multiplied by xscale and yscale. This buffer is
1475bd8deadSopenharmony_ci        used as the target for rendering instead of the specified texture level.
1485bd8deadSopenharmony_ci        The buffer is associated with the attachment and gets deleted after the
1495bd8deadSopenharmony_ci        attachment is broken.
1505bd8deadSopenharmony_ci
1515bd8deadSopenharmony_ci        When the texture level is used as a source or destination for any
1525bd8deadSopenharmony_ci        operation, the attachment is flushed, or when the attachment is broken,
1535bd8deadSopenharmony_ci        an implicit downsample of the color data from the color buffer to the
1545bd8deadSopenharmony_ci        texture level may be performed. After such a downsample, the contents
1555bd8deadSopenharmony_ci        of the color buffer become undefined.
1565bd8deadSopenharmony_ci
1575bd8deadSopenharmony_ci        The operations which may cause a resolve include:
1585bd8deadSopenharmony_ci            * Drawing with the texture bound to an active texture unit
1595bd8deadSopenharmony_ci            * ReadPixels or CopyTex[Sub]Image* while the texture is
1605bd8deadSopenharmony_ci              attached to the framebuffer
1615bd8deadSopenharmony_ci            * CopyTex[Sub]Image*, Tex[Sub]Image*,
1625bd8deadSopenharmony_ci              CompressedTex[Sub]Image* with the specified level as
1635bd8deadSopenharmony_ci              destination
1645bd8deadSopenharmony_ci            * GenerateMipmap
1655bd8deadSopenharmony_ci            * Flush or Finish while the texture is attached to the
1665bd8deadSopenharmony_ci              framebuffer
1675bd8deadSopenharmony_ci            * BindFramebuffer while the texture is attached to the currently
1685bd8deadSopenharmony_ci              bound framebuffer.
1695bd8deadSopenharmony_ci
1705bd8deadSopenharmony_ci        Whether each of the above cause a resolve or not is implementation-
1715bd8deadSopenharmony_ci        dependent.
1725bd8deadSopenharmony_ci
1735bd8deadSopenharmony_ci    Add the following to the sub-section "Attaching Texture Images to a
1745bd8deadSopenharmony_ci    Framebuffer" after the paragraph describing FramebufferTextureLayer:
1755bd8deadSopenharmony_ci
1765bd8deadSopenharmony_ci        The command
1775bd8deadSopenharmony_ci
1785bd8deadSopenharmony_ci            void FramebufferTextureLayerDownsampleIMG(
1795bd8deadSopenharmony_ci                    enum target, enum attachment,
1805bd8deadSopenharmony_ci                    uint texture, int level,
1815bd8deadSopenharmony_ci                    int layer, uint xscale, uint yscale);
1825bd8deadSopenharmony_ci
1835bd8deadSopenharmony_ci        allows a rendering into a single layer of a texture object that has a
1845bd8deadSopenharmony_ci        lower resolution than the framebuffer. It operates like a combination of
1855bd8deadSopenharmony_ci        FramebufferTexture2DDownsampleIMG and FramebufferTextureLayer; it allows
1865bd8deadSopenharmony_ci        the developer to set scaling values and attaches a single layer of a
1875bd8deadSopenharmony_ci        three-dimensional or two-dimensional array texture level.
1885bd8deadSopenharmony_ci
1895bd8deadSopenharmony_ci        target, attachment, level, xscale and yscale correspond to the same
1905bd8deadSopenharmony_ci        parameters for FramebufferTexture2DDownsampleIMG and have the same
1915bd8deadSopenharmony_ci        restrictions.
1925bd8deadSopenharmony_ci
1935bd8deadSopenharmony_ci        texture can only be a two-dimensional array texture, but otherwise has
1945bd8deadSopenharmony_ci        the same restrictions as it does for FramebufferTextureLayer.
1955bd8deadSopenharmony_ci
1965bd8deadSopenharmony_ci        layer corresponds to the same parameter for FramebufferTextureLayer and
1975bd8deadSopenharmony_ci        has the same restrictions.
1985bd8deadSopenharmony_ci
1995bd8deadSopenharmony_ci    In the sub-section "Effects of Attaching a Texture Image", change the bullet
2005bd8deadSopenharmony_ci    list to the following:
2015bd8deadSopenharmony_ci
2025bd8deadSopenharmony_ci        * The value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is set to TEXTURE.
2035bd8deadSopenharmony_ci        * The value of FRAMEBUFFER_ATTACHMENT_OBJECT_NAME is set to texture.
2045bd8deadSopenharmony_ci        * The value of FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL is set to level.
2055bd8deadSopenharmony_ci        * If FramebufferTexture2D is called and texture is a cube map texture,
2065bd8deadSopenharmony_ci          then the value of FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE is set
2075bd8deadSopenharmony_ci          to textarget; otherwise it is set to the default (NONE).
2085bd8deadSopenharmony_ci        * If FramebufferTextureLayer is called, then the value of FRAMEBUFFER_-
2095bd8deadSopenharmony_ci          ATTACHMENT_TEXTURE_LAYER is set to layer; otherwise it is set to zero.
2105bd8deadSopenharmony_ci        * If FramebufferTexture2DDownsampleIMG or
2115bd8deadSopenharmony_ci          FramebufferTextureLayerDownsampleIMG is called, then the value of
2125bd8deadSopenharmony_ci          FRAMEBUFFER_ATTACHMENT_TEXTURE_SCALE_IMG is set to {xscale, yscale};
2135bd8deadSopenharmony_ci          otherwise it is set to {1, 1}.
2145bd8deadSopenharmony_ci
2155bd8deadSopenharmony_ci    In section 4.4.4 "Framebuffer Completeness", add the following bullet to the
2165bd8deadSopenharmony_ci    end of the list in subsection "Framebuffer Attachment Completeness":
2175bd8deadSopenharmony_ci
2185bd8deadSopenharmony_ci
2195bd8deadSopenharmony_ci        * If the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is TEXTURE and the
2205bd8deadSopenharmony_ci          value of FRAMEBUFFER_ATTACHMENT_TEXTURE_SCALE_IMG is supported by the
2215bd8deadSopenharmony_ci          internal format of the attachment (see GetInternalFormativ in section
2225bd8deadSopenharmony_ci          6.1.15).
2235bd8deadSopenharmony_ci
2245bd8deadSopenharmony_ci    In section 4.4.4 "Framebuffer Completeness", add the following bullet to the
2255bd8deadSopenharmony_ci    end of the list in subsection "Whole Framebuffer Completeness":
2265bd8deadSopenharmony_ci
2275bd8deadSopenharmony_ci        * The value of FRAMEBUFFER_ATTACHMENT_TEXTURE_SCALE_IMG for all
2285bd8deadSopenharmony_ci          attachments is {1,1}, or if not, the value of TEXTURE_SAMPLES_EXT or
2295bd8deadSopenharmony_ci          RENDERBUFFER_SAMPLES for all attachments is zero.
2305bd8deadSopenharmony_ci          FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_AND_DOWNSAMPLE_IMG
2315bd8deadSopenharmony_ci
2325bd8deadSopenharmony_ciAdditions to Chapter 6 of the OpenGL ES 3.0 Specification:
2335bd8deadSopenharmony_ci
2345bd8deadSopenharmony_ci    Add the following bullet point to the list in Section 6.1.13 "Framebuffer
2355bd8deadSopenharmony_ci    Object Queries" describing valid pname values when FRAMEBUFFER_ATTACHMENT_-
2365bd8deadSopenharmony_ci    OBJECT_TYPE is TEXTURE:
2375bd8deadSopenharmony_ci
2385bd8deadSopenharmony_ci        * If pname is FRAMEBUFFER_ATTACHMENT_TEXTURE_SCALE_IMG, then params will
2395bd8deadSopenharmony_ci          contain two integer values - the downsample scale pair for that
2405bd8deadSopenharmony_ci          attachment.
2415bd8deadSopenharmony_ci
2425bd8deadSopenharmony_ci    Change the paragraph in Section 6.1.15 "Internal Format Queries" describing
2435bd8deadSopenharmony_ci    valid target values to:
2445bd8deadSopenharmony_ci
2455bd8deadSopenharmony_ci        target indicates the usage of the internalformat, and must be one of
2465bd8deadSopenharmony_ci    RENDERBUFFER, TEXTURE_2D, TEXTURE_CUBE_MAP or TEXTURE_2D_ARRAY.
2475bd8deadSopenharmony_ci
2485bd8deadSopenharmony_ci    Add the following paragraphs to Section 6.1.15 "Internal Format Queries" to
2495bd8deadSopenharmony_ci    the paragraphs describing valid pname values:
2505bd8deadSopenharmony_ci
2515bd8deadSopenharmony_ci        If pname is NUM_DOWNSAMPLE_SCALES_IMG, the number of downscales that
2525bd8deadSopenharmony_ci    would be returned by querying DOWNSAMPLE_SCALES_IMG is returned in params.
2535bd8deadSopenharmony_ci        If pname is DOWNSAMPLE_SCALES_IMG, the available downscale pairs for the
2545bd8deadSopenharmony_ci    format are written into params.
2555bd8deadSopenharmony_ci        Formats that don't support downsampling will still return one valid
2565bd8deadSopenharmony_ci    downsample scale pair - {1,1}. A value of one for NUM_DOWNSAMPLE_SCALES_IMG
2575bd8deadSopenharmony_ci    will always mean no downscaling available, as {1,1} must be supported by
2585bd8deadSopenharmony_ci    every format. Targets that don't support downscaling (e.g. RENDERBUFFER)
2595bd8deadSopenharmony_ci    will return no downsample scale pairs.
2605bd8deadSopenharmony_ci
2615bd8deadSopenharmony_ciInteractions with OpenGL ES 2.0
2625bd8deadSopenharmony_ci
2635bd8deadSopenharmony_ci    In section 4.4.5 of the OpenGL ES 2.0 Specification "Framebuffer
2645bd8deadSopenharmony_ci    Completeness", subsection "Framebuffer Attachment Completeness", replace:
2655bd8deadSopenharmony_ci
2665bd8deadSopenharmony_ci        * All attached images have the same width and height.
2675bd8deadSopenharmony_ci          FRAMEBUFFER_INCOMPLETE_DIMENSIONS
2685bd8deadSopenharmony_ci
2695bd8deadSopenharmony_ci    with:
2705bd8deadSopenharmony_ci
2715bd8deadSopenharmony_ci        * All attached images have the same value of width * xscale and
2725bd8deadSopenharmony_ci          height * yscale.
2735bd8deadSopenharmony_ci          FRAMEBUFFER_INCOMPLETE_DIMENSIONS
2745bd8deadSopenharmony_ci
2755bd8deadSopenharmony_ciInteractions with OpenGL ES 3.1
2765bd8deadSopenharmony_ci
2775bd8deadSopenharmony_ci    If OpenGL ES 3.1 is supported, replace TEXTURE_SAMPLES_EXT with TEXTURE_-
2785bd8deadSopenharmony_ci    SAMPLES, and add TEXTURE_2D_MULTISAMPLE to the list of valid targets for
2795bd8deadSopenharmony_ci    GetInternalFormativ.
2805bd8deadSopenharmony_ci
2815bd8deadSopenharmony_ciInteractions with EXT_multisampled_render_to_texture
2825bd8deadSopenharmony_ci
2835bd8deadSopenharmony_ci    If EXT_multisampled_render_to_texture is not supported:
2845bd8deadSopenharmony_ci        - ignore references to TEXTURE_SAMPLES_EXT
2855bd8deadSopenharmony_ci        - the sample counts returned by GetInternalFormativ with a target of
2865bd8deadSopenharmony_ci          TEXTURE* will be the sample values available to be used with
2875bd8deadSopenharmony_ci          FramebufferTexture2DMultisampleEXT
2885bd8deadSopenharmony_ci
2895bd8deadSopenharmony_ciDependencies on OpenGL ES 3.0
2905bd8deadSopenharmony_ci
2915bd8deadSopenharmony_ci    If OpenGL ES 3.0 or higher is not supported, ignore references to
2925bd8deadSopenharmony_ci    glFramebufferTextureLayerDownsample and glGetIntegeri_v.
2935bd8deadSopenharmony_ci
2945bd8deadSopenharmony_ciInteractions with EXT_color_buffer_float and EXT_color_buffer_half_float
2955bd8deadSopenharmony_ci
2965bd8deadSopenharmony_ci    If either of these extensions are supported, it is not guaranteed that
2975bd8deadSopenharmony_ci    downscale of these formats is supported, but it may be - users will have to
2985bd8deadSopenharmony_ci    check with the GetInternalFormat query.
2995bd8deadSopenharmony_ci
3005bd8deadSopenharmony_ci    This equally applies to any other additional render formats provided by
3015bd8deadSopenharmony_ci    extension.
3025bd8deadSopenharmony_ci
3035bd8deadSopenharmony_ciErrors
3045bd8deadSopenharmony_ci
3055bd8deadSopenharmony_ci    The error INVALID_VALUE is generated if FramebufferTextureLayerDownsampleIMG
3065bd8deadSopenharmony_ci    or FramebufferTexture2DDownsampleIMG are are called with an <xscale> and
3075bd8deadSopenharmony_ci    <yscale> value pair that isn't reported by DOWNSAMPLE_SCALES_IMG.
3085bd8deadSopenharmony_ci
3095bd8deadSopenharmony_ci    The error INVALID_ENUM is generated if FramebufferTextureLayerDownsampleIMG
3105bd8deadSopenharmony_ci    or FramebufferTexture2DDownsampleIMG are called with an <attachment> that is
3115bd8deadSopenharmony_ci    not COLOR_ATTACHMENTn.
3125bd8deadSopenharmony_ci
3135bd8deadSopenharmony_ciNew State
3145bd8deadSopenharmony_ci
3155bd8deadSopenharmony_ci    Add to Table 6.14 "Framebuffer (state per attachment point)"
3165bd8deadSopenharmony_ci
3175bd8deadSopenharmony_ci                                                        Initial
3185bd8deadSopenharmony_ci    Get Value         Type        Get Command           Value   Description     Sec.
3195bd8deadSopenharmony_ci    ----------------- ----------- --------------------- ------- --------------- ----
3205bd8deadSopenharmony_ci    FRAMEBUFFER_-     2 x Z+      GetFramebuffer-       {1,1}   Framebuffer     4.4.2
3215bd8deadSopenharmony_ci    ATTACHMENT_-                  AttachmentParameteriv         texture scale
3225bd8deadSopenharmony_ci    TEXTURE_SCALE_IMG
3235bd8deadSopenharmony_ci
3245bd8deadSopenharmony_ciNew Implementation Dependent State
3255bd8deadSopenharmony_ci
3265bd8deadSopenharmony_ci    Add to Table 6.35 "Framebuffer Dependent Values"
3275bd8deadSopenharmony_ci                                                     Minimum
3285bd8deadSopenharmony_ci    Get Value         Type        Get Command        Value   Description     Sec.
3295bd8deadSopenharmony_ci    ----------------- ----------- ------------------ ------- --------------- ----
3305bd8deadSopenharmony_ci    NUM_DOWNSAMPLE_-  2 x Z+      GetIntegerv        2       Number of       4.4.2
3315bd8deadSopenharmony_ci    SCALES_IMG                                               scale value
3325bd8deadSopenharmony_ci                                                             pairs available
3335bd8deadSopenharmony_ci
3345bd8deadSopenharmony_ci    DOWNSAMPLE_-      1* x 2 x Z+ GetIntegeri_v      **      Scale value     4.4.2
3355bd8deadSopenharmony_ci    SCALES_IMG                                               pairs available
3365bd8deadSopenharmony_ci
3375bd8deadSopenharmony_ci
3385bd8deadSopenharmony_ci    ** At least {1,1} and {2,2} must be supported as a minimum to support this extension.
3395bd8deadSopenharmony_ci
3405bd8deadSopenharmony_ciExample
3415bd8deadSopenharmony_ci
3425bd8deadSopenharmony_ci    GLint xDownscale = 1;
3435bd8deadSopenharmony_ci    GLint yDownscale = 1;
3445bd8deadSopenharmony_ci
3455bd8deadSopenharmony_ci    // Select a downscale amount if possible
3465bd8deadSopenharmony_ci    if (extension_is_supported("GL_IMG_framebuffer_downsample")
3475bd8deadSopenharmony_ci    {
3485bd8deadSopenharmony_ci        // Query the number of available scales
3495bd8deadSopenharmony_ci        GLint numScales;
3505bd8deadSopenharmony_ci        glGetIntegerv(GL_NUM_DOWNSAMPLE_SCALES_IMG, &numScales);
3515bd8deadSopenharmony_ci
3525bd8deadSopenharmony_ci        // 2 scale modes are supported as minimum, so only need to check for
3535bd8deadSopenharmony_ci        // better than 2x2 if more modes are exposed.
3545bd8deadSopenharmony_ci        if (numScales > 2)
3555bd8deadSopenharmony_ci        {
3565bd8deadSopenharmony_ci            // Try to select most aggressive scaling.
3575bd8deadSopenharmony_ci            GLint bestScale = 1;
3585bd8deadSopenharmony_ci            GLint tempScale[2];
3595bd8deadSopenharmony_ci            GLint i;
3605bd8deadSopenharmony_ci            for (i = 0; i < numScales; ++i)
3615bd8deadSopenharmony_ci            {
3625bd8deadSopenharmony_ci                glGetIntegeri_v(GL_DOWNSAMPLE_SCALES_IMG, i, tempScale);
3635bd8deadSopenharmony_ci
3645bd8deadSopenharmony_ci                // If the scaling is more aggressive, update our x/y scale values.
3655bd8deadSopenharmony_ci                if (tempScale[0] * tempScale[1] > bestScale)
3665bd8deadSopenharmony_ci                {
3675bd8deadSopenharmony_ci                    xDownscale = tempScale[0];
3685bd8deadSopenharmony_ci                    yDownscale = tempScale[1];
3695bd8deadSopenharmony_ci                }
3705bd8deadSopenharmony_ci            }
3715bd8deadSopenharmony_ci        }
3725bd8deadSopenharmony_ci        else
3735bd8deadSopenharmony_ci        {
3745bd8deadSopenharmony_ci            xDownscale = 2;
3755bd8deadSopenharmony_ci            yDownscale = 2;
3765bd8deadSopenharmony_ci        }
3775bd8deadSopenharmony_ci    }
3785bd8deadSopenharmony_ci
3795bd8deadSopenharmony_ci    // Create depth texture. Depth and stencil buffers must be full size
3805bd8deadSopenharmony_ci    GLuint depthTexture;
3815bd8deadSopenharmony_ci    glGenTextures(1, &depthTexture);
3825bd8deadSopenharmony_ci    glBindTexture(GL_TEXTURE_2D, depthTexture);
3835bd8deadSopenharmony_ci    glTexStorage2D(GL_TEXTURE_2D, 1, GL_DEPTH_COMPONENT16, width, height);
3845bd8deadSopenharmony_ci    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3855bd8deadSopenharmony_ci    glBindTexture(GL_TEXTURE_2D, 0);
3865bd8deadSopenharmony_ci
3875bd8deadSopenharmony_ci    // Create a full size RGBA texture with single mipmap level
3885bd8deadSopenharmony_ci    GLuint texture;
3895bd8deadSopenharmony_ci    glGenTextures(1, &texture);
3905bd8deadSopenharmony_ci    glBindTexture(GL_TEXTURE_2D, texture);
3915bd8deadSopenharmony_ci    glTexStorage2D(GL_TEXTURE_2D, 0, GL_RGBA4, width, height);
3925bd8deadSopenharmony_ci    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3935bd8deadSopenharmony_ci    glBindTexture(GL_TEXTURE_2D, 0);
3945bd8deadSopenharmony_ci
3955bd8deadSopenharmony_ci    // Scale the width and height appropriately.
3965bd8deadSopenharmony_ci    GLint scaledWidth = width / xDownscale;
3975bd8deadSopenharmony_ci    GLint scaledHeight = height / yDownscale;
3985bd8deadSopenharmony_ci
3995bd8deadSopenharmony_ci    // Create a reduced size RGBA texture with single mipmap level
4005bd8deadSopenharmony_ci    GLuint scaledTexture;
4015bd8deadSopenharmony_ci    glGenTextures(1, &scaledTexture);
4025bd8deadSopenharmony_ci    glBindTexture(GL_TEXTURE_2D, scaledTexture);
4035bd8deadSopenharmony_ci    glTexStorage2D(GL_TEXTURE_2D, 0, GL_RGBA4, scaledWidth, scaledHeight);
4045bd8deadSopenharmony_ci    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4055bd8deadSopenharmony_ci    glBindTexture(GL_TEXTURE_2D, 0);
4065bd8deadSopenharmony_ci
4075bd8deadSopenharmony_ci    // Create framebuffer object, attach textures
4085bd8deadSopenharmony_ci    GLuint framebuffer;
4095bd8deadSopenharmony_ci    glGenFramebuffers(1, &framebuffer);
4105bd8deadSopenharmony_ci    glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
4115bd8deadSopenharmony_ci    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
4125bd8deadSopenharmony_ci        GL_TEXTURE_2D, depthTexture);
4135bd8deadSopenharmony_ci    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
4145bd8deadSopenharmony_ci        GL_TEXTURE_2D, texture, 0);
4155bd8deadSopenharmony_ci    glFramebufferTexture2DDownsampleIMG(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1,
4165bd8deadSopenharmony_ci        GL_TEXTURE_2D, scaledTexture, 0, xDownscale, yDownscale);
4175bd8deadSopenharmony_ci
4185bd8deadSopenharmony_ci    // Handle unsupported cases
4195bd8deadSopenharmony_ci    if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
4205bd8deadSopenharmony_ci    {
4215bd8deadSopenharmony_ci        ...
4225bd8deadSopenharmony_ci    }
4235bd8deadSopenharmony_ci
4245bd8deadSopenharmony_ci    // Draw to the texture
4255bd8deadSopenharmony_ci    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
4265bd8deadSopenharmony_ci    ...
4275bd8deadSopenharmony_ci
4285bd8deadSopenharmony_ci    // Discard the depth renderbuffer contents if possible/available
4295bd8deadSopenharmony_ci    if (extension_supported("GL_EXT_discard_framebuffer"))
4305bd8deadSopenharmony_ci    {
4315bd8deadSopenharmony_ci        GLenum discard_attachments[] = { GL_DEPTH_ATTACHMENT };
4325bd8deadSopenharmony_ci        glDiscardFramebufferEXT(GL_FRAMEBUFFER, 1, discard_attachments);
4335bd8deadSopenharmony_ci    }
4345bd8deadSopenharmony_ci
4355bd8deadSopenharmony_ci    /*
4365bd8deadSopenharmony_ci        Draw to the default framebuffer using the textures with various post
4375bd8deadSopenharmony_ci        processing effects.
4385bd8deadSopenharmony_ci    */
4395bd8deadSopenharmony_ci    glBindFramebuffer(GL_FRAMEBUFFER, 0);
4405bd8deadSopenharmony_ci    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
4415bd8deadSopenharmony_ci    glActiveTexture(GL_TEXTURE0);
4425bd8deadSopenharmony_ci    glBindTexture(GL_TEXTURE_2D, texture);
4435bd8deadSopenharmony_ci    glActiveTexture(GL_TEXTURE1);
4445bd8deadSopenharmony_ci    glBindTexture(GL_TEXTURE_2D, scaledTexture);
4455bd8deadSopenharmony_ci    ...
4465bd8deadSopenharmony_ci
4475bd8deadSopenharmony_ciIssues
4485bd8deadSopenharmony_ci
4495bd8deadSopenharmony_ci    1) Should renderbuffers be resolvable in this way too?
4505bd8deadSopenharmony_ci
4515bd8deadSopenharmony_ci       RESOLVED
4525bd8deadSopenharmony_ci
4535bd8deadSopenharmony_ci       No, renderbuffers are considered somewhat legacy and thus will
4545bd8deadSopenharmony_ci       not be supported by this extension.
4555bd8deadSopenharmony_ci
4565bd8deadSopenharmony_ci    2) Should any scale values other than {1,1} be mandated as minimum?
4575bd8deadSopenharmony_ci
4585bd8deadSopenharmony_ci       RESOLVED
4595bd8deadSopenharmony_ci
4605bd8deadSopenharmony_ci       Yes, {2,2} will also be required. Implementations may support additional
4615bd8deadSopenharmony_ci       values though, so a query is also added for other values.
4625bd8deadSopenharmony_ci
4635bd8deadSopenharmony_ci    3) What formats support downscaling?
4645bd8deadSopenharmony_ci
4655bd8deadSopenharmony_ci       RESOLVED
4665bd8deadSopenharmony_ci
4675bd8deadSopenharmony_ci       Formats that are guaranteed color-renderable by the core ES 3.1
4685bd8deadSopenharmony_ci       specification, excluding integer and signed integer formats, support all
4695bd8deadSopenharmony_ci       available downscale modes. Other formats only support {1,1} (no
4705bd8deadSopenharmony_ci       downscaling).
4715bd8deadSopenharmony_ci
4725bd8deadSopenharmony_ci    4) What should happen if an application calls GetInternalFormativ with a
4735bd8deadSopenharmony_ci       target of TEXTURE* (not TEXTURE_2D_MULTISAMPLE)?
4745bd8deadSopenharmony_ci
4755bd8deadSopenharmony_ci       RESOLVED
4765bd8deadSopenharmony_ci
4775bd8deadSopenharmony_ci       For standard OpenGL ES, NUM_SAMPLE_COUNTS should be zero. However, if
4785bd8deadSopenharmony_ci       EXT_multisampled_render_to_texture is supported, valid configurations
4795bd8deadSopenharmony_ci       for FramebufferTexture2DMultisampleEXT should be returned here.
4805bd8deadSopenharmony_ci
4815bd8deadSopenharmony_ciRevision History
4825bd8deadSopenharmony_ci
4835bd8deadSopenharmony_ci    Revision 1, 2014/08/27
4845bd8deadSopenharmony_ci      - First draft
4855bd8deadSopenharmony_ci
4865bd8deadSopenharmony_ci    Revision 2, 2015/03/16
4875bd8deadSopenharmony_ci      - Mandated {2,2} as a required downsample scale.
4885bd8deadSopenharmony_ci      - Coupled x and y scale values into pairs
4895bd8deadSopenharmony_ci
4905bd8deadSopenharmony_ci    Revision 3, 2015/03/19
4915bd8deadSopenharmony_ci      - Moved framebuffer completeness information to correct (whole framebuffer
4925bd8deadSopenharmony_ci        completeness) section, and corrected wording.
4935bd8deadSopenharmony_ci      - Added note about minimum support in the overview.
4945bd8deadSopenharmony_ci
4955bd8deadSopenharmony_ci    Revision 4, 2015/03/19
4965bd8deadSopenharmony_ci      - Added a specific revision of the OpenGL ES 3.0 specification
4975bd8deadSopenharmony_ci      - Added an error that only COLOR_ATTACHMENTn can be used as an attachment
4985bd8deadSopenharmony_ci        point
4995bd8deadSopenharmony_ci
5005bd8deadSopenharmony_ci    Revision 5, 2015/06/02
5015bd8deadSopenharmony_ci      - Added internalformat query capability, so that formats can opt into
5025bd8deadSopenharmony_ci        downscaling support
5035bd8deadSopenharmony_ci      - Added section on downscaling to per-fragment operations.
5045bd8deadSopenharmony_ci      - Added issue about what formats support downscaling.
5055bd8deadSopenharmony_ci      - Restricted layer downscaling to 2D array textures.
5065bd8deadSopenharmony_ci
5075bd8deadSopenharmony_ci    Revision 6, 2015/06/03
5085bd8deadSopenharmony_ci      - Fixed typo in incomplete framebuffer condition
5095bd8deadSopenharmony_ci      - Added a bullet point to describe the FRAMEBUFFER_ATTACHMENT_TEXTURE_-
5105bd8deadSopenharmony_ci        SCALE_IMG parameter to GetFramebufferAttachmentiv
5115bd8deadSopenharmony_ci      - Clarified targets to GetInternalFormativ
5125bd8deadSopenharmony_ci
5135bd8deadSopenharmony_ci    Revision 7, 2015/06/17
5145bd8deadSopenharmony_ci      - Clarified interactions with EXT_color_buffer_float and
5155bd8deadSopenharmony_ci        EXT_color_buffer_half_float
5165bd8deadSopenharmony_ci
5175bd8deadSopenharmony_ci    Revision 8, 2015/06/22
5185bd8deadSopenharmony_ci      - Added NUM_DOWNSAMPLE_SCALES_IMG as a parameter to GetInternalFormativ
5195bd8deadSopenharmony_ci      - Added framebuffer attachment incomplete message and removed error when
5205bd8deadSopenharmony_ci        scale pair isn't supported by textures' internalformat, as
5215bd8deadSopenharmony_ci        internalformat is not necessarily known at attachment time.
5225bd8deadSopenharmony_ci
5235bd8deadSopenharmony_ci    Revision 9, 2015/08/19
5245bd8deadSopenharmony_ci      - Assigned enum values
5255bd8deadSopenharmony_ci
5265bd8deadSopenharmony_ci    Revision 10, 2015/08/20
5275bd8deadSopenharmony_ci      - Allowed DOWNSAMPLE_SCALES_IMG to be used with GetIntegerv/GetInteger64v
5285bd8deadSopenharmony_ci
5295bd8deadSopenharmony_ci    Revision 11, 2015/12/18
5305bd8deadSopenharmony_ci      - Fixed example - "tempScale" is an array so doesn't need to be dereferenced.
531