1 /******************************************************************************
2 Copyright (C) 2013 by Hugh Bailey <obs.jim@gmail.com>
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 ******************************************************************************/
17
18 #include "../util/base.h"
19 #include "../util/dstr.h"
20 #include "../util/platform.h"
21 #include "graphics-internal.h"
22
23 #define GRAPHICS_IMPORT(func) \
24 do { \
25 exports->func = os_dlsym(module, #func); \
26 if (!exports->func) { \
27 success = false; \
28 blog(LOG_ERROR, \
29 "Could not load function '%s' from " \
30 "module '%s'", \
31 #func, module_name); \
32 } \
33 } while (false)
34
35 #define GRAPHICS_IMPORT_OPTIONAL(func) \
36 do { \
37 exports->func = os_dlsym(module, #func); \
38 } while (false)
39
load_graphics_imports(struct gs_exports * exports,void * module,const char * module_name)40 bool load_graphics_imports(struct gs_exports *exports, void *module,
41 const char *module_name)
42 {
43 bool success = true;
44
45 GRAPHICS_IMPORT(device_get_name);
46 GRAPHICS_IMPORT(device_get_type);
47 GRAPHICS_IMPORT_OPTIONAL(device_enum_adapters);
48 GRAPHICS_IMPORT(device_preprocessor_name);
49 GRAPHICS_IMPORT(device_create);
50 GRAPHICS_IMPORT(device_destroy);
51 GRAPHICS_IMPORT(device_enter_context);
52 GRAPHICS_IMPORT(device_leave_context);
53 GRAPHICS_IMPORT(device_get_device_obj);
54 GRAPHICS_IMPORT(device_swapchain_create);
55 GRAPHICS_IMPORT(device_resize);
56 GRAPHICS_IMPORT(device_get_size);
57 GRAPHICS_IMPORT(device_get_width);
58 GRAPHICS_IMPORT(device_get_height);
59 GRAPHICS_IMPORT(device_texture_create);
60 GRAPHICS_IMPORT(device_cubetexture_create);
61 GRAPHICS_IMPORT(device_voltexture_create);
62 GRAPHICS_IMPORT(device_zstencil_create);
63 GRAPHICS_IMPORT(device_stagesurface_create);
64 GRAPHICS_IMPORT(device_samplerstate_create);
65 GRAPHICS_IMPORT(device_vertexshader_create);
66 GRAPHICS_IMPORT(device_pixelshader_create);
67 GRAPHICS_IMPORT(device_vertexbuffer_create);
68 GRAPHICS_IMPORT(device_indexbuffer_create);
69 GRAPHICS_IMPORT(device_timer_create);
70 GRAPHICS_IMPORT(device_timer_range_create);
71 GRAPHICS_IMPORT(device_get_texture_type);
72 GRAPHICS_IMPORT(device_load_vertexbuffer);
73 GRAPHICS_IMPORT(device_load_indexbuffer);
74 GRAPHICS_IMPORT(device_load_texture);
75 GRAPHICS_IMPORT(device_load_samplerstate);
76 GRAPHICS_IMPORT(device_load_vertexshader);
77 GRAPHICS_IMPORT(device_load_pixelshader);
78 GRAPHICS_IMPORT(device_load_default_samplerstate);
79 GRAPHICS_IMPORT(device_get_vertex_shader);
80 GRAPHICS_IMPORT(device_get_pixel_shader);
81 GRAPHICS_IMPORT(device_get_render_target);
82 GRAPHICS_IMPORT(device_get_zstencil_target);
83 GRAPHICS_IMPORT(device_set_render_target);
84 GRAPHICS_IMPORT(device_set_cube_render_target);
85 GRAPHICS_IMPORT(device_enable_framebuffer_srgb);
86 GRAPHICS_IMPORT(device_framebuffer_srgb_enabled);
87 GRAPHICS_IMPORT(device_copy_texture_region);
88 GRAPHICS_IMPORT(device_copy_texture);
89 GRAPHICS_IMPORT(device_stage_texture);
90 GRAPHICS_IMPORT(device_begin_frame);
91 GRAPHICS_IMPORT(device_begin_scene);
92 GRAPHICS_IMPORT(device_draw);
93 GRAPHICS_IMPORT(device_load_swapchain);
94 GRAPHICS_IMPORT(device_end_scene);
95 GRAPHICS_IMPORT(device_clear);
96 GRAPHICS_IMPORT(device_present);
97 GRAPHICS_IMPORT(device_flush);
98 GRAPHICS_IMPORT(device_set_cull_mode);
99 GRAPHICS_IMPORT(device_get_cull_mode);
100 GRAPHICS_IMPORT(device_enable_blending);
101 GRAPHICS_IMPORT(device_enable_depth_test);
102 GRAPHICS_IMPORT(device_enable_stencil_test);
103 GRAPHICS_IMPORT(device_enable_stencil_write);
104 GRAPHICS_IMPORT(device_enable_color);
105 GRAPHICS_IMPORT(device_blend_function);
106 GRAPHICS_IMPORT(device_blend_function_separate);
107 GRAPHICS_IMPORT(device_depth_function);
108 GRAPHICS_IMPORT(device_stencil_function);
109 GRAPHICS_IMPORT(device_stencil_op);
110 GRAPHICS_IMPORT(device_set_viewport);
111 GRAPHICS_IMPORT(device_get_viewport);
112 GRAPHICS_IMPORT(device_set_scissor_rect);
113 GRAPHICS_IMPORT(device_ortho);
114 GRAPHICS_IMPORT(device_frustum);
115 GRAPHICS_IMPORT(device_projection_push);
116 GRAPHICS_IMPORT(device_projection_pop);
117
118 GRAPHICS_IMPORT(gs_swapchain_destroy);
119
120 GRAPHICS_IMPORT(gs_texture_destroy);
121 GRAPHICS_IMPORT(gs_texture_get_width);
122 GRAPHICS_IMPORT(gs_texture_get_height);
123 GRAPHICS_IMPORT(gs_texture_get_color_format);
124 GRAPHICS_IMPORT(gs_texture_map);
125 GRAPHICS_IMPORT(gs_texture_unmap);
126 GRAPHICS_IMPORT_OPTIONAL(gs_texture_is_rect);
127 GRAPHICS_IMPORT(gs_texture_get_obj);
128
129 GRAPHICS_IMPORT(gs_cubetexture_destroy);
130 GRAPHICS_IMPORT(gs_cubetexture_get_size);
131 GRAPHICS_IMPORT(gs_cubetexture_get_color_format);
132
133 GRAPHICS_IMPORT(gs_voltexture_destroy);
134 GRAPHICS_IMPORT(gs_voltexture_get_width);
135 GRAPHICS_IMPORT(gs_voltexture_get_height);
136 GRAPHICS_IMPORT(gs_voltexture_get_depth);
137 GRAPHICS_IMPORT(gs_voltexture_get_color_format);
138
139 GRAPHICS_IMPORT(gs_stagesurface_destroy);
140 GRAPHICS_IMPORT(gs_stagesurface_get_width);
141 GRAPHICS_IMPORT(gs_stagesurface_get_height);
142 GRAPHICS_IMPORT(gs_stagesurface_get_color_format);
143 GRAPHICS_IMPORT(gs_stagesurface_map);
144 GRAPHICS_IMPORT(gs_stagesurface_unmap);
145
146 GRAPHICS_IMPORT(gs_zstencil_destroy);
147
148 GRAPHICS_IMPORT(gs_samplerstate_destroy);
149
150 GRAPHICS_IMPORT(gs_vertexbuffer_destroy);
151 GRAPHICS_IMPORT(gs_vertexbuffer_flush);
152 GRAPHICS_IMPORT(gs_vertexbuffer_flush_direct);
153 GRAPHICS_IMPORT(gs_vertexbuffer_get_data);
154
155 GRAPHICS_IMPORT(gs_indexbuffer_destroy);
156 GRAPHICS_IMPORT(gs_indexbuffer_flush);
157 GRAPHICS_IMPORT(gs_indexbuffer_flush_direct);
158 GRAPHICS_IMPORT(gs_indexbuffer_get_data);
159 GRAPHICS_IMPORT(gs_indexbuffer_get_num_indices);
160 GRAPHICS_IMPORT(gs_indexbuffer_get_type);
161
162 GRAPHICS_IMPORT(gs_timer_destroy);
163 GRAPHICS_IMPORT(gs_timer_begin);
164 GRAPHICS_IMPORT(gs_timer_end);
165 GRAPHICS_IMPORT(gs_timer_get_data);
166 GRAPHICS_IMPORT(gs_timer_range_destroy);
167 GRAPHICS_IMPORT(gs_timer_range_begin);
168 GRAPHICS_IMPORT(gs_timer_range_end);
169 GRAPHICS_IMPORT(gs_timer_range_get_data);
170
171 GRAPHICS_IMPORT(gs_shader_destroy);
172 GRAPHICS_IMPORT(gs_shader_get_num_params);
173 GRAPHICS_IMPORT(gs_shader_get_param_by_idx);
174 GRAPHICS_IMPORT(gs_shader_get_param_by_name);
175 GRAPHICS_IMPORT(gs_shader_get_viewproj_matrix);
176 GRAPHICS_IMPORT(gs_shader_get_world_matrix);
177 GRAPHICS_IMPORT(gs_shader_get_param_info);
178 GRAPHICS_IMPORT(gs_shader_set_bool);
179 GRAPHICS_IMPORT(gs_shader_set_float);
180 GRAPHICS_IMPORT(gs_shader_set_int);
181 GRAPHICS_IMPORT(gs_shader_set_matrix3);
182 GRAPHICS_IMPORT(gs_shader_set_matrix4);
183 GRAPHICS_IMPORT(gs_shader_set_vec2);
184 GRAPHICS_IMPORT(gs_shader_set_vec3);
185 GRAPHICS_IMPORT(gs_shader_set_vec4);
186 GRAPHICS_IMPORT(gs_shader_set_texture);
187 GRAPHICS_IMPORT(gs_shader_set_val);
188 GRAPHICS_IMPORT(gs_shader_set_default);
189 GRAPHICS_IMPORT(gs_shader_set_next_sampler);
190
191 GRAPHICS_IMPORT_OPTIONAL(device_nv12_available);
192
193 GRAPHICS_IMPORT(device_debug_marker_begin);
194 GRAPHICS_IMPORT(device_debug_marker_end);
195
196 /* OSX/Cocoa specific functions */
197 #ifdef __APPLE__
198 GRAPHICS_IMPORT(device_shared_texture_available);
199 GRAPHICS_IMPORT_OPTIONAL(device_texture_open_shared);
200 GRAPHICS_IMPORT_OPTIONAL(device_texture_create_from_iosurface);
201 GRAPHICS_IMPORT_OPTIONAL(gs_texture_rebind_iosurface);
202
203 /* win32 specific functions */
204 #elif _WIN32
205 GRAPHICS_IMPORT(device_gdi_texture_available);
206 GRAPHICS_IMPORT(device_shared_texture_available);
207 GRAPHICS_IMPORT_OPTIONAL(device_get_duplicator_monitor_info);
208 GRAPHICS_IMPORT_OPTIONAL(device_duplicator_get_monitor_index);
209 GRAPHICS_IMPORT_OPTIONAL(device_duplicator_create);
210 GRAPHICS_IMPORT_OPTIONAL(gs_duplicator_destroy);
211 GRAPHICS_IMPORT_OPTIONAL(gs_duplicator_update_frame);
212 GRAPHICS_IMPORT_OPTIONAL(gs_duplicator_get_texture);
213 GRAPHICS_IMPORT_OPTIONAL(gs_get_adapter_count);
214 GRAPHICS_IMPORT_OPTIONAL(device_texture_create_gdi);
215 GRAPHICS_IMPORT_OPTIONAL(gs_texture_get_dc);
216 GRAPHICS_IMPORT_OPTIONAL(gs_texture_release_dc);
217 GRAPHICS_IMPORT_OPTIONAL(device_texture_open_shared);
218 GRAPHICS_IMPORT_OPTIONAL(device_texture_get_shared_handle);
219 GRAPHICS_IMPORT_OPTIONAL(device_texture_wrap_obj);
220 GRAPHICS_IMPORT_OPTIONAL(device_texture_acquire_sync);
221 GRAPHICS_IMPORT_OPTIONAL(device_texture_release_sync);
222 GRAPHICS_IMPORT_OPTIONAL(device_texture_create_nv12);
223 GRAPHICS_IMPORT_OPTIONAL(device_stagesurface_create_nv12);
224 GRAPHICS_IMPORT_OPTIONAL(device_register_loss_callbacks);
225 GRAPHICS_IMPORT_OPTIONAL(device_unregister_loss_callbacks);
226 #elif __linux__
227 GRAPHICS_IMPORT(device_texture_create_from_dmabuf);
228 #endif
229
230 return success;
231 }
232