GL11,GL12... Noob question

Started by lagz85, February 15, 2010, 09:54:46

Previous topic - Next topic

lagz85

I've been recently been porting my OpenGL to LWJGL from JOGL. I am making OpenGL calls using the static classes GL11,GL12,GL13... etc. One thing that I have found slightly annoying with LWJGL is how the functions are distributed throughout these classes. If you don't know exactly which version of OpenGL first introduced a function/constant then you have to search through all of the GLxx classes to find it.

In JOGL they use objects corresponding to versions of OpenGL, where you can call all commands/functions introduced up to version X on an object corresponding to that version, hence avoiding the need to search multiple classes.

Admittedly this is a very minor inconvenience, but why doesn't GL20, for example, include all methods and constants that are in the GL1x classes? Then you could just decide which version of OpenGL to target and use the corresponding static class everywhere throughout your application, rather than having to go hunting around the different classes. The only reason I can think of is possibly distribution size?

Alternatively it is possible that I am doing things wrong and that there is a "better" way to make OpenGL calls in LWJGL. If so please let me know!

Thanks

princec

Hmm, once upon a time, GL14 for example used to extend GL11. I'm not sure why it doesn't any more, as it is logically correct. I think Elias may have changed that for some reason - if I can get ahold of him I'll ask him why it's no longer the case.

Cas :)

lagz85

That approach would seem to make logical sense to me. Still, if it was previous there and was explicitly removed then I guess there was a good reason! Let me know if you find out :) .

spasi

Tbh I much more prefer the way it is now. Except the distribution size issue, inheritance of static functionality is simply unnatural in Java. In fact, my IDE would not even auto-complete GL11 stuff if I used GL13 and that's how it should be. Yes, it may be an inconvenience, but it's a very very minor one and it actually forces you to think what you're doing (in OpenGL terms). Imagine having the functionality of all extensions in the same class, that would be convenient but also chaotic. It even gets dangerous with the newer OpenGL versions as we've seen recently, you really need to be careful and code around different paths when you deal with profiles and forward compatibility, etc.

Anyway, the current structure helps a lot when you want to know what pieces of functionality were introduced in what version. I think the real problem with what lagz85 is suggesting is exactly the opposite: People don't really care about old functionality and old OpenGL versions, they expect everything to be supported and it is in fact supported on basically every OpenGL driver out there. So my suggestion is this: Instead of extending static functionality, we should actually merge it. If you think about it, this is what we did with GL11, there never was a GL10 because it was never needed. I believe we can safely merge GL11 through GL13 (or GL14? or GL15? we'll have to do some research) and leave the rest as is (the new GL13 would be an empty class extending the new core class, so we don't break API compatibility).

princec

I think a big refactor of that nature might be best saved for LWJGL3.0. We could probably have a good think about the multiple contexts thing as well, and other wotsits like passing Strings to shaders and getting &ints back out of glGet*/Gen* functions and so on.

Cas :)

Fool Running

For me, it doesn't really make much difference either way. I'm just statically importing the GL classes I need for each class so having the GL classes inherit wouldn't change my code much and keeping them the same doesn't bother me at all.

EDIT: But I agree it would be nice to get passing strings/single ints easier as princec suggested.
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D