graphics-imports.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /******************************************************************************
  2. Copyright (C) 2023 by Lain Bailey <lain@obsproject.com>
  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 "../util/base.h"
  15. #include "../util/dstr.h"
  16. #include "../util/platform.h"
  17. #include "graphics-internal.h"
  18. #define GRAPHICS_IMPORT(func) \
  19. do { \
  20. exports->func = os_dlsym(module, #func); \
  21. if (!exports->func) { \
  22. success = false; \
  23. blog(LOG_ERROR, \
  24. "Could not load function '%s' from " \
  25. "module '%s'", \
  26. #func, module_name); \
  27. } \
  28. } while (false)
  29. #define GRAPHICS_IMPORT_OPTIONAL(func) \
  30. do { \
  31. exports->func = os_dlsym(module, #func); \
  32. } while (false)
  33. bool load_graphics_imports(struct gs_exports *exports, void *module, const char *module_name)
  34. {
  35. bool success = true;
  36. GRAPHICS_IMPORT(device_get_name);
  37. GRAPHICS_IMPORT(device_get_type);
  38. GRAPHICS_IMPORT_OPTIONAL(device_enum_adapters);
  39. GRAPHICS_IMPORT(device_preprocessor_name);
  40. GRAPHICS_IMPORT(device_create);
  41. GRAPHICS_IMPORT(device_destroy);
  42. GRAPHICS_IMPORT(device_enter_context);
  43. GRAPHICS_IMPORT(device_leave_context);
  44. GRAPHICS_IMPORT(device_get_device_obj);
  45. GRAPHICS_IMPORT(device_swapchain_create);
  46. GRAPHICS_IMPORT(device_resize);
  47. GRAPHICS_IMPORT(device_get_color_space);
  48. GRAPHICS_IMPORT(device_update_color_space);
  49. GRAPHICS_IMPORT(device_get_size);
  50. GRAPHICS_IMPORT(device_get_width);
  51. GRAPHICS_IMPORT(device_get_height);
  52. GRAPHICS_IMPORT(device_texture_create);
  53. GRAPHICS_IMPORT(device_cubetexture_create);
  54. GRAPHICS_IMPORT(device_voltexture_create);
  55. GRAPHICS_IMPORT(device_zstencil_create);
  56. GRAPHICS_IMPORT(device_stagesurface_create);
  57. GRAPHICS_IMPORT(device_samplerstate_create);
  58. GRAPHICS_IMPORT(device_vertexshader_create);
  59. GRAPHICS_IMPORT(device_pixelshader_create);
  60. GRAPHICS_IMPORT(device_vertexbuffer_create);
  61. GRAPHICS_IMPORT(device_indexbuffer_create);
  62. GRAPHICS_IMPORT(device_timer_create);
  63. GRAPHICS_IMPORT(device_timer_range_create);
  64. GRAPHICS_IMPORT(device_get_texture_type);
  65. GRAPHICS_IMPORT(device_load_vertexbuffer);
  66. GRAPHICS_IMPORT(device_load_indexbuffer);
  67. GRAPHICS_IMPORT(device_load_texture);
  68. GRAPHICS_IMPORT(device_load_samplerstate);
  69. GRAPHICS_IMPORT(device_load_vertexshader);
  70. GRAPHICS_IMPORT(device_load_pixelshader);
  71. GRAPHICS_IMPORT(device_load_default_samplerstate);
  72. GRAPHICS_IMPORT(device_get_vertex_shader);
  73. GRAPHICS_IMPORT(device_get_pixel_shader);
  74. GRAPHICS_IMPORT(device_get_render_target);
  75. GRAPHICS_IMPORT(device_get_zstencil_target);
  76. GRAPHICS_IMPORT(device_set_render_target);
  77. GRAPHICS_IMPORT(device_set_render_target_with_color_space);
  78. GRAPHICS_IMPORT(device_set_cube_render_target);
  79. GRAPHICS_IMPORT(device_enable_framebuffer_srgb);
  80. GRAPHICS_IMPORT(device_framebuffer_srgb_enabled);
  81. GRAPHICS_IMPORT(device_copy_texture_region);
  82. GRAPHICS_IMPORT(device_copy_texture);
  83. GRAPHICS_IMPORT(device_stage_texture);
  84. GRAPHICS_IMPORT(device_begin_frame);
  85. GRAPHICS_IMPORT(device_begin_scene);
  86. GRAPHICS_IMPORT(device_draw);
  87. GRAPHICS_IMPORT(device_load_swapchain);
  88. GRAPHICS_IMPORT(device_end_scene);
  89. GRAPHICS_IMPORT(device_clear);
  90. GRAPHICS_IMPORT(device_is_present_ready);
  91. GRAPHICS_IMPORT(device_present);
  92. GRAPHICS_IMPORT(device_flush);
  93. GRAPHICS_IMPORT(device_set_cull_mode);
  94. GRAPHICS_IMPORT(device_get_cull_mode);
  95. GRAPHICS_IMPORT(device_enable_blending);
  96. GRAPHICS_IMPORT(device_enable_depth_test);
  97. GRAPHICS_IMPORT(device_enable_stencil_test);
  98. GRAPHICS_IMPORT(device_enable_stencil_write);
  99. GRAPHICS_IMPORT(device_enable_color);
  100. GRAPHICS_IMPORT(device_blend_function);
  101. GRAPHICS_IMPORT(device_blend_function_separate);
  102. GRAPHICS_IMPORT(device_blend_op);
  103. GRAPHICS_IMPORT(device_depth_function);
  104. GRAPHICS_IMPORT(device_stencil_function);
  105. GRAPHICS_IMPORT(device_stencil_op);
  106. GRAPHICS_IMPORT(device_set_viewport);
  107. GRAPHICS_IMPORT(device_get_viewport);
  108. GRAPHICS_IMPORT(device_set_scissor_rect);
  109. GRAPHICS_IMPORT(device_ortho);
  110. GRAPHICS_IMPORT(device_frustum);
  111. GRAPHICS_IMPORT(device_projection_push);
  112. GRAPHICS_IMPORT(device_projection_pop);
  113. GRAPHICS_IMPORT(gs_swapchain_destroy);
  114. GRAPHICS_IMPORT(gs_texture_destroy);
  115. GRAPHICS_IMPORT(gs_texture_get_width);
  116. GRAPHICS_IMPORT(gs_texture_get_height);
  117. GRAPHICS_IMPORT(gs_texture_get_color_format);
  118. GRAPHICS_IMPORT(gs_texture_map);
  119. GRAPHICS_IMPORT(gs_texture_unmap);
  120. GRAPHICS_IMPORT_OPTIONAL(gs_texture_is_rect);
  121. GRAPHICS_IMPORT(gs_texture_get_obj);
  122. GRAPHICS_IMPORT(gs_cubetexture_destroy);
  123. GRAPHICS_IMPORT(gs_cubetexture_get_size);
  124. GRAPHICS_IMPORT(gs_cubetexture_get_color_format);
  125. GRAPHICS_IMPORT(gs_voltexture_destroy);
  126. GRAPHICS_IMPORT(gs_voltexture_get_width);
  127. GRAPHICS_IMPORT(gs_voltexture_get_height);
  128. GRAPHICS_IMPORT(gs_voltexture_get_depth);
  129. GRAPHICS_IMPORT(gs_voltexture_get_color_format);
  130. GRAPHICS_IMPORT(gs_stagesurface_destroy);
  131. GRAPHICS_IMPORT(gs_stagesurface_get_width);
  132. GRAPHICS_IMPORT(gs_stagesurface_get_height);
  133. GRAPHICS_IMPORT(gs_stagesurface_get_color_format);
  134. GRAPHICS_IMPORT(gs_stagesurface_map);
  135. GRAPHICS_IMPORT(gs_stagesurface_unmap);
  136. GRAPHICS_IMPORT(gs_zstencil_destroy);
  137. GRAPHICS_IMPORT(gs_samplerstate_destroy);
  138. GRAPHICS_IMPORT(gs_vertexbuffer_destroy);
  139. GRAPHICS_IMPORT(gs_vertexbuffer_flush);
  140. GRAPHICS_IMPORT(gs_vertexbuffer_flush_direct);
  141. GRAPHICS_IMPORT(gs_vertexbuffer_get_data);
  142. GRAPHICS_IMPORT(gs_indexbuffer_destroy);
  143. GRAPHICS_IMPORT(gs_indexbuffer_flush);
  144. GRAPHICS_IMPORT(gs_indexbuffer_flush_direct);
  145. GRAPHICS_IMPORT(gs_indexbuffer_get_data);
  146. GRAPHICS_IMPORT(gs_indexbuffer_get_num_indices);
  147. GRAPHICS_IMPORT(gs_indexbuffer_get_type);
  148. GRAPHICS_IMPORT(gs_timer_destroy);
  149. GRAPHICS_IMPORT(gs_timer_begin);
  150. GRAPHICS_IMPORT(gs_timer_end);
  151. GRAPHICS_IMPORT(gs_timer_get_data);
  152. GRAPHICS_IMPORT(gs_timer_range_destroy);
  153. GRAPHICS_IMPORT(gs_timer_range_begin);
  154. GRAPHICS_IMPORT(gs_timer_range_end);
  155. GRAPHICS_IMPORT(gs_timer_range_get_data);
  156. GRAPHICS_IMPORT(gs_shader_destroy);
  157. GRAPHICS_IMPORT(gs_shader_get_num_params);
  158. GRAPHICS_IMPORT(gs_shader_get_param_by_idx);
  159. GRAPHICS_IMPORT(gs_shader_get_param_by_name);
  160. GRAPHICS_IMPORT(gs_shader_get_viewproj_matrix);
  161. GRAPHICS_IMPORT(gs_shader_get_world_matrix);
  162. GRAPHICS_IMPORT(gs_shader_get_param_info);
  163. GRAPHICS_IMPORT(gs_shader_set_bool);
  164. GRAPHICS_IMPORT(gs_shader_set_float);
  165. GRAPHICS_IMPORT(gs_shader_set_int);
  166. GRAPHICS_IMPORT(gs_shader_set_matrix3);
  167. GRAPHICS_IMPORT(gs_shader_set_matrix4);
  168. GRAPHICS_IMPORT(gs_shader_set_vec2);
  169. GRAPHICS_IMPORT(gs_shader_set_vec3);
  170. GRAPHICS_IMPORT(gs_shader_set_vec4);
  171. GRAPHICS_IMPORT(gs_shader_set_texture);
  172. GRAPHICS_IMPORT(gs_shader_set_val);
  173. GRAPHICS_IMPORT(gs_shader_set_default);
  174. GRAPHICS_IMPORT(gs_shader_set_next_sampler);
  175. GRAPHICS_IMPORT_OPTIONAL(device_nv12_available);
  176. GRAPHICS_IMPORT_OPTIONAL(device_p010_available);
  177. GRAPHICS_IMPORT_OPTIONAL(device_texture_create_nv12);
  178. GRAPHICS_IMPORT_OPTIONAL(device_texture_create_p010);
  179. GRAPHICS_IMPORT(device_is_monitor_hdr);
  180. GRAPHICS_IMPORT(device_debug_marker_begin);
  181. GRAPHICS_IMPORT(device_debug_marker_end);
  182. GRAPHICS_IMPORT_OPTIONAL(gs_get_adapter_count);
  183. /* OSX/Cocoa specific functions */
  184. #ifdef __APPLE__
  185. GRAPHICS_IMPORT(device_shared_texture_available);
  186. GRAPHICS_IMPORT(device_texture_open_shared);
  187. GRAPHICS_IMPORT(device_texture_create_from_iosurface);
  188. GRAPHICS_IMPORT(gs_texture_rebind_iosurface);
  189. /* win32 specific functions */
  190. #elif _WIN32
  191. GRAPHICS_IMPORT(device_gdi_texture_available);
  192. GRAPHICS_IMPORT(device_shared_texture_available);
  193. GRAPHICS_IMPORT_OPTIONAL(device_get_duplicator_monitor_info);
  194. GRAPHICS_IMPORT_OPTIONAL(device_duplicator_get_monitor_index);
  195. GRAPHICS_IMPORT_OPTIONAL(device_duplicator_create);
  196. GRAPHICS_IMPORT_OPTIONAL(gs_duplicator_destroy);
  197. GRAPHICS_IMPORT_OPTIONAL(gs_duplicator_update_frame);
  198. GRAPHICS_IMPORT_OPTIONAL(gs_duplicator_get_texture);
  199. GRAPHICS_IMPORT_OPTIONAL(gs_duplicator_get_color_space);
  200. GRAPHICS_IMPORT_OPTIONAL(gs_duplicator_get_sdr_white_level);
  201. GRAPHICS_IMPORT_OPTIONAL(device_can_adapter_fast_clear);
  202. GRAPHICS_IMPORT_OPTIONAL(device_texture_create_gdi);
  203. GRAPHICS_IMPORT_OPTIONAL(gs_texture_get_dc);
  204. GRAPHICS_IMPORT_OPTIONAL(gs_texture_release_dc);
  205. GRAPHICS_IMPORT_OPTIONAL(device_texture_open_shared);
  206. GRAPHICS_IMPORT_OPTIONAL(device_texture_open_nt_shared);
  207. GRAPHICS_IMPORT_OPTIONAL(device_texture_get_shared_handle);
  208. GRAPHICS_IMPORT_OPTIONAL(device_texture_wrap_obj);
  209. GRAPHICS_IMPORT_OPTIONAL(device_texture_acquire_sync);
  210. GRAPHICS_IMPORT_OPTIONAL(device_texture_release_sync);
  211. GRAPHICS_IMPORT_OPTIONAL(device_stagesurface_create_nv12);
  212. GRAPHICS_IMPORT_OPTIONAL(device_stagesurface_create_p010);
  213. GRAPHICS_IMPORT_OPTIONAL(device_register_loss_callbacks);
  214. GRAPHICS_IMPORT_OPTIONAL(device_unregister_loss_callbacks);
  215. #elif defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__)
  216. GRAPHICS_IMPORT(device_texture_create_from_dmabuf);
  217. GRAPHICS_IMPORT(device_query_dmabuf_capabilities);
  218. GRAPHICS_IMPORT(device_query_dmabuf_modifiers_for_format);
  219. GRAPHICS_IMPORT(device_texture_create_from_pixmap);
  220. #endif
  221. return success;
  222. }