I am trying to develop an Android app to process (in OpenCL) every frame of the camera preview. The preview is implemented with Android's GLSurfaceView and SurfaceTexture, which use OpenGL. My problem is that, from the JNI side, I don't know of a way to get hold of the OpenGL context.
I am trying to follow this excellent article, OpenCL and OpenGL Interoperability Tutorial, by Maxim Shevtsov of Intel. Maxim's article assumes that the reader has the OpenGL context already created, and that both the OpenGL context and HDC are available. That's a very good starting point for most people. However, that's where my challenges are.
The Java code that I use to create the OpenGL context is like this:
// SurfaceView
public class CamGLView extends GLSurfaceView
{
CamGLViewRenderer mRenderer;
CamGLView(Context context) {
super(context);
mRenderer = new CamGLViewRenderer(this);
setEGLContextClientVersion(3); //OpenGL context is created, but how to get hold of it from JNI side ?
setRenderer((Renderer)mRenderer);
setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
}
......
}
// Renderer
public class CamGLViewRenderer implements GLSurfaceView.Renderer, SurfaceTexture.OnFrameAvailableListener
{
@Override
public void onSurfaceCreated(GL10 unused, EGLConfig config) {
mSTexture = new SurfaceTexture(mTexID[0]);
if (null == mSTexture) {
Log.e(mTag, "Creating SurfaceTexture failed !");
return;
}
mSTexture.setOnFrameAvailableListener(this);
// Setup the camera preview
try {
mCamera.setPreviewTexture(mSTexture);
} catch(IOException ioe)
{
Log.e(mTag, "Camera.setPreviewTexture Error! " + ioe.getMessage());
ioe.printStackTrace();
return;
}
}
......
}
The Android app is up and running. The camera preview is displayed. Now on the JNI side, I want to grab each preview frame, send it to the OpenCL kernel to be processed, and then send it back to OpenGL to be displayed. To begin with, I need the OpenGL context on the JNI side.
Any ideas and thoughts to solve my problem?
Thank you very much