99@interface OOTexture (OOPrivate)
108#ifdef OO_DEBUG_MONITOR_ENABLED
109- (id)retainInContext:(NSString*)context;
110- (void)releaseInContext:(NSString*)context;
111- (id)autoreleaseInContext:(NSString*)context;
116#ifdef OO_DEBUG_MONITOR_ENABLED
117static NSString* sGlobalTraceContext =
nil;
119#define SET_TRACE_CONTEXT(str) \
121 sGlobalTraceContext = (str); \
124#define SET_TRACE_CONTEXT(str) \
128#define CLEAR_TRACE_CONTEXT() SET_TRACE_CONTEXT(nil)
132+ (id)textureWithName:(NSString*)name
133 inFolder:(NSString*)directory
135 anisotropy:(GLfloat)anisotropy
136 lodBias:(GLfloat)lodBias
140 NSString* path =
nil;
170 result = [[[
OOConcreteTexture alloc] initWithPath:path key:key options:options anisotropy:anisotropy lodBias:lodBias] autorelease];
176+ (id)textureWithName:(NSString*)name
177 inFolder:(NSString*)directory
181 options:kOOTextureDefaultOptions
183 lodBias:kOOTextureDefaultLODBias];
186+ (id)textureWithConfiguration:(
id)configuration
191+ (id)textureWithConfiguration:(
id)configuration extraOptions:(
OOTextureFlags)extraOptions
195 GLfloat anisotropy = 0.0f;
196 GLfloat lodBias = 0.0f;
216 if (generator ==
nil)
219#ifndef OOTEXTURE_NO_CACHE
221 if (existing !=
nil && !enqueue)
222 return [[
existing retain] autorelease];
225 if (![generator enqueue]) {
226 OOLogERR(
@"texture.generator.queue.failed",
@"Failed to queue generator %@", generator);
229 OOLog(
@"texture.generator.queue",
@"Queued texture generator %@", generator);
242 if ((
self = [super
init])) {
245 [sAllLiveTextures addObject:[
NSValue valueWithPointer:
self]];
253 [sAllLiveTextures removeObject:[
NSValue valueWithPointer:
self]];
266 OOGL(glBindTexture(GL_TEXTURE_2D, 0));
267#if OO_TEXTURE_CUBE_MAP
269 OOGL(glBindTexture(GL_TEXTURE_CUBE_MAP, 0));
272#if GL_EXT_texture_lod_bias
274 OOGL(glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, 0));
326 return NSMakeSize(1.0, 1.0);
341 [sLiveTextureCache autorelease];
352 NSEnumerator* textureEnum =
nil;
363#ifdef OO_DEBUG_MONITOR_ENABLED
364- (void)setTrace:(BOOL)trace
366 if (trace && !_trace) {
367 OOLog(
@"texture.allocTrace.begin",
@"Started tracing texture %p with retain count %zu.",
self, [
self retainCount]);
372+ (NSArray*)cachedTexturesByAge
379 NSMutableSet* result = [NSMutableSet setWithCapacity:[sAllLiveTextures count]];
382 [result addObject:[box pointerValue]];
390 NSSize dimensions = [
self dimensions];
391 size_t size = dimensions.width * dimensions.height;
392 if ([
self isCubeMap])
394 if ([
self isMipMapped])
414#ifndef OOTEXTURE_NO_CACHE
415 NSString* cacheKey = [
self cacheKey];
424 [sLiveTextureCache setObject:[
NSValue valueWithPointer:
self] forKey:cacheKey];
443#ifndef OOTEXTURE_NO_CACHE
444 NSString* cacheKey = [
self cacheKey];
448 [sLiveTextureCache removeObjectForKey:cacheKey];
462 NSAssert2(0,
@"Texture retain count error for %@; cacheKey is %@.",
self, cacheKey);
471#ifndef OOTEXTURE_NO_CACHE
473 return (
OOTexture*)[[sLiveTextureCache objectForKey:key] pointerValue];
491#if GL_EXT_texture_filter_anisotropic
493 OOGL(glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &
gOOTextureInfo.anisotropyScale));
494 gOOTextureInfo.anisotropyScale *=
OOClamp_0_1_f([[NSUserDefaults standardUserDefaults] oo_floatForKey:
@"texture-anisotropy-scale" defaultValue:0.5]);
497#ifdef GL_CLAMP_TO_EDGE
501#if OO_GL_CLIENT_STORAGE
507#if GL_EXT_texture_lod_bias
508 if ([[NSUserDefaults standardUserDefaults] oo_boolForKey:
@"use-texture-lod-bias" defaultValue:YES]) {
515#if GL_EXT_texture_rectangle
519#if OO_TEXTURE_CUBE_MAP
520 if (![[NSUserDefaults standardUserDefaults] boolForKey:
@"disable-cube-maps"]) {
529#ifdef OO_DEBUG_MONITOR_ENABLED
530- (id)retainInContext:(NSString*)context
534 OOLog(
@"texture.allocTrace.retain",
@"Texture %p retained (retain count -> %zu) - %@.",
self, [
self retainCount] + 1, context);
536 OOLog(
@"texture.allocTrace.retain",
@"Texture %p retained (retain count -> %zu).",
self, [
self retainCount] + 1);
539 return [
super retain];
542- (void)releaseInContext:(NSString*)context
546 OOLog(
@"texture.allocTrace.release",
@"Texture %p released (retain count -> %zu) - %@.",
self, [
self retainCount] - 1, context);
548 OOLog(
@"texture.allocTrace.release",
@"Texture %p released (retain count -> %zu).",
self, [
self retainCount] - 1);
554- (id)autoreleaseInContext:(NSString*)context
558 OOLog(
@"texture.allocTrace.autoreleased",
@"Texture %p autoreleased - %@.",
self, context);
560 OOLog(
@"texture.allocTrace.autoreleased",
@"Texture %p autoreleased.",
self);
563 return [
super autorelease];
568 return [
self retainInContext:sGlobalTraceContext];
571- (oneway void)release
573 [
self releaseInContext:sGlobalTraceContext];
578 return [
self autoreleaseInContext:sGlobalTraceContext];
584@implementation NSDictionary (OOTextureConveniences)
586- (NSDictionary*)oo_textureSpecifierForKey:(
id)key defaultName:(NSString*)name
593@implementation NSArray (OOTextureConveniences)
595- (NSDictionary*)oo_textureSpecifierAtIndex:(
unsigned)index defaultName:(NSString*)name
605 object = defaultName;
606 if ([
object isKindOfClass:[NSString
class]]) {
607 if ([
object isEqualToString:
@""])
609 return [NSDictionary dictionaryWithObject:object forKey:@"name"];
611 if (![
object isKindOfClass:[NSDictionary
class]])
615 if (defaultName ==
nil || [
object oo_stringForKey:
@"name"] !=
nil)
619 NSMutableDictionary* mutableResult = [NSMutableDictionary dictionaryWithDictionary:object];
620 [mutableResult setObject:[[defaultName copy] autorelease] forKey:@"name"];
621 return mutableResult;
650 NSString* name =
nil;
655 if ([specifier isKindOfClass:[NSString
class]]) {
657 }
else if ([specifier isKindOfClass:[NSDictionary
class]]) {
658 name = [specifier oo_stringForKey:kOOTextureSpecifierNameKey];
660 OOLog(
@"texture.load.noName",
@"Invalid texture configuration dictionary (must specify name):\n%@", specifier);
664 int quickFlags = [specifier oo_intForKey:kOOTextureSpecifierFlagValueInternalKey defaultValue:-1];
665 if (quickFlags != -1) {
666 options = quickFlags;
668 NSString* filterString = [specifier oo_stringForKey:kOOTextureSpecifierMinFilterKey defaultValue:@"default"];
669 if ([filterString isEqualToString:
@"nearest"])
671 else if ([filterString isEqualToString:
@"linear"])
673 else if ([filterString isEqualToString:
@"mipmap"])
678 filterString = [specifier oo_stringForKey:kOOTextureSpecifierMagFilterKey defaultValue:@"default"];
679 if ([filterString isEqualToString:
@"nearest"])
695 if (!ignoreExtract) {
696 NSString* extractChannel = [specifier oo_stringForKey:@"extract_channel"];
697 if (extractChannel !=
nil) {
698 if ([extractChannel isEqualToString:
@"r"])
700 else if ([extractChannel isEqualToString:
@"g"])
702 else if ([extractChannel isEqualToString:
@"b"])
704 else if ([extractChannel isEqualToString:
@"a"])
707 OOLogWARN(
@"texture.load.extractChannel.invalid",
@"Unknown value \"%@\
" for extract_channel in specifier \"%@\" (should be \"r\", \"g\", \"b\" or \"a\").", extractChannel, specifier);
712 anisotropy = [specifier oo_floatForKey:@"anisotropy" defaultValue:kOOTextureDefaultAnisotropy];
713 lodBias = [specifier oo_floatForKey:@"texture_LOD_bias" defaultValue:kOOTextureDefaultLODBias];
716 if (specifier !=
nil)
721 if ([name length] == 0)
726 if (outOptions != NULL)
727 *outOptions = options;
728 if (outAnisotropy != NULL)
729 *outAnisotropy = anisotropy;
730 if (outLODBias != NULL)
731 *outLODBias = lodBias;
738 NSMutableDictionary* result = [NSMutableDictionary dictionary];
740 [result setObject:name forKey:kOOTextureSpecifierNameKey];
743 [result oo_setFloat:anisotropy forKey:kOOTextureSpecifierAnisotropyKey];
745 [result oo_setFloat:lodBias forKey:kOOTextureSpecifierLODBiasKey];
748 [result oo_setUnsignedInteger:options forKey:kOOTextureSpecifierFlagValueInternalKey];
750 NSString* value =
nil;
768 [result setObject:value forKey:kOOTextureSpecifierNoShrinkKey];
780 [result setObject:value forKey:kOOTextureSpecifierMagFilterKey];
804 [result setObject:value forKey:kOOTextureSpecifierSwizzleKey];
807 [result oo_setBool:YES forKey:kOOTextureSpecifierNoShrinkKey];
809 [result oo_setBool:YES forKey:kOOTextureSpecifierRepeatSKey];
811 [result oo_setBool:YES forKey:kOOTextureSpecifierRepeatTKey];
813 [result oo_setBool:YES forKey:kOOTextureSpecifierCubeMapKey];
848#if GL_EXT_texture_rectangle
872 return [NSString stringWithFormat:@"%@%@%@:0x%.4X/%g/%g", directory ? directory : (NSString*)@"", directory ? @"/" : @"", name, options, anisotropy, lodBias];
OOINLINE float OOClamp_0_1_f(float value) INLINE_CONST_FUNC
#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
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()
NSString * pathForFileNamed:inFolder:(NSString *fileName,[inFolder] NSString *folderName)