Reputation: 356
In configuration of libgdx, there is a useGL30 boolean. As I've never worked with OpenGL I'm not sure what that method does. And btw. should i set it to false or true? Which is better for my game?
Upvotes: 5
Views: 3810
Reputation: 8123
The other answer is very extensive but unfortunately not correct at some parts. First to answer your questions:
You want to set the config.useGL30
member to false
, regardless the platform (desktop or android).
You should not set the config.useGL30 member to true
, unless you have an actual need to use OpenGL ES 3.0 functionality. In which case (if you need to use GLES3 functionality) you will need to take care of compatibility, even at places where you don't need that functionality.
Simply setting config.useGL30
to true
will not be better for your game. In fact, it might introduce issues.
To clarify a few things:
OpenGL
and OpenGL ES
are two different things, the versions can not be compared. If you really want to compare the versions, then OpenGL ES 2.0 can be compared with (is a subset of) OpenGL 4.3 and OpenGL ES 3.0 can be compared with (is a subset of) OpenGL 4.5.
In that respect the naming useGL30
, Gdx.gl20
, Gdx.gl30
can be considered misleading, because the 20
and 30
in that naming is actually referring to the OpenGLES version and not the OpenGL version. A better naming would be perhaps useGLES30
, Gdx.gles20
and Gdx.gles30
.
OpenGL ES 3.0 is not fully backwards compatible with OpenGL ES 2.0, which is also true for desktop (on which OpenGL ES is emulated through OpenGL). Even though the API itself is compatible, this isn't the case for the shader language used. So, if you set config.useGL30
to true
then chances are quite big that your shaders won't work anymore as you'd expect. This includes the shaders that come with libgdx (SpriteBatch, ShapeRenderer, ModelBatch, etc).
So, it doesn't make sense to set the useGL30
member only to true for your desktop project, especially if you aren't making other adjustments to your code as well.
Upvotes: 7
Reputation: 28258
From the docs of LwjglApplicationConfiguration:
whether to attempt use OpenGL ES 3.0.
LibGDX uses a lot of features to maintain compatibility across multiple platforms. If you don't enable the setting, you can't use OpenGL 3 where it's possible (IIRC). Basically what the method does is enable the use of OpenGL ES 3. (I think all newer computers support OpenGL 3, the problem lies in Android where it was added in API 18 and it depends on custom implementations by manufacturers. I'll get back to that later)
It's worth checking out this answer even though the question is slightly different, it explains how LibGDX works:
LibGDX is running OpenGL ES2.0, which is ancient by modern standards. It has to for compatibility reasons: Most mobile devices do not support any higher standard.
OpenGL ES2.0 is similar to OpenGL 2.0, but with some changes, and was released in 2007. LWJGL, on the other hand, supports the latest and greatest (OpenGL 4.5) and everything below. It also has OpenCL (GPU processing), OpenAL (3D audio) and Vulkan (Magic drivers and stuff) bindings.
OpenGL ES 3 is the newest version available on Android (and I assume iOS devices as well), while OpenGL 4.6 is the newest available on desktop devices (where there is a graphics card that supports it).
One thing that's worth noting is that OpenGL ES 3 is also fairly old (2012) but it's backwards compatible with OpenGL ES 2.
Not knowing much about this particular part, this is more or less an educated guess: when you write code using LibGDX you make calls to Gdx.gl
(or Gdx.gl20
or Gdx.gl30
). LibGDX then makes calls to the appropriate API (OpenGL ES on Android and iOS, LWJGL/JOGL on desktop, etc)
AFAIK, using useGl30
enables the use of OpenGL ES 3. The main reason you shouldn't use OpenGL 3 is Android. OpenGL 3 is added in API 18, and:
Caution: Support of the OpenGL ES 3.0 API on a device requires an implementation of this graphics pipeline provided by the device manufacturer. A device running Android 4.3 or higher may not support the OpenGL ES 3.0 API
But that isn't a problem for you since you (from what I understood) aren't targeting Android. So using the newest available is a good idea.
Meaning you could be using Open GL 4.6. But this would mean you would have to call the LWJGL bindings directly.
The problem is that you can only do that for specific things, LibGDX itself will still use 2.0/3.0.
With all that in mind, I'm going to answer the two last questions:
And btw. should i set it to false or true?
You should set it to true
if you're not targeting Android. There will be problems as not all devices running API 18+ necessarily supports it (link to that is earlier in this answer). If you're running desktop you should target the newest one you can find, as the newer versions also add new features you may need. Unless there are specific things in OpenGL 4+ (4+ is not a typo) you should stick to the framework itself and not make calls directly to LWJGL (LibGDX on desktop is built on top of LWJGL).
You can make a game with OpenGL 2.0 alone. OpenGL 1 and 2 are not compatible, but 2 and 3 are. Meaning if you decide you want to use OpenGL 3, you can still make calls to OpenGL 2 (AFAIK, from experience with LWJGL, the later versions rely on each other to work properly. If you use 4 you still need to make calls to 2 and 3 to get the appropriate API's. I may be wrong on that though)
Which is better for my game?
This is a matter of opinion, but there's one important thing you have to remember: If you use OpenGL 3, you can still use OpenGL 2. At that there's no choice between which you pick. If you enable OpenGL 3, you can use 2 and 3 because openGL ES 3 is backwards compatible with OpenGL ES 2.
Something I haven't mentioned yet is using the different versions.
Gdx.gl
, by default, uses OpenGL 2. Meaning if you want to access the 3.0 features, you have to call Gdx.gl30.*
to the relevant methods. As it is backwards compatible, 2.0 features (I think) have to be called using Gdx.gl20.*
as they aren't directly present in 3.0 (as a result of backwards compatibility, if you have 3.0 you also have 2.0)
I used LWJGL a while ago, and to call some of the fields that were added in earlier versions (but not removed) you had to call the relevant version. If you were using 4.6, you'd still need to call 2.0 to clear color. But this was a while ago, so I may remember incorrectly
So to sum up:
useGl30
enables the use of 3.0 where available.Upvotes: 2