How to use GL_HALF_FLOAT_OES typed textures in iOS?

瘦欲@ 提交于 2019-11-29 02:02:46

After a year I faced the problem again. I did some research and finally found the solution:

On almost all iOS devices it is possible to create and use float and half-float-typed textures. In fact all devices that support the OES_texture_float extension (or OES_texture_half_float, respectively) allow the creation of float-typed textures.

However, if you are trying to render into a float-typed texture using a Framebuffer Object, the device needs to support the EXT_color_buffer_half_float extension as well. As the name suggests this extension allows to bind half-float-typed textures to the render target of an FBO.

Now it turns out that this extension is only supported on devices that have a PowerVR SGX 543 or 554 graphics card, which are basically all devices released after (and including) the iPhone 4S. You can refere to Apple's OpenGL ES Hardware Platform Guide for iOS for a list of devices and their capabilities.

Summary:

If you want to render to a float-typed texture, you need to check if your device supports the EXT_color_buffer_half_float extension and you need to create your texture with

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_HALF_FLOAT_OES, NULL);

If your device does not support half-float color buffers, you can only bind unsigned-byte-typed textures to your FBO:

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

(Note that the format and internal format of the texture (GL_RGBA in this case) depends on the attachment point of the FBO.)

I'm afraid you are doing nothing wrong, GL_HALF_FLOAT_OES is only supported on the iPhone4S and iPad2, despite there being no documentation to this effect. Float textures are a massive performance killer, even a basic variance shadow mapping implementation is completely unusable on an iPhone4S.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!