Android 上使用 OpenGL ES 1.0 的简单粒子系统

发布于 2024-10-18 08:05:10 字数 787 浏览 5 评论 0原文

我正在尝试使用 OpenGL 将粒子系统放在 Android 中。我想要几千个粒子,其中大部分可能在任何给定时间都在屏幕外。它们在视觉上是相当简单的粒子,我的世界是 2D,但它们会移动、改变颜色(不是大小 - 它们是 2x2),然后我需要能够添加和删除。

我目前有一个数组,我可以迭代它,处理速度变化,管理生命周期(杀死旧的,添加新的),并使用 glDrawArrays 绘制它们。不过,对于此调用,OpenGl 所指向的是单个顶点;我将其 glTranslatex 转换为我想要绘制的每个粒子的相关坐标,一次一个,使用 glColor4x 设置颜色,然后使用 glDrawArrays 它。它确实有效,但速度有点慢,而且只适用于几百个粒子。我自己处理剪辑。

我编写了一个支持静态粒子的系统,我已将其加载到顶点/颜色数组中并使用 glDrawArrays 进行绘图,但这种方法似乎仅适用于永远不会改变相对位置的粒子(即我使用 glTranslate 移动所有粒子)、颜色以及我不需要添加/删除粒子的地方。在我的手机(HTC Desire)上进行的一些测试表明,尝试更改这些数组(OpenGL 指向的 ByteBuffer)的内容非常慢。

也许有某种方法可以让 CPU 自己手动写入屏幕。如果我只是在屏幕上绘制 1x1/2x2 点,并且我纯粹对写作感兴趣,而不进行任何混合/抗锯齿,这是一个选项吗?它会比 OpenGL 所做的更快吗?

(在具有兆内存的 1ghz 机器上有 200 个左右的粒子。这比我 20 年前在具有 <500k 内存的 7mhz 机器上得到的要慢得多!我很感激我在这里使用 Java,但肯定有我是否必须使用 NDK 才能获得 C++ 的强大功能,或者是我所追求的可能)

I'm trying to put a particle system together in Android, using OpenGL. I want a few thousand particles, most of which will probably be offscreen at any given time. They're fairly simple particles visually, and my world is 2D, but they will be moving, changing colour (not size - they're 2x2), and I need to be able to add and remove then.

I currently have an array which I iterate through, handling velocity changes, managing lifecyling (killing old ones, adding new ones), and plotting them, using glDrawArrays. What OpenGl is pointing at, though, for this call, is a single vertex; I glTranslatex it to the relevant co-ords for each particle I want to plot, one at a time, set the colour with glColor4x then glDrawArrays it. It works, but it's a bit slow and only works for a few hundred particles. I'm handling the clipping myself.

I've written a system to support static particles which I have loaded into a vertex/colourarray and plot using glDrawArrays, but this approach only seems suitable for particles which will never change relative location (ie I move all of them using glTranslate), colour and where I don't need to add/remove particles. A few tests on my phone (HTC Desire) suggest that trying to alter the contents of those arrays (which are ByteBuffers, pointed to by OpenGL) is extremely slow.

Perhaps there's some way of manually writing the screen myself with the CPU. If I'm just plotting 1x1/2x2 dots on the screen, and I'm purely interested in writing and not doing any blending/antialiasing, is this an option? Would it be quicker than whatever OpenGl is doing?

(200 or so particles on a 1ghz machine with megs of ram. This is way slower than I was getting 20 years ago on a 7mhz machine with <500k of ram! I appreciate I'm using Java here, but surely there must be a better solution. Do I have to use the NDK to get the power of C++, or is what I'm after possible)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一瞬间的火花 2024-10-25 08:05:10

我一直希望有人能明确回答这个问题,因为我自己也需要 Android 上的粒子。 (不过,我正在使用 C++ 工作——目前使用 glDrawArrays(),但尚未将粒子推向极限。)

我发现 gamedev.stackexchange.com 上的这个线程(不是 Android 特定的),没有人能就那里的最佳方法达成一致,但你可能想要尝试一些事情并亲自看看。

我本来打算建议 glDrawArrays(GL_POINTS, ...) 与 glPointSize() 一起使用,但提出问题的人似乎对此不满意。

如果您找到好的解决方案,请告诉我们!

I've been hoping somebody might answer this definitively, as I'll be needing particles on Android myself. (I'm working in C++, though -- Currently using glDrawArrays(), but haven't pushed particles to the limit yet.)

I found this thread on gamedev.stackexchange.com (not Android-specific), and nobody can agree on the best approach there, but you might want to try a few things out and see for yourself.

I was going to suggest glDrawArrays(GL_POINTS, ...) with glPointSize(), but the guy asking the question there seemed unhappy with it.

Let us know if you find a good solution!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文