最快的方式提请精灵在Android上opengles 2.0 [英] Fastest way to draw sprites in opengles 2.0 on android

查看:146
本文介绍了最快的方式提请精灵在Android上opengles 2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

于是我试着去弄清楚如何绘制一个纹理的四边形很多次。我的问题是,由于这些都是创建和删除,他们每个人都有一个独特的位置和旋转。林不知道一个VBO是因为我听说过修改的缓冲区最好的解决办法是在Android上非常慢,似乎我需要创建一个新的每一帧,因为不同的四边形可能会消失随机(与敌人发生冲突)。如果我简单地做一个平局呼吁每一个我得到20fps的100家左右,这是不可用的。什么建议?

So Im trying to figure out how to draw a single textured quad many times. My issue is that since these are create and deleted and every one of them has a unique position and rotation. Im not sure a vbo is the best solution as I've heard modifying buffers is extremely slow on android and it seems I would need to create a new one each frame since different quads might disappear randomly (collide with an enemy). If I simply do a draw call for each one I get 20fps around 100, which is unusable. any advice?

编辑:我试图创造一个bullethell,但搞清楚如何绘制500+事情是伤害我的头

I'm trying to create a bullethell, but figuring out how to draw 500+ things is hurting my head.

推荐答案

我觉得你是一个粒子系统后。类似的问题在这里:在OpenGL ES 1.1 很快吸引了许多质感的颗粒

I think you're after a particle system. A similar question is here: Drawing many textured particles quickly in OpenGL ES 1.1.

使用点精灵是相当便宜的,但你必须做一些额外的工作,在片段着色器,我不知道,如果GLES2支持 gl_PointSize 如果你需要不同大小的颗粒。 gl_PointSize对应于世界空间的大小

Using point sprites is quite cheap, but you have to do extra work in the fragment shader and I'm not sure if GLES2 supports gl_PointSize if you need different sized particles. gl_PointSize Corresponding to World Space Size

我去到粒子系统存储在一个双缓冲结构的位置,然后绘制使用单个绘图调用和四边形的静态数组。 是相关的,但我会形容它更为这里有点...

My go-to particle system is storing positions in a double buffered texture, then draw using a single draw call and a static array of quads. This is related but I'll describe it a bit more here...

  1. 创建纹理(浮点如果可以的话,但是这可能会限制支持的设备)。每个像素包含的粒子的位置,也许转动信息。
  2. [EDITED如果你需要,你要每一帧改变纹理的值的粒子动画。为了使快速,让GPU做在一个着色器。使用FBO,绘制一个全屏的多边形,并在片段着色器更新值。问题是你不能读取和写入相同的纹理(或不应该)。通常的做法是将翻一番通过创建第二个渲染,而你从第一个,那么它们之间的乒乓缓冲区读取纹理。
  3. 创建一个VBO绘制三角形。的位置都是相同的,并填充在-1到1四边形。然而使纹理坐标每个四边形解决正确的像素在上面的纹理。
  4. 绘制VBO,结合你的位置质感。在顶点着色器,阅读给定的顶点纹理坐标的位置。缩放-1到1顶点位置到合适的大小,应聘的职位和任何旋转。使用原-1到1的位置作为纹理坐标传递到片段着色器以添加任何常规颜色纹理。

  1. Create a texture (floating point if you can, but this may limit the supported devices). Each pixel holds the particle position and maybe rotation information.
  2. If you need to animate the particles you want to change the values in the texture each frame. To make it fast, get the GPU to do it in a shader. Using an FBO, draw a fullscreen polygon and update the values in the fragment shader. The problem is you can't read and write to the same texture (or shouldn't). The common approach is to double buffer the texture by creating a second one to render to while you read from the first, then ping-pong between them.
  3. Create a VBO for drawing triangles. The positions are all the same, filling a -1 to 1 quad. However make texture coordinates for each quad address the correct pixel in the above texture.
  4. Draw the VBO, binding your positions texture. In the vertex shader, read the position given the vertex texture coordinate. Scale the -1 to 1 vertex positions to the right size, apply the position and any rotation. Use the original -1 to 1 position as the texture coordinate to pass to the fragment shader to add any regular colour textures.

如果你曾经有一个GLSL版本 gl_Vertex ,我很喜欢在顶点着色器生成这些坐标,节省了存储不必要的琐碎数据只是绘制简单对象。 例如,这

If you ever have a GLSL version with gl_Vertex, I quite like generating these coordinates in the vertex shader, saving storing unnecessarily trivial data just to draw simple objects. This for example.

这篇关于最快的方式提请精灵在Android上opengles 2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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