问题
I am working with a GLSurfaceView
activity to display the camera frame on an android device. As I am newb in OpenGl Es
, I wondered how I can get the image buffer and modify it, then display the modified frame on the phone?
In my Renderer class which implements GLSurfaceView.Renderer
, I call a native function:
public class Renderer implements GLSurfaceView.Renderer {
public void onDrawFrame(GL10 gl) {
MyJNINative.render();
}
...
}
The API
I am working with, provided a connectCallBack
method that enables accessing image buffer via something like onFrameAvailableNow
.
So I have already the image buffer which is unfortunately of const
type. So my modifications to it will not get reflected.
Now my question is how to add some gl
methods to modify the image buffer that can be reflected on the display?
My native renderer:
Java_com_project_MyJNINative_render(
JNIEnv*, jobject) {
// Let's say I have image buffer here called "uint_8t* buffer"
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glViewport(0, 0, width, height);
// UpdateTexture()
api_handler.UpdateTexture());
gl_vid_obj->Render(glm::mat4(1.0f), glm::mat4(1.0f));
/// I NEED SOME CODE HERE TO set gl buffer
}
回答1:
As fadden explained, you cannot change the preview buffer that is connected to SurfaceTexture. But you can obtain the preview buffers with onPreviewFrame(), modify it and push the result to OpenGL via glTexSubImage2D(). There are two pitfalls: you should hide the actual preview (probably connecting it to a texture that will not be visible on your GL surface), and you should do all processing fast enough (20 FPS at least for the "preview" to look natural).
来源:https://stackoverflow.com/questions/31359081/modify-and-update-camera-frame-via-glsurfaceview