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:
authorChris Blackbourn <chrisbblend@gmail.com>2022-06-09 04:03:12 +0300
committerChris Blackbourn <chrisbblend@gmail.com>2022-06-09 04:03:12 +0300
commit443699c201610a4caf57103329270122c57b0f1b (patch)
treeb61514f765096e466c0a99ca79dc867201c77703
parent431187edf84b79d8f2f1f52cc619789afef4fb57 (diff)
Cleanup (GPU): Faster circle drawing.temp-circle
-rw-r--r--source/blender/gpu/intern/gpu_immediate_util.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/source/blender/gpu/intern/gpu_immediate_util.c b/source/blender/gpu/intern/gpu_immediate_util.c
index 67035853594..d03c3e8a8af 100644
--- a/source/blender/gpu/intern/gpu_immediate_util.c
+++ b/source/blender/gpu/intern/gpu_immediate_util.c
@@ -337,13 +337,27 @@ static void imm_draw_circle_3D(
/* Note(Metal/AMD): For small primitives, line list more efficient than line strip. */
immBegin(GPU_PRIM_LINES, nsegments * 2);
- immVertex3f(pos, x + radius * cosf(0.0f), y + radius * sinf(0.0f), 0.0f);
- for (int i = 1; i < nsegments; i++) {
- float angle = (float)(2 * M_PI) * ((float)i / (float)nsegments);
- immVertex3f(pos, x + radius * cosf(angle), y + radius * sinf(angle), 0.0f);
- immVertex3f(pos, x + radius * cosf(angle), y + radius * sinf(angle), 0.0f);
+ const float angle = (float)(2 * M_PI / (float)nsegments);
+ float xprev = cosf(-angle) * radius;
+ float yprev = sinf(-angle) * radius;
+ const float alpha = 2.0f * cosf(angle);
+
+ float xr = radius;
+ float yr = 0;
+
+ for (int i = 0; i < nsegments; i++) {
+ immVertex3f(pos, x + xr, y + yr, 0.0f);
+ if (i) {
+ immVertex3f(pos, x + xr, y + yr, 0.0f);
+ }
+ const float xnext = alpha * xr - xprev;
+ const float ynext = alpha * yr - yprev;
+ xprev = xr;
+ yprev = yr;
+ xr = xnext;
+ yr = ynext;
}
- immVertex3f(pos, x + radius * cosf(0.0f), y + radius * sinf(0.0f), 0.0f);
+ immVertex3f(pos, x + radius, y, 0.0f);
immEnd();
}
else {