全屏纹理iPhone OpenGL ES [英] Fullscreen texture iPhone OpenGL ES

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

问题描述

我知道iphone上的OpenGL纹理必须是2的强大,这对OpenGL 2.0来说也是如此吗?如果我有一个尺寸为320 x 480的图像并想要全屏绘制,那么有可能用OpenGL做这个。

I'm aware that OpenGL textures on the the iphone are required to be a power of 2, is this true of OpenGL 2.0 as well? If I have an image that is 320 x 480 in size and want to draw it full screen is there any possible way to do this with OpenGL.

谢谢

推荐答案

PowerVR SGX硬件支持NPOT纹理 ,但有限制。 NPOT纹理不能使用mipmap,必须是2D(没有立方体贴图或3D纹理),并且必须使用 GL_CLAMP_TO_EDGE 在两个维度中进行纹理包装;这在默认情况下支持OpenGL ES 2.0和ES 1.1下的扩展 GL_APPLE_texture_2D_limited_npot

NPOT textures are supported on PowerVR SGX hardware, but have restrictions. NPOT textures cannot use mipmaps, must be 2D (no cube-maps or 3D textures) and must use the GL_CLAMP_TO_EDGE for texture wrapping in both dimensions; this is supported by default in OpenGL ES 2.0 and under ES 1.1 by the extension GL_APPLE_texture_2D_limited_npot

对于ES 1.1,你可以在运行时检查此代码是否存在此扩展:

For ES 1.1, you can check at runtime to see if this extension is present with this code:

const char* extensions = (char*) glGetString(GL_EXTENSIONS);
bool npot = strstr(extensions, "GL_APPLE_texture_2D_limited_npot") != 0;

由于这只出现在SGX而不是MBX上,请注意依赖于NPOT纹理支持将限制您使用较新的SGX设备。当然,依赖ES 2.0也会这样做,所以如果这是您的预期目标,NPOT支持是一个没有实际意义的点,您可以继续使用NPOT纹理。

Since this is only present on the SGX and not the MBX, be aware that relying on NPOT texture support will limit you to the newer SGX devices. Of course, relying on ES 2.0 will do the same, so if that's your intended target, NPOT support is a moot point and you can go ahead with NPOT textures.

这是一个备用解决方案,可让您继续使用ES 1.1并保留完整的设备支持。将320x480纹理放在512x512内,用其他背景图块,字形或其他将同时绘制的纹理填充空白(以避免多个 glBindTexture 调用)和然后使用我最喜欢的ES 1.1扩展之一 GL_OES_draw_texture ,快速将320x480部分复制到视口上:

Here's an alternate solution that lets you keep using ES 1.1 and retain full device support. Put the 320x480 texture inside a 512x512, fill the whitespace with other background tiles, glyphs, or other textures that will be drawn at the same time (to avoid multiple glBindTexture calls) and then use one of my favourite ES 1.1 extensions, GL_OES_draw_texture, to quickly copy the 320x480 section onto the viewport:

int rect[4] = {0, 0, 480, 320};
glBindTexture(GL_TEXTURE_2D, texBackground);
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, rect);
glDrawTexiOES(0, 0, z, 480, 320);

补充工具栏:OpenGL ES 2.0规范本身并未对NPOT纹理指定任何限制;除非我弄错了,Apple正在施加限制 - 当然,在ES 1.1世界中,NPOT支持根本不存在,所以它是一个补充。

Sidebar: The OpenGL ES 2.0 spec itself doesn't specify any restrictions on NPOT textures; unless I'm mistaken, Apple is imposing the limitations - of course, in the ES 1.1 world, NPOT support doesn't exist at all, so it's an addition there.

这篇关于全屏纹理iPhone OpenGL ES的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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