~glproxy-dev/glproxy/trunk

« back to all changes in this revision

Viewing changes to src/gl_proxy.c

  • Committer: Marc Ordinas i Llopis
  • Date: 2011-12-08 11:35:53 UTC
  • mfrom: (35.1.7 fixes)
  • Revision ID: marc.ordinasillopis@linaro.org-20111208113553-og785wmh311tv427
EGL support: Add EGL virtualization support to glproxy.

Also,
- Removed the "automagic" best renderer detection, as it needed to start
both EGL and GLX which caused problems on some systems. It will return,
but in a more application-controlled way.
- Now it's necessary to pass the current display to the extensions helper
functions, as using an internal one caused NULL being returned as the
extensions string in some systems.
- A lot of code clean-ups.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include <stdlib.h>
31
31
#include <dlfcn.h>
32
32
#include <string.h>
33
 
#include <GL/gl_proxy.h>
34
 
#include <GL/glx_proxy.h>
35
 
 
36
 
#include "egldef.h"
 
33
#include "GL/gl_proxy.h"
 
34
#include "GL/glx_proxy.h"
 
35
#include "EGL/egl_proxy.h"
37
36
 
38
37
/* global proxy context */
39
38
PROXY_CONTEXT global_proxy_context;
40
39
 
41
40
/* library names for different backends */
42
41
const char *opengl_libraries[] = {
43
 
        "libGL.so",
44
 
        "libGLESv2.so",
 
42
    "libGL.so.1",
 
43
    "libGLESv2.so.2",
45
44
};
46
45
 
 
46
#define LIBEGL_PATH     "libEGL.so.1"
 
47
 
47
48
/* proxy functions */
48
49
PFNPROXYACTIVETEXTUREPROC pfnProxyActiveTexture = NULL;
49
50
PFNPROXYATTACHSHADERPROC pfnProxyAttachShader = NULL;
188
189
PFNPROXYVERTEXATTRIBPOINTERPROC pfnProxyVertexAttribPointer = NULL;
189
190
PFNPROXYVIEWPORTPROC pfnProxyViewport = NULL;
190
191
 
191
 
/* Proc address for EGL/GLX symbol resolve function
192
 
 * Note:
193
 
 * eglGetProcAddress can only be used for GL or EGL extension function
194
 
 * glXGetProcAddress/glXGetProcAddressARB can be used for all GL/GLX funtions
195
 
 */
196
 
PFNPROXYGLXGETPROCADDRESSPROC pfnProxyGLXGetProcAddressARB = NULL;
197
 
PFNPROXYGLXGETPROCADDRESSPROC pfnProxyGLXGetProcAddress = NULL;
198
 
PFNPROXYEGLGETPROCADDRESSPROC pfnProxyEGLGetProcAddress = NULL;
199
 
 
200
 
PFNPROXYEGLQUERYSTRINGPROC        pfnProxyEGLQueryString = NULL;
201
 
 
202
 
/* EGL APIs needed for backend selection */
203
 
PFNPROXYEGLGETDISPLAYPROC pfnProxyEGLGetDisplay = NULL;
204
 
PFNPROXYEGLINITIALIZEPROC pfnProxyEGLInitialize = NULL;
205
 
PFNPROXYEGLTERMINATEPROC pfnProxyEGLTerminate = NULL;
206
 
PFNPROXYEGLCHOOSECONFIGPROC pfnProxyEGLChooseConfig = NULL;
207
 
PFNPROXYEGLCREATECONTEXTPROC pfnProxyEGLCreateContext = NULL;
208
 
PFNPROXYEGLDESTROYCONTEXTPROC pfnProxyEGLDestroyContext = NULL;
209
 
PFNPROXYEGLCREATEPBUFFERSURFACEPROC pfnProxyEGLCreatePbufferSurface = NULL;
210
 
PFNPROXYEGLDESTROYSURFACEPROC pfnProxyEGLDestroySurface = NULL;
211
 
PFNPROXYEGLMAKECURRENTPROC pfnProxyEGLMakeCurrent = NULL;
212
 
 
213
192
static void *glProxyOpenLibrary(const char *name)
214
193
{
215
 
        return dlopen(name, RTLD_LAZY | RTLD_GLOBAL);
 
194
    return dlopen(name, RTLD_LAZY | RTLD_GLOBAL);
216
195
}
217
196
 
218
197
static int glProxyCloseLibrary(void *handle)
219
198
{
220
 
        return dlclose(handle);
221
 
}
222
 
 
223
 
/* A valid EGL rendering context is needed in scenarios similar as below:
224
 
 * - call glGetString to get renderer information
225
 
 * - call eglGetProcAddress to get symbol address for functions of GLES2 extenstions
226
 
 */
227
 
static int CreateEGLRenderingContext(Display *dpy, PROXY_CONTEXT *proxy_context)
228
 
{
229
 
        EGLDisplay egl_dpy;
230
 
        EGLConfig config;
231
 
        EGLint num_configs = 1;
232
 
 
233
 
        static const EGLint config_attribs[] = {
234
 
                EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
235
 
                EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
236
 
                EGL_NONE
237
 
        };
238
 
        static const EGLint ctx_attribs[] = {
239
 
                EGL_CONTEXT_CLIENT_VERSION, 2,
240
 
                EGL_NONE
241
 
        };
242
 
        static const EGLint surface_attribs[] = {
243
 
                EGL_WIDTH, 1,
244
 
                EGL_HEIGHT, 1,
245
 
                EGL_NONE
246
 
        };
247
 
 
248
 
        if (proxy_context->egl_dpy && proxy_context->egl_ctx && proxy_context->egl_surf)
249
 
                return 0;
250
 
 
251
 
        egl_dpy = proxy_context->egl_dpy = (*pfnProxyEGLGetDisplay)(dpy);
252
 
 
253
 
        if ((EGL_NO_DISPLAY == egl_dpy) || !(*pfnProxyEGLInitialize)(egl_dpy, NULL, NULL)) {
254
 
                printf("egl initialization failed\n");
255
 
                return -1;
256
 
        }
257
 
        
258
 
        if (!(*pfnProxyEGLChooseConfig)(egl_dpy, config_attribs, &config, num_configs, &num_configs) || num_configs < 1) {
259
 
                printf("failed to get egl config\n");
260
 
                return -1;
261
 
        }
262
 
        
263
 
        proxy_context->egl_ctx = (*pfnProxyEGLCreateContext)(egl_dpy, config, EGL_NO_CONTEXT, ctx_attribs);
264
 
        if (EGL_NO_CONTEXT == proxy_context->egl_ctx) {
265
 
                printf("eglCreateContext failed\n");
266
 
                return -1;
267
 
        }
268
 
        
269
 
        proxy_context->egl_surf = (*pfnProxyEGLCreatePbufferSurface)(egl_dpy, config, surface_attribs);
270
 
        if (EGL_NO_SURFACE == proxy_context->egl_surf) {
271
 
                printf("eglCreatePbufferSurface failed\n");
272
 
                return -1;
273
 
        }
274
 
        
275
 
        if (!(*pfnProxyEGLMakeCurrent)(egl_dpy, proxy_context->egl_surf, proxy_context->egl_surf, proxy_context->egl_ctx)) {
276
 
                printf("eglMakeCurrent failed\n");
277
 
                return -1;
278
 
        }
279
 
 
280
 
        return 0;
281
 
}
282
 
 
283
 
static int DestroyEGLRenderingContext(PROXY_CONTEXT *proxy_context)
284
 
{
285
 
        (*pfnProxyEGLMakeCurrent)(proxy_context->egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
286
 
        (*pfnProxyEGLDestroyContext)(proxy_context->egl_dpy, proxy_context->egl_ctx);
287
 
        (*pfnProxyEGLDestroySurface)(proxy_context->egl_dpy, proxy_context->egl_surf);
288
 
        (*pfnProxyEGLTerminate)(proxy_context->egl_dpy);
289
 
 
290
 
        proxy_context->egl_dpy = EGL_NO_DISPLAY;
291
 
        proxy_context->egl_ctx = EGL_NO_CONTEXT;
292
 
        proxy_context->egl_surf = EGL_NO_SURFACE;
293
 
 
294
 
        return 0;
295
 
}
296
 
 
297
 
static int glProxyEarlyResolve(PROXY_CONTEXT *proxy_context)
298
 
{
299
 
        if (OPENGL_BACKEND == proxy_context->current_backend) {
300
 
                proxy_context->gl_handle = glProxyOpenLibrary(opengl_libraries[OPENGL_BACKEND]);
301
 
                pfnProxyGLXGetProcAddress = dlsym(proxy_context->gl_handle, "glXGetProcAddress");
302
 
                if (NULL == pfnProxyGLXGetProcAddress) {
303
 
                        pfnProxyGLXGetProcAddressARB = dlsym(proxy_context->gl_handle, "glXGetProcAddressARB");
304
 
                }
305
 
        }
306
 
        else if (OPENGL_ES20_BACKEND == proxy_context->current_backend) {
307
 
                Display *dpy = XOpenDisplay(NULL);
308
 
 
309
 
                if (NULL == dpy) {
310
 
                        printf("failed to open display\n");
311
 
                        return -1;
312
 
                }
313
 
 
314
 
                if (NULL == proxy_context->egl_handle) {
315
 
                        proxy_context->egl_handle = glProxyOpenLibrary(LIBEGL_PATH);
316
 
                        pfnProxyEGLGetDisplay = dlsym(proxy_context->egl_handle, "eglGetDisplay");
317
 
                        pfnProxyEGLInitialize = dlsym(proxy_context->egl_handle, "eglInitialize");
318
 
                        pfnProxyEGLChooseConfig = dlsym(proxy_context->egl_handle, "eglChooseConfig");
319
 
                        pfnProxyEGLCreateContext = dlsym(proxy_context->egl_handle, "eglCreateContext");
320
 
                        pfnProxyEGLCreatePbufferSurface = dlsym(proxy_context->egl_handle, "eglCreatePbufferSurface");
321
 
                        pfnProxyEGLMakeCurrent = dlsym(proxy_context->egl_handle, "eglMakeCurrent");
322
 
                        pfnProxyEGLDestroyContext = dlsym(proxy_context->egl_handle, "eglDestroyContext");
323
 
                        pfnProxyEGLDestroySurface = dlsym(proxy_context->egl_handle, "eglDestroySurface");
324
 
                        pfnProxyEGLTerminate = dlsym(proxy_context->egl_handle, "eglTerminate");
325
 
                }
326
 
 
327
 
                if (CreateEGLRenderingContext(dpy, proxy_context) < 0)
328
 
                        return -1;
329
 
 
330
 
                pfnProxyEGLGetProcAddress = dlsym(proxy_context->egl_handle, "eglGetProcAddress");
331
 
                pfnProxyEGLQueryString = dlsym(proxy_context->egl_handle, "eglQueryString");
332
 
        }
333
 
 
334
 
        return 0;
335
 
}
336
 
 
337
 
void *glProxyGetProcAddr(void *handle, const char *name)
338
 
{
339
 
        if (pfnProxyGLXGetProcAddress) {
340
 
                return (*pfnProxyGLXGetProcAddress)((const GLubyte *)name);
341
 
        }
342
 
        else if (pfnProxyGLXGetProcAddressARB) {
343
 
                return (*pfnProxyGLXGetProcAddressARB)((const GLubyte *)name);
344
 
        }
345
 
        else {
346
 
                return dlsym(handle, name);
347
 
        }
 
199
    return dlclose(handle);
 
200
}
 
201
 
 
202
static int glProxyEarlyResolve(PROXY_CONTEXT *proxy_context) {
 
203
    if (OPENGL_BACKEND == proxy_context->current_backend) {
 
204
        proxy_context->gl_handle = glProxyOpenLibrary(opengl_libraries[OPENGL_BACKEND]);
 
205
 
 
206
        pfnProxyGLXGetProcAddress = dlsym(proxy_context->gl_handle, "glXGetProcAddress");
 
207
        if (NULL == pfnProxyGLXGetProcAddress) {
 
208
            pfnProxyGLXGetProcAddressARB = dlsym(proxy_context->gl_handle,
 
209
                    "glXGetProcAddressARB");
 
210
        }
 
211
    } else if (OPENGL_ES20_BACKEND == proxy_context->current_backend) {
 
212
        proxy_context->egl_handle = glProxyOpenLibrary(LIBEGL_PATH);
 
213
        pfnProxyEglGetProcAddress = dlsym(proxy_context->egl_handle, "eglGetProcAddress");
 
214
    }
 
215
 
 
216
    return 0;
 
217
}
 
218
 
 
219
void *glProxyGetProcAddr(void *handle, const char *name) {
 
220
    if (pfnProxyGLXGetProcAddress) {
 
221
        return (*pfnProxyGLXGetProcAddress)((const GLubyte *) name);
 
222
    } else if (pfnProxyGLXGetProcAddressARB) {
 
223
        return (*pfnProxyGLXGetProcAddressARB)((const GLubyte *) name);
 
224
    } else {
 
225
        return dlsym(handle, name);
 
226
    }
348
227
}
349
228
 
350
229
static GLboolean glProxyCheckExtension(const char *list, const char *name)
364
243
    return (ext_ptr != NULL)? GL_TRUE : GL_FALSE;
365
244
}
366
245
 
367
 
GLboolean glProxyHasExtension(const char *extension)
 
246
GLboolean glProxyHasExtension(void *display, const char *extension)
368
247
{
369
248
    char const *backend_extensions = NULL;
370
249
    char const *gl_extensions = NULL;
375
254
    /* Get the backend extensions string */
376
255
    if (global_proxy_context.current_backend == OPENGL_BACKEND &&
377
256
        pfnProxyQueryExtensionsString) {
378
 
 
379
 
        if (!global_proxy_context.x_dpy) {
380
 
            global_proxy_context.x_dpy = XOpenDisplay(NULL);
381
 
        }
382
 
 
383
257
        backend_extensions = pfnProxyQueryExtensionsString(
384
 
                                 global_proxy_context.x_dpy,
385
 
                                 DefaultScreen(global_proxy_context.x_dpy));
 
258
                                 display,
 
259
                                 DefaultScreen(display));
386
260
    } else if (global_proxy_context.current_backend == OPENGL_ES20_BACKEND &&
387
 
               pfnProxyEGLQueryString) {
388
 
 
389
 
        backend_extensions = pfnProxyEGLQueryString(
390
 
                                (EGLDisplay)global_proxy_context.egl_dpy,
 
261
               pfnProxyEglQueryString) {
 
262
        backend_extensions = pfnProxyEglQueryString(
 
263
                                (EGLDisplay)display,
391
264
                                EGL_EXTENSIONS);
392
265
    }
393
266
 
403
276
    return GL_FALSE;
404
277
}
405
278
 
406
 
void *glProxyGetExtProcAddr(const char *extension, const char *name)
407
 
{
408
 
    if (!glProxyHasExtension(extension))
 
279
void *glProxyGetExtProcAddr(void *display, const char *extension, const char *name) {
 
280
    if (!glProxyHasExtension(display, extension))
409
281
        return NULL;
410
282
 
411
 
    if (pfnProxyEGLGetProcAddress) {
412
 
                return (*pfnProxyEGLGetProcAddress)(name);
413
 
        }
414
 
        else if (pfnProxyGLXGetProcAddress) {
415
 
                return (*pfnProxyGLXGetProcAddress)((const GLubyte *)name);
416
 
        }
417
 
        else if (pfnProxyGLXGetProcAddressARB) {
418
 
                return (*pfnProxyGLXGetProcAddressARB)((const GLubyte *)name);
419
 
        }
 
283
    if (pfnProxyEglGetProcAddress) {
 
284
        return (*pfnProxyEglGetProcAddress)(name);
 
285
    } else if (pfnProxyGLXGetProcAddress) {
 
286
        return (*pfnProxyGLXGetProcAddress)((const GLubyte *) name);
 
287
    } else if (pfnProxyGLXGetProcAddressARB) {
 
288
        return (*pfnProxyGLXGetProcAddressARB)((const GLubyte *) name);
 
289
    }
420
290
 
421
291
    return NULL;
422
292
}
423
293
 
424
 
static const char *glProxyGetGLRenderer(Display *dpy)
425
 
{
426
 
        int scrnum;
427
 
        Window root;
428
 
        const char *renderer = NULL;
429
 
 
430
 
        GLXContext glx_ctx;
431
 
        int attribs[] = {
432
 
                GLX_RGBA,
433
 
                None };
434
 
        XVisualInfo *visinfo = NULL;
435
 
 
436
 
        scrnum = DefaultScreen(dpy);
437
 
        root = RootWindow(dpy, scrnum);
438
 
 
439
 
        visinfo = (*pfnProxyChooseVisual)(dpy, scrnum, attribs);
440
 
 
441
 
        if (!visinfo) {
442
 
                printf("failed to get visual\n");
443
 
                return NULL;
444
 
        }
445
 
 
446
 
        glx_ctx = (*pfnProxyCreateContext)(dpy, visinfo, NULL, True);
447
 
        if (!glx_ctx) {
448
 
                printf("failed to create GLX context\n");
449
 
                return NULL;
450
 
        }
451
 
 
452
 
        (*pfnProxyMakeCurrent)(dpy, root, glx_ctx);
453
 
 
454
 
        renderer = (const char *)(*pfnProxyGetString)(GL_RENDERER);
455
 
 
456
 
        (*pfnProxyMakeCurrent)(dpy, None, NULL);
457
 
 
458
 
        (*pfnProxyDestroyContext)(dpy, glx_ctx);
459
 
 
460
 
        XFree(visinfo);
461
 
 
462
 
        return renderer;
463
 
}
464
 
 
465
294
static void glProxyBackendSelection(PROXY_BACKEND_OPTION *pProxyBackend, PROXY_CONTEXT *proxy_context)
466
295
{
467
 
        PROXY_BACKEND_OPTION option = *pProxyBackend;
468
 
        const char *gl_renderer = NULL;
469
 
        const char *gles2_renderer = NULL;
470
 
 
471
 
        if (OPENGL_BACKEND == option) {
472
 
                if ((proxy_context->gl_handle = glProxyOpenLibrary(opengl_libraries[OPENGL_BACKEND]))) {
473
 
                        *pProxyBackend = OPENGL_BACKEND;
474
 
                }
475
 
                else if ((proxy_context->gles2_handle = glProxyOpenLibrary(opengl_libraries[OPENGL_ES20_BACKEND]))) {
476
 
                        *pProxyBackend = OPENGL_ES20_BACKEND;
477
 
                }
478
 
                else {
479
 
                        *pProxyBackend = UNKNOWN_BACKEND;
480
 
                }
481
 
        } else if (OPENGL_ES20_BACKEND == option) {
482
 
                if ((proxy_context->gles2_handle = glProxyOpenLibrary(opengl_libraries[OPENGL_ES20_BACKEND]))) {
483
 
                        *pProxyBackend = OPENGL_ES20_BACKEND;
484
 
                }
485
 
                else if ((proxy_context->gl_handle = glProxyOpenLibrary(opengl_libraries[OPENGL_BACKEND]))) {
486
 
                        *pProxyBackend = OPENGL_BACKEND;
487
 
                }
488
 
                else {
489
 
                        *pProxyBackend = UNKNOWN_BACKEND;
490
 
                }
491
 
        } else {
492
 
                /* Select backend automatically */
493
 
                proxy_context->gles2_handle = glProxyOpenLibrary(opengl_libraries[OPENGL_ES20_BACKEND]);
494
 
                proxy_context->egl_handle = glProxyOpenLibrary(LIBEGL_PATH);
495
 
                proxy_context->gl_handle = glProxyOpenLibrary(opengl_libraries[OPENGL_BACKEND]);
496
 
 
497
 
#if 1 
498
 
                /* There is a bug for mesa driver to get GL and GLES2 renderer info in one process
499
 
                 * https://bugs.freedesktop.org/show_bug.cgi?id=32285
500
 
                 */
501
 
 
502
 
                Display *dpy = XOpenDisplay(NULL);
503
 
 
504
 
                if (NULL == dpy) {
505
 
                        printf("failed to open display\n");
506
 
                        *pProxyBackend = UNKNOWN_BACKEND;
507
 
                        return;
508
 
                }
509
 
 
510
 
                proxy_context->x_dpy = dpy;
511
 
 
512
 
                /* Try to get the gles2 renderer info */
513
 
                if (proxy_context->egl_handle && proxy_context->gles2_handle) {
514
 
                        /* Resolve EGL APIs for create rendering context to get GL_RENDERER */
515
 
                        pfnProxyEGLGetDisplay = dlsym(proxy_context->egl_handle, "eglGetDisplay");
516
 
                        pfnProxyEGLInitialize = dlsym(proxy_context->egl_handle, "eglInitialize");
517
 
                        pfnProxyEGLChooseConfig = dlsym(proxy_context->egl_handle, "eglChooseConfig");
518
 
                        pfnProxyEGLCreateContext = dlsym(proxy_context->egl_handle, "eglCreateContext");
519
 
                        pfnProxyEGLCreatePbufferSurface = dlsym(proxy_context->egl_handle, "eglCreatePbufferSurface");
520
 
                        pfnProxyEGLMakeCurrent = dlsym(proxy_context->egl_handle, "eglMakeCurrent");
521
 
                        pfnProxyEGLDestroyContext = dlsym(proxy_context->egl_handle, "eglDestroyContext");
522
 
                        pfnProxyEGLDestroySurface = dlsym(proxy_context->egl_handle, "eglDestroySurface");
523
 
                        pfnProxyEGLTerminate = dlsym(proxy_context->egl_handle, "eglTerminate");
524
 
 
525
 
                        /* Resolve glGetString */
526
 
                        pfnProxyGetString = dlsym(proxy_context->gles2_handle, "glGetString");
527
 
 
528
 
                        CreateEGLRenderingContext(dpy, proxy_context);
529
 
 
530
 
                        gles2_renderer = (const char *)pfnProxyGetString(GL_RENDERER);
531
 
 
532
 
                        /* Reset the function pointers */
533
 
                        pfnProxyGetString = NULL;
534
 
                }
535
 
 
536
 
                printf("OpenGL ES2.0 Renderer: %s\n", gles2_renderer ? gles2_renderer : "Not Available");
537
 
 
538
 
                /* Try to get the opengl renderer info if available */
539
 
                if (proxy_context->gl_handle) {
540
 
                        /* Resolve GLX APIs needed for create rendering context */
541
 
                        pfnProxyChooseVisual = dlsym(proxy_context->gl_handle, "glXChooseVisual");
542
 
                        pfnProxyCreateContext = dlsym(proxy_context->gl_handle, "glXCreateContext");
543
 
                        pfnProxyMakeCurrent = dlsym(proxy_context->gl_handle, "glXMakeCurrent");
544
 
                        pfnProxyDestroyContext = dlsym(proxy_context->gl_handle, "glXDestroyContext");
545
 
 
546
 
                        /* Resolve glGetString */
547
 
                        pfnProxyGetString = dlsym(proxy_context->gl_handle, "glGetString");
548
 
 
549
 
                        gl_renderer = glProxyGetGLRenderer(dpy);
550
 
 
551
 
                        /* Reset the function pointers */
552
 
                        pfnProxyGetString = NULL;
553
 
                        pfnProxyChooseVisual = NULL;
554
 
                        pfnProxyCreateContext = NULL;
555
 
                        pfnProxyMakeCurrent = NULL;
556
 
                        pfnProxyDestroyContext = NULL;
557
 
                }
558
 
 
559
 
                printf("OpenGL Renderer: %s\n", gl_renderer ? gl_renderer : "Not Available");
560
 
 
561
 
                if (gles2_renderer && gl_renderer) {
562
 
                        if (strstr(gl_renderer, "Soft") || strstr(gl_renderer, "soft")) {
563
 
                                /* if OpenGL renderer is SW, use GLES2 renderer */
564
 
                                *pProxyBackend = OPENGL_ES20_BACKEND;
565
 
                        }
566
 
                        else if (strstr(gles2_renderer, "Soft") || strstr(gles2_renderer, "soft")) {
567
 
                                /* if OpenGL renderer is HW, GLES2 renderer is SW, use OpenGL renderer */
568
 
                                *pProxyBackend = OPENGL_BACKEND;
569
 
                        }
570
 
                        else {
571
 
                                /* if both renderers are HW, use GLES2 renderer */
572
 
                                *pProxyBackend = OPENGL_ES20_BACKEND;
573
 
                        }
574
 
                }
575
 
                else if (gles2_renderer) {
576
 
                        *pProxyBackend = OPENGL_ES20_BACKEND;
577
 
                }
578
 
                else if (gl_renderer) {
579
 
                        *pProxyBackend = OPENGL_BACKEND;
580
 
                }
581
 
                else {
582
 
                        *pProxyBackend = UNKNOWN_BACKEND;
583
 
                }
584
 
#else
585
 
                if (proxy_context->gles2_handle) {
586
 
                        /* Use GLES2 by default if available */
587
 
                        *pProxyBackend = OPENGL_ES20_BACKEND;
588
 
                }
589
 
                else if (proxy_context->gl_handle) {
590
 
                        *pProxyBackend = OPENGL_BACKEND;
591
 
                }
592
 
                else {
593
 
                        *pProxyBackend = UNKNOWN_BACKEND;
594
 
                }
595
 
                
596
 
#endif
597
 
 
598
 
                if (OPENGL_ES20_BACKEND == *pProxyBackend) {
599
 
                        if (proxy_context->gl_handle) {
600
 
                                glProxyCloseLibrary(proxy_context->gl_handle);
601
 
                                proxy_context->gl_handle = NULL;
602
 
                        }
603
 
                }
604
 
                else if (OPENGL_BACKEND == *pProxyBackend) {
605
 
                        if (proxy_context->egl_ctx) {
606
 
                                DestroyEGLRenderingContext(proxy_context);
607
 
                                pfnProxyEGLGetDisplay = NULL;
608
 
                                pfnProxyEGLInitialize = NULL;
609
 
                                pfnProxyEGLChooseConfig = NULL;
610
 
                                pfnProxyEGLCreateContext = NULL;
611
 
                                pfnProxyEGLCreatePbufferSurface = NULL;
612
 
                                pfnProxyEGLMakeCurrent = NULL;
613
 
                                pfnProxyEGLDestroyContext = NULL;
614
 
                                pfnProxyEGLDestroySurface = NULL;
615
 
                                pfnProxyEGLTerminate = NULL;
616
 
                        }
617
 
 
618
 
                        if (proxy_context->egl_handle) {
619
 
                                glProxyCloseLibrary(proxy_context->egl_handle);
620
 
                                proxy_context->egl_handle = NULL;
621
 
                        }
622
 
 
623
 
                        if (proxy_context->gles2_handle) {
624
 
                                glProxyCloseLibrary(proxy_context->gles2_handle);
625
 
                                proxy_context->gles2_handle = NULL;
626
 
                        }
627
 
                }
628
 
        }
629
 
 
630
 
        proxy_context->current_backend = *pProxyBackend;
 
296
    PROXY_BACKEND_OPTION option = *pProxyBackend;
 
297
 
 
298
    if (OPENGL_BACKEND == option) {
 
299
        if ((proxy_context->gl_handle = glProxyOpenLibrary(
 
300
                opengl_libraries[OPENGL_BACKEND]))) {
 
301
            *pProxyBackend = OPENGL_BACKEND;
 
302
        } else if ((proxy_context->gles2_handle = glProxyOpenLibrary(
 
303
                opengl_libraries[OPENGL_ES20_BACKEND]))) {
 
304
            *pProxyBackend = OPENGL_ES20_BACKEND;
 
305
        } else {
 
306
            *pProxyBackend = UNKNOWN_BACKEND;
 
307
        }
 
308
    } else if (OPENGL_ES20_BACKEND == option) {
 
309
        if ((proxy_context->gles2_handle = glProxyOpenLibrary(
 
310
                opengl_libraries[OPENGL_ES20_BACKEND]))) {
 
311
            *pProxyBackend = OPENGL_ES20_BACKEND;
 
312
        } else if ((proxy_context->gl_handle = glProxyOpenLibrary(
 
313
                opengl_libraries[OPENGL_BACKEND]))) {
 
314
            *pProxyBackend = OPENGL_BACKEND;
 
315
        } else {
 
316
            *pProxyBackend = UNKNOWN_BACKEND;
 
317
        }
 
318
    } else {
 
319
        /* Select backend automatically */
 
320
        proxy_context->gles2_handle = glProxyOpenLibrary(
 
321
                opengl_libraries[OPENGL_ES20_BACKEND]);
 
322
        proxy_context->egl_handle = glProxyOpenLibrary(LIBEGL_PATH);
 
323
        proxy_context->gl_handle = glProxyOpenLibrary(
 
324
                opengl_libraries[OPENGL_BACKEND]);
 
325
 
 
326
        if (proxy_context->gles2_handle) {
 
327
            /* Use GLES2 by default if available */
 
328
            *pProxyBackend = OPENGL_ES20_BACKEND;
 
329
        } else if (proxy_context->gl_handle) {
 
330
            *pProxyBackend = OPENGL_BACKEND;
 
331
        } else {
 
332
            *pProxyBackend = UNKNOWN_BACKEND;
 
333
        }
 
334
 
 
335
        if (OPENGL_ES20_BACKEND == *pProxyBackend) {
 
336
            if (proxy_context->gl_handle) {
 
337
                glProxyCloseLibrary(proxy_context->gl_handle);
 
338
                proxy_context->gl_handle = NULL;
 
339
            }
 
340
        } else if (OPENGL_BACKEND == *pProxyBackend) {
 
341
            if (proxy_context->egl_handle) {
 
342
                glProxyCloseLibrary(proxy_context->egl_handle);
 
343
                proxy_context->egl_handle = NULL;
 
344
            }
 
345
 
 
346
            if (proxy_context->gles2_handle) {
 
347
                glProxyCloseLibrary(proxy_context->gles2_handle);
 
348
                proxy_context->gles2_handle = NULL;
 
349
            }
 
350
        }
 
351
    }
 
352
 
 
353
    proxy_context->current_backend = *pProxyBackend;
631
354
}
632
355
 
633
356
static int glProxyCoreInit(void *handle)
634
357
{
635
358
        if (NULL == handle) {
636
 
                return -1;
637
 
        }
638
 
 
639
 
        pfnProxyActiveTexture = glProxyGetProcAddr(handle, "glActiveTexture");
640
 
        pfnProxyAttachShader = glProxyGetProcAddr(handle, "glAttachShader");
641
 
        pfnProxyBindAttribLocation = glProxyGetProcAddr(handle, "glBindAttribLocation");
642
 
        pfnProxyBindBuffer = glProxyGetProcAddr(handle, "glBindBuffer");
643
 
        pfnProxyBindFramebuffer = glProxyGetProcAddr(handle, "glBindFramebuffer");
644
 
        pfnProxyBindRenderbuffer = glProxyGetProcAddr(handle, "glBindRenderbuffer");
645
 
        pfnProxyBindTexture = glProxyGetProcAddr(handle, "glBindTexture");
646
 
        pfnProxyBlendColor = glProxyGetProcAddr(handle, "glBlendColor");
647
 
        pfnProxyBlendEquation = glProxyGetProcAddr(handle, "glBlendEquation");
648
 
        pfnProxyBlendEquationSeparate = glProxyGetProcAddr(handle, "glBlendEquationSeparate");
649
 
        pfnProxyBlendFunc = glProxyGetProcAddr(handle, "glBlendFunc");
650
 
        pfnProxyBlendFuncSeparate = glProxyGetProcAddr(handle, "glBlendFuncSeparate");
651
 
        pfnProxyBufferData = glProxyGetProcAddr(handle, "glBufferData");
652
 
        pfnProxyBufferSubData = glProxyGetProcAddr(handle, "glBufferSubData");
653
 
        pfnProxyCheckFramebufferStatus = glProxyGetProcAddr(handle, "glCheckFramebufferStatus");
654
 
        pfnProxyClear = glProxyGetProcAddr(handle, "glClear");
655
 
        pfnProxyClearColor = glProxyGetProcAddr(handle, "glClearColor");
656
 
        pfnProxyClearDepthf = glProxyGetProcAddr(handle, "glClearDepthf");
657
 
        pfnProxyClearStencil = glProxyGetProcAddr(handle, "glClearStencil");
658
 
        pfnProxyColorMask = glProxyGetProcAddr(handle, "glColorMask");
659
 
        pfnProxyCompileShader = glProxyGetProcAddr(handle, "glCompileShader");
660
 
        pfnProxyCompressedTexImage2D = glProxyGetProcAddr(handle, "glCompressedTexImage2D");
661
 
        pfnProxyCompressedTexSubImage2D = glProxyGetProcAddr(handle, "glCompressedTexSubImage2D");
662
 
        pfnProxyCopyTexImage2D = glProxyGetProcAddr(handle, "glCopyTexImage2D");
663
 
        pfnProxyCopyTexSubImage2D = glProxyGetProcAddr(handle, "glCopyTexSubImage2D");
664
 
        pfnProxyCreateProgram = glProxyGetProcAddr(handle, "glCreateProgram");
665
 
        pfnProxyCreateShader = glProxyGetProcAddr(handle, "glCreateShader");
666
 
        pfnProxyCullFace = glProxyGetProcAddr(handle, "glCullFace");
667
 
        pfnProxyDeleteBuffers = glProxyGetProcAddr(handle, "glDeleteBuffers");
668
 
        pfnProxyDeleteFramebuffers = glProxyGetProcAddr(handle, "glDeleteFramebuffers");
669
 
        pfnProxyDeleteProgram = glProxyGetProcAddr(handle, "glDeleteProgram");
670
 
        pfnProxyDeleteRenderbuffers = glProxyGetProcAddr(handle, "glDeleteRenderbuffers");
671
 
        pfnProxyDeleteShader = glProxyGetProcAddr(handle, "glDeleteShader");
672
 
        pfnProxyDeleteTextures = glProxyGetProcAddr(handle, "glDeleteTextures");
673
 
        pfnProxyDepthFunc = glProxyGetProcAddr(handle, "glDepthFunc");
674
 
        pfnProxyDepthMask = glProxyGetProcAddr(handle, "glDepthMask");
675
 
        pfnProxyDepthRangef = glProxyGetProcAddr(handle, "glDepthRangef");
676
 
        pfnProxyDetachShader = glProxyGetProcAddr(handle, "glDetachShader");
677
 
        pfnProxyDisable = glProxyGetProcAddr(handle, "glDisable");
678
 
        pfnProxyDisableVertexAttribArray = glProxyGetProcAddr(handle, "glDisableVertexAttribArray");
679
 
        pfnProxyDrawArrays = glProxyGetProcAddr(handle, "glDrawArrays");
680
 
        pfnProxyDrawElements = glProxyGetProcAddr(handle, "glDrawElements");
681
 
        pfnProxyEnable = glProxyGetProcAddr(handle, "glEnable");
682
 
        pfnProxyEnableVertexAttribArray = glProxyGetProcAddr(handle, "glEnableVertexAttribArray");
683
 
        pfnProxyFinish = glProxyGetProcAddr(handle, "glFinish");
684
 
        pfnProxyFlush = glProxyGetProcAddr(handle, "glFlush");
685
 
        pfnProxyFramebufferRenderbuffer = glProxyGetProcAddr(handle, "glFramebufferRenderbuffer");
686
 
        pfnProxyFramebufferTexture2D = glProxyGetProcAddr(handle, "glFramebufferTexture2D");
687
 
        pfnProxyFrontFace = glProxyGetProcAddr(handle, "glFrontFace");
688
 
        pfnProxyGenBuffers = glProxyGetProcAddr(handle, "glGenBuffers");
689
 
        pfnProxyGenerateMipmap = glProxyGetProcAddr(handle, "glGenerateMipmap");
690
 
        pfnProxyGenFramebuffers = glProxyGetProcAddr(handle, "glGenFramebuffers");
691
 
        pfnProxyGenRenderbuffers = glProxyGetProcAddr(handle, "glGenRenderbuffers");
692
 
        pfnProxyGenTextures = glProxyGetProcAddr(handle, "glGenTextures");
693
 
        pfnProxyGetActiveAttrib = glProxyGetProcAddr(handle, "glGetActiveAttrib");
694
 
        pfnProxyGetActiveUniform = glProxyGetProcAddr(handle, "glGetActiveUniform");
695
 
        pfnProxyGetAttachedShaders = glProxyGetProcAddr(handle, "glGetAttachedShaders");
696
 
        pfnProxyGetAttribLocation = glProxyGetProcAddr(handle, "glGetAttribLocation");
697
 
        pfnProxyGetBooleanv = glProxyGetProcAddr(handle, "glGetBooleanv");
698
 
        pfnProxyGetBufferParameteriv = glProxyGetProcAddr(handle, "glGetBufferParameteriv");
699
 
        pfnProxyGetError = glProxyGetProcAddr(handle, "glGetError");
700
 
        pfnProxyGetFloatv = glProxyGetProcAddr(handle, "glGetFloatv");
701
 
        pfnProxyGetFramebufferAttachmentParameteriv = glProxyGetProcAddr(handle, "glGetFramebufferAttachmentParameteriv");
702
 
        pfnProxyGetIntegerv = glProxyGetProcAddr(handle, "glGetIntegerv");
703
 
        pfnProxyGetProgramiv = glProxyGetProcAddr(handle, "glGetProgramiv");
704
 
        pfnProxyGetProgramInfoLog = glProxyGetProcAddr(handle, "glGetProgramInfoLog");
705
 
        pfnProxyGetRenderbufferParameteriv = glProxyGetProcAddr(handle, "glGetRenderbufferParameteriv");
706
 
        pfnProxyGetShaderiv = glProxyGetProcAddr(handle, "glGetShaderiv");
707
 
        pfnProxyGetShaderInfoLog = glProxyGetProcAddr(handle, "glGetShaderInfoLog");
708
 
        pfnProxyGetShaderPrecisionFormat = glProxyGetProcAddr(handle, "glGetShaderPrecisionFormat");
709
 
        pfnProxyGetShaderSource = glProxyGetProcAddr(handle, "glGetShaderSource");
710
 
        pfnProxyGetString = glProxyGetProcAddr(handle, "glGetString");
711
 
        pfnProxyGetTexParameterfv = glProxyGetProcAddr(handle, "glGetTexParameterfv");
712
 
        pfnProxyGetTexParameteriv = glProxyGetProcAddr(handle, "glGetTexParameteriv");
713
 
        pfnProxyGetUniformfv = glProxyGetProcAddr(handle, "glGetUniformfv");
714
 
        pfnProxyGetUniformiv = glProxyGetProcAddr(handle, "glGetUniformiv");
715
 
        pfnProxyGetUniformLocation = glProxyGetProcAddr(handle, "glGetUniformLocation");
716
 
        pfnProxyGetVertexAttribfv = glProxyGetProcAddr(handle, "glGetVertexAttribfv");
717
 
        pfnProxyGetVertexAttribiv = glProxyGetProcAddr(handle, "glGetVertexAttribiv");
718
 
        pfnProxyGetVertexAttribPointerv = glProxyGetProcAddr(handle, "glGetVertexAttribPointerv");
719
 
        pfnProxyHint = glProxyGetProcAddr(handle, "glHint");
720
 
        pfnProxyIsBuffer = glProxyGetProcAddr(handle, "glIsBuffer");
721
 
        pfnProxyIsEnabled = glProxyGetProcAddr(handle, "glIsEnabled");
722
 
        pfnProxyIsFramebuffer = glProxyGetProcAddr(handle, "glIsFramebuffer");
723
 
        pfnProxyIsProgram = glProxyGetProcAddr(handle, "glIsProgram");
724
 
        pfnProxyIsRenderbuffer = glProxyGetProcAddr(handle, "glIsRenderbuffer");
725
 
        pfnProxyIsShader = glProxyGetProcAddr(handle, "glIsShader");
726
 
        pfnProxyIsTexture = glProxyGetProcAddr(handle, "glIsTexture");
727
 
        pfnProxyLineWidth = glProxyGetProcAddr(handle, "glLineWidth");
728
 
        pfnProxyLinkProgram = glProxyGetProcAddr(handle, "glLinkProgram");
729
 
        pfnProxyPixelStorei = glProxyGetProcAddr(handle, "glPixelStorei");
730
 
        pfnProxyPolygonOffset = glProxyGetProcAddr(handle, "glPolygonOffset");
731
 
        pfnProxyReadPixels = glProxyGetProcAddr(handle, "glReadPixels");
732
 
        pfnProxyReleaseShaderCompiler = glProxyGetProcAddr(handle, "glReleaseShaderCompiler");
733
 
        pfnProxyRenderbufferStorage = glProxyGetProcAddr(handle, "glRenderbufferStorage");
734
 
        pfnProxySampleCoverage = glProxyGetProcAddr(handle, "glSampleCoverage");
735
 
        pfnProxyScissor = glProxyGetProcAddr(handle, "glScissor");
736
 
        pfnProxyShaderBinary = glProxyGetProcAddr(handle, "glShaderBinary");
737
 
        pfnProxyShaderSource = glProxyGetProcAddr(handle, "glShaderSource");
738
 
        pfnProxyStencilFunc = glProxyGetProcAddr(handle, "glStencilFunc");
739
 
        pfnProxyStencilFuncSeparate = glProxyGetProcAddr(handle, "glStencilFuncSeparate");
740
 
        pfnProxyStencilMask = glProxyGetProcAddr(handle, "glStencilMask");
741
 
        pfnProxyStencilMaskSeparate = glProxyGetProcAddr(handle, "glStencilMaskSeparate");
742
 
        pfnProxyStencilOp = glProxyGetProcAddr(handle, "glStencilOp");
743
 
        pfnProxyStencilOpSeparate = glProxyGetProcAddr(handle, "glStencilOpSeparate");
744
 
        pfnProxyTexImage2D = glProxyGetProcAddr(handle, "glTexImage2D");
745
 
        pfnProxyTexParameterf = glProxyGetProcAddr(handle, "glTexParameterf");
746
 
        pfnProxyTexParameterfv = glProxyGetProcAddr(handle, "glTexParameterfv");
747
 
        pfnProxyTexParameteri = glProxyGetProcAddr(handle, "glTexParameteri");
748
 
        pfnProxyTexParameteriv = glProxyGetProcAddr(handle, "glTexParameteriv");
749
 
        pfnProxyTexSubImage2D = glProxyGetProcAddr(handle, "glTexSubImage2D");
750
 
        pfnProxyUniform1f = glProxyGetProcAddr(handle, "glUniform1f");
751
 
        pfnProxyUniform1fv = glProxyGetProcAddr(handle, "glUniform1fv");
752
 
        pfnProxyUniform1i = glProxyGetProcAddr(handle, "glUniform1i");
753
 
        pfnProxyUniform1iv = glProxyGetProcAddr(handle, "glUniform1iv");
754
 
        pfnProxyUniform2f = glProxyGetProcAddr(handle, "glUniform2f");
755
 
        pfnProxyUniform2fv = glProxyGetProcAddr(handle, "glUniform2fv");
756
 
        pfnProxyUniform2i = glProxyGetProcAddr(handle, "glUniform2i");
757
 
        pfnProxyUniform2iv = glProxyGetProcAddr(handle, "glUniform2iv");
758
 
        pfnProxyUniform3f = glProxyGetProcAddr(handle, "glUniform3f");
759
 
        pfnProxyUniform3fv = glProxyGetProcAddr(handle, "glUniform3fv");
760
 
        pfnProxyUniform3i = glProxyGetProcAddr(handle, "glUniform3i");
761
 
        pfnProxyUniform3iv = glProxyGetProcAddr(handle, "glUniform3iv");
762
 
        pfnProxyUniform4f = glProxyGetProcAddr(handle, "glUniform4f");
763
 
        pfnProxyUniform4fv = glProxyGetProcAddr(handle, "glUniform4fv");
764
 
        pfnProxyUniform4i = glProxyGetProcAddr(handle, "glUniform4i");
765
 
        pfnProxyUniform4iv = glProxyGetProcAddr(handle, "glUniform4iv");
766
 
        pfnProxyUniformMatrix2fv = glProxyGetProcAddr(handle, "glUniformMatrix2fv");
767
 
        pfnProxyUniformMatrix3fv = glProxyGetProcAddr(handle, "glUniformMatrix3fv");
768
 
        pfnProxyUniformMatrix4fv = glProxyGetProcAddr(handle, "glUniformMatrix4fv");
769
 
        pfnProxyUseProgram = glProxyGetProcAddr(handle, "glUseProgram");
770
 
        pfnProxyValidateProgram = glProxyGetProcAddr(handle, "glValidateProgram");
771
 
        pfnProxyVertexAttrib1f = glProxyGetProcAddr(handle, "glVertexAttrib1f");
772
 
        pfnProxyVertexAttrib1fv = glProxyGetProcAddr(handle, "glVertexAttrib1fv");
773
 
        pfnProxyVertexAttrib2f = glProxyGetProcAddr(handle, "glVertexAttrib2f");
774
 
        pfnProxyVertexAttrib2fv = glProxyGetProcAddr(handle, "glVertexAttrib2fv");
775
 
        pfnProxyVertexAttrib3f = glProxyGetProcAddr(handle, "glVertexAttrib3f");
776
 
        pfnProxyVertexAttrib3fv = glProxyGetProcAddr(handle, "glVertexAttrib3fv");
777
 
        pfnProxyVertexAttrib4f = glProxyGetProcAddr(handle, "glVertexAttrib4f");
778
 
        pfnProxyVertexAttrib4fv = glProxyGetProcAddr(handle, "glVertexAttrib4fv");
779
 
        pfnProxyVertexAttribPointer = glProxyGetProcAddr(handle, "glVertexAttribPointer");
780
 
        pfnProxyViewport = glProxyGetProcAddr(handle, "glViewport");
781
 
        
782
 
        return 0;
 
359
        return -1;
 
360
    }
 
361
 
 
362
    pfnProxyActiveTexture = glProxyGetProcAddr(handle, "glActiveTexture");
 
363
    pfnProxyAttachShader = glProxyGetProcAddr(handle, "glAttachShader");
 
364
    pfnProxyBindAttribLocation = glProxyGetProcAddr(handle,
 
365
            "glBindAttribLocation");
 
366
    pfnProxyBindBuffer = glProxyGetProcAddr(handle, "glBindBuffer");
 
367
    pfnProxyBindFramebuffer = glProxyGetProcAddr(handle, "glBindFramebuffer");
 
368
    pfnProxyBindRenderbuffer = glProxyGetProcAddr(handle, "glBindRenderbuffer");
 
369
    pfnProxyBindTexture = glProxyGetProcAddr(handle, "glBindTexture");
 
370
    pfnProxyBlendColor = glProxyGetProcAddr(handle, "glBlendColor");
 
371
    pfnProxyBlendEquation = glProxyGetProcAddr(handle, "glBlendEquation");
 
372
    pfnProxyBlendEquationSeparate = glProxyGetProcAddr(handle,
 
373
            "glBlendEquationSeparate");
 
374
    pfnProxyBlendFunc = glProxyGetProcAddr(handle, "glBlendFunc");
 
375
    pfnProxyBlendFuncSeparate = glProxyGetProcAddr(handle,
 
376
            "glBlendFuncSeparate");
 
377
    pfnProxyBufferData = glProxyGetProcAddr(handle, "glBufferData");
 
378
    pfnProxyBufferSubData = glProxyGetProcAddr(handle, "glBufferSubData");
 
379
    pfnProxyCheckFramebufferStatus = glProxyGetProcAddr(handle,
 
380
            "glCheckFramebufferStatus");
 
381
    pfnProxyClear = glProxyGetProcAddr(handle, "glClear");
 
382
    pfnProxyClearColor = glProxyGetProcAddr(handle, "glClearColor");
 
383
    pfnProxyClearDepthf = glProxyGetProcAddr(handle, "glClearDepthf");
 
384
    pfnProxyClearStencil = glProxyGetProcAddr(handle, "glClearStencil");
 
385
    pfnProxyColorMask = glProxyGetProcAddr(handle, "glColorMask");
 
386
    pfnProxyCompileShader = glProxyGetProcAddr(handle, "glCompileShader");
 
387
    pfnProxyCompressedTexImage2D = glProxyGetProcAddr(handle,
 
388
            "glCompressedTexImage2D");
 
389
    pfnProxyCompressedTexSubImage2D = glProxyGetProcAddr(handle,
 
390
            "glCompressedTexSubImage2D");
 
391
    pfnProxyCopyTexImage2D = glProxyGetProcAddr(handle, "glCopyTexImage2D");
 
392
    pfnProxyCopyTexSubImage2D = glProxyGetProcAddr(handle,
 
393
            "glCopyTexSubImage2D");
 
394
    pfnProxyCreateProgram = glProxyGetProcAddr(handle, "glCreateProgram");
 
395
    pfnProxyCreateShader = glProxyGetProcAddr(handle, "glCreateShader");
 
396
    pfnProxyCullFace = glProxyGetProcAddr(handle, "glCullFace");
 
397
    pfnProxyDeleteBuffers = glProxyGetProcAddr(handle, "glDeleteBuffers");
 
398
    pfnProxyDeleteFramebuffers = glProxyGetProcAddr(handle,
 
399
            "glDeleteFramebuffers");
 
400
    pfnProxyDeleteProgram = glProxyGetProcAddr(handle, "glDeleteProgram");
 
401
    pfnProxyDeleteRenderbuffers = glProxyGetProcAddr(handle,
 
402
            "glDeleteRenderbuffers");
 
403
    pfnProxyDeleteShader = glProxyGetProcAddr(handle, "glDeleteShader");
 
404
    pfnProxyDeleteTextures = glProxyGetProcAddr(handle, "glDeleteTextures");
 
405
    pfnProxyDepthFunc = glProxyGetProcAddr(handle, "glDepthFunc");
 
406
    pfnProxyDepthMask = glProxyGetProcAddr(handle, "glDepthMask");
 
407
    pfnProxyDepthRangef = glProxyGetProcAddr(handle, "glDepthRangef");
 
408
    pfnProxyDetachShader = glProxyGetProcAddr(handle, "glDetachShader");
 
409
    pfnProxyDisable = glProxyGetProcAddr(handle, "glDisable");
 
410
    pfnProxyDisableVertexAttribArray = glProxyGetProcAddr(handle,
 
411
            "glDisableVertexAttribArray");
 
412
    pfnProxyDrawArrays = glProxyGetProcAddr(handle, "glDrawArrays");
 
413
    pfnProxyDrawElements = glProxyGetProcAddr(handle, "glDrawElements");
 
414
    pfnProxyEnable = glProxyGetProcAddr(handle, "glEnable");
 
415
    pfnProxyEnableVertexAttribArray = glProxyGetProcAddr(handle,
 
416
            "glEnableVertexAttribArray");
 
417
    pfnProxyFinish = glProxyGetProcAddr(handle, "glFinish");
 
418
    pfnProxyFlush = glProxyGetProcAddr(handle, "glFlush");
 
419
    pfnProxyFramebufferRenderbuffer = glProxyGetProcAddr(handle,
 
420
            "glFramebufferRenderbuffer");
 
421
    pfnProxyFramebufferTexture2D = glProxyGetProcAddr(handle,
 
422
            "glFramebufferTexture2D");
 
423
    pfnProxyFrontFace = glProxyGetProcAddr(handle, "glFrontFace");
 
424
    pfnProxyGenBuffers = glProxyGetProcAddr(handle, "glGenBuffers");
 
425
    pfnProxyGenerateMipmap = glProxyGetProcAddr(handle, "glGenerateMipmap");
 
426
    pfnProxyGenFramebuffers = glProxyGetProcAddr(handle, "glGenFramebuffers");
 
427
    pfnProxyGenRenderbuffers = glProxyGetProcAddr(handle, "glGenRenderbuffers");
 
428
    pfnProxyGenTextures = glProxyGetProcAddr(handle, "glGenTextures");
 
429
    pfnProxyGetActiveAttrib = glProxyGetProcAddr(handle, "glGetActiveAttrib");
 
430
    pfnProxyGetActiveUniform = glProxyGetProcAddr(handle, "glGetActiveUniform");
 
431
    pfnProxyGetAttachedShaders = glProxyGetProcAddr(handle,
 
432
            "glGetAttachedShaders");
 
433
    pfnProxyGetAttribLocation = glProxyGetProcAddr(handle,
 
434
            "glGetAttribLocation");
 
435
    pfnProxyGetBooleanv = glProxyGetProcAddr(handle, "glGetBooleanv");
 
436
    pfnProxyGetBufferParameteriv = glProxyGetProcAddr(handle,
 
437
            "glGetBufferParameteriv");
 
438
    pfnProxyGetError = glProxyGetProcAddr(handle, "glGetError");
 
439
    pfnProxyGetFloatv = glProxyGetProcAddr(handle, "glGetFloatv");
 
440
    pfnProxyGetFramebufferAttachmentParameteriv = glProxyGetProcAddr(handle,
 
441
            "glGetFramebufferAttachmentParameteriv");
 
442
    pfnProxyGetIntegerv = glProxyGetProcAddr(handle, "glGetIntegerv");
 
443
    pfnProxyGetProgramiv = glProxyGetProcAddr(handle, "glGetProgramiv");
 
444
    pfnProxyGetProgramInfoLog = glProxyGetProcAddr(handle,
 
445
            "glGetProgramInfoLog");
 
446
    pfnProxyGetRenderbufferParameteriv = glProxyGetProcAddr(handle,
 
447
            "glGetRenderbufferParameteriv");
 
448
    pfnProxyGetShaderiv = glProxyGetProcAddr(handle, "glGetShaderiv");
 
449
    pfnProxyGetShaderInfoLog = glProxyGetProcAddr(handle, "glGetShaderInfoLog");
 
450
    pfnProxyGetShaderPrecisionFormat = glProxyGetProcAddr(handle,
 
451
            "glGetShaderPrecisionFormat");
 
452
    pfnProxyGetShaderSource = glProxyGetProcAddr(handle, "glGetShaderSource");
 
453
    pfnProxyGetString = glProxyGetProcAddr(handle, "glGetString");
 
454
    pfnProxyGetTexParameterfv = glProxyGetProcAddr(handle,
 
455
            "glGetTexParameterfv");
 
456
    pfnProxyGetTexParameteriv = glProxyGetProcAddr(handle,
 
457
            "glGetTexParameteriv");
 
458
    pfnProxyGetUniformfv = glProxyGetProcAddr(handle, "glGetUniformfv");
 
459
    pfnProxyGetUniformiv = glProxyGetProcAddr(handle, "glGetUniformiv");
 
460
    pfnProxyGetUniformLocation = glProxyGetProcAddr(handle,
 
461
            "glGetUniformLocation");
 
462
    pfnProxyGetVertexAttribfv = glProxyGetProcAddr(handle,
 
463
            "glGetVertexAttribfv");
 
464
    pfnProxyGetVertexAttribiv = glProxyGetProcAddr(handle,
 
465
            "glGetVertexAttribiv");
 
466
    pfnProxyGetVertexAttribPointerv = glProxyGetProcAddr(handle,
 
467
            "glGetVertexAttribPointerv");
 
468
    pfnProxyHint = glProxyGetProcAddr(handle, "glHint");
 
469
    pfnProxyIsBuffer = glProxyGetProcAddr(handle, "glIsBuffer");
 
470
    pfnProxyIsEnabled = glProxyGetProcAddr(handle, "glIsEnabled");
 
471
    pfnProxyIsFramebuffer = glProxyGetProcAddr(handle, "glIsFramebuffer");
 
472
    pfnProxyIsProgram = glProxyGetProcAddr(handle, "glIsProgram");
 
473
    pfnProxyIsRenderbuffer = glProxyGetProcAddr(handle, "glIsRenderbuffer");
 
474
    pfnProxyIsShader = glProxyGetProcAddr(handle, "glIsShader");
 
475
    pfnProxyIsTexture = glProxyGetProcAddr(handle, "glIsTexture");
 
476
    pfnProxyLineWidth = glProxyGetProcAddr(handle, "glLineWidth");
 
477
    pfnProxyLinkProgram = glProxyGetProcAddr(handle, "glLinkProgram");
 
478
    pfnProxyPixelStorei = glProxyGetProcAddr(handle, "glPixelStorei");
 
479
    pfnProxyPolygonOffset = glProxyGetProcAddr(handle, "glPolygonOffset");
 
480
    pfnProxyReadPixels = glProxyGetProcAddr(handle, "glReadPixels");
 
481
    pfnProxyReleaseShaderCompiler = glProxyGetProcAddr(handle,
 
482
            "glReleaseShaderCompiler");
 
483
    pfnProxyRenderbufferStorage = glProxyGetProcAddr(handle,
 
484
            "glRenderbufferStorage");
 
485
    pfnProxySampleCoverage = glProxyGetProcAddr(handle, "glSampleCoverage");
 
486
    pfnProxyScissor = glProxyGetProcAddr(handle, "glScissor");
 
487
    pfnProxyShaderBinary = glProxyGetProcAddr(handle, "glShaderBinary");
 
488
    pfnProxyShaderSource = glProxyGetProcAddr(handle, "glShaderSource");
 
489
    pfnProxyStencilFunc = glProxyGetProcAddr(handle, "glStencilFunc");
 
490
    pfnProxyStencilFuncSeparate = glProxyGetProcAddr(handle,
 
491
            "glStencilFuncSeparate");
 
492
    pfnProxyStencilMask = glProxyGetProcAddr(handle, "glStencilMask");
 
493
    pfnProxyStencilMaskSeparate = glProxyGetProcAddr(handle,
 
494
            "glStencilMaskSeparate");
 
495
    pfnProxyStencilOp = glProxyGetProcAddr(handle, "glStencilOp");
 
496
    pfnProxyStencilOpSeparate = glProxyGetProcAddr(handle,
 
497
            "glStencilOpSeparate");
 
498
    pfnProxyTexImage2D = glProxyGetProcAddr(handle, "glTexImage2D");
 
499
    pfnProxyTexParameterf = glProxyGetProcAddr(handle, "glTexParameterf");
 
500
    pfnProxyTexParameterfv = glProxyGetProcAddr(handle, "glTexParameterfv");
 
501
    pfnProxyTexParameteri = glProxyGetProcAddr(handle, "glTexParameteri");
 
502
    pfnProxyTexParameteriv = glProxyGetProcAddr(handle, "glTexParameteriv");
 
503
    pfnProxyTexSubImage2D = glProxyGetProcAddr(handle, "glTexSubImage2D");
 
504
    pfnProxyUniform1f = glProxyGetProcAddr(handle, "glUniform1f");
 
505
    pfnProxyUniform1fv = glProxyGetProcAddr(handle, "glUniform1fv");
 
506
    pfnProxyUniform1i = glProxyGetProcAddr(handle, "glUniform1i");
 
507
    pfnProxyUniform1iv = glProxyGetProcAddr(handle, "glUniform1iv");
 
508
    pfnProxyUniform2f = glProxyGetProcAddr(handle, "glUniform2f");
 
509
    pfnProxyUniform2fv = glProxyGetProcAddr(handle, "glUniform2fv");
 
510
    pfnProxyUniform2i = glProxyGetProcAddr(handle, "glUniform2i");
 
511
    pfnProxyUniform2iv = glProxyGetProcAddr(handle, "glUniform2iv");
 
512
    pfnProxyUniform3f = glProxyGetProcAddr(handle, "glUniform3f");
 
513
    pfnProxyUniform3fv = glProxyGetProcAddr(handle, "glUniform3fv");
 
514
    pfnProxyUniform3i = glProxyGetProcAddr(handle, "glUniform3i");
 
515
    pfnProxyUniform3iv = glProxyGetProcAddr(handle, "glUniform3iv");
 
516
    pfnProxyUniform4f = glProxyGetProcAddr(handle, "glUniform4f");
 
517
    pfnProxyUniform4fv = glProxyGetProcAddr(handle, "glUniform4fv");
 
518
    pfnProxyUniform4i = glProxyGetProcAddr(handle, "glUniform4i");
 
519
    pfnProxyUniform4iv = glProxyGetProcAddr(handle, "glUniform4iv");
 
520
    pfnProxyUniformMatrix2fv = glProxyGetProcAddr(handle, "glUniformMatrix2fv");
 
521
    pfnProxyUniformMatrix3fv = glProxyGetProcAddr(handle, "glUniformMatrix3fv");
 
522
    pfnProxyUniformMatrix4fv = glProxyGetProcAddr(handle, "glUniformMatrix4fv");
 
523
    pfnProxyUseProgram = glProxyGetProcAddr(handle, "glUseProgram");
 
524
    pfnProxyValidateProgram = glProxyGetProcAddr(handle, "glValidateProgram");
 
525
    pfnProxyVertexAttrib1f = glProxyGetProcAddr(handle, "glVertexAttrib1f");
 
526
    pfnProxyVertexAttrib1fv = glProxyGetProcAddr(handle, "glVertexAttrib1fv");
 
527
    pfnProxyVertexAttrib2f = glProxyGetProcAddr(handle, "glVertexAttrib2f");
 
528
    pfnProxyVertexAttrib2fv = glProxyGetProcAddr(handle, "glVertexAttrib2fv");
 
529
    pfnProxyVertexAttrib3f = glProxyGetProcAddr(handle, "glVertexAttrib3f");
 
530
    pfnProxyVertexAttrib3fv = glProxyGetProcAddr(handle, "glVertexAttrib3fv");
 
531
    pfnProxyVertexAttrib4f = glProxyGetProcAddr(handle, "glVertexAttrib4f");
 
532
    pfnProxyVertexAttrib4fv = glProxyGetProcAddr(handle, "glVertexAttrib4fv");
 
533
    pfnProxyVertexAttribPointer = glProxyGetProcAddr(handle,
 
534
            "glVertexAttribPointer");
 
535
    pfnProxyViewport = glProxyGetProcAddr(handle, "glViewport");
 
536
 
 
537
    return 0;
783
538
}
784
539
 
785
540
extern int glxProxyInit(void *handle);
 
541
extern int eglProxyInit(void *handle);
786
542
 
787
543
int glProxyInit(PROXY_BACKEND_OPTION *pProxyBackend)
788
544
{
789
545
    global_proxy_context.current_backend = UNKNOWN_BACKEND;
790
 
    global_proxy_context.x_dpy = NULL;
791
 
 
792
 
        /* Select backend first */
793
 
        glProxyBackendSelection(pProxyBackend, &global_proxy_context);
794
 
 
795
 
        if (UNKNOWN_BACKEND == global_proxy_context.current_backend) {
796
 
                printf("Error: No OpenGL or OpenGL ES2.0 renderer available\n");
797
 
                return -1;
798
 
        }
799
 
 
800
 
        printf("%s backend is selected for rendering\n", (global_proxy_context.current_backend == OPENGL_BACKEND) ? "OpenGL" : "OpenGL ES2.0");
801
 
 
802
 
        /* Load selected backend, and resolve glXGetProcAddress/eglGetProcAddress */
803
 
        if (glProxyEarlyResolve(&global_proxy_context) < 0)
804
 
            return -1;
805
 
 
806
 
        /* Resolve symbols */
807
 
        if (OPENGL_BACKEND == global_proxy_context.current_backend) {
808
 
                glProxyCoreInit(global_proxy_context.gl_handle);
809
 
                glxProxyInit(global_proxy_context.gl_handle);
810
 
        }
811
 
        else if (OPENGL_ES20_BACKEND == global_proxy_context.current_backend) {
812
 
                glProxyCoreInit(global_proxy_context.gles2_handle);
813
 
        }
814
 
        else {
815
 
                /* should not get here */
816
 
                return -1;
817
 
        }
818
 
 
819
 
        return 0;
 
546
 
 
547
    /* Select backend first */
 
548
    glProxyBackendSelection(pProxyBackend, &global_proxy_context);
 
549
 
 
550
    if (UNKNOWN_BACKEND == global_proxy_context.current_backend) {
 
551
        printf("Error: No OpenGL or OpenGL ES2.0 renderer available\n");
 
552
        return -1;
 
553
    }
 
554
 
 
555
    printf("%s backend is selected for rendering\n",
 
556
            (global_proxy_context.current_backend == OPENGL_BACKEND) ? "OpenGL"
 
557
                    : "OpenGL ES2.0");
 
558
 
 
559
    /* Load selected backend, and resolve glXGetProcAddress/eglGetProcAddress */
 
560
    if (glProxyEarlyResolve(&global_proxy_context) < 0)
 
561
        return -1;
 
562
 
 
563
    /* Resolve symbols */
 
564
    if (OPENGL_BACKEND == global_proxy_context.current_backend) {
 
565
        glProxyCoreInit(global_proxy_context.gl_handle);
 
566
        glxProxyInit(global_proxy_context.gl_handle);
 
567
    } else if (OPENGL_ES20_BACKEND == global_proxy_context.current_backend) {
 
568
        glProxyCoreInit(global_proxy_context.gles2_handle);
 
569
        eglProxyInit(global_proxy_context.egl_handle);
 
570
    } else {
 
571
        /* should not get here */
 
572
        return -1;
 
573
    }
 
574
 
 
575
    return 0;
820
576
}
821
577
 
822
578
int glProxyClose(void)
823
579
{
824
 
        if (OPENGL_ES20_BACKEND == global_proxy_context.current_backend)
825
 
                DestroyEGLRenderingContext(&global_proxy_context);
826
 
 
827
 
        if (global_proxy_context.x_dpy) {
828
 
                XCloseDisplay(global_proxy_context.x_dpy);
829
 
                global_proxy_context.x_dpy = NULL;
830
 
        }
831
 
 
832
 
        if (global_proxy_context.gl_handle) {
833
 
                glProxyCloseLibrary(global_proxy_context.gl_handle);
834
 
                global_proxy_context.gl_handle = NULL;
835
 
        }
836
 
 
837
 
        if (global_proxy_context.gles2_handle) {
838
 
                glProxyCloseLibrary(global_proxy_context.gles2_handle);
839
 
                global_proxy_context.gles2_handle = NULL;
840
 
        }
841
 
 
842
 
        if (global_proxy_context.egl_handle) {
843
 
                glProxyCloseLibrary(global_proxy_context.egl_handle);
844
 
                global_proxy_context.egl_handle = NULL;
845
 
        }
846
 
 
847
 
        global_proxy_context.current_backend = UNKNOWN_BACKEND;
848
 
 
849
 
        return 0;
 
580
    if (global_proxy_context.gl_handle) {
 
581
        glProxyCloseLibrary(global_proxy_context.gl_handle);
 
582
        global_proxy_context.gl_handle = NULL;
 
583
    }
 
584
 
 
585
    if (global_proxy_context.gles2_handle) {
 
586
        glProxyCloseLibrary(global_proxy_context.gles2_handle);
 
587
        global_proxy_context.gles2_handle = NULL;
 
588
    }
 
589
 
 
590
    if (global_proxy_context.egl_handle) {
 
591
        glProxyCloseLibrary(global_proxy_context.egl_handle);
 
592
        global_proxy_context.egl_handle = NULL;
 
593
    }
 
594
 
 
595
    global_proxy_context.current_backend = UNKNOWN_BACKEND;
 
596
 
 
597
    return 0;
850
598
}