39@implementation OOMultiTextureMaterial
41- (id)initWithName:(NSString *)name configuration:(NSDictionary *)configuration
49 NSDictionary *diffuseSpec = [configuration oo_diffuseMapSpecifierWithDefaultName:name];
50 NSDictionary *emissionSpec = [configuration oo_emissionMapSpecifier];
51 NSDictionary *illuminationSpec = [configuration oo_illuminationMapSpecifier];
52 NSDictionary *emissionAndIlluminationSpec = [configuration oo_emissionAndIlluminationMapSpecifier];
53 OOColor *diffuseColor = [configuration oo_diffuseColor];
55 OOColor *illuminationColor = [configuration oo_illuminationModulateColor];
57 NSMutableDictionary *mutableConfiguration = [NSMutableDictionary dictionaryWithDictionary:configuration];
59 if (emissionSpec !=
nil || emissionAndIlluminationSpec !=
nil)
61 emissionColor = [configuration oo_emissionModulateColor];
66 [mutableConfiguration removeObjectForKey:kOOMaterialEmissionColorName];
67 [mutableConfiguration removeObjectForKey:kOOMaterialEmissionColorLegacyName];
70 if ((
self = [super initWithName:name configuration:mutableConfiguration]))
72 if (diffuseSpec !=
nil)
75 if (_diffuseMap !=
nil) _unitsUsed++;
79 if (emissionSpec !=
nil && illuminationSpec ==
nil && emissionAndIlluminationSpec ==
nil && emissionColor ==
nil)
82 if (_emissionMap !=
nil) _unitsUsed++;
88 if (emissionAndIlluminationSpec !=
nil)
91 diffuseMap:_diffuseMap
92 diffuseColor:diffuseColor
93 emissionColor:emissionColor
94 illuminationColor:illuminationColor
95 optionsSpecifier:emissionAndIlluminationSpec];
100 emissionColor:emissionColor
101 diffuseMap:_diffuseMap
102 diffuseColor:diffuseColor
103 illuminationMapSpec:illuminationSpec
104 illuminationColor:illuminationColor
105 optionsSpecifier:emissionSpec ?: illuminationSpec];
109 if (_emissionMap !=
nil) _unitsUsed++;
128- (NSString *) descriptionComponents
130 NSMutableArray *bits = [NSMutableArray array];
131 if (_diffuseMap) [bits addObject:[NSString stringWithFormat:@"diffuse map: %@", [_diffuseMap shortDescription]]];
132 if (_emissionMap) [bits addObject:[NSString stringWithFormat:@"emission map: %@", [_emissionMap shortDescription]]];
134 NSString *result = [
super descriptionComponents];
135 if ([bits
count] > 0) result = [result stringByAppendingFormat:@" - %@", [bits componentsJoinedByString:@","]];
140- (NSUInteger) textureUnitCount
146- (NSUInteger) countOfTextureUnitsWithBaseCoordinates
152- (void) ensureFinishedLoading
154 [_diffuseMap ensureFinishedLoading];
155 [_emissionMap ensureFinishedLoading];
165 GLenum textureUnit = GL_TEXTURE0_ARB;
167 if (_diffuseMap !=
nil)
169 OOGL(glActiveTextureARB(textureUnit++));
170 OOGL(glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB));
171 OOGL(glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE));
175 if (_emissionMap !=
nil)
177 OOGL(glActiveTextureARB(textureUnit++));
178 OOGL(glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB));
179 OOGL(glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_ADD));
180 [_emissionMap apply];
183 NSAssert2(textureUnit - GL_TEXTURE0_ARB == _unitsUsed,
@"OOMultiTextureMaterial texture unit count invalid (expected %lu, actually using %u)", _unitsUsed, textureUnit - GL_TEXTURE0_ARB);
185 if (textureUnit > GL_TEXTURE1_ARB)
187 OOGL(glActiveTextureARB(GL_TEXTURE0_ARB));
196 [
super unapplyWithNext:next];
199 i = [next isKindOfClass:[OOMultiTextureMaterial class]] ? [(OOMultiTextureMaterial *)next textureUnitCount] : 0;
200 for (; i != _unitsUsed; ++i)
202 OOGL(glActiveTextureARB(GL_TEXTURE0_ARB + i));
204 OOGL(glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE));
206 OOGL(glActiveTextureARB(GL_TEXTURE0_ARB));
211- (NSSet *) allTextures
213 if (_diffuseMap ==
nil)
return [NSSet setWithObject:_emissionMap];
214 return [NSSet setWithObjects:_diffuseMap, _emissionMap, nil];
#define OO_ENTER_OPENGL()
id textureWithGenerator:(OOTextureGenerator *generator)
id textureWithConfiguration:extraOptions:(id configuration,[extraOptions] OOTextureFlags extraOptions)
id textureWithConfiguration:(id configuration)