Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I support OpenGL ES GL10, GL11, and GL20 in Libgdx?

I am writing a 3d game that is using GL10, but I'd like the application to support GL11 or GL20 if available. What is the best design for supporting all 3? Or is this a fool's errand and I should just focus on supporting one version?

My current idea is to split my render() function into renderGL10, renderGL11, renderGL20 and call the appropriate render function based on the available GL instance. Inside each render function is the proper way to render for the GL version; there will likely be overlap for GL10 and GL11. Is this an appropriate way to handle my problem or is there a better way?

public render(){
  if (Gdx.graphics.isGL20Available()){
    renderGL20();
  } else if (Gdx.graphics.isGL11Available()){
    renderGL11();
  } else { 
    renderGL10();
  }
}

EDIT: Solution: If gl1.x is available, gl10 is also available (and Gdx.gl10 is not null). So, my render code should generally be structured as follows:

public render(){
  // Use Gdx.gl for any gl calls common to all versions
  if (Gdx.graphics.isGL20Available()){
    // Use Gdx.GL20 for all gl calls
  } else {
    if (Gdx.graphics.isGL11Available()){
      // Use Gdx.gl11 for any gl11 call not supported by gl10
    } 
    // Use Gdx.gl10 for all gl calls
  }
}
like image 674
Doran Avatar asked Sep 29 '11 23:09

Doran


1 Answers

Do you actually use shaders in your OpenGL ES 2.0 path or do you rely on SpriteBatch and consorts to handle the dirty details for you? In the later case there's no real benefit in going GLES 2.0 (apart from non-power of two textures, which might be slower on some devices)

Usually you chose between either GLES 1.x or 2.0. If you go with 1.x you don't have to do anything. If you want to use 2.0 you have to create an AndroidApplicationConfig and set the useGL20 flag to true. If GLES 2.0 is not supported on the device you run your app on, libgdx will fall back to 1.x. You can then use your above render loop which will use GLES 2.0 if available and fall back to 1.x otherwise. You are unlikely to have to have separate paths for 1.0 and 1.x though, unless you use GLES calls directly.

like image 133
badlogic Avatar answered Sep 25 '22 15:09

badlogic