diff options
author | Campbell Barton <ideasman42@gmail.com> | 2017-04-05 11:30:14 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2017-04-05 11:43:59 +0300 |
commit | a4fac21fc5a2e5e3c816884da6499f931dfe6dd1 (patch) | |
tree | 4b99909176b694a7d6985f94f5a724ddb60a6bf5 /source/blender/editors/screen/glutil.c | |
parent | e9bb018a4aea1b4aeb692cdadce158496a270e32 (diff) |
Cleanup: Move imm_draw utils into own file
These were in BIF_glutil which is documented to be removed,
so best not define new API's there.
Diffstat (limited to 'source/blender/editors/screen/glutil.c')
-rw-r--r-- | source/blender/editors/screen/glutil.c | 245 |
1 files changed, 2 insertions, 243 deletions
diff --git a/source/blender/editors/screen/glutil.c b/source/blender/editors/screen/glutil.c index 1852df66df7..57bff45fc6e 100644 --- a/source/blender/editors/screen/glutil.c +++ b/source/blender/editors/screen/glutil.c @@ -82,249 +82,6 @@ void set_inverted_drawing(int enable) GL_TOGGLE(GL_DITHER, !enable); } -static void imm_draw_circle(PrimitiveType prim_type, unsigned pos, float x, float y, float rad, int nsegments) -{ - immBegin(prim_type, nsegments); - for (int i = 0; i < nsegments; ++i) { - float angle = 2 * M_PI * ((float)i / (float)nsegments); - immVertex2f(pos, x + rad * cosf(angle), y + rad * sinf(angle)); - } - immEnd(); -} - -void imm_draw_lined_circle(unsigned pos, float x, float y, float rad, int nsegments) -{ - imm_draw_circle(PRIM_LINE_LOOP, pos, x, y, rad, nsegments); -} - -void imm_draw_circle_fill(unsigned pos, float x, float y, float rad, int nsegments) -{ - imm_draw_circle(PRIM_TRIANGLE_FAN, pos, x, y, rad, nsegments); -} - -/** - * \note We could have `imm_draw_lined_disk_partial` but currently there is no need. - */ -static void imm_draw_disk_partial( - PrimitiveType prim_type, unsigned pos, float x, float y, - float rad_inner, float rad_outer, int nsegments, float start, float sweep) -{ - /* shift & reverse angle, increase 'nsegments' to match gluPartialDisk */ - const float angle_start = -(DEG2RADF(start)) + (M_PI / 2); - const float angle_end = -(DEG2RADF(sweep) - angle_start); - nsegments += 1; - immBegin(prim_type, nsegments * 2); - 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_inner * angle_cos, y + rad_inner * angle_sin); - immVertex2f(pos, x + rad_outer * angle_cos, y + rad_outer * angle_sin); - } - immEnd(); -} - -/** - * Replacement for gluPartialDisk, (without 'loops' argument). - */ -void imm_draw_disk_partial_fill( - unsigned pos, float x, float y, - float rad_inner, float rad_outer, int nsegments, float start, float sweep) -{ - imm_draw_disk_partial(PRIM_TRIANGLE_STRIP, pos, x, y, rad_inner, rad_outer, nsegments, start, sweep); -} - -static void imm_draw_circle_3D( - PrimitiveType prim_type, unsigned pos, float x, float y, - float rad, int nsegments) -{ - immBegin(prim_type, nsegments); - for (int i = 0; i < nsegments; ++i) { - float angle = 2 * M_PI * ((float)i / (float)nsegments); - immVertex3f(pos, x + rad * cosf(angle), y + rad * sinf(angle), 0.0f); - } - immEnd(); -} - -void imm_draw_circle_wire_3d(unsigned pos, float x, float y, float rad, int nsegments) -{ - imm_draw_circle_3D(PRIM_LINE_LOOP, pos, x, y, rad, nsegments); -} - -void imm_draw_circle_fill_3d(unsigned pos, float x, float y, float rad, int nsegments) -{ - imm_draw_circle_3D(PRIM_TRIANGLE_FAN, pos, x, y, rad, nsegments); -} - -void imm_draw_line_box(unsigned pos, float x1, float y1, float x2, float y2) -{ - immBegin(PRIM_LINE_LOOP, 4); - immVertex2f(pos, x1, y1); - immVertex2f(pos, x1, y2); - immVertex2f(pos, x2, y2); - immVertex2f(pos, x2, y1); - immEnd(); -} - -void imm_draw_line_box_3d(unsigned pos, float x1, float y1, float x2, float y2) -{ - /* use this version when VertexFormat has a vec3 position */ - immBegin(PRIM_LINE_LOOP, 4); - immVertex3f(pos, x1, y1, 0.0f); - immVertex3f(pos, x1, y2, 0.0f); - immVertex3f(pos, x2, y2, 0.0f); - immVertex3f(pos, x2, y1, 0.0f); - immEnd(); -} - -void imm_draw_checker_box(float x1, float y1, float x2, float y2) -{ - unsigned int pos = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 2, KEEP_FLOAT); - immBindBuiltinProgram(GPU_SHADER_2D_CHECKER); - - immUniform4f("color1", 0.15f, 0.15f, 0.15f, 1.0f); - immUniform4f("color2", 0.2f, 0.2f, 0.2f, 1.0f); - immUniform1i("size", 8); - - immRectf(pos, x1, y1, x2, y2); - - immUnbindProgram(); -} - -void imm_cpack(unsigned int x) -{ - immUniformColor3ub(((x) & 0xFF), - (((x) >> 8) & 0xFF), - (((x) >> 16) & 0xFF)); -} - -void imm_draw_cylinder_fill_normal_3d( - unsigned int pos, unsigned int nor, float base, float top, float height, int slices, int stacks) -{ - immBegin(GL_TRIANGLES, 6 * slices * stacks); - for (int i = 0; i < slices; ++i) { - const float angle1 = 2 * M_PI * ((float)i / (float)slices); - const float angle2 = 2 * M_PI * ((float)(i + 1) / (float)slices); - const float cos1 = cosf(angle1); - const float sin1 = sinf(angle1); - const float cos2 = cosf(angle2); - const float sin2 = sinf(angle2); - - for (int j = 0; j < stacks; ++j) { - float fac1 = (float)j / (float)stacks; - float fac2 = (float)(j + 1) / (float)stacks; - float r1 = base * (1.f - fac1) + top * fac1; - float r2 = base * (1.f - fac2) + top * fac2; - float h1 = height * ((float)j / (float)stacks); - float h2 = height * ((float)(j + 1) / (float)stacks); - - float v1[3] = {r1 *cos2, r1 * sin2, h1}; - float v2[3] = {r2 *cos2, r2 * sin2, h2}; - float v3[3] = {r2 *cos1, r2 * sin1, h2}; - float v4[3] = {r1 *cos1, r1 * sin1, h1}; - float n1[3], n2[3]; - - /* calc normals */ - sub_v3_v3v3(n1, v2, v1); - normalize_v3(n1); - n1[0] = cos1; n1[1] = sin1; n1[2] = 1 - n1[2]; - - sub_v3_v3v3(n2, v3, v4); - normalize_v3(n2); - n2[0] = cos2; n2[1] = sin2; n2[2] = 1 - n2[2]; - - /* first tri */ - immAttrib3fv(nor, n2); - immVertex3fv(pos, v1); - immVertex3fv(pos, v2); - immAttrib3fv(nor, n1); - immVertex3fv(pos, v3); - - /* second tri */ - immVertex3fv(pos, v3); - immVertex3fv(pos, v4); - immAttrib3fv(nor, n2); - immVertex3fv(pos, v1); - } - } - immEnd(); -} - -void imm_draw_cylinder_wire_3d(unsigned int pos, float base, float top, float height, int slices, int stacks) -{ - immBegin(GL_LINES, 6 * slices * stacks); - for (int i = 0; i < slices; ++i) { - const float angle1 = 2 * M_PI * ((float)i / (float)slices); - const float angle2 = 2 * M_PI * ((float)(i + 1) / (float)slices); - const float cos1 = cosf(angle1); - const float sin1 = sinf(angle1); - const float cos2 = cosf(angle2); - const float sin2 = sinf(angle2); - - for (int j = 0; j < stacks; ++j) { - float fac1 = (float)j / (float)stacks; - float fac2 = (float)(j + 1) / (float)stacks; - float r1 = base * (1.f - fac1) + top * fac1; - float r2 = base * (1.f - fac2) + top * fac2; - float h1 = height * ((float)j / (float)stacks); - float h2 = height * ((float)(j + 1) / (float)stacks); - - float v1[3] = {r1 * cos2, r1 * sin2, h1}; - float v2[3] = {r2 * cos2, r2 * sin2, h2}; - float v3[3] = {r2 * cos1, r2 * sin1, h2}; - float v4[3] = {r1 * cos1, r1 * sin1, h1}; - - immVertex3fv(pos, v1); - immVertex3fv(pos, v2); - - immVertex3fv(pos, v2); - immVertex3fv(pos, v3); - - immVertex3fv(pos, v1); - immVertex3fv(pos, v4); - } - } - immEnd(); -} - -void imm_draw_cylinder_fill_3d(unsigned int pos, float base, float top, float height, int slices, int stacks) -{ - immBegin(GL_TRIANGLES, 6 * slices * stacks); - for (int i = 0; i < slices; ++i) { - const float angle1 = 2 * M_PI * ((float)i / (float)slices); - const float angle2 = 2 * M_PI * ((float)(i + 1) / (float)slices); - const float cos1 = cosf(angle1); - const float sin1 = sinf(angle1); - const float cos2 = cosf(angle2); - const float sin2 = sinf(angle2); - - for (int j = 0; j < stacks; ++j) { - float fac1 = (float)j / (float)stacks; - float fac2 = (float)(j + 1) / (float)stacks; - float r1 = base * (1.f - fac1) + top * fac1; - float r2 = base * (1.f - fac2) + top * fac2; - float h1 = height * ((float)j / (float)stacks); - float h2 = height * ((float)(j + 1) / (float)stacks); - - float v1[3] = {r1 * cos2, r1 * sin2, h1}; - float v2[3] = {r2 * cos2, r2 * sin2, h2}; - float v3[3] = {r2 * cos1, r2 * sin1, h2}; - float v4[3] = {r1 * cos1, r1 * sin1, h1}; - - /* first tri */ - immVertex3fv(pos, v1); - immVertex3fv(pos, v2); - immVertex3fv(pos, v3); - - /* second tri */ - immVertex3fv(pos, v3); - immVertex3fv(pos, v4); - immVertex3fv(pos, v1); - } - } - immEnd(); -} - float glaGetOneFloat(int param) { GLfloat v; @@ -927,6 +684,8 @@ void cpack(unsigned int x) (((x) >> 16) & 0xFF)); } +/* don't move to GPU_immediate_util.h because this uses user-prefs + * and isn't very low level */ void immDrawBorderCorners(unsigned int pos, const rcti *border, float zoomx, float zoomy) { float delta_x = 4.0f * UI_DPI_FAC / zoomx; |