I am trying to use Google Cardboard Android SDK which contains native .so files which I suppose contains GL level code in it.
Upon integrating it with another 3D rendering Engine I get 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)
Actually during initialization of rendering engine. It is calling,
eglCreateWindowSurface(m_display, config, &window, NULL);
which is a try to create EGLSurface which I think is already created by Cardboard Native code and thus throwing above mentioned error.
Therefor I am trying to get already created EGLSurface using below command but it is not working either.
eglGetCurrentSurface(EGL_DRAW)
Here I do not know what exactly to pass in eglGetCurrentSurface EGL_DRAW or EGL_READ. I have tried reading OpenGL documentation but it was not of much help.
Overall I am trying to get EGLContext, EGLSurface and EGLDisplay instead of creating them.
Below is the original code which I am trying to modify.
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;
#ifdef EEGEO_DROID_EMULATOR
m_sharedSurface = EGL_NO_SURFACE;
m_resourceBuildSharedContext = EGL_NO_CONTEXT;
#else
if(m_resourceBuildSharedContext == EGL_NO_CONTEXT)
{
m_resourceBuildSharedContext = eglCreateContext(m_display, config, m_context, contextAttribs);
}
EGLint pBufferAttribs[] =
{
EGL_WIDTH, 1,
EGL_HEIGHT, 1,
EGL_TEXTURE_TARGET, EGL_NO_TEXTURE,
EGL_TEXTURE_FORMAT, EGL_NO_TEXTURE,
EGL_NONE
};
EGLConfig sharedSurfaceConfig;
if (!DefaultEGLChooser(m_display, EGL_PBUFFER_BIT, sharedSurfaceConfig))
{
Eegeo_ERROR("unabled to find a good pbuffer surface type");
}
m_sharedSurface = eglCreatePbufferSurface(m_display, sharedSurfaceConfig, pBufferAttribs);
#endif
and below is my modified version which gives me 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;
#ifdef EEGEO_DROID_EMULATOR
m_sharedSurface = EGL_NO_SURFACE;
m_resourceBuildSharedContext = EGL_NO_CONTEXT;
#else
if(m_resourceBuildSharedContext == EGL_NO_CONTEXT)
{
m_resourceBuildSharedContext = eglCreateContext(m_display, config, m_context, contextAttribs);
}
EGLint pBufferAttribs[] =
{
EGL_WIDTH, 1,
EGL_HEIGHT, 1,
EGL_TEXTURE_TARGET, EGL_NO_TEXTURE,
EGL_TEXTURE_FORMAT, EGL_NO_TEXTURE,
EGL_NONE
};
EGLConfig sharedSurfaceConfig;
if (!DefaultEGLChooser(m_display, EGL_PBUFFER_BIT, sharedSurfaceConfig))
{
Eegeo_ERROR("unabled to find a good pbuffer surface type");
}
m_sharedSurface = eglCreatePbufferSurface(m_display, sharedSurfaceConfig, pBufferAttribs);
#endif