comparison libvo/gl_common.c @ 29938:eb6c70e2cbea

Very preliminary code to allow selecting the OpenGL backend at runtime. Works in the currently supported cases for only Win32 and only X11, the mixed case is not working yet though. But applied anyway since the code is slightly less messy than the current one.
author reimar
date Tue, 08 Dec 2009 06:42:46 +0000
parents 908f55fb5ed8
children 319b62d55feb
comparison
equal deleted inserted replaced
29937:d654021c9652 29938:eb6c70e2cbea
1456 if (res) return res; 1456 if (res) return res;
1457 oglmod = GetModuleHandle("opengl32.dll"); 1457 oglmod = GetModuleHandle("opengl32.dll");
1458 return GetProcAddress(oglmod, procName); 1458 return GetProcAddress(oglmod, procName);
1459 } 1459 }
1460 1460
1461 int setGlWindow(int *vinfo, HGLRC *context, HWND win) 1461 static int setGlWindow_w32(MPGLContext *ctx)
1462 { 1462 {
1463 HWND win = vo_w32_window;
1464 int *vinfo = &ctx->vinfo.w32;
1465 HGLRC *context = &ctx->context.w32;
1463 int new_vinfo; 1466 int new_vinfo;
1464 HDC windc = vo_w32_get_dc(win); 1467 HDC windc = vo_w32_get_dc(win);
1465 HGLRC new_context = 0; 1468 HGLRC new_context = 0;
1466 int keep_context = 0; 1469 int keep_context = 0;
1467 int res = SET_WINDOW_FAILED; 1470 int res = SET_WINDOW_FAILED;
1516 out: 1519 out:
1517 vo_w32_release_dc(win, windc); 1520 vo_w32_release_dc(win, windc);
1518 return res; 1521 return res;
1519 } 1522 }
1520 1523
1521 void releaseGlContext(int *vinfo, HGLRC *context) { 1524 static void releaseGlContext_w32(MPGLContext *ctx) {
1525 int *vinfo = &ctx->vinfo.w32;
1526 HGLRC *context = &ctx->context.w32;
1522 *vinfo = 0; 1527 *vinfo = 0;
1523 if (*context) { 1528 if (*context) {
1524 wglMakeCurrent(0, 0); 1529 wglMakeCurrent(0, 0);
1525 wglDeleteContext(*context); 1530 wglDeleteContext(*context);
1526 } 1531 }
1527 *context = 0; 1532 *context = 0;
1528 } 1533 }
1529 1534
1530 void swapGlBuffers(void) { 1535 static void swapGlBuffers_w32(MPGLContext *ctx) {
1531 HDC vo_hdc = vo_w32_get_dc(vo_w32_window); 1536 HDC vo_hdc = vo_w32_get_dc(vo_w32_window);
1532 SwapBuffers(vo_hdc); 1537 SwapBuffers(vo_hdc);
1533 vo_w32_release_dc(vo_w32_window, vo_hdc); 1538 vo_w32_release_dc(vo_w32_window, vo_hdc);
1534 } 1539 }
1535 #else 1540 #endif
1541 #ifdef CONFIG_X11
1536 #ifdef HAVE_LIBDL 1542 #ifdef HAVE_LIBDL
1537 #include <dlfcn.h> 1543 #include <dlfcn.h>
1538 #endif 1544 #endif
1539 #include "x11_common.h" 1545 #include "x11_common.h"
1540 /** 1546 /**
1593 * \return one of SET_WINDOW_FAILED, SET_WINDOW_OK or SET_WINDOW_REINIT. 1599 * \return one of SET_WINDOW_FAILED, SET_WINDOW_OK or SET_WINDOW_REINIT.
1594 * In case of SET_WINDOW_REINIT the context could not be transfered 1600 * In case of SET_WINDOW_REINIT the context could not be transfered
1595 * and the caller must initialize it correctly. 1601 * and the caller must initialize it correctly.
1596 * \ingroup glcontext 1602 * \ingroup glcontext
1597 */ 1603 */
1598 int setGlWindow(XVisualInfo **vinfo, GLXContext *context, Window win) 1604 static int setGlWindow_x11(MPGLContext *ctx)
1599 { 1605 {
1606 XVisualInfo **vinfo = &ctx->vinfo.x11;
1607 GLXContext *context = &ctx->context.x11;
1608 Window win = vo_window;
1600 XVisualInfo *new_vinfo; 1609 XVisualInfo *new_vinfo;
1601 GLXContext new_context = NULL; 1610 GLXContext new_context = NULL;
1602 int keep_context = 0; 1611 int keep_context = 0;
1603 1612
1604 // should only be needed when keeping context, but not doing glFinish 1613 // should only be needed when keeping context, but not doing glFinish
1672 1681
1673 /** 1682 /**
1674 * \brief free the VisualInfo and GLXContext of an OpenGL context. 1683 * \brief free the VisualInfo and GLXContext of an OpenGL context.
1675 * \ingroup glcontext 1684 * \ingroup glcontext
1676 */ 1685 */
1677 void releaseGlContext(XVisualInfo **vinfo, GLXContext *context) { 1686 static void releaseGlContext_x11(MPGLContext *ctx) {
1687 XVisualInfo **vinfo = &ctx->vinfo.x11;
1688 GLXContext *context = &ctx->context.x11;
1678 if (*vinfo) 1689 if (*vinfo)
1679 XFree(*vinfo); 1690 XFree(*vinfo);
1680 *vinfo = NULL; 1691 *vinfo = NULL;
1681 if (*context) 1692 if (*context)
1682 { 1693 {
1685 glXDestroyContext(mDisplay, *context); 1696 glXDestroyContext(mDisplay, *context);
1686 } 1697 }
1687 *context = 0; 1698 *context = 0;
1688 } 1699 }
1689 1700
1690 void swapGlBuffers(void) { 1701 static void swapGlBuffers_x11(MPGLContext *ctx) {
1691 glXSwapBuffers(mDisplay, vo_window); 1702 glXSwapBuffers(mDisplay, vo_window);
1692 } 1703 }
1704
1705 static int x11_check_events(void) {
1706 return vo_x11_check_events(mDisplay);
1707 }
1693 #endif 1708 #endif
1694 1709
1710 int init_mpglcontext(MPGLContext *ctx, enum MPGLType type) {
1711 memset(ctx, 0, sizeof(*ctx));
1712 ctx->type = type;
1713 switch (ctx->type) {
1714 #ifdef GL_WIN32
1715 case GLTYPE_W32:
1716 ctx->setGlWindow = setGlWindow_w32;
1717 ctx->releaseGlContext = releaseGlContext_w32;
1718 ctx->swapGlBuffers = swapGlBuffers_w32;
1719 ctx->update_xinerama_info = w32_update_xinerama_info;
1720 ctx->border = vo_w32_border;
1721 ctx->check_events = vo_w32_check_events;
1722 ctx->fullscreen = vo_w32_fullscreen;
1723 ctx->ontop = vo_w32_ontop;
1724 return vo_w32_init();
1725 #endif
1726 #ifdef CONFIG_X11
1727 case GLTYPE_X11:
1728 ctx->setGlWindow = setGlWindow_x11;
1729 ctx->releaseGlContext = releaseGlContext_x11;
1730 ctx->swapGlBuffers = swapGlBuffers_x11;
1731 ctx->update_xinerama_info = update_xinerama_info;
1732 ctx->border = vo_x11_border;
1733 ctx->check_events = x11_check_events;
1734 ctx->fullscreen = vo_x11_fullscreen;
1735 ctx->ontop = vo_x11_ontop;
1736 return vo_init();
1737 #endif
1738 default:
1739 return 0;
1740 }
1741 }
1742
1743 void uninit_mpglcontext(MPGLContext *ctx) {
1744 ctx->releaseGlContext(ctx);
1745 switch (ctx->type) {
1746 #ifdef GL_WIN32
1747 case GLTYPE_W32:
1748 vo_w32_uninit();
1749 break;
1750 #endif
1751 #ifdef CONFIG_X11
1752 case GLTYPE_X11:
1753 vo_x11_uninit();
1754 break;
1755 #endif
1756 }
1757 memset(ctx, 0, sizeof(*ctx));
1758 }