From 2fb5b67012bce29f18db917c4ba2ed13f3d25b3f Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 10 Nov 2022 21:19:01 +0900 Subject: [PATCH] [vulkan] Implement line graph rendering I should probably just use the line rendering for all renderers and pull the graph drawing out to the client code. --- include/QF/Vulkan/qf_draw.h | 3 +++ libs/video/renderer/vid_render_vulkan.c | 1 + libs/video/renderer/vulkan/vulkan_draw.c | 15 +++++++++++++++ 3 files changed, 19 insertions(+) diff --git a/include/QF/Vulkan/qf_draw.h b/include/QF/Vulkan/qf_draw.h index fa4f83772..1edb16882 100644 --- a/include/QF/Vulkan/qf_draw.h +++ b/include/QF/Vulkan/qf_draw.h @@ -85,4 +85,7 @@ void Vulkan_End2D (struct vulkan_ctx_s *ctx); void Vulkan_DrawReset (struct vulkan_ctx_s *ctx); void Vulkan_FlushText (struct qfv_renderframe_s *rFrame); +void Vulkan_LineGraph (int x, int y, int *h_vals, int count, int height, + struct vulkan_ctx_s *ctx); + #endif//__QF_Vulkan_qf_draw_h diff --git a/libs/video/renderer/vid_render_vulkan.c b/libs/video/renderer/vid_render_vulkan.c index 6457ba8bc..733ada82d 100644 --- a/libs/video/renderer/vid_render_vulkan.c +++ b/libs/video/renderer/vid_render_vulkan.c @@ -136,6 +136,7 @@ vulkan_R_NewScene (scene_t *scene) static void vulkan_R_LineGraph (int x, int y, int *h_vals, int count, int height) { + Vulkan_LineGraph (x, y, h_vals, count, height, vulkan_ctx); } static void diff --git a/libs/video/renderer/vulkan/vulkan_draw.c b/libs/video/renderer/vulkan/vulkan_draw.c index 127b6645e..f520e8ba5 100644 --- a/libs/video/renderer/vulkan/vulkan_draw.c +++ b/libs/video/renderer/vulkan/vulkan_draw.c @@ -1330,3 +1330,18 @@ Vulkan_Draw_FontString (int x, int y, int fontid, const char *str, RText_RenderText (shaper, &text, x, y, vulkan_render_glyph, &rgctx); RText_DeleteShaper (shaper); } + +void +Vulkan_LineGraph (int x, int y, int *h_vals, int count, int height, + vulkan_ctx_t *ctx) +{ + static int colors[] = { 0xd0, 0x4f, 0x6f }; + + while (count-- > 0) { + int h = *h_vals++; + int c = h < 9998 || h > 10000 ? 0xfe : colors[h - 9998]; + h = min (h, height); + Vulkan_Draw_Line (x, y, x, y - h, c, ctx); + x++; + } +}