Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (517)
Games in Android Showcase (123)
games submitted by our members
Games in WIP (578)
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 1796 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.

CopyableCougar4

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

Github: http://github.com/CopyableCougar4
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
« 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
« League of Dukes »

JGO Overlord


Medals: 823
Projects: 4
Exp: 16 years


Hand over your head.


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

offtopic:

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)



ontopic:

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_
« Reply #10 - Posted 2014-07-11 08:59:59 »

+1

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 Kernel


Medals: 409
Projects: 3
Exp: 16 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.

1  
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

The same in OpenTK translates to

1  
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
GL_VERSION
a frequently used one while debugging is translated to? It is translated to
StringName.Version
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  
 
 

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

DarkCart (16 views)
2014-10-31 21:44:48

DarkCart (21 views)
2014-10-31 21:43:57

TehJavaDev (40 views)
2014-10-27 03:28:38

TehJavaDev (31 views)
2014-10-27 03:27:51

DarkCart (44 views)
2014-10-26 19:37:11

Luminem (27 views)
2014-10-26 10:17:50

Luminem (30 views)
2014-10-26 10:14:04

theagentd (36 views)
2014-10-25 15:46:29

Longarmx (64 views)
2014-10-17 03:59:02

Norakomi (62 views)
2014-10-16 15:22:06
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org 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‑gaming.org
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!