title: glTexSubImage2D -> GL_INVALID_OPERATION
body: <p><strong>Why is <a href="http://www.opengl.org/sdk/docs/man/xhtml/glTexSubImage2D.xml" rel="nofollow">glTexSubImage2D()</a> suddenly causing GL_INVALID_OPERATION?</strong></p>
  
  <p>I'm trying to upgrade my hopelessly outdated augmented reality app from iOS4.x to iOS5.x, but I'm having difficulties. I run iOS5.0. Last week I ran iOS4.3. My device is an iPhone4.</p>
  
  <hr>
  
  <p>Here is a snippet from my <code>captureOutput:didOutputSampleBuffer:fromConnection:</code> code</p>
  
  <pre><code>uint8_t *baseAddress = /* pointer to camera buffer */
  GLuint texture = /* the texture name */
  glBindTexture(GL_TEXTURE_2D, texture);
  glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 480, 360, GL_BGRA, GL_UNSIGNED_BYTE, baseAddress);
  /* now glGetError(); -&gt; returns 0x0502 GL_INVALID_OPERATION on iOS5.0, works fine on iOS4.x */
  </code></pre>
  
  <hr>
  
  <p>Here is a snippet from my setup code</p>
  
  <pre><code>GLuint texture = /* the texture name */
  glGenTextures(1, &amp;texture);
  glActiveTexture(GL_TEXTURE0);
  glBindTexture(GL_TEXTURE_2D, texture);
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); 
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); 
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
  </code></pre>
  
  <hr>
  
  <p>For simplicity I have inserted hardcoded values here. In my actual code I obtain these values with CVPixelBufferGetWidth/Height/BaseAddress. The EAGLContext is initialized with kEAGLRenderingAPIOpenGLES2.</p>