Skip to content

Commit b96c38c

Browse files
committed
Remember texture size so we don't have to load the image again
1 parent c2db926 commit b96c38c

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

Source/Ejecta/EJCanvas/EJTexture.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
BOOL drawFlippedY;
1111
BOOL isCompressed;
1212
BOOL lazyLoaded;
13+
BOOL dimensionsKnown;
1314
short width, height;
1415
NSString *fullPath;
1516
EJTextureStorage *textureStorage;

Source/Ejecta/EJCanvas/EJTexture.m

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ - (id)initWithWidth:(int)widthp height:(int)heightp format:(GLenum)formatp {
158158

159159
width = widthp;
160160
height = heightp;
161+
dimensionsKnown = true;
161162
[self createWithPixels:NULL format:formatp];
162163
}
163164
return self;
@@ -171,6 +172,7 @@ - (id)initWithWidth:(int)widthp height:(int)heightp pixels:(NSData *)pixels {
171172

172173
width = widthp;
173174
height = heightp;
175+
dimensionsKnown = true;
174176
[self createWithPixels:pixels format:GL_RGBA];
175177
}
176178
return self;
@@ -278,16 +280,25 @@ - (BOOL)isDynamic {
278280
}
279281

280282
- (short)width {
283+
if( dimensionsKnown ) {
284+
return width;
285+
}
281286
EJ_ENSURE_LAZY_LOADED_STORAGE();
282287
return width;
283288
}
284289

285290
- (short)height {
291+
if( dimensionsKnown ) {
292+
return height;
293+
}
286294
EJ_ENSURE_LAZY_LOADED_STORAGE();
287295
return height;
288296
}
289297

290298
- (float)contentScale {
299+
if( dimensionsKnown ) {
300+
return contentScale;
301+
}
291302
EJ_ENSURE_LAZY_LOADED_STORAGE();
292303
return contentScale;
293304
}
@@ -323,6 +334,7 @@ - (void)createWithTexture:(EJTexture *)other {
323334
height = other->height;
324335
isCompressed = other->isCompressed;
325336
lazyLoaded = other->lazyLoaded;
337+
dimensionsKnown = other->dimensionsKnown;
326338

327339
textureStorage = [other->textureStorage retain];
328340
}
@@ -511,6 +523,7 @@ - (NSMutableData *)loadPixelsFromPath:(NSString *)path {
511523
PVRTextureHeader *header = (PVRTextureHeader *)pixels.bytes;
512524
width = header->width;
513525
height = header->height;
526+
dimensionsKnown = true;
514527
isCompressed = true;
515528
}
516529

@@ -535,6 +548,7 @@ - (NSMutableData *)loadPixelsFromUIImage:(UIImage *)image {
535548

536549
width = CGImageGetWidth(cgImage);
537550
height = CGImageGetHeight(cgImage);
551+
dimensionsKnown = true;
538552

539553
NSMutableData *pixels = [NSMutableData dataWithLength:width*height*4];
540554
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

0 commit comments

Comments
 (0)