OpenGl immediate mode: remove imm_draw_line

Replaced all calls to `imm_draw_line` by plain `immVertex2f` calls, and
removed `imm_draw_line`, as that function was not supposed to exist in
the first place, and causes unnecessary calls to `immBegin`/`immEnd`.

Part of T49043
This commit is contained in:
2017-02-23 02:52:36 -03:00
parent 30420845b9
commit 3b3ed19c18
7 changed files with 172 additions and 51 deletions

View File

@@ -131,7 +131,6 @@ void imm_draw_line_box_3D(unsigned pos, float x1, float y1, float x2, float y2);
/* Draw a standard checkerboard to indicate transparent backgrounds */
void imm_draw_checker_box(float x1, float y1, float x2, float y2);
void imm_draw_line(unsigned pos, float x1, float y1, float x2, float y2);
/**
* Pack color into 3 bytes
*

View File

@@ -667,8 +667,15 @@ void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol)
immUniformColor4f(1.0f, 1.0f, 1.0f, 0.5f);
}
imm_draw_line(pos, rect.xmin, rect.ymin + fac * h, rect.xmax, rect.ymin + fac * h);
imm_draw_line(pos, rect.xmin + fac * w, rect.ymin, rect.xmin + fac * w, rect.ymax);
immBegin(GL_LINES, 4);
immVertex2f(pos, rect.xmin, rect.ymin + fac * h);
immVertex2f(pos, rect.xmax, rect.ymin + fac * h);
immVertex2f(pos, rect.xmin + fac * w, rect.ymin);
immVertex2f(pos, rect.xmin + fac * w, rect.ymax);
immEnd();
}
if (hist->mode == HISTO_MODE_LUMA) {
@@ -783,30 +790,61 @@ void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol),
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
immUniformColor4f(1.0f, 1.0f, 1.0f, 0.08f);
/* draw grid lines here */
immBegin(GL_LINES, 12);
for (int i = 0; i < 6; i++) {
imm_draw_line(pos, rect.xmin + 22, yofs + (i * 0.2f) * h, rect.xmax + 1, yofs + (i * 0.2f) * h);
immVertex2f(pos, rect.xmin + 22, yofs + (i * 0.2f) * h);
immVertex2f(pos, rect.xmax + 1, yofs + (i * 0.2f) * h);
}
immEnd();
/* 3 vertical separation */
if (scopes->wavefrm_mode != SCOPES_WAVEFRM_LUMA) {
immBegin(GL_LINES, 4);
for (int i = 1; i < 3; i++) {
imm_draw_line(pos, rect.xmin + i * w3, rect.ymin, rect.xmin + i * w3, rect.ymax);
immVertex2f(pos, rect.xmin + i * w3, rect.ymin);
immVertex2f(pos, rect.xmin + i * w3, rect.ymax);
}
immEnd();
}
/* separate min max zone on the right */
imm_draw_line(pos, rect.xmin + w, rect.ymin, rect.xmin + w, rect.ymax);
immBegin(GL_LINES, 2);
immVertex2f(pos, rect.xmin + w, rect.ymin);
immVertex2f(pos, rect.xmin + w, rect.ymax);
immEnd();
/* 16-235-240 level in case of ITU-R BT601/709 */
immUniformColor4f(1.0f, 0.4f, 0.0f, 0.2f);
if (ELEM(scopes->wavefrm_mode, SCOPES_WAVEFRM_YCC_601, SCOPES_WAVEFRM_YCC_709)) {
imm_draw_line(pos, rect.xmin + 22, yofs + h * 16.0f / 255.0f, rect.xmax + 1, yofs + h * 16.0f / 255.0f);
imm_draw_line(pos, rect.xmin + 22, yofs + h * 235.0f / 255.0f, rect.xmin + w3, yofs + h * 235.0f / 255.0f);
imm_draw_line(pos, rect.xmin + 3 * w3, yofs + h * 235.0f / 255.0f, rect.xmax + 1, yofs + h * 235.0f / 255.0f);
imm_draw_line(pos, rect.xmin + w3, yofs + h * 240.0f / 255.0f, rect.xmax + 1, yofs + h * 240.0f / 255.0f);
immBegin(GL_LINES, 8);
immVertex2f(pos, rect.xmin + 22, yofs + h * 16.0f / 255.0f);
immVertex2f(pos, rect.xmax + 1, yofs + h * 16.0f / 255.0f);
immVertex2f(pos, rect.xmin + 22, yofs + h * 235.0f / 255.0f);
immVertex2f(pos, rect.xmin + w3, yofs + h * 235.0f / 255.0f);
immVertex2f(pos, rect.xmin + 3 * w3, yofs + h * 235.0f / 255.0f);
immVertex2f(pos, rect.xmax + 1, yofs + h * 235.0f / 255.0f);
immVertex2f(pos, rect.xmin + w3, yofs + h * 240.0f / 255.0f);
immVertex2f(pos, rect.xmax + 1, yofs + h * 240.0f / 255.0f);
immEnd();
}
/* 7.5 IRE black point level for NTSC */
if (scopes->wavefrm_mode == SCOPES_WAVEFRM_LUMA)
imm_draw_line(pos, rect.xmin, yofs + h * 0.075f, rect.xmax + 1, yofs + h * 0.075f);
if (scopes->wavefrm_mode == SCOPES_WAVEFRM_LUMA) {
immBegin(GL_LINES, 2);
immVertex2f(pos, rect.xmin, yofs + h * 0.075f);
immVertex2f(pos, rect.xmax + 1, yofs + h * 0.075f);
immEnd();
}
if (scopes->ok && scopes->waveform_1 != NULL) {
gpuMatrixBegin3D_legacy();
@@ -831,7 +869,11 @@ void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol),
max = yofs + scopes->minmax[0][1] * h;
CLAMP(min, rect.ymin, rect.ymax);
CLAMP(max, rect.ymin, rect.ymax);
imm_draw_line(pos, rect.xmax - 3, min, rect.xmax - 3, max);
immBegin(GL_LINES, 2);
immVertex2f(pos, rect.xmax - 3, min);
immVertex2f(pos, rect.xmax - 3, max);
immEnd();
}
/* RGB (3 channel) */
else if (scopes->wavefrm_mode == SCOPES_WAVEFRM_RGB) {
@@ -881,7 +923,11 @@ void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol),
max = yofs + scopes->minmax[c][1] * h;
CLAMP(min, rect.ymin, rect.ymax);
CLAMP(max, rect.ymin, rect.ymax);
imm_draw_line(pos, rect.xmin + w + 2 + c * 2, min, rect.xmin + w + 2 + c * 2, max);
immBegin(GL_LINES, 2);
immVertex2f(pos, rect.xmin + w + 2 + c * 2, min);
immVertex2f(pos, rect.xmin + w + 2 + c * 2, max);
immEnd();
}
}
gpuMatrixEnd();
@@ -1005,8 +1051,16 @@ void ui_draw_but_VECTORSCOPE(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wco
immUniformColor4f(1.0f, 1.0f, 1.0f, 0.08f);
/* draw grid elements */
/* cross */
imm_draw_line(pos, centerx - (diam * 0.5f) - 5, centery, centerx + (diam * 0.5f) + 5, centery);
imm_draw_line(pos, centerx, centery - (diam * 0.5f) - 5, centerx, centery + (diam * 0.5f) + 5);
immBegin(GL_LINES, 4);
immVertex2f(pos, centerx - (diam * 0.5f) - 5, centery);
immVertex2f(pos, centerx + (diam * 0.5f) + 5, centery);
immVertex2f(pos, centerx, centery - (diam * 0.5f) - 5);
immVertex2f(pos, centerx, centery + (diam * 0.5f) + 5);
immEnd();
/* circles */
for (int j = 0; j < 5; j++) {
const int increment = 15;
@@ -1020,8 +1074,12 @@ void ui_draw_but_VECTORSCOPE(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wco
}
/* skin tone line */
immUniformColor4f(1.0f, 0.4f, 0.0f, 0.2f);
imm_draw_line(pos, polar_to_x(centerx, diam, 0.5f, skin_rad), polar_to_y(centery, diam, 0.5f, skin_rad),
polar_to_x(centerx, diam, 0.1f, skin_rad), polar_to_y(centery, diam, 0.1f, skin_rad));
immBegin(GL_LINES, 2);
immVertex2f(pos, polar_to_x(centerx, diam, 0.5f, skin_rad), polar_to_y(centery, diam, 0.5f, skin_rad));
immVertex2f(pos, polar_to_x(centerx, diam, 0.1f, skin_rad), polar_to_y(centery, diam, 0.1f, skin_rad));
immEnd();
/* saturation points */
for (int i = 0; i < 6; i++)
vectorscope_draw_target(pos, centerx, centery, diam, colors[i]);
@@ -1262,9 +1320,19 @@ void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti
/* layer: box outline */
glEnable(GL_BLEND);
immUniformColor4f(0.0f, 0.0f, 0.0f, 0.5f);
imm_draw_line(position, x1, y1, x1 + sizex, y1);
immBegin(GL_LINES, 2);
immVertex2f(position, x1, y1);
immVertex2f(position, x1 + sizex, y1);
immEnd();
immUniformColor4f(1.0f, 1.0f, 1.0f, 0.25f);
imm_draw_line(position, x1, y1 - 1, x1 + sizex, y1 - 1);
immBegin(GL_LINES, 2);
immVertex2f(position, x1, y1 - 1);
immVertex2f(position, x1 + sizex, y1 - 1);
immEnd();
glDisable(GL_BLEND);
/* layer: draw handles */

View File

@@ -453,9 +453,16 @@ static void ui_draw_anti_x(unsigned int pos, float x1, float y1, float x2, float
glEnable(GL_BLEND);
glLineWidth(2.0);
imm_draw_line(pos, x1, y1, x2, y2);
imm_draw_line(pos, x1, y2, x2, y1);
immBegin(GL_LINES, 4);
immVertex2f(pos, x1, y1);
immVertex2f(pos, x2, y2);
immVertex2f(pos, x1, y2);
immVertex2f(pos, x2, y1);
immEnd();
glDisable(GL_LINE_SMOOTH);
glDisable(GL_BLEND);
@@ -487,12 +494,29 @@ static void ui_draw_panel_scalewidget(unsigned int pos, const rcti *rect)
glEnable(GL_BLEND);
immUniformColor4ub(255, 255, 255, 50);
imm_draw_line(pos, xmin, ymin, xmax, ymax);
imm_draw_line(pos, xmin + dx, ymin, xmax, ymax - dy);
immBegin(GL_LINES, 4);
immVertex2f(pos, xmin, ymin);
immVertex2f(pos, xmax, ymax);
immVertex2f(pos, xmin + dx, ymin);
immVertex2f(pos, xmax, ymax - dy);
immEnd();
immUniformColor4ub(0, 0, 0, 50);
imm_draw_line(pos, xmin, ymin + 1, xmax, ymax + 1);
imm_draw_line(pos, xmin + dx, ymin + 1, xmax, ymax - dy + 1);
immBegin(GL_LINES, 4);
immVertex2f(pos, xmin, ymin + 1);
immVertex2f(pos, xmax, ymax + 1);
immVertex2f(pos, xmin + dx, ymin + 1);
immVertex2f(pos, xmax, ymax - dy + 1);
immEnd();
glDisable(GL_BLEND);
}
static void ui_draw_panel_dragwidget(unsigned int pos, const rctf *rect)
@@ -600,8 +624,15 @@ void ui_draw_aligned_panel(uiStyle *style, uiBlock *block, const rcti *rect, con
immUniformThemeColor(TH_PANEL_HEADER);
immRectf(pos, minx, headrect.ymin + 1, maxx, y);
imm_draw_line(pos, minx, y, maxx, y);
imm_draw_line(pos, minx, y, maxx, y);
immBegin(GL_LINES, 4);
immVertex2f(pos, minx, y);
immVertex2f(pos, maxx, y);
immVertex2f(pos, minx, y);
immVertex2f(pos, maxx, y);
immEnd();
}
else if (!(panel->runtime_flag & PNL_FIRST)) {
/* draw embossed separator */
@@ -612,9 +643,18 @@ void ui_draw_aligned_panel(uiStyle *style, uiBlock *block, const rcti *rect, con
}
immUniformColor4f(0.0f, 0.0f, 0.0f, 0.5f);
imm_draw_line(pos, minx, y, maxx, y);
immBegin(GL_LINES, 2);
immVertex2f(pos, minx, y);
immVertex2f(pos, maxx, y);
immEnd();
immUniformColor4f(1.0f, 1.0f, 1.0f, 0.25f);
imm_draw_line(pos, minx, y - 1, maxx, y - 1);
immBegin(GL_LINES, 2);
immVertex2f(pos, minx, y - 1);
immVertex2f(pos, maxx, y - 1);
immEnd();
}
glDisable(GL_BLEND);

View File

@@ -2702,7 +2702,12 @@ static void ui_draw_separator(const rcti *rect, uiWidgetColors *wcol)
glEnable(GL_BLEND);
immUniformColor4ubv(col);
glLineWidth(1.0f);
imm_draw_line(pos, rect->xmin, y, rect->xmax, y);
immBegin(GL_LINES, 2);
immVertex2f(pos, rect->xmin, y);
immVertex2f(pos, rect->xmax, y);
immEnd();
glDisable(GL_BLEND);
immUnbindProgram();

View File

@@ -214,14 +214,6 @@ void imm_draw_line_box(unsigned pos, float x1, float y1, float x2, float y2)
immEnd();
}
void imm_draw_line(unsigned pos, float x1, float y1, float x2, float y2)
{
immBegin(PRIM_LINES, 2);
immVertex2f(pos, x1, y1);
immVertex2f(pos, x2, y2);
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 */

View File

@@ -151,9 +151,10 @@ static void paint_draw_smooth_cursor(bContext *C, int x, int y, void *customdata
immUniformColor4ubv(paint->paint_cursor_col);
immBegin(GL_LINES, 2);
imm_draw_line(pos, x, y, stroke->last_mouse_position[0],
stroke->last_mouse_position[1]);
immVertex2f(pos, x, y);
immVertex2f(pos, stroke->last_mouse_position[0], stroke->last_mouse_position[1]);
immEnd();
immUnbindProgram();
glDisable(GL_BLEND);
@@ -176,25 +177,36 @@ static void paint_draw_line_cursor(bContext *C, int x, int y, void *customdata)
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
immUniformColor4ub(0, 0, 0, paint->paint_cursor_col[3]);
immBegin(GL_LINES, 2);
if (stroke->constrain_line) {
imm_draw_line(pos, stroke->last_mouse_position[0], stroke->last_mouse_position[1],
stroke->constrained_pos[0], stroke->constrained_pos[1]);
immVertex2f(pos, stroke->last_mouse_position[0], stroke->last_mouse_position[1]);
immVertex2f(pos, stroke->constrained_pos[0], stroke->constrained_pos[1]);
}
else {
imm_draw_line(pos, stroke->last_mouse_position[0], stroke->last_mouse_position[1],
x, y);
immVertex2f(pos, stroke->last_mouse_position[0], stroke->last_mouse_position[1]);
immVertex2f(pos, x, y);
}
immEnd();
glLineWidth(1.0f);
immUniformColor4ub(255, 255, 255, paint->paint_cursor_col[3]);
immBegin(GL_LINES, 2);
if (stroke->constrain_line) {
imm_draw_line(pos, stroke->last_mouse_position[0], stroke->last_mouse_position[1],
stroke->constrained_pos[0], stroke->constrained_pos[1]);
immVertex2f(pos, stroke->last_mouse_position[0], stroke->last_mouse_position[1]);
immVertex2f(pos, stroke->constrained_pos[0], stroke->constrained_pos[1]);
}
else {
imm_draw_line(pos, stroke->last_mouse_position[0], stroke->last_mouse_position[1],
x, y);
immVertex2f(pos, stroke->last_mouse_position[0], stroke->last_mouse_position[1]);
immVertex2f(pos, x, y);
}
immEnd();
immUnbindProgram();
setlinestyle(0);

View File

@@ -1651,7 +1651,12 @@ static void outliner_draw_struct_marks(ARegion *ar, SpaceOops *soops, ListBase *
unsigned pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
immThemeColorShadeAlpha(TH_BACK, -15, -200);
imm_draw_line(pos, 0, (float)*starty + UI_UNIT_Y, ar->v2d.cur.xmax, (float)*starty + UI_UNIT_Y);
immBegin(GL_LINES, 2);
immVertex2f(pos, 0, (float)*starty + UI_UNIT_Y);
immVertex2f(pos, ar->v2d.cur.xmax, (float)*starty + UI_UNIT_Y);
immEnd();
immUnbindProgram();
}
}