gl-nix.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /******************************************************************************
  2. Copyright (C) 2019 by Jason Francis <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #include "gl-nix.h"
  15. #include "gl-x11-glx.h"
  16. #include "gl-x11-egl.h"
  17. static const struct gl_winsys_vtable *gl_vtable = NULL;
  18. static void init_winsys(void)
  19. {
  20. assert(gl_vtable == NULL);
  21. switch (obs_get_nix_platform()) {
  22. case OBS_NIX_PLATFORM_X11_GLX:
  23. gl_vtable = gl_x11_glx_get_winsys_vtable();
  24. break;
  25. case OBS_NIX_PLATFORM_X11_EGL:
  26. gl_vtable = gl_x11_egl_get_winsys_vtable();
  27. break;
  28. }
  29. assert(gl_vtable != NULL);
  30. }
  31. extern struct gl_windowinfo *
  32. gl_windowinfo_create(const struct gs_init_data *info)
  33. {
  34. return gl_vtable->windowinfo_create(info);
  35. }
  36. extern void gl_windowinfo_destroy(struct gl_windowinfo *info)
  37. {
  38. gl_vtable->windowinfo_destroy(info);
  39. }
  40. extern struct gl_platform *gl_platform_create(gs_device_t *device,
  41. uint32_t adapter)
  42. {
  43. init_winsys();
  44. return gl_vtable->platform_create(device, adapter);
  45. }
  46. extern void gl_platform_destroy(struct gl_platform *plat)
  47. {
  48. gl_vtable->platform_destroy(plat);
  49. gl_vtable = NULL;
  50. }
  51. extern bool gl_platform_init_swapchain(struct gs_swap_chain *swap)
  52. {
  53. return gl_vtable->platform_init_swapchain(swap);
  54. }
  55. extern void gl_platform_cleanup_swapchain(struct gs_swap_chain *swap)
  56. {
  57. gl_vtable->platform_cleanup_swapchain(swap);
  58. }
  59. extern void device_enter_context(gs_device_t *device)
  60. {
  61. gl_vtable->device_enter_context(device);
  62. }
  63. extern void device_leave_context(gs_device_t *device)
  64. {
  65. gl_vtable->device_leave_context(device);
  66. }
  67. extern void *device_get_device_obj(gs_device_t *device)
  68. {
  69. return gl_vtable->device_get_device_obj(device);
  70. }
  71. extern void gl_getclientsize(const struct gs_swap_chain *swap, uint32_t *width,
  72. uint32_t *height)
  73. {
  74. gl_vtable->getclientsize(swap, width, height);
  75. }
  76. extern void gl_clear_context(gs_device_t *device)
  77. {
  78. gl_vtable->clear_context(device);
  79. }
  80. extern void gl_update(gs_device_t *device)
  81. {
  82. gl_vtable->update(device);
  83. }
  84. extern void device_load_swapchain(gs_device_t *device, gs_swapchain_t *swap)
  85. {
  86. gl_vtable->device_load_swapchain(device, swap);
  87. }
  88. extern void device_present(gs_device_t *device)
  89. {
  90. gl_vtable->device_present(device);
  91. }