title: Grabbing SurfaceTexture's GL context from NDK
body: <p><strong>Purpose :</strong> 
  I'm using <code>SurfaceTexture</code> for displaying the camera preview, and need to draw on top of surface by acquiring GL context from NDK. I've chosen <code>SurfaceTexture</code> approach as I can avoid camera frame buffer's manual passing from java to NDK, to save some performance.</p>
  
  <pre><code>public class MainActivity extends Activity implements SurfaceTextureListener {
  
  private Camera mCamera;
  private TextureView mTextureView;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      mTextureView = new TextureView(this);
      mTextureView.setSurfaceTextureListener(this);
  
      setContentView(mTextureView);
  }
  
  @Override
  public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
      mCamera = Camera.open();
      Camera.Size previewSize = mCamera.getParameters().getPreviewSize();
      mTextureView.setLayoutParams(new FrameLayout.LayoutParams(previewSize.width, previewSize.height, Gravity.CENTER));
  
      try {
          mCamera.setPreviewTexture(surface);
      } catch (IOException t) {
      }
  
      mCamera.startPreview();
  }
  
  @Override
  public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
      // Ignored, the Camera does all the work for us
  }
  
  @Override
  public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
      mCamera.stopPreview();
      mCamera.release();
      return true;
  }
  
  @Override
  public void onSurfaceTextureUpdated(SurfaceTexture surface) {
      // Update your view here
  }
  </code></pre>
  
  <p><strong>What I've tried :</strong>
  I suppose <code>SurfaceTexture</code> internally uses GL functionality for drawing the context. From NDK getting the default display fails with <code>BAD_DISPLAY</code> error.</p>
  
  <pre><code>EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
  </code></pre>
  
  <p>Of course I'm able to initialize a new GL context and do my drawing but still I want to keep the texture displayed from java code in background.</p>
  
  <p><strong>Question :</strong> Is it possible at all to grab the GL context from NDK when using <code>SurfaceTexture</code> ? 
  Probably I have to use on <code>GLSurfaceView</code>, initialize GL context manually from java code and grab it from NDK ?</p>