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上制作的,我不认为将它们移动到着色器中是个好主意.我知道每次传球都会消耗大部分时间.我知道有一种方法来实例化对象并传递制服并在一次调用中绘制它但我找不到任何描述它的教程,你知道我在哪里可以找到它吗?
尝试将法线和顶点包含在一个数组中,如下所示:
\n\nsqTex.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"));\nRun 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.\nRun Code Online (Sandbox Code Playgroud)\n\n那本书也有这样使用的例子
\n| 归档时间: |
|
| 查看次数: |
13225 次 |
| 最近记录: |