https://github.com/bestswifter/BSPanoramaView
OpenGL !
Usage
#import "BSPanoramaView.h"
- (void)viewDidLoad {
[super viewDidLoad];
BSPanoramaView *panoView = [[BSPanoramaView alloc] initWithFrame:self.view.bounds imageName:@"test"];
[self.view addSubview:panoView];
}
- (void)setImageWithName:(NSString *)imageName {
self.shouldUnload = NO;
/// 将图片转换成为纹理信息,由于OpenGL的默认坐标系设置在左下角, 而GLKit在左上角, 因此需要转换
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], GLKTextureLoaderOriginBottomLeft, nil];
UIImage *textureImage = [UIImage imageNamed:imageName];
GLKTextureLoader *loader = [[GLKTextureLoader alloc] initWithSharegroup:self.context.sharegroup];
[loader textureWithCGImage:textureImage.CGImage options:options queue:dispatch_get_main_queue() completionHandler:^(GLKTextureInfo * _Nullable textureInfo, NSError * _Nullable outError) {
if (self.shouldUnload) { // 因为是异步加载,所以需要考虑调用完 unloadImage 才加载成功的情况
[[PanoramaManager sharedInstance] unRegisterView:self];
GLuint name = textureInfo.name;
glDeleteTextures(1, &name);
glDrawElements(GL_TRIANGLES, self.numIndices, GL_UNSIGNED_SHORT, 0);
return ;
}
/// 设置着色器的纹理
self.effect = [[GLKBaseEffect alloc] init];
self.effect.texture2d0.enabled = GL_TRUE;
self.effect.texture2d0.name = textureInfo.name;
}];
}