Oolite 1.91.0.7645-241119-222d325
Loading...
Searching...
No Matches
OOCombinedEmissionMapGenerator(Private) Category Reference

Instance Methods

(id) - initWithEmissionMapSpec:emissionColor:diffuseMap:diffuseColor:illuminationMapSpec:illuminationColor:isCombinedMap:optionsSpecifier:
 
(NSString *) - constructCacheKey
 

Detailed Description

Definition at line 45 of file OOCombinedEmissionMapGenerator.m.

Method Documentation

◆ constructCacheKey

- (NSString *) constructCacheKey

Extends class OOCombinedEmissionMapGenerator.

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 {
215 emissionDesc = OOTextureCacheKeyForSpecifier(_emissionSpec);
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 {
228 illuminationDesc = OOTextureCacheKeyForSpecifier(_illuminationSpec);
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

◆ 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 

Extends class OOCombinedEmissionMapGenerator.

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;
152 _anisotropy = anisotropy;
153 _lodBias = lodBias;
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 {
165 _diffusePx = [diffuseMap copyPixMapRepresentation];
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

The documentation for this category was generated from the following file: