Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpembem22 <pembem22>2020-08-28 23:22:36 +0300
committerHans Goudey <h.goudey@me.com>2020-08-28 23:22:36 +0300
commitd8283a1f89493076ec2750350a31d45233da6c11 (patch)
treefa3d1d5530a86a761c3c9cd85bec4574682b236c /source/blender/editors
parent744eb1172e3ba16af21813de6c1e772490a68b91 (diff)
UI: Improve curve grid drawing code
This patch fixes assert on grid drawing. `for` loops are used instead of `while` loops to make sure the number of lines is exact. The old code draws lots of unnecessary lines offscreen. This bug is fixed as well. See the patch for a comparison without a scissor test. Differential Revision: https://developer.blender.org/D8745
Diffstat (limited to 'source/blender/editors')
-rw-r--r--source/blender/editors/interface/interface_draw.c48
1 files changed, 23 insertions, 25 deletions
diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c
index 25c5e63d23e..13dd4ce3001 100644
--- a/source/blender/editors/interface/interface_draw.c
+++ b/source/blender/editors/interface/interface_draw.c
@@ -1825,37 +1825,35 @@ void ui_draw_but_UNITVEC(uiBut *but, const uiWidgetColors *wcol, const rcti *rec
immUnbindProgram();
}
-static void ui_draw_but_curve_grid(
- uint pos, const rcti *rect, float zoomx, float zoomy, float offsx, float offsy, float step)
+static void ui_draw_but_curve_grid(const uint pos,
+ const rcti *rect,
+ const float zoom_x,
+ const float zoom_y,
+ const float offset_x,
+ const float offset_y,
+ const float step)
{
- const float dx = step * zoomx;
- float fx = rect->xmin + zoomx * (-offsx);
- if (fx > rect->xmin) {
- fx -= dx * (floorf(fx - rect->xmin));
- }
+ const float start_x = (ceilf(offset_x / step) * step - offset_x) * zoom_x + rect->xmin;
+ const float start_y = (ceilf(offset_y / step) * step - offset_y) * zoom_y + rect->ymin;
- const float dy = step * zoomy;
- float fy = rect->ymin + zoomy * (-offsy);
- if (fy > rect->ymin) {
- fy -= dy * (floorf(fy - rect->ymin));
- }
+ const int line_count_x = ceilf((rect->xmax - start_x) / (step * zoom_x));
+ const int line_count_y = ceilf((rect->ymax - start_y) / (step * zoom_y));
- float line_count = (floorf((rect->xmax - fx) / dx) + 1.0f + floorf((rect->ymax - fy) / dy) +
- 1.0f);
+ if (line_count_x + line_count_y == 0) {
+ return;
+ }
- immBegin(GPU_PRIM_LINES, (int)line_count * 2);
- while (fx <= rect->xmax) {
- immVertex2f(pos, fx, rect->ymin);
- immVertex2f(pos, fx, rect->ymax);
- fx += dx;
+ immBegin(GPU_PRIM_LINES, (line_count_x + line_count_y) * 2);
+ for (int i = 0; i < line_count_x; i++) {
+ const float x = start_x + i * step * zoom_x;
+ immVertex2f(pos, x, rect->ymin);
+ immVertex2f(pos, x, rect->ymax);
}
- while (fy <= rect->ymax) {
- immVertex2f(pos, rect->xmin, fy);
- immVertex2f(pos, rect->xmax, fy);
- fy += dy;
+ for (int i = 0; i < line_count_y; i++) {
+ const float y = start_y + i * step * zoom_y;
+ immVertex2f(pos, rect->xmin, y);
+ immVertex2f(pos, rect->xmax, y);
}
- /* Note: Assertion fails with here when the view is moved farther below the center.
- * Missing two points from the number given with immBegin. */
immEnd();
}