Hi
It is the good approach but it would be better if you reduce the number of checks.
At first, when it is possible, just check whether you have to use the fixed pipeline or the programmable pipeline. Use the most general interface.
Secondly, a GL instance should never be stored, please have a look at the user guide and the wiki.