简体   繁体   English

Android:如何将此应用程序从 GLES1 移植到 GLES3

[英]Android: How can I port this app from GLES1 to GLES3

I'm tasked with converting an android app from GLES1 to GLES3.我的任务是将 android 应用程序从 GLES1 转换为 GLES3。 The app does all its OpenGL calls in JNI, runs in a thread, and calls into Java to run basic functions like:该应用程序在 JNI 中执行所有 OpenGL 调用,在线程中运行,并调用 Java 以运行基本功能,例如:

InitOpenGL();
MakeContextCurrent();
GLSwapBuffer();

The app maintains its own clock, etc-- so basically the main loop of the app looks something like this (simplified).该应用程序维护自己的时钟等 - 所以基本上应用程序的主循环看起来像这样(简化)。

JavaBridge->InitOpenGL();
while (stillRunning())
{
   SleepUntilRightTime();
   UpdateEverything();
   if (shouldDraw())
   {
      JavaBridge->MakeContextCurrent();
      DrawEverything();
      JavaBridge->GLSwapBuffers();
   }
}

So, to accomplish this, the app has its own OpenGL factory, which initializes OpenGL1.1.因此,为了实现这一点,应用程序有自己的 OpenGL 工厂,它初始化 OpenGL1.1。 I'll try to cut out everything unncessary for brevity, here are the basics (removed all error checking to keep it short):为了简洁起见,我将尝试删除所有不必要的内容,这里是基础知识(删除了所有错误检查以保持简短):

public class GLView extends SurfaceView implements SurfaceHolder.Callback
{
   EGL10 m_GL;
   EGLContext m_GLContext;
   EGLDisplay m_GLDisplay=null;
   EGLSurface m_GLSurface=null;
   EGLConfig m_GLConfig=null;
   
   public void InitOpenGL()
   {
      m_GL = (EGL10) EGLContext.getEGL();
      m_GLDisplay = m_GL.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
      m_GL.eglInitialize(m_GLDisplay, null);
      EGLConfig[] configs = new EGLConfig[1];
      int[] config_count = new int[1];
      int[] specs = { EGL10.EGL_ALPHA_SIZE, 8, EGL10.EGL_DEPTH_SIZE, 16, EGL10.EGL_STENCIL_SIZE, 8, EGL10.EGL_NONE };
      m_GL.eglChooseConfig(m_GLDisplay, specs, configs, 1, config_count);
      m_GLContext = m_GL.eglCreateContext(m_GLDisplay, m_GLConfig, EGL10.EGL_NO_CONTEXT, null);
      SurfaceHolder h = getHolder();
      m_GLSurface = m_GL.eglCreateWindowSurface(m_GLDisplay, m_GLConfig, h, null);
      m_GL.eglMakeCurrent(m_GLDisplay, m_GLSurface, m_GLSurface, m_GLContext);
      m_GL = (EGL10) EGLContext.getEGL();
   } 
   public void MakeContextCurrent() 
   {
      m_GL.eglMakeCurrent(m_GLDisplay, m_GLSurface, m_GLSurface,    m_GLContext);
   }
   public void SwapBuffers() 
   {
      m_GL.eglSwapBuffers(m_GLDisplay, m_GLSurface);
   }
}

This all works beautifully, the app runs in its thread and paints the screen whenever it deems fit (it's a game, btw, that's why the constant loop).这一切都很好,应用程序在其线程中运行并在它认为合适的时候绘制屏幕(这是一个游戏,顺便说一句,这就是为什么不断循环)。

Now: I was hoping that to turn this into an OpenGL3.0 context, I'd just say "hey request version number" or something like that.现在:我希望将其转换为 OpenGL3.0 上下文,我只想说“嘿,请求版本号”或类似的东西。 I've tried a few things without success (setting GL_VERSION in an attrib list with createcontext, making sure the right libraries are linked, fixed manifest, etc, etc, on and on) but no matter what I do, openGL calls in the JNI either do nothing, or crash the program.我尝试了一些没有成功的事情(使用 createcontext 在属性列表中设置 GL_VERSION,确保链接正确的库,固定清单等,等等),但无论我做什么,openGL 在 JNI 中调用要么什么都不做,要么让程序崩溃。

I can't even get glClear to work unless I just revert everything back to square one.我什至不能让 glClear 工作,除非我把所有东西都恢复到第一格。 Anyone have any advice on offer to turn this thing into a 3.0 capable context?有人有什么建议可以将这个东西变成一个支持 3.0 的上下文吗?

Okay, managed to figure this out.好的,设法解决了这个问题。 For anyone using modern android, you'll find that EG10.EGL_CONTEXT_CLIENT_VERSION is not defined.对于使用现代 android 的任何人,您会发现未定义 EG10.EGL_CONTEXT_CLIENT_VERSION。 It seems like using EGL_VERSION would be the substitute, but it's not.似乎使用 EGL_VERSION 可以替代,但事实并非如此。

Why isn't EGL_CONTEXT_CLIENT_VERSION defined?为什么没有定义 EGL_CONTEXT_CLIENT_VERSION? Is it depreciated?是不是贬值了? Is it shunned?被回避了吗? We'll never know.我们永远不会知道。 But we DO know that if it WAS defined it would be 0x3098.但我们确实知道,如果它被定义,它将是 0x3098。

So, making this all magically work was as simple as saying:所以,让这一切神奇地工作就像说:

        int[] attrib_list=new int[]{0x3098,3,EGL10.EGL_NONE};
        m_GLContext = m_GL.eglCreateContext(m_GLDisplay, m_GLConfig, EGL10.EGL_NO_CONTEXT,attrib_list);

Is it dangerous to do this?这样做有危险吗? Probably.大概。 I'll do a little more research into it.我会做更多的研究。 If I never return to edit this, then I found no real answer yea or nay.如果我再也没有回来编辑这个,那么我找不到真正的答案是或否。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM