This question is part-technical, part-meta, part-subjective and very specific:
I'm an indie game dev working on android, and for the past 6 months I've struggled and finally succeeded in making my own 3D game app for android. So I thought I'd hop on SO and help out others struggling with android and openGL-ES
However, the vast majority of questions relate to extending GLSurfaceView
. I made my whole app without extending GLSurfaceView
(and it runs fine). I can't see any reason at all to extend GLSurfaceView
for the majority of questions I come across.
Worse, the android documentation implies that you ought to, but gives no detailed explaination of why or what the pros/cons are vs not extending and doing everything through implementing your own GLSurfaceView.Renderer
as I did
Still, the sheer volume of questions where the problem is purely to do with extending GLSurfaceView
is making me wonder whether actually there is some really good reason for doing it that way vs the way I've been doing it (and suggesting in my answers to others to do).
So, is there something I'm missing? Should I stop answering questions in the meantime?
Best Answer
I have a very minimal extension for my
GLSurfaceView
, and most of the wisdom belongs to my implementation ofGLSurfaceView.Renderer
. I had the following three reasons to use a wrapper forGLSurfaceView
:The base
GLSurfaceView
provides no way to get theRenderer
instance back. I have multiple surfaces, and when I receive a UI event for one of them, I want to pass the command to the corresponding renderer. So, I overridesetRenderer
and keep the reference in my extended class.GLSurfaceView.Renderer
does not receive notifications foronDetachedFromWindow()
orsurfaceDestroyed()
. This caused some problems to my implementation. My extension ofGLSurfaceView
overrides these methods and lets the mRenderer know. It's possible because of ยง1.Some methods are only wrapped to add
try { super.
whatever; } catch() { log(
whatever) }
. For example,queueEvent()
will throw if Renderer is not set; but for me, it's OK to simply ignore such timeline inconsistencies.