Oolite 1.91.0.7646-241128-10e222e
Loading...
Searching...
No Matches
OOCombinedEmissionMapGenerator Class Reference

#include <OOCombinedEmissionMapGenerator.h>

+ Inheritance diagram for OOCombinedEmissionMapGenerator:
+ Collaboration diagram for OOCombinedEmissionMapGenerator:

Instance Methods

(id) - initWithEmissionMapSpec:emissionColor:diffuseMap:diffuseColor:illuminationMapSpec:illuminationColor:optionsSpecifier:
 
(id) - initWithEmissionAndIlluminationMapSpec:diffuseMap:diffuseColor:emissionColor:illuminationColor:optionsSpecifier:
 
(id) - initWithEmissionMapSpec:emissionColor:diffuseMap:diffuseColor:illuminationMapSpec:illuminationColor:isCombinedMap:optionsSpecifier: [implementation]
 
(NSString *) - constructCacheKey [implementation]
 
(void) - dealloc [implementation]
 
(NSString *) - descriptionComponents [implementation]
 
(uint32_t) - textureOptions [implementation]
 
(GLfloat) - anisotropy [implementation]
 
(GLfloat) - lodBias [implementation]
 
(NSString *) - cacheKey [implementation]
 
(void) - loadTexture [implementation]
 
- Instance Methods inherited from OOTextureGenerator
(BOOL) - enqueue
 
- Instance Methods inherited from OOTextureLoader
(BOOL) - isReady
 
(BOOL) - getResult:format:originalWidth:originalHeight:
 
(id) - initWithPath:options:
 
(NSString *) - path
 
(NSString *) - shortDescriptionComponents [implementation]
 
(void) - performAsyncTask [implementation]
 
(void) - generateMipMapsForCubeMap [implementation]
 
(void) - applySettings [implementation]
 
(void) - getDesiredWidth:andHeight: [implementation]
 
(void) - completeAsyncTask [implementation]
 
- Instance Methods inherited from <OOAsyncWorkTask>

Private Attributes

NSString * _cacheKey
 
NSDictionary * _emissionSpec
 
NSDictionary * _illuminationSpec
 
OOTexture_diffuseMap
 
OOPixMap _emissionPx
 
OOPixMap _diffusePx
 
OOPixMap _illuminationPx
 
OOColor_emissionColor
 
OOColor_illuminationColor
 
BOOL _isCombinedMap
 
uint32_t _textureOptions
 
GLfloat _anisotropy
 
GLfloat _lodBias
 
NSString * _emissionDesc
 
NSString * _illuminationDesc
 
NSString * _diffuseDesc
 

Additional Inherited Members

- Class Methods inherited from OOTextureLoader
(id) + loaderWithPath:options:
 
(id) + loaderWithTextureSpecifier:extraOptions:folder:
 
(void) + setUp [implementation]
 
- Protected Attributes inherited from OOTextureLoader
NSString * _path
 
OOTextureFlags _options
 
uint8_t _generateMipMaps: 1
 
uint8_t _scaleAsNormalMap: 1
 
uint8_t _avoidShrinking: 1
 
uint8_t _noScalingWhatsoever: 1
 
uint8_t _extractChannel: 1
 
uint8_t _allowCubeMap: 1
 
uint8_t _isCubeMap: 1
 
uint8_t _ready: 1
 
uint8_t _extractChannelIndex
 
OOTextureDataFormat _format
 
void * _data
 
uint32_t _width
 
uint32_t _height
 
uint32_t _originalWidth
 
uint32_t _originalHeight
 
uint32_t _shrinkThreshold
 
uint32_t _maxSize
 
size_t _rowBytes
 

Detailed Description

Definition at line 38 of file OOCombinedEmissionMapGenerator.h.

Method Documentation

◆ anisotropy

- (GLfloat) anisotropy
implementation

Reimplemented from OOTextureGenerator.

Definition at line 463 of file OOCombinedEmissionMapGenerator.m.

References OOPixMap::height, MIN, OOIsValidPixMap(), OOScalePixMap(), and OOPixMap::width.

+ Here is the call graph for this function:

◆ cacheKey

- (NSString *) cacheKey
implementation

Reimplemented from OOTextureGenerator.

Definition at line 463 of file OOCombinedEmissionMapGenerator.m.

◆ constructCacheKey

- (NSString *) constructCacheKey
implementation

Provided by category OOCombinedEmissionMapGenerator(Private).

Definition at line 463 of file OOCombinedEmissionMapGenerator.m.

204{
205 NSMutableString *cacheKey = [NSMutableString string];
206
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;"];
211
212 NSString *emissionDesc = nil;
213 if (_emissionSpec != nil)
214 {
216 [cacheKey appendFormat:@"emission:{%@}", emissionDesc];
217 if (_emissionColor != nil) [cacheKey appendFormat:@"*%@", [_emissionColor rgbaDescription]];
218 [cacheKey appendString:@";"];
219 }
220
221 NSString *illuminationDesc = nil;
222 if (_isCombinedMap)
223 {
224 illuminationDesc = [NSString stringWithFormat:@"%@:a", emissionDesc];
225 }
226 else if (_illuminationSpec != nil)
227 {
229 }
230
231 if (illuminationDesc != nil)
232 {
233 [cacheKey appendFormat:@"illumination:{%@}*{%@}", illuminationDesc, [_diffuseMap cacheKey]];
234 if (_illuminationColor != nil) [cacheKey appendFormat:@"*%@", [_illuminationColor rgbaDescription]];
235 [cacheKey appendString:@";"];
236 }
237
238 return cacheKey;
239}
return nil
NSString * OOTextureCacheKeyForSpecifier(id specifier)
Definition OOTexture.m:924

◆ dealloc

◆ descriptionComponents

- (NSString *) descriptionComponents
implementation

Reimplemented from OOTextureLoader.

Definition at line 463 of file OOCombinedEmissionMapGenerator.m.

266{
267 NSMutableString *result = [NSMutableString string];
268 BOOL haveIllumination = NO;
269
270 if (_emissionDesc != nil)
271 {
272 [result appendFormat:@"emission map: %@", _emissionDesc];
273 if (_isCombinedMap)
274 {
275 [result appendString:@".rgb"];
276 }
277 if (_emissionColor != nil)
278 {
279 [result appendFormat:@" * %@", [_emissionColor rgbaDescription]];
280 }
281
282 if (_isCombinedMap)
283 {
284 [result appendFormat:@", illumination map: %@.a", _emissionDesc];
285 haveIllumination = YES;
286 }
287 }
288
289 if (_illuminationDesc != nil)
290 {
291 if (_emissionDesc != nil) [result appendString:@", "];
292 [result appendFormat:@"illumination map: %@", _illuminationDesc];
293 haveIllumination = YES;
294 }
295
296 if (haveIllumination)
297 {
298 if (_diffuseDesc != nil)
299 {
300 [result appendFormat:@" * %@", _diffuseDesc];
301 }
302 if (_illuminationColor != nil)
303 {
304 [result appendFormat:@" * %@", [_illuminationColor rgbaDescription]];
305 }
306 }
307
308 return result;
309}

◆ initWithEmissionAndIlluminationMapSpec:diffuseMap:diffuseColor:emissionColor:illuminationColor:optionsSpecifier:

- (id) initWithEmissionAndIlluminationMapSpec: (NSDictionary *) emissionAndIlluminationMapSpec
diffuseMap: (OOTexture *) diffuseMap
diffuseColor: (OOColor *) diffuseColor
emissionColor: (OOColor *) emissionColor
illuminationColor: (OOColor *) illuminationColor
optionsSpecifier: (NSDictionary *) spec 

Definition at line 463 of file OOCombinedEmissionMapGenerator.m.

82 :(NSDictionary *)emissionAndIlluminationMapSpec
83 diffuseMap:(OOTexture *)diffuseMap
84 diffuseColor:(OOColor *)diffuseColor
85 emissionColor:(OOColor *)emissionColor
86 illuminationColor:(OOColor *)illuminationColor
87 optionsSpecifier:(NSDictionary *)spec
88{
89 return [self initWithEmissionMapSpec:emissionAndIlluminationMapSpec
90 emissionColor:emissionColor
91 diffuseMap:diffuseMap
92 diffuseColor:diffuseColor
93 illuminationMapSpec:nil
94 illuminationColor:illuminationColor
95 isCombinedMap:YES
96 optionsSpecifier:spec];
97}

◆ initWithEmissionMapSpec:emissionColor:diffuseMap:diffuseColor:illuminationMapSpec:illuminationColor:isCombinedMap:optionsSpecifier:

- (id) initWithEmissionMapSpec: (NSDictionary *) emissionMapSpec
emissionColor: (OOColor *) emissionColor
diffuseMap: (OOTexture *) diffuseMap
diffuseColor: (OOColor *) diffuseColor
illuminationMapSpec: (NSDictionary *) illuminationMapSpec
illuminationColor: (OOColor *) illuminationColor
isCombinedMap: (BOOL) isCombinedMap
optionsSpecifier: (NSDictionary *) spec 
implementation

Provided by category OOCombinedEmissionMapGenerator(Private).

Definition at line 463 of file OOCombinedEmissionMapGenerator.m.

100 :(NSDictionary *)emissionMapSpec
101 emissionColor:(OOColor *)emissionColor
102 diffuseMap:(OOTexture *)diffuseMap
103 diffuseColor:(OOColor *)diffuseColor
104 illuminationMapSpec:(NSDictionary *)illuminationMapSpec
105 illuminationColor:(OOColor *)illuminationColor
106 isCombinedMap:(BOOL)isCombinedMap
107 optionsSpecifier:(NSDictionary *)spec
108{
109 if (emissionMapSpec == nil && illuminationMapSpec == nil)
110 {
111 [self release];
112 return nil;
113 }
114
115 NSParameterAssert(illuminationMapSpec == nil || !isCombinedMap);
116
117 uint32_t options;
118 GLfloat anisotropy;
119 GLfloat lodBias;
120 OOInterpretTextureSpecifier(spec, NULL, &options, &anisotropy, &lodBias, YES);
121 options = OOApplyTextureOptionDefaults(options);
122
123 if ((self = [super initWithPath:@"<generated emission map>" options:options]))
124 {
125 /* Illumination contribution is:
126 illuminationMap * illuminationColor * diffuseMap * diffuseColor
127 Since illuminationColor and diffuseColor aren't used otherwise,
128 we may as well combine them up front.
129 */
130 illuminationColor = ModulateColor(diffuseColor, illuminationColor);
131
132 if ([emissionColor isWhite]) emissionColor = nil;
133 if ([illuminationColor isWhite]) illuminationColor = nil;
134 if (!isCombinedMap && illuminationMapSpec == nil) diffuseMap = nil; // Diffuse map is only used with illumination
135
136 // Insert extraShrink flag here instead of using extraOptions later because we need it in cache key too.
137 NSMutableDictionary *emissionSpec = [emissionMapSpec mutableCopy];
138 [emissionSpec oo_setBool:YES forKey:kOOTextureSpecifierExtraShrinkKey];
139 _emissionSpec = emissionSpec;
140
141 NSMutableDictionary *illuminationSpec = [illuminationMapSpec mutableCopy];
142 [illuminationSpec oo_setBool:YES forKey:kOOTextureSpecifierExtraShrinkKey];
143 _illuminationSpec = illuminationSpec;
144
145 _diffuseMap = [diffuseMap retain];
146
147 _emissionColor = [emissionColor retain];
148 _illuminationColor = [illuminationColor retain];
149 _isCombinedMap = isCombinedMap;
150
151 _textureOptions = options;
154
155 _cacheKey = [self constructCacheKey];
156
157 if ([OOTexture existingTextureForKey:_cacheKey] == nil)
158 {
159 /* Extract pixmap from diffuse map. This must be done in the main
160 thread even if scheduling is fixed, because it might involve
161 reading back pixels from OpenGL.
162 */
163 if (diffuseMap != nil)
164 {
166#ifndef NDEBUG
167 _diffuseDesc = [[diffuseMap shortDescription] copy];
168#endif
169 }
170
171 /* Extract emission and illumination pixmaps from loaders. Ideally,
172 this would be done asynchronously, but that requires dependency
173 management in OOAsyncWorkManager.
174 */
175 OOTextureDataFormat format;
176 if (_emissionSpec != nil)
177 {
178 OOTextureLoader *emissionMapLoader = [OOTextureLoader loaderWithTextureSpecifier:_emissionSpec
180 folder:@"Textures"];
181 [emissionMapLoader getResult:&_emissionPx format:&format originalWidth:NULL originalHeight:NULL];
182#ifndef NDEBUG
183 _emissionDesc = [[emissionMapLoader shortDescription] copy];
184#endif
185 }
186 if (_illuminationSpec != nil)
187 {
188 OOTextureLoader *illuminationMapLoader = [OOTextureLoader loaderWithTextureSpecifier:_illuminationSpec
190 folder:@"Textures"];
191 [illuminationMapLoader getResult:&_illuminationPx format:&format originalWidth:NULL originalHeight:NULL];
192#ifndef NDEBUG
193 _illuminationDesc = [[illuminationMapLoader shortDescription] copy];
194#endif
195 }
196 }
197 }
198
199 return self;
200}
static OOColor * ModulateColor(OOColor *a, OOColor *b)
OOPixMapFormat
Definition OOPixMap.h:39
OOTextureFlags OOApplyTextureOptionDefaults(OOTextureFlags options)
Definition OOTexture.m:855
BOOL OOInterpretTextureSpecifier(id specifier, NSString **outName, OOTextureFlags *outOptions, float *outAnisotropy, float *outLODBias, BOOL ignoreExtract)
Definition OOTexture.m:694
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()
Definition OOTexture.m:326

◆ initWithEmissionMapSpec:emissionColor:diffuseMap:diffuseColor:illuminationMapSpec:illuminationColor:optionsSpecifier:

- (id) initWithEmissionMapSpec: (NSDictionary *) emissionMapSpec
emissionColor: (OOColor *) emissionColor
diffuseMap: (OOTexture *) diffuseMap
diffuseColor: (OOColor *) diffuseColor
illuminationMapSpec: (NSDictionary *) illuminationMapSpec
illuminationColor: (OOColor *) illuminationColor
optionsSpecifier: (NSDictionary *) spec 

Definition at line 463 of file OOCombinedEmissionMapGenerator.m.

63 :(NSDictionary *)emissionMapSpec
64 emissionColor:(OOColor *)emissionColor
65 diffuseMap:(OOTexture *)diffuseMap
66 diffuseColor:(OOColor *)diffuseColor
67 illuminationMapSpec:(NSDictionary *)illuminationMapSpec
68 illuminationColor:(OOColor *)illuminationColor
69 optionsSpecifier:(NSDictionary *)spec
70{
71 return [self initWithEmissionMapSpec:emissionMapSpec
72 emissionColor:emissionColor
73 diffuseMap:diffuseMap
74 diffuseColor:diffuseColor
75 illuminationMapSpec:illuminationMapSpec
76 illuminationColor:illuminationColor
77 isCombinedMap:NO
78 optionsSpecifier:spec];
79}

◆ loadTexture

- (void) loadTexture
implementation

Reimplemented from OOTextureLoader.

Definition at line 463 of file OOCombinedEmissionMapGenerator.m.

338{
339 OOPixMap illuminationPx = kOONullPixMap;
340 BOOL haveEmission = NO, haveIllumination = NO, haveDiffuse = NO;
341
342#if DUMP_COMBINER
343 static unsigned sTexID = 0;
344 unsigned texID = ++sTexID, dumpCount = 0;
345
346#define DUMP(pm, label) OODumpPixMap(pm, [NSString stringWithFormat:@"lightmap %u.%u - %@", texID, ++dumpCount, label]);
347#else
348#define DUMP(pm, label) do {} while (0)
349#endif
350
351 haveEmission = !OOIsNullPixMap(_emissionPx);
352 if (haveEmission) DUMP(_emissionPx, @"source emission map");
353
354 // Extract illumination component if emission_and_illumination_map.
356 {
358 illuminationPx = OODuplicatePixMap(_emissionPx, 0);
359 OOExtractPixMapChannel(&illuminationPx, 3, YES);
360 haveIllumination = YES;
361 DUMP(illuminationPx, @"extracted illumination map");
362 }
363
364 // Tint emission map if necessary.
365 if (haveEmission && _emissionColor != nil)
366 {
367 OOPixMapModulateUniform(&_emissionPx, [_emissionColor redComponent], [_emissionColor greenComponent], [_emissionColor blueComponent], 1.0);
368 DUMP(_emissionPx, @"modulated emission map");
369 }
370
372 {
373 NSAssert(!_isCombinedMap, @"OOCombinedEmissionMapGenerator configured with both illumination map and combined emission/illumination map.");
374
375 illuminationPx = _illuminationPx;
376 _illuminationPx.pixels = NULL;
377 haveIllumination = YES;
378 DUMP(illuminationPx, @"source illumination map");
379 }
380
381 // Tint illumination map if necessary.
382 if (haveIllumination && _illuminationColor != nil)
383 {
384 OOPixMapModulateUniform(&illuminationPx, [_illuminationColor redComponent], [_illuminationColor greenComponent], [_illuminationColor blueComponent], 1.0);
385 DUMP(illuminationPx, @"modulated illumination map");
386 }
387
388 // Load diffuse map and combine with illumination map.
389 haveDiffuse = !OOIsNullPixMap(_diffusePx);
390 if (haveDiffuse) DUMP(_diffusePx, @"source diffuse map");
391
392 if (haveIllumination && haveDiffuse)
393 {
394 // Modulate illumination with diffuse map.
395 ScaleToMatch(&_diffusePx, &illuminationPx);
397 OOPixMapModulatePixMap(&illuminationPx, _diffusePx);
398 DUMP(illuminationPx, @"combined diffuse and illumination map");
399 }
401
402 if (haveIllumination)
403 {
404 if (haveEmission)
405 {
406 OOPixMapToRGBA(&illuminationPx);
407 OOPixMapAddPixMap(&_emissionPx, illuminationPx);
408 OOFreePixMap(&illuminationPx);
409 DUMP(_emissionPx, @"combined emission and illumination map");
410 }
411 else if (haveIllumination)
412 {
413 // No explicit emission map -> modulated illumination map is our only emission map.
414 _emissionPx = illuminationPx;
415 haveEmission = YES;
416 illuminationPx.pixels = NULL;
417 }
418 haveIllumination = NO; // Either way, illumination is now baked into emission.
419 }
420
421 (void)haveEmission;
422 (void)haveIllumination;
423
424 // Done: emissionPx now contains combined emission map.
427 {
433
434 _emissionPx.pixels = NULL; // So it won't be freed by -dealloc.
435 }
436 if (_data == NULL)
437 {
438 OOLogERR(@"texture.combinedEmissionMap.error", @"Unknown error loading %@", self);
439 }
440}
#define DUMP(pm, label)
static void ScaleToMatch(OOPixMap *pmA, OOPixMap *pmB)
#define OOLogERR(class, format,...)
Definition OOLogging.h:112
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)
const OOPixMap kOONullPixMap
Definition OOPixMap.m:31
OOINLINE BOOL OOIsNullPixMap(OOPixMap pixMap)
Definition OOPixMap.h:60
BOOL OOIsValidPixMap(OOPixMap pixMap)
Definition OOPixMap.m:42
BOOL OOPixMapFormatHasAlpha(OOPixMapFormat format) PURE_FUNC
Definition OOPixMap.m:232
OOPixMap OODuplicatePixMap(OOPixMap srcPixMap, size_t desiredSize)
Definition OOPixMap.m:95
OOINLINE void OOCompactPixMap(OOPixMap *ioPixMap)
Definition OOPixMap.h:103
OOTextureDataFormat _format
OOPixMapDimension height
Definition OOPixMap.h:50
size_t rowBytes
Definition OOPixMap.h:52
void * pixels
Definition OOPixMap.h:49
OOPixMapDimension width
Definition OOPixMap.h:50
OOPixMapFormat format
Definition OOPixMap.h:51

◆ lodBias

- (GLfloat) lodBias
implementation

Reimplemented from OOTextureGenerator.

Definition at line 463 of file OOCombinedEmissionMapGenerator.m.

326{
327 return _lodBias;
328}

◆ textureOptions

- (uint32_t) textureOptions
implementation

Reimplemented from OOTextureGenerator.

Definition at line 463 of file OOCombinedEmissionMapGenerator.m.

314{
315 return _textureOptions;
316}

Member Data Documentation

◆ _anisotropy

- (GLfloat) _anisotropy
private

Definition at line 55 of file OOCombinedEmissionMapGenerator.h.

◆ _cacheKey

- (NSString*) _cacheKey
private

Definition at line 41 of file OOCombinedEmissionMapGenerator.h.

◆ _diffuseDesc

- (NSString*) _diffuseDesc
private

Definition at line 61 of file OOCombinedEmissionMapGenerator.h.

◆ _diffuseMap

- (OOTexture*) _diffuseMap
private

Definition at line 45 of file OOCombinedEmissionMapGenerator.h.

◆ _diffusePx

- (OOPixMap) _diffusePx
private

Definition at line 48 of file OOCombinedEmissionMapGenerator.h.

◆ _emissionColor

- (OOColor*) _emissionColor
private

Definition at line 50 of file OOCombinedEmissionMapGenerator.h.

◆ _emissionDesc

- (NSString*) _emissionDesc
private

Definition at line 59 of file OOCombinedEmissionMapGenerator.h.

◆ _emissionPx

- (OOPixMap) _emissionPx
private

Definition at line 47 of file OOCombinedEmissionMapGenerator.h.

◆ _emissionSpec

- (NSDictionary*) _emissionSpec
private

Definition at line 43 of file OOCombinedEmissionMapGenerator.h.

◆ _illuminationColor

- (OOColor*) _illuminationColor
private

Definition at line 51 of file OOCombinedEmissionMapGenerator.h.

◆ _illuminationDesc

- (NSString*) _illuminationDesc
private

Definition at line 60 of file OOCombinedEmissionMapGenerator.h.

◆ _illuminationPx

- (OOPixMap) _illuminationPx
private

Definition at line 49 of file OOCombinedEmissionMapGenerator.h.

◆ _illuminationSpec

- (NSDictionary*) _illuminationSpec
private

Definition at line 44 of file OOCombinedEmissionMapGenerator.h.

◆ _isCombinedMap

- (BOOL) _isCombinedMap
private

Definition at line 52 of file OOCombinedEmissionMapGenerator.h.

◆ _lodBias

- (GLfloat) _lodBias
private

Definition at line 56 of file OOCombinedEmissionMapGenerator.h.

◆ _textureOptions

- (uint32_t) _textureOptions
private

Definition at line 54 of file OOCombinedEmissionMapGenerator.h.


The documentation for this class was generated from the following files: