Imagination PowerVR SDK Blog

Something about the performance using OpenglES 1.x


#1

Hi,everyone.I am a learner  as to Opengl ES.Now I am doing some test about the performace on a PND with POWERVR MBX ,using Wince OS.I am quite puzzled about the  result.

codes like this:

1、rend 1000 triangles using glDrawElements and glColor4f


void Render()
{
     long time = 0;
     int i;
                         
     GLshort vertexArray[500] = {-25,-25,0,   25,-25,0,   0,25,0 };
    GLubyte colorArray[12] = {255,0,0,0,   0,255,0,0,    0,0,255,0};

    GLubyte vertexIdx[3000];
  for (i = 0; i < 1000; i ++)
  {

 vertexIdx[i*3 + 0] = 0;
 vertexIdx[i*3 + 1] = 1;
 vertexIdx[i*3 + 2] = 2;
  }
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
  glLoadIdentity(); 

  glTranslatex(0, 0, FixedFromInt(-10));
time = GetTickCount();

  //Enable the vertices array 
  glEnableClientState(GL_VERTEX_ARRAY);
  glVertexPointer(3, GL_SHORT, 0, vertexArray);
  //3 = XYZ coordinates, GL_SHORT = data type, 0 = 0 stride bytes
   glColor4f(255,0,0,1);
  glDrawElements(GL_TRIANGLES, 3000, GL_UNSIGNED_BYTE, vertexIdx);

  glDisableClientState(GL_VERTEX_ARRAY);
 
  eglSwapBuffers(glesDisplay, glesSurface);
 

  time = GetTickCount() - time;
  PrintDebugInfo("time = %ldn",time);
}

the result is as follows:

time = 282
time = 393
time = 392
time = 392
time = 392
time = 392
time = 393
time = 392
time = 393
time = 392
time = 392
time = 393

 

2、rend 1000 triangles using glDrawArrays and glColor4f


void Render()
{
     long time = 0;
     int i;
                         
     GLshort vertexArray[9000] = {-25,-25,0,   25,-25,0,   0,25,0 };
    GLubyte colorArray[12] = {255,0,0,0,   0,255,0,0,    0,0,255,0};
  for (i = 0; i < 1000; i ++)
  {
 vertexArray[9*i + 0] = -25;
 vertexArray[9*i + 1] = -25;
 vertexArray[9*i + 2] = 0;

 vertexArray[9*i + 3] = 25;
 vertexArray[9*i + 4] = -25;
 vertexArray[9*i + 5] = 0;
 vertexArray[9*i + 6] = 0;
 vertexArray[9*i + 7] = 25;
 vertexArray[9*i + 8] = 0;
  }
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
  glLoadIdentity(); 

  glTranslatex(0, 0, FixedFromInt(-10));
time = GetTickCount();

  //Enable the vertices array 
  glEnableClientState(GL_VERTEX_ARRAY);
  glVertexPointer(3, GL_SHORT, 0, vertexArray);
  //3 = XYZ coordinates, GL_SHORT = data type, 0 = 0 stride bytes
  glColor4f(255,0,0,1);
  glDrawArrays(GL_TRIANGLES, 0, 3000);

  glDisableClientState(GL_VERTEX_ARRAY);
 
  eglSwapBuffers(glesDisplay, glesSurface);
 

  time = GetTickCount() - time;
  PrintDebugInfo("time = %ldn",time);
}

the result is :

time = 79
time = 379
time = 376
time = 380
time = 334
time = 379
time = 378
time = 379
time = 379
time = 379
time = 377

 

3。rend 1000 triangles using glDrawElements but without glColor4f


void Render()
{
     long time = 0;
     int i;
                         
     GLshort vertexArray[500] = {-25,-25,0,   25,-25,0,   0,25,0 };
    GLubyte colorArray[12] = {255,0,0,0,   0,255,0,0,    0,0,255,0};

    GLubyte vertexIdx[3000];
  for (i = 0; i < 1000; i ++)
  {

 vertexIdx[i*3 + 0] = 0;
 vertexIdx[i*3 + 1] = 1;
 vertexIdx[i*3 + 2] = 2;
  }
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
  glLoadIdentity(); 

  glTranslatex(0, 0, FixedFromInt(-10));
time = GetTickCount();

  //Enable the vertices array 
  glEnableClientState(GL_VERTEX_ARRAY);
  glVertexPointer(3, GL_SHORT, 0, vertexArray);
  //3 = XYZ coordinates, GL_SHORT = data type, 0 = 0 stride bytes
  // glColor4f(255,0,0,1);
  glDrawElements(GL_TRIANGLES, 3000, GL_UNSIGNED_BYTE, vertexIdx);

  glDisableClientState(GL_VERTEX_ARRAY);
 
  eglSwapBuffers(glesDisplay, glesSurface);
 

  time = GetTickCount() - time;
  PrintDebugInfo("time = %ldn",time);
}

the result is :


time = 349
time = 483
time = 481
time = 482
time = 481
time = 482
time = 481
time = 481
time = 483
time = 484

 

so,I can't  understand the results.

 

First, comparing code 1 and code 2, I find that the performance of the code using glDrawArrays is a little better than glDrawElements  .While,theoretically speaking,it seems using  glDrawElements  is better.right?

 

Second, comparing code 1 and code 3, why the performance of the code calling glColor4f explicitly is much better than using the default color?

 

Third,rending 1000 triangles takes about 400 microseconds.This result is  quiet terrible,though I don't know how long it should take to rend.Is there any serious problem in my codes?