ogl_beamforming

Ultrasound Beamforming Implemented with OpenGL
git clone anongit@rnpnr.xyz:ogl_beamforming.git
Log | Files | Refs | Feed | Submodules | LICENSE

Commit: b70e37172cb82062608901eeb4693efe14cd889c
Parent: b149668559f6045fa4f87bcafa266f64cecdbf00
Author: Randy Palamar
Date:   Mon, 24 Jun 2024 13:32:14 -0600

add win32 platform code

Diffstat:
Mbeamformer.c | 11+----------
Mbuild.sh | 25++++++++++++++++++-------
Mmain.c | 8--------
Aos_win32.c | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mutil.c | 4++++
Mutil.h | 18+++++++++++++++++-
6 files changed, 116 insertions(+), 26 deletions(-)

diff --git a/beamformer.c b/beamformer.c @@ -1,18 +1,9 @@ /* See LICENSE for license details. */ +#define GRAPHICS_API_OPENGL_43 #include <raylib.h> #include <rlgl.h> -#include <stdatomic.h> -#include <stdio.h> -#include <stdlib.h> - -#ifndef GL_GLEXT_PROTOTYPES -#define GL_GLEXT_PROTOTYPES 1 -#include <GL/glcorearb.h> -#include <GL/glext.h> -#endif - #include "util.h" static void diff --git a/build.sh b/build.sh @@ -1,13 +1,24 @@ #!/bin/sh - cflags="-march=native -ggdb -O0 -Wall" -ldflags="-lraylib -lGL" +ldflags="-lraylib" + +case "$1" in +"win32") + cflags="$cflags -I./external/include" + ldflags="$ldflags -lgdi32 -lwinmm -L./external" + ;; +*) + ldflags="$ldflags -lGL" + + # Hot Reloading/Debugging + cflags="$cflags -D_DEBUG" + + libcflags="$cflags -fPIC -flto -Wno-unused-function" + libldflags="$ldflags -shared" -# Hot Reloading/Debugging -cflags="$cflags -D_DEBUG" + cc $libcflags beamformer.c -o beamformer.so $libldflags + ;; +esac -libcflags="$cflags -fPIC -flto" -libldflags="$ldflags -shared" -cc $libcflags beamformer.c -o beamformer.so $libldflags cc $cflags -o ogl main.c $ldflags diff --git a/main.c b/main.c @@ -3,15 +3,7 @@ #include <raylib.h> #include <rlgl.h> -#include <stdio.h> -#include <stdlib.h> - -#define GL_GLEXT_PROTOTYPES 1 -#include <GL/glcorearb.h> -#include <GL/glext.h> - #include "util.h" -#include "os_unix.c" static char *compute_shader_paths[CS_LAST] = { //[CS_MIN_MAX] = "shaders/min_max.glsl", diff --git a/os_win32.c b/os_win32.c @@ -0,0 +1,76 @@ +/* See LICENSE for license details. */ +#include <fileapi.h> +#include <handleapi.h> +#include <memoryapi.h> +#include <sysinfoapi.h> + +typedef FILETIME os_filetime; + +typedef struct { + size filesize; + os_filetime timestamp; +} os_file_stats; + +static Arena +os_new_arena(size capacity) +{ + Arena a = {0}; + + SYSTEM_INFO Info; + GetSystemInfo(&Info); + + if (capacity % Info.dwPageSize != 0) + capacity += (Info.dwPageSize - capacity % Info.dwPageSize); + + a.beg = VirtualAlloc(0, capacity, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); + if (a.beg == NULL) + die("os_new_arena: couldn't allocate memory\n"); + a.end = a.beg + capacity; + return a; +} + +static s8 +os_read_file(Arena *a, char *fname, size fsize) +{ + if (fsize > (size)U32_MAX) + die("os_read_file: %s\nHandling files >4GB is not yet " + "handled in win32 code\n", fname); + + HANDLE h = CreateFileA(fname, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0); + if (h == INVALID_HANDLE_VALUE) + die("os_read_file: couldn't open file: %s\n", fname); + + s8 ret = s8alloc(a, fsize); + + DWORD rlen = 0; + if (!ReadFile(h, ret.data, ret.len, &rlen, 0) && rlen != ret.len) + die("os_read_file: couldn't read file: %s\n", fname); + CloseHandle(h); + + return ret; +} + +static os_file_stats +os_get_file_stats(char *fname) +{ + HANDLE h = CreateFileA(fname, 0, 0, 0, OPEN_EXISTING, 0, 0); + if (h == INVALID_HANDLE_VALUE) { + fputs("os_get_file_stats: couldn't open file\n", stderr); + return (os_file_stats){0}; + } + + BY_HANDLE_FILE_INFORMATION fileinfo; + if (!GetFileInformationByHandle(h, &fileinfo)) { + fputs("os_get_file_stats: couldn't get file info\n", stderr); + CloseHandle(h); + return (os_file_stats){0}; + } + CloseHandle(h); + + size filesize = (size)fileinfo.nFileSizeHigh << 32; + filesize |= (size)fileinfo.nFileSizeLow; + return (os_file_stats){ + .filesize = filesize, + .timestamp = fileinfo.ftLastWriteTime, + }; +} diff --git a/util.c b/util.c @@ -1,4 +1,8 @@ /* See LICENSE for license details. */ +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> + static void __attribute__((noreturn)) die(char *fmt, ...) { diff --git a/util.h b/util.h @@ -2,8 +2,9 @@ #ifndef _UTIL_H_ #define _UTIL_H_ -#include <stdint.h> +#include <stdatomic.h> #include <stddef.h> +#include <stdint.h> #ifdef _DEBUG #define ASSERT(c) do { if (!(c)) asm("int3; nop"); } while (0); @@ -108,9 +109,24 @@ typedef struct { #define MEGABYTE (1024ULL * 1024ULL) #define GIGABYTE (1024ULL * 1024ULL * 1024ULL) +#define U32_MAX (0xFFFFFFFFUL) + #define ARRAY_COUNT(a) (sizeof(a) / sizeof(*a)) #define ABS(x) ((x) < 0 ? (-x) : (x)) #define CLAMP(x, a, b) ((x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x)) #include "util.c" + +#if defined(__unix__) +#define GL_GLEXT_PROTOTYPES 1 +#include <GL/glcorearb.h> +#include <GL/glext.h> +#include "os_unix.c" +#elif defined(_WIN32) +#include <glad.h> +#include "os_win32.c" +#else +#error Unsupported Platform! +#endif + #endif /*_UTIL_H_ */