改进粒子系统OpenGL [英] Improve Particle system OpenGL

查看:68
本文介绍了改进粒子系统OpenGL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来提高我的粒子系统性能,因为它在 FPS 方面的成本非常高.这是因为我打电话给:

I'm looking for a way to improve my particle system performance, since it is very costly in terms of FPS. This is because I call:

glDrawElements(GL_TRIANGLE_STRIP, mNumberOfIndices,
          GL_UNSIGNED_SHORT, 0);

我为应用程序中的每个粒子(可能介于 1000 到 5000 个粒子之间)调用此方法.请注意,当增加到超过 1000 个粒子时,我的应用程序的 FPS 开始下降.我正在使用 VBO:s,但调用此方法时的性能成本太高.

I call this method for every particle in my application (which could be between 1000 and 5000 particles). Note that when increasing to over 1000 particles my application starting to drop down in FPS. I'm using VBO:s, but the performance when calling this method is too costly.

有什么想法可以让粒子系统更高效吗?

Any ideas how I can make the particle system more efficient?

这就是我的粒子系统绘制东西的方式:

This is how my particle system draw things:

glBindTexture(GL_TEXTURE_2D, textureObject);
glBindBuffer(GL_ARRAY_BUFFER, vboVertexBuffer[0]);
glVertexPointer(3, GL_FLOAT, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, vboTextureBuffer[0]);
glTexCoordPointer(2, GL_FLOAT, 0, 0); 
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIndexBuffer[0]);

Vector3f partPos;

for (int i = 0; i < m_numParticles; i++) {
    partPos = m_particleList[i].m_pos;          
    glTranslatef(partPos.x, partPos.y, partPos.z);
    glDrawElements(GL_TRIANGLE_STRIP, mNumberOfIndices, 
        GL_UNSIGNED_SHORT, 0);
    gl.glTranslatef(-partPos.x, -partPos.y, -partPos.z);
}

推荐答案

从您描述的方式来看,听起来您对每个粒子都有自己的 VBO.这不是应该做的.将所有粒子放入一个 VBO 中,并使用单个 glDrawElementsglDrawArrays 调用一次性绘制所有粒子.或者甚至更好(如果可用):使用实例化.

The way you describe it, it sounds like you have a own VBO for each particle. This is not how it should be done. Put all particles into a single VBO and draw them all at once using a single glDrawElements or glDrawArrays call. Or even better, if available: Use instancing.

这篇关于改进粒子系统OpenGL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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