GLKit 框架的設計⽬標是爲了簡化基於OpenGL / OpenGL ES 的應⽤開發. 它的出現 加快OpenGL ES或OpenGL應用程序開發。 使⽤數學庫,背景紋理加載,預先建立的着 色器效果,以及標準視圖和視圖控制器來實現渲染循環。 GLKit框架提供了功能和類,能夠減小建立新的基於着⾊器的應用程序所需的⼯做量,或者支持依賴早期版本的OpenGL ES或OpenGL提供的固定函數頂點或片斷處理的現有應用程序。緩存
GLKTextuerLoader
提供相關API加載紋理數據。GLKView
和 GLKViewController
GLKView繼承自UIViewbash
- (instancetype)initWithFrame:(CGRect)frame context:(EAGLContext *)context;
複製代碼
@property (nullable, nonatomic, assign) IBOutlet id <GLKViewDelegate> delegate;
複製代碼
@property (nonatomic, retain) EAGLContext *context;
複製代碼
drawableColorFormat 顏⾊渲染緩存區格式:
GLKViewDrawableColorFormatRGBA8888 = 0,
GLKViewDrawableColorFormatRGB565,
GLKViewDrawableColorFormatSRGBA8888,
drawableDepthFormat 深度渲染緩存區格式:
GLKViewDrawableDepthFormatNone = 0,
GLKViewDrawableDepthFormat16,
GLKViewDrawableDepthFormat24,
drawableStencilFormat 模板渲染緩存區的格式:
GLKViewDrawableStencilFormatNone = 0,
GLKViewDrawableStencilFormat8,
drawableMultisample 多重採樣緩存區的格式:
GLKViewDrawableMultisampleNone = 0,
GLKViewDrawableMultisample4X,
複製代碼
drawableHeight 底層緩存區對象的⾼度(以像素爲單位)
drawableWidth 底層緩存區對象的寬度(以像素爲單位)
複製代碼
- (void)bindDrawable;
複製代碼
- (void)deleteDrawable;
複製代碼
@property (readonly, strong) UIImage *snapshot;
複製代碼
@property (nonatomic) BOOL enableSetNeedsDisplay;
複製代碼
- (void)display;
複製代碼
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect;
複製代碼
@property (nullable, nonatomic, assign) IBOutlet id <GLKViewControllerDelegate> delegate;
複製代碼
//視圖控制器調用視圖以及更新視圖內容的速率
@property (nonatomic) NSInteger preferredFramesPerSecond;
//視圖控制器調用視圖以及更新其內容的實際速率
@property (nonatomic, readonly) NSInteger framesPerSecond;
複製代碼
//Bool值,渲染循環是否已暫停
@property (nonatomic, getter=isPaused) BOOL paused;
//Bool值,當前程序從新激活活動狀態時視圖控制器是否自動暫停循環渲染
@property (nonatomic) BOOL pauseOnWillResignActive;
//Bool值,當前程序變爲活動狀態時視圖控制器是否自動恢復呈現渲染
@property (nonatomic) BOOL resumeOnDidBecomeActive;
複製代碼
//視圖控制器自建立以來發送的幀更新數
@property (nonatomic, readonly) NSInteger framesDisplayed;
//⾃視圖控制器第⼀次恢復發送更新事件以來通過的時間量
@property (nonatomic, readonly) NSTimeInterval timeSinceFirstResume;
//自上次視圖控制器恢復發送更新事件以來更新的時間量
@property (nonatomic, readonly) NSTimeInterval timeSinceLastResume;
//⾃上次視圖控制器調用委託⽅法以及通過的時間量
@property (nonatomic, readonly) NSTimeInterval timeSinceLastUpdate;
//⾃上次視圖控制器調用視圖display 方法以來通過的時間量
@property (nonatomic, readonly) NSTimeInterval timeSinceLastDraw;
複製代碼
//在顯示每一個幀以前調用
- (void)glkViewControllerUpdate:(GLKViewController *)controller;
複製代碼
//在渲染循環暫停或者恢復以前調用
- (void)glkViewController:(GLKViewController *)controller willPause:(BOOL)pause;
複製代碼
主要包含紋理的一下信息:框架
//初始化一個新的紋理加載到對象中
- (instancetype)initWithSharegroup:(EAGLSharegroup *)sharegroup;
//初始化一個新的紋理加載對象
- (instancetype)initWithShareContext:(NSOpenGLContext *)context;
複製代碼
//從文件加載2D紋理圖像並從數據中建立新的紋理
+ (nullable GLKTextureInfo *)textureWithContentsOfFile:(NSString *)path options:(nullable NSDictionary<NSString*, NSNumber*> *)options error:(NSError * __nullable * __nullable)outError;
//從文件中異步加載2D紋理圖像,並根據數據建立新紋理
- (void)textureWithContentsOfFile:(NSString *)path options:(nullable NSDictionary<NSString*, NSNumber*> *)options queue:(nullable dispatch_queue_t)queue completionHandler:(GLKTextureLoaderCallback)block;
複製代碼
//用URL加載2D紋理圖像並從數據中建立新的紋理
+ (nullable GLKTextureInfo *)textureWithContentsOfURL:(NSURL *)url options:(nullable NSDictionary<NSString*, NSNumber*> *)options error:(NSError * __nullable * __nullable)outError;
//用URL異步加載2D紋理圖像,並根據數據建立新紋理
- (void)textureWithContentsOfFile:(NSString *)path options:(nullable NSDictionary<NSString*, NSNumber*> *)options queue:(nullable dispatch_queue_t)queue completionHandler:(GLKTextureLoaderCallback)block;
複製代碼
//從內存空間加載2D紋理圖像並從數據中建立新的紋理
+ (nullable GLKTextureInfo *)textureWithContentsOfData:(NSData *)data options:(nullable NSDictionary<NSString*, NSNumber*> *)options error:(NSError * __nullable * __nullable)outError;
//從內存空間異步加載2D紋理圖像,並根據數據建立新紋理
- (void)textureWithContentsOfData:(NSData *)data options:(nullable NSDictionary<NSString*, NSNumber*> *)options queue:(nullable dispatch_queue_t)queue completionHandler:(GLKTextureLoaderCallback)block;
複製代碼
//從Quartz加載2D紋理圖像並從數據中建立新的紋理
+ (nullable GLKTextureInfo *)textureWithCGImage:(CGImageRef)cgImage options:(nullable NSDictionary<NSString*, NSNumber*> *)options error:(NSError * __nullable * __nullable)outError;
//從Quartz異步加載2D紋理圖像,並根據數據建立新紋理
- (void)textureWithCGImage:(CGImageRef)cgImage options:(nullable NSDictionary<NSString*, NSNumber*> *)options queue:(nullable dispatch_queue_t)queue completionHandler:(GLKTextureLoaderCallback)block;
複製代碼
//從單個URL加載⽴方體貼圖紋理圖像,並根據數據建立新紋理
+ (nullable GLKTextureInfo*)cubeMapWithContentsOfURL:(NSURL *)url options:(nullable NSDictionary<NSString*, NSNumber*> *)options error:(NSError * __nullable * __nullable)outError;
//從單個URL異步加載⽴方體貼圖紋理圖像,並根據數據建立新紋理
- (void)cubeMapWithContentsOfURL:(NSURL *)url options:(nullable NSDictionary<NSString*, NSNumber*> *)options queue:(nullable dispatch_queue_t)queue completionHandler:(GLKTextureLoaderCallback)block;
複製代碼
//從單個文件加載⽴方體貼圖紋理對象,並從數據中建立新紋理
+ (nullable GLKTextureInfo*)cubeMapWithContentsOfFile:(NSString *)path options:(nullable NSDictionary<NSString*, NSNumber*> *)options error:(NSError * __nullable * __nullable)outError;
//從單個文件異步立方體貼圖紋理圖像,並根據數據建立新紋理
- (void)cubeMapWithContentsOfFile:(NSString *)path options:(nullable NSDictionary<NSString*, NSNumber*> *)options queue:(nullable dispatch_queue_t)queue completionHandler:(GLKTextureLoaderCallback)block;
//從一系列文件加載立方體貼圖紋理圖像.並根據數據建立新的紋理
+ (nullable GLKTextureInfo*)cubeMapWithContentsOfFiles:(NSArray<id> *)paths options:(nullable NSDictionary<NSString*, NSNumber*> *)options error:(NSError * __nullable * __nullable)outError;
//從一系列文件異步立方體貼圖紋理圖像,並根據數據建立新紋理
- (void)cubeMapWithContentsOfFiles:(NSArray<id> *)paths options:(nullable NSDictionary<NSString*, NSNumber*> *)options queue:(nullable dispatch_queue_t)queue completionHandler:(GLKTextureLoaderCallback)block;
複製代碼
//用字符串給Effect(效果)命名
NSString *label;
複製代碼
//綁定效果時應用於頂點數據的模型視圖,投影和紋理變換
GLKEffectPropertyTransform *transform;
複製代碼
//⽤於計算每一個片斷的光照策略,
GLKLightingType lightingType;
//枚舉值
GLKLightingTypePerVertex :表示在三⻆形中每一個頂點執⾏光照計算,而後在三角形進行插值。
GLKLightingTypePerPixel :表示光照計算的輸⼊在三角形內插入,而且在每一個片斷執行光照計算。
複製代碼
//布爾值,表示爲基元的兩側計算光照
GLboolean lightModelTwoSided;
//計算渲染圖元光照使⽤用的材質屬性
GLKEffectPropertyMaterial *material;
//環境顏色,應⽤效果渲染的全部圖元
GLKVector4 lightModelAmbientColor;
//場景中第一個光照屬性,第二個光照屬性,第三個光照屬性
GLKEffectPropertyLight *light0, *light1, *light2;
複製代碼
//第⼀個紋理屬性,第二個紋理屬性
GLKEffectPropertyTexture *texture2d0, *texture2d1;
//紋理應⽤於渲染圖元的順序
NSArray<GLKEffectPropertyTexture*> *textureOrder;
複製代碼
//應用於場景的霧屬性
GLKEffectPropertyFog *fog;
複製代碼
//布爾值,表示計算光照與材質交互時是否使用顏色頂點屬性
GLboolean colorMaterialEnabled;
//布爾值,指示是否使用常量顏⾊
GLboolean useConstantColor;
//不提供每一個頂點顏色數據時使用常量顏⾊
GLKVector4 constantColor;
複製代碼
//準備渲染效果
- (void) prepareToDraw;
複製代碼