为什么来自 PBO 的 glReadPixel GL_RGB 出现错误 0x502 INVALD OPTION

why glReadPixel GL_RGB from PBO got error 0x502 INVALD OPTION

我看到了

format specifies the format of the returned pixel values; accepted values are:

GL_ALPHA GL_RGB GL_RGBA RGBA color components are read from the color buffer. Each color component is converted to floating point such that zero intensity maps to 0.0 and full intensity maps to 1.0.

Unneeded data is then discarded. For example, GL_ALPHA discards the red, green, and blue components, while GL_RGB discards only the alpha component. GL_LUMINANCE computes a single-component value as the sum of the red, green, and blue components, and GL_LUMINANCE_ALPHA does the same, while keeping alpha as a second value. The final values are clamped to the range [0, 1]."

https://www.khronos.org/opengles/sdk/1.1/docs/man/glReadPixels.xml

使用GL_RGBA效果很好。但是如果我改变

glReadPixelsPBOJNI(0, 0, width, height, GLES30.GL_RGBA, GLES30.GL_UNSIGNED_BYTE, 0);

glReadPixelsPBOJNI(0, 0, width, height, GLES30.GL_RGB, GLES30.GL_UNSIGNED_BYTE, 0);

0x502得到。这有什么问题吗?

我的代码在这里:

GL_RGB 在 OpenGL ES 中通常不支持作为 glReadPixels() 的格式。来自 ES 3.0 规范:

Only two combinations of format and type are accepted in most cases. The first varies depending on the format of the currently bound rendering surface. For normalized fixed-point rendering surfaces, the combination format RGBA and type UNSIGNED_BYTE is accepted. [..]

The second is an implementation-chosen format from among those defined in table 3.2, excluding formats DEPTH_COMPONENT and DEPTH_STENCIL. The values of format and type for this format may be determined by calling GetIntegerv with the symbolic constants IMPLEMENTATION_COLOR_READ_FORMAT and IMPLEMENTATION_COLOR_READ_TYPE, respectively.

因此,除非您查询 implementation-chosen 格式,并且它返回为 GL_RGB,否则您不能使用 GL_RGB。唯一可以在任何地方使用的格式是 GL_RGBA.

您找到的手册页中的引述看起来像是一个简单的错误。如果您查看列出参数的顶部,它不会将 GL_RGB 列为在 格式 下有效。因此,该页面上的信息显然不一致。手册页中的错误很常见。如有疑问,您必须查看规范文档以获取更多决定性信息。