104@interface OOTexture (OOPrivate)
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];
134+ (id)textureWithName:(NSString *)name {
…}
181+ (id)textureWithName:(NSString *)name
182 inFolder:(NSString*)directory
186 options:kOOTextureDefaultOptions
192+ (id)textureWithConfiguration:(
id)configuration
198+ (id) textureWithConfiguration:(
id)configuration extraOptions:(
OOTextureFlags)extraOptions
202 GLfloat anisotropy = 0.0f;
203 GLfloat lodBias = 0.0f;
225 if (generator ==
nil)
return nil;
227#ifndef OOTEXTURE_NO_CACHE
232 if (![generator enqueue])
234 OOLogERR(
@"texture.generator.queue.failed",
@"Failed to queue generator %@", generator);
237 OOLog(
@"texture.generator.queue",
@"Queued texture generator %@", generator);
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
284 if (
gOOTextureInfo.textureLODBiasAvailable)
OOGL(glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0));
346 return NSMakeSize(1.0, 1.0);
363 [sLiveTextureCache autorelease];
375 NSEnumerator *textureEnum =
nil;
389- (void) setTrace:(BOOL)trace
393 OOLog(
@"texture.allocTrace.begin",
@"Started tracing texture %p with retain count %lu.",
self, [
self retainCount]);
389- (void) setTrace:(BOOL)trace {
…}
407 NSMutableSet *result = [
NSMutableSet setWithCapacity:[sAllLiveTextures count]];
409 NSEnumerator *texEnum =
nil;
446#ifndef OOTEXTURE_NO_CACHE
447 NSString *cacheKey = [
self cacheKey];
448 if (cacheKey ==
nil)
return;
454 [sLiveTextureCache setObject:[
NSValue valueWithPointer:
self] forKey:cacheKey];
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);
504#ifndef OOTEXTURE_NO_CACHE
507 return (
OOTexture *)[[sLiveTextureCache objectForKey:key] pointerValue];
526#if GL_EXT_texture_filter_anisotropic
528 OOGL(glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &
gOOTextureInfo.anisotropyScale));
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];
572- (id) retainInContext:(NSString *)context {
…}
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);
584- (void) releaseInContext:(NSString *)context {
…}
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];
596- (id) autoreleaseInContext:(NSString *)context {
…}
629@implementation NSDictionary (OOTextureConveniences)
631- (NSDictionary *) oo_textureSpecifierForKey:(
id)key defaultName:(NSString *)name
631- (NSDictionary *) oo_textureSpecifierForKey:(
id)key defaultName:(NSString *)name {
…}
638@implementation NSArray (OOTextureConveniences)
640- (NSDictionary *) oo_textureSpecifierAtIndex:(
unsigned)index defaultName:(NSString *)name
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
920 return [NSString stringWithFormat:@"%@%@%@:0x%.4X/%g/%g", directory ? directory : (NSString *)@"", directory ? @"/" : @"", name, options, anisotropy, lodBias];
198+ (id) textureWithConfiguration:(
id)configuration extraOptions:(
OOTextureFlags)extraOptions {
…}
192+ (id)textureWithConfiguration:(
id)configuration {
…}
181+ (id)textureWithName:(NSString *)name {
…}
#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 kOOTextureSpecifierSelfColorKey
NSString *const kOOTextureSpecifierNoShrinkKey
NSString *const kOOTextureSpecifierNameKey
BOOL OOCubeMapsAvailable(void)
uint8_t OOTextureComponentsForFormat(OOTextureDataFormat format)
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)
NSString *const kOOTextureSpecifierScaleFactorKey
@ kOOTextureAllowRectTexture
@ kOOTextureExtractChannelA
@ kOOTextureExtractChannelB
@ kOOTextureMinFilterDefault
@ kOOTextureExtractChannelNone
@ kOOTextureMagFilterMask
@ kOOTextureExtractChannelMask
@ kOOTextureMinFilterLinear
@ kOOTextureMinFilterMask
@ kOOTextureDefaultOptions
@ kOOTextureMinFilterMipMap
@ kOOTextureMagFilterNearest
@ kOOTextureExtractChannelG
@ kOOTextureFlagsAllowedForRectangleTexture
@ kOOTextureExtractChannelR
@ kOOTextureMagFilterLinear
@ kOOTextureMinFilterNearest
#define kOOTextureDefaultAnisotropy
NSString *const kOOTextureSpecifierBindingKey
@ kOOTextureDataGrayscaleAlpha
@ kOOTextureDataGrayscale
NSString *const kOOTextureSpecifierIlluminationModeKey
NSString *const kOOTextureSpecifierMinFilterKey
NSString *const kOOTextureSpecifierMagFilterKey
NSString *const kOOTextureSpecifierAnisotropyKey
NSString *const kOOTextureSpecifierRepeatSKey
OOPixMapFormat OOTextureDataFormat
#define kOOTextureDefaultLODBias
NSString *const kOOTextureSpecifierModulateColorKey
BOOL OOInterpretTextureSpecifier(id specifier, NSString **outName, OOTextureFlags *outOptions, float *outAnisotropy, float *outLODBias, BOOL ignoreExtract)
NSString *const kOOTextureSpecifierCubeMapKey
NSString *const kOOTextureSpecifierSwizzleKey
NSString *const kOOTextureSpecifierExtraShrinkKey
NSString *const kOOTextureSpecifierLODBiasKey
#define CLEAR_TRACE_CONTEXT()
#define SET_TRACE_CONTEXT(str)
static OOCache * sRecentTextures
static NSMutableDictionary * sLiveTextureCache
static NSString * sGlobalTraceContext
NSString * OOTextureCacheKeyForSpecifier(id specifier)
static BOOL sCheckedExtensions
static NSMutableSet * sAllLiveTextures
static NSString *const kOOTextureSpecifierFlagValueInternalKey
NSString * OOGenerateTextureCacheKey(NSString *directory, NSString *name, OOTextureFlags options, float anisotropy, float lodBias)
OOTextureInfo gOOTextureInfo
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()
id textureWithConfiguration:extraOptions:(id configuration,[extraOptions] OOTextureFlags extraOptions)
OOTexture * existingTextureForKey:(NSString *key)
NSSize originalDimensions()
BOOL isRectangleTexture()
id textureWithGenerator:enqueue:(OOTextureGenerator *generator,[enqueue] BOOL enqueue)
OOPixMap copyPixMapRepresentation()
id textureWithName:inFolder:options:anisotropy:lodBias:(NSString *name,[inFolder] NSString *directory,[options] OOTextureFlags options,[anisotropy] GLfloat anisotropy,[lodBias] GLfloat lodBias)
void ensureFinishedLoading()
void releaseInContext:(NSString *context)
id retainInContext:(NSString *context)
NSArray * cachedTexturesByAge()
id autoreleaseInContext:(NSString *context)
NSString * pathForFileNamed:inFolder:(NSString *fileName,[inFolder] NSString *folderName)