42#define DUMP_CONVERTED_CUBE_MAPS 0
59@interface OOTextureLoader (OOPrivate)
70+ (id)loaderWithPath:(NSString*)inPath options:(uint32_t)options
72 NSString* extension =
nil;
84 extension = [[
inPath pathExtension] lowercaseString];
85 if ([extension isEqualToString:
@"png"]) {
86 result = [[[
OOPNGTextureLoader alloc] initWithPath:inPath options:options] autorelease];
88 OOLog(
@"texture.load.unknownType",
@"Can't use %@ as a texture - extension \"%@\
" does not identify a known type.", inPath, extension);
99+ (id)loaderWithTextureSpecifier:(
id)specifier extraOptions:(uint32_t)extraOptions folder:(NSString*)folder
101 NSString* name =
nil;
103 uint32_t options = 0;
107 options |= extraOptions;
120- (id)initWithPath:(NSString*)inPath options:(uint32_t)options
147#if OO_TEXTURE_CUBE_MAP
171 OOLogERR(
@"texture.load.unknownExtractChannelMask",
@"Unknown texture extract channel mask (0x%.4X). This is an internal error, please report it.", options &
kOOTextureExtractChannelMask);
191 NSString* state =
nil;
200#if INSTRUMENT_TEXTURE_LOADING
206 return [
NSString stringWithFormat:@"{%@ -- %@}", _path, state];
211 return [_path lastPathComponent];
226 originalWidth:(uint32_t*)outWidth
227 originalHeight:(uint32_t*)outHeight
229 NSParameterAssert(result != NULL && outFormat != NULL);
244 if (outWidth != NULL)
246 if (outHeight != NULL)
260 return [
NSString stringWithFormat:@"%@:0x%.4X", [[
self path] lastPathComponent], _options];
272 OOGL(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize));
274 OOLog(
@"texture.load.rescale.maxSize",
@"GL maximum texture size: %u",
sGLMaxSize);
279 OOLog(
@"texture.load.rescale.maxSize",
@"User maximum texture size: %u",
sUserMaxSize);
291 OOLog(
@"texture.load.asyncLoad",
@"Loading texture %@", [
_path lastPathComponent]);
297 OOLog(
@"texture.load.failed.internalError",
@"Texture loader internal error for %@: data is non-null but data format is invalid (%u).",
_path,
_format);
305 OOLog(
@"texture.load.asyncLoad.done",
@"%@",
@"Loading complete.");
307 @catch (NSException* exception) {
308 OOLog(
@"texture.load.asyncLoad.exception",
@"***** Exception loading texture %@: %@ (%@).",
_path, [exception name], [exception reason]);
319 NSParameterAssert(
_data != NULL);
323 size_t newSideSize = srcSideSize * 4 / 3;
324 newSideSize = (newSideSize + 15) & ~15;
325 size_t newSize = newSideSize * 6;
327 void* newData = malloc(newSize);
335 for (i = 0; i < 6; i++) {
336 void* srcBytes = ((uint8_t*)
_data) + srcSideSize * i;
337 void* dstBytes = ((uint8_t*)newData) + newSideSize * i;
339 memcpy(dstBytes, srcBytes, srcSideSize);
358 if (_originalWidth == 0)
359 _originalWidth = _width;
360 if (_originalHeight == 0)
361 _originalHeight = _height;
363 _rowBytes = _width * components;
365 pixMap =
OOMakePixMap(_data, _width, _height, components, _rowBytes, 0);
367 if (_extractChannel) {
372 OOLogWARN(
@"texture.load.extractChannel.invalid",
@"Cannot extract channel from texture \"%@\
"", [_path lastPathComponent]);
380 desiredHeight =
MIN(desiredWidth * 2, 512U);
383 desiredWidth = desiredHeight * 2;
390#if DUMP_CONVERTED_CUBE_MAPS
391 OODumpPixMap(pixMap, [NSString stringWithFormat:
@"converted cube map %@", [[_path lastPathComponent] stringByDeletingPathExtension]]);
396 rescale = (_width != desiredWidth || _height != desiredHeight);
398 BOOL leaveSpaceForMipMaps = _generateMipMaps;
399#if OO_TEXTURE_CUBE_MAP
401 leaveSpaceForMipMaps = NO;
404 OOLog(
@"texture.load.rescale",
@"Rescaling texture \"%@\
" from %u x %u to %u x %u.", [_path lastPathComponent], pixMap.
width, pixMap.
height, desiredWidth, desiredHeight);
406 pixMap =
OOScalePixMap(pixMap, desiredWidth, desiredHeight, leaveSpaceForMipMaps);
411 _width = pixMap.
width;
416#if OO_TEXTURE_CUBE_MAP
418 if (_generateMipMaps) {
426 if (_generateMipMaps) {
428 newSize = desiredWidth * components * desiredHeight;
429 newSize = (newSize * 4) / 3;
434 _width = pixMap.
width;
438 if (_generateMipMaps) {
450 if (!_noScalingWhatsoever) {
452 if (_allowCubeMap && _height == _width * 6) {
458 if (256 < desiredWidth)
463 desiredHeight = desiredWidth * 6;
470 desiredWidth = _width;
471 desiredHeight = _height;
477 if (!_avoidShrinking) {
479 if (_shrinkThreshold < desiredWidth)
481 if (_shrinkThreshold < desiredHeight)
485 desiredWidth =
MIN(desiredWidth, _maxSize);
486 desiredHeight =
MIN(desiredHeight, _maxSize);
490 desiredWidth = _width;
491 desiredHeight = _height;
494 if (outDesiredWidth != NULL)
495 *outDesiredWidth = desiredWidth;
496 if (outDesiredHeight != NULL)
497 *outDesiredHeight = desiredHeight;
OOPixMap OOConvertCubeMapToLatLong(OOPixMap sourcePixMap, OOPixMapDimension height, BOOL leaveSpaceForMipMaps)
void OOStandardsError(NSString *message)
OOINLINE INLINE_CONST_FUNC uint32_t OORoundUpToPowerOf2_32(uint32_t value)
#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)
void OOFreePixMap(OOPixMap *ioPixMap)
uint32_t OOPixMapDimension
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)