Oolite 1.91.0.7645-241119-222d325
Loading...
Searching...
No Matches
OOConcreteTexture(Private) Category Reference

Instance Methods

(void) - setUpTexture
 
(void) - uploadTexture
 
(void) - uploadTextureDataWithMipMap:format:
 
(GLenum) - glTextureTarget
 
(BOOL) - isReloadable
 
(void) - forceRebind [implementation]
 

Detailed Description

Definition at line 54 of file OOConcreteTexture.m.

Method Documentation

◆ forceRebind

- (void) forceRebind
implementation

Extends class OOConcreteTexture.

Definition at line 671 of file OOConcreteTexture.m.

632{
633 if (_loaded && _uploaded && _valid)
634 {
636
637 _uploaded = NO;
638 OOGL(glDeleteTextures(1, &_textureName));
639 _textureName = 0;
640
641#if OOTEXTURE_RELOADABLE
642 if ([self isReloadable])
643 {
644 OOLog(@"texture.reload", @"Reloading texture %@", self);
645
646 free(_bytes);
647 _bytes = NULL;
648 _loaded = NO;
649 _uploaded = NO;
650 _valid = NO;
651
652 _loader = [[OOTextureLoader loaderWithPath:_path options:_options] retain];
653 }
654#endif
655 }
656}
#define OOLog(class, format,...)
Definition OOLogging.h:88
#define OO_ENTER_OPENGL()
#define OOGL(statement)
Definition OOOpenGL.h:251
id loaderWithPath:options:(NSString *path,[options] uint32_t options)

◆ glTextureTarget

- (GLenum) glTextureTarget

Extends class OOConcreteTexture.

Definition at line 671 of file OOConcreteTexture.m.

619{
620 GLenum texTarget = GL_TEXTURE_2D;
621#if OO_TEXTURE_CUBE_MAP
622 if (_isCubeMap)
623 {
624 texTarget = GL_TEXTURE_CUBE_MAP;
625 }
626#endif
627 return texTarget;
628}

◆ isReloadable

- (BOOL) isReloadable

Extends class OOConcreteTexture.

Definition at line 671 of file OOConcreteTexture.m.

662{
663 return _path != nil;
664}
return nil

◆ setUpTexture

- (void) setUpTexture

Extends class OOConcreteTexture.

Definition at line 671 of file OOConcreteTexture.m.

424{
425 OOPixMap pm;
426
427 // This will block until loading is completed, if necessary.
428 if ([_loader getResult:&pm format:&_format originalWidth:&_originalWidth originalHeight:&_originalHeight])
429 {
430 _bytes = pm.pixels;
431 _width = pm.width;
432 _height = pm.height;
433
434#if OO_TEXTURE_CUBE_MAP
435 if (_options & kOOTextureAllowCubeMap && _height == _width * 6 && gOOTextureInfo.cubeMapAvailable)
436 {
437 _isCubeMap = YES;
438 }
439#endif
440
441#if !defined(NDEBUG) && OOTEXTURE_RELOADABLE
442 if (_trace)
443 {
444 static unsigned dumpID = 0;
445 NSString *name = [NSString stringWithFormat:@"tex dump %u \"%@\"", ++dumpID,[self name]];
446 OOLog(@"texture.trace.dump", @"Dumped traced texture %@ to \'%@.png\'", self, name);
447 OODumpPixMap(pm, name);
448 }
449#endif
450
451 [self uploadTexture];
452 }
453 else
454 {
455 _textureName = 0;
456 _valid = NO;
457 _uploaded = YES;
458 }
459
460 _loaded = YES;
461
462 DESTROY(_loader);
463}
#define DESTROY(x)
Definition OOCocoa.h:77
void OODumpPixMap(OOPixMap pixMap, NSString *name)
Definition OOPixMap.m:145
@ kOOTextureAllowCubeMap
Definition OOTexture.h:61
OOTextureInfo gOOTextureInfo
Definition OOTexture.m:101
OOPixMapDimension height
Definition OOPixMap.h:50
void * pixels
Definition OOPixMap.h:49
OOPixMapDimension width
Definition OOPixMap.h:50
unsigned cubeMapAvailable

◆ uploadTexture

- (void) uploadTexture

Extends class OOConcreteTexture.

Definition at line 671 of file OOConcreteTexture.m.

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 // Select wrap mode
481 GLint clampMode = gOOTextureInfo.clampToEdgeAvailable ? GL_CLAMP_TO_EDGE : GL_CLAMP;
482 GLint wrapS = (_options & kOOTextureRepeatS) ? GL_REPEAT : clampMode;
483 GLint wrapT = (_options & kOOTextureRepeatT) ? GL_REPEAT : clampMode;
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 // Select min filter
497 filter = _options & kOOTextureMinFilterMask;
498 if (filter == kOOTextureMinFilterNearest) filter = GL_NEAREST;
499 else if (filter == kOOTextureMinFilterMipMap)
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
508 if (gOOTextureInfo.anisotropyAvailable && mipMap && 1.0 < _anisotropy)
509 {
510 OOGL(glTexParameterf(texTarget, GL_TEXTURE_MAX_ANISOTROPY_EXT, _anisotropy));
511 }
512#endif
513
514 // Select mag filter
515 filter = _options & kOOTextureMagFilterMask;
516 if (filter == kOOTextureMagFilterNearest) filter = GL_NEAREST;
517 else filter = GL_LINEAR;
518 OOGL(glTexParameteri(texTarget, GL_TEXTURE_MAG_FILTER, filter));
519
520 // if (gOOTextureInfo.clientStorageAvailable) EnableClientStorage();
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
543 if ([self isReloadable])
544 {
545 free(_bytes);
546 _bytes = NULL;
547 }
548#endif
549 }
550}
#define GL_CLAMP_TO_EDGE
@ kOOTextureRepeatS
Definition OOTexture.h:55
@ kOOTextureMagFilterMask
Definition OOTexture.h:73
@ kOOTextureMinFilterMask
Definition OOTexture.h:72
@ kOOTextureRepeatT
Definition OOTexture.h:56
@ kOOTextureMinFilterMipMap
Definition OOTexture.h:48
@ kOOTextureMagFilterNearest
Definition OOTexture.h:50
@ kOOTextureMinFilterNearest
Definition OOTexture.h:46
unsigned anisotropyAvailable
unsigned clampToEdgeAvailable

◆ uploadTextureDataWithMipMap:format:

- (void) uploadTextureDataWithMipMap: (BOOL) mipMap
format: (OOTextureDataFormat) format 

Extends class OOConcreteTexture.

Definition at line 671 of file OOConcreteTexture.m.

553 :(BOOL)mipMap format:(OOTextureDataFormat)format
554{
555 GLenum glFormat = 0, internalFormat = 0, type = 0;
556 unsigned w = _width,
557 h = _height,
558 level = 0;
559 char *bytes = _bytes;
560 uint8_t components = OOTextureComponentsForFormat(format);
561
563
564 if (!DecodeFormat(format, _options, &glFormat, &internalFormat, &type)) return;
565
566 while (0 < w && 0 < h)
567 {
568 OOGL(glTexImage2D(GL_TEXTURE_2D, level++, internalFormat, w, h, 0, glFormat, type, bytes));
569 if (!mipMap) return;
570 bytes += w * components * h;
571 w >>= 1;
572 h >>= 1;
573 }
574
575 // Note: we only reach here if (mipMap).
576 _mipLevels = level - 1;
577 OOGL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, _mipLevels));
578}
static BOOL DecodeFormat(OOTextureDataFormat format, uint32_t options, GLenum *outFormat, GLenum *outInternalFormat, GLenum *outType)
OOPixMapFormat
Definition OOPixMap.h:39
#define GL_TEXTURE_MAX_LEVEL
uint8_t OOTextureComponentsForFormat(OOTextureDataFormat format)
Definition OOTexture.m:667

The documentation for this category was generated from the following file: