Immediate-Mode-UI / Immediate-Mode-UI/Nuklear

Extra work to render polylines?

Open
#352 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
11.4k
Forks
686
Avg merge
4d 1h
Merged PRs (30d)
3

Description

Looking at the api, it appears as though when rendering polygons / polylines there's work being done to allocate data for the buffer, then to cast data to shorts, then later cast back to floats. I just made a quick tweak by adding an extra command to pass along a float* since all the draw calls appear to expect floating point data anyway, removed the casts. Appears to be a pretty nice improvement. Unless I'm missing something important about how those functions work.

```c

struct nk_command_polyline_float {
struct nk_command header;
struct nk_color color;
unsigned short line_thickness;
unsigned short point_count;
struct nk_vec2 *points; //struct nk_vec2 points[1];
};
//...
NK_API void
nk_stroke_polyline_float(struct nk_command_buffer* b, float* points, int point_count,
float line_thickness, struct nk_color col)
{
int i;
nk_size size = 0;
struct nk_command_polyline_float *cmd;

NK_ASSERT(b);
if (!b || col.a == 0 || line_thickness <= 0) return;
size = sizeof(*cmd);
//+ sizeof(float) * 2 * (nk_size)point_count;
cmd = (struct nk_command_polyline_float*)nk_command_buffer_push(b, NK_COMMAND_POLYLINE_FLOAT, size);
if (!cmd) return;
cmd->color = col;
cmd->point_count = (unsigned short)point_count;
cmd->line_thickness = (unsigned short)line_thickness;
cmd->points = (struct nk_vec2*)points;
}.
//...
case NK_COMMAND_POLYLINE_FLOAT: {
const struct nk_command_polyline_float* p = (const struct nk_command_polyline_float*)cmd;
nk_draw_list_stroke_poly_line(&ctx->draw_list,
p->points, p->point_count, p->color, NK_STROKE_OPEN, p->line_thickness, (&ctx->draw_list)->config.line_AA);
}
```

Also reduces the size of the command struct being allocated as we don't need to allocate any additional data.

Contributor guide

Open the contributing guide

Research direction

Start by tracing nk_stroke_polyline and the NK_COMMAND_POLYLINE path through nk_command_buffer_push to nk_draw_list_stroke_poly_line. Check how polygon and polyline commands store and consume point data, including the proposed float-pointer path. Done means confirming rendering remains correct while avoiding the intermediate short allocation and float casts, with the command allocation reduced.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
performance
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.