38#define DUMP_COMBINER 0
45@interface OOCombinedEmissionMapGenerator (Private)
47- (id) initWithEmissionMapSpec:(NSDictionary *)emissionMapSpec
48 emissionColor:(
OOColor *)emissionColor
50 diffuseColor:(
OOColor *)diffuseColor
51 illuminationMapSpec:(NSDictionary *)illuminationMapSpec
52 illuminationColor:(
OOColor *)illuminationColor
53 isCombinedMap:(BOOL)isCombinedMap
54 optionsSpecifier:(NSDictionary *)spec;
63- (id) initWithEmissionMapSpec:(NSDictionary *)emissionMapSpec
64 emissionColor:(
OOColor *)emissionColor
66 diffuseColor:(
OOColor *)diffuseColor
67 illuminationMapSpec:(NSDictionary *)illuminationMapSpec
68 illuminationColor:(
OOColor *)illuminationColor
69 optionsSpecifier:(NSDictionary *)spec
82- (id) initWithEmissionAndIlluminationMapSpec:(NSDictionary *)emissionAndIlluminationMapSpec
84 diffuseColor:(
OOColor *)diffuseColor
85 emissionColor:(
OOColor *)emissionColor
86 illuminationColor:(
OOColor *)illuminationColor
87 optionsSpecifier:(NSDictionary *)spec
89 return [
self initWithEmissionMapSpec:emissionAndIlluminationMapSpec
90 emissionColor:emissionColor
92 diffuseColor:diffuseColor
93 illuminationMapSpec:nil
94 illuminationColor:illuminationColor
96 optionsSpecifier:spec];
100- (id) initWithEmissionMapSpec:(NSDictionary *)emissionMapSpec
101 emissionColor:(
OOColor *)emissionColor
103 diffuseColor:(
OOColor *)diffuseColor
104 illuminationMapSpec:(NSDictionary *)illuminationMapSpec
105 illuminationColor:(
OOColor *)illuminationColor
106 isCombinedMap:(BOOL)isCombinedMap
107 optionsSpecifier:(NSDictionary *)spec
109 if (emissionMapSpec ==
nil && illuminationMapSpec ==
nil)
115 NSParameterAssert(illuminationMapSpec ==
nil || !isCombinedMap);
123 if ((
self = [super initWithPath:
@"<generated emission map>" options:options]))
130 illuminationColor =
ModulateColor(diffuseColor, illuminationColor);
132 if ([emissionColor isWhite]) emissionColor =
nil;
133 if ([illuminationColor isWhite]) illuminationColor =
nil;
134 if (!isCombinedMap && illuminationMapSpec ==
nil) diffuseMap =
nil;
137 NSMutableDictionary *emissionSpec = [emissionMapSpec mutableCopy];
138 [emissionSpec oo_setBool:YES forKey:kOOTextureSpecifierExtraShrinkKey];
139 _emissionSpec = emissionSpec;
141 NSMutableDictionary *illuminationSpec = [illuminationMapSpec mutableCopy];
142 [illuminationSpec oo_setBool:YES forKey:kOOTextureSpecifierExtraShrinkKey];
143 _illuminationSpec = illuminationSpec;
145 _diffuseMap = [diffuseMap
retain];
147 _emissionColor = [emissionColor retain];
148 _illuminationColor = [illuminationColor retain];
149 _isCombinedMap = isCombinedMap;
151 _textureOptions = options;
152 _anisotropy = anisotropy;
155 _cacheKey = [
self constructCacheKey];
163 if (diffuseMap !=
nil)
167 _diffuseDesc = [[diffuseMap shortDescription] copy];
176 if (_emissionSpec !=
nil)
183 _emissionDesc = [[emissionMapLoader shortDescription] copy];
186 if (_illuminationSpec !=
nil)
193 _illuminationDesc = [[illuminationMapLoader shortDescription] copy];
205 NSMutableString *cacheKey = [NSMutableString string];
207 if (_isCombinedMap) [cacheKey appendString:@"combined emission and illumination map;"];
208 else if (_emissionSpec ==
nil) [cacheKey appendString:@"illumination map;"];
209 else if (_illuminationSpec ==
nil) [cacheKey appendString:@"emission map;"];
210 else [cacheKey appendString:@"merged emission and illumination map;"];
212 NSString *emissionDesc =
nil;
213 if (_emissionSpec !=
nil)
216 [cacheKey appendFormat:@"emission:{%@}", emissionDesc];
217 if (_emissionColor !=
nil) [cacheKey appendFormat:@"*%@", [_emissionColor rgbaDescription]];
218 [cacheKey appendString:@";"];
221 NSString *illuminationDesc =
nil;
224 illuminationDesc = [NSString stringWithFormat:@"%@:a", emissionDesc];
226 else if (_illuminationSpec !=
nil)
231 if (illuminationDesc !=
nil)
233 [cacheKey appendFormat:@"illumination:{%@}*{%@}", illuminationDesc, [_diffuseMap cacheKey]];
234 if (_illuminationColor !=
nil) [cacheKey appendFormat:@"*%@", [_illuminationColor rgbaDescription]];
235 [cacheKey appendString:@";"];
265- (NSString *) descriptionComponents
267 NSMutableString *result = [NSMutableString string];
268 BOOL haveIllumination = NO;
270 if (_emissionDesc !=
nil)
272 [result appendFormat:@"emission map: %@", _emissionDesc];
275 [result appendString:@".rgb"];
277 if (_emissionColor !=
nil)
279 [result appendFormat:@" * %@", [_emissionColor rgbaDescription]];
284 [result appendFormat:@", illumination map: %@.a", _emissionDesc];
285 haveIllumination = YES;
289 if (_illuminationDesc !=
nil)
291 if (_emissionDesc !=
nil) [result appendString:@", "];
292 [result appendFormat:@"illumination map: %@", _illuminationDesc];
293 haveIllumination = YES;
296 if (haveIllumination)
298 if (_diffuseDesc !=
nil)
300 [result appendFormat:@" * %@", _diffuseDesc];
302 if (_illuminationColor !=
nil)
304 [result appendFormat:@" * %@", [_illuminationColor rgbaDescription]];
313- (uint32_t) textureOptions
315 return _textureOptions;
319- (GLfloat) anisotropy
331- (NSString *) cacheKey
340 BOOL haveEmission = NO, haveIllumination = NO, haveDiffuse = NO;
343 static unsigned sTexID = 0;
344 unsigned texID = ++sTexID, dumpCount = 0;
346#define DUMP(pm, label) OODumpPixMap(pm, [NSString stringWithFormat:@"lightmap %u.%u - %@", texID, ++dumpCount, label]);
348#define DUMP(pm, label) do {} while (0)
352 if (haveEmission)
DUMP(_emissionPx,
@"source emission map");
360 haveIllumination = YES;
361 DUMP(illuminationPx,
@"extracted illumination map");
365 if (haveEmission && _emissionColor !=
nil)
367 OOPixMapModulateUniform(&_emissionPx, [_emissionColor redComponent], [_emissionColor greenComponent], [_emissionColor blueComponent], 1.0);
368 DUMP(_emissionPx,
@"modulated emission map");
373 NSAssert(!_isCombinedMap,
@"OOCombinedEmissionMapGenerator configured with both illumination map and combined emission/illumination map.");
375 illuminationPx = _illuminationPx;
376 _illuminationPx.
pixels = NULL;
377 haveIllumination = YES;
378 DUMP(illuminationPx,
@"source illumination map");
382 if (haveIllumination && _illuminationColor !=
nil)
384 OOPixMapModulateUniform(&illuminationPx, [_illuminationColor redComponent], [_illuminationColor greenComponent], [_illuminationColor blueComponent], 1.0);
385 DUMP(illuminationPx,
@"modulated illumination map");
390 if (haveDiffuse)
DUMP(_diffusePx,
@"source diffuse map");
392 if (haveIllumination && haveDiffuse)
398 DUMP(illuminationPx,
@"combined diffuse and illumination map");
402 if (haveIllumination)
409 DUMP(_emissionPx,
@"combined emission and illumination map");
411 else if (haveIllumination)
414 _emissionPx = illuminationPx;
416 illuminationPx.
pixels = NULL;
418 haveIllumination = NO;
422 (void)haveIllumination;
428 _data = _emissionPx.pixels;
429 _width = _emissionPx.width;
430 _height = _emissionPx.height;
431 _rowBytes = _emissionPx.rowBytes;
432 _format = _emissionPx.format;
434 _emissionPx.pixels = NULL;
438 OOLogERR(
@"texture.combinedEmissionMap.error",
@"Unknown error loading %@",
self);
447 if (a ==
nil)
return b;
448 if (b ==
nil)
return a;
470 if (pmA->
width != minWidth || pmA->
height != minHeight)
474 if (pmB->
width != minWidth || pmB->
height != minHeight)
static OOColor * ModulateColor(OOColor *a, OOColor *b)
static void ScaleToMatch(OOPixMap *pmA, OOPixMap *pmB)
#define OOLogERR(class, format,...)
BOOL OOPixMapModulateUniform(OOPixMap *ioPixMap, float f0, float f1, float f2, float f3)
BOOL OOExtractPixMapChannel(OOPixMap *ioPixMap, uint8_t channelIndex, BOOL compactWhenDone)
BOOL OOPixMapAddPixMap(OOPixMap *ioDstPixMap, OOPixMap otherPixMap)
BOOL OOPixMapModulatePixMap(OOPixMap *ioDstPixMap, OOPixMap otherPixMap)
BOOL OOPixMapToRGBA(OOPixMap *ioPixMap)
uint_fast32_t OOPixMapDimension
void OOFreePixMap(OOPixMap *ioPixMap)
const OOPixMap kOONullPixMap
OOINLINE BOOL OOIsNullPixMap(OOPixMap pixMap)
BOOL OOIsValidPixMap(OOPixMap pixMap)
BOOL OOPixMapFormatHasAlpha(OOPixMapFormat format) PURE_FUNC
OOPixMap OODuplicatePixMap(OOPixMap srcPixMap, size_t desiredSize)
OOINLINE void OOCompactPixMap(OOPixMap *ioPixMap)
OOPixMap OOScalePixMap(OOPixMap srcPixMap, OOPixMapDimension dstWidth, OOPixMapDimension dstHeight, BOOL leaveSpaceForMipMaps)
OOTextureFlags OOApplyTextureOptionDefaults(OOTextureFlags options)
BOOL OOInterpretTextureSpecifier(id specifier, NSString **outName, OOTextureFlags *outOptions, float *outAnisotropy, float *outLODBias, BOOL ignoreExtract)
NSString * OOTextureCacheKeyForSpecifier(id specifier)
NSString * constructCacheKey()
OOColor * colorWithRGBAComponents:(OORGBAComponents components)
OORGBAComponents rgbaComponents()
id initWithEmissionMapSpec:emissionColor:diffuseMap:diffuseColor:illuminationMapSpec:illuminationColor:isCombinedMap:optionsSpecifier:(NSDictionary *emissionMapSpec, [emissionColor] OOColor *emissionColor, [diffuseMap] OOTexture *diffuseMap, [diffuseColor] OOColor *diffuseColor, [illuminationMapSpec] NSDictionary *illuminationMapSpec, [illuminationColor] OOColor *illuminationColor, [isCombinedMap] BOOL isCombinedMap, [optionsSpecifier] NSDictionary *spec)
id loaderWithTextureSpecifier:extraOptions:folder:(id specifier,[extraOptions] uint32_t extraOptions,[folder] NSString *folder)
BOOL getResult:format:originalWidth:originalHeight:(OOPixMap *result,[format] OOTextureDataFormat *outFormat,[originalWidth] uint32_t *outWidth,[originalHeight] uint32_t *outHeight)
OOPixMap copyPixMapRepresentation()