I'm having trouble getting EGL to produce an OpenGL context for me. All the functions return no errors except eglCreateContext() which returns EGL_NO_CONTEXT, and eglGetError() produces the code for EGL_BAD_CONFIG. eglChooseConfig() produces no error.
I have some experience with OpenGL, but I've never had to create my own context before, so maybe I've missed something important.
I looked through the forums for a similar question and found this this post. I was struck by how similar his code looked to mine. He says that it works, but mine does not, and I can't see any meaningful difference.
Here's my code, stripping error checking to be concise:
/*
* EGL Initialization
* Creates OpenGl context
*/
/* This part lives in a header */
struct gl_details {
GLuint vShader;
GLuint fShader;
EGLDisplay display;
EGLConfig config;
EGLSurface surface;
EGLContext context;
EGLNativeDisplayType nDispType;
EGLNativeWindowType nWinType;
};
struct gl_details glDetails;
/* The rest lives in the .c file */
glDetails->nDispType = fbGetDisplayByIndex(0);
glDetails->display = eglGetDisplay(glDetails->nDispType);
eglInitialize(glDetails->display, NULL, NULL)
eglBindAPI(EGL_OPENGL_ES_API)
/* This is the part where I'm most suspicious. */
static const EGLint fb_attribute_list[] = {
EGL_RED_SIZE, 5,
EGL_GREEN_SIZE, 6,
EGL_BLUE_SIZE, 5,
EGL_ALPHA_SIZE, 0,
EGL_SAMPLES, 0,
EGL_DEPTH_SIZE, 24,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_NONE /* EGL null terminator */
};
EGLint configResults = 0;
eglChooseConfig(glDetails->display, &fb_attribute_list[0], &(glDetails->config), 1, &configResults)
glDetails->nWinType = fbCreateWindow(glDetails->nDispType, 0, 0, g_DsyInfo.fb_W, g_DsyInfo.fb_H);
glDetails->surface = eglCreateWindowSurface(glDetails->display, glDetails->config, glDetails->nWinType, NULL);
EGLint const context_attrib_list[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
glDetails->context = eglCreateContext(glDetails->display, glDetails->config, EGL_NO_CONTEXT, context_attrib_list);
eglMakeCurrent(glDetails->display, glDetails->surface, glDetails->surface, glDetails->context);
If anyone can see what I've done wrong, or even can tell me how to get better output for debugging, it would be much appreciated.
Hi Thomas,
Is difficult is you not show the error but perform standard EGL initialization steps. Create EGL context from the ANativeWindow* pointer:
EGLint numConfigs; |
EGLint majorVersion;
EGLint minorVersion;
EGLConfig eglConfig;
EGLContext eglContext;
EGLSurface eglSurface;
EGLDisplay eglDisplay
static const EGLint contextAttribs[] =
{
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
static const EGLint configAttribs[] =
{
EGL_SAMPLES, 0,
EGL_RED_SIZE, 5,
EGL_GREEN_SIZE, 6,
EGL_BLUE_SIZE, 5,
EGL_ALPHA_SIZE, 0,
EGL_DEPTH_SIZE, 0,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_NONE
};
EGLint w;
EGLint h;
eglBindAPI(EGL_OPENGL_ES_API);
eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
eglInitialize(eglDisplay, &majorVersion, &minorVersion);
eglGetConfigs(eglDisplay, NULL, 0, &numConfigs);
eglChooseConfig(eglDisplay, configAttribs, &eglConfig, 1, &numConfigs);
ANativeWindow* anw = CameraHardwareInterface::getANativeWindow(mNativeWindow);
eglCreateWindowSurface(eglDisplay, eglConfig, anw, NULL);
eglContext = eglCreateContext(eglDisplay, eglConfig, EGL_NO_CONTEXT, contextAttribs);
eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext);
eglQuerySurface(eglDisplay, eglSurface, EGL_WIDTH, &w);
eglQuerySurface(eglDisplay, eglSurface, EGL_HEIGHT, &h);
Regards
Update: swapped out eglChooseConfig with eglGetConfigs so I could see if any of the configs were acceptable. All 70 configs failed.