我正在使用iPhone ES 1.1为OpenGL开发一个游戏。在这个游戏中,我有血液粒子,当他们被拍摄时从人物身上发射出来,所以在任何时候屏幕上都可以有1000+的血液粒子。问题是,当我有超过500个粒子要渲染时,游戏的帧速率会大幅下降。
目前,每个粒子使用glDrawArrays(..),呈现自己,我知道这是减速的原因。所有的粒子都有相同的纹理图谱。
那么,减少吸收许多粒子的速度的最佳选择是什么呢?以下是我发现的选择:
把所有的血液粒子聚集在一起,用一个单一的
。
这是每个粒子自己呈现出来的。这是我最初的粒子渲染方法,它导致游戏在500+粒子被渲染后,帧速率显著下降。
// original method: each particle renders itself.
// slow when many particles must be rendered
[[AtlasLibrary sharedAtlasLibrary] ensureContainingTextureAtlasIsBoundInOpenGLES:self.containingAtlasKey];
glPushMatrix();
// translate
glTranslatef(translation.x, translation.y, translation.z);
// rotate
glRotatef(rotation.x, 1, 0, 0);
glRotatef(rotation.y, 0, 1, 0);
glRotatef(rotation.z, 0, 0, 1);
// scale
glScalef(scale.x, scale.y, scale.z);
// alpha
glColor4f(1.0, 1.0, 1.0, alpha);
// load vertices
glVertexPointer(2, GL_FLOAT, 0, texturedQuad.vertices);
glEnableClientState(GL_VERTEX_ARRAY);
// load uv coordinates for texture
glTexCoordPointer(2, GL_FLOAT, 0, texturedQuad.textureCoords);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
// render
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glPopMatrix();然后,我使用方法1,但粒子不能有独特的旋转,规模,或阿尔法使用这种方法(据我所知)。
// this is method 1: group all particles and call glDrawArrays(..) once
// declare vertex and uv-coordinate arrays
int numParticles = 2000;
CGFloat *vertices = (CGFloat *) malloc(2 * 6 * numParticles * sizeof(CGFloat));
CGFloat *uvCoordinates = (CGFloat *) malloc (2 * 6 * numParticles * sizeof(CGFloat));
...build vertex arrays based on particle vertices and uv-coordinates.
...this part works fine.
// get ready to render the particles
glPushMatrix();
glLoadIdentity();
// if the particles' texture atlas is not already bound in OpenGL ES, then bind it
[[AtlasLibrary sharedAtlasLibrary] ensureContainingTextureAtlasIsBoundInOpenGLES:((Particle *)[particles objectAtIndex:0]).containingAtlasKey];
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, vertices);
glTexCoordPointer(2, GL_FLOAT, 0, uvCoordinates);
// render
glDrawArrays(GL_TRIANGLES, 0, vertexIndex);
glPopMatrix();我将重申我的问题:
如何在没有帧速率急剧下降的情况下呈现1000+粒子,并且每个粒子仍然具有独特的旋转、α和尺度?
任何建设性的建议都会很有帮助,我们会非常感激的!
谢谢!
发布于 2011-09-15 19:47:44
使用大约1-10个纹理,每个纹理由透明背景上的200个红色血点组成,然后每一个画3到10次。那你就有成千上万的点了。你把所有的图像都画成一个球形的图案,等等--层层爆炸。
当你玩游戏时,你不能总是和现实保持1比1的对应。仔细看看一些运行在旧Xbox或iPad等上的游戏--你需要做一些快捷键--当它们完成时,它们通常看起来很棒。
https://stackoverflow.com/questions/7435123
复制相似问题