[英]android read pixels from GL_TEXTURE_EXTERNAL_OES
I am trying to read pixels/data from an OpenGL texture which is bound to GL_TEXTURE_EXTERNAL_OES. 我试图从一个绑定到GL_TEXTURE_EXTERNAL_OES的OpenGL纹理中读取像素/数据。
The reason for binding the texture to that target is because in order get live camera feed on android a SurfaceTexture needs to be created from an OpenGL texture which is bound to GL_TEXTURE_EXTERNAL_OES. 将纹理绑定到该目标的原因是因为为了获得Android上的实时相机源,需要从绑定到GL_TEXTURE_EXTERNAL_OES的OpenGL纹理创建SurfaceTexture。
Since android uses OpenGL ES I can't use glGetTexImage() to read the image data. 由于android使用OpenGL ES,我无法使用glGetTexImage()来读取图像数据。
Therefore I am binding the target to an FBO and then reading it using readPixels(). 因此,我将目标绑定到FBO,然后使用readPixels()读取它。 This is my code:
这是我的代码:
GLuint framebuffer;
glGenFramebuffers(1, &framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
//Attach 2D texture to this FBO
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_EXTERNAL_OES, cameraTexture, 0);
status("glFramebufferTexture2D() returned error %d", glGetError());
However I am getting error 1282 (GL_INVALID_OPERATION) for some reason. 但是由于某种原因我收到错误1282(GL_INVALID_OPERATION)。
I think this might be the problem: 我想这可能是问题所在:
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_EXTERNAL_OES, cameraTexture, 0);
You should not attach the cameraTexture to the framebuffer, instead you should generate a new texture in the format of GL_TEXTURE_2D 你不应该将cameraTexture附加到帧缓冲区,而应该生成格式为GL_TEXTURE_2D的新纹理。
glGenTextures(1, mTextureHandle, 0);
glBindTexture(GL_TEXTURE_2D, mTextureHandle[0]);
...
cameraTexture is the one you get from SurfaceTexture, and it is the source used for rendering. cameraTexture是您从SurfaceTexture获得的,它是用于渲染的源。 This new texture is the one you should render to (which could be used later in the rendering pipeline).
这个新纹理是你应该渲染的纹理(可以在以后的渲染管道中使用)。 Then do this:
然后这样做:
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, mTextureHandle[0], 0);
cameraTexture is drawn to the framebuffer's attached texture, using a simple shader program to draw, bind the cameraTexture when the shader program is in use: cameraTexture被绘制到framebuffer的附加纹理,使用简单的着色器程序绘制,在着色器程序使用时绑定cameraTexture:
glBindTexture(GL_TEXTURE_EXTERNAL_OES, cameraTexture);
The GL_TEXTURE_EXTERNAL_OES texture target is usually in a YUV color space and glReadPixels() requires the target to be RGB. GL_TEXTURE_EXTERNAL_OES纹理目标通常位于YUV颜色空间中,glReadPixels()要求目标为RGB。 It probably does not do the color space conversion automatically.
它可能不会自动进行色彩空间转换。 However, you could do the conversion in your own fragment shader which renders RGB into another texture and then use glReadPixels() to read that.
但是,您可以在自己的片段着色器中进行转换,该着色器将RGB渲染为另一个纹理,然后使用glReadPixels()来读取它。
texture for YUV420 to RGB conversion in OpenGL ES 在OpenGL ES中进行YUV420到RGB转换的纹理
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.