467{
468 GLint filter;
469 BOOL mipMap = NO;
470
472
473 if (!_uploaded)
474 {
475 GLenum texTarget = [self glTextureTarget];
476
477 OOGL(glGenTextures(1, &_textureName));
478 OOGL(glBindTexture(texTarget, _textureName));
479
480
484
485#if OO_TEXTURE_CUBE_MAP
486 if (texTarget == GL_TEXTURE_CUBE_MAP)
487 {
488 wrapS = wrapT = clampMode;
489 OOGL(glTexParameteri(texTarget, GL_TEXTURE_WRAP_R, clampMode));
490 }
491#endif
492
493 OOGL(glTexParameteri(texTarget, GL_TEXTURE_WRAP_S, wrapS));
494 OOGL(glTexParameteri(texTarget, GL_TEXTURE_WRAP_T, wrapT));
495
496
500 {
501 mipMap = YES;
502 filter = GL_LINEAR_MIPMAP_LINEAR;
503 }
504 else filter = GL_LINEAR;
505 OOGL(glTexParameteri(texTarget, GL_TEXTURE_MIN_FILTER, filter));
506
507#if GL_EXT_texture_filter_anisotropic
509 {
510 OOGL(glTexParameterf(texTarget, GL_TEXTURE_MAX_ANISOTROPY_EXT, _anisotropy));
511 }
512#endif
513
514
517 else filter = GL_LINEAR;
518 OOGL(glTexParameteri(texTarget, GL_TEXTURE_MAG_FILTER, filter));
519
520
521
522 if (texTarget == GL_TEXTURE_2D)
523 {
524 [self uploadTextureDataWithMipMap:mipMap format:_format];
525 OOLog(
@"texture.upload",
@"Uploaded texture %u (%ux%u pixels, %@)", _textureName, _width, _height, _key);
526 }
527#if OO_TEXTURE_CUBE_MAP
528 else if (texTarget == GL_TEXTURE_CUBE_MAP)
529 {
530 [self uploadTextureCubeMapDataWithMipMap:mipMap format:_format];
531 OOLog(
@"texture.upload",
@"Uploaded cube map texture %u (%ux%ux6 pixels, %@)", _textureName, _width, _width, _key);
532 }
533#endif
534 else
535 {
536 [NSException raise:NSInternalInconsistencyException format:@"Unhandled texture target 0x%X.", texTarget];
537 }
538
539 _valid = YES;
540 _uploaded = YES;
541
542#if OOTEXTURE_RELOADABLE
544 {
545 free(_bytes);
546 _bytes = NULL;
547 }
548#endif
549 }
550}
@ kOOTextureMagFilterMask
@ kOOTextureMinFilterMask
@ kOOTextureMinFilterMipMap
@ kOOTextureMagFilterNearest
@ kOOTextureMinFilterNearest
unsigned anisotropyAvailable
unsigned clampToEdgeAvailable