How to grab the OpenGL context created by Android's GLSurfaceView?

How to grab the OpenGL context created by Android's GLSurfaceView?

Hello Intel engineers and fellow Intel developers (and Maxim Shevtsov specifically):

I've always liked the high-quality and hands-on tutorials/application notes written by Intel engineers. Now I am trying to follow the excellent article, OpenCL and OpenGL Interoperability Tutorial, by Maxim Shevtsov, and would like to ask a question.

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.

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, with the code like this:

public class CamGLView extends GLSurfaceView
    CamGLViewRenderer mRenderer;

    CamGLView(Context context) {
        mRenderer = new CamGLViewRenderer(this);
        setEGLContextClientVersion(3);  //OpenGL context is created, but how to get hold of it from JNI side ?

public class CamGLViewRenderer implements GLSurfaceView.Renderer, SurfaceTexture.OnFrameAvailableListener
    public void onSurfaceCreated(GL10 unused, EGLConfig config) {
        mSTexture = new SurfaceTexture(mTexID[0]);
        if (null == mSTexture) {
            Log.e(mTag, "Creating SurfaceTexture failed !");

        // Setup the camera preview
        try {
        } catch(IOException ioe) {
            Log.e(mTag, "Camera.setPreviewTexture Error! " + ioe.getMessage());

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. Maxim's article perfectly fits my application, except that I don't know a way to get the OpenGL context, created by the Java code, to begin with.

Any ideas and thoughts to solve my problem? 

Thank you very much,


2 posts / 0 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.
Portrait de Robert Ioffe (Intel)

Take a look at this article:

I haven't tried it, but it my help solve the issue: it shows the same context created on the C++ and Java side of things.

Connectez-vous pour laisser un commentaire.