[c3d] glReadPixels support

RESOLVED WORKSFORME

Status

()

Core
Canvas: WebGL
--
enhancement
RESOLVED WORKSFORME
9 years ago
6 years ago

People

(Reporter: Ilmari Heikkinen, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(2 attachments, 2 obsolete attachments)

(Reporter)

Description

9 years ago
User-Agent:       Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2a1pre) Gecko/20090226 Minefield/3.2a1pre
Build Identifier: 

There's no gl.readPixels in the canvas3d extension. readPixels is useful for reading from the currently bound framebuffer (not necessarily the visible image), which makes it useful for things like picking by unique color and reading back results of off-screen computation.

Reproducible: Always

Steps to Reproduce:
1. gl.readPixels(0,0,1,1, gl.RGBA, gl.UNSIGNED_BYTE)

Actual Results:  
Error, no method named readPixels.

Expected Results:  
Should return an ImageData object {width: 1, height: 1, data: [r,g,b,a]}.
(Reporter)

Comment 1

9 years ago
Created attachment 364311 [details] [diff] [review]
gl.readPixels implementation
(Reporter)

Comment 2

9 years ago
Created attachment 364312 [details]
Testcase for gl.readPixels

Renders to an FBO, reads from it and uses putImageData to draw the read image on a 2D canvas. Should have a large blank canvas on the left and a small canvas with a clipped downwards-pointing green rectangle on a yellow field.
(Reporter)

Comment 3

9 years ago
s/rectangle/triangle
(Reporter)

Comment 4

9 years ago
The above patch copies PRBool IsCallerTrustedForRead() over from nsContentUtils.cpp, as I had no luck with #include "nsContentUtils.h". If someone more familiar with the system manages to make the include work, they shall be praised, and the copied implementation removed.

Another issue is that glReadPixels returns an y-flipped image. I don't know if it should be flipped or left to user.

And I don't know if the data array pixel component order remains r,g,b,a on big-endian, so that should be tested.
Status: UNCONFIRMED → NEW
Ever confirmed: true
(Reporter)

Comment 5

9 years ago
Created attachment 365145 [details] [diff] [review]
Updated patch, uses CheckSaneSubrectSize from nsCanvasRenderingContext2D.cpp
Attachment #364311 - Attachment is obsolete: true
Attachment #365145 - Flags: review?(vladimir)
(Reporter)

Comment 6

9 years ago
Created attachment 365149 [details]
Updated test, as glReadPixels now errors on (0,0,0,0) like getImageData
Attachment #364312 - Attachment is obsolete: true
Component: Canvas: 2D → Canvas: WebGL
Closing FIXED as the WebGL support in Gecko does support a readPixels function.
Status: NEW → RESOLVED
Last Resolved: 8 years ago
Resolution: --- → FIXED

Updated

6 years ago
Resolution: FIXED → WORKSFORME

Updated

6 years ago
Attachment #365145 - Flags: review?(vladimir)
You need to log in before you can comment on or make changes to this bug.