Oolite
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 50 of file OOConcreteTexture.m.

Method Documentation

◆ forceRebind

- (void) forceRebind
implementation

Extends class OOConcreteTexture.

Definition at line 573 of file OOConcreteTexture.m.

574{
575 if (_loaded && _uploaded && _valid) {
577
578 _uploaded = NO;
579 OOGL(glDeleteTextures(1, &_textureName));
580 _textureName = 0;
581
582#if OOTEXTURE_RELOADABLE
583 if ([self isReloadable]) {
584 OOLog(@"texture.reload", @"Reloading texture %@", self);
585
586 free(_bytes);
587 _bytes = NULL;
588 _loaded = NO;
589 _uploaded = NO;
590 _valid = NO;
591
592 _loader = [[OOTextureLoader loaderWithPath:_path options:_options] retain];
593 }
594#endif
595 }
596}
#define OOLog(class, format,...)
Definition OOLogging.h:84
#define OO_ENTER_OPENGL()
#define OOGL(statement)
Definition OOOpenGL.h:262
id loaderWithPath:options:(NSString *path,[options] uint32_t options)

References forceRebind, isReloadable, OOTextureLoader::loaderWithPath:options:, OO_ENTER_OPENGL, OOGL, and OOLog.

Referenced by forceRebind.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ glTextureTarget

- (GLenum) glTextureTarget

Extends class OOConcreteTexture.

Definition at line 562 of file OOConcreteTexture.m.

563{
564 GLenum texTarget = GL_TEXTURE_2D;
565#if OO_TEXTURE_CUBE_MAP
566 if (_isCubeMap) {
567 texTarget = GL_TEXTURE_CUBE_MAP;
568 }
569#endif
570 return texTarget;
571}

References glTextureTarget.

Referenced by glTextureTarget.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isReloadable

- (BOOL) isReloadable

Extends class OOConcreteTexture.

Definition at line 600 of file OOConcreteTexture.m.

601{
602 return _path != nil;
603}
return nil

References isReloadable, and nil.

Referenced by forceRebind, isReloadable, and uploadTexture.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setUpTexture

- (void) setUpTexture

Extends class OOConcreteTexture.

Definition at line 381 of file OOConcreteTexture.m.

382{
383 OOPixMap pm;
384
385 // This will block until loading is completed, if necessary.
386 if ([_loader getResult:&pm format:&_format originalWidth:&_originalWidth originalHeight:&_originalHeight]) {
387 _bytes = pm.pixels;
388 _width = pm.width;
389 _height = pm.height;
390
391#if OO_TEXTURE_CUBE_MAP
392 if (_options & kOOTextureAllowCubeMap && _height == _width * 6 && gOOTextureInfo.cubeMapAvailable) {
393 _isCubeMap = YES;
394 }
395#endif
396
397#if defined(OO_DEBUG_MONITOR_ENABLED) && OOTEXTURE_RELOADABLE
398 if (_trace) {
399 static unsigned dumpID = 0;
400 NSString* name = [NSString stringWithFormat:@"tex dump %u \"%@\"", ++dumpID, [self name]];
401 OOLog(@"texture.trace.dump", @"Dumped traced texture %@ to \'%@.png\'", self, name);
402 OODumpPixMap(pm, name);
403 }
404#endif
405
406 [self uploadTexture];
407 } else {
408 _textureName = 0;
409 _valid = NO;
410 _uploaded = YES;
411 }
412
413 _loaded = YES;
414
415 DESTROY(_loader);
416}
#define DESTROY(x)
void OODumpPixMap(OOPixMap pixMap, NSString *name)
Definition OOPixMap.m:140
struct OOPixMap OOPixMap
@ kOOTextureAllowCubeMap
Definition OOTexture.h:61
OOTextureInfo gOOTextureInfo
Definition OOTexture.m:97
OOPixMapDimension height
Definition OOPixMap.h:45
void * pixels
Definition OOPixMap.h:44
OOPixMapDimension width
Definition OOPixMap.h:45
unsigned cubeMapAvailable

References DESTROY, gOOTextureInfo, OOPixMap::height, kOOTextureAllowCubeMap, OODumpPixMap(), OOLog, OOPixMap::pixels, setUpTexture, OOConcreteTexture::uploadTexture, and OOPixMap::width.

Referenced by setUpTexture.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ uploadTexture

- (void) uploadTexture

Extends class OOConcreteTexture.

Definition at line 418 of file OOConcreteTexture.m.

419{
420 GLint filter;
421 BOOL mipMap = NO;
422
424
425 if (!_uploaded) {
426 GLenum texTarget = [self glTextureTarget];
427
428 OOGL(glGenTextures(1, &_textureName));
429 OOGL(glBindTexture(texTarget, _textureName));
430
431 // Select wrap mode
432 GLint clampMode = gOOTextureInfo.clampToEdgeAvailable ? GL_CLAMP_TO_EDGE : GL_CLAMP;
433 GLint wrapS = (_options & kOOTextureRepeatS) ? GL_REPEAT : clampMode;
434 GLint wrapT = (_options & kOOTextureRepeatT) ? GL_REPEAT : clampMode;
435
436#if OO_TEXTURE_CUBE_MAP
437 if (texTarget == GL_TEXTURE_CUBE_MAP) {
438 wrapS = wrapT = clampMode;
439 OOGL(glTexParameteri(texTarget, GL_TEXTURE_WRAP_R, clampMode));
440 }
441#endif
442
443 OOGL(glTexParameteri(texTarget, GL_TEXTURE_WRAP_S, wrapS));
444 OOGL(glTexParameteri(texTarget, GL_TEXTURE_WRAP_T, wrapT));
445
446 // Select min filter
447 filter = _options & kOOTextureMinFilterMask;
448 if (filter == kOOTextureMinFilterNearest)
449 filter = GL_NEAREST;
450 else if (filter == kOOTextureMinFilterMipMap) {
451 mipMap = YES;
452 filter = GL_LINEAR_MIPMAP_LINEAR;
453 } else
454 filter = GL_LINEAR;
455 OOGL(glTexParameteri(texTarget, GL_TEXTURE_MIN_FILTER, filter));
456
457#if GL_EXT_texture_filter_anisotropic
458 if (gOOTextureInfo.anisotropyAvailable && mipMap && 1.0 < _anisotropy) {
459 OOGL(glTexParameterf(texTarget, GL_TEXTURE_MAX_ANISOTROPY_EXT, _anisotropy));
460 }
461#endif
462
463 // Select mag filter
464 filter = _options & kOOTextureMagFilterMask;
465 if (filter == kOOTextureMagFilterNearest)
466 filter = GL_NEAREST;
467 else
468 filter = GL_LINEAR;
469 OOGL(glTexParameteri(texTarget, GL_TEXTURE_MAG_FILTER, filter));
470
471 // if (gOOTextureInfo.clientStorageAvailable) EnableClientStorage();
472
473 if (texTarget == GL_TEXTURE_2D) {
474 [self uploadTextureDataWithMipMap:mipMap format:_format];
475 OOLog(@"texture.upload", @"Uploaded texture %u (%ux%u pixels, %@)", _textureName, _width, _height, _key);
476 }
477#if OO_TEXTURE_CUBE_MAP
478 else if (texTarget == GL_TEXTURE_CUBE_MAP) {
479 [self uploadTextureCubeMapDataWithMipMap:mipMap format:_format];
480 OOLog(@"texture.upload", @"Uploaded cube map texture %u (%ux%ux6 pixels, %@)", _textureName, _width, _width, _key);
481 }
482#endif
483 else {
484 [NSException raise:NSInternalInconsistencyException format:@"Unhandled texture target 0x%X.", texTarget];
485 }
486
487 _valid = YES;
488 _uploaded = YES;
489
490#if OOTEXTURE_RELOADABLE
491 if ([self isReloadable]) {
492 free(_bytes);
493 _bytes = NULL;
494 }
495#endif
496 }
497}
#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

References GL_CLAMP_TO_EDGE, OOConcreteTexture::glTextureTarget, gOOTextureInfo, isReloadable, kOOTextureMagFilterMask, kOOTextureMagFilterNearest, kOOTextureMinFilterMask, kOOTextureMinFilterMipMap, kOOTextureMinFilterNearest, kOOTextureRepeatS, kOOTextureRepeatT, OO_ENTER_OPENGL, OOGL, OOLog, uploadTexture, and OOConcreteTexture::uploadTextureDataWithMipMap:format:.

Referenced by uploadTexture.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ uploadTextureDataWithMipMap:format:

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

Extends class OOConcreteTexture.

Definition at line 499 of file OOConcreteTexture.m.

499 :(BOOL)mipMap format:(OOTextureDataFormat)format
500{
501 GLenum glFormat = 0, internalFormat = 0, type = 0;
502 unsigned w = _width,
503 h = _height,
504 level = 0;
505 char* bytes = _bytes;
506 uint8_t components = OOTextureComponentsForFormat(format);
507
509
510 if (!DecodeFormat(format, _options, &glFormat, &internalFormat, &type))
511 return;
512
513 while (0 < w && 0 < h) {
514 OOGL(glTexImage2D(GL_TEXTURE_2D, level++, internalFormat, w, h, 0, glFormat, type, bytes));
515 if (!mipMap)
516 return;
517 bytes += w * components * h;
518 w >>= 1;
519 h >>= 1;
520 }
521
522 // Note: we only reach here if (mipMap).
523 _mipLevels = level - 1;
524 OOGL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, _mipLevels));
525}
static BOOL DecodeFormat(OOTextureDataFormat format, uint32_t options, GLenum *outFormat, GLenum *outInternalFormat, GLenum *outType)
#define GL_TEXTURE_MAX_LEVEL
uint8_t OOTextureComponentsForFormat(OOTextureDataFormat format)
Definition OOTexture.m:624
OOPixMapFormat OOTextureDataFormat
Definition OOTexture.h:107

References DecodeFormat(), GL_TEXTURE_MAX_LEVEL, OO_ENTER_OPENGL, OOGL, and OOTextureComponentsForFormat().

Here is the call graph for this function:

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