main_generic.c (2178B)
1 /* See LICENSE for license details. */ 2 #include "beamformer.h" 3 4 #if defined(__unix__) 5 #include "os_unix.c" 6 7 #define OS_DEBUG_LIB_NAME "./beamformer.so" 8 #define OS_DEBUG_LIB_TEMP_NAME "./beamformer_temp.so" 9 10 #define OS_CUDA_LIB_NAME "./external/cuda_toolkit.so" 11 #define OS_CUDA_LIB_TEMP_NAME "./external/cuda_toolkit_temp.so" 12 13 #define OS_PIPE_NAME "/tmp/beamformer_data_fifo" 14 #define OS_SMEM_NAME "/ogl_beamformer_parameters" 15 16 #elif defined(_WIN32) 17 #include "os_win32.c" 18 19 #define OS_DEBUG_LIB_NAME "beamformer.dll" 20 #define OS_DEBUG_LIB_TEMP_NAME "beamformer_temp.dll" 21 22 #define OS_CUDA_LIB_NAME "external\\cuda_toolkit.dll" 23 #define OS_CUDA_LIB_TEMP_NAME "external\\cuda_toolkit_temp.dll" 24 25 #define OS_PIPE_NAME "\\\\.\\pipe\\beamformer_data_fifo" 26 #define OS_SMEM_NAME "Local\\ogl_beamformer_parameters" 27 #else 28 #error Unsupported Platform! 29 #endif 30 31 #include "static.c" 32 33 int 34 main(void) 35 { 36 BeamformerCtx ctx = {0}; 37 BeamformerInput input = {0}; 38 Arena temp_memory = os_alloc_arena((Arena){0}, 16 * MEGABYTE); 39 ctx.error_stream = stream_alloc(&temp_memory, 1 * MEGABYTE); 40 41 ctx.ui_backing_store = sub_arena(&temp_memory, 2 * MEGABYTE); 42 43 Pipe data_pipe = os_open_named_pipe(OS_PIPE_NAME); 44 input.pipe_handle = data_pipe.file; 45 ASSERT(data_pipe.file != INVALID_FILE); 46 47 input.executable_reloaded = 1; 48 49 #define X(name) ctx.platform.name = os_ ## name; 50 PLATFORM_FNS 51 #undef X 52 53 setup_beamformer(&ctx, temp_memory); 54 55 while(!(ctx.flags & SHOULD_EXIT)) { 56 do_debug(&ctx.error_stream); 57 if (ctx.gl.vendor_id == GL_VENDOR_NVIDIA) 58 check_and_load_cuda_lib(&ctx.cuda_lib, &ctx.error_stream); 59 60 if (ctx.flags & RELOAD_SHADERS) { 61 ctx.flags &= ~RELOAD_SHADERS; 62 reload_shaders(&ctx, temp_memory); 63 } 64 65 input.last_mouse = input.mouse; 66 input.mouse.rl = GetMousePosition(); 67 input.pipe_data_available = os_poll_pipe(data_pipe); 68 69 beamformer_frame_step(&ctx, &temp_memory, &input); 70 71 input.executable_reloaded = 0; 72 } 73 74 /* NOTE: make sure this will get cleaned up after external 75 * programs release their references */ 76 os_remove_shared_memory(OS_SMEM_NAME); 77 78 /* NOTE: garbage code needed for Linux */ 79 os_close_named_pipe(data_pipe); 80 }