glTexSubImage2D - > GL_INVALID_OPERATION

时间:2012-03-08 11:59:37

标签: ios opengl-es-2.0 augmented-reality

为什么glTexSubImage2D()突然导致GL_INVALID_OPERATION?

我正在尝试将我无望的过时的增强现实应用程序从iOS4.x升级到iOS5.x,但我遇到了困难。我运行iOS5.0。上周我跑了iOS4.3。我的设备是iPhone4。


以下是我的captureOutput:didOutputSampleBuffer:fromConnection:代码

中的代码段
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(); -> returns 0x0502 GL_INVALID_OPERATION on iOS5.0, works fine on iOS4.x */

以下是我的设置代码

的摘录
GLuint texture = /* the texture name */
glGenTextures(1, &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);

为简单起见,我在此处插入了硬编码值。在我的实际代码中,我使用CVPixelBufferGetWidth / Height / BaseAddress获取这些值。使用kEAGLRenderingAPIOpenGLES2初始化EAGLContext。

1 个答案:

答案 0 :(得分:6)

啊..我在发布这个问题后立即修好了。不得不将GL_RGBA改为GL_BRGA。

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 512, 512, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);

希望它有所帮助。

顺便说一句。如果您想编写AR应用,请考虑使用CVOpenGLESTextureCache而不是glTexSubImage2d。它应该更快。

相关问题