Alex Rivera | Logout

Converting from GLSurfaceView to TextureView (via GLTextureView)

Asked 2012-08-21T19:08:05.490
24

When Android 4.0 (Ice Cream Sandwich) was released, a new view was introduced into the sdk. This View is the TextureView. In the documentation, it says that the TextureView can be used to display content for an OpenGL scene.

When you look up how to do this, you'll find this link to one example.

https://groups.google.com/forum/?fromgroups=#!topic/android-developers/U5RXFGpAHPE

However I wanted to just replace GLSurfaceView with TextureView, and keep the rest of my code the same, and just receive the advantages of the TextureView.

Edit
Report

1 Answer

14

Brilliant!

A minor addition to Mr. Goodale's brilliant answer:

The 4.1.1 version of GLSurfaceView seems to have been modified to avoid rendering on a zero-width/height surface, I think. And there doesn't seem to be a gratuitous onSurfaceTextureChanged notification immediately following onSurfaceTextureAvailable.

If you start with the 4.1.1 sources, onSurfaceTextureAvailable needs to read as follows:

public void onSurfaceTextureAvailable(SurfaceTexture surface, int width,
        int height) 
{
    this.surfaceCreated(surface);
    this.surfaceChanged(surface, 0,width,height);
}

Other than that, I was up and running in about five minutes flat! Thanks.

answered 2012-08-23T01:04:01.653

Your Answer