Android: Deciding between SurfaceView and OpenGL (GLSurfaceView)
Asked Answered
N

2

21

Is there a way to decide up front based on the expected complexity of a game/app in the planning phase whether to use regular Canvas drawing in a SurfaceView or to go with OpenGL?

I've been playing around with a Canvas and only need 2D movement, and on a fairly new phone I'm getting pretty decent performance with a bunch of primitive objects and a few bitmaps running around the screen on a solid background.

Is it fair to say that if I'm going to be drawing background images and increasing the number of objects being moved and drawn on top of them that I should go straight to OpenGL?

Nanny answered 2/3, 2011 at 15:1 Comment(0)
K
31

All I can say is that it depends on how many sprites you're gonna use. Chris Pruett from Google has also documented this part very well.

Google I/O 2009 and Google I/O 2010.

Below is a picture from one of his slides that are related to your topic: enter image description here

With that knowledge, you should go with OpenGL using the draw_texture extension. Remember to query out the string and check if draw_texture is supported on the actual device.

For further information that are related to game development in general, see this.

Kempf answered 2/3, 2011 at 15:9 Comment(1)
But this picture doesn't show the load on ARM core vs GPU. When you render with OpenGL, you are moving the load to GPU while ARM core is available for other computing tasks. I believe Canvas ends up calling into Skia which mostly uses ARM cycles for rendering. Based on version of Android you are using, some parts of Skia seemed to be hardware accelerated.Sibling
M
11

SurfaceView

A GLSurfaceView is a SurfaceView that you can render into with OpenGL. Choosing between them is simple:

If you're familiar with OpenGL and need what it provides, use a GLSurfaceView. Otherwise, use a SurfaceView. OpenGL is low-level. If you're not already familiar with it, it's an undertaking to learn. If you only need 2D drawing, SurfaceView uses the high-level, reasonably high-performance Canvas. It's very easy to work with.

Unless you have a strong reason to use a GLSurfaceView, you should use a regular SurfaceView. I would suggest that if you don't already know that you need GL, then you probably don't.

OpenGL

OpenGL would be able to handle the rotations and scaling easily.

Honestly, you would probably need to learn a lot of OpenGL to do this, specifically related to the topics of:

Geometry Lighting (or just disabling it) Picking (selecting geometry to draw on it) Pixel Maps Texture Mapping Mipmapping Also, learning OpenGL for this might be overkill, and you would have to be pretty good at it to make it efficient.

Instead, I would recommend using the graphic components of a game library built on top of openGL, such as:

Cocos2d

libgdx

Any of the engines listed here

Source

Difference between SurfaceView and GLSurfaceView in Android

Android: Canvas vs OpenGL

Majuscule answered 6/9, 2013 at 8:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.