ogl_beamforming

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

Commit: 5055e0d4f13f8fc51358f9ed82a37ee38d3e0130
Parent: f15b9fab81866a6f6b22c95f30d4ad5aceaed1c7
Author: Randy Palamar
Date:   Mon, 12 Aug 2024 13:00:16 -0600

add displayed image filtering

Diffstat:
Mbeamformer.c | 15++++++++++++++-
Mbeamformer.h | 1+
2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/beamformer.c b/beamformer.c @@ -27,6 +27,10 @@ alloc_output_image(BeamformerCtx *ctx) UnloadRenderTexture(ctx->fsctx.output); ctx->fsctx.output = LoadRenderTexture(odim.x, odim.y); + GenTextureMipmaps(&ctx->fsctx.output.texture); + //SetTextureFilter(ctx->fsctx.output.texture, TEXTURE_FILTER_ANISOTROPIC_8X); + //SetTextureFilter(ctx->fsctx.output.texture, TEXTURE_FILTER_TRILINEAR); + SetTextureFilter(ctx->fsctx.output.texture, TEXTURE_FILTER_BILINEAR); ctx->flags &= ~ALLOC_OUT_TEX; } @@ -584,6 +588,7 @@ do_beamformer(BeamformerCtx *ctx, Arena arena) do_compute_shader(ctx, CS_UFORCES); do_compute_shader(ctx, CS_MIN_MAX); ctx->flags &= ~DO_COMPUTE; + ctx->flags |= GEN_MIPMAPS; glDeleteSync(ctx->csctx.timer_fence); ctx->csctx.timer_fence = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); } @@ -600,6 +605,12 @@ do_beamformer(BeamformerCtx *ctx, Arena arena) EndShaderMode(); EndTextureMode(); + /* NOTE: regenerate mipmaps only when the output has actually changed */ + if (ctx->flags & GEN_MIPMAPS) { + GenTextureMipmaps(&ctx->fsctx.output.texture); + ctx->flags &= ~GEN_MIPMAPS; + } + /* NOTE: Draw UI */ BeginDrawing(); ClearBackground(colour_from_normalized(BG_COLOUR)); @@ -655,8 +666,10 @@ do_beamformer(BeamformerCtx *ctx, Arena arena) /* NOTE: check mouse wheel for adjusting dynamic range of image */ v2 mouse = { .rl = GetMousePosition() }; if (CheckCollisionPointRec(mouse.rl, vr.rl)) { - ctx->fsctx.db += GetMouseWheelMove(); + f32 delta = GetMouseWheelMove(); + ctx->fsctx.db += delta; CLAMP(ctx->fsctx.db, -120, 0); + if (delta) ctx->flags |= GEN_MIPMAPS; } static f32 txt_colour_t[2]; diff --git a/beamformer.h b/beamformer.h @@ -56,6 +56,7 @@ enum program_flags { ALLOC_SSBOS = 1 << 1, ALLOC_OUT_TEX = 1 << 2, UPLOAD_FILTER = 1 << 3, + GEN_MIPMAPS = 1 << 29, DO_COMPUTE = 1 << 30, };