glReadPixels and GL_ALPHA
I'm trying to read the alpha pixel values using glRead开发者_Python百科Pixels. The first thing I did was read the pixels individually. To try to speed things up, I tried reading all the pixels at once :
GLubyte *pixels = new GLubyte[w*h*4];
glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
and it worked, but really slow. Now I'm trying to just retrieve the alpha value, without wasting space to the RGB components :
GLubyte *pixels = new GLubyte[w*h];
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadPixels(0, 0, w, h, GL_ALPHA, GL_UNSIGNED_BYTE, pixels);
But I get : OpenGL error 0x0500 in -[EAGLView swapBuffers]
.
Any idea as to why a INVALID_ENUM (0x0500)
is thrown?
According to the documentation on glReadPixels() for OpenGL ES, the only valid enum values for the format parameter are GL_RGBA
and GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES
. You'd need to check and see what GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES
means as a format for the iPhone, but it may not provide support for GL_ALPHA
.
In any case, I doubt that going that route will dramatically speed up your reads, because all that will do is discard the RGB components. Your performance issues with glReadPixels() probably lie elsewhere. A good discussion of the reasons for this can be found in the discussion thread here.
Would it be possible for you to render into an offscreen framebuffer that was backed by a texture, then do further processing on the GPU using that texture? This sounds like it would yield better performance than using glReadPixels()
.
精彩评论