AndEngine中TextureOptions的区别

来源:互联网 发布:阿里云最便宜服务器 编辑:程序博客网 时间:2024/04/30 09:32

在学习AndEngine中的贴图,发现TextureOptions有多种选项在源码中如下:

public static final TextureOptions NEAREST = new TextureOptions(GLES20.GL_NEAREST, GLES20.GL_NEAREST, GLES20.GL_CLAMP_TO_EDGE, GLES20.GL_CLAMP_TO_EDGE, false);public static final TextureOptions BILINEAR = new TextureOptions(GLES20.GL_LINEAR, GLES20.GL_LINEAR, GLES20.GL_CLAMP_TO_EDGE, GLES20.GL_CLAMP_TO_EDGE, false);public static final TextureOptions REPEATING_NEAREST = new TextureOptions(GLES20.GL_NEAREST, GLES20.GL_NEAREST, GLES20.GL_REPEAT, GLES20.GL_REPEAT, false);public static final TextureOptions REPEATING_BILINEAR = new TextureOptions(GLES20.GL_LINEAR, GLES20.GL_LINEAR, GLES20.GL_REPEAT, GLES20.GL_REPEAT, false);public static final TextureOptions NEAREST_PREMULTIPLYALPHA = new TextureOptions(GLES20.GL_NEAREST, GLES20.GL_NEAREST, GLES20.GL_CLAMP_TO_EDGE, GLES20.GL_CLAMP_TO_EDGE, true);public static final TextureOptions BILINEAR_PREMULTIPLYALPHA = new TextureOptions(GLES20.GL_LINEAR, GLES20.GL_LINEAR, GLES20.GL_CLAMP_TO_EDGE, GLES20.GL_CLAMP_TO_EDGE, true);public static final TextureOptions REPEATING_NEAREST_PREMULTIPLYALPHA = new TextureOptions(GLES20.GL_NEAREST, GLES20.GL_NEAREST, GLES20.GL_REPEAT, GLES20.GL_REPEAT, true);public static final TextureOptions REPEATING_BILINEAR_PREMULTIPLYALPHA = new TextureOptions(GLES20.GL_LINEAR, GLES20.GL_LINEAR, GLES20.GL_REPEAT, GLES20.GL_REPEAT, true);public static final TextureOptions DEFAULT = NEAREST;

在其论坛中有网友给出了如下说明:

- NEAREST: Faster then BILINEAR as only the nearest pixel on the Texture is used (Sprites tend to look pixelated when, physical resolution is higher or lower than texture resolution. Up/Down-scaling)
- BILINEAR: Slower than NEAREST, but looks better, as not only one pixel from the texture is fetched but the 4 nearest.

The difference between those and the REPEATING TextureOptions is the way OpenGL treats TextureCoordinates that are out of the physical bounds of the Texture (usually ranging from 0.0 to 1.0).
Where REPEATING paints the Texture twice when the coordinates go from 0.0 to 2.0, NON-REPEATING will stretch the outermost pixel of the Texture what looks pretty ugly.

So the REPEATING TextureOptions are used only in very special cases.

For a description what the PREMULTIPLYALPHA-thing is, have a look here: 点击打开链接

大致就是说NEAREST要比BILINEAR快,因为NEAREST在缩放时使用距离缩放位置最近的一个像素而BILINEAR要使用最近的4个像素来确定缩放位置的最终显示效果。但是BILINEAR所得到的效果要比EAREST好。

带REPEATING的只在特殊情况下使用。

原创粉丝点击