Difference between SurfaceView and GLSurfaceView in Android
Asked Answered
U

3

21

Can anyone tell me what the basic difference is between SurfaceView and GLSurfaceView? When should I use SurfaceView, and when should I use GLSurfaceView?

I read some already answered questions on Stack Overflow, but they did not satisfy my queries.

Any help would be appreciated.

Uralian answered 14/6, 2012 at 8:59 Comment(1)
take a look at this link : pierrchen.blogspot.jp/2014/04/…Byre
L
37

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.

Leeuwenhoek answered 14/6, 2012 at 10:6 Comment(4)
Thank you for answer. I have one question...for Camera, which one would be better?Uralian
@Uralian You're going to have to be a lot more specific. Although taking a stab at what you mean: if you want to show a preview of live images from the camera, you only need a SurfaceView: developer.android.com/guide/topics/media/…Leeuwenhoek
Note that it's possible to use OpenGL with a SurfaceView. It's just less complicated to do it with a GLSurfaceView. See the Graphics architecture document.Reconcilable
This is a pretty bad answer. check @pierrotlefou's insteadKirkman
B
15

GLSurfaceView is the primary building block for 3D applications as View is for 2D applications. It is widely used not only in 3D games but also multimedia applications such as camera to create special preview affect.

GLSurfaceView extends SurfaceView and additionally owns a render thread and a render object set by the client. The render thread keeps running , continuously or on-demand, and delegates to the render object to draw frame using OpenGL API. For both SurfaceView and GLSurfaceView, rendering is performing in a separate thread other than main thread. The difference is with SurfaceView the rendering thread is created by client while with GLSurfaceView it is created by the system. What's more, GLSurfaceView will internally handle the synchronization between main thread and rendering thread.

For more, check out this and this

Byre answered 10/4, 2014 at 13:31 Comment(0)
M
6

SurfaceView

AFAIK Canvas is Simple to implement and effective in 2D drawing but 3D drawing are not supported on it

GLSurfaceView

If you want to design some 3D Game then you shold go with GLSurfaceView and OGLES

Whats my experience is if you just want to do 2D processing then select Canvas because its easier to implement and effective compare to GLSurfaceView.

Methedrine answered 14/6, 2012 at 9:10 Comment(2)
In case of of 2D processing, why Canvas is effective?Uralian
Note that it's possible to use OpenGL with a SurfaceView. It's just less complicated to do it with a GLSurfaceView. See the Graphics architecture document.Reconcilable

© 2022 - 2024 — McMap. All rights reserved.