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 %lu.",
self, [
self retainCount]);
399+ (NSArray *) cachedTexturesByAge
405+ (NSSet *) allTextures
407 NSMutableSet *result = [NSMutableSet setWithCapacity:[sAllLiveTextures count]];
409 NSEnumerator *texEnum =
nil;
410 for (texEnum = [
sAllLiveTextures objectEnumerator]; (box = [texEnum nextObject]); )
412 [result addObject:[box pointerValue]];
421 NSSize dimensions = [
self dimensions];
422 size_t size = dimensions.width * dimensions.height;
423 if ([
self isCubeMap])
size *= 6;
424 if ([
self isMipMapped])
size =
size * 4 / 3;
446#ifndef OOTEXTURE_NO_CACHE
447 NSString *cacheKey = [
self cacheKey];
448 if (cacheKey ==
nil)
return;
454 [sLiveTextureCache setObject:[NSValue valueWithPointer:self] forKey:cacheKey];
461 [sRecentTextures
setName:@"recent textures"];
473- (void) removeFromCaches
475#ifndef OOTEXTURE_NO_CACHE
476 NSString *cacheKey = [
self cacheKey];
477 if (cacheKey ==
nil)
return;
479 [sLiveTextureCache removeObjectForKey:cacheKey];
494 NSAssert2(0,
@"Texture retain count error for %@; cacheKey is %@.",
self, cacheKey);
502+ (
OOTexture *) existingTextureForKey:(NSString *)key
504#ifndef OOTEXTURE_NO_CACHE
507 return (
OOTexture *)[[sLiveTextureCache objectForKey:key] pointerValue];
526#if GL_EXT_texture_filter_anisotropic
529 gOOTextureInfo.
anisotropyScale *= OOClamp_0_1_f([[NSUserDefaults standardUserDefaults] oo_floatForKey:
@"texture-anisotropy-scale" defaultValue:0.5]);
532#ifdef GL_CLAMP_TO_EDGE
536#if OO_GL_CLIENT_STORAGE
542#if GL_EXT_texture_lod_bias
543 if ([[NSUserDefaults standardUserDefaults] oo_boolForKey:
@"use-texture-lod-bias" defaultValue:YES])
553#if GL_EXT_texture_rectangle
557#if OO_TEXTURE_CUBE_MAP
558 if (![[NSUserDefaults standardUserDefaults] boolForKey:
@"disable-cube-maps"])
572- (id) retainInContext:(NSString *)context
576 if (context)
OOLog(
@"texture.allocTrace.retain",
@"Texture %p retained (retain count -> %lu) - %@.",
self, [
self retainCount] + 1, context);
577 else OOLog(
@"texture.allocTrace.retain",
@"Texture %p retained (retain count -> %lu).",
self, [
self retainCount] + 1);
580 return [
super retain];
584- (void) releaseInContext:(NSString *)context
588 if (context)
OOLog(
@"texture.allocTrace.release",
@"Texture %p released (retain count -> %lu) - %@.",
self, [
self retainCount] - 1, context);
589 else OOLog(
@"texture.allocTrace.release",
@"Texture %p released (retain count -> %lu).",
self, [
self retainCount] - 1);
596- (id) autoreleaseInContext:(NSString *)context
600 if (context)
OOLog(
@"texture.allocTrace.autoreleased",
@"Texture %p autoreleased - %@.",
self, context);
601 else OOLog(
@"texture.allocTrace.autoreleased",
@"Texture %p autoreleased.",
self);
604 return [
super autorelease];
610 return [
self retainInContext:sGlobalTraceContext];
614- (oneway void) release
616 [
self releaseInContext:sGlobalTraceContext];
622 return [
self autoreleaseInContext:sGlobalTraceContext];
629@implementation NSDictionary (OOTextureConveniences)
631- (NSDictionary *) oo_textureSpecifierForKey:(
id)key defaultName:(NSString *)name
638@implementation NSArray (OOTextureConveniences)
640- (NSDictionary *) oo_textureSpecifierAtIndex:(
unsigned)index defaultName:(NSString *)name
649 if (
object ==
nil)
object = defaultName;
650 if ([
object isKindOfClass:[NSString
class]])
652 if ([
object isEqualToString:
@""])
return nil;
653 return [NSDictionary dictionaryWithObject:object forKey:@"name"];
655 if (![
object isKindOfClass:[NSDictionary
class]])
return nil;
658 if (defaultName ==
nil || [
object oo_stringForKey:
@"name"] !=
nil)
return object;
661 NSMutableDictionary *mutableResult = [NSMutableDictionary dictionaryWithDictionary:object];
662 [mutableResult setObject:[[defaultName copy] autorelease] forKey:@"name"];
663 return mutableResult;
696 NSString *name =
nil;
701 if ([specifier isKindOfClass:[NSString
class]])
705 else if ([specifier isKindOfClass:[NSDictionary
class]])
707 name = [specifier oo_stringForKey:kOOTextureSpecifierNameKey];
710 OOLog(
@"texture.load.noName",
@"Invalid texture configuration dictionary (must specify name):\n%@", specifier);
714 int quickFlags = [specifier oo_intForKey:kOOTextureSpecifierFlagValueInternalKey defaultValue:-1];
715 if (quickFlags != -1)
717 options = quickFlags;
721 NSString *filterString = [specifier oo_stringForKey:kOOTextureSpecifierMinFilterKey defaultValue:@"default"];
727 filterString = [specifier oo_stringForKey:kOOTextureSpecifierMagFilterKey defaultValue:@"default"];
739 NSString *extractChannel = [specifier oo_stringForKey:@"extract_channel"];
740 if (extractChannel !=
nil)
748 OOLogWARN(
@"texture.load.extractChannel.invalid",
@"Unknown value \"%@\
" for extract_channel in specifier \"%@\" (should be \"r\", \"g\", \"b\" or \"a\").", extractChannel,specifier);
753 anisotropy = [specifier oo_floatForKey:@"anisotropy" defaultValue:kOOTextureDefaultAnisotropy];
754 lodBias = [specifier oo_floatForKey:@"texture_LOD_bias" defaultValue:kOOTextureDefaultLODBias];
759 if (specifier !=
nil)
OOLog(
kOOLogParameterError,
@"%s: expected string or dictionary, got %@.", __PRETTY_FUNCTION__, [specifier
class]);
763 if ([name length] == 0)
return NO;
765 if (outName != NULL) *outName = name;
766 if (outOptions != NULL) *outOptions = options;
767 if (outAnisotropy != NULL) *outAnisotropy = anisotropy;
768 if (outLODBias != NULL) *outLODBias = lodBias;
776 NSMutableDictionary *result = [NSMutableDictionary dictionary];
778 [result setObject:name forKey:kOOTextureSpecifierNameKey];
785 [result oo_setUnsignedInteger:options forKey:kOOTextureSpecifierFlagValueInternalKey];
789 NSString *value =
nil;
807 if (value !=
nil) [result setObject:value forKey:kOOTextureSpecifierNoShrinkKey];
819 if (value !=
nil) [result setObject:value forKey:kOOTextureSpecifierMagFilterKey];
843 if (value !=
nil) [result setObject:value forKey:kOOTextureSpecifierSwizzleKey];
845 if (options &
kOOTextureNoShrink) [result oo_setBool:YES forKey:kOOTextureSpecifierNoShrinkKey];
846 if (options &
kOOTextureRepeatS) [result oo_setBool:YES forKey:kOOTextureSpecifierRepeatSKey];
847 if (options &
kOOTextureRepeatT) [result oo_setBool:YES forKey:kOOTextureSpecifierRepeatTKey];
892#if GL_EXT_texture_rectangle
895 options &= ~kOOTextureAllowRectTexture;
898 options &= ~kOOTextureAllowRectTexture;
920 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