如何在 iOS 中使用 GL_HALF_FLOAT_OES 类型纹理? [英] How to use GL_HALF_FLOAT_OES typed textures in iOS?

查看:27
本文介绍了如何在 iOS 中使用 GL_HALF_FLOAT_OES 类型纹理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个浮动纹理来存储由片段着色器创建的渲染管道的中间结果.我需要片段的值是有符号的浮点数.

I'm trying to create a float texture to store intermediate results of my rendering pipeline created by a fragment shader. I need the values of the fragments to be signed floats.

我了解应该有 OES_texture_float 扩展所有新的 iOS 设备都支持(即根据 Apple 指南).

I understand that there is the OES_texture_float extension which should be supported by all new iOS devices (i.e. beginning from iPhone 3GS/iPod Touch 3/iPad according to the Apple guide).

但是,当我使用

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

启动我的应用并在 Instruments 中检查它,它告诉我:

start my app and inspect it in Instruments, it tells me:

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_HALF_FLOAT_OES, NULL) : (invalid enum=0x8d61): invalid enum for argument 'type'

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_HALF_FLOAT_OES, NULL) : (invalid enum=0x8d61): Invalid enum for argument 'type'

奇怪的是,它仍然可以在我的 iPhone 4S 上运行,但不能在 iPhone 4 上运行(应该也支持).但是,两个设备都会出现错误消息.但在 iPhone 4 上,OpenGL 无法使用此纹理作为渲染目标来构建有效的帧缓冲区对象.在完美运行的4S上.

The curious thing is that it's nevertheless working on my iPhone 4S, but not on a iPhone 4 (which should be supported as well). The error message appears for both devices, though. But on the iPhone 4 OpenGL can't build a valid framebuffer object using this texture as a rendering target. On the 4S that works perfectly well.

你对我做错了什么有什么建议吗?

Do you have any suggestions what I'm doing wrong?

谢谢!

推荐答案

一年后我又遇到了这个问题.我做了一些研究,终于找到了解决方案:

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

在几乎所有 iOS 设备上,都可以创建和使用浮动和半浮动类型的纹理.事实上,所有支持 OES_texture_float 扩展(或分别为 OES_texture_half_float)的设备都允许创建浮点类型的纹理.

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.

但是,如果您尝试使用 Framebuffer 对象将 渲染到浮点型纹理,则设备需要支持 EXT_color_buffer_half_float扩展名也是如此.顾名思义,这个扩展允许将半浮点类型的纹理绑定到 FBO 的渲染目标.

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.

现在事实证明,此扩展仅在具有 PowerVR SGX 543 或 554 显卡的设备上受支持,这些设备基本上是 iPhone 4S 之后(包括)发布的所有设备.可以参考苹果的OpenGL ES Hardware Platform Guide for iOS 获取设备列表及其功能.

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.

如果你想渲染一个浮点类型的纹理,你需要检查你的设备是否支持 EXT_color_buffer_half_float 扩展并且你需要创建你的纹理

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);

如果您的设备不支持半浮点颜色缓冲区,您只能将无符号字节类型的纹理绑定到您的 FBO:

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);

(注意纹理的格式和内部格式(本例中为GL_RGBA)取决于FBO的附着点.)

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

这篇关于如何在 iOS 中使用 GL_HALF_FLOAT_OES 类型纹理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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