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

#include <OOMaterial.h>

+ Inheritance diagram for OOMaterial:
+ Collaboration diagram for OOMaterial:

Instance Methods

(NSString *) - name
 
(void) - apply
 
(void) - ensureFinishedLoading
 
(BOOL) - isFinishedLoading
 
(void) - setBindingTarget:
 
(BOOL) - wantsNormalsAsTextureCoordinates
 
(NSSet *) - allTextures
 
(void) - dealloc [implementation]
 
(NSString *) - descriptionComponents [implementation]
 
(BOOL) - doApply
 
(void) - unapplyWithNext:
 
(void) - willDealloc
 

Class Methods

(void) + setUp
 
(void) + applyNone
 
(OOMaterial *) + current
 
(OOMaterial *) + materialWithName:cacheKey:configuration:macros:bindingTarget:forSmoothedMesh:
 
(OOMaterial *) + materialWithName:cacheKey:materialDictionary:shadersDictionary:macros:bindingTarget:forSmoothedMesh:
 
(NSDictionary *) + synthesizeMaterialDictionaryWithName:configuration:macros: [implementation]
 
(OOMaterial *) + defaultShaderMaterialWithName:cacheKey:configuration:macros:bindingTarget: [implementation]
 

Detailed Description

Definition at line 42 of file OOMaterial.h.

Method Documentation

◆ allTextures

- (NSSet *) allTextures

Reimplemented in OOBasicMaterial, and OOSingleTextureMaterial.

Definition at line 33 of file OOMaterial.m.

128{
129 return nil;
130}
return nil

◆ apply

- (void) apply

Definition at line 33 of file OOMaterial.m.

68{
69 [sActiveMaterial unapplyWithNext:self];
70 [sActiveMaterial release];
72
73 if ([self doApply])
74 {
75 sActiveMaterial = [self retain];
76 }
77}
static OOMaterial * sActiveMaterial
Definition OOMaterial.m:33
BOOL doApply()
Definition OOMaterial.m:138

◆ applyNone

+ (void) applyNone

Definition at line 33 of file OOMaterial.m.

81{
82 [sActiveMaterial unapplyWithNext:nil];
83 [sActiveMaterial release];
85}

Referenced by OODebugBeginWireframe().

+ Here is the caller graph for this function:

◆ current

+ (OOMaterial *) current

Definition at line 33 of file OOMaterial.m.

89{
90 return [[sActiveMaterial retain] autorelease];
91}

Referenced by OODebugBeginWireframe().

+ Here is the caller graph for this function:

◆ dealloc

- (void) dealloc
implementation

Reimplemented in OOBasicMaterial, and OOSingleTextureMaterial.

Definition at line 33 of file OOMaterial.m.

45{
46 // Ensure cleanup happens; doing it more than once is safe.
47 [self willDealloc];
48
49 [super dealloc];
50}

◆ defaultShaderMaterialWithName:cacheKey:configuration:macros:bindingTarget:

+ (OOMaterial *) defaultShaderMaterialWithName: (NSString *) name
cacheKey: (NSString *) cacheKey
configuration: (NSDictionary *) configuration
macros: (NSDictionary *) macros
bindingTarget: (id<OOWeakReferenceSupport>) target 
implementation

Provided by category OOMaterial(OOConvenienceCreators).

Definition at line 62 of file OOMaterialConvenienceCreators.m.

146 :(NSString *)name
147 cacheKey:(NSString *)cacheKey
148 configuration:(NSDictionary *)configuration
149 macros:(NSDictionary *)macros
150 bindingTarget:(id<OOWeakReferenceSupport>)target
151{
152 OOCacheManager *cache = nil;
153 NSDictionary *synthesizedConfig = nil;
154 OOMaterial *result = nil;
155
156 // Avoid looping (can happen if shader fails to compile).
157 if ([configuration objectForKey:@"_oo_is_synthesized_config"] != nil)
158 {
159 OOLog(@"material.synthesize.loop", @"Synthesis loop for material %@.", name);
160 return nil;
161 }
162
163 if (cacheKey != nil)
164 {
165 cache = [OOCacheManager sharedCache];
166 // configuration must be in cache key, as otherwise changes in
167 // non-diffuse map can end up miscached
168 cacheKey = [NSString stringWithFormat:@"%@/%@/%@", cacheKey, name, configuration];
169 synthesizedConfig = [cache objectForKey:cacheKey inCache:@"synthesized shader materials"];
170 }
171
172 if (synthesizedConfig == nil)
173 {
174 synthesizedConfig = [self synthesizeMaterialDictionaryWithName:name
175 configuration:configuration
176 macros:macros];
177 if (synthesizedConfig != nil && cacheKey != nil)
178 {
179 [cache setObject:synthesizedConfig
180 forKey:cacheKey
181 inCache:@"synthesized shader materials"];
182 }
183 }
184
185 if (synthesizedConfig != nil)
186 {
187 result = [self materialWithName:name
188 cacheKey:cacheKey
189 configuration:synthesizedConfig
190 macros:[synthesizedConfig objectForKey:@"_oo_synthesized_material_macros"]
191 bindingTarget:target
192 forSmoothedMesh:YES];
193 }
194
195 return result;
196}
#define OOLog(class, format,...)
Definition OOLogging.h:88
void setObject:forKey:inCache:(id inElement,[forKey] NSString *inKey,[inCache] NSString *inCacheKey)
id objectForKey:inCache:(NSString *inKey,[inCache] NSString *inCacheKey)
OOCacheManager * sharedCache()

◆ descriptionComponents

- (NSString *) descriptionComponents
implementation

Reimplemented in OOSingleTextureMaterial.

Definition at line 33 of file OOMaterial.m.

54{
55 return [NSString stringWithFormat:@"\"%@\"", [self name]];
56}

◆ doApply

- (BOOL) doApply

Reimplemented in OOBasicMaterial, and OOSingleTextureMaterial.

Provided by category OOMaterial(OOSubclassInterface).

Definition at line 33 of file OOMaterial.m.

139{
141 return NO;
142}
#define OOLogGenericSubclassResponsibility()
Definition OOLogging.h:129

◆ ensureFinishedLoading

- (void) ensureFinishedLoading

Reimplemented in OOSingleTextureMaterial.

Definition at line 33 of file OOMaterial.m.

95{
96
97}

◆ isFinishedLoading

- (BOOL) isFinishedLoading

Reimplemented in OOSingleTextureMaterial.

Definition at line 33 of file OOMaterial.m.

101{
102 return YES;
103}

◆ materialWithName:cacheKey:configuration:macros:bindingTarget:forSmoothedMesh:

+ (OOMaterial *) materialWithName: (NSString *) name
cacheKey: (NSString *) cacheKey
configuration: (NSDictionary *) configuration
macros: (NSDictionary *) macros
bindingTarget: (id<OOWeakReferenceSupport>) object
forSmoothedMesh: (BOOL) smooth 

Provided by category OOMaterial(OOConvenienceCreators).

Definition at line 62 of file OOMaterialConvenienceCreators.m.

267 :(NSString *)name
268 cacheKey:(NSString *)cacheKey
269 configuration:(NSDictionary *)configuration
270 macros:(NSDictionary *)macros
271 bindingTarget:(id<OOWeakReferenceSupport>)object
272 forSmoothedMesh:(BOOL)smooth // Internally, this flg really means "force use of shaders".
273{
274 id result = nil;
275
276#if OO_SHADERS
277
278 if ([UNIVERSE useShaders])
279 {
280 if ([OOShaderMaterial configurationDictionarySpecifiesShaderMaterial:configuration])
281 {
282 result = [OOShaderMaterial shaderMaterialWithName:name
283 configuration:configuration
284 macros:macros
285 bindingTarget:object];
286 }
287
288 // Use default shader if smoothing is on, or shader detail is full, DEBUG_NO_SHADER_FALLBACK is set, or material uses an effect map.
289 if (result == nil &&
290 (smooth ||
292 [UNIVERSE detailLevel] >= DETAIL_LEVEL_SHADERS ||
293 [configuration oo_combinedSpecularMapSpecifier] != nil ||
294 [configuration oo_normalMapSpecifier] != nil ||
295 [configuration oo_parallaxMapSpecifier] != nil ||
296 [configuration oo_normalAndParallaxMapSpecifier] != nil ||
297 [configuration oo_emissionMapSpecifier] != nil ||
298 [configuration oo_illuminationMapSpecifier] != nil ||
299 [configuration oo_emissionAndIlluminationMapSpecifier] != nil
300 ))
301 {
302 result = [self defaultShaderMaterialWithName:name
303 cacheKey:cacheKey
304 configuration:configuration
305 macros:macros
306 bindingTarget:(id<OOWeakReferenceSupport>)object];
307 }
308 }
309#endif
310
311#if OO_MULTITEXTURE
312 if (result == nil /*&& ![UNIVERSE reducedDetail]*/)
313 {
314 if ([configuration oo_emissionMapSpecifier] != nil ||
315 [configuration oo_illuminationMapSpecifier] ||
316 [configuration oo_emissionAndIlluminationMapSpecifier] != nil)
317 {
318 result = [[OOMultiTextureMaterial alloc] initWithName:name configuration:configuration];
319 [result autorelease];
320 }
321 }
322#endif
323
324 if (result == nil)
325 {
326 if ([configuration oo_diffuseMapSpecifierWithDefaultName:name] == nil)
327 {
328 result = [[OOBasicMaterial alloc] initWithName:name configuration:configuration];
329 }
330 else
331 {
332 result = [[OOSingleTextureMaterial alloc] initWithName:name configuration:configuration];
333 }
334 if (result == nil)
335 {
336 result = [[OOBasicMaterial alloc] initWithName:name configuration:configuration];
337 }
338 [result autorelease];
339 }
340 return result;
341}
NSUInteger gDebugFlags
Definition main.m:7
@ DEBUG_NO_SHADER_FALLBACK
@ DETAIL_LEVEL_SHADERS
Definition OOTypes.h:246
#define UNIVERSE
Definition Universe.h:840

◆ materialWithName:cacheKey:materialDictionary:shadersDictionary:macros:bindingTarget:forSmoothedMesh:

+ (OOMaterial *) materialWithName: (NSString *) name
cacheKey: (NSString *) cacheKey
materialDictionary: (NSDictionary *) materialDict
shadersDictionary: (NSDictionary *) shadersDict
macros: (NSDictionary *) macros
bindingTarget: (id<OOWeakReferenceSupport>) object
forSmoothedMesh: (BOOL) smooth 

Provided by category OOMaterial(OOConvenienceCreators).

Definition at line 62 of file OOMaterialConvenienceCreators.m.

344 :(NSString *)name
345 cacheKey:(NSString *)cacheKey
346 materialDictionary:(NSDictionary *)materialDict
347 shadersDictionary:(NSDictionary *)shadersDict
348 macros:(NSDictionary *)macros
349 bindingTarget:(id<OOWeakReferenceSupport>)object
350 forSmoothedMesh:(BOOL)smooth
351{
352 NSDictionary *configuration = nil;
353
354#if OO_SHADERS
355
356 if ([UNIVERSE useShaders])
357 {
358 configuration = [shadersDict oo_dictionaryForKey:name];
359 }
360#endif
361
362 if (configuration == nil)
363 {
364 configuration = [materialDict oo_dictionaryForKey:name];
365 }
366
367 if (configuration == nil)
368 {
369 // Use fallback material for non-existent simple texture.
370 // Texture caching means this won't be wasted in the general case.
371 OOTexture *texture = [OOTexture textureWithName:name inFolder:@"Textures"];
372 if (texture == nil) return nil;
373
374 configuration = [NSDictionary dictionary];
375 }
376
377 return [self materialWithName:name
378 cacheKey:cacheKey
379 configuration:configuration
380 macros:macros
381 bindingTarget:object
382 forSmoothedMesh:smooth];
383}
id textureWithName:inFolder:(NSString *name,[inFolder] NSString *directory)
Definition OOTexture.m:181

◆ name

- (NSString *) name

Reimplemented in OOBasicMaterial.

Definition at line 33 of file OOMaterial.m.

60{
62 return nil;
63}
#define OOLogGenericParameterError()
Definition OOLogging.h:125

◆ setBindingTarget:

- (void) setBindingTarget: (id<OOWeakReferenceSupport>) target

Definition at line 33 of file OOMaterial.m.

106 :(id<OOWeakReferenceSupport>)target
107{
108
109}

◆ setUp

+ (void) setUp

Definition at line 33 of file OOMaterial.m.

39{
40 // I thought we'd need this, but the stuff I needed it for turned out to be problematic. Maybe in future. -- Ahruman
41}

◆ synthesizeMaterialDictionaryWithName:configuration:macros:

+ (NSDictionary *) synthesizeMaterialDictionaryWithName: (NSString *) name
configuration: (NSDictionary *) configuration
macros: (NSDictionary *) macros 
implementation

Provided by category OOMaterial(OOConvenienceCreators).

Definition at line 62 of file OOMaterialConvenienceCreators.m.

92 :(NSString *)name
93 configuration:(NSDictionary *)configuration
94 macros:(NSDictionary *)macros
95{
96 if (configuration == nil) configuration = [NSDictionary dictionary];
98 {
99 .inConfig = configuration,
100 .outConfig = [NSMutableDictionary dictionary],
102
103 .macros = [NSMutableDictionary dictionaryWithDictionary:macros],
104 .textures = [NSMutableArray array],
105 .uniforms = [NSMutableDictionary dictionary]
106 };
107
108 if ([UNIVERSE reducedDetail])
109 {
110 context.maxTextures = 3;
111 }
112
113 // Basic stuff.
114
115 /* Set up the various material attributes.
116 Order is significant here, because it determines the order in which
117 features will be dropped if we exceed the hardware's texture image
118 unit limit.
119 */
120 SynthDiffuse(&context, name);
122 SynthNormalMap(&context);
123 SynthSpecular(&context);
124
125 if ([UNIVERSE detailLevel] >= DETAIL_LEVEL_SHADERS)
126 {
127 // Add uniforms required for hull heat glow.
128 [context.uniforms setObject:@"hullHeatLevel" forKey:@"uHullHeatLevel"];
129 [context.uniforms setObject:@"timeElapsedSinceSpawn" forKey:@"uTime"];
130 [context.uniforms setObject:@"fogUniform" forKey:@"uFogColor"];
131 }
132
133 // Stuff in the general properties.
134 [context.outConfig setObject:@"true" forKey:@"_oo_is_synthesized_config"];
135 [context.outConfig setObject:@"oolite-tangent-space-vertex.vertex" forKey:@"vertex_shader"];
136 [context.outConfig setObject:@"oolite-default-shader.fragment" forKey:@"fragment_shader"];
137
138 if ([context.textures count] != 0) [context.outConfig setObject:context.textures forKey:@"textures"];
139 if ([context.uniforms count] != 0) [context.outConfig setObject:context.uniforms forKey:@"uniforms"];
140 if ([context.macros count] != 0) [context.outConfig setObject:context.macros forKey:@"_oo_synthesized_material_macros"];
141
142 return context.outConfig;
143}
static void SynthDiffuse(OOMaterialSynthContext *context, NSString *name)
static void SynthSpecular(OOMaterialSynthContext *context)
static void SynthNormalMap(OOMaterialSynthContext *context)
static void SynthEmissionAndIllumination(OOMaterialSynthContext *context)
unsigned count
OOOpenGLExtensionManager * sharedManager()

◆ unapplyWithNext:

- (void) unapplyWithNext: (OOMaterial *) next

Reimplemented in OOBasicMaterial, and OOSingleTextureMaterial.

Provided by category OOMaterial(OOSubclassInterface).

Definition at line 33 of file OOMaterial.m.

145 :(OOMaterial *)next
146{
147 // Do nothing.
148}

◆ wantsNormalsAsTextureCoordinates

- (BOOL) wantsNormalsAsTextureCoordinates

Reimplemented in OOSingleTextureMaterial.

Definition at line 33 of file OOMaterial.m.

113{
114 return NO;
115}

◆ willDealloc

- (void) willDealloc

Provided by category OOMaterial(OOSubclassInterface).

Definition at line 33 of file OOMaterial.m.

152{
153 if (EXPECT_NOT(sActiveMaterial == self))
154 {
155 OOLog(@"shader.dealloc.imbalance", @"%@", @"***** Material deallocated while active, indicating a retain/release imbalance.");
156 [self unapplyWithNext:nil];
158 }
159}
#define EXPECT_NOT(x)

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