浮点或定点为Android NDK的OpenGL应用程序?浮点、应用程序、点为、Android

2023-09-06 02:24:26 作者:喜孤

我试图决定是否主要使用浮筒或整数在我的应用程序的所有3D相关的元素(这是C ++在大多数情况下)。据我所知,大多数基于ARM的设备没有硬件浮点支持,所以我想,任何繁重的工作与花车将明显变慢。

I'm trying to decide on whether to primarily use floats or ints for all 3D-related elements in my app (which is C++ for the most part). I understand that most ARM-based devices have no hardware floating point support, so I figure that any heavy lifting with floats would be noticeably slower.

不过,我打算preP大部分的所有数据(即具有顶点缓冲适用和使用矩阵没有发生很大的变化变换),所以我只是随便找数据下降的OpenGL的喉咙。我可以假设的是:这或多或少直接到GPU,并会这样是相当快的? (顺便说一句,最低要求是OpenGL ES 2.0的,所以presumably排除旧的1.x的系统的手机。)

However, I'm planning to prep all data for the most part (i.e. have vertex buffers where applicable and transform using matrices that don't change a lot), so I'm just stuffing data down OpenGL's throat. Can I assume that this goes more or less straight to the GPU and will as such be reasonably fast? (Btw, the minimum requirement is OpenGL ES 2.0, so that presumably excludes older 1.x-based phones.)

另外 - 怎么处罚我时,混合和匹配整型和浮点?假设我所有的几何只是pre-建浮法缓冲区,但我用整数的矩阵,因为这些确实需要像矩阵乘法,多少愤怒将我在这里承担昂贵的操作?

Also - how is the penalty when I mix and match ints and floats? Assuming that all my geometry is just pre-built float buffers, but I use ints for matrices since those do require expensive operations like matrix multiplications, how much wrath will I incur here?

顺便说一句,我知道我应该把我的期望值低(听起来甚至要求在CPU上的花车被要求太高),但有任何远程类似的128位寄存器VMX?

By the way, I know that I should keep my expectations low (sounds like even asking for floats on the CPU is asking for too much), but is there anything remotely like 128-bit VMX registers?

(我暗暗希望,法登在读这个问题,并有一个真棒答案。)

(And I'm secretly hoping that fadden is reading this question and has an awesome answer.)

推荐答案

像G1和的myTouch较早的Andr​​oid设备具有的ARMv6的CPU不支持浮点运算。大多数较新的设备,如在Droid,Nexus One的,和令人难以置信的,用的ARMv7-A的确实有FP硬件的CPU。如果你的游戏是真正的3D密集型的,它可能会要求更多的3D实现比旧的设备可以提供无论如何,所以你需要决定要支持什么级别的硬件。

Older Android devices like the G1 and MyTouch have ARMv6 CPUs without floating point support. Most newer devices, like the Droid, Nexus One, and Incredible, use ARMv7-A CPUs that do have FP hardware. If your game is really 3D-intensive, it might demand more from the 3D implementation than the older devices can provide anyway, so you need to decide what level of hardware you want to support.

如果您code只在Java中,你的程序将采取FP硬件的优势时可用。如果你编写本地code与NDK,并选择用于ARMv5TE架构,您将无法获得硬件FP的。如果您选择的ARMv7-A架构,你会的,但你的应用程序将不会适用于pre-的ARMv7-A设备。

If you code exclusively in Java, your app will take advantage of the FP hardware when available. If you write native code with the NDK, and select the armv5te architecture, you won't get hardware FP at all. If you select the armv7-a architecture, you will, but your app won't be available on pre-ARMv7-A devices.

的OpenGL现在应该坐在直接字节的缓冲区顶部,这是目前缓慢的从Java访问,但速度非常快,从本机端。 (我不知道很多有关GL执行的,所以我不能提供远不止于此。)

OpenGL from Java should be sitting on top of "direct" byte buffers now, which are currently slow to access from Java but very fast from the native side. (I don't know much about the GL implementation though, so I can't offer much more than that.)

有些设备另外还支持NEON高级SIMD扩展,它提供了一些花哨的功能,超越了基本的VFP的支持了。但是,您必须在运行测试这一点,如果你想使用它(看起来像有样本code这个现在 - 看到的 NDK页 NDK R4B)。

Some devices additionally support the NEON "Advanced SIMD" extension, which provides some fancy features beyond what the basic VFP support has. However, you must test for this at runtime if you want to use it (looks like there's sample code for this now -- see the NDK page for NDK r4b).

这是较早的答案有一定的info有关硬FP使用NDK的海湾合作​​委员会的标志。

An earlier answer has some info about the gcc flags used by the NDK for "hard" fp.

最后,为固定或浮动归结到你希望你的应用程序运行在什么设备类的答案。这当然更容易code对ARMv7-A,但你从一块市场割伤自己了。

Ultimately, the answer to "fixed or float" comes down to what class of devices you want your app to run on. It's certainly easier to code for armv7-a, but you cut yourself off from a piece of the market.