Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
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 enumerations  (Read 1239 times)
0 Members and 1 Guest are viewing this topic.
Offline StrideColossus
« Posted 2014-03-24 13:17:20 »

I have a platform-agnostic core engine that is extended by platform-specific 'back-ends' for Android and LWJGL.  One aspect of this design that I can't make up my mind on is mapping of the various enumerations in the core part (e.g. primitive types, texture filters, etc) to the corresponding OpenGL constants in the back-end implementations (e.g. GL_TRIANGLE_STRIP, GL_CLAMP_TO_EDGE, etc).

Here are the approaches I've considered so far:

1. Map enums to constants in each back-end

Each back-end implementation is responsible for mapping the enumerations to the constants.  Easy to do using a switch statement, but laborious and possibly error-prone to implement (temptation to cut-and-paste), particularly irksome for some of the larger sets such as blending functions, also adds slight over-head of constantly having to perform the mapping.

2. Hard-code OpenGL constants in the core engine

Assume that the constants are the same across all OpenGL implementations (Android and LWJGL) and hard-code them in the core engine - Is this assumption valid?

(Could probably minimise the hard-coding in most cases by using just one value and the ordinal() of the enum since most OpenGL constants are contiguous).

3. Dodgy reflection lookup of OpenGL constants

Use some devious reflection logic to lookup the OpenGL constants by name, e.g. take the enumeration name(), prepen GL_ and reflect through the static GL classes to find the matching constant - Works but feels dirty!

So:

Any other approaches I've not thought of?
Any opinion on the best approach?  (I'm inclined to #2 since that seems the least effort / risk)

Cheers for any thoughts.

- stride
Offline Danny02
« Reply #1 - Posted 2014-03-24 13:28:38 »

yes OpenGL constants are constants  Wink
Offline princec

JGO Kernel


Medals: 365
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #2 - Posted 2014-03-24 13:48:23 »

What he means is, they are the same, on all versions of OpenGL, on all platforms. No mapping to do!

Cas Smiley

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline StrideColossus
« Reply #3 - Posted 2014-03-24 14:22:56 »

Cool, assumed they were constant across all implementation but just wanted to check before I go ahead.
Ta
Smiley
Offline gouessej
« Reply #4 - Posted 2014-03-25 14:31:56 »

I have a platform-agnostic core engine that is extended by platform-specific 'back-ends' for Android and LWJGL.
Why do you need to do that? Doesn't LWJGL support Android??

Offline StrideColossus
« Reply #5 - Posted 2014-03-25 15:04:38 »

I have a platform-agnostic core engine that is extended by platform-specific 'back-ends' for Android and LWJGL.
Why do you need to do that? Doesn't LWJGL support Android??

No, or at least not yet AFAIK.

LWJGL nicely wraps up the underlying OpenGL APIs (and provides some other stuff such as display and mouse/keyboard device management).
Android has this stuff as part of it's core API (depending on version ofc) so they're sort of mutually-exclusive.

I believe most (all?) other libraries/engines use the same approach: LWJGL for Linux / Windows / Mac and OpenGL-ES for Android.
Offline gouessej
« Reply #6 - Posted 2014-03-26 14:46:40 »

I believe most (all?) other libraries/engines use the same approach: LWJGL for Linux / Windows / Mac and OpenGL-ES for Android.
OpenGL-ES can be used under GNU Linux too, for example on the Raspberry Pi. The engine backends based on LWJGL work that way because as far as I know it provides no windowing toolkit compatible both with Android and desktop environments which isn't the case of all engine backends and that's why it's possible to use the Raspberry Pi with JMonkeyEngine without making a separate native renderer based on its Android GL backend.

Offline StrideColossus
« Reply #7 - Posted 2014-03-26 15:35:11 »

Quote from: gouessej
OpenGL-ES can be used under GNU Linux too, for example on the Raspberry Pi. The engine backends based on LWJGL work that way because as far as I know it provides no windowing toolkit compatible both with Android and desktop environments which isn't the case of all engine backends and that's why it's possible to use the Raspberry Pi with JMonkeyEngine without making a separate native renderer based on its Android GL backend.

Cool I didn't know that.  Couple of my work colleagues have Raspberry Pi's that they're fiddling with, will have to target that as well.
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.

TehJavaDev (15 views)
2014-08-28 18:26:30

CopyableCougar4 (25 views)
2014-08-22 19:31:30

atombrot (38 views)
2014-08-19 09:29:53

Tekkerue (33 views)
2014-08-16 06:45:27

Tekkerue (32 views)
2014-08-16 06:22:17

Tekkerue (20 views)
2014-08-16 06:20:21

Tekkerue (30 views)
2014-08-16 06:12:11

Rayexar (66 views)
2014-08-11 02:49:23

BurntPizza (43 views)
2014-08-09 21:09:32

BurntPizza (34 views)
2014-08-08 02:01:56
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!