libsgl: glesTex: Rework mipmap generation code

Mipmap generation code was never fully tested and it turned out to be
completely broken. Copied from Android software GL implementation it was
subject to severe bitrot and finally after several serious modifications
of texture handling it stopped working at all, leading to complete
garbage being generated.

This patch completely reimplements this code to make it work correctly
and meet some coding style standards. In addition, semantics of mipmap
generation are slightly changed to comply with the OpenGL ES 1.1
standard, which states that after modifying any mipmap level (as opposed
to just level 0 in current code), including glTexSubImage() (as oposed to
just glTexImage() in current code) all subsequent levels are
regenerated.

Signed-off-by: Tomasz Figa <tomasz.figa@gmail.com>