Fast polygon drawing with OpenGL ES

Tutorials concerning the OpenGL® ES cross-platform API for full-function 2D and 3D graphics on the Google-Android platform.

Fast polygon drawing with OpenGL ES

Postby Patton » Tue Dec 01, 2009 10:49 am

Hello,

I'm doing a little research which method is the fastest to draw a bunch of polygons on screen. I made a simple print routine to output the framerate in the upper left corner of the screen (1 quad per char). If I only clear the screen, and output the framerate, fps is 58. The trouble is when I draw 50 small polygons at the center of the screen, framerate drops to 4-10, which is unacceptable. Obviously I'm doing something wrong. I've tried several methods: draw vertex arrays using glDrawElements and glDrawArrays, I've tried to use floats and int's (fixed point math) to store coords, framerate is still low. All buffers are preallocated so in the rendering thread I'm only doing the gl. work.

I'm testing this on a emulator, version 1.5.
Patton
Junior Developer
Junior Developer
 
Posts: 23
Joined: Sat Jan 19, 2008 5:52 pm

Top

Postby hardcoras » Tue Dec 01, 2009 5:18 pm

Emulator is a lot slower than real devices. Besides emulator speed is dependent on your computer's CPU.
For e.g. if i run my game (in dev right now) on an older ~2Ghz CPU i get only 5-7fps, on a quad core @2.6Ghz i get about 30-40fps. That's a huge difference.
Performance tips:
- to draw shapes use glDrawArrays in STRIP mode (if you can);
- use VBO's with GL_STATIC_DRAW (i think it would give you a huge performance boost)
- don't use glBindTexture often, if you can use texture atlas (if you don't fit in 1024x1024 use several);
- also with GL 1.1 es you can draw textures directly into color buffer (the fastest method), but (don't know for sure) you will be limited in some ways, like no blending.

Good luck.
hardcoras
Experienced Developer
Experienced Developer
 
Posts: 62
Joined: Sat Nov 14, 2009 2:31 pm
Location: Lithunia

Postby Patton » Tue Dec 01, 2009 7:52 pm

I'm running WinXP on a Quadcore machine, let's say the hardware is not the problem.

Weird, I'm running the same routine now, and I'm getting 30fps while rendering 100 polys. Some background process ran last night, I have no other explanation :) Now I'm gonna tweak that routine a little bit more, and cut down as much gl. calls as I can.

Can you give me an example how to use GL_STATIC_DRAW?

Thanks!

EDIT: And I have another, perhaps noob, question :)
Let's assume that I have a rotating cube translated 0.0f, 0.0f, -8.0f from the camera; it runs nice at 40+fps. When I translate that cube to 0.0f, 0.0f, 0.0f (to create a skybox around the camera), framerate drops to 18. What seems to be the problem?
Patton
Junior Developer
Junior Developer
 
Posts: 23
Joined: Sat Jan 19, 2008 5:52 pm

Postby hardcoras » Tue Dec 01, 2009 11:55 pm

:D sometimes weird things happen to mess you a day :) Next time check your cpu usage and process list :D

Ok back to VBO's:

To create VBO use:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. int[] buffer = new int[1];
  2.  
  3. gl11.glGenBuffers(1, buffer, 0);
  4.  
  5. int VBOID = buffer[0];
  6.  
  7. gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, VBOID);
  8.  
  9. gl11.glBufferData(GL11.GL_ARRAY_BUFFER, buffer.capacity() * 4, buffer, GL11.GL_STATIC_DRAW);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


you can provide different data transfer modes:

GL_STREAM_DRAW when vertices data could be updated between each rendering.
GL_DYNAMIC_DRAW when vertices data could be updated between each frames.
GL_STATIC_DRAW when vertices data are never or almost never updated.

Keep in mind that GL_STATIC_DRAW is expensive mode, but it optimizes data for a fast math calculations.

To draw from VBO use:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, VBOID);
  2.  
  3. gl11.glVertexPointer(3, GL10.GL_FIXED, 0, 0); //Last param is ZERO !!!!
  4.  
  5.  
  6.  
  7. gl11.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertexCount);
  8.  
  9. gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, 0); //unbind buffer
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Note, that VBO requires OGL 1.1 ES, so don't forget a fallback for OGL 1.0 ES.

I hope i explained myself quite clear. If something is unclear just ask.

And what depends your other issue, i'm not a good helper here. I'm an opengl noob also :D
First thing what comes on a mind: maybe you are using bi-linear interpolation for texture magnification filter. But it's just a guess.

Good luck.
hardcoras
Experienced Developer
Experienced Developer
 
Posts: 62
Joined: Sat Nov 14, 2009 2:31 pm
Location: Lithunia

Postby Patton » Wed Dec 02, 2009 12:01 am

I use GL_LINEAR while creating GL_TEXTURE_MIN_FILTER and GL_TEXTURE_MAG_FILTER.
Patton
Junior Developer
Junior Developer
 
Posts: 23
Joined: Sat Jan 19, 2008 5:52 pm

Postby hardcoras » Wed Dec 02, 2009 12:21 am

Hmm... thats strange, its a very simple implementation of skydome to put the camera inside the box. And it should generate quite a lot frames per sec. Maybe you should investigate your code again or check for a background process :D what you know :D

Anyway let us know what was the problem.

P.S.
And don't forget to try my guess about texture magnification. Use gl_nearest filter (GL_TEXTURE_MAG_FILTER, GL_NEAREST). Maybe I'm lucky :D ...... u r NOT! :D
hardcoras
Experienced Developer
Experienced Developer
 
Posts: 62
Joined: Sat Nov 14, 2009 2:31 pm
Location: Lithunia

Top

Postby Patton » Wed Dec 02, 2009 8:30 pm

Tried with GL_NEAREST nothing special happens :)
Patton
Junior Developer
Junior Developer
 
Posts: 23
Joined: Sat Jan 19, 2008 5:52 pm

Postby hardcoras » Wed Dec 02, 2009 11:40 pm

Hmm... that means no help from me. The only thing i can suggest is to disable various opengl states one by one like texture, alpha blending, depth buffer, etc. Maybe you will find the one which messes your frame rate.
Good luck in your searches for the right solution. Maybe someone more qualified will help you.
hardcoras
Experienced Developer
Experienced Developer
 
Posts: 62
Joined: Sat Nov 14, 2009 2:31 pm
Location: Lithunia

Postby zorro » Wed Dec 16, 2009 8:39 am

When the quad/cube is farther from the camera, the drawn pixels count is smaller than when the cube is around the camera (skybox) because the texturing is done on the entire screen. This is a known fill rate problem (on all hardware). So i'm saying that the fps should normally drop, but only by a small amount. The question is why it is dropping by such a big margin?
User avatar
zorro
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Mon Aug 10, 2009 3:11 pm
Location: Romania

Postby Patton » Wed Dec 16, 2009 10:39 am

That makes sense... but we also figured out that simulator rendering sucks in some cases, and skyboxes on a real device shouldn't make any speed problems.
Patton
Junior Developer
Junior Developer
 
Posts: 23
Joined: Sat Jan 19, 2008 5:52 pm

Postby Skywhy » Sun Dec 27, 2009 5:11 pm

In personal experience: DO NOT TRUST WHAT THE EMULATOR TELLS YOU.

No matter what PC you are running, the emulator is SLOWER than the actual device. Also it has the tendency of making things "work" even though they might not work on the actual phone (like HTC Hero and power of two textures).

It's quite common when it comes to mobile phone emulators that the emulator does not run even close to the actual device speed, why? No idea, it's just a known fact in the field. This makes programming games for several different mobile phone hardwares annoying. Like let's say you work for a company that releases games for Nokia devices and Android devices. They have tool chain running and the tool chain compiles the game for all different platforms and then it's just down to testing it on the devices.

Point of this post being: The emulator is not to be trusted. The performance is always better on the phone and the emulator just makes stuff up.

I'm emulating my Android on 8gigs of RAM, two high end GFX cards, and 8 cores churning down ... Still I cannot get to the same FPS I get on the phone. I think iPhone emulator is one of the only emulators that run FASTER or at the same speed as the actual device. All though it has the tendency of running faster on PC than on the actual phone because it takes so good use of PC power.

As said earlier, fastest way to render polygons ins VBO's on Android as far as I know.
Skywhy
Developer
Developer
 
Posts: 35
Joined: Tue Oct 20, 2009 7:55 pm

Top

Return to Android 2D/3D Graphics - OpenGL Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest