I am trying to use the Google Cardboard Android SDK, which contains its own .so files, which I believe contain GL level code in it.
After integrating with another 3D rendering engine, I get the following error.
> 03-09 21:28:13.322: E/libEGL(29766): EGLNativeWindowType 0x76c99010 > already connected to another API 03-09 21:28:13.322: E/libEGL(29766): > eglCreateWindowSurface:414 error 3003 (EGL_BAD_ALLOC)
In fact, during the initialization of the rendering engine. He calls
eglCreateWindowSurface(m_display, config, &window, NULL);
which is trying to create an EGLSurface, which I think has already been created with Cardboard's own code and thus throws the above error.
Therefore, I am trying to get an already created EGLSurface using the command below, but it also does not work.
eglGetCurrentSurface(EGL_DRAW)
Here I do not know what exactly to transfer to eglGetCurrentSurface EGL_DRAW or EGL_READ. I tried reading the OpenGL documentation, but that didn't help.
In general, I am trying to get EGLContext, EGLSurface and EGLDisplay instead of creating them.
Below is the source code I'm trying to change.
EGLint w, h, dummy, format; EGLConfig config; EGLSurface surface; if (!DefaultEGLChooser(m_display, EGL_WINDOW_BIT, config)) { Eegeo_ERROR("unable to find a good display type"); return false; } eglGetConfigAttrib(m_display, config, EGL_NATIVE_VISUAL_ID, &format); ANativeWindow_setBuffersGeometry(&window, 0, 0, format); static const EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; surface = eglCreateWindowSurface(m_display, config, &window, NULL); if(m_context == EGL_NO_CONTEXT) { m_context = eglCreateContext(m_display, config, NULL, contextAttribs); } if (eglMakeCurrent(m_display, surface, surface, m_context) == EGL_FALSE) { Eegeo_ERROR("Unable to eglMakeCurrent"); return false; } //Eegeo_TTY("printing extensions\n"); //char * extensionsString = (char *) glGetString(GL_EXTENSIONS); //Eegeo_TTY("%s\n",extensionsString); Eegeo_GL(eglQuerySurface(m_display, surface, EGL_WIDTH, &w)); Eegeo_GL(eglQuerySurface(m_display, surface, EGL_HEIGHT, &h)); m_surface = surface;
and below is my modified version that gives me a black screen.
EGLint w, h, dummy, format; EGLConfig config; EGLSurface surface; if (!DefaultEGLChooser(m_display, EGL_WINDOW_BIT, config)) { Eegeo_ERROR("unable to find a good display type"); return false; } eglGetConfigAttrib(m_display, config, EGL_NATIVE_VISUAL_ID, &format); ANativeWindow_setBuffersGeometry(&window, 0, 0, format); static const EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; // surface = eglCreateWindowSurface(m_display, config, &window, NULL); surface = eglGetCurrentSurface(EGL_DRAW); if(m_context == EGL_NO_CONTEXT) { m_context = eglGetCurrentContext(); } if (eglMakeCurrent(m_display, surface, surface, m_context) == EGL_FALSE) { Eegeo_ERROR("Unable to eglMakeCurrent"); return false; } Eegeo_GL(eglQuerySurface(m_display, surface, EGL_WIDTH, &w)); Eegeo_GL(eglQuerySurface(m_display, surface, EGL_HEIGHT, &h)); Eegeo_TTY("%.2f , %.2f", w, h); m_surface = surface;