为什么iPhone上的纹理图像需要具有二维功率? [英] Why do images for textures on the iPhone need to have power-of-two dimensions?

查看:58
本文介绍了为什么iPhone上的纹理图像需要具有二维功率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试解决iphone上的这个闪烁问题(开放游戏)。我有一些没有2维度的图像。我要用适当尺寸的图像替换它们......但为什么尺寸必须是2的幂?

I'm trying to solve this flickering problem on the iphone (open gl es game). I have a few images that don't have pow-of-2 dimensions. I'm going to replace them with images with appropriate dimensions... but why do the dimensions need to be powers of two?

推荐答案

大多数系统(甚至许多现代显卡)需要2次幂纹理的原因是mipmapping。

The reason that most systems (even many modern graphics cards) demand power-of-2 textures is mipmapping.

什么是mipmapping?

将创建较小版本的图片为了使东西看起来非常小。将图像一次又一次地除以2以制作新图像。

Smaller versions of the image will be created in order to make the thing look correctly at a very small size. The image is divided by 2 over and over to make new images.

所以,想象一下256x128的图像。这将创建尺寸为128x64,64x32,32x16,16x8,8x4,4x2,2x1和1x1的较小版本。

So, imagine a 256x128 image. This would have smaller versions created of dimensions 128x64, 64x32, 32x16, 16x8, 8x4, 4x2, 2x1, and 1x1.

如果这张图片是256x192,那么在你达到4x3的尺寸之前它会正常工作。下一个较小的图像将是2x1.5,这显然不是有效的大小。一些图形硬件可以解决这个问题,但很多类型都不能处理。

If this image was 256x192, it would work fine until you got down to a size of 4x3. The next smaller image would be 2x1.5 which is obviously not a valid size. Some graphics hardware can deal with this, but many types cannot.

某些硬件也需要方形图像,但这不再常见了。

Some hardware also requires a square image but this isn't very common anymore.

为什么需要mipmapping?

想象一下你的照片非常远,所以很远只有4像素的大小。现在,当绘制每个像素时,将选择图像上的位置作为该像素的颜色。所以你最终得到的4个像素可能完全不能代表整个图像。

Imagine that you have a picture that is VERY far away, so far away as to be only the size of 4 pixels. Now, when each pixel is drawn, a position on the image will be selected as the color for that pixel. So you end up with 4 pixels that may not be at all representative of the image as a whole.

现在,想象一下图片正在移动。每次绘制新帧时,都会选择一个新像素。因为图像很远,所以很可能会看到非常不同的颜色,以适应运动中的微小变化。这会导致非常难看的闪烁。

Now, imagine that the picture is moving. Every time a new frame is drawn, a new pixel is selected. Because the image is SO far away, you are very likely to see very different colors for small changes in movement. This leads to very ugly flashing.

缺少mipmapping导致任何小于纹理大小的大小的问题,但是当图像被绘制到最小时它是最明显的一个非常少的像素。

Lack of mipmapping causes problems for any size that is smaller than the texture size, but it is most pronounced when the image is drawn down to a very small number of pixels.

使用mipmap,硬件可以访问2x2版本的纹理,因此它上面的每个像素都是该象限的平均颜色图像。这消除了奇怪的颜色闪烁。

With mipmaps, the hardware will have access to 2x2 version of the texture, so each pixel on it will be the average color of that quadrant of the image. This eliminates the odd color flashing.

http:/ /en.wikipedia.org/wiki/Mipmap

编辑给那些不再这样说的人:
很多现代人都是如此GPU可以支持非二次幂纹理,但许多人不能这样做。

Edit to people who say this isn't true anymore: It's true that many modern GPUs can support non-power-of-two textures but it's also true that many cannot.

事实上,就在上周我在XNA应用程序中有一个1024x768纹理我正在努力,它在一台只有一年左右的笔记本电脑上引起了游戏负载的崩溃。它在大多数机器上运行良好。可以肯定的是,iPhone的gpu比完整的PC gpu简单得多。

In fact, just last week I had a 1024x768 texture in an XNA app I was working on, and it caused a crash upon game load on a laptop that was only about a year old. It worked fine on most machines though. It's a safe bet that the iPhone's gpu is considerably more simple than a full PC gpu.

这篇关于为什么iPhone上的纹理图像需要具有二维功率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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