02-OpenGL ES GLKit resolve common API

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 Shadereffects. GLKitAllows 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:
      GLKBaseEffectclass implements a subset of OpenGL ES 1.1 Key shading and lighting model;
      GLKReflectionMapEffectsubstantially expanded to include the effect of the reflection type support mapping;
      GLKSkyboxEffectclass provides an implementation skyboxeffect.
  • View of the GLKit and corresponding ViewController. GLKView ClassAnd GLKViewController 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. GLKTextureInfoCreate 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. GLTextureLoadersimplified 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 objects

  • Load 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 texture

  • Load 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 data

  • Representation 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 data

  • Create 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 texture

  • Create 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 data

  • File 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. GLKViewUse OpenGL ES rendering view the contents of the default implementation

  • Initialization view
    - initWithFrame:context:initialize a new view

  • Agent
    delegatefor an agent view

  • Configuration frame buffer objects
    drawableColorFormatcolor rendering format buffer
    drawableDepthFormatdepth buffer rendering format
    drawableStencilFormattemplate rendering format buffer of
    drawableMultisamplemulti-sampling buffer format

  • Attributes frame buffer
    drawableHeightand altitudes (in pixels) of the underlying cache object
    drawableWidthunderlying cache object width (in pixels)

  • SUMMARY pictorial view of
    contextOpenGL ES rendering vertical view the file content used when
    - bindDrawablethe object is bound to the underlying FrameBuffer OpenGL ES
    enableSetNeedsDisplayBoolean value that specifies whether the view the content view response message be ineffective
    - displayattention immediately redraw view content
    snapshotrendering and content view as The new image object return

  • Delete view FrameBuffer objects
    - deleteDrawableto delete the view associated drawable

4 GLKViewDelegatefor GLKViewsubject correction Remedies

- glkView:drawInRect:Drawing view contents (must implement agency management)

The GLKViewControllermanagement cycle OpenGL ES rendering view controller

  • Update
    - (void) updateupdate view content
    - (void) glkViewControllerUpdate:agency put France

  • Configuring the frame rate
    preferredFramesPerSecondview and update the view controller Use tone-view content rate
    framesPerSencondview and the controller calls the view's update its contents the actual rate

  • Configuration GLKViewControllerAgent

//处理更新事件
//在现实每个帧之前调用
- (void)glkViewControllerUpdate:(GLKViewController *)controller;
//暂停/恢复通知
//在渲染循环暂停或回复之前调用
- (void)glkViewController:(GLKViewController *)controller willPause:(BOOL)pause;
  • Control frame update
    pausedBoolean value, whether the cycle is paused rendering
    pausedOnWillResignActivea Boolean value, the current program to reactivate the active view controller automatically stops if the rendering loop
    resumeOnDidBecomeActiveview control when a Boolean value, the current program becomes active if automatic recovery render loop

  • View information about obtaining updated
    frameDisplayedsince the view controller created automatically update the number of frames sent
    timeSinceFirstResumethe amount of time that has elapsed since the first view controller automatically sends updates to restore the event
    timeSinceLastResumethe amount of time since the last update to restore view controller sends an update event
    timeSinceLastUpdateautomatically last view controller calls the delegate Remedies and the amount of time that has elapsed
    timeSinceLastDrawautomatically calls the last view controller view displaythe amount of time elapsed since the method

6. GLKBaseEffectA 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
    labelto Effect (effect) named

  • Configuration model view transformation
    transformis applied to the vertex data model view when binding effect, projection and texture transform

  • Configuration lighting effects
    lightingTypeUse 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
    lightModelTwoSidedBoolean value that indicates lighting calculations on both sides of the primitive
    materialcomputing rendering the primitive that the light material properties Using the
    lightModelAmbientColorambient color, all application effect rendered membered FIG.
    light0Scenario first light property
    light1scene illumination properties th second shot
    light2scenes the third light properties

  • Texture arranged
    texture2d0first texture attribute
    texture2d1second shot texture attributes
    textureOrdertextures to rendered primitive sequence

  • Spray configuration
    fogapplied to the scene mist properties

  • Configuration information of colors in
    colorMaterialEnablea Boolean value indicating whether color light calculation vertex attributes and material interaction
    useConstantColorBoolean value that indicates whether to use of colors in the constant
    constantColorusing the constant color is not provided for each vertex color data discolored

  • Ready to draw effects
    - prepareToDrawready to render effects

Reproduced in: https: //www.jianshu.com/p/d272c3917e98

Guess you like

Origin blog.csdn.net/weixin_34119545/article/details/91161647