简体   繁体   English

保存多个实例数据的最佳方法

[英]Best way to save data of many instances

I have a particle system and for that I render (for 1 particle effect for example) 100 quads with texture on it. 我有一个粒子系统,为此我渲染(例如1个粒子效果)带有纹理的100个四边形。 If I add several particle effects it lags because each particle has its own velicity (2f vector), position (3f vec), etc... (Vectors are from LwJGL) 如果我添加多个粒子效果,则它会滞后,因为每个粒子都有其自己的垂直度(2f矢量),位置(3f vec)等...(矢量来自LwJGL)

As a consequence each instance means like 5 or 6 data types. 结果,每个实例意味着5或6种数据类型。 Now my question is: 现在我的问题是:

Is there a way of making this better, so that not every instance has 5 new vectors? 有没有一种方法可以使它变得更好,以便不是每个实例都有5个新向量? (And I know, that there are many other better ways of creating a particle system, but this one I choose was easy and I can practice "performance boosting".. (而且,我知道创建粒子系统还有许多其他更好的方法,但是我选择的这种方法很简单,我可以练习“性能提升”。)

Ok, so, I will refer to this code where you probably get inspired by. 好的,因此,我将参考此代码 ,您可能会从中受到启发。

I also suppose you have at least GL 3.3 profile. 我还假设您至少具有GL 3.3配置文件。

In theory, to optimaze at best you should move Map<ParticleTexture, List<Particle>> particles (using a texture atlas) on the gpu and upload only the changing data per-frame, like camera . 从理论上讲,要充其量进行优化,您应该在GPU上移动Map<ParticleTexture, List<Particle>> particles (使用纹理图集),并且每帧仅上载变化的数据,例如camera But this is not easy to do in one step, so I suggest you to modify your current algorithm step by step by moving one thing at time on the gpu. 但这一步很难做到,所以我建议您通过在gpu上一次移动一件事来逐步修改当前算法。

Some observations: 一些观察:

  • in prepare() and finishRendering() , the enabling of the i-th VertexAttribArray is part of the vao, if you bind/unbind the vao, it's enough. prepare()finishRendering() ,启用第i个VertexAttribArray是vao的一部分,如果您绑定/取消绑定vao,就足够了。 glEnableVertexAttribArray and glDisableVertexAttribArray can be removed 可以删除glEnableVertexAttribArrayglDisableVertexAttribArray
  • use uniform buffer, don't have all those single uniforms alone. 使用统一缓冲区,不要单独拥有所有这些统一的缓冲区。
  • loader.updateVbo() is quite expensive , it creates a FloatBuffer every render and clear the buffer before copying the data. loader.updateVbo()非常昂贵 ,它在每次render时都创建一个FloatBuffer并在复制数据之前清除缓冲区。 You should allocate a float [] or a FloatBuffer just once, reuse it and call simply glBufferSubData , avoiding glBufferData 您应该只分配一次float []FloatBuffer ,重用它,然后简单地调用glBufferSubData ,避免使用glBufferData

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM