如何在Libgdx中支持OpenGL ES GL10,GL11和GL20? [英] How do I support OpenGL ES GL10, GL11, and GL20 in Libgdx?

查看:249
本文介绍了如何在Libgdx中支持OpenGL ES GL10,GL11和GL20?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写使用GL10的3D游戏,但我希望该应用程序支持GL11或GL20(如果可用)。支持所有3个的最佳设计是什么?或者这是一个傻瓜的差事,我应该专注于支持一个版本?

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?

我目前的想法是将我的render()函数拆分为renderGL10,renderGL11,renderGL20和call基于可用GL实例的适当渲染功能。每个渲染函数内部都是渲染GL版本的正确方法; GL10和GL11可能会有重叠。这是处理我的问题的合适方式还是有更好的方法?

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();
  }
}

编辑:
解决方案:如果是gl1。 x可用,gl10也可用(并且Gdx.gl10不为空)。因此,我的渲染代码通常应该按如下方式构造:

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
  }
}


推荐答案

你真的用过吗?您的OpenGL ES 2.0路径中的着色器,还是依靠SpriteBatch和consorts为您处理脏信息?在后一种情况下,使用GLES 2.0并没有什么好处(除了两种纹理的非功能,在某些设备上可能会更慢)

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)

通常你选择GLES 1.x或2.0。如果你选择1.x,你不需要做任何事情。如果要使用2.0,则必须创建AndroidApplicationConfig并将useGL20标志设置为true。如果您运行应用程序的设备不支持GLES 2.0,则libgdx将回退到1.x.然后,您可以使用上面的渲染循环,如果可用,将使用GLES 2.0,否则将回退到1.x.除非你直接使用GLES调用,否则你不一定要有1.0和1.x的单独路径。

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.

这篇关于如何在Libgdx中支持OpenGL ES GL10,GL11和GL20?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆