A, GLKit Framework Overview
- GLKit framework designed to simplify the development of applications based on OpenGL / OpenGL ES's. It appears
to accelerate OpenGL ES or OpenGL development of the applications. Use math library, background texture loading, pre-created with
color filter effects, as well as the standard view and the view controller to achieve rendering loop. - GLKit framework provides functions and classes required can be reduced to create a new application based shader work,
or a fixed support existing vertex or fragment processing function dependent on an earlier version of the OpenGL ES or OpenGL provides
an application. - Draw spaces provided GLKView (View)
- GLKViewController (UIKit extensions to the standard design pattern for managing drawing view content and presentation)
- Apple abandoned OpenGL ES, but iOS developers can continue to use.
Second, the use GLKit view render OpenGL ES content
Third, the configuration view GLKit
- (void)viewDidLoad{
[super viewDidLoad];
//创建OpenGL ES上下文并将其分配给从故事板加载的视图
GLKView * view =(GLKView *)self.view;
view.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
//配置视图创建的渲染缓冲区
view.drawableColorFormat = GLKViewDrawableColorFormatRGBA8888;
view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
view.drawableStencilFormat = GLKViewDrawableStencilFormat8;
//启⽤多重采样
view.drawableMultisample = GLKViewDrawableMultisample4X;
}
-(void)drawRect:(CGRect)rect
{
//清除帧缓冲区
glClearColor(0.0f,0.0f,0.1f,1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//使用先前配置的纹理,着色器和顶点数组绘制
glBindTexture(GL_TEXTURE_2D,_planetTexture);
glUseProgram(_diffuseShading);
glUniformMatrix4fv(_uniformModelViewProjectionMatrix,1,0,_modelViewProjectionMatrix.m);
glBindVertexArrayOES(_planetMesh);
glDrawElements(GL_TRIANGLE_STRIP,256,GL_UNSIGNED_SHORT);
}
Four, GLKit function
- Load textures
- ADVANCED providing performance math
- It provides constant ⻅ shaders
- And a controller provides a view of view.
Five, GLKit texture load
1. GLKTextureInfo create OpenGL texture information
- name: OpenGL texture context name
- target: target texture bound
- height: loading textures and altitudes
- width: Width of the loaded textures
- textureOrigin: Load the texture of the origin position
- alphaState: loading state texture alpha component
- containsMipmaps: Boolean value that contains loads of texture mip map
2. GLTextureLoader simplified load textures from a variety of resource file
-
initialization
- initWithSharegroup: initialize a new texture loaded into an object
- initWithShareContext: Initialization causes a new texture loading objects
-
Load processing from a file
- +textureWithContentsOfFile:options:errer: 从文件加载2D纹理图像并从数据中创建新的纹理
- -textureWithContentsOfFile:options:queue:completionHandler: 从⽂件中异步加载2D纹理图像,并根据数据创建新纹理
-
从URL加载纹理
- -textureWithContentsOfURL:options:error: 从URL加载2D纹理图像并从数据创建新纹理
- -textureWithContentsOfURL:options:queue:completionHandler: 从URL异步加载2D纹理图像,并根据数据创建新纹理
-
从内存中表示创建纹理
- +textureWithContentsOfData:options:errer: 从内存空间加载2D纹理图像,并根据数据创建新纹理
- -textureWithContentsOfData:options:queue:completionHandler:从内存空间异步加载2D纹理图像,并从数据中创建新纹理
-
从CGImages创建纹理
- -textureWithCGImage:options:error: 从Quartz图像加载2D纹理图像并从数据创建新纹理
- -textureWithCGImage:options:queue:completionHandler: 从Quartz图像异步加载2D纹理图像,并根据数据创建新纹理
-
从URL加载多维创建纹理
- +cabeMapWithContentsOfURL:options:errer: 从单个URL加载立方体贴图纹理图像,并根据数据创建新纹理
- -cabeMapWithContentsOfURL:options:queue:completionHandler:从单个URL异步加载立方体贴图纹理图像,并根据数据创建新纹理
-
从文件加载多维数据创建纹理
- +cubeMapWithContentsOfFile:options:errer: 从单个⽂件加载立⽅体贴图纹理对象,并从数据中创建新纹理
- -cubeMapWithContentsOfFile:options:queue:completionHandler:从单个文件异步加载⽴方体贴图纹理对象,并从数据中创建新纹理
- +cubeMapWithContentsOfFiles:options:errer: 从⼀系列文件中加载立方体贴图纹理图像,并从数据总创建新纹理
- -cubeMapWithContentsOfFiles:options:options:queue:completionHandler:从一系列文件异步加载⽴方体贴图纹理图像,并从数据中创建新纹理
六、GLKit OpenGL ES 视图渲染
1. GLKView 使⽤OpenGL ES 绘制内容的视图默认实现
-
初始化视图
- -initWithFrame:context: 初始化新视图
-
代理
- delegate 视图的代理
-
配置帧缓存区对象
- drawableColorFormat 颜色渲染缓存区格式
- drawableDepthFormat 深度渲染缓存区格式
- drawableStencilFormat 模板渲染缓存区的格式
- drawableMultisample 多重采样缓存区的格式
-
帧缓存区属性
- drawableHeight 底层缓存区对象的高度(以像素为单位)
- drawableWidth 底层缓存区对象的宽度(以像素为单位)
-
绘制视图的内容
- context 绘制视图内容时使⽤的OpenGL ES 上下文
- -bindDrawable 将底层FrameBuffer 对象绑定到OpenGL ES
- enableSetNeedsDisplay 布尔值,指定视图是否响应使得视图内容无效的消息
- -display 立即重绘视图内容
- snapshot 绘制视图内容并将其作为新图像对象返回
-
删除视图FrameBuffer对象
- -deleteDrawable 删除与视图关联的可绘制对象
2. GLKViewDelegate ⽤于GLKView 对象回调方法
- 绘制视图的内容
- -glkView:drawInRect: 绘制视图内容 (必须实现代理)
3. GLKViewController 管理OpenGL ES 渲染循环的视图控制器
-
更新
- -(void)update 更新视图内容
- -(void)glkViewControllerUpdate:
-
配置帧速率
- preferredFramesPerSecond 视图控制器调用视图以及更新视图内容的速率
- framesPerSencond 视图控制器调用视图以及更新其内容的实际速率
-
配置GLKViewController 代理
- delegate 视图控制器的代理
-
控制帧更新
- paused 布尔值,渲染循环是否已暂停
- pausedOnWillResignActive 布尔值,当前程序重新激活活动状态时视图控制器是否⾃动暂停渲染循环
- resumeOnDidBecomeActive 布尔值,当前程序变为活动状态时视图控制是否自动恢复呈现循环
-
获取有关View 更新信息
- frameDisplayed 视图控制器⾃创建以来发送的帧更新数
- timeSinceFirstResume ⾃视图控制器第一次恢复发送更新事件以来经过的时间量
- timeSinceLastResume 自上次视图控制器恢复发送更新事件以来更新的时间量
- timeSinceLastUpdate ⾃上次视图控制器调用委托⽅法以及经过的时间量 glkViewControllerUpdate:
- timeSinceLastDraw ⾃上次视图控制器调用视图display 方法以来经过的时间量.
4. GLKViewControllerDelegate 渲染循环回调⽅法
-
处理更新事件
- -glkViewControllerUpdate: 在显示每个帧之前调⽤
-
暂停/恢复通知
- -glkViewController:willPause: 在渲染循环暂停或恢复之前调⽤
5. GLKBaseEffect ⼀ species simple light / coloring system, based on OpenGL rendering shader
-
Named Effect
- label to Effect (effect) named
-
Configuration model view conversion
- Applied to the vertex data when the binding effect model view transform, projection transform, and texture
-
Configuration lighting effects
- Use lightingType in each segment is calculated illumination strategy, GLKLightingType
- GLKLightingType
- Each vertex represents GLKLightingTypePerVertex perform lighting calculations in a three-shaped ⻆ then interpolated three-shaped ⻆
- GLKLightingTypePerPixel calculated input light represented in three ⻆ inserted shape, and each segment is calculated in the light YES
-
Configuration of light
- lightModelTwoSided Boolean value indicating the calculated illumination on both sides of the primitive
- material calculated material properties rendering the primitive using light
- lightModelAmbientColor ambient color, the effect of rendering the application of all elements.
- a first frame light0 scene illumination properties
- light1 second scene illumination properties
- light2 third scene illumination properties
-
Configuration texture
- texture2d0 first texture attributes
- texture2d1 second texture properties
- textureOrder textures to rendered primitive sequence
-
Configuration atomization
- fog fog properties to apply it to the scene
-
Of colors in the configuration information
- colorMaterialEnable Boolean value that indicates whether the color of light and calculating the vertex attributes material interaction
- useConstantColor Boolean value that indicates whether to use of colors in constant
- ConstantColor constant color when using each vertex color data is not available
-
Ready to draw results
- -prepareToDraw ready to render effects
Reproduced in: https: //www.jianshu.com/p/5364db740e40