GLSurfaceView.Renderer details

The OpenGL code is encapsulated in the Renderer object. Each of its three methods is invoked on a specific condition, which tells us which functionality is appropriate for the method.

Notes

The Renderer is responsible for drawing onto the surface, we need only understand the purpose of each of these three methods to determine the code that best lives in each method.

onSurfaceCreated

Is called when a surface is created. Things that need to be initialized once for each surface live here. For example the shaders are compiled; buffers, and the initial model-view and projection matrices are created. This is the same functionality from the WebGL example that was outside of the drawFrame method.

onSurfaceChanged

Invoked when the size of a surface is changed. This has no analogy in the WebGL world as these size changes are handled for you.

onDrawFrame

Invoked to draw a frame. This will follow the same path as the WebGL drawFrame method. Quantities that change from frame to frame will be recomputed, and the actual drawing happens here.