How to handle different versions of OpenGL in library

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to handle different versions of OpenGL in library

sarevok
Hello,

I want to write crossplatform library which will be compatible with JOGL2 and I stuck in one place.

I dont know how to handle different versions of OpenGL, including GLES ones...

Just look at my code:

public class MySimpleLib {
        private GL gl;

        public MySimpleLib(GL gl) {
                this.gl = gl;
       }

        public void setModelMatrixMode() {
                if (GLProfile.getDefault().isGL2())
                        gl.glMatrixMode(GL2.GL_MODELVIEW); << The method glMatrixMode(int) is undefined for the type GL
                if (GLProfile.getDefault().isGL3())
                        gl.glMatrixMode(GL3.GL_MODELVIEW); << The method glMatrixMode(int) is undefined for the type GL
                if (GLProfile.getDefault().isGLES1())
                        gl.glMatrixMode(GLES1.GL_MODELVIEW); << The method glMatrixMode(int) is undefined for the type GL
        }
}

So I can cast it to gl to this.gl to different GL profiles ((GL2) gl).glMatrixMode(GL2.GL_MODELVIEW); but is that good aproach? It seems not for me...

So whats the correct way to handle different GL versions here, depending from choosen GLProfile? Any advices?
Reply | Threaded
Open this post in threaded view
|

Re: How to handle different versions of OpenGL in library

gouessej
Administrator
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.
Julien Gouesse | Personal blog | Website