我正在尝试使用包含原生.so文件的Google Cardboard Android SDK,我认为其中包含GL级代码。
将其与其他3D渲染引擎集成后,我得到以下错误。
> 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)
实际上在初始化渲染引擎期间。它在呼唤,
eglCreateWindowSurface(m_display, config, &window, NULL);
尝试创建EGLSurface,我认为它已经由Cardboard Native代码创建,因此抛出了上述错误。
因此我试图使用下面的命令创建EGLSurface,但它也不起作用。
eglGetCurrentSurface(EGL_DRAW)
这里我不知道究竟要通过eglGetCurrentSurface EGL_DRAW或EGL_READ传递什么。我试过阅读OpenGL文档,但它没有多大帮助。
总的来说,我试图获得EGLContext,EGLSurface和EGLDisplay而不是创建它们。
以下是我要修改的原始代码。
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
以下是我的修改版本,它给了我黑屏。
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