[Bf-blender-cvs] [9a77f33badc] blender2.8: GPU: utility function to draw a partial circle
Campbell Barton
noreply at git.blender.org
Mon Sep 24 08:15:42 CEST 2018
Commit: 9a77f33badce2dfc24350ecc800c1c4beeb79acc
Author: Campbell Barton
Date: Mon Sep 24 16:22:22 2018 +1000
Branches: blender2.8
https://developer.blender.org/rB9a77f33badce2dfc24350ecc800c1c4beeb79acc
GPU: utility function to draw a partial circle
===================================================================
M source/blender/gpu/GPU_immediate_util.h
M source/blender/gpu/intern/gpu_immediate_util.c
===================================================================
diff --git a/source/blender/gpu/GPU_immediate_util.h b/source/blender/gpu/GPU_immediate_util.h
index 58555e287b0..9f1d9646246 100644
--- a/source/blender/gpu/GPU_immediate_util.h
+++ b/source/blender/gpu/GPU_immediate_util.h
@@ -48,6 +48,11 @@ void imm_draw_circle_fill_aspect_2d(uint shdr_pos, float x, float y, float radiu
void imm_draw_circle_wire_3d(uint pos, float x, float y, float radius, int nsegments);
void imm_draw_circle_fill_3d(uint pos, float x, float y, float radius, int nsegments);
+/* same as 'imm_draw_disk_partial_fill_2d', except it draws a wire arc. */
+void imm_draw_circle_partial_wire_2d(
+ uint pos, float x, float y,
+ float radius, int nsegments, float start, float sweep);
+
void imm_draw_disk_partial_fill_2d(
uint pos, float x, float y,
float radius_inner, float radius_outer, int nsegments, float start, float sweep);
diff --git a/source/blender/gpu/intern/gpu_immediate_util.c b/source/blender/gpu/intern/gpu_immediate_util.c
index fdba7800016..93695e0fbab 100644
--- a/source/blender/gpu/intern/gpu_immediate_util.c
+++ b/source/blender/gpu/intern/gpu_immediate_util.c
@@ -201,9 +201,31 @@ void imm_draw_circle_fill_aspect_2d(uint shdr_pos, float x, float y, float rad_x
imm_draw_circle(GPU_PRIM_TRI_FAN, shdr_pos, x, y, rad_x, rad_y, nsegments);
}
-/**
- * \note We could have `imm_draw_lined_disk_partial` but currently there is no need.
- */
+static void imm_draw_circle_partial(
+ GPUPrimType prim_type, uint pos, float x, float y,
+ float rad, int nsegments, float start, float sweep)
+{
+ /* shift & reverse angle, increase 'nsegments' to match gluPartialDisk */
+ const float angle_start = -(DEG2RADF(start)) + (float)(M_PI / 2);
+ const float angle_end = -(DEG2RADF(sweep) - angle_start);
+ nsegments += 1;
+ immBegin(prim_type, nsegments);
+ for (int i = 0; i < nsegments; ++i) {
+ const float angle = interpf(angle_start, angle_end, ((float)i / (float)(nsegments - 1)));
+ const float angle_sin = sinf(angle);
+ const float angle_cos = cosf(angle);
+ immVertex2f(pos, x + rad * angle_cos, y + rad * angle_sin);
+ }
+ immEnd();
+}
+
+void imm_draw_circle_partial_wire_2d(
+ uint pos, float x, float y,
+ float rad, int nsegments, float start, float sweep)
+{
+ imm_draw_circle_partial(GPU_PRIM_LINE_STRIP, pos, x, y, rad, nsegments, start, sweep);
+}
+
static void imm_draw_disk_partial(
GPUPrimType prim_type, uint pos, float x, float y,
float rad_inner, float rad_outer, int nsegments, float start, float sweep)
More information about the Bf-blender-cvs
mailing list