Line data Source code
1 0 : /* 2 : 3 : OOSingleTextureMaterial.h 4 : 5 : 6 : Copyright (C) 2007-2013 Jens Ayton 7 : 8 : Permission is hereby granted, free of charge, to any person obtaining a copy 9 : of this software and associated documentation files (the "Software"), to deal 10 : in the Software without restriction, including without limitation the rights 11 : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 : copies of the Software, and to permit persons to whom the Software is 13 : furnished to do so, subject to the following conditions: 14 : 15 : The above copyright notice and this permission notice shall be included in all 16 : copies or substantial portions of the Software. 17 : 18 : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 : IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 : FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 : AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 : LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 : OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 : SOFTWARE. 25 : 26 : */ 27 : 28 : #import "OOSingleTextureMaterial.h" 29 : #import "OOTexture.h" 30 : #import "OOCollectionExtractors.h" 31 : #import "OOFunctionAttributes.h" 32 : 33 : 34 : @implementation OOSingleTextureMaterial 35 : 36 : - (id)initWithName:(NSString *)name configuration:(NSDictionary *)configuration 37 : { 38 : id texSpec = nil; 39 : 40 : if (configuration != nil) 41 : { 42 : texSpec = [configuration oo_textureSpecifierForKey:@"diffuse_map" defaultName:name]; 43 : } 44 : else 45 : { 46 : texSpec = name; 47 : } 48 : 49 : return [self initWithName:name 50 : texture:[OOTexture textureWithConfiguration:texSpec] 51 : configuration:configuration]; 52 : } 53 : 54 : 55 : - (id) initWithName:(NSString *)name texture:(OOTexture *)texture configuration:(NSDictionary *)configuration 56 : { 57 : if (name != nil && texture != nil) 58 : { 59 : self = [super initWithName:name configuration:configuration]; 60 : if (self != nil) 61 : { 62 : _texture = [texture retain]; 63 : } 64 : } 65 : else 66 : { 67 : DESTROY(self); 68 : } 69 : 70 : 71 : return self; 72 : } 73 : 74 : 75 0 : - (void)dealloc 76 : { 77 : [self willDealloc]; 78 : [_texture release]; 79 : 80 : [super dealloc]; 81 : } 82 : 83 : 84 0 : - (NSString *) descriptionComponents 85 : { 86 : return [_texture description]; 87 : } 88 : 89 : 90 0 : - (BOOL)doApply 91 : { 92 : if (EXPECT_NOT(![super doApply])) return NO; 93 : 94 : [_texture apply]; 95 : return YES; 96 : } 97 : 98 : 99 0 : - (void)unapplyWithNext:(OOMaterial *)next 100 : { 101 : if (![next isKindOfClass:[OOSingleTextureMaterial class]]) [OOTexture applyNone]; 102 : [super unapplyWithNext:next]; 103 : } 104 : 105 : 106 0 : - (void)ensureFinishedLoading 107 : { 108 : [_texture ensureFinishedLoading]; 109 : } 110 : 111 : 112 0 : - (BOOL) isFinishedLoading 113 : { 114 : return [_texture isFinishedLoading]; 115 : } 116 : 117 : 118 0 : - (BOOL) wantsNormalsAsTextureCoordinates 119 : { 120 : return [_texture isCubeMap]; 121 : } 122 : 123 : 124 : #ifndef NDEBUG 125 0 : - (NSSet *) allTextures 126 : { 127 : return [NSSet setWithObject:_texture]; 128 : } 129 : #endif 130 : 131 : @end