ios – glGenTextures返回现有纹理名称
具体来说,在初始化时,我遍历我的纹理并让OpenGL知道它们,如下所示:
// Generate the OpenGL texture objects for (Object3D *object3D in self.objects3D) { [self installIntoOpenGLObject3D:object3D]; } - (void)installIntoOpenGLObject3D:(Object3D *)object3D { GLuint nID; glGenTextures(1,&nID); Texture *texture = object3D.texture; texture.identifier = nID; glBindTexture(GL_TEXTURE_2D,nID); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,GL_RGBA,[texture width],[texture height],GL_UNSIGNED_BYTE,(GLvoid*)[texture pngData]); ARLogInfo(@"Installed texture '%@' with OpenGL identifier %d",texture.name,texture.identifier); }
这时,我看到了纹理名称,如1,2,3,…… n.
但是,稍后(异步网络调用返回后)我创建新纹理并调用installIntoOpenGLObject3D:安装它们.正是在这个时候,我看到glGenTextures返回之前发布的名字.显然,这会导致应用程序呈现不正确的纹理.
文档http://www.khronos.org/opengles/sdk/docs/man/xhtml/glGenTextures.xml表明:
Texture names returned by a call to glGenTextures are not returned by subsequent calls,unless they are first deleted with glDeleteTextures.
而且我没有调用glDeleteTextures;但是文档也说:
it is guaranteed that none of the returned names was in use immediately before the call to glGenTextures.
这是令人困惑的,因为它暗示如果它们没有“使用”,返回的名称可能是相同的.据我所知,通过调用glBindTexture纹理来满足“使用中”的概念,但是,有些事情是错误的.
我的另一个想法可能是EAGLContext正在改变第一组调用glGenTextures之间的某个地方,唉,在调试器中单步调试告诉我上下文没有改变.
作为一个(也许是愚蠢的)黑客的
解决方法
,我试图确保纹理名称本身就是独一无二的,正如你在下面看到的那样,但是我最终得到了一个我不跟踪的纹理名称,但仍然代表了不同的纹理,所以这个方法不提供解决方法
:- (void)installIntoOpenGLObject3D:(Object3D *)object3D { if (!self.object3DTextureIdentifiers) { self.object3DTextureIdentifiers = [NSMutableSet set]; } GLuint nID; NSNumber *idObj; do { glGenTextures(1,&nID); GLboolean isTexture = glIsTexture(nID); idObj = [NSNumber numberWithUnsignedInt:nID]; } while ([self.object3DTextureIdentifiers containsObject:idObj]); [self.object3DTextureIdentifiers addObject:idObj]; Texture *texture = object3D.texture; texture.identifier = nID; glBindTexture(GL_TEXTURE_2D,texture.identifier); }
有关为什么glGenTextures返回之前返回的名称的任何想法?
解决方法
虽然我确定glGenTextures只是从一个线程(main)调用,但事实证明,调用其他OpenGL方法是在另一个线程上调用的.重构所以对glGenTextures的调用也只发生在其他线程(not-main)似乎解决了这个问题.
以上是来客网为你收集整理的ios – glGenTextures返回现有纹理名称全部内容,希望文章能够帮你解决ios – glGenTextures返回现有纹理名称所遇到的程序开发问题。
如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。