104@interface OOTexture (OOPrivate)
107+ (
OOTexture *) existingTextureForKey:(NSString *)key;
114- (id) retainInContext:(NSString *)context;
115- (void) releaseInContext:(NSString *)context;
116- (id) autoreleaseInContext:(NSString *)context;
125#define SET_TRACE_CONTEXT(str) do { sGlobalTraceContext = (str); } while (0)
127#define SET_TRACE_CONTEXT(str) do { } while (0)
129#define CLEAR_TRACE_CONTEXT() SET_TRACE_CONTEXT(nil)
134+ (id)textureWithName:(NSString *)name
135 inFolder:(NSString*)directory
137 anisotropy:(GLfloat)anisotropy
138 lodBias:(GLfloat)lodBias
142 NSString *path =
nil;
173 result = [[[
OOConcreteTexture alloc] initWithPath:path key:key options:options anisotropy:anisotropy lodBias:lodBias] autorelease];
181+ (id)textureWithName:(NSString *)name
182 inFolder:(NSString*)directory
184 return [
self textureWithName:name
186 options:kOOTextureDefaultOptions
187 anisotropy:kOOTextureDefaultAnisotropy
188 lodBias:kOOTextureDefaultLODBias];
192+ (id)textureWithConfiguration:(
id)configuration
194 return [
self textureWithConfiguration:configuration extraOptions:0];
198+ (id) textureWithConfiguration:(
id)configuration extraOptions:(
OOTextureFlags)extraOptions
200 NSString *name =
nil;
202 GLfloat anisotropy = 0.0f;
203 GLfloat lodBias = 0.0f;
207 return [
self textureWithName:name inFolder:@"Textures" options:options | extraOptions anisotropy:anisotropy lodBias:lodBias];
219 return [
self textureWithGenerator:generator enqueue: NO];
225 if (generator ==
nil)
return nil;
227#ifndef OOTEXTURE_NO_CACHE
229 if (existing !=
nil && !enqueue)
return [[existing
retain] autorelease];
232 if (![generator enqueue])
234 OOLogERR(
@"texture.generator.queue.failed",
@"Failed to queue generator %@", generator);
237 OOLog(
@"texture.generator.queue",
@"Queued texture generator %@", generator);
243 lodBias:[generator
lodBias]] autorelease];
251 if ((
self = [super init]))
254 [sAllLiveTextures addObject:[NSValue valueWithPointer:self]];
263 [sAllLiveTextures removeObject:[NSValue valueWithPointer:self]];
278 OOGL(glBindTexture(GL_TEXTURE_2D, 0));
279#if OO_TEXTURE_CUBE_MAP
283#if GL_EXT_texture_lod_bias
289- (void)ensureFinishedLoading
294- (BOOL) isFinishedLoading
300- (NSString *) cacheKey
313- (NSSize) originalDimensions
315 return [
self dimensions];
326- (struct
OOPixMap) copyPixMapRepresentation
332- (BOOL) isRectangleTexture
344- (NSSize)texCoordsScale
346 return NSMakeSize(1.0, 1.0);
350- (GLint)glTextureName
363 [sLiveTextureCache autorelease];
367 [sRecentTextures autorelease];
373+ (void)rebindAllTextures
375 NSEnumerator *textureEnum =
nil;
381 for (textureEnum = [
sAllLiveTextures objectEnumerator]; (texture = [[textureEnum nextObject] pointerValue]); )
383 [texture forceRebind];
389- (void) setTrace:(BOOL)trace
391 if (trace && !_trace)
393 OOLog(
@"texture.allocTrace.begin",
@"Started tracing texture %p with retain count %llu.",
self, [
self retainCount]);
399+ (NSArray *) cachedTexturesByAge
405+ (NSSet *) allTextures
407 NSMutableSet *result = [NSMutableSet setWithCapacity:[sAllLiveTextures count]];
411 [result addObject:[box pointerValue]];
420 NSSize dimensions = [
self dimensions];
421 size_t size = dimensions.width * dimensions.height;
422 if ([
self isCubeMap])
size *= 6;
423 if ([
self isMipMapped])
size =
size * 4 / 3;
445#ifndef OOTEXTURE_NO_CACHE
446 NSString *cacheKey = [
self cacheKey];
447 if (cacheKey ==
nil)
return;
453 [sLiveTextureCache setObject:[NSValue valueWithPointer:self] forKey:cacheKey];
460 [sRecentTextures
setName:@"recent textures"];
472- (void) removeFromCaches
474#ifndef OOTEXTURE_NO_CACHE
475 NSString *cacheKey = [
self cacheKey];
476 if (cacheKey ==
nil)
return;
478 [sLiveTextureCache removeObjectForKey:cacheKey];
493 NSAssert2(0,
@"Texture retain count error for %@; cacheKey is %@.",
self, cacheKey);
501+ (
OOTexture *) existingTextureForKey:(NSString *)key
503#ifndef OOTEXTURE_NO_CACHE
506 return (
OOTexture *)[[sLiveTextureCache objectForKey:key] pointerValue];
525#if GL_EXT_texture_filter_anisotropic
528 gOOTextureInfo.
anisotropyScale *= OOClamp_0_1_f([[NSUserDefaults standardUserDefaults] oo_floatForKey:
@"texture-anisotropy-scale" defaultValue:0.5]);
531#ifdef GL_CLAMP_TO_EDGE
535#if OO_GL_CLIENT_STORAGE
541#if GL_EXT_texture_lod_bias
542 if ([[NSUserDefaults standardUserDefaults] oo_boolForKey:
@"use-texture-lod-bias" defaultValue:YES])
552#if GL_EXT_texture_rectangle
556#if OO_TEXTURE_CUBE_MAP
557 if (![[NSUserDefaults standardUserDefaults] boolForKey:
@"disable-cube-maps"])
571- (id) retainInContext:(NSString *)context
575 if (context)
OOLog(
@"texture.allocTrace.retain",
@"Texture %p retained (retain count -> %llu) - %@.",
self, [
self retainCount] + 1, context);
576 else OOLog(
@"texture.allocTrace.retain",
@"Texture %p retained (retain count -> %llu).",
self, [
self retainCount] + 1);
579 return [
super retain];
583- (void) releaseInContext:(NSString *)context
587 if (context)
OOLog(
@"texture.allocTrace.release",
@"Texture %p released (retain count -> %llu) - %@.",
self, [
self retainCount] - 1, context);
588 else OOLog(
@"texture.allocTrace.release",
@"Texture %p released (retain count -> %llu).",
self, [
self retainCount] - 1);
595- (id) autoreleaseInContext:(NSString *)context
599 if (context)
OOLog(
@"texture.allocTrace.autoreleased",
@"Texture %p autoreleased - %@.",
self, context);
600 else OOLog(
@"texture.allocTrace.autoreleased",
@"Texture %p autoreleased.",
self);
603 return [
super autorelease];
609 return [
self retainInContext:sGlobalTraceContext];
613- (oneway void) release
615 [
self releaseInContext:sGlobalTraceContext];
621 return [
self autoreleaseInContext:sGlobalTraceContext];
628@implementation NSDictionary (OOTextureConveniences)
630- (NSDictionary *) oo_textureSpecifierForKey:(
id)key defaultName:(NSString *)name
637@implementation NSArray (OOTextureConveniences)
639- (NSDictionary *) oo_textureSpecifierAtIndex:(
unsigned)index defaultName:(NSString *)name
648 if (
object ==
nil)
object = defaultName;
649 if ([
object isKindOfClass:[NSString class]])
651 if ([
object isEqualToString:
@""])
return nil;
652 return [NSDictionary dictionaryWithObject:object forKey:@"name"];
654 if (![
object isKindOfClass:[NSDictionary class]])
return nil;
657 if (defaultName ==
nil || [
object oo_stringForKey:
@"name"] !=
nil)
return object;
660 NSMutableDictionary *mutableResult = [NSMutableDictionary dictionaryWithDictionary:object];
661 [mutableResult setObject:[[defaultName copy] autorelease] forKey:@"name"];
662 return mutableResult;
695 NSString *name =
nil;
700 if ([specifier isKindOfClass:[NSString class]])
704 else if ([specifier isKindOfClass:[NSDictionary class]])
706 name = [specifier oo_stringForKey:kOOTextureSpecifierNameKey];
709 OOLog(
@"texture.load.noName",
@"Invalid texture configuration dictionary (must specify name):\n%@", specifier);
713 int quickFlags = [specifier oo_intForKey:kOOTextureSpecifierFlagValueInternalKey defaultValue:-1];
714 if (quickFlags != -1)
716 options = quickFlags;
720 NSString *filterString = [specifier oo_stringForKey:kOOTextureSpecifierMinFilterKey defaultValue:@"default"];
726 filterString = [specifier oo_stringForKey:kOOTextureSpecifierMagFilterKey defaultValue:@"default"];
738 NSString *extractChannel = [specifier oo_stringForKey:@"extract_channel"];
739 if (extractChannel !=
nil)
747 OOLogWARN(
@"texture.load.extractChannel.invalid",
@"Unknown value \"%@\
" for extract_channel in specifier \"%@\" (should be \"r\", \"g\", \"b\" or \"a\").", extractChannel,specifier);
752 anisotropy = [specifier oo_floatForKey:@"anisotropy" defaultValue:kOOTextureDefaultAnisotropy];
753 lodBias = [specifier oo_floatForKey:@"texture_LOD_bias" defaultValue:kOOTextureDefaultLODBias];
758 if (specifier !=
nil)
OOLog(
kOOLogParameterError,
@"%s: expected string or dictionary, got %@.", __PRETTY_FUNCTION__, [specifier
class]);
762 if ([name length] == 0)
return NO;
764 if (outName != NULL) *outName = name;
765 if (outOptions != NULL) *outOptions = options;
766 if (outAnisotropy != NULL) *outAnisotropy = anisotropy;
767 if (outLODBias != NULL) *outLODBias = lodBias;
775 NSMutableDictionary *result = [NSMutableDictionary dictionary];
777 [result setObject:name forKey:kOOTextureSpecifierNameKey];
784 [result oo_setUnsignedInteger:options forKey:kOOTextureSpecifierFlagValueInternalKey];
788 NSString *value =
nil;
806 if (value !=
nil) [result setObject:value forKey:kOOTextureSpecifierNoShrinkKey];
818 if (value !=
nil) [result setObject:value forKey:kOOTextureSpecifierMagFilterKey];
842 if (value !=
nil) [result setObject:value forKey:kOOTextureSpecifierSwizzleKey];
844 if (options &
kOOTextureNoShrink) [result oo_setBool:YES forKey:kOOTextureSpecifierNoShrinkKey];
845 if (options &
kOOTextureRepeatS) [result oo_setBool:YES forKey:kOOTextureSpecifierRepeatSKey];
846 if (options &
kOOTextureRepeatT) [result oo_setBool:YES forKey:kOOTextureSpecifierRepeatTKey];
891#if GL_EXT_texture_rectangle
894 options &= ~kOOTextureAllowRectTexture;
897 options &= ~kOOTextureAllowRectTexture;
919 return [NSString stringWithFormat:@"%@%@%@:0x%.4X/%g/%g", directory ? directory : (NSString *)@"", directory ? @"/" : @"", name, options, anisotropy, lodBias];
#define OOLogWARN(class, format,...)
#define OOLogERR(class, format,...)
#define OOLogGenericSubclassResponsibility()
#define OOLog(class, format,...)
NSString *const kOOLogParameterError
NSString *const kOOLogFileNotFound
#define OO_ENTER_OPENGL()
const OOPixMap kOONullPixMap
NSString *const kOOTextureSpecifierNoShrinkKey
BOOL OOCubeMapsAvailable(void)
uint8_t OOTextureComponentsForFormat(OOTextureDataFormat format)
@ kOOTextureDataGrayscaleAlpha
@ kOOTextureDataGrayscale
NSDictionary * OOMakeTextureSpecifier(NSString *name, OOTextureFlags options, float anisotropy, float lodBias, BOOL internal)
NSString *const kOOTextureSpecifierRepeatTKey
OOTextureFlags OOApplyTextureOptionDefaults(OOTextureFlags options)
NSDictionary * OOTextureSpecFromObject(id object, NSString *defaultName)
#define kOOTextureDefaultAnisotropy
@ kOOTextureAllowRectTexture
@ kOOTextureExtractChannelA
@ kOOTextureExtractChannelB
@ kOOTextureMinFilterDefault
@ kOOTextureExtractChannelNone
@ kOOTextureMagFilterMask
@ kOOTextureExtractChannelMask
@ kOOTextureMinFilterLinear
@ kOOTextureMinFilterMask
@ kOOTextureDefaultOptions
@ kOOTextureMinFilterMipMap
@ kOOTextureMagFilterNearest
@ kOOTextureExtractChannelG
@ kOOTextureFlagsAllowedForRectangleTexture
@ kOOTextureExtractChannelR
@ kOOTextureMagFilterLinear
@ kOOTextureMinFilterNearest
NSString *const kOOTextureSpecifierRepeatSKey
#define kOOTextureDefaultLODBias
BOOL OOInterpretTextureSpecifier(id specifier, NSString **outName, OOTextureFlags *outOptions, float *outAnisotropy, float *outLODBias, BOOL ignoreExtract)
NSString *const kOOTextureSpecifierCubeMapKey
NSString *const kOOTextureSpecifierExtraShrinkKey
#define CLEAR_TRACE_CONTEXT()
NSString *const kOOTextureSpecifierSelfColorKey
NSString *const kOOTextureSpecifierNoShrinkKey
NSString *const kOOTextureSpecifierNameKey
#define SET_TRACE_CONTEXT(str)
static OOCache * sRecentTextures
NSString *const kOOTextureSpecifierRepeatTKey
static NSMutableDictionary * sLiveTextureCache
NSString *const kOOTextureSpecifierScaleFactorKey
static NSString * sGlobalTraceContext
NSString * OOTextureCacheKeyForSpecifier(id specifier)
static BOOL sCheckedExtensions
NSString *const kOOTextureSpecifierBindingKey
static NSMutableSet * sAllLiveTextures
NSString *const kOOTextureSpecifierIlluminationModeKey
NSString *const kOOTextureSpecifierMinFilterKey
NSString *const kOOTextureSpecifierMagFilterKey
NSString *const kOOTextureSpecifierAnisotropyKey
static NSString *const kOOTextureSpecifierFlagValueInternalKey
NSString *const kOOTextureSpecifierRepeatSKey
NSString * OOGenerateTextureCacheKey(NSString *directory, NSString *name, OOTextureFlags options, float anisotropy, float lodBias)
NSString *const kOOTextureSpecifierModulateColorKey
NSString *const kOOTextureSpecifierCubeMapKey
OOTextureInfo gOOTextureInfo
NSString *const kOOTextureSpecifierSwizzleKey
NSString *const kOOTextureSpecifierExtraShrinkKey
NSString *const kOOTextureSpecifierLODBiasKey
void setPruneThreshold:(unsigned threshold)
void setName:(NSString *name)
void setAutoPrune:(BOOL flag)
void removeObjectForKey:(id key)
void setObject:forKey:(id value,[forKey] id key)
OONullTexture * sharedNullTexture()
BOOL versionIsAtLeastMajor:minor:(unsigned maj,[minor] unsigned min)
OOOpenGLExtensionManager * sharedManager()
BOOL haveExtension:(NSString *extension)
uint32_t textureOptions()
OOTexture * existingTextureForKey:(NSString *key)
NSString * pathForFileNamed:inFolder:(NSString *fileName,[inFolder] NSString *folderName)
unsigned clientStorageAvailable
unsigned textureMaxLevelAvailable
unsigned anisotropyAvailable
unsigned clampToEdgeAvailable
unsigned cubeMapAvailable
unsigned rectangleTextureAvailable
unsigned textureLODBiasAvailable