GLKit 􏰼􏰜常用API

2019-06-02  本文已影响0人  ChiLeung

前言

GLKit 是为了加速基于OpenGL或OpenGl ES应用开发而设计出来的,它简化了基于着色器的应用程序所需的工作量,提高了开发效率。

GLKit 框架

功能:

1.  加载纹理

2.  高性能的数学运算库。 

3.  提供常见的标准Shader特效。 

4. 提供视图以及视图控制器.

GLKit API

纹理加载

初始化

- (instancetype)initWithSharegroup:(EAGLSharegroup*)sharegroup; //初始化一个纹理加载到对象中

 - (instancetype)initWithShareContext:(NSOpenGLContext *)context; //初始化一个纹理加载对象

从文件中加载

+ (nullableGLKTextureInfo*)textureWithContentsOfFile:(NSString*)path  options:(nullableNSDictionary *)options error:(NSError*__nullable*__nullable)outError;  //从文件中加载纹理

- (void)textureWithContentsOfFile:(NSString*)path  options:(nullableNSDictionary *)options queue:(nullabledispatch_queue_t)queue completionHandler:(GLKTextureLoaderCallback)block;  //从文件中异步加载纹理

从URL加载纹理

+ (nullableGLKTextureInfo*)textureWithContentsOfURL:(NSURL*)url options:(nullableNSDictionary *)options error:(NSError*__nullable*__nullable)outError;  //从URL加载纹理

- (void)textureWithContentsOfURL:(NSURL*)url options:(nullableNSDictionary *)options queue:(nullabledispatch_queue_t)queue completionHandler:(GLKTextureLoaderCallback)block; //从URL异步加载纹理

从内存中表示创建纹理

+ (nullableGLKTextureInfo*)textureWithContentsOfData:(NSData*)data options:(nullableNSDictionary *)options error:(NSError*__nullable*__nullable)outError; //从内存数据加载纹理

- (void)textureWithContentsOfData:(NSData*)data options:(nullableNSDictionary *)options queue:(nullabledispatch_queue_t)queue completionHandler:(GLKTextureLoaderCallback)block; //从内存数据异步加载纹理

从CGImage加载纹理

+ (nullableGLKTextureInfo*)textureWithCGImage:(CGImageRef)cgImage  options:(nullableNSDictionary *)options error:(NSError*__nullable*__nullable)outError; //从CGImage加载纹理

- (void)textureWithCGImage:(CGImageRef)cgImage  options:(nullable NSDictionary<NSString*, NSNumber*> *)options queue:(nullabledispatch_queue_t)queue completionHandler:(GLKTextureLoaderCallback)block; //从CGImage异步加载纹理

从文件加载多维创建纹理

+ (nullableGLKTextureInfo*)cubeMapWithContentsOfFile:(NSString*)path  options:(nullableNSDictionary *)options error:(NSError*__nullable*__nullable)outError; //从单个文件加载立方体贴图纹理对象

- (void)cubeMapWithContentsOfFile:(NSString*)path options:(nullableNSDictionary *)options queue:(nullabledispatch_queue_t)queue completionHandler:(GLKTextureLoaderCallback)block; //从单个文件异步加载立方体贴图纹理对象

+ (nullableGLKTextureInfo*)cubeMapWithContentsOfFiles:(NSArray<id> *)paths options:(nullableNSDictionary *)options error:(NSError*__nullable*__nullable)outError;  //从多个文件加载立方体贴图纹理对象

- (void)cubeMapWithContentsOfFiles:(NSArray<id> *)paths options:(nullableNSDictionary *)options queue:(nullabledispatch_queue_t)queue completionHandler:(GLKTextureLoaderCallback)block; //从多个文件异步加载立方体贴图纹理对象

从URL加载多维创建纹理

+ (nullableGLKTextureInfo*)cubeMapWithContentsOfURL:(NSURL*)url options:(nullableNSDictionary *)options error:(NSError*__nullable*__nullable)outError; //从URL加载立方体贴图纹理对象

- (void)cubeMapWithContentsOfURL:(NSURL*)url  options:(nullableNSDictionary *)options queue:(nullabledispatch_queue_t)queue completionHandler:(GLKTextureLoaderCallback)block; //从URL异步加载立方体贴图纹理对象


GLKView

初始化视图

- (instancetype)initWithFrame:(CGRect)frame context:(EAGLContext*)context; //初始化一个新的视图

帧缓存区对象

@property (nonatomic) GLKViewDrawableColorFormat drawableColorFormat; //颜色缓冲区格式

@property (nonatomic) GLKViewDrawableDepthFormat drawableDepthFormat; //深度缓冲区格式

@property (nonatomic) GLKViewDrawableStencilFormat drawableStencilFormat; //模板缓冲区格式

@property (nonatomic) GLKViewDrawableMultisample drawableMultisample; //多从采样缓冲区格式

帧缓存区属性

@property (nonatomic, readonly) NSInteger drawableWidth; //底层缓存区对象的⾼度(以像素为单位)

@property (nonatomic, readonly) NSInteger drawableHeight; //底层缓存区对象的宽度(以像素为单位)

绘制视图的内容

@property (nonatomic, retain) EAGLContext *context; //绘制使用的OpenGL ES上下文

@property(nonatomic)BOOL enableSetNeedsDisplay; //指定视图是否响应使得视图内容无效的消息

@property (readonly, strong) UIImage *snapshot; //绘制视图内容并将其作为新图像对象返回

- (void)display; //立刻重新绘制视图

- (void)bindDrawable; //将底层FrameBuffer对象绑定到OpenGL ES

- (void)deleteDrawable; //删除与视图关联的可绘制对象


GLKViewDelegate

- (void)glkView:(GLKView*)view drawInRect:(CGRect)rect; //绘制视图内容(必须实现)


GLKViewController

更新

- (void)glkViewControllerUpdate:(GLKViewController*)controller; 

配置帧速率

@property(nonatomic)NSIntegerpreferredFramesPerSecond; //视图控制器调用视图以及更新视图内容的速率

@property (nonatomic, readonly) NSInteger framesPerSecond; //视图控制器调⽤视图以及更新其内容的实际速率

控制帧更新

@property (nonatomic, getter=isPaused) BOOL paused; //渲染循环是否已暂停

@property(nonatomic)BOOL pauseOnWillResignActive; //当前程序重新激活动状态时视图控制器是否⾃动暂停渲染循环

@property(nonatomic)BOOL resumeOnDidBecomeActive; //当前程序变为活动状态时视图控制是否⾃动恢复呈现循环

获取有关View 更新信息

@property (nonatomic, readonly) NSInteger framesDisplayed; //视图控制器⾃创建以来发送的帧更新数

@property(nonatomic,readonly)NSTimeInterval timeSinceFirstResume; //自视图控制器第一次恢复发送更新事件以来经过的时间量

@property(nonatomic,readonly)NSTimeInterval timeSinceLastResume; //⾃上次视图控制器恢复发送更新事件以来更新的时间量

@property(nonatomic,readonly)NSTimeInterval timeSinceLastUpdate; //⾃上次视图控制器调⽤委托⽅法以及经过的时间量

@property (nonatomic, readonly) NSTimeInterval timeSinceLastDraw; //⾃上次视图控制器调用视图display方法以来经过的时间量


GLKViewControllerDelegate

处理更新事件

- (void)glkViewControllerUpdate:(GLKViewController*)controller; //在显示每个帧之前调⽤

暂停/恢复通知

- (void)glkViewController:(GLKViewController*)controller willPause:(BOOL)pause; //在渲染循环暂停或恢复之前调用


GLKBaseEffect

命名

@property(nullable,nonatomic,copy) NSString *label; 

配置模型视图转换

@property(nonatomic,readonly) GLKEffectPropertyTransform *transform; //绑定效果时应⽤于顶点数据的模型视图,投影和纹理变换

配置光照效果

@property(nonatomic,assign) GLKLightingType lightingType;  //⽤于计算每个片段的光照策略,取值为GLKLightingTypePerVertex,GLKLightingTypePerPixel

GLKLightingTypePerVertex //表示在三角形中每个顶点执行光照计算,然后在三角形进行插值

GLKLightingTypePerPixel //表示光照计算的输⼊在三角形内插入,并且在每个片段执行光照计算

配置光照

@property(nonatomic,assign) GLboolean lightModelTwoSided; //表示为基元的两侧计算光照

@property(nonatomic,readonly) GLKEffectPropertyMaterial *material; //计算渲染图元光照使用的材质属性

@property(nonatomic,assign) GLKVector4 lightModelAmbientColor; //环境颜⾊,应用效果渲染的所有图元

@property(nonatomic,readonly) GLKEffectPropertyLight *light0, *light1, *light2; //场景中第一、二、三个光照属性

配置纹理

@property(nonatomic,readonly) GLKEffectPropertyTexture *texture2d0, *texture2d1; //场景中第⼀、二个纹理理属性

@property (nullable, nonatomic, copy) NSArray<GLKEffectPropertyTexture*> *textureOrder; //纹理应用于渲染图元的顺序

配置雾化

@property(nonatomic,readonly) GLKEffectPropertyFog *fog; //应用于场景的雾属性

配置颜⾊信息

@property(nonatomic,assign) GLboolean colorMaterialEnabled; //表示计算光照与材质交互时是否使用颜色顶点属性

@property(nonatomic,assign) GLboolean useConstantColor; //指示是否使用常量颜色

@property(nonatomic,assign) GLKVector4 constantColor; //不提供每个顶点颜⾊数据时使⽤常量颜色

准备绘制效果

- (void) prepareToDraw; //准备渲染


上一篇下一篇

猜你喜欢

热点阅读