Appears GLKit framework
GLKit destination time frame is designed to simplify application development scale based on the OpenGL / OpenGL ES's. It appears to accelerate OpenGL ES or OpenGL development of the applications. Using the math library, background texture loading, pre-created shader effects, as well as the standard view and the view controller to achieve rendering loop.
GLKit framework provides functions and classes, can be reduced to create a new work based on the desired application amount ⼯ shader's or earlier versions dependent ⽀ support OpenGL ES or OpenGL provides fixed function vertex or fragment thereof should be treated prior Using the procedure.
Draw spaces provided GLKView (View)
GLKViewController (extension to the standard UIKit design patterns. Use to view the contents of the drawing management and presentation)
The main function GLKit
GLKit main functions are as follows:
-
Texture load
(Texture loading)
:GLKTextuerLoader Class
.- Texture load allows your application to easily load textures from a variety of sources. You can even use a few lines of code to be loaded asynchronously in the background texture.
-
High performance scientific computing library that supports vector, quaternion, matrix operations and so on.
- Math library provides common vector and matrix operations quaternion. These implementations are optimized to deliver outstanding performance.
-
Implement common standards
Shader
effects.GLKit
Allows you to configure the special effects you need, it will automatically create and load the corresponding Shader.GLKBaseEffect, GLKReflectionMapEffect, GLKSkyboxEffect Class
.- Effect provides a standard ordinary coloring effect achieved. You configure effect and related vertex data, the effect is to create and load the appropriate shader. GLKit comprising three effects:
GLKBaseEffect
class implements a subset of OpenGL ES 1.1 Key shading and lighting model;GLKReflectionMapEffect
substantially expanded to include the effect of the reflection type support mapping;GLKSkyboxEffect
class provides an implementationskybox
effect.
- Effect provides a standard ordinary coloring effect achieved. You configure effect and related vertex data, the effect is to create and load the appropriate shader. GLKit comprising three effects:
-
View of the GLKit and corresponding ViewController.
GLKView Class
AndGLKViewController Class
.- ES-view and the controller provides the respective standard views and view controller OpenGL implementation. This reduces the amount of code required to create iOS applications using the OpenGL ES program.
GLKit resolve common API
1. GLKTextureInfo
Create a OpenGL texture information
name: OpenGL texture vertical File Name
target: Texture bound destination time standard
height: the height of the texture loaded
width: the width of the load textures
textureOrigin: loading the origin position in the texture
alphaState: loading a texture alpha components of the state
containsMipmaps: Boolean, loading texture mapping is included mip
2. GLTextureLoader
simplified texture to be loaded from a variety of resource files.
Initialization
- initWithSharegroup:
Initialization causes a new texture loaded into an object- initWithShareContext:
to initialize a new texture loading objectsLoad process from a file
+ textureWithContentsOfFile:options:errer:
is loaded from the file 2D texture image and create a new texture data from the- textureWithContentsOfFile:options:queue:completionHandler:
load from the 2D texture image files asynchronously, based on the data and creates a new textureLoad texture from a URL
- textureWithContentsOfURL:options:error:
to load image from URL and 2D texture create a new texture from data- textureWithContentsOfURL:options:queue:completionHandler:
from a URL asynchronously
loaded 2D texture image and create a new texture based on the dataRepresentation from memory to create a texture
+ textureWithContentsOfData:options:errer:
load an image from a 2D texture memory space, and create a new texture data based on- textureWithContentsOfData:options:queue:completionHandler:
loading an image from a 2D texture asynchronous memory space, and create a new texture from dataCreate a texture from CGImages reason
- textureWithCGImage:options:error:
to load images from the Quartz 2D texture image and create a new texture from the data- textureWithCGImage:options:queue:completionHandler:
loaded from Quartz 2D texture image image asynchronously, based on the data and create a new textureCreate a multi-dimensional texture loaded from a URL
+ cabeMapWithContentsOfURL:options:errer:
to load textures attention immediately ⽅ body image from a single URL, and create a new texture based on data- cabeMapWithContentsOfURL:options:queue:completionHandler:
from a single
load attention immediately cube map texture image asynchronous URL, and create a new texture based on the dataFile load cube textures created from
+ cubeMapWithContentsOfFile:options:errer:
loading textures attention immediately ⽅ body object from a single file, and create a new texture from data- cubeMapWithContentsOfFile:options:queue:completionHandler:
loading attention immediately cube map texture object from a single file asynchronously, and create a new texture from data+ cubeMapWithContentsOfFiles:options:errer:
from a set of files load attention immediately cube map texture images and data from the total to create a new texture- cubeMapWithContentsOfFiles:options:options:queue:completionHandler:
loading attention immediately cube map texture image from a series of asynchronous file, and create a new texture from data
3. GLKView
Use OpenGL ES rendering view the contents of the default implementation
Initialization view
- initWithFrame:context:
initialize a new viewAgent
delegate
for an agent viewConfiguration frame buffer objects
drawableColorFormat
color rendering format bufferdrawableDepthFormat
depth buffer rendering formatdrawableStencilFormat
template rendering format buffer ofdrawableMultisample
multi-sampling buffer formatAttributes frame buffer
drawableHeight
and altitudes (in pixels) of the underlying cache objectdrawableWidth
underlying cache object width (in pixels)SUMMARY pictorial view of
context
OpenGL ES rendering vertical view the file content used when- bindDrawable
the object is bound to the underlying FrameBuffer OpenGL ESenableSetNeedsDisplay
Boolean value that specifies whether the view the content view response message be ineffective- display
attention immediately redraw view contentsnapshot
rendering and content view as The new image object returnDelete view FrameBuffer objects
- deleteDrawable
to delete the view associated drawable
4 GLKViewDelegate
for GLKView
subject correction Remedies
- glkView:drawInRect:
Drawing view contents (must implement agency management)
The GLKViewController
management cycle OpenGL ES rendering view controller
Update
- (void) update
update view content- (void) glkViewControllerUpdate:
agency put FranceConfiguring the frame rate
preferredFramesPerSecond
view and update the view controller Use tone-view content rateframesPerSencond
view and the controller calls the view's update its contents the actual rateConfiguration
GLKViewController
Agent
//处理更新事件
//在现实每个帧之前调用
- (void)glkViewControllerUpdate:(GLKViewController *)controller;
//暂停/恢复通知
//在渲染循环暂停或回复之前调用
- (void)glkViewController:(GLKViewController *)controller willPause:(BOOL)pause;
Control frame update
paused
Boolean value, whether the cycle is paused renderingpausedOnWillResignActive
a Boolean value, the current program to reactivate the active view controller automatically stops if the rendering loopresumeOnDidBecomeActive
view control when a Boolean value, the current program becomes active if automatic recovery render loopView information about obtaining updated
frameDisplayed
since the view controller created automatically update the number of frames senttimeSinceFirstResume
the amount of time that has elapsed since the first view controller automatically sends updates to restore the eventtimeSinceLastResume
the amount of time since the last update to restore view controller sends an update eventtimeSinceLastUpdate
automatically last view controller calls the delegate Remedies and the amount of time that has elapsedtimeSinceLastDraw
automatically calls the last view controller viewdisplay
the amount of time elapsed since the method
6. GLKBaseEffect
A simple light / coloring system, based on the discolored Use OpenGL rendering device
@interface GLKBaseEffect : NSObject <GLKNamedEffect>
{
@protected
// Switches to turn effect features on and off
GLboolean _colorMaterialEnabled;
GLboolean _fogEnabled;
// Modelview, projection, texture and derived matrices for transformation
GLKEffectPropertyTransform *_transform;
// Lights
GLKLightingType _lightingType;
GLKEffectPropertyLight *_light0, *_light1, *_light2;
// Material for lighting
GLKEffectPropertyMaterial *_material;
// GL Texture Names
GLKEffectPropertyTexture *_texture2d0, *_texture2d1;
// Texture ordering array
NSArray *_textureOrder;
// Constant color (fixed color value to supplant the use of the "color" named vertex attrib array)
GLKVector4 _constantColor;
// Fog
GLKEffectPropertyFog *_fog;
// Label for effect
NSString *_label;
}
Named Effect
label
to Effect (effect) namedConfiguration model view transformation
transform
is applied to the vertex data model view when binding effect, projection and texture transform-
Configuration lighting effects
lightingType
Use strategy for each still picture to calculate lighting segment-
GLKLightingType
-
GLKLightingTypePerVertex
Denotes each vertex lighting calculations performed in the triangle, then three interpolated shaped ⻆ -
GLKLightingTypePerPixel
It represents a calculated input light in three ⻆ inserted shape, and calculates the lighting on each execution release segment
-
-
Illumination configuration
lightModelTwoSided
Boolean value that indicates lighting calculations on both sides of the primitivematerial
computing rendering the primitive that the light material properties Using thelightModelAmbientColor
ambient color, all application effect rendered membered FIG.light0
Scenario first light propertylight1
scene illumination properties th second shotlight2
scenes the third light propertiesTexture arranged
texture2d0
first texture attributetexture2d1
second shot texture attributestextureOrder
textures to rendered primitive sequenceSpray configuration
fog
applied to the scene mist propertiesConfiguration information of colors in
colorMaterialEnable
a Boolean value indicating whether color light calculation vertex attributes and material interactionuseConstantColor
Boolean value that indicates whether to use of colors in the constantconstantColor
using the constant color is not provided for each vertex color data discoloredReady to draw effects
- prepareToDraw
ready to render effects
Reproduced in: https: //www.jianshu.com/p/d272c3917e98