英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论