美文网首页
OpenGL ES(GLKView+GLKViewControl

OpenGL ES(GLKView+GLKViewControl

作者: 忆痕无殇 | 来源:发表于2019-06-04 18:09 被阅读0次

GLKView使用OpenGL ES绘制内容的视图默认实现

1:初始化视图

- (instancetype)initWithFrame:(CGRect)frame context:(EAGLContext *)context

context 绘制视图内容时使⽤用的OpenGL ES 上下⽂文

2:代理方法

/*
 Required method for implementing GLKViewDelegate. This draw method variant should be used when not subclassing GLKView.
 This method will not be called if the GLKView object has been subclassed and implements -(void)drawRect:(CGRect)rect.
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect;

代理方法是有调用条件的:实现GLKView的delegate方法。当不对GLKView进行子类化时,应该使用这个draw方法变量。
如果GLKView对象已被子类化并实现了 -(void)drawRect:(CGRect)rect,则不会调用此方法。

3:配置帧缓存对象

1) drawableColorFormat

/*
 Enums for color buffer formats.
 */
typedef NS_ENUM(GLint, GLKViewDrawableColorFormat)
{
    GLKViewDrawableColorFormatRGBA8888 = 0,
    GLKViewDrawableColorFormatRGB565,
    GLKViewDrawableColorFormatSRGBA8888,
} NS_ENUM_AVAILABLE(10_8, 5_0);

注:8888代表R、G、B、A
2)drawableDepthFormat

/*
 Enums for depth buffer formats.
 */
typedef NS_ENUM(GLint, GLKViewDrawableDepthFormat)
{
    GLKViewDrawableDepthFormatNone = 0,
    GLKViewDrawableDepthFormat16,
    GLKViewDrawableDepthFormat24,
} NS_ENUM_AVAILABLE(10_8, 5_0);

3)drawableStencilFormat

/*
 Enums for stencil buffer formats.
 */
typedef NS_ENUM(GLint, GLKViewDrawableStencilFormat)
{
    GLKViewDrawableStencilFormatNone = 0,
    GLKViewDrawableStencilFormat8,
} NS_ENUM_AVAILABLE(10_8, 5_0);

4)drawableMultisample

/*
 Enums for MSAA.
 */
typedef NS_ENUM(GLint, GLKViewDrawableMultisample)
{
    GLKViewDrawableMultisampleNone = 0,
    GLKViewDrawableMultisample4X,
} NS_ENUM_AVAILABLE(10_8, 5_0);

4:帧缓存区属性

drawableHeight 底层缓存区对象的⾼高度(以像素为单位)
drawableWidth 底层缓存区对象的宽度(以像素为单位)

4:绘制视图流程 GLKView绘制思维导图.jpg

GLKViewController管理OpenGL ES 渲染循环的视图控制器

1:更新

/*
 Required method for implementing GLKViewControllerDelegate. This update method variant should be used
 when not subclassing GLKViewController. This method will not be called if the GLKViewController object
 has been subclassed and implements -(void)update.
 */
- (void)glkViewControllerUpdate:(GLKViewController *)controller;

2:配置帧速率

·preferredFramesPerSecond 视图控制器调⽤视图以及更新视图内容的速率
framesPerSencond 视图控制器调⽤视图以及更新其内容的实际速率

3:代理

@required
/*
 Required method for implementing GLKViewControllerDelegate. This update method variant should be used
 when not subclassing GLKViewController. This method will not be called if the GLKViewController object
 has been subclassed and implements -(void)update.
 */
- (void)glkViewControllerUpdate:(GLKViewController *)controller;
//处理更新事件,在显示每个帧之前调⽤。
@optional
/*
 Delegate method that gets called when the pause state changes. 
 */
- (void)glkViewController:(GLKViewController *)controller willPause:(BOOL)pause;
//暂停/恢复通知,在渲染循环暂停或恢复之前调用。

4:控制帧更新

1.paused 布尔值,渲染循环是否已暂停
2.pausedOnWillResignActive 布尔值,当前程序重新激活活动状态时视图控制器是否自动暂停渲染循环
3.resumeOnDidBecomeActive 布尔值,当前程序变为活动状态时视图控制是否自动恢复呈现循环。

5:获取有关View更新信息

/*
 The total number of frames displayed since drawing began.
 */
@property (nonatomic, readonly) NSInteger framesDisplayed;

/*

//视图控制器自创建以来发送的帧更新数

/*
 Time interval since properties.
 */
@property (nonatomic, readonly) NSTimeInterval timeSinceFirstResume;
@property (nonatomic, readonly) NSTimeInterval timeSinceLastResume;
@property (nonatomic, readonly) NSTimeInterval timeSinceLastUpdate;
@property (nonatomic, readonly) NSTimeInterval timeSinceLastDraw;

/*

//timeSinceFirstResume 自视图控制器第一次恢复发送更新事件以来经过的时间量
timeSinceLastResume ⾃上次视图控制器恢复发送更新事件以来更新的时间量
timeSinceLastUpdate ⾃上次视图控制器调用委托⽅法以及经过的时间量
glkViewControllerUpdate:
timeSinceLastDraw ⾃自上次视图控制器器调⽤用视图display ⽅方法以来经过的时间量量.

相关文章

网友评论

      本文标题:OpenGL ES(GLKView+GLKViewControl

      本文链接:https://www.haomeiwen.com/subject/uvlhxctx.html