starbugs / icedcoffee

A lightweight OpenGL user interface framework written in Objective-C

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Addition of loadTextureFromURL methods

opened this issue · comments

I have an embedded TouchDB datbase, this uses a custom URL protocol to access document attachments so I need to be able to load textures from a URL.

I have this working (only tested on iOS) by adding the following static method to the ICTextureLoader and wrapping with an instance method on ICTextureCache:

  • (ICTexture2D *)loadTextureFromURL:(NSURL *)url
    {
    ICTexture2D *texture = nil;

ifdef __IC_PLATFORM_MAC

NSData *data = [[NSData alloc] initWithContentsOfURL:url];
NSBitmapImageRep *image = [[NSBitmapImageRep alloc] initWithData:data];
texture = [[[ICTexture2D alloc] initWithCGImage:[image CGImage]] autorelease];

[data release];
[image release];

elif __IC_PLATFORM_IOS

// FIXME: need to determine resolution type
UIImage * image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:url]];
texture = [[[ICTexture2D alloc] initWithCGImage:image.CGImage resolutionType:ICResolutionTypeUnknown] autorelease];
[image release];

endif

return texture;

}

I will integrate this into the ICTextureLoader class and test it on the Mac.

A side note: we are currently thinking about rewriting ICTexture2D (it's a mess imported and adapted from cocos2d). Thus, ICTextureLoader will most likely be deprecated or redesigned at some point in the future.

I have created an IcedCoffee Google Group where we will announce important release notes in the future. Please join this group if you wish to be notified.

Tobias

I've integrated your code into ICTextureLoader, added and refactored certain methods in ICTextureCache. It's all committed to the development branch. If you like, please feel free to test these additions.