OpenGl es 2.0 Geometry实例化

ZZZ*_*ZZZ 6 opengl-es opengl-es-2.0

我有170个对象要绘制,每个都是从312个顶点构建的.我有一个对象,我用不同的martixes绘制了170次,我已经发现我不需要调用一些函数,如果我逐个绘制它们,所以我只在开始时调用它们,这给了我大约5fps,我我使用非索引三角形与drawArrays.

if(!started)
{
    glUseProgram( __programObject );
    glEnableVertexAttribArray(attPosition);
    glVertexAttribPointer(attPosition, 3, GL_FLOAT, GL_FALSE, 3*sizeof(float), vVertices);//3*sizeof(float)
    glEnableVertexAttribArray(attNormals);
    glVertexAttribPointer(attNormals, 3, GL_FLOAT, GL_FALSE, 3*sizeof(float), vNormals);//3*sizeof(float)
}
Run Code Online (Sandbox Code Playgroud)

有没有办法让它在es 2.0下更快?我在sgx 540上得到大约23fps,将每个对象的顶点细节降低到36不会增加帧速率,矩阵计算中有大约10fps(缩放,乘法,平移,转换,反转)但它们是在cpu上制作的,我不认为将它们移动到着色器中是个好主意.我知道每次传球都会消耗大部分时间.我知道有一种方法来实例化对象并传递制服并在一次调用中绘制它但我找不到任何描述它的教程,你知道我在哪里可以找到它吗?

Yur*_*lov 3

尝试将法线和顶点包含在一个数组中,如下所示:

\n\n
sqTex.getVertexBuffer().position(sqTex.VERT_OFFSET);\nGLES20.glVertexAttribPointer(\n                                GLES20.glGetAttribLocation(programTextured, "aPosition"), 3,\n                                GLES20.GL_FLOAT, false, 5 * 4, sqTex.getVertexBuffer());\nGLES20.glEnableVertexAttribArray(GLES20.glGetAttribLocation(programTextured, "aPosition"));\n\nsqTex.getVertexBuffer().position(sqTex.TEXT_OFFSET);\nGLES20.glVertexAttribPointer(\n                                GLES20.glGetAttribLocation(programTextured, "aTextureCoord"), 2,\n                                GLES20.GL_FLOAT, false, 5 * 4, sqTex.getVertexBuffer());\nGLES20.glEnableVertexAttribArray(GLES20.glGetAttribLocation(programTextured, "aTextureCoord"));\n
Run Code Online (Sandbox Code Playgroud)\n\n

在这个例子中,我有一个顶点和纹理坐标数组

\n\n

引自 OpenGL ES 2.0 编程指南:

\n\n
 How to store different attributes of a vertex\nWe described the two most common ways of storing vertex attributes\xe2\x80\x94\narray of structures and structure of arrays. The question to ask is which allocation\nmethod would be the most efficient for OpenGL ES 2.0 hardware\nimplementations. The answer is array of structures. The reason is that the\nattribute data for each vertex can be read in sequential fashion and so will\nmost likely result in an efficient memory access pattern. A disadvantage of\nusing array of structures is when an application wants to modify specific\nattributes. If a subset of vertex attribute data needs to be modified (e.g., texture\ncoordinates), this will result in strided updates to the vertex buffer.\nWhen vertex buffer is supplied as a buffer object, the entire vertex attribute\nbuffer will need to be reloaded. One can avoid this inefficiency by storing\nvertex attributes that are dynamic in nature in a separate buffer.\n
Run Code Online (Sandbox Code Playgroud)\n\n

那本书也有这样使用的例子

\n

  • 向量的不同数组的问题是 GPU 需要为每个顶点从一个内存源跳转到另一个内存源。这是额外的操作。恕我直言 (2认同)
  • 线性化数据以获得最佳缓存性能并不依赖于硬件。每当一组指令在多个数据源上运行时,为了缓存局部性,建议交错该数据。即使对于 CPU,这也是一个很好的建议。 (2认同)