1

I'm copying a framebuffer to a pixel buffer object.

Is there a way during the call of gl.readPixels() to go from RGBA to only RED ?

In OpenGL, we can control the glReadPixels() transfer with glPixelTransfer(), but I can't find the couterpart in WebGL.

Is there a way to performs this ?

1 Answers1

2

It seems there isn't a way to do this. WebGL is based on OpenGL ES 3.0 (rather than full-blown desktop OpenGL). For OpenGL ES, glReadPixels is covered in section 4.3.2 of the standard (https://registry.khronos.org/OpenGL/specs/es/3.0/es_spec_3.0.pdf) and specifically states:

Only two combinations of format and type are accepted in most cases...

Unfortunately, GL_RED is not one of the guaranteed-to-be-supported values. As you noted, glPixelTransfer is not supported in GL-ES 3.0 either.

If you need to copy data from a framebuffer object to a buffer, you could possibly use a vertex shader that reads from the texture along with transform feedback, but that won't be as clean as a simple readPixels() call.

jh100
  • 416
  • 2
  • 7