Oolite
Loading...
Searching...
No Matches
OOMaterial.m
Go to the documentation of this file.
1/*
2
3OOMaterial.m
4
5
6Copyright (C) 2007-2013 Jens Ayton and contributors
7
8Permission is hereby granted, free of charge, to any person obtaining a copy
9of this software and associated documentation files (the "Software"), to deal
10in the Software without restriction, including without limitation the rights
11to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12copies of the Software, and to permit persons to whom the Software is
13furnished to do so, subject to the following conditions:
14
15The above copyright notice and this permission notice shall be included in all
16copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24SOFTWARE.
25
26*/
27
28#import "OOMaterial.h"
30#import "OOLogging.h"
31
33
34@implementation OOMaterial
35
36+ (void)setUp
37{
38 // I thought we'd need this, but the stuff I needed it for turned out to be problematic. Maybe in future. -- Ahruman
39}
40
41- (void)dealloc
42{
43 // Ensure cleanup happens; doing it more than once is safe.
44 [self willDealloc];
45
46 [super dealloc];
47}
48
50{
51 return [NSString stringWithFormat:@"\"%@\"", [self name]];
52}
53
54- (NSString*)name
55{
57 return nil;
58}
59
60// Make this the current GL shader program.
61- (void)apply
62{
64 [sActiveMaterial release];
66
67 if ([self doApply]) {
68 sActiveMaterial = [self retain];
69 }
70}
71
72+ (void)applyNone
73{
75 [sActiveMaterial release];
77}
78
80{
81 return [[sActiveMaterial retain] autorelease];
82}
83
85{
86}
87
89{
90 return YES;
91}
92
93- (void)setBindingTarget:(id<OOWeakReferenceSupport>)target
94{
95}
96
98{
99 return NO;
100}
101
102#if OO_MULTITEXTURE
103- (NSUInteger)countOfTextureUnitsWithBaseCoordinates
104{
105 return 1;
106}
107#endif
108
109#ifdef OO_DEBUG_MONITOR_ENABLED
110- (NSSet*)allTextures
111{
112 return nil;
113}
114#endif
115
116@end
117
118@implementation OOMaterial (OOSubclassInterface)
119
120- (BOOL)doApply
121{
123 return NO;
124}
125
126- (void)unapplyWithNext:(OOMaterial*)next
127{
128 // Do nothing.
129}
130
132{
133 if (EXPECT_NOT(sActiveMaterial == self)) {
134 OOLog(@"shader.dealloc.imbalance", @"%@", @"***** Material deallocated while active, indicating a retain/release imbalance.");
135 [self unapplyWithNext:nil];
137 }
138}
139
140@end
#define EXPECT_NOT(x)
#define OOLogGenericParameterError()
Definition OOLogging.h:137
#define OOLogGenericSubclassResponsibility()
Definition OOLogging.h:141
#define OOLog(class, format,...)
Definition OOLogging.h:84
static OOMaterial * sActiveMaterial
Definition OOMaterial.m:32
return nil
void dealloc()
Definition OOMaterial.m:41
void apply()
Definition OOMaterial.m:61
void ensureFinishedLoading()
Definition OOMaterial.m:84
OOMaterial * current()
Definition OOMaterial.m:79
BOOL doApply()
Definition OOMaterial.m:120
BOOL isFinishedLoading()
Definition OOMaterial.m:88
void unapplyWithNext:(OOMaterial *next)
Definition OOMaterial.m:126
void setUp()
Definition OOMaterial.m:36
NSString * descriptionComponents()
Definition OOMaterial.m:49
void applyNone()
Definition OOMaterial.m:72
BOOL wantsNormalsAsTextureCoordinates()
Definition OOMaterial.m:97
NSString * name()
Definition OOMaterial.m:54
void willDealloc()
Definition OOMaterial.m:131