1 /*
2  * Copyright (c) 2014 Derelict Developers
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  *   notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  *   notice, this list of conditions and the following disclaimer in the
14  *   documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the names 'Derelict', 'DerelictILUT', nor the names of its contributors
17  *   may be used to endorse or promote products derived from this software
18  *   without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 module derelict.bgfx.bgfx;
33 
34 public
35 {
36     import derelict.bgfx.types;
37     import derelict.bgfx.funcs;
38 }
39 
40 private
41 {
42     import derelict.util.loader;    
43 }
44 
45 private
46 {
47     import derelict.util.loader;
48     import derelict.util.system;
49 
50     static if(Derelict_OS_Windows)
51         enum libNames = "bgfx-shared-libRelease.dll, bgfx-shared-libDebug.dll";
52     else static if (Derelict_OS_Mac)
53         static assert(0, "Need to implement BASS libNames for this operating system.");
54     else static if (Derelict_OS_Linux)
55         static assert(0, "Need to implement BASS libNames for this operating system.");
56     else
57         static assert(0, "Need to implement BASS libNames for this operating system.");
58 }
59 
60 class DerelictBgfxLoader : SharedLibLoader
61 {
62 
63     protected
64     {
65         override void loadSymbols()
66         {
67             bindFunc(cast(void**)&bgfx_vertex_decl_begin, "bgfx_vertex_decl_begin");
68             bindFunc(cast(void**)&bgfx_vertex_decl_add, "bgfx_vertex_decl_add");
69             bindFunc(cast(void**)&bgfx_vertex_decl_skip, "bgfx_vertex_decl_skip");
70             bindFunc(cast(void**)&bgfx_vertex_decl_end, "bgfx_vertex_decl_end");
71             bindFunc(cast(void**)&bgfx_vertex_pack, "bgfx_vertex_pack");
72             bindFunc(cast(void**)&bgfx_vertex_unpack, "bgfx_vertex_unpack");
73             bindFunc(cast(void**)&bgfx_vertex_convert, "bgfx_vertex_convert");
74             bindFunc(cast(void**)&bgfx_weld_vertices, "bgfx_weld_vertices");
75             bindFunc(cast(void**)&bgfx_image_swizzle_bgra8, "bgfx_image_swizzle_bgra8");
76             bindFunc(cast(void**)&bgfx_image_rgba8_downsample_2x2, "bgfx_image_rgba8_downsample_2x2");
77             bindFunc(cast(void**)&bgfx_get_supported_renderers, "bgfx_get_supported_renderers");
78             bindFunc(cast(void**)&bgfx_get_renderer_name, "bgfx_get_renderer_name");
79             bindFunc(cast(void**)&bgfx_init, "bgfx_init");
80             bindFunc(cast(void**)&bgfx_shutdown, "bgfx_shutdown");
81             bindFunc(cast(void**)&bgfx_reset, "bgfx_reset");
82             bindFunc(cast(void**)&bgfx_frame, "bgfx_frame");
83             bindFunc(cast(void**)&bgfx_get_renderer_type, "bgfx_get_renderer_type");
84             bindFunc(cast(void**)&bgfx_get_caps, "bgfx_get_caps");
85             bindFunc(cast(void**)&bgfx_alloc, "bgfx_alloc");
86             bindFunc(cast(void**)&bgfx_copy, "bgfx_copy");
87             bindFunc(cast(void**)&bgfx_make_ref, "bgfx_make_ref");
88             bindFunc(cast(void**)&bgfx_set_debug, "bgfx_set_debug");
89             bindFunc(cast(void**)&bgfx_dbg_text_clear, "bgfx_dbg_text_clear");
90             bindFunc(cast(void**)&bgfx_dbg_text_printf, "bgfx_dbg_text_printf");
91             bindFunc(cast(void**)&bgfx_create_index_buffer, "bgfx_create_index_buffer");
92             bindFunc(cast(void**)&bgfx_destroy_index_buffer, "bgfx_destroy_index_buffer");
93             bindFunc(cast(void**)&bgfx_create_vertex_buffer, "bgfx_create_vertex_buffer");
94             bindFunc(cast(void**)&bgfx_destroy_vertex_buffer, "bgfx_destroy_vertex_buffer");
95             bindFunc(cast(void**)&bgfx_create_dynamic_index_buffer, "bgfx_create_dynamic_index_buffer");
96             bindFunc(cast(void**)&bgfx_create_dynamic_index_buffer_mem, "bgfx_create_dynamic_index_buffer_mem");
97             bindFunc(cast(void**)&bgfx_update_dynamic_index_buffer, "bgfx_update_dynamic_index_buffer");
98             bindFunc(cast(void**)&bgfx_destroy_dynamic_index_buffer, "bgfx_destroy_dynamic_index_buffer");
99             bindFunc(cast(void**)&bgfx_create_dynamic_vertex_buffer, "bgfx_create_dynamic_vertex_buffer");
100             bindFunc(cast(void**)&bgfx_create_dynamic_vertex_buffer_mem, "bgfx_create_dynamic_vertex_buffer_mem");
101             bindFunc(cast(void**)&bgfx_update_dynamic_vertex_buffer, "bgfx_update_dynamic_vertex_buffer");
102             bindFunc(cast(void**)&bgfx_destroy_dynamic_vertex_buffer, "bgfx_destroy_dynamic_vertex_buffer");
103             bindFunc(cast(void**)&bgfx_check_avail_transient_index_buffer, "bgfx_check_avail_transient_index_buffer");
104             bindFunc(cast(void**)&bgfx_check_avail_transient_vertex_buffer, "bgfx_check_avail_transient_vertex_buffer");
105             bindFunc(cast(void**)&bgfx_check_avail_instance_data_buffer, "bgfx_check_avail_instance_data_buffer");
106             bindFunc(cast(void**)&bgfx_check_avail_transient_buffers, "bgfx_check_avail_transient_buffers");
107             bindFunc(cast(void**)&bgfx_alloc_transient_index_buffer, "bgfx_alloc_transient_index_buffer");
108             bindFunc(cast(void**)&bgfx_alloc_transient_vertex_buffer, "bgfx_alloc_transient_vertex_buffer");
109             bindFunc(cast(void**)&bgfx_alloc_transient_buffers, "bgfx_alloc_transient_buffers");
110             bindFunc(cast(void**)&bgfx_alloc_instance_data_buffer, "bgfx_alloc_instance_data_buffer");
111             bindFunc(cast(void**)&bgfx_create_shader, "bgfx_create_shader");
112             bindFunc(cast(void**)&bgfx_get_shader_uniforms, "bgfx_get_shader_uniforms");
113             bindFunc(cast(void**)&bgfx_destroy_shader, "bgfx_destroy_shader");
114             bindFunc(cast(void**)&bgfx_create_program, "bgfx_create_program");
115             bindFunc(cast(void**)&bgfx_destroy_program, "bgfx_destroy_program");
116             bindFunc(cast(void**)&bgfx_calc_texture_size, "bgfx_calc_texture_size");
117             bindFunc(cast(void**)&bgfx_create_texture, "bgfx_create_texture");
118             bindFunc(cast(void**)&bgfx_create_texture_2d, "bgfx_create_texture_2d");
119             bindFunc(cast(void**)&bgfx_create_texture_3d, "bgfx_create_texture_3d");
120             bindFunc(cast(void**)&bgfx_create_texture_cube, "bgfx_create_texture_cube");
121             bindFunc(cast(void**)&bgfx_update_texture_2d, "bgfx_update_texture_2d");
122             bindFunc(cast(void**)&bgfx_update_texture_3d, "bgfx_update_texture_3d");
123             bindFunc(cast(void**)&bgfx_update_texture_cube, "bgfx_update_texture_cube");
124             bindFunc(cast(void**)&bgfx_destroy_texture, "bgfx_destroy_texture");
125             bindFunc(cast(void**)&bgfx_create_frame_buffer, "bgfx_create_frame_buffer");
126             bindFunc(cast(void**)&bgfx_create_frame_buffer_from_handles, "bgfx_create_frame_buffer_from_handles");
127             bindFunc(cast(void**)&bgfx_destroy_frame_buffer, "bgfx_destroy_frame_buffer");
128             bindFunc(cast(void**)&bgfx_create_uniform, "bgfx_create_uniform");
129             bindFunc(cast(void**)&bgfx_destroy_uniform, "bgfx_destroy_uniform");
130             bindFunc(cast(void**)&bgfx_set_view_name, "bgfx_set_view_name");
131             bindFunc(cast(void**)&bgfx_set_view_rect, "bgfx_set_view_rect");
132             bindFunc(cast(void**)&bgfx_set_view_rect_mask, "bgfx_set_view_rect_mask");
133             bindFunc(cast(void**)&bgfx_set_view_scissor, "bgfx_set_view_scissor");
134             bindFunc(cast(void**)&bgfx_set_view_scissor_mask, "bgfx_set_view_scissor_mask");
135             bindFunc(cast(void**)&bgfx_set_view_clear, "bgfx_set_view_clear");
136             bindFunc(cast(void**)&bgfx_set_view_clear_mask, "bgfx_set_view_clear_mask");
137             bindFunc(cast(void**)&bgfx_set_view_seq, "bgfx_set_view_seq");
138             bindFunc(cast(void**)&bgfx_set_view_seq_mask, "bgfx_set_view_seq_mask");
139             bindFunc(cast(void**)&bgfx_set_view_frame_buffer, "bgfx_set_view_frame_buffer");
140             bindFunc(cast(void**)&bgfx_set_view_frame_buffer_mask, "bgfx_set_view_frame_buffer_mask");
141             bindFunc(cast(void**)&bgfx_set_view_transform, "bgfx_set_view_transform");
142             bindFunc(cast(void**)&bgfx_set_view_transform_mask, "bgfx_set_view_transform_mask");
143             bindFunc(cast(void**)&bgfx_set_marker, "bgfx_set_marker");
144             bindFunc(cast(void**)&bgfx_set_state, "bgfx_set_state");
145             bindFunc(cast(void**)&bgfx_set_stencil, "bgfx_set_stencil");
146             bindFunc(cast(void**)&bgfx_set_scissor, "bgfx_set_scissor");
147             bindFunc(cast(void**)&bgfx_set_scissor_cached, "bgfx_set_scissor_cached");
148             bindFunc(cast(void**)&bgfx_set_transform, "bgfx_set_transform");
149             bindFunc(cast(void**)&bgfx_set_transform_cached, "bgfx_set_transform_cached");
150             bindFunc(cast(void**)&bgfx_set_uniform, "bgfx_set_uniform");
151             bindFunc(cast(void**)&bgfx_set_index_buffer, "bgfx_set_index_buffer");
152             bindFunc(cast(void**)&bgfx_set_dynamic_index_buffer, "bgfx_set_dynamic_index_buffer");
153             bindFunc(cast(void**)&bgfx_set_transient_index_buffer, "bgfx_set_transient_index_buffer");
154             bindFunc(cast(void**)&bgfx_set_vertex_buffer, "bgfx_set_vertex_buffer");
155             bindFunc(cast(void**)&bgfx_set_dynamic_vertex_buffer, "bgfx_set_dynamic_vertex_buffer");
156             bindFunc(cast(void**)&bgfx_set_transient_vertex_buffer, "bgfx_set_transient_vertex_buffer");
157             bindFunc(cast(void**)&bgfx_set_instance_data_buffer, "bgfx_set_instance_data_buffer");
158             bindFunc(cast(void**)&bgfx_set_program, "bgfx_set_program");
159             bindFunc(cast(void**)&bgfx_set_texture, "bgfx_set_texture");
160             bindFunc(cast(void**)&bgfx_set_texture_from_frame_buffer, "bgfx_set_texture_from_frame_buffer");
161             bindFunc(cast(void**)&bgfx_submit, "bgfx_submit");
162             bindFunc(cast(void**)&bgfx_submit_mask, "bgfx_submit_mask");
163             bindFunc(cast(void**)&bgfx_discard, "bgfx_discard");
164             bindFunc(cast(void**)&bgfx_save_screen_shot, "bgfx_save_screen_shot");
165 
166             bindFunc(cast(void**)&bgfx_render_frame, "bgfx_render_frame");
167 
168             version (Android)
169             {
170                 bindFunc(cast(void**)&bgfx_android_set_window, "bgfx_android_set_window");
171             }
172 
173             version(linux)
174             {
175                 bindFunc(cast(void**)&bgfx_x11_set_display_window, "bgfx_x11_set_display_window");
176             }
177 
178             version(OSX)
179             {
180                 bindFunc(cast(void**)&bgfx_osx_set_ns_window, "bgfx_osx_set_ns_window");
181             }
182 
183             version(Windows)
184             {
185                 bindFunc(cast(void**)&bgfx_win_set_hwnd, "bgfx_win_set_hwnd");
186             }
187         }
188     }
189 
190     public
191     {
192         this()
193         {
194             super(libNames);
195         }
196     }
197 }
198 
199 __gshared DerelictBgfxLoader DerelictBgfx;
200 
201 shared static this()
202 {
203     DerelictBgfx = new DerelictBgfxLoader();
204 }