Game Development Reference
In-Depth Information
Can you see what we've done here? We can treat our vertices and all those pointers just like we
treat a texture. We “bind� the vertex pointers via a single call to Vertices.bind() . From this point
on, every Vertices.draw() call will work with those “bound� vertices, just like the draw call will also
use the currently bound texture. Once we are done rendering stuff with that Vertices instance,
we call Vertices.unbind() to disable any vertex attributes that another Vertices instance might
not need. Keeping our OpenGL ES state clean is a good thing. Here's how our present() method
looks now [we moved the glMatrixMode(GL10.GL_MODELVIEW) call to resume() as well]:
@Override
public void present( float deltaTime) {
GL10 gl = glGraphics.getGL();
gl.glClear(GL10. GL_COLOR_BUFFER_BIT );
bobModel.bind();
for ( int i = 0; i < NUM_BOBS ; i++) {
gl.glLoadIdentity();
gl.glTranslatef(bobs[i].x, bobs[i].y, 0);
bobModel.draw(GL10. GL_TRIANGLES , 0, 6);
}
bobModel.unbind();
fpsCounter.logFrame();
}
This effectively calls the glXXXPointer() and glEnableClientState() methods only once per
frame. We thus save nearly 100 Ă— 6 calls to OpenGL ES. That should have a huge impact on
performance, right?
Hero:
12-10 05:16:59.710: DEBUG/FPSCounter(865): fps: 51
12-10 05:17:00.720: DEBUG/FPSCounter(865): fps: 46
12-10 05:17:01.720: DEBUG/FPSCounter(865): fps: 47
12-10 05:17:02.610: DEBUG/dalvikvm(865): GC freed 21815 objects / 524272 bytes in 131ms
12-10 05:17:02.740: DEBUG/FPSCounter(865): fps: 44
12-10 05:17:03.750: DEBUG/FPSCounter(865): fps: 50
Droid:
12-10 05:22:27.519: DEBUG/FPSCounter(2040): fps: 57
12-10 05:22:28.519: DEBUG/FPSCounter(2040): fps: 57
12-10 05:22:29.526: DEBUG/FPSCounter(2040): fps: 57
12-10 05:22:30.526: DEBUG/FPSCounter(2040): fps: 55
Nexus One:
12-10 05:18:31.915: DEBUG/FPSCounter(2509): fps: 56
12-10 05:18:32.935: DEBUG/FPSCounter(2509): fps: 56
12-10 05:18:33.935: DEBUG/FPSCounter(2509): fps: 55
12-10 05:18:34.965: DEBUG/FPSCounter(2509): fps: 54
All three devices are nearly on par now. The Droid performs the best, followed by the Nexus One.
Our little Hero performs great as well. We are up to 50 FPS from 22 FPS in the nonoptimized
case. That's an increase in performance of over 100 percent. We can be proud of ourselves. Our
optimized Bob test is pretty much optimal.
Search WWH ::




Custom Search