Hi All,
Currently I am doing some experiments with mesa 7.9 driver to check the
renderer info of underlying OpenGL and OpenGL ES2.0 drivers to decide which
driver to use at runtime. With my code attached, the renderer info for GLES2
can be got successfully, and although the EGL and GLES2 libraries are
unloaded before creating the GLX context, glGetString(GL_RENDERER) for
OpenGL still returns NULL. After enable MESA_DEBUG, I found the error
message "GL User Error: calling GL function without a rendering context",
and many warnings as "Mesa warning: failed to remap ....". I also changed
the sequence for GL and GLES2, but got similar results. If do separately,
both renderer info can be got successfully. It seems that EGL/GLES2 and
GLX/GL affects each other in this case, may be related to library
load/unload(?). Do you guys have some ideas to solve this problem?
Regards,
Jammy
static const char *GetRenderer(bool gles2)
{
Display *dpy = XOpenDisplay(NULL);
int scrnum;
Window root;
const char *renderer = NULL;
if (NULL == dpy) {
printf("failed to open display\n");
return NULL;
}
scrnum = DefaultScreen(dpy);
root = RootWindow(dpy, scrnum);
if (gles2) {
EGLDisplay egl_dpy;
EGLConfig config;
EGLint num_configs = 1;
EGLContext egl_ctx;
EGLSurface egl_surf;
static const EGLint ctx_attribs[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
egl_dpy = (*pfnEGLGetDisplay)(dpy);
if ((NULL == egl_dpy) || !(*pfnEGLInitialize)(egl_dpy, NULL, NULL)) {
printf("egl initialization failed\n");
return NULL;
}
if (!(*pfnEGLGetConfigs)(egl_dpy, &config, num_configs, &num_configs) || num_configs < 1) {
printf("failed to get egl config\n");
return NULL;
}
egl_ctx = (*pfnEGLCreateContext)(egl_dpy, config, EGL_NO_CONTEXT, ctx_attribs);
if (!egl_ctx) {
printf("eglCreateContext failed\n");
return NULL;
}
egl_surf = (*pfnEGLCreateWindowSurface)(egl_dpy, config, root, NULL);
if (!egl_surf) {
printf("eglCreateWindowSurface failed\n");
return;
}
if (!(*pfnEGLMakeCurrent)(egl_dpy, egl_surf, egl_surf, egl_ctx))
return;
renderer = (*pfnGetString)(GL_RENDERER);
(*pfnEGLMakeCurrent)(egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
(*pfnEGLDestroyContext)(egl_dpy, egl_ctx);
(*pfnEGLDestroySurface)(egl_dpy, egl_surf);
(*pfnEGLTerminate)(egl_dpy);
}
else {
GLXContext glx_ctx;
int attribs[] = {
GLX_RGBA,
None };
XVisualInfo *visinfo = NULL;
visinfo = (*pfnGLXChooseVisual)(dpy, scrnum, attribs);
if (!visinfo) {
printf("failed to get visual\n");
return NULL;
}
glx_ctx = (*pfnGLXCreateContext)(dpy, visinfo, NULL, True);
if (!glx_ctx) {
printf("failed to create GLX context\n");
return NULL;
}
(*pfnGLXMakeCurrent)(dpy, root, glx_ctx);
renderer = (*pfnGetString)(GL_RENDERER);
(*pfnGLXMakeCurrent)(dpy, None, NULL);
(*pfnGLXDestroyContext)(dpy, glx_ctx);
XFree(visinfo);
}
XCloseDisplay(dpy);
return renderer;
}
void check_renderer(void)
{
void *egl_handle = NULL;
void *gl_handle = NULL;
void *gles2_handle = NULL;
const char *gl_renderer = NULL;
const char *gles2_renderer = NULL;
gles2_handle = dlopen("/usr/lib/libGLESv2.so");
egl_handle = dlopen("/usr/lib/libEGL.so");
if (egl_handle && gles2_handle) {
/* Resolve EGL APIs for create rendering context to get GL_RENDERER */
pfnEGLGetDisplay = dlsym(egl_handle, "eglGetDisplay");
pfnEGLInitialize = dlsym(egl_handle, "eglInitialize");
pfnEGLGetConfigs = dlsym(egl_handle, "eglGetConfigs");
pfnEGLCreateContext = dlsym(egl_handle, "eglCreateContext");
pfnEGLCreateWindowSurface = dlsym(egl_handle, "eglCreateWindowSurface");
pfnEGLMakeCurrent = dlsym(egl_handle, "eglMakeCurrent");
pfnEGLDestroyContext = dlsym(egl_handle, "eglDestroyContext");
pfnEGLDestroySurface = dlsym(egl_handle, "eglDestroySurface");
pfnEGLTerminate = dlsym(egl_handle, "eglTerminate");
/* Resolve glGetString */
pfnGetString = dlsym(gles2_handle, "glGetString");
gles2_renderer = GetRenderer(true);
pfnGetString = NULL;
}
if (egl_handle) {
dlclose(egl_handle);
egl_handle = NULL;
}
if (gles2_handle) {
dlclose(gles2_handle);
gles2_handle = NULL;
}
printf("OpenGL ES2.0 Renderer: %s\n", gles2_renderer ? gles2_renderer : "Not Available");
/* Try to get the opengl renderer info if available */
gl_handle = dlopen("/usr/lib/libGL.so");
if (gl_handle) {
/* Resolve GLX APIs needed for create rendering context */
pfnGLXChooseVisual = dlsym(gl_handle, "glXChooseVisual");
pfnGLXCreateContext = dlsym(gl_handle, "glXCreateContext");
pfnGLXMakeCurrent = dlsym(gl_handle, "glXMakeCurrent");
pfnGLXDestroyContext = dlsym(gl_handle, "glXDestroyContext");
/* Resolve glGetString */
pfnGetString = dlsym(gl_handle, "glGetString");
gl_renderer = GetRenderer(false);
pfnProxyGetString = NULL;
/* Close the library*/
dlclose(gl_handle);
}
printf("OpenGL Renderer: %s\n", gl_renderer ? gl_renderer : "Not Available");
}
_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev