我正在使用SurfaceTexture进行实时相机预览 . 这将数据流作为纹理直接发送到GPU .
每个新相机框架都会覆盖此纹理 .
Now - I want to avoid this overwriting and retain last several(n) previous frames in the memory (which is my ultimate goal here)
来自相机的数据总是会覆盖可用n种纹理中最古老的纹理 . 我只需要在它们之间交替 .
当数据进入时,这些纹理需要立即呈现 .
我不需要:将捕获的数据保存为字节缓冲区并将其转换回新的纹理=慢,所有都必须是实时的 . 性能是关键 .
我使用此程序示例在surfaceTexture模式下运行相机:http://maninara.blogspot.co.uk/2012/09/render-camera-preview-using-opengl-es.html
我试图使用SurfaceTexture类的attachToGLContext(int texName)方法附加一个新纹理,但它似乎不允许我这样做而不破坏前一个,似乎我必须在附加一个新的之前使用“detachFromGLContext()” ..
http://developer.android.com/reference/android/graphics/SurfaceTexture.html
任何帮助赞赏 .
1 回答
如何将数据流发送到纹理?
在我的例子中,我在
onSurfaceCreated
中创建了多个纹理 . 然后在onDraw
中覆盖它们 . 整个过程是实时的,不需要帧缓冲来存储数据 .在
onDraw
中,我使用glActiveTexture
和glBindTexture
来选择我想要覆盖的纹理 . 这是代码,希望它有所帮助 .GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + texture_index); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, m_texture[texture_index]); GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, m_frame.width, m_frame.height, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, camera_data);