Commit: 85e0891e6f8b1c6c65aad9409267a58f38b55bae
Parent: b70e37172cb82062608901eeb4693efe14cd889c
Author: Randy Palamar
Date: Tue, 25 Jun 2024 13:17:40 -0600
draw output image to a RenderTexture
Diffstat:
3 files changed, 20 insertions(+), 21 deletions(-)
diff --git a/beamformer.c b/beamformer.c
@@ -102,20 +102,25 @@ do_beamformer(BeamformerCtx *ctx, Arena arena, s8 rf_data)
do_compute_shader(ctx, rf_ssbo_idx, CS_UFORCES);
}
- BeginDrawing();
-
- ClearBackground(ctx->bg);
+ BeginTextureMode(ctx->fsctx.output);
+ ClearBackground(ctx->bg);
+ BeginShaderMode(ctx->fsctx.shader);
+ glUseProgram(ctx->fsctx.shader.id);
+ glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, ctx->out_data_ssbo);
+ glUniform3uiv(ctx->fsctx.out_data_dim_id, 1, ctx->out_data_dim.E);
+ DrawTexture(ctx->fsctx.output.texture, 0, 0, WHITE);
+ EndShaderMode();
+ EndTextureMode();
- BeginShaderMode(ctx->fsctx.shader);
- glUseProgram(ctx->fsctx.shader.id);
- glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, ctx->out_data_ssbo);
- glUniform3uiv(ctx->fsctx.out_data_dim_id, 1, ctx->out_data_dim.E);
- DrawTexture(ctx->fsctx.output, 0, 0, WHITE);
- EndShaderMode();
+ BeginDrawing();
+ ClearBackground(ctx->bg);
- DrawTextEx(ctx->font, txt[txt_idx], pos.rl, fontsize, fontspace, BLACK);
- draw_debug_overlay(ctx, arena);
+ Texture *rtext = &ctx->fsctx.output.texture;
+ Rectangle rect = { 0.0f, 0.0f, (f32)rtext->width, -(f32)rtext->height };
+ DrawTextureRec(*rtext, rect, (Vector2){0}, WHITE);
+ DrawTextEx(ctx->font, txt[txt_idx], pos.rl, fontsize, fontspace, BLACK);
+ draw_debug_overlay(ctx, arena);
EndDrawing();
if (IsKeyPressed(KEY_R))
diff --git a/main.c b/main.c
@@ -152,13 +152,7 @@ init_fragment_shader_ctx(FragmentShaderCtx *ctx, uv3 out_data_dim)
/* TODO: add min max uniform */
/* output texture for image blitting */
- Texture2D new;
- new.width = out_data_dim.w;
- new.height = out_data_dim.h;
- new.mipmaps = 1;
- new.format = RL_PIXELFORMAT_UNCOMPRESSED_R32G32B32A32;
- new.id = rlLoadTexture(0, new.width, new.height, new.format, new.mipmaps);
- ctx->output = new;
+ ctx->output = LoadRenderTexture(out_data_dim.w, out_data_dim.h);
}
static u32
diff --git a/util.h b/util.h
@@ -86,9 +86,9 @@ typedef struct {
} ComputeShaderCtx;
typedef struct {
- Shader shader;
- Texture2D output;
- i32 out_data_dim_id;
+ Shader shader;
+ RenderTexture2D output;
+ i32 out_data_dim_id;
} FragmentShaderCtx;
typedef struct {