WebGL在gl.readPixels()期间的颜色转换

huangapple go评论62阅读模式
英文:

WebGL color conversion during gl.readPixels()

问题

我正在将帧缓冲复制到像素缓冲对象。

在调用gl.readPixels()期间,是否有办法从RGBA转换为仅红色?

在OpenGL中,我们可以使用glPixelTransfer()控制glReadPixels()传输,但我在WebGL中找不到对应的部分。

有办法执行这个操作吗?

英文:

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

得分: 2

似乎没有办法做到这一点。WebGL基于OpenGL ES 3.0(而不是完整的桌面OpenGL)。对于OpenGL ES,glReadPixels在标准的4.3.2节中有详细说明(https://registry.khronos.org/OpenGL/specs/es/3.0/es_spec_3.0.pdf),并明确规定:

> 在大多数情况下只有两种格式和类型的组合被接受...

不幸的是,GL_RED不是保证支持的值之一。正如你所指出的,GL-ES 3.0中也不支持glPixelTransfer。

如果需要从帧缓冲对象复制数据到缓冲区,可能可以使用从纹理读取数据以及变换反馈的顶点着色器,但这不会像简单的readPixels()调用那样干净。

英文:

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.

huangapple
  • 本文由 发表于 2023年3月9日 20:50:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/75684875.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定