Difference between SurfaceView and GLSurfaceView i

2019-02-06 17:08发布

问题:

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.

回答1:

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.



回答2:

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



回答3:

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.