Oolite 1.91.0.7644-241112-7f5034b
Loading...
Searching...
No Matches
OOTextureLoader(OOPrivate) Category Reference

Instance Methods

(void) - applySettings
 
(void) - getDesiredWidth:andHeight:
 

Class Methods

(void) + setUp
 

Detailed Description

Definition at line 63 of file OOTextureLoader.m.

Method Documentation

◆ applySettings

- (void) applySettings

Extends class OOTextureLoader.

Definition at line 60 of file OOTextureLoader.m.

380{
381 OOPixMapDimension desiredWidth, desiredHeight;
382 BOOL rescale;
383 size_t newSize;
384 uint8_t components;
385 OOPixMap pixMap;
386
387 components = OOTextureComponentsForFormat(_format);
388
389 // Apply defaults.
390 if (_originalWidth == 0) _originalWidth = _width;
391 if (_originalHeight == 0) _originalHeight = _height;
392 if (_rowBytes == 0) _rowBytes = _width * components;
393
394 pixMap = OOMakePixMap(_data, _width, _height, components, _rowBytes, 0);
395
396 if (_extractChannel)
397 {
398 if (OOExtractPixMapChannel(&pixMap, _extractChannelIndex, NO))
399 {
400 _format = kOOTextureDataGrayscale;
401 components = 1;
402 }
403 else
404 {
405 OOLogWARN(@"texture.load.extractChannel.invalid", @"Cannot extract channel from texture \"%@\"", [_path lastPathComponent]);
406 }
407 }
408
409 [self getDesiredWidth:&desiredWidth andHeight:&desiredHeight];
410
411 if (_isCubeMap && !OOCubeMapsAvailable())
412 {
413 OOPixMapToRGBA(&pixMap);
414 desiredHeight = MIN(desiredWidth * 2, 512U);
415 if (sReducedDetail && desiredHeight > kCubeShrinkThreshold) desiredHeight /= 2;
416 desiredWidth = desiredHeight * 2;
417
418 OOPixMap converted = OOConvertCubeMapToLatLong(pixMap, desiredHeight, _generateMipMaps);
419 OOFreePixMap(&pixMap);
420 pixMap = converted;
421 _isCubeMap = NO;
422
423#if DUMP_CONVERTED_CUBE_MAPS
424 OODumpPixMap(pixMap, [NSString stringWithFormat:@"converted cube map %@", [[_path lastPathComponent] stringByDeletingPathExtension]]);
425#endif
426 }
427
428 // Rescale if needed.
429 rescale = (_width != desiredWidth || _height != desiredHeight);
430 if (rescale)
431 {
432 BOOL leaveSpaceForMipMaps = _generateMipMaps;
433#if OO_TEXTURE_CUBE_MAP
434 if (_isCubeMap) leaveSpaceForMipMaps = NO;
435#endif
436
437 OOLog(@"texture.load.rescale", @"Rescaling texture \"%@\" from %u x %u to %u x %u.", [_path lastPathComponent], pixMap.width, pixMap.height, desiredWidth, desiredHeight);
438
439 pixMap = OOScalePixMap(pixMap, desiredWidth, desiredHeight, leaveSpaceForMipMaps);
440 if (EXPECT_NOT(!OOIsValidPixMap(pixMap))) return;
441
442 _data = pixMap.pixels;
443 _width = pixMap.width;
444 _height = pixMap.height;
445 _rowBytes = pixMap.rowBytes;
446 }
447
448#if OO_TEXTURE_CUBE_MAP
449 if (_isCubeMap)
450 {
451 if (_generateMipMaps)
452 {
453 [self generateMipMapsForCubeMap];
454 }
455 return;
456 }
457#endif
458
459 // Generate mip maps if needed.
460 if (_generateMipMaps)
461 {
462 // Make space if needed.
463 newSize = desiredWidth * components * desiredHeight;
464 newSize = (newSize * 4) / 3;
465 // +1 to fix overrun valgrind spotted - CIM
466 _generateMipMaps = OOExpandPixMap(&pixMap, newSize+1);
467
468 _data = pixMap.pixels;
469 _width = pixMap.width;
470 _height = pixMap.height;
471 _rowBytes = pixMap.rowBytes;
472 }
473 if (_generateMipMaps)
474 {
475 OOGenerateMipMaps(_data, _width, _height, _format);
476 }
477
478 // All done.
479}
OOPixMap OOConvertCubeMapToLatLong(OOPixMap sourcePixMap, OOPixMapDimension height, BOOL leaveSpaceForMipMaps)
#define EXPECT_NOT(x)
#define OOLogWARN(class, format,...)
Definition OOLogging.h:113
#define OOLog(class, format,...)
Definition OOLogging.h:88
#define MIN(A, B)
Definition OOMaths.h:111
BOOL OOExtractPixMapChannel(OOPixMap *ioPixMap, uint8_t channelIndex, BOOL compactWhenDone)
BOOL OOPixMapToRGBA(OOPixMap *ioPixMap)
uint_fast32_t OOPixMapDimension
Definition OOPixMap.h:33
void OOFreePixMap(OOPixMap *ioPixMap)
Definition OOPixMap.m:86
void OODumpPixMap(OOPixMap pixMap, NSString *name)
Definition OOPixMap.m:145
OOPixMap OOMakePixMap(void *pixels, OOPixMapDimension width, OOPixMapDimension height, OOPixMapFormat format, size_t rowBytes, size_t bufferSize)
Definition OOPixMap.m:53
BOOL OOIsValidPixMap(OOPixMap pixMap)
Definition OOPixMap.m:42
BOOL OOExpandPixMap(OOPixMap *ioPixMap, size_t desiredSize)
Definition OOPixMap.m:130
static BOOL sReducedDetail
@ kCubeShrinkThreshold
OOPixMap OOScalePixMap(OOPixMap srcPixMap, OOPixMapDimension dstWidth, OOPixMapDimension dstHeight, BOOL leaveSpaceForMipMaps)
BOOL OOGenerateMipMaps(void *textureBytes, OOPixMapDimension width, OOPixMapDimension height, OOPixMapFormat format)
BOOL OOCubeMapsAvailable(void)
Definition OOTexture.m:688
uint8_t OOTextureComponentsForFormat(OOTextureDataFormat format)
Definition OOTexture.m:667
@ kOOTextureDataGrayscale
Definition OOTexture.h:110
OOPixMapDimension height
Definition OOPixMap.h:50
size_t rowBytes
Definition OOPixMap.h:52
void * pixels
Definition OOPixMap.h:49
OOPixMapDimension width
Definition OOPixMap.h:50

◆ getDesiredWidth:andHeight:

- (void) getDesiredWidth: (OOPixMapDimension *) outDesiredWidth
andHeight: (OOPixMapDimension *) outDesiredHeight 

Extends class OOTextureLoader.

Definition at line 60 of file OOTextureLoader.m.

482 :(OOPixMapDimension *)outDesiredWidth andHeight:(OOPixMapDimension *)outDesiredHeight
483{
484 OOPixMapDimension desiredWidth, desiredHeight;
485
486 // Work out appropriate final size for textures.
487 if (!_noScalingWhatsoever)
488 {
489 // Cube maps are six times as high as they are wide, and we need to preserve that.
490 if (_allowCubeMap && _height == _width * 6)
491 {
492 _isCubeMap = YES;
493
494 desiredWidth = OORoundUpToPowerOf2_PixMap((2 * _width) / 3);
495 desiredWidth = MIN(desiredWidth, sGLMaxSize / 8);
496 if (sReducedDetail)
497 {
498 if (256 < desiredWidth) desiredWidth /= 2;
499 }
500 desiredWidth = MIN(desiredWidth, sUserMaxSize / 4);
501
502 desiredHeight = desiredWidth * 6;
503 }
504 else
505 {
507 {
508 // Round to nearest power of two. NOTE: this is duplicated in OOTextureVerifierStage.m.
509 desiredWidth = OORoundUpToPowerOf2_PixMap((2 * _width) / 3);
510 desiredHeight = OORoundUpToPowerOf2_PixMap((2 * _height) / 3);
511 }
512 else
513 {
514 desiredWidth = _width;
515 desiredHeight = _height;
516 }
517
518 desiredWidth = MIN(desiredWidth, sGLMaxSize);
519 desiredHeight = MIN(desiredHeight, sGLMaxSize);
520
521 if (!_avoidShrinking)
522 {
523 if (sReducedDetail)
524 {
525 if (_shrinkThreshold < desiredWidth) desiredWidth /= 2;
526 if (_shrinkThreshold < desiredHeight) desiredHeight /= 2;
527 }
528
529 desiredWidth = MIN(desiredWidth, _maxSize);
530 desiredHeight = MIN(desiredHeight, _maxSize);
531 }
532 }
533 }
534 else
535 {
536 desiredWidth = _width;
537 desiredHeight = _height;
538 }
539
540 if (outDesiredWidth != NULL) *outDesiredWidth = desiredWidth;
541 if (outDesiredHeight != NULL) *outDesiredHeight = desiredHeight;
542}
#define OORoundUpToPowerOf2_PixMap
Definition OOPixMap.h:35
static unsigned sGLMaxSize
static uint32_t sUserMaxSize
static BOOL sHaveNPOTTextures

◆ setUp

+ (void) setUp

Extends class OOTextureLoader.


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