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

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

问题描述

我试图创建一个浮点纹理来存储由片段着色器创建的渲染管线的中间结果。我需要的碎片的值是签署浮动。



据我所知,有一个 OES_texture_float 扩展,它应该由所有新的iOS设备(支持即从iPhone 3GS的/ iPod Touch的3 / iPad的开始根据
$ b $创建这样一个纹理的时候 b'pre> glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,宽度,高度,0,GL_RGB,GL_HALF_FLOAT_OES,NULL);

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


glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,width,height,0,GL_RGB,GL_HALF_FLOAT_OES,NULL):(无效枚举= 0x8d61):参数'type' / p>

好奇的是,它仍然在我的iPhone 4S上工作,而不是在iPhone 4上(这也应该被支持)。虽然,两个设备都会显示错误消息。但在iPhone 4上,OpenGL无法使用此纹理构建有效的帧缓冲区对象作为渲染目标。在这个4S上工作的很好。



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

谢谢!

解决方案

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

几乎所有的iOS设备上都可以创建和使用float和half-float类型的纹理。在事实(分别或 OES_texture_half_float )支持 OES_texture_float 扩展的所有设备允许浮动类型的纹理的创建。但是,如果您试图使用Framebuffer对象将渲染为浮动类型的纹理,则设备还需要支持 EXT_color_buffer_half_float 扩展名。顾名思义,这个扩展允许将半浮点型纹理绑定到FBO的渲染目标上。

现在事实证明,这个扩展只支持在设备上有一个PowerVR SGX 543或554显卡,基本上都是在iPhone 4S(包括)之后发布的所有设备。您可以参考Apple的适用于iOS的OpenGL ES硬件平台指南,获取设备及其功能列表。

总结:

如果您想渲染为浮点类型的纹理,你需要检查,如果你的设备支持 EXT_color_buffer_half_float 扩展,你需要使用

  glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,width,height,0,GL_RGBA,GL_HALF_FLOAT_OES,NULL)来创建纹理。 

如果您的设备不支持半浮点颜色缓冲区,则只能绑定unsigned-byte-typed纹理到你的FBO:

$ pre $ g $ g $ g $ g $ GL $ GL_EXTURE_2D,0,GL_RGBA,width,height,0,GL_RGBA,GL_UNSIGNED_BYTE,NULL); (请注意,纹理的格式和内部格式( GL_RGBA





在这种情况下)取决于FBO的连接点。)


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.

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

However, when I create such a texture using

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

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'

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?

Thanks!

解决方案

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

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

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