OpenGL ES 中的大滚动背景 [英] Large scrolling background in OpenGL ES

查看:34
本文介绍了OpenGL ES 中的大滚动背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 iPhone 开发一款 2D 滚动游戏.我有一个大图像背景,比如 480×6000 像素,只有一部分是可见的(正好是一个屏幕的价值,480×320 像素).在屏幕上获得这种背景的最佳方法是什么?

I am working on a 2D scrolling game for iPhone. I have a large image background, say 480×6000 pixels, of only a part is visible (exactly one screen’s worth, 480×320 pixels). What is the best way to get such a background on the screen?

目前我将背景分成几个纹理(以绕过最大纹理大小限制),并在每一帧中将整个背景绘制为带纹理的三角形条.滚动是通过转换模型视图矩阵来完成的.剪刀框设置为窗口大小,480×320像素.这并不意味着很快,我只是想要在开始优化之前的工作代码.

Currently I have the background split into several textures (to get around the maximum texture size limit) and draw the whole background in each frame as a textured triangle strip. The scrolling is done by translating the modelview matrix. The scissor box is set to the window size, 480×320 pixels. This is not meant to be fast, I just wanted a working code before I get to optimizing.

我认为 OpenGL 实现可能足够聪明,可以丢弃背景的不可见部分,但根据我编写的一些测量代码,背景看起来平均需要 7 毫秒,最多需要 84 毫秒.(这是在模拟器中测量的.)这大约是整个渲染循环的一半,即.对我来说很慢.

I thought that maybe the OpenGL implementation would be smart enough to discard the invisible portion of the background, but according to some measuring code I wrote it looks like background takes 7 ms to draw on average and 84 ms at maximum. (This is measured in the simulator.) This is about a half of the whole render loop, ie. quite slow for me.

绘制背景应该像将一些 480×320 像素从 VRAM 的一个部分复制到另一个部分一样简单,或者换句话说,非常快.接近这种性能的最佳方法是什么?

Drawing the background should be as easy as copying some 480×320 pixels from one part of the VRAM to another, or, in other words, blazing fast. What is the best way to get closer to such performance?

推荐答案

这是最快的方法.您可以采取哪些措施来提高性能:

That's the fast way of doing it. Things you can do to improve performance:

  • 尝试不同的纹理格式.大概 SDK 文档有关于首选格式的详细信息,并且可能越小越好.
  • 自己完全剔除屏幕外的图块
  • 将图像分割成更小的纹理

我假设您以 1:1 的缩放比例进行绘图;是这样吗?

I'm assuming you're drawing at a 1:1 zoom-level; is that the case?

糟糕.更仔细地阅读您的问题后,我必须提供另一条建议:在模拟器上制作的时间毫无价值.

Oops. Having read your question more carefully, I have to offer another piece of advice: Timings made on the simulator are worthless.

这篇关于OpenGL ES 中的大滚动背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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