title: Access an OpenGL texture as a CIImage
body: <p>I am trying to pass a reference of a cameras texture into xcode so that I can then use it for face detection. Most methods I have tried have left me stumped, but I think I am close with what I currently have.</p>
  
  <p>In unity I get the texture id and pass this through a plugin:</p>
  
  <pre><code>[DllImport("__Internal")]
  
  public static extern void SendBackground(int id, int width, int height);
  
  
  
  //in Update
  
  Texture bg_Img = GetComponentInChildren&lt;VideoTextureBehaviour&gt;().GetTexture(); //this is from Vuforia
  
  int texture_Id = bg_Img.GetNativeTextureID();
  
  SendBackground(texture_Id, bg_Img.width, bg_Img.height);
  </code></pre>
  
  <p>xcode receives the texture ID fine, I then try to access it from OpenGL and get it to a CIImage</p>
  
  <pre><code>- (void) DetectFaces:(int)tex_id :(int)width :(int)height
  
  {
  
      glGenTextures(1, (GLuint)&amp;tex_id);
  
      glBindTexture(GL_TEXTURE_2D, (GLuint)tex_id);
  
  
  
      CIImage *image = [[CIImage alloc]  initWithTexture:(GLuint)tex_id size:CGSizeMake(width, height) flipped:YES colorSpace: (CGColorSpaceRef) kCGColorSpaceModelRGB];
  
  }
  </code></pre>
  
  <p>Currently that last line results in a bad access exception at run time. I need to get the texture to CIImage so that I can then use the iOS native CIDetector code on it.</p>