Quantcast
Channel: Опыт пользователя и дизайн
Viewing all articles
Browse latest Browse all 360

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

$
0
0

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) {

        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);

    }

    ......

}

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. 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,

Robby


Viewing all articles
Browse latest Browse all 360

Trending Articles