glkView:drawInRect: 和 glkViewControllerUpdate: 之间的区别?OpenGL ES 2 - iOS [英] Difference between glkView:drawInRect: and glkViewControllerUpdate:? OpenGL ES 2 - iOS

查看:33
本文介绍了glkView:drawInRect: 和 glkViewControllerUpdate: 之间的区别?OpenGL ES 2 - iOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的渲染循环中这两种方法之间的区别应该是什么?

What should be the difference, purpose wise, between these two methods in my render loop?

苹果有话要说......

Apple has this to say....

关于更新()视图控制器调用其委托的 glkViewControllerUpdate: 方法.您的委托应更新不涉及将结果呈现到屏幕的帧数据.

关于 drawInRect:GLKView 对象使其 OpenGL ES 上下文成为当前上下文,并将其帧缓冲区绑定为 OpenGL ES 渲染命令的目标.然后你的委托方法应该绘制视图的内容.

About drawInRect: the GLKView object makes its OpenGL ES context the current context and binds its framebuffer as the target for OpenGL ES rendering commands. Your delegate method should then draw the view’s contents.

所以基本上,当我在我的视图控制器中创建一个 GLKView 时,该控制器成为 delate,所以我并排查看这些方法.

So basically, when I create a GLKView in my view controller, that controller becomes the delate, so I am looking at these methods side by side.

我假设 update() 应该包含任何转换或其他逻辑.

I assumed that update() should contain any transforms or other logic.

推荐答案

首先,Apple 试图帮助您将时序与帧速率分离.如果您的游戏总是设法在分配给单个帧的时间内绘制一个帧,则两者将同步发生.但即使屏幕上出现大量对象并且您的帧速率略有下降,您仍然会获得相同数量的每秒更新,因此对象仍会以相同速度移动.

In the first instance, Apple are trying to help you decouple timing from frame rate. If your game always manages to draw a frame in the time allotted for a single frame, the two will occur in lockstep. But even if lots of objects come on screen and your frame rate sags a little, you'll still get the same number of updates a second so objects will still move at the same speed.

第二,它们帮助您将代码划分为模型-视图-控制器.对象的呈现方式应与其行为方式分离.

In the second, they're helping you keep your code divided as model-view-controller. How your objects are presented should be decoupled from how they act.

所以你的更新应该进行,无论是什么导致你的动画,你的绘制应该呈现当前状态.

So your update should progress whatever it is that causes your animation, your draw should present the current state.

这篇关于glkView:drawInRect: 和 glkViewControllerUpdate: 之间的区别?OpenGL ES 2 - iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆