OpenGL ES 2.0 纹理未在某些设备上显示 [英] OpenGL ES 2.0 texture not showing on some device

查看:31
本文介绍了OpenGL ES 2.0 纹理未在某些设备上显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了一个名为 Rajawali 我正在学习如何使用它.我遵循了最基本的教程,它使用 1024x512 大小的 jpg 图像为纹理渲染一个 shpere 对象.它在 Galaxy Nexus 上运行良好,但在 Galaxy Player GB70 上却无法运行.

I found a 3D graphics framework for Android called Rajawali and I am learning how to use it. I followed the most basic tutorial which is rendering a shpere object with a 1024x512 size jpg image for the texture. It worked fine on Galaxy Nexus, but it didn't work on the Galaxy Player GB70.

当我说它不起作用时,我的意思是对象出现但纹理没有渲染.最终,我更改了一些在创建纹理时用于 Rajawali 框架的参数并使其工作.这是我发现的.

When I say it didn't work, I mean that the object appears but the texture is not rendered. Eventually, I changed some parameters that I use for the Rajawali framework when creating textures and got it to work. Here is what I found out.

原因来自设置 GL_TEXTURE_MIN_FILTER 的位置.以下四个值中

The cause was coming from where the GL_TEXTURE_MIN_FILTER was being set. Among the following four values

GLES20.GL_LINEAR_MIPMAP_LINEAR
GLES20.GL_NEAREST_MIPMAP_NEAREST
GLES20.GL_LINEAR
GLES20.GL_NEAREST

仅当 GL_TEXTURE_MIN_FILTER 未使用 mipmap 设置为过滤器时才会渲染纹理.因此,当 GL_TEXTURE_MIN_FILTER 设置为最后两个时,它可以工作.

the texture is only rendered when GL_TEXTURE_MIN_FILTER is not set to a filter using mipmap. So when GL_TEXTURE_MIN_FILTER is set to the last two it works.

现在这里是我不理解和好奇的地方.当我将用作纹理的图像缩小到 512x512 时,GL_TEXTURE_MIN_FILTER 设置无关紧要.min 过滤器的所有四个设置都有效.

Now here is the what I don't understand and am curious about. When I shrink the image which I'm using as the texture to size 512x512 the GL_TEXTURE_MIN_FILTER settings does not matter. All four settings of the min filter works.

所以我的问题是,对纹理使用最小滤镜时,对图像的尺寸有要求吗?比如我需要使用正方形的图像吗?其他的东西,比如 wrap 样式或 mag 过滤器的配置是否有问题?

So my question is, is there a requirement for the dimensions of the image when using min filter for the texture? Such as am I required to use an image that is square? Can other things such as the wrap style or the the configuration of the mag filter be a problem?

或者它看起来像是设备的 OpenGL 实现错误?

Or does it seem like a OpenGL implementation bug of the device?

推荐答案

早上好,这是非幂次纹理的典型例子.

Good morning, this a typical example of non-power of 2 textures.

由于多种原因,纹理的分辨率必须是 2 的幂,这是一个非常常见的错误,每个人都曾遇到过这个陷阱 :) 我也是.

Textures need to be power of 2 in their resolution for a multitude of reasons, this is a very common mistake and it did happen to everybody to fall in this pitfall :) too me too.

non power of 2 纹理在某些设备/GPU 上运行顺畅这一事实仅取决于 OpenGL 驱动程序的实现,有些 GPU 清楚地支持它们,有些则不支持,我强烈建议您按顺序使用 pow2 纹理能够保证所有设备上的功能.

The fact that non power of 2 textures work smoothly on some devices/GPU, depends merely to the OpenGL drivers implementation, some GPUs support them clearly, some others don't, I strongly suggest you to go for pow2 textures in order to be able to guarantee the functioning on all the devices.

最后但同样重要的是,使用非 2 次幂纹理可能会导致 GPU 内存利用率出现灾难性场景,因为大多数接受非 2 次幂纹理的驱动程序需要在内存中将纹理重新缩放到最接近的更高幂2 因素.例如,具有 520X520 的纹理可能会导致实际的内存映射为 1024X1024.

Last but not least, using non power of 2 textures can lead you to a cathastrophic scenarious in GPU memory utilization since, most of the drivers which accept non-powerof2 textures, need to rescale in memory the textures to the nearest higher power of 2 factor. For instance, having a texture of 520X520 could lead to an actual memory mapping of 1024X1024.

这是您不想要的,因为在现实世界中尺寸很重要",尤其是在移动设备上.

This is something you don't want because in real world "size matters", especially on mobile devices.

您可以在 OpenGL Gold Book,OpenGL ES 2.0 中找到一个很好的解释:

You can find a quite good explanation in the OpenGL Gold Book, the OpenGL ES 2.0:

在 OpenGL ES 2.0 中,纹理可以有非二次幂 (npot)方面.换句话说,宽度和高度不需要是两个的幂.但是,OpenGL ES 2.0 确实对如果纹理尺寸不是幂次方可以使用的环绕模式二.也就是说,对于 npot 纹理,wrap 模式只能是GL_CLAMP_TO_EDGE 和缩小过滤器只能是 GL_NEAREST或 GL_LINEAR(换句话说,不是 mip-mapped).扩展名GL_OES_texture_npot 放宽了这些限制并允许换行模式GL_REPEAT 和 GL_MIRRORED_REPEAT 并且还允许 npot 纹理使用全套缩小过滤器进行 mipmap.

In OpenGL ES 2.0, textures can have non-power-of-two (npot) dimensions. In other words, the width and height do not need to be a power of two. However, OpenGL ES 2.0 does have a restriction on the wrap modes that can be used if the texture dimensions are not power of two. That is, for npot textures, the wrap mode can only be GL_CLAMP_TO_EDGE and the minifica- tion filter can only be GL_NEAREST or GL_LINEAR (in other words, not mip- mapped). The extension GL_OES_texture_npot relaxes these restrictions and allows wrap modes of GL_REPEAT and GL_MIRRORED_REPEAT and also allows npot textures to be mipmapped with the full set of minification filters.

我建议您评估这本书,因为它对该主题的报道相当不错.

I suggest you to evaluate this book since it does a quite decent coverage to this topic.

这篇关于OpenGL ES 2.0 纹理未在某些设备上显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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