Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGl es 2.0 Geometry instancing

i have 170 objects to draw, each is build from 312 vertexes. I have one object and i am drawing it 170 times with diffrent martixes, i have figured out that i dont need to call some functions if i draw them one by one so i call them only at the begining, this gives me about 5fps, i am using non indexed triangles with 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)
}

Is there any way to make it faster under es 2.0 ? i am getting about 23fps on sgx 540, lowering vertex detail to 36 per object does not increase frame rate, there are about 10fps in matrix calculations(scale, multiply, translate, transponse, invert) but they are made on cpu and i dont think that moving them into shaders is good idea. I know that most time is consumed on passing uniforms each time. I know that there is a way to instantiate objects and pass uniforms and draw it in one call but i cant find any tutorial describing it, do you know where i can find it?

like image 326
ZZZ Avatar asked Apr 25 '11 04:04

ZZZ


1 Answers

try to inculde normals and vertices in one array like this:

sqTex.getVertexBuffer().position(sqTex.VERT_OFFSET);
GLES20.glVertexAttribPointer(
                                GLES20.glGetAttribLocation(programTextured, "aPosition"), 3,
                                GLES20.GL_FLOAT, false, 5 * 4, sqTex.getVertexBuffer());
GLES20.glEnableVertexAttribArray(GLES20.glGetAttribLocation(programTextured, "aPosition"));

sqTex.getVertexBuffer().position(sqTex.TEXT_OFFSET);
GLES20.glVertexAttribPointer(
                                GLES20.glGetAttribLocation(programTextured, "aTextureCoord"), 2,
                                GLES20.GL_FLOAT, false, 5 * 4, sqTex.getVertexBuffer());
GLES20.glEnableVertexAttribArray(GLES20.glGetAttribLocation(programTextured, "aTextureCoord"));

In this example i have one array for vertices and tex coords

quot from OpenGL ES 2.0 Programming Guide:

 How to store different attributes of a vertex
We described the two most common ways of storing vertex attributes—
array of structures and structure of arrays. The question to ask is which allocation
method would be the most efficient for OpenGL ES 2.0 hardware
implementations. The answer is array of structures. The reason is that the
attribute data for each vertex can be read in sequential fashion and so will
most likely result in an efficient memory access pattern. A disadvantage of
using array of structures is when an application wants to modify specific
attributes. If a subset of vertex attribute data needs to be modified (e.g., texture
coordinates), this will result in strided updates to the vertex buffer.
When vertex buffer is supplied as a buffer object, the entire vertex attribute
buffer will need to be reloaded. One can avoid this inefficiency by storing
vertex attributes that are dynamic in nature in a separate buffer.

That book also has examples of using in this manner

like image 110
Yuriy Vikulov Avatar answered Oct 28 '22 14:10

Yuriy Vikulov