Commit: b424e774689fac0c11a54fa07d7ac81bb6862cfe
Parent: 47ed0e4eb83b38dac3216e2c67f5366228f9a4b6
Author: Randy Palamar
Date: Fri, 5 Jul 2024 13:44:22 -0600
make util.h self contained so that os_win32.c can be cross-compiled
Diffstat:
M | beamformer.c | | | 7 | +------ |
A | beamformer.h | | | 106 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
M | main.c | | | 7 | +------ |
M | os_win32.c | | | 2 | ++ |
M | util.h | | | 106 | +++++-------------------------------------------------------------------------- |
5 files changed, 116 insertions(+), 112 deletions(-)
diff --git a/beamformer.c b/beamformer.c
@@ -1,10 +1,5 @@
/* See LICENSE for license details. */
-
-#define GRAPHICS_API_OPENGL_43
-#include <raylib.h>
-#include <rlgl.h>
-
-#include "util.h"
+#include "beamformer.h"
static void
do_compute_shader(BeamformerCtx *ctx, enum compute_shaders shader)
diff --git a/beamformer.h b/beamformer.h
@@ -0,0 +1,106 @@
+/* See LICENSE for license details. */
+#ifndef _BEAMFORMER_H_
+#define _BEAMFORMER_H_
+
+#include <immintrin.h>
+
+#define GRAPHICS_API_OPENGL_43
+#include <raylib.h>
+#include <rlgl.h>
+
+#include "util.h"
+
+typedef union {
+ struct { u32 x, y; };
+ struct { u32 w, h; };
+ u32 E[2];
+} uv2;
+
+typedef union {
+ struct { u32 x, y, z; };
+ struct { u32 w, h, d; };
+ u32 E[3];
+} uv3;
+
+typedef union {
+ struct { f32 x, y; };
+ f32 E[2];
+ Vector2 rl;
+} v2;
+
+typedef union {
+ struct { f32 x, y, z, w; };
+ struct { f32 r, g, b, a; };
+ f32 E[4];
+ Vector4 rl;
+} v4;
+
+enum compute_shaders {
+// CS_FORCES,
+ CS_HADAMARD,
+// CS_HERCULES,
+ CS_MIN_MAX,
+ CS_UFORCES,
+ CS_LAST
+};
+
+enum program_flags {
+ RELOAD_SHADERS = 1 << 0,
+};
+
+#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
+
+typedef struct {
+ u32 programs[CS_LAST];
+
+ /* NOTE: One SSBO for raw data and one for decoded data */
+ u32 rf_data_ssbos[2];
+ u32 hadamard_ssbo;
+ uv2 hadamard_dim;
+
+ uv3 rf_data_dim;
+ i32 rf_data_dim_id;
+ i32 out_data_tex_id;
+ i32 mip_view_tex_id;
+ i32 mips_level_id;
+} ComputeShaderCtx;
+
+typedef struct {
+ Shader shader;
+ RenderTexture2D output;
+ i32 out_data_tex_id;
+ i32 db_cutoff_id;
+ f32 db;
+} FragmentShaderCtx;
+
+typedef struct {
+ uv2 window_size;
+ u32 flags;
+
+ Font font;
+
+ Color bg, fg;
+
+ uv3 out_data_dim;
+ u32 out_texture;
+ u32 out_texture_unit;
+ u32 out_texture_mips;
+
+ ComputeShaderCtx csctx;
+ FragmentShaderCtx fsctx;
+
+ os_pipe data_pipe;
+ u32 partial_transfer_count;
+} BeamformerCtx;
+
+#endif /*_BEAMFORMER_H_ */
diff --git a/main.c b/main.c
@@ -1,10 +1,5 @@
/* See LICENSE for license details. */
-
-#include <immintrin.h>
-#include <raylib.h>
-#include <rlgl.h>
-
-#include "util.h"
+#include "beamformer.h"
static char *compute_shader_paths[CS_LAST] = {
[CS_MIN_MAX] = "shaders/min_max.glsl",
diff --git a/os_win32.c b/os_win32.c
@@ -8,6 +8,8 @@
typedef void *HWND;
#include <winbase.h>
+#include "util.h"
+
#define OS_INVALID_FILE (INVALID_HANDLE_VALUE)
typedef HANDLE os_file;
typedef struct {
diff --git a/util.h b/util.h
@@ -13,17 +13,17 @@
#define DEBUG_EXPORT static
#endif
-#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 MAX(a, b) ((a) > (b) ? (a) : (b))
#define CLAMP(x, a, b) ((x) = (x) < (a) ? (a) : (x) > (b) ? (b) : (x))
#define ISPOWEROF2(a) (((a) & ((a) - 1)) == 0)
+#define MEGABYTE (1024ULL * 1024ULL)
+#define GIGABYTE (1024ULL * 1024ULL * 1024ULL)
+
+#define U32_MAX (0xFFFFFFFFUL)
+
typedef uint8_t u8;
typedef int16_t i16;
typedef int32_t i32;
@@ -37,100 +37,6 @@ typedef struct { u8 *beg, *end; } Arena;
typedef struct { size len; u8 *data; } s8;
-typedef union {
- struct { u32 x, y; };
- struct { u32 w, h; };
- u32 E[2];
-} uv2;
-
-typedef union {
- struct { u32 x, y, z; };
- struct { u32 w, h, d; };
- u32 E[3];
-} uv3;
-
-typedef union {
- struct { f32 x, y; };
- f32 E[2];
- Vector2 rl;
-} v2;
-
-typedef union {
- struct { f32 x, y, z, w; };
- struct { f32 r, g, b, a; };
- f32 E[4];
- Vector4 rl;
-} v4;
-
-enum compute_shaders {
-// CS_FORCES,
- CS_HADAMARD,
-// CS_HERCULES,
- CS_MIN_MAX,
- CS_UFORCES,
- CS_LAST
-};
-
-enum program_flags {
- RELOAD_SHADERS = 1 << 0,
-};
-
#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
-
-typedef struct {
- u32 programs[CS_LAST];
-
- /* NOTE: One SSBO for raw data and one for decoded data */
- u32 rf_data_ssbos[2];
- u32 hadamard_ssbo;
- uv2 hadamard_dim;
-
- uv3 rf_data_dim;
- i32 rf_data_dim_id;
- i32 out_data_tex_id;
- i32 mip_view_tex_id;
- i32 mips_level_id;
-} ComputeShaderCtx;
-
-typedef struct {
- Shader shader;
- RenderTexture2D output;
- i32 out_data_tex_id;
- i32 db_cutoff_id;
- f32 db;
-} FragmentShaderCtx;
-
-typedef struct {
- uv2 window_size;
- u32 flags;
-
- Font font;
-
- Color bg, fg;
-
- uv3 out_data_dim;
- u32 out_texture;
- u32 out_texture_unit;
- u32 out_texture_mips;
-
- ComputeShaderCtx csctx;
- FragmentShaderCtx fsctx;
-
- os_pipe data_pipe;
- u32 partial_transfer_count;
-} BeamformerCtx;
-
-#endif /*_UTIL_H_ */
+#endif /* _UTIL_H_ */