<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>219023</bug_id>
          
          <creation_ts>2020-11-17 00:42:30 -0800</creation_ts>
          <short_desc>Blank glReadPixels since iOS 14.2</short_desc>
          <delta_ts>2023-10-27 04:17:18 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebGL</component>
          <version>Safari 14</version>
          <rep_platform>iPhone / iPad</rep_platform>
          <op_sys>Other</op_sys>
          <bug_status>REOPENED</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Major</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>263770</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter>paul</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>dino</cc>
    
    <cc>kkinnunen</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1708147</commentid>
    <comment_count>0</comment_count>
    <who name="">paul</who>
    <bug_when>2020-11-17 00:42:30 -0800</bug_when>
    <thetext>Reproduction steps:
- iOS 14.2
- go to https://labs.sketchfab.com/experiments/screenshots/#model/818a31e7b4194dc688dc19be9dcafdec
- click on &quot;export screenshot&quot; blue button on the right panel
- get a PNG file downloaded, but blank


Sketchfab is a webGL based app, here using glReadpixels webgl command to read pixel back from GPU framebuffer.

Since ios 14.2, on safari, glReadPixels return blank image where it was working before.

- iPhone 8+ iOS 14.2 - does not work
- iPhone 11, iOS 14.2 - does not work
VS
- iphone 7+, 13.6.1 works</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1708461</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2020-11-17 18:46:11 -0800</bug_when>
    <thetext>&lt;rdar://problem/71518366&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1714393</commentid>
    <comment_count>2</comment_count>
    <who name="Kimmo Kinnunen">kkinnunen</who>
    <bug_when>2020-12-14 01:23:58 -0800</bug_when>
    <thetext>Thanks for the report, sorry it took so long to look at it.
I can repro the issue.

I can see the webgl element is depth==false, antialias==false, preserveDrawingBuffer==false.

In case it is easy for you to provide more info:
Would you have any more details on how you do glReadPixels?
1) is it reading the default Framebuffer or user-defined Framebuffer?
If it is user-defined:
2) What format is the texture attachment? Does the texture attachment have alpha?
3) Anything out-of-ordinary with the framebuffer?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1714416</commentid>
    <comment_count>3</comment_count>
    <who name="">paul</who>
    <bug_when>2020-12-14 03:34:40 -0800</bug_when>
    <thetext>1) is it reading the default Framebuffer or user-defined Framebuffer?
It&apos;s user defined

2) What format is the texture attachment? Does the texture attachment have alpha?
yes

3) Anything out-of-ordinary with the framebuffer?
Nothing special RGBA unsigned byte buffer it is.
We go extra length to make sure the render is finished. (gl finisht etc.)

```

    var  canvasPixels = new Uint8Array(4 * width * height);
    var status = gl.checkFramebufferStatus(gl.FRAMEBUFFER);
    if (status !== gl.FRAMEBUFFER_COMPLETE) {
        return console.error(&apos;FRAMEBUFFER status invalid.&apos;, status);
    }
    gl.flush();
    gl.finish();
    gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, canvasPixels);
```</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1719585</commentid>
    <comment_count>4</comment_count>
    <who name="Kimmo Kinnunen">kkinnunen</who>
    <bug_when>2021-01-14 06:47:44 -0800</bug_when>
    <thetext>This is now fixed in trunk, but it&apos;s unclear which commit.

I tried to revert:
 - &quot;Enable some ANGLE workarounds on iOS&quot; (bug 220203)
 - &quot;Snapshots of WebGL content in the tab picker don&apos;t work (black map on Google M
aps)&quot; (bug 219946)

Neither of the above reproed the problem, though.

Marking as fixed. Please reopen if more info is needed.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1726006</commentid>
    <comment_count>5</comment_count>
    <who name="">paul</who>
    <bug_when>2021-02-05 04:45:55 -0800</bug_when>
    <thetext>somehow fixed if canvas is transparent, not if canvas is opaque

transparent canvas =&gt; 

https://jsfiddle.net/sketchfab/ej87khya/
for just embed test on ios https://jsfiddle.net/sketchfab/ej87khya/show


opaque canvas =&gt; 

https://jsfiddle.net/sketchfab/gw3xh29f/
for just embed test on ios https://jsfiddle.net/sketchfab/gw3xh29f/show

In sketchfab js webgl code, transparent/opaque canvas path implications are just that we enable the alpha option in the canvas context creation.

So it doesn&apos;t work if we switch that option &quot;off&quot;
here is out context creation code, with comment on the option switch (&quot;on&quot; it works, &quot;off&quot; it breaks, same exact code for the rest of application)


in our case, complete code is doesn&apos;t work with:

```
const gl = canvas.getContext(&apos;webgl&apos;, {
            powerPreference: &apos;high-performance&apos;,
            antialias: false, 
            depth: false,
            stencil: false,
            alpha: off, // &lt;= switching that off but rest exact same breaks screenshotting
            premultipliedAlpha: true,
            fullscreen: false,
            preserveDrawingBuffer: false
});
```</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>