32

In my iOS app (targeted for iPad), I'd like to use non power of two (NPT) textures. My GL_VERSION query returns "OpenGL ES 2.0 APPLE". According to the spec, it should support NPT textures, but a simple test shows that I need to resize the texture to 2^N before it shows up.

Does Apple not support the full ES 2.0 spec? Where can I find documentation on what is not supported?

I am using Xcode 4.3.2 and iOS 5.1.

Edit:

A closer look at the ES 2.0.25 spec (section 3.8.2), reveals that there are a few conditions to be met for NPOT to work. Essentially if I use the settings below, I am able to load NPOT textures:

// use linear filetring
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); 
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
// clamp to edge
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

Should I close this or answer my own question?

genpfault
  • 51,148
  • 11
  • 85
  • 139
M-V
  • 5,167
  • 7
  • 52
  • 55
  • 3
    No need to close the question, you can just compose the answer and accept it. It could potentially be helpful to someone else one day. – Tim Jun 17 '12 at 08:10
  • I remember a same question and answer few days ago. This is a frequent topic. – Luca Jun 17 '12 at 13:29

2 Answers2

27

As mentioned in my edit, I found the solution. NPOT on ES 2.0 requires that you use linear filtering and clamp to edge. Also, no mipmaps.

M-V
  • 5,167
  • 7
  • 52
  • 55
  • Also check the `GL_APPLE_texture_2D_limited_npot` extension to make sure it is supported. – Tim R. Aug 02 '12 at 06:38
  • 1
    It works with GL_NEAREST as min/mag filter for me on ios7. GL_CLAMP_TO_EDGE was the issue. – Martin May 19 '14 at 12:31
  • 1
    @Martin Could you share an snippet on how to draw a non-power of two texture under iOS? I'm trying to do it, but I can only display a white image: https://gist.github.com/anonymous/53307d146d3d1a750554 – amb Aug 27 '14 at 13:32
0
- (BOOL)isSupportNPOT {
//    GL_OES_texture_npot
//    GL_APPLE_texture_2D_limited_npot
//    GL_ARB_texture_non_power_of_two
    EAGLContext *context_ = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
    [EAGLContext setCurrentContext:context_];
    NSArray *extensionNames = nil;
    NSString *extensionsString = [NSString stringWithCString:(const char *)glGetString(GL_EXTENSIONS) encoding:NSASCIIStringEncoding];
    extensionNames = [extensionsString componentsSeparatedByString:@" "];
    BOOL isSupport = [extensionNames containsObject:@"GL_APPLE_texture_2D_limited_npot"];
    [EAGLContext setCurrentContext:nil];
    NSLog(@"Apple Opengl support NPOT is %@", isSupport ? @"YES" : @"NO");
    return isSupport;
}
jeff
  • 142
  • 7