Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [opengl] Why are LWJGL enums as integers?  (Read 8538 times)
0 Members and 1 Guest are viewing this topic.
Offline Spacebeans
« Posted 2014-07-08 19:31:44 »

Not sure if this is the right thread, but why are LWJGL's enumerators, integers? It would have been easier to code them as enumerators, or does JNI not allow Java's enums?

EDIT: Changed the title to 'LWJGL'
Offline Drenius
« Reply #1 - Posted 2014-07-08 19:33:09 »

I think you kinda got the reason.
It would at least complicate it a lot.
Offline Spacebeans
« Reply #2 - Posted 2014-07-08 19:35:01 »

Why not just give the enums a parameter (probably an integer) of what they would represent through the JNI?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline CopyableCougar4
« Reply #3 - Posted 2014-07-08 19:35:39 »

That would require extra steps, when the current system is just as readable.


Either wandering the forum or programming. Most likely the latter Smiley

Offline Drenius
« Reply #4 - Posted 2014-07-08 19:35:52 »

Possible, but not necessary.
Offline The Lion King
« Reply #5 - Posted 2014-07-08 19:36:34 »

in C the gl "enums" have values. To keep LWJGL consistent it makes sense to give them values, though a wrapper from the values to enums could be made relatively easily.

"You have to want it more than you want to breath, then you will be successful"
Offline BurntPizza

« JGO Bitwise Duke »

Medals: 485
Exp: 7 years

« Reply #6 - Posted 2014-07-08 19:39:34 »

Worth pointing out that Enums were not present in Java until 1.5. JNI is older. Lwjgl is older. OGL itself is also older, and not Java.
OGL is also probably designed with older idioms, and in a way to be interfaceable with other languages. That idom is actually pretty common.

EDIT: ah, you changed the title.
Offline pitbuller
« Reply #7 - Posted 2014-07-08 19:47:43 »

If you miss some rare/new extension you can just use raw integer.
Offline relminator
« Reply #8 - Posted 2014-07-11 05:33:27 »

AFAIK, you can't bitwise "|" enums in Java.  That's probably the reason why they used ints in favor of enums.
Offline Riven

« JGO Overlord »

Medals: 1340
Projects: 4
Exp: 16 years

Hand over your head.

« Reply #9 - Posted 2014-07-11 06:42:42 »


enums are just ints to the JVM, and bitwise OR is accessible through EnumSet.of(..., ...). This operation is supposedly just as fast as ORing ints, as the EnumSet is an int too (or a long, for enums with more than 32 values, and finally it falls back to some primitive array)


using enums would create a mess in the API, as every system theoretically supports another subset of each enum in each gl-call.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline basil_

« JGO Bitwise Duke »

Medals: 418
Exp: 13 years

« Reply #10 - Posted 2014-07-11 08:59:59 »


i wouldn't be able to mix-in jocl (opencl) with jwlgl (gl-shared display and another cl-device, what the heck) without making a mess in my api code.

numbers are just numbers whatever context you're in.
Offline princec

« JGO Spiffy Duke »

Medals: 1033
Projects: 3
Exp: 20 years

Eh? Who? What? ... Me?

« Reply #11 - Posted 2014-07-11 10:22:15 »

Having a GLEnum type would actually be at least something of a boon to avoid mixing up ordinary integer arguments with what should be, well, GL enums, however, because of the way GL works - arbitrary extensions adding symbols on an ad-hoc basis at run time - you can't really use Java enums in the way they were intended, and instead you'd have to make a GLEnum class that wasn't actually an enum. Then there'd be the irritating need to extract the int value from that enum from every parameter in every API call. It's probably not worth the effort.

Cas Smiley

Offline SHC
« Reply #12 - Posted 2014-07-11 14:18:57 »

Just take a look at the design of OpenTK. It uses enums for everything. Let's see a simple example of clearing screen in C++ OpenGL.


The same in OpenTK translates to

GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

Does it make OpenGL easy or tough? I'd say it makes confusing because most of the tutorials are in the native C++ code and translating that is confusing.

Can you expect what
a frequently used one while debugging is translated to? It is translated to
but we beginners expect it to be something like GL.VERSION or something.

It's not really useful.

Offline Spasi
« Reply #13 - Posted 2014-07-11 17:30:33 »

One of the improvements in LWJGL 3 is javadoc generation for all bindings. This includes links to enums that an OpenGL function argument supports. Imho, it makes a huge difference in productivity and it's not an issue anymore that GL enums are integers. I've tried to list all core GL enums and plan to keep them up-to-date as new versions are released. I've also included several extension enums, but that's obviously a huge task and requires help from the community. Feel free to submit documentation patches at any time.
Offline SHC
« Reply #14 - Posted 2014-07-11 17:39:24 »

Great work Spasi. Am waiting for the release of LWJGL 3. Any expectations on release date?

Offline Spasi
« Reply #15 - Posted 2014-07-11 18:06:48 »

There will be a usable build for public testing after GLFW 3.1 is released.
Pages: [1]
  ignore  |  Print  

EgonOlsen (76 views)
2018-06-10 19:43:48

EgonOlsen (56 views)
2018-06-10 19:43:44

EgonOlsen (76 views)
2018-06-10 19:43:20

DesertCoockie (256 views)
2018-05-13 18:23:11

nelsongames (156 views)
2018-04-24 18:15:36

nelsongames (155 views)
2018-04-24 18:14:32

ivj94 (896 views)
2018-03-24 14:47:39

ivj94 (157 views)
2018-03-24 14:46:31

ivj94 (809 views)
2018-03-24 14:43:53

Solater (173 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!