有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Android:无法为OpenGLES 3.0创建EGL上下文,初始化EGL总是返回V1.0

在我尝试在Android上为OpenGL ES编写一个颤振插件时遇到了同样的问题,我决定测试我的代码是否可以在原生Android Java应用程序中工作

不幸的是,我看到了完全相同的行为。我总是得到EGL版本V1。0和我无法为3.0创建EGL上下文并使其成为当前

调用eglCreateContext时,我已经收到一个错误的属性错误,除非在选择配置时删除所有属性。在这种情况下,我可以创建上下文并使其成为当前上下文,但它是OpenGL V1。1检查版本时

当轮胎转动使其成为当前状态时,我得到一个错误匹配。 我在Windows和Mac上运行的代码与直接加载libegl时的代码几乎相同。因此,从使用FFI的颤振到直接使用C库,我得到了EGLv1.4/1.5,并且可以创建上下文

您可以在这里找到Android测试项目:https://github.com/escamoteur/EGL_Test_Android_Native

我不是本地的Android开发者,所以我在按钮的点击处理程序中测试代码的方法可能是不合法的。如果是这样,请给我一个提示,在哪里可以更好地尝试。最后,这段代码应该进行一些GLES离屏渲染,我需要与直接使用GLES c库的代码共享上下文

这是当前代码

            public void onClick(View view) {
                EGLDisplay display = EGL14.eglGetDisplay(EGL_DEFAULT_DISPLAY);
                //EGLDisplay display = EGL14.eglGetCurrentDisplay();

                int[] version = new int[2];
                boolean initializeResult = EGL14.eglInitialize(display, version, 0, version, 1);
                if (!initializeResult) {
                    int error = EGL14.eglGetError();

                    Log.i("EGL InitError", "eglInit failed");
                    return;
                }

                Log.i("FlutterWegGL", "EGL version is " + version[0] + "." + version[1]);


                int[] attribute_list = new int[]{
                        EGL_RENDERABLE_TYPE,
                        EGL_OPENGL_ES3_BIT_KHR,
                        EGL_RED_SIZE, 8,
                        EGL_GREEN_SIZE, 8,
                        EGL_BLUE_SIZE, 8,
                        EGL_ALPHA_SIZE, 8,
                        EGL_DEPTH_SIZE, 16,
                        EGL_NONE};

                int[] configsCount = new int[1];
                EGLConfig[] configs = new EGLConfig[1];
                EGLConfig config;
                boolean chooseConfigResult = EGL14.eglChooseConfig(display, attribute_list, 0, configs, 0, 1, configsCount, 0);
                if (!chooseConfigResult) {
                    Log.i("EGL InitError", "eglChooseConfig failed");
                    return;
                }

                config = configs[0];

                int[] surfaceAttributes = new int[]{
                        EGL_WIDTH, 16,
                        EGL_HEIGHT, 16,
                        EGL_NONE
                };

                // This is just a dummy surface that it needed to make an OpenGL context current (bind it to this thread)
                EGLSurface dummySurfaceForDartSide = EGL14.eglCreatePbufferSurface(display, config, surfaceAttributes, 0);
                EGLSurface dummySurfaceForPlugin = EGL14.eglCreatePbufferSurface(display, config, surfaceAttributes, 0);

                Log.i("FlutterWegGL", "EGL Error: " + EGL14.eglGetError());

                    int[] attribList = {EGL_CONTEXT_CLIENT_VERSION, 3, EGL14.EGL_NONE};
                EGLContext eglContext = EGL14.eglCreateContext(display, config, EGL_NO_CONTEXT, attribute_list, 0);
                Log.i("FlutterWegGL", "EGL Error: " + EGL14.eglGetError());
                /// we send back the context. This might look a bit strange, but is necessary to allow this function to be called
                /// from Dart Isolates.

                if (!eglMakeCurrent(display, dummySurfaceForPlugin, dummySurfaceForPlugin, eglContext)) {
                    int eglerror = EGL14.eglGetError();

                    Log.i("FlutterWegGL", "Error: MakeCurrent " + eglerror);
                }
                String v = GLES30.glGetString(GL_VENDOR);
                int error = glGetError();
                if (error != GL_NO_ERROR)
                {

                    Log.i("FlutterWegGL", "GLError: " + error);
                }
                String r = GLES30.glGetString(GL_RENDERER);
                String v2 = GLES30.glGetString(GL_VERSION);


                Log.i("FlutterWegGL", "OpenGL initialized: Vendor:" + v + " renderer: " + r + " Version: " + v2);

我还补充说

    <uses-feature 安卓:glEsVersion="0x00030000" 安卓:required="true" />

但它没有改变任何东西

我认为使用此SDK设置,获得EGL应该没有问题>;V1。0

安卓 {
    compileSdkVersion 30
    buildToolsVersion "30.0.2"

    defaultConfig {
        applicationId "com.example.egl_test"
        minSdkVersion 28
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

更新

我对import javax.microedition.khronos.egl.EGL10绑定也做了同样的尝试,通过它们,我可以毫无问题地为OpenGL ES 3.0创建OpenGL上下文

之后我可以叫‘EGL14’。getCurrentContext'以便我可以访问本机EGLContext句柄

这似乎可行,但看起来像一个丑陋的黑客


共 (0) 个答案