43#define DUMP_CONVERTED_CUBE_MAPS 0
63@interface OOTextureLoader (OOPrivate)
76+ (id)loaderWithPath:(NSString *)inPath options:(uint32_t)options
78 NSString *extension =
nil;
88 extension = [[
inPath pathExtension] lowercaseString];
89 if ([extension isEqualToString:
@"png"])
91 result = [[[
OOPNGTextureLoader alloc] initWithPath:inPath options:options] autorelease];
95 OOLog(
@"texture.load.unknownType",
@"Can't use %@ as a texture - extension \"%@\
" does not identify a known type.", inPath, extension);
76+ (id)loaderWithPath:(NSString *)inPath options:(uint32_t)options {
…}
107+ (id)loaderWithTextureSpecifier:(
id)specifier extraOptions:(uint32_t)extraOptions folder:(NSString *)folder
109 NSString *name =
nil;
111 uint32_t options = 0;
114 options |= extraOptions;
107+ (id)loaderWithTextureSpecifier:(
id)specifier extraOptions:(uint32_t)extraOptions folder:(NSString *)folder {
…}
130- (id)initWithPath:(NSString *)inPath options:(uint32_t)options
133 if (
self ==
nil)
return nil;
161#if OO_TEXTURE_CUBE_MAP
187 OOLogERR(
@"texture.load.unknownExtractChannelMask",
@"Unknown texture extract channel mask (0x%.4X). This is an internal error, please report it.", options &
kOOTextureExtractChannelMask);
130- (id)initWithPath:(NSString *)inPath options:(uint32_t)options {
…}
209 NSString *state =
nil;
213 if (
_data != NULL) state =
@"ready";
214 else state =
@"failed";
219#if INSTRUMENT_TEXTURE_LOADING
220 if (debugHasLoaded) state =
@"loaded";
224 return [
NSString stringWithFormat:@"{%@ -- %@}", _path, state];
230 return [_path lastPathComponent];
248 originalWidth:(uint32_t *)outWidth
249 originalHeight:(uint32_t *)outHeight
251 NSParameterAssert(result != NULL && outFormat != NULL);
259 if (
_data == NULL) OK = NO;
283 return [
NSString stringWithFormat:@"%@:0x%.4X", [[
self path] lastPathComponent], _options];
297 OOGL(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize));
299 OOLog(
@"texture.load.rescale.maxSize",
@"GL maximum texture size: %u",
sGLMaxSize);
318 OOLog(
@"texture.load.asyncLoad",
@"Loading texture %@", [
_path lastPathComponent]);
325 OOLog(
@"texture.load.failed.internalError",
@"Texture loader internal error for %@: data is non-null but data format is invalid (%u).",
_path,
_format);
332 OOLog(
@"texture.load.asyncLoad.done",
@"%@",
@"Loading complete.");
334 @catch (NSException *exception)
336 OOLog(
@"texture.load.asyncLoad.exception",
@"***** Exception loading texture %@: %@ (%@).",
_path, [exception name], [exception reason]);
348 NSParameterAssert(
_data != NULL);
352 size_t newSideSize = srcSideSize * 4 / 3;
353 newSideSize = (newSideSize + 15) & ~15;
354 size_t newSize = newSideSize * 6;
356 void *newData = malloc(newSize);
365 for (i = 0; i < 6; i++)
367 void *srcBytes = ((uint8_t *)
_data) + srcSideSize * i;
368 void *dstBytes = ((uint8_t *)newData) + newSideSize * i;
370 memcpy(dstBytes, srcBytes, srcSideSize);
390 if (_originalWidth == 0) _originalWidth = _width;
391 if (_originalHeight == 0) _originalHeight = _height;
392 if (_rowBytes == 0) _rowBytes = _width * components;
394 pixMap =
OOMakePixMap(_data, _width, _height, components, _rowBytes, 0);
405 OOLogWARN(
@"texture.load.extractChannel.invalid",
@"Cannot extract channel from texture \"%@\
"", [_path lastPathComponent]);
414 desiredHeight =
MIN(desiredWidth * 2, 512U);
416 desiredWidth = desiredHeight * 2;
423#if DUMP_CONVERTED_CUBE_MAPS
424 OODumpPixMap(pixMap, [NSString stringWithFormat:
@"converted cube map %@", [[_path lastPathComponent] stringByDeletingPathExtension]]);
429 rescale = (_width != desiredWidth || _height != desiredHeight);
432 BOOL leaveSpaceForMipMaps = _generateMipMaps;
433#if OO_TEXTURE_CUBE_MAP
434 if (_isCubeMap) leaveSpaceForMipMaps = NO;
437 OOLog(
@"texture.load.rescale",
@"Rescaling texture \"%@\
" from %u x %u to %u x %u.", [_path lastPathComponent], pixMap.
width, pixMap.
height, desiredWidth, desiredHeight);
439 pixMap =
OOScalePixMap(pixMap, desiredWidth, desiredHeight, leaveSpaceForMipMaps);
443 _width = pixMap.
width;
448#if OO_TEXTURE_CUBE_MAP
451 if (_generateMipMaps)
460 if (_generateMipMaps)
463 newSize = desiredWidth * components * desiredHeight;
464 newSize = (newSize * 4) / 3;
469 _width = pixMap.
width;
473 if (_generateMipMaps)
487 if (!_noScalingWhatsoever)
490 if (_allowCubeMap && _height == _width * 6)
498 if (256 < desiredWidth) desiredWidth /= 2;
502 desiredHeight = desiredWidth * 6;
514 desiredWidth = _width;
515 desiredHeight = _height;
521 if (!_avoidShrinking)
525 if (_shrinkThreshold < desiredWidth) desiredWidth /= 2;
526 if (_shrinkThreshold < desiredHeight) desiredHeight /= 2;
529 desiredWidth =
MIN(desiredWidth, _maxSize);
530 desiredHeight =
MIN(desiredHeight, _maxSize);
536 desiredWidth = _width;
537 desiredHeight = _height;
540 if (outDesiredWidth != NULL) *outDesiredWidth = desiredWidth;
541 if (outDesiredHeight != NULL) *outDesiredHeight = desiredHeight;
OOPixMap OOConvertCubeMapToLatLong(OOPixMap sourcePixMap, OOPixMapDimension height, BOOL leaveSpaceForMipMaps)
void OOStandardsError(NSString *message)
#define OOLogWARN(class, format,...)
#define OOLogERR(class, format,...)
#define OOLogGenericSubclassResponsibility()
#define OOLog(class, format,...)
NSString *const kOOLogFileNotFound
BOOL OOExtractPixMapChannel(OOPixMap *ioPixMap, uint8_t channelIndex, BOOL compactWhenDone)
BOOL OOPixMapToRGBA(OOPixMap *ioPixMap)
uint_fast32_t OOPixMapDimension
void OOFreePixMap(OOPixMap *ioPixMap)
void OODumpPixMap(OOPixMap pixMap, NSString *name)
const OOPixMap kOONullPixMap
#define OORoundUpToPowerOf2_PixMap
OOPixMap OOMakePixMap(void *pixels, OOPixMapDimension width, OOPixMapDimension height, OOPixMapFormat format, size_t rowBytes, size_t bufferSize)
BOOL OOIsValidPixMap(OOPixMap pixMap)
BOOL OOExpandPixMap(OOPixMap *ioPixMap, size_t desiredSize)
static unsigned sGLMaxSize
@ kDefaultShrinkThreshold
static BOOL sReducedDetail
static uint32_t sUserMaxSize
static BOOL sHaveNPOTTextures
OOPixMap OOScalePixMap(OOPixMap srcPixMap, OOPixMapDimension dstWidth, OOPixMapDimension dstHeight, BOOL leaveSpaceForMipMaps)
BOOL OOGenerateMipMaps(void *textureBytes, OOPixMapDimension width, OOPixMapDimension height, OOPixMapFormat format)
BOOL OOCubeMapsAvailable(void)
uint8_t OOTextureComponentsForFormat(OOTextureDataFormat format)
@ kOOTextureExtractChannelA
@ kOOTextureExtractChannelB
@ kOOTextureExtractChannelMask
@ kOOTextureMinFilterLinear
@ kOOTextureMinFilterMask
@ kOOTextureMinFilterMipMap
@ kOOTextureExtractChannelG
@ kOOTextureExtractChannelR
@ kOOTextureDataGrayscale
OOPixMapFormat OOTextureDataFormat
BOOL OOInterpretTextureSpecifier(id specifier, NSString **outName, OOTextureFlags *outOptions, float *outAnisotropy, float *outLODBias, BOOL ignoreExtract)
void waitForTaskToComplete:(id< OOAsyncWorkTask > task)
OOAsyncWorkManager * sharedAsyncWorkManager()
void generateMipMapsForCubeMap()
OOTextureDataFormat _format
NSString * descriptionComponents()
uint8_t _extractChannelIndex
NSString * shortDescriptionComponents()
uint32_t _shrinkThreshold
id loaderWithPath:options:(NSString *path,[options] uint32_t options)
uint8_t _noScalingWhatsoever
void getDesiredWidth:andHeight:(OOPixMapDimension *outDesiredWidth, [andHeight] OOPixMapDimension *outDesiredHeight)
NSString * pathForFileNamed:inFolder:(NSString *fileName,[inFolder] NSString *folderName)