Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 5.0 GLKit GLKTextureLoader- where does glBindTexture happen?

Just have a quick question about GLKit in the iOS 5.0 framework.

If you use GLKTextureLoader, does it just load the texture in the currently active texture unit? I've looked at examples and I don't see anywhere that you have to say the GLKTextureInfo in variable x is bound to GL_TEXTURE0.

I've seen examples where people use glActiveTexture in conjunction with GLKTextureLoader, but it looks like the texture just automagically gets locked into the active texture unit. Once I load it, I just have to pass in texture coordinates?

Thanks in advance.

like image 788
robotpsyche Avatar asked Apr 07 '12 23:04

robotpsyche


2 Answers

Yes, there is some automagic going on. After loading a 2nd texture, that texture would then be bound to GL_TEXTURE0 but if you want it in GL_TEXTURE1:

glActiveTexture(GL_TEXTURE1);
glBindTexture(someTexture.target, someTexture.name);
glUniform1i(u_someSampler, 1); // u_someSampler retrieved from prev call to glGetUniformLocation
like image 34
aoakenfo Avatar answered Nov 15 '22 07:11

aoakenfo


After GLKTextureLoader loads your GLKTextureInfo object, then you're ready to bind the texture yourself. So when GLKLTextureLoader has finished loading, your loaded texture is not bound to any texture unit. When you're ready to draw, you call:

glActiveTexture(GL_TEXTURE0); // to specify texture unit 0
glBindTexture(textureInfo.target, textureInfo.name);

I would highly reccommend the book Learning OpenGL ES for iOS: A Hands-On Guide to Modern 3D Graphics Programming, as it does a great job of demonstrating what goes on inside the GLKit classes. You could also reference this demo code I wrote, which uses GLKTextureLoader: https://github.com/joekim/MobileMeetup/tree/master/GLKitDemo

like image 59
jankins Avatar answered Nov 15 '22 09:11

jankins