diff options
Diffstat (limited to 'source/blender/editors/interface')
-rw-r--r-- | source/blender/editors/interface/CMakeLists.txt | 2 | ||||
-rw-r--r-- | source/blender/editors/interface/interface.c | 28 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_draw.c | 1070 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_icons.c | 235 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_ops.c | 2 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_panel.c | 109 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_regions.c | 8 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_widgets.c | 455 | ||||
-rw-r--r-- | source/blender/editors/interface/resources.c | 118 | ||||
-rw-r--r-- | source/blender/editors/interface/view2d.c | 192 |
10 files changed, 1234 insertions, 985 deletions
diff --git a/source/blender/editors/interface/CMakeLists.txt b/source/blender/editors/interface/CMakeLists.txt index 8ba86673f87..89e7603109a 100644 --- a/source/blender/editors/interface/CMakeLists.txt +++ b/source/blender/editors/interface/CMakeLists.txt @@ -70,4 +70,6 @@ if(WITH_PYTHON) add_definitions(-DWITH_PYTHON) endif() +add_definitions(-DGLEW_STATIC) + blender_add_lib(bf_editor_interface "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index e2f105b5761..560a5a716c3 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -57,7 +57,8 @@ #include "BKE_screen.h" #include "BKE_idprop.h" -#include "BIF_gl.h" +#include "GPU_colors.h" +#include "GPU_compatibility.h" #include "BLF_api.h" #include "BLF_translation.h" @@ -497,11 +498,11 @@ static void ui_draw_linkline(uiLinkLine *line, int highlightActiveLines) rect.ymax = BLI_rctf_cent_y(&line->to->rect); if (line->flag & UI_SELECT) - glColor3ub(100, 100, 100); + gpuCurrentGray3f(0.392f); else if (highlightActiveLines && ((line->from->flag & UI_ACTIVE) || (line->to->flag & UI_ACTIVE))) UI_ThemeColor(TH_TEXT_HI); else - glColor3ub(0, 0, 0); + gpuCurrentColor3x(CPACK_BLACK); ui_draw_link_bezier(&rect); } @@ -1034,9 +1035,6 @@ void uiDrawBlock(const bContext *C, uiBlock *block) if (multisample_enabled) glDisable(GL_MULTISAMPLE_ARB); - /* we set this only once */ - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - /* scale fonts */ ui_fontscale(&style.paneltitle.points, block->aspect); ui_fontscale(&style.grouplabel.points, block->aspect); @@ -1047,11 +1045,11 @@ void uiDrawBlock(const bContext *C, uiBlock *block) ui_but_to_pixelrect(&rect, ar, block, NULL); /* pixel space for AA widgets */ - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadIdentity(); + gpuMatrixMode(GL_PROJECTION); + gpuPushMatrix(); + gpuMatrixMode(GL_MODELVIEW); + gpuPushMatrix(); + gpuLoadIdentity(); wmOrtho2(-0.01f, ar->winx - 0.01f, -0.01f, ar->winy - 0.01f); @@ -1074,10 +1072,10 @@ void uiDrawBlock(const bContext *C, uiBlock *block) } /* restore matrix */ - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); + gpuMatrixMode(GL_PROJECTION); + gpuPopMatrix(); + gpuMatrixMode(GL_MODELVIEW); + gpuPopMatrix(); if (multisample_enabled) glEnable(GL_MULTISAMPLE_ARB); diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c index 4d96ad810d4..80003222faa 100644 --- a/source/blender/editors/interface/interface_draw.c +++ b/source/blender/editors/interface/interface_draw.c @@ -50,7 +50,9 @@ #include "IMB_imbuf_types.h" #include "IMB_colormanagement.h" -#include "BIF_gl.h" +#include "GPU_colors.h" +#include "GPU_primitives.h" + #include "BIF_glutil.h" #include "BLF_api.h" @@ -87,49 +89,53 @@ void uiDrawBox(int mode, float minx, float miny, float maxx, float maxy, float r mul_v2_fl(vec[a], rad); } - glBegin(mode); + gpuImmediateFormat_V2(); // DOODLE: ui box, a rounded rectangle + gpuBegin(mode); + + /* start with corner right-bottom */ if (roundboxtype & UI_CNR_BOTTOM_RIGHT) { - glVertex2f(maxx - rad, miny); + gpuVertex2f(maxx - rad, miny); for (a = 0; a < 7; a++) { - glVertex2f(maxx - rad + vec[a][0], miny + vec[a][1]); + gpuVertex2f(maxx - rad + vec[a][0], miny + vec[a][1]); } - glVertex2f(maxx, miny + rad); + gpuVertex2f(maxx, miny + rad); } - else glVertex2f(maxx, miny); - + else gpuVertex2f(maxx, miny); + /* corner right-top */ if (roundboxtype & UI_CNR_TOP_RIGHT) { - glVertex2f(maxx, maxy - rad); + gpuVertex2f(maxx, maxy - rad); for (a = 0; a < 7; a++) { - glVertex2f(maxx - vec[a][1], maxy - rad + vec[a][0]); + gpuVertex2f(maxx - vec[a][1], maxy - rad + vec[a][0]); } - glVertex2f(maxx - rad, maxy); + gpuVertex2f(maxx - rad, maxy); } - else glVertex2f(maxx, maxy); - + else gpuVertex2f(maxx, maxy); + /* corner left-top */ if (roundboxtype & UI_CNR_TOP_LEFT) { - glVertex2f(minx + rad, maxy); + gpuVertex2f(minx + rad, maxy); for (a = 0; a < 7; a++) { - glVertex2f(minx + rad - vec[a][0], maxy - vec[a][1]); + gpuVertex2f(minx + rad - vec[a][0], maxy - vec[a][1]); } - glVertex2f(minx, maxy - rad); + gpuVertex2f(minx, maxy - rad); } - else glVertex2f(minx, maxy); - + else gpuVertex2f(minx, maxy); + /* corner left-bottom */ if (roundboxtype & UI_CNR_BOTTOM_LEFT) { - glVertex2f(minx, miny + rad); + gpuVertex2f(minx, miny + rad); for (a = 0; a < 7; a++) { - glVertex2f(minx + vec[a][1], miny + rad - vec[a][0]); + gpuVertex2f(minx + vec[a][1], miny + rad - vec[a][0]); } - glVertex2f(minx + rad, miny); + gpuVertex2f(minx + rad, miny); } - else glVertex2f(minx, miny); - - glEnd(); + else gpuVertex2f(minx, miny); + + gpuEnd(); + gpuImmediateUnformat(); } static void round_box_shade_col(const float col1[3], float const col2[3], const float fac) @@ -139,7 +145,7 @@ static void round_box_shade_col(const float col1[3], float const col2[3], const col[0] = (fac * col1[0] + (1.0f - fac) * col2[0]); col[1] = (fac * col1[1] + (1.0f - fac) * col2[1]); col[2] = (fac * col1[2] + (1.0f - fac) * col2[2]); - glColor3fv(col); + gpuColor3fv(col); } /* linear horizontal shade within button or in outline */ @@ -157,8 +163,8 @@ void uiDrawBoxShade(int mode, float minx, float miny, float maxx, float maxy, fl for (a = 0; a < 7; a++) { mul_v2_fl(vec[a], rad); } - /* get current color, needs to be outside of glBegin/End */ - glGetFloatv(GL_CURRENT_COLOR, color); + /* get current color, needs to be outside of gpuBegin/End */ + gpuGetCurrentColor4fv(color); /* 'shade' defines strength of shading */ coltop[0] = min_ff(1.0f, color[0] + shadetop); @@ -169,84 +175,84 @@ void uiDrawBoxShade(int mode, float minx, float miny, float maxx, float maxy, fl coldown[2] = max_ff(0.0f, color[2] + shadedown); glShadeModel(GL_SMOOTH); - glBegin(mode); + gpuBegin(mode); /* start with corner right-bottom */ if (roundboxtype & UI_CNR_BOTTOM_RIGHT) { round_box_shade_col(coltop, coldown, 0.0); - glVertex2f(maxx - rad, miny); + gpuVertex2f(maxx - rad, miny); for (a = 0; a < 7; a++) { round_box_shade_col(coltop, coldown, vec[a][1] * idiv); - glVertex2f(maxx - rad + vec[a][0], miny + vec[a][1]); + gpuVertex2f(maxx - rad + vec[a][0], miny + vec[a][1]); } round_box_shade_col(coltop, coldown, rad * idiv); - glVertex2f(maxx, miny + rad); + gpuVertex2f(maxx, miny + rad); } else { round_box_shade_col(coltop, coldown, 0.0); - glVertex2f(maxx, miny); + gpuVertex2f(maxx, miny); } /* corner right-top */ if (roundboxtype & UI_CNR_TOP_RIGHT) { round_box_shade_col(coltop, coldown, (div - rad) * idiv); - glVertex2f(maxx, maxy - rad); + gpuVertex2f(maxx, maxy - rad); for (a = 0; a < 7; a++) { round_box_shade_col(coltop, coldown, (div - rad + vec[a][1]) * idiv); - glVertex2f(maxx - vec[a][1], maxy - rad + vec[a][0]); + gpuVertex2f(maxx - vec[a][1], maxy - rad + vec[a][0]); } round_box_shade_col(coltop, coldown, 1.0); - glVertex2f(maxx - rad, maxy); + gpuVertex2f(maxx - rad, maxy); } else { round_box_shade_col(coltop, coldown, 1.0); - glVertex2f(maxx, maxy); + gpuVertex2f(maxx, maxy); } /* corner left-top */ if (roundboxtype & UI_CNR_TOP_LEFT) { round_box_shade_col(coltop, coldown, 1.0); - glVertex2f(minx + rad, maxy); + gpuVertex2f(minx + rad, maxy); for (a = 0; a < 7; a++) { round_box_shade_col(coltop, coldown, (div - vec[a][1]) * idiv); - glVertex2f(minx + rad - vec[a][0], maxy - vec[a][1]); + gpuVertex2f(minx + rad - vec[a][0], maxy - vec[a][1]); } round_box_shade_col(coltop, coldown, (div - rad) * idiv); - glVertex2f(minx, maxy - rad); + gpuVertex2f(minx, maxy - rad); } else { round_box_shade_col(coltop, coldown, 1.0); - glVertex2f(minx, maxy); + gpuVertex2f(minx, maxy); } /* corner left-bottom */ if (roundboxtype & UI_CNR_BOTTOM_LEFT) { round_box_shade_col(coltop, coldown, rad * idiv); - glVertex2f(minx, miny + rad); + gpuVertex2f(minx, miny + rad); for (a = 0; a < 7; a++) { round_box_shade_col(coltop, coldown, (rad - vec[a][1]) * idiv); - glVertex2f(minx + vec[a][1], miny + rad - vec[a][0]); + gpuVertex2f(minx + vec[a][1], miny + rad - vec[a][0]); } round_box_shade_col(coltop, coldown, 0.0); - glVertex2f(minx + rad, miny); + gpuVertex2f(minx + rad, miny); } else { round_box_shade_col(coltop, coldown, 0.0); - glVertex2f(minx, miny); + gpuVertex2f(minx, miny); } - glEnd(); + gpuEnd(); glShadeModel(GL_FLAT); } @@ -266,8 +272,8 @@ void uiDrawBoxVerticalShade(int mode, float minx, float miny, float maxx, float for (a = 0; a < 7; a++) { mul_v2_fl(vec[a], rad); } - /* get current color, needs to be outside of glBegin/End */ - glGetFloatv(GL_CURRENT_COLOR, color); + /* get current color, needs to be outside of gpuBegin/End */ + gpuGetCurrentColor4fv(color); /* 'shade' defines strength of shading */ colLeft[0] = min_ff(1.0f, color[0] + shadeLeft); @@ -278,102 +284,98 @@ void uiDrawBoxVerticalShade(int mode, float minx, float miny, float maxx, float colRight[2] = max_ff(0.0f, color[2] + shadeRight); glShadeModel(GL_SMOOTH); - glBegin(mode); + gpuBegin(mode); /* start with corner right-bottom */ if (roundboxtype & UI_CNR_BOTTOM_RIGHT) { round_box_shade_col(colLeft, colRight, 0.0); - glVertex2f(maxx - rad, miny); + gpuVertex2f(maxx - rad, miny); for (a = 0; a < 7; a++) { round_box_shade_col(colLeft, colRight, vec[a][0] * idiv); - glVertex2f(maxx - rad + vec[a][0], miny + vec[a][1]); + gpuVertex2f(maxx - rad + vec[a][0], miny + vec[a][1]); } round_box_shade_col(colLeft, colRight, rad * idiv); - glVertex2f(maxx, miny + rad); + gpuVertex2f(maxx, miny + rad); } else { round_box_shade_col(colLeft, colRight, 0.0); - glVertex2f(maxx, miny); + gpuVertex2f(maxx, miny); } /* corner right-top */ if (roundboxtype & UI_CNR_TOP_RIGHT) { round_box_shade_col(colLeft, colRight, 0.0); - glVertex2f(maxx, maxy - rad); + gpuVertex2f(maxx, maxy - rad); for (a = 0; a < 7; a++) { round_box_shade_col(colLeft, colRight, (div - rad - vec[a][0]) * idiv); - glVertex2f(maxx - vec[a][1], maxy - rad + vec[a][0]); + gpuVertex2f(maxx - vec[a][1], maxy - rad + vec[a][0]); } round_box_shade_col(colLeft, colRight, (div - rad) * idiv); - glVertex2f(maxx - rad, maxy); + gpuVertex2f(maxx - rad, maxy); } else { round_box_shade_col(colLeft, colRight, 0.0); - glVertex2f(maxx, maxy); + gpuVertex2f(maxx, maxy); } /* corner left-top */ if (roundboxtype & UI_CNR_TOP_LEFT) { round_box_shade_col(colLeft, colRight, (div - rad) * idiv); - glVertex2f(minx + rad, maxy); + gpuVertex2f(minx + rad, maxy); for (a = 0; a < 7; a++) { round_box_shade_col(colLeft, colRight, (div - rad + vec[a][0]) * idiv); - glVertex2f(minx + rad - vec[a][0], maxy - vec[a][1]); + gpuVertex2f(minx + rad - vec[a][0], maxy - vec[a][1]); } round_box_shade_col(colLeft, colRight, 1.0); - glVertex2f(minx, maxy - rad); + gpuVertex2f(minx, maxy - rad); } else { round_box_shade_col(colLeft, colRight, 1.0); - glVertex2f(minx, maxy); + gpuVertex2f(minx, maxy); } /* corner left-bottom */ if (roundboxtype & UI_CNR_BOTTOM_LEFT) { round_box_shade_col(colLeft, colRight, 1.0); - glVertex2f(minx, miny + rad); + gpuVertex2f(minx, miny + rad); for (a = 0; a < 7; a++) { round_box_shade_col(colLeft, colRight, (vec[a][0]) * idiv); - glVertex2f(minx + vec[a][1], miny + rad - vec[a][0]); + gpuVertex2f(minx + vec[a][1], miny + rad - vec[a][0]); } round_box_shade_col(colLeft, colRight, 1.0); - glVertex2f(minx + rad, miny); + gpuVertex2f(minx + rad, miny); } else { round_box_shade_col(colLeft, colRight, 1.0); - glVertex2f(minx, miny); + gpuVertex2f(minx, miny); } - glEnd(); + gpuEnd(); glShadeModel(GL_FLAT); } /* plain antialiased unfilled rectangle */ void uiRoundRect(float minx, float miny, float maxx, float maxy, float rad) { - float color[4]; - if (roundboxtype & UI_RB_ALPHA) { - glGetFloatv(GL_CURRENT_COLOR, color); - color[3] = 0.5; - glColor4fv(color); + gpuCurrentAlpha(0.5f); glEnable(GL_BLEND); } - + /* set antialias line */ glEnable(GL_LINE_SMOOTH); glEnable(GL_BLEND); uiDrawBox(GL_LINE_LOOP, minx, miny, maxx, maxy, rad); - + glDisable(GL_BLEND); glDisable(GL_LINE_SMOOTH); } @@ -381,16 +383,12 @@ void uiRoundRect(float minx, float miny, float maxx, float maxy, float rad) /* (old, used in outliner) plain antialiased filled box */ void uiRoundBox(float minx, float miny, float maxx, float maxy, float rad) { - float color[4]; - if (roundboxtype & UI_RB_ALPHA) { - glGetFloatv(GL_CURRENT_COLOR, color); - color[3] = 0.5; - glColor4fv(color); + gpuCurrentAlpha(0.5f); glEnable(GL_BLEND); } - - ui_draw_anti_roundbox(GL_POLYGON, minx, miny, maxx, maxy, rad); + + ui_draw_anti_roundbox(GL_TRIANGLE_FAN, minx, miny, maxx, maxy, rad); } @@ -400,23 +398,25 @@ void uiRoundBox(float minx, float miny, float maxx, float maxy, float rad) /* text_draw.c uses this */ void uiEmboss(float x1, float y1, float x2, float y2, int sel) { - + gpuImmediateFormat_C4_V2(); // DOODLE: fixed number of colored lines + gpuBegin(GL_LINES); + /* below */ - if (sel) glColor3ub(200, 200, 200); - else glColor3ub(50, 50, 50); - fdrawline(x1, y1, x2, y1); + gpuCurrentGray3f(sel ? 0.784f : 0.196f); + gpuAppendLinef(x1, y1, x2, y1); /* right */ - fdrawline(x2, y1, x2, y2); + gpuAppendLinef(x2, y1, x2, y2); /* top */ - if (sel) glColor3ub(50, 50, 50); - else glColor3ub(200, 200, 200); - fdrawline(x1, y2, x2, y2); + gpuCurrentGray3f(!sel ? 0.784f : 0.196f); + gpuAppendLinef(x1, y2, x2, y2); /* left */ - fdrawline(x1, y1, x1, y2); - + gpuAppendLinef(x1, y1, x1, y2); + + gpuEnd(); + gpuImmediateUnformat(); } /* ************** SPECIAL BUTTON DRAWING FUNCTIONS ************* */ @@ -435,18 +435,18 @@ void ui_draw_but_IMAGE(ARegion *UNUSED(ar), uiBut *but, uiWidgetColors *UNUSED(w /* scissor doesn't seem to be doing the right thing...? */ #if 0 - //glColor4f(1.0, 0.f, 0.f, 1.f); - //fdrawbox(rect->xmin, rect->ymin, rect->xmax, rect->ymax) + //gpuCurrentColor3x(CPACK_RED); + //gpuSingleWireRectf(rect->xmin, rect->ymin, rect->xmax, rect->ymax) w = BLI_rcti_size_x(rect); h = BLI_rcti_size_y(rect); /* prevent drawing outside widget area */ - glGetIntegerv(GL_SCISSOR_BOX, scissor); - glScissor(ar->winrct.xmin + rect->xmin, ar->winrct.ymin + rect->ymin, w, h); + gpuGetSizeBox(GL_SCISSOR_BOX, scissor); + gpuScissor(ar->winrct.xmin + rect->xmin, ar->winrct.ymin + rect->ymin, w, h); #endif glEnable(GL_BLEND); - glColor4f(0.0, 0.0, 0.0, 0.0); + gpuCurrentColor4x(CPACK_BLACK, 0.000f); glaDrawPixelsSafe((float)rect->xmin, (float)rect->ymin, ibuf->x, ibuf->y, ibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect); //glaDrawPixelsTex((float)rect->xmin, (float)rect->ymin, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, ibuf->rect); @@ -455,7 +455,7 @@ void ui_draw_but_IMAGE(ARegion *UNUSED(ar), uiBut *but, uiWidgetColors *UNUSED(w #if 0 // restore scissortest - glScissor(scissor[0], scissor[1], scissor[2], scissor[3]); + gpuScissor(scissor[0], scissor[1], scissor[2], scissor[3]); #endif #endif @@ -531,10 +531,10 @@ static void ui_draw_but_CHARTAB(uiBut *but) /* Start drawing the button itself */ glShadeModel(GL_SMOOTH); - glColor3ub(200, 200, 200); - glRectf((rect->xmin), (rect->ymin), (rect->xmax), (rect->ymax)); + gpuCurrentGray3f(0.784f); + gpuSingleFilledRectf((rect->xmin), (rect->ymin), (rect->xmax), (rect->ymax)); - glColor3ub(0, 0, 0); + gpuCurrentColor3x(CPACK_BLACK); for (y = 0; y < 6; y++) { /* Do not draw more than the category allows */ if (cs > charmax) break; @@ -545,12 +545,12 @@ static void ui_draw_but_CHARTAB(uiBut *but) if (cs > charmax) break; /* Draw one grid cell */ - glBegin(GL_LINE_LOOP); - glVertex2f(sx, sy); - glVertex2f(ex, sy); - glVertex2f(ex, ey); - glVertex2f(sx, ey); - glEnd(); + gpuBegin(GL_LINE_LOOP); + gpuVertex2f(sx, sy); + gpuVertex2f(ex, sy); + gpuVertex2f(ex, ey); + gpuVertex2f(sx, ey); + gpuEnd(); /* Draw character inside the cell */ memset(wstr, 0, sizeof(wchar_t) * 2); @@ -635,25 +635,30 @@ static void ui_draw_but_CHARTAB(uiBut *but) static void draw_scope_end(const rctf *rect, GLint *scissor) { float scaler_x1, scaler_x2; - + /* restore scissortest */ - glScissor(scissor[0], scissor[1], scissor[2], scissor[3]); - - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - + gpuScissor(scissor[0], scissor[1], scissor[2], scissor[3]); + /* scale widget */ scaler_x1 = rect->xmin + BLI_rctf_size_x(rect) / 2 - SCOPE_RESIZE_PAD; scaler_x2 = rect->xmin + BLI_rctf_size_x(rect) / 2 + SCOPE_RESIZE_PAD; - - glColor4f(0.f, 0.f, 0.f, 0.25f); - fdrawline(scaler_x1, rect->ymin - 4, scaler_x2, rect->ymin - 4); - fdrawline(scaler_x1, rect->ymin - 7, scaler_x2, rect->ymin - 7); - glColor4f(1.f, 1.f, 1.f, 0.25f); - fdrawline(scaler_x1, rect->ymin - 5, scaler_x2, rect->ymin - 5); - fdrawline(scaler_x1, rect->ymin - 8, scaler_x2, rect->ymin - 8); - + + gpuImmediateFormat_C4_V2(); // DOODLE: fixed number of colored lines + gpuBegin(GL_LINES); + + gpuCurrentColor4x(CPACK_BLACK, 0.250f); + gpuAppendLinef(scaler_x1, rect->ymin - 4, scaler_x2, rect->ymin - 4); + gpuAppendLinef(scaler_x1, rect->ymin - 7, scaler_x2, rect->ymin - 7); + + gpuCurrentColor4x(CPACK_WHITE, 0.250f); + gpuAppendLinef(scaler_x1, rect->ymin - 5, scaler_x2, rect->ymin - 5); + gpuAppendLinef(scaler_x1, rect->ymin - 8, scaler_x2, rect->ymin - 8); + + gpuEnd(); + gpuImmediateUnformat(); + /* outline */ - glColor4f(0.f, 0.f, 0.f, 0.5f); + gpuCurrentColor4x(CPACK_BLACK, 0.500f); uiSetRoundBox(UI_CNR_ALL); uiDrawBox(GL_LINE_LOOP, rect->xmin - 1, rect->ymin, rect->xmax + 1, rect->ymax + 1, 3.0f); } @@ -662,54 +667,57 @@ static void histogram_draw_one(float r, float g, float b, float alpha, float x, float y, float w, float h, float *data, int res, const short is_line) { int i; - - if (is_line) { + if (is_line) { glLineWidth(1.5); - glBlendFunc(GL_SRC_ALPHA, GL_ONE); - glColor4f(r, g, b, alpha); + glBlendFunc(GL_SRC_ALPHA, GL_ONE); /* non-standard blend function */ + gpuCurrentColor4f(r, g, b, alpha); /* curve outline */ - glBlendFunc(GL_SRC_ALPHA, GL_ONE); glEnable(GL_LINE_SMOOTH); - glBegin(GL_LINE_STRIP); + gpuBegin(GL_LINE_STRIP); for (i = 0; i < res; i++) { float x2 = x + i * (w / (float)res); - glVertex2f(x2, y + (data[i] * h)); + gpuVertex2f(x2, y + (data[i] * h)); } - glEnd(); + gpuEnd(); glDisable(GL_LINE_SMOOTH); glLineWidth(1.0); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); /* reset blender default */ } else { /* under the curve */ glBlendFunc(GL_SRC_ALPHA, GL_ONE); - glColor4f(r, g, b, alpha); + gpuCurrentColor4f(r, g, b, alpha); glShadeModel(GL_FLAT); - glBegin(GL_QUAD_STRIP); - glVertex2f(x, y); - glVertex2f(x, y + (data[0] * h)); + + gpuBegin(GL_TRIANGLE_STRIP); // DOODLE: line graph drawn using quads, locking done by function callee + gpuVertex2f(x, y); + gpuVertex2f(x, y + (data[0] * h)); for (i = 1; i < res; i++) { float x2 = x + i * (w / (float)res); - glVertex2f(x2, y + (data[i] * h)); - glVertex2f(x2, y); + gpuVertex2f(x2, y + (data[i] * h)); + gpuVertex2f(x2, y); } - glEnd(); + gpuEnd(); /* curve outline */ - glColor4f(0.f, 0.f, 0.f, 0.25f); + gpuCurrentColor4x(CPACK_BLACK, 0.250f); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); /* reset blender default */ glEnable(GL_LINE_SMOOTH); - glBegin(GL_LINE_STRIP); + + gpuBegin(GL_LINE_STRIP); // DOODLE: line graph drawn using a line strip, locking done by callee for (i = 0; i < res; i++) { float x2 = x + i * (w / (float)res); - glVertex2f(x2, y + (data[i] * h)); + gpuVertex2f(x2, y + (data[i] * h)); } - glEnd(); + gpuEnd(); + glDisable(GL_LINE_SMOOTH); } } @@ -724,7 +732,6 @@ void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol) int i; float w, h; const short is_line = (hist->flag & HISTO_FLAG_LINE) != 0; - //float alpha; GLint scissor[4]; rect.xmin = (float)recti->xmin + 1; @@ -736,33 +743,36 @@ void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol) h = BLI_rctf_size_y(&rect) * hist->ymax; glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - glColor4f(0.f, 0.f, 0.f, 0.3f); + + gpuCurrentColor4x(CPACK_BLACK, 0.300f); uiSetRoundBox(UI_CNR_ALL); - uiDrawBox(GL_POLYGON, rect.xmin - 1, rect.ymin - 1, rect.xmax + 1, rect.ymax + 1, 3.0f); + uiDrawBox(GL_TRIANGLE_FAN, rect.xmin - 1, rect.ymin - 1, rect.xmax + 1, rect.ymax + 1, 3.0f); /* need scissor test, histogram can draw outside of boundary */ - glGetIntegerv(GL_VIEWPORT, scissor); - glScissor(ar->winrct.xmin + (rect.xmin - 1), + gpuGetSizeBox(GL_VIEWPORT, scissor); + gpuScissor(ar->winrct.xmin + (rect.xmin - 1), ar->winrct.ymin + (rect.ymin - 1), (rect.xmax + 1) - (rect.xmin - 1), (rect.ymax + 1) - (rect.ymin - 1)); - glColor4f(1.f, 1.f, 1.f, 0.08f); + gpuCurrentColor4x(CPACK_WHITE, 0.080f); + + gpuImmediateFormat_V2(); /* lock both for grid and histogram */ // DOODLE: 4 monochrome lines and 1 or 3 histograms + /* draw grid lines here */ for (i = 1; i < (HISTOGRAM_TOT_GRID_LINES + 1); i++) { const float fac = (float)i / (float)HISTOGRAM_TOT_GRID_LINES; /* so we can tell the 1.0 color point */ if (i == HISTOGRAM_TOT_GRID_LINES) { - glColor4f(1.0f, 1.0f, 1.0f, 0.5f); + gpuCurrentColor4f(1.0f, 1.0f, 1.0f, 0.5f); } - fdrawline(rect.xmin, rect.ymin + fac * h, rect.xmax, rect.ymin + fac * h); - fdrawline(rect.xmin + fac * w, rect.ymin, rect.xmin + fac * w, rect.ymax); + gpuAppendLinef(rect.xmin, rect.ymin + fac * h, rect.xmax, rect.ymin + fac * h); + gpuAppendLinef(rect.xmin + fac * w, rect.ymin, rect.xmin + fac * w, rect.ymax); } - + gpuEnd(); + if (hist->mode == HISTO_MODE_LUMA) { histogram_draw_one(1.0, 1.0, 1.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_luma, res, is_line); } @@ -777,7 +787,9 @@ void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol) if (hist->mode == HISTO_MODE_RGB || hist->mode == HISTO_MODE_B) histogram_draw_one(0.0, 0.0, 1.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_b, res, is_line); } - + + gpuImmediateUnformat(); + /* outline, scale gripper */ draw_scope_end(&rect, scissor); } @@ -795,9 +807,9 @@ void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), float colorsycc[3][3] = {{1, 0, 1}, {1, 1, 0}, {0, 1, 1}}; float colors_alpha[3][3], colorsycc_alpha[3][3]; /* colors pre multiplied by alpha for speed up */ float min, max; - + if (scopes == NULL) return; - + rect.xmin = (float)recti->xmin + 1; rect.xmax = (float)recti->xmax - 1; rect.ymin = (float)recti->ymin + SCOPE_RESIZE_PAD + 2; @@ -809,94 +821,108 @@ void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), h = BLI_rctf_size_y(&rect) * scopes->wavefrm_yfac; yofs = rect.ymin + (BLI_rctf_size_y(&rect) - h) / 2.0f; w3 = w / 3.0f; - + /* log scale for alpha */ alpha = scopes->wavefrm_alpha * scopes->wavefrm_alpha; - + for (c = 0; c < 3; c++) { for (i = 0; i < 3; i++) { colors_alpha[c][i] = colors[c][i] * alpha; colorsycc_alpha[c][i] = colorsycc[c][i] * alpha; } } - + glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - glColor4f(0.f, 0.f, 0.f, 0.3f); + + gpuCurrentColor4x(CPACK_BLACK, 0.300f); uiSetRoundBox(UI_CNR_ALL); - uiDrawBox(GL_POLYGON, rect.xmin - 1, rect.ymin - 1, rect.xmax + 1, rect.ymax + 1, 3.0f); + uiDrawBox(GL_TRIANGLE_FAN, rect.xmin - 1, rect.ymin - 1, rect.xmax + 1, rect.ymax + 1, 3.0f); /* need scissor test, waveform can draw outside of boundary */ - glGetIntegerv(GL_VIEWPORT, scissor); - glScissor(ar->winrct.xmin + (rect.xmin - 1), + gpuGetSizeBox(GL_VIEWPORT, scissor); + gpuScissor(ar->winrct.xmin + (rect.xmin - 1), ar->winrct.ymin + (rect.ymin - 1), (rect.xmax + 1) - (rect.xmin - 1), (rect.ymax + 1) - (rect.ymin - 1)); - glColor4f(1.f, 1.f, 1.f, 0.08f); + gpuCurrentColor4x(CPACK_WHITE, 0.080f); + /* draw grid lines here */ + gpuImmediateFormat_V2(); // DOODLE: fixed number of monochrome lines, a grid + gpuBegin(GL_LINES); + for (i = 0; i < 6; i++) { + gpuAppendLinef(rect.xmin + 22, yofs + (i / 5.f) * h, rect.xmax + 1, yofs + (i / 5.f) * h); + } + gpuEnd(); + gpuImmediateUnformat(); + + /* draw text on grid */ + BLF_draw_default_lock(); // DOODLE: grid of numbers for (i = 0; i < 6; i++) { char str[4]; BLI_snprintf(str, sizeof(str), "%-3d", i * 20); str[3] = '\0'; - fdrawline(rect.xmin + 22, yofs + (i / 5.f) * h, rect.xmax + 1, yofs + (i / 5.f) * h); BLF_draw_default(rect.xmin + 1, yofs - 5 + (i / 5.f) * h, 0, str, sizeof(str) - 1); - /* in the loop because blf_draw reset it */ - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } + BLF_draw_default_unlock(); + + gpuImmediateFormat_C4_V2(); // DOODLE: variable number of lines, colors passed mainly to reduce number of batches + gpuBegin(GL_LINES); + /* 3 vertical separation */ if (scopes->wavefrm_mode != SCOPES_WAVEFRM_LUMA) { for (i = 1; i < 3; i++) { - fdrawline(rect.xmin + i * w3, rect.ymin, rect.xmin + i * w3, rect.ymax); + gpuAppendLinef(rect.xmin + i * w3, rect.ymin, rect.xmin + i * w3, rect.ymax); } } - + /* separate min max zone on the right */ - fdrawline(rect.xmin + w, rect.ymin, rect.xmin + w, rect.ymax); + gpuAppendLinef(rect.xmin + w, rect.ymin, rect.xmin + w, rect.ymax); /* 16-235-240 level in case of ITU-R BT601/709 */ - glColor4f(1.f, 0.4f, 0.f, 0.2f); + gpuColor4f(1.0f, 0.4f, 0.0f, 0.200f); if (ELEM(scopes->wavefrm_mode, SCOPES_WAVEFRM_YCC_601, SCOPES_WAVEFRM_YCC_709)) { - fdrawline(rect.xmin + 22, yofs + h * 16.0f / 255.0f, rect.xmax + 1, yofs + h * 16.0f / 255.0f); - fdrawline(rect.xmin + 22, yofs + h * 235.0f / 255.0f, rect.xmin + w3, yofs + h * 235.0f / 255.0f); - fdrawline(rect.xmin + 3 * w3, yofs + h * 235.0f / 255.0f, rect.xmax + 1, yofs + h * 235.0f / 255.0f); - fdrawline(rect.xmin + w3, yofs + h * 240.0f / 255.0f, rect.xmax + 1, yofs + h * 240.0f / 255.0f); + gpuAppendLinef(rect.xmin + 22, yofs + h * 16.0f / 255.0f, rect.xmax + 1, yofs + h * 16.0f / 255.0f); + gpuAppendLinef(rect.xmin + 22, yofs + h * 235.0f / 255.0f, rect.xmin + w3, yofs + h * 235.0f / 255.0f); + gpuAppendLinef(rect.xmin + 3 * w3, yofs + h * 235.0f / 255.0f, rect.xmax + 1, yofs + h * 235.0f / 255.0f); + gpuAppendLinef(rect.xmin + w3, yofs + h * 240.0f / 255.0f, rect.xmax + 1, yofs + h * 240.0f / 255.0f); } /* 7.5 IRE black point level for NTSC */ - if (scopes->wavefrm_mode == SCOPES_WAVEFRM_LUMA) - fdrawline(rect.xmin, yofs + h * 0.075f, rect.xmax + 1, yofs + h * 0.075f); + if (scopes->wavefrm_mode == SCOPES_WAVEFRM_LUMA) { + gpuAppendLinef(rect.xmin, yofs + h * 0.075f, rect.xmax + 1, yofs + h * 0.075f); + } + + gpuEnd(); + gpuImmediateUnformat(); if (scopes->ok && scopes->waveform_1 != NULL) { - + GPUarrays arrays = GPU_ARRAYS_V2F; + + glBlendFunc(GL_ONE, GL_ONE); /* non-standard blend function */ + + gpuImmediateFormat_V2(); + /* LUMA (1 channel) */ - glBlendFunc(GL_ONE, GL_ONE); - glColor3f(alpha, alpha, alpha); + gpuCurrentGray3f(alpha); if (scopes->wavefrm_mode == SCOPES_WAVEFRM_LUMA) { - glBlendFunc(GL_ONE, GL_ONE); - - glPushMatrix(); - glEnableClientState(GL_VERTEX_ARRAY); - - glTranslatef(rect.xmin, yofs, 0.f); - glScalef(w, h, 0.f); - glVertexPointer(2, GL_FLOAT, 0, scopes->waveform_1); - glDrawArrays(GL_POINTS, 0, scopes->waveform_tot); - - glDisableClientState(GL_VERTEX_ARRAY); - glPopMatrix(); + gpuPushMatrix(); + gpuTranslate(rect.xmin, yofs, 0); + gpuScale(w, h, 0); + + arrays.vertexPointer = scopes->waveform_1; + gpuDrawClientArrays(GL_POINTS, &arrays, 0, scopes->waveform_tot); + + gpuPopMatrix(); /* min max */ - glColor3f(0.5f, 0.5f, 0.5f); + gpuCurrentGray3f(0.500f); min = yofs + scopes->minmax[0][0] * h; max = yofs + scopes->minmax[0][1] * h; CLAMP(min, rect.ymin, rect.ymax); CLAMP(max, rect.ymin, rect.ymax); - fdrawline(rect.xmax - 3, min, rect.xmax - 3, max); + gpuDrawLinef(rect.xmax - 3, min, rect.xmax - 3, max); } - /* RGB / YCC (3 channels) */ else if (ELEM4(scopes->wavefrm_mode, SCOPES_WAVEFRM_RGB, @@ -904,50 +930,54 @@ void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), SCOPES_WAVEFRM_YCC_709, SCOPES_WAVEFRM_YCC_JPEG)) { + GPUarrays arrays = GPU_ARRAYS_V2F; + int rgb = (scopes->wavefrm_mode == SCOPES_WAVEFRM_RGB); - - glBlendFunc(GL_ONE, GL_ONE); - - glPushMatrix(); - glEnableClientState(GL_VERTEX_ARRAY); - - glTranslatef(rect.xmin, yofs, 0.f); - glScalef(w3, h, 0.f); - - glColor3fv((rgb) ? colors_alpha[0] : colorsycc_alpha[0]); - glVertexPointer(2, GL_FLOAT, 0, scopes->waveform_1); - glDrawArrays(GL_POINTS, 0, scopes->waveform_tot); - - glTranslatef(1.f, 0.f, 0.f); - glColor3fv((rgb) ? colors_alpha[1] : colorsycc_alpha[1]); - glVertexPointer(2, GL_FLOAT, 0, scopes->waveform_2); - glDrawArrays(GL_POINTS, 0, scopes->waveform_tot); - - glTranslatef(1.f, 0.f, 0.f); - glColor3fv((rgb) ? colors_alpha[2] : colorsycc_alpha[2]); - glVertexPointer(2, GL_FLOAT, 0, scopes->waveform_3); - glDrawArrays(GL_POINTS, 0, scopes->waveform_tot); - - glDisableClientState(GL_VERTEX_ARRAY); - glPopMatrix(); - + gpuPushMatrix(); + + gpuTranslate(rect.xmin, yofs, 0); + gpuScale(w3, h, 0); + + gpuCurrentColor3fv((rgb) ? colors_alpha[0] : colorsycc_alpha[0]); + arrays.vertexPointer = scopes->waveform_1; + gpuDrawClientArrays(GL_POINTS, &arrays, 0, scopes->waveform_tot); + + gpuTranslate(1, 0, 0); + gpuCurrentColor3fv((rgb) ? colors_alpha[1] : colorsycc_alpha[1]); + arrays.vertexPointer = scopes->waveform_2; + gpuDrawClientArrays(GL_POINTS, &arrays, 0, scopes->waveform_tot); + + gpuTranslate(1, 0, 0); + gpuCurrentColor3fv((rgb) ? colors_alpha[2] : colorsycc_alpha[2]); + arrays.vertexPointer = scopes->waveform_3; + gpuDrawClientArrays(GL_POINTS, &arrays, 0, scopes->waveform_tot); + + gpuPopMatrix(); + /* min max */ for (c = 0; c < 3; c++) { - if (scopes->wavefrm_mode == SCOPES_WAVEFRM_RGB) - glColor3f(colors[c][0] * 0.75f, colors[c][1] * 0.75f, colors[c][2] * 0.75f); - else - glColor3f(colorsycc[c][0] * 0.75f, colorsycc[c][1] * 0.75f, colorsycc[c][2] * 0.75f); + if (scopes->wavefrm_mode == SCOPES_WAVEFRM_RGB) { + gpuCurrentColor3f(colors[c][0] * 0.75f, colors[c][1] * 0.75f, colors[c][2] * 0.75f); + } + else { + gpuCurrentColor3f(colorsycc[c][0] * 0.75f, colorsycc[c][1] * 0.75f, colorsycc[c][2] * 0.75f); + } + min = yofs + scopes->minmax[c][0] * h; max = yofs + scopes->minmax[c][1] * h; CLAMP(min, rect.ymin, rect.ymax); CLAMP(max, rect.ymin, rect.ymax); - fdrawline(rect.xmin + w + 2 + c * 2, min, rect.xmin + w + 2 + c * 2, max); + + gpuDrawLinef(rect.xmin + w + 2 + c * 2, min, rect.xmin + w + 2 + c * 2, max); // DOODLE: single line } } - + + gpuImmediateUnformat(); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); /* reset blender default */ } - + /* outline, scale gripper */ draw_scope_end(&rect, scissor); } @@ -977,42 +1007,43 @@ static void vectorscope_draw_target(float centerx, float centery, float diam, co tampli = sqrtf(u * u + v * v); /* small target vary by 2.5 degree and 2.5 IRE unit */ - glColor4f(1.0f, 1.0f, 1.0, 0.12f); + gpuCurrentColor4x(CPACK_WHITE, 0.120f); + dangle = DEG2RADF(2.5f); dampli = 2.5f / 200.0f; - glBegin(GL_LINE_STRIP); - glVertex2f(polar_to_x(centerx, diam, tampli + dampli, tangle + dangle), polar_to_y(centery, diam, tampli + dampli, tangle + dangle)); - glVertex2f(polar_to_x(centerx, diam, tampli - dampli, tangle + dangle), polar_to_y(centery, diam, tampli - dampli, tangle + dangle)); - glVertex2f(polar_to_x(centerx, diam, tampli - dampli, tangle - dangle), polar_to_y(centery, diam, tampli - dampli, tangle - dangle)); - glVertex2f(polar_to_x(centerx, diam, tampli + dampli, tangle - dangle), polar_to_y(centery, diam, tampli + dampli, tangle - dangle)); - glVertex2f(polar_to_x(centerx, diam, tampli + dampli, tangle + dangle), polar_to_y(centery, diam, tampli + dampli, tangle + dangle)); - glEnd(); + + gpuBegin(GL_LINE_STRIP); + gpuVertex2f(polar_to_x(centerx, diam, tampli + dampli, tangle + dangle), polar_to_y(centery, diam, tampli + dampli, tangle + dangle)); + gpuVertex2f(polar_to_x(centerx, diam, tampli - dampli, tangle + dangle), polar_to_y(centery, diam, tampli - dampli, tangle + dangle)); + gpuVertex2f(polar_to_x(centerx, diam, tampli - dampli, tangle - dangle), polar_to_y(centery, diam, tampli - dampli, tangle - dangle)); + gpuVertex2f(polar_to_x(centerx, diam, tampli + dampli, tangle - dangle), polar_to_y(centery, diam, tampli + dampli, tangle - dangle)); + gpuVertex2f(polar_to_x(centerx, diam, tampli + dampli, tangle + dangle), polar_to_y(centery, diam, tampli + dampli, tangle + dangle)); + gpuEnd(); /* big target vary by 10 degree and 20% amplitude */ - glColor4f(1.0f, 1.0f, 1.0, 0.12f); dangle = DEG2RADF(10.0f); dampli = 0.2f * tampli; dangle2 = DEG2RADF(5.0f); dampli2 = 0.5f * dampli; - glBegin(GL_LINE_STRIP); - glVertex2f(polar_to_x(centerx, diam, tampli + dampli - dampli2, tangle + dangle), polar_to_y(centery, diam, tampli + dampli - dampli2, tangle + dangle)); - glVertex2f(polar_to_x(centerx, diam, tampli + dampli, tangle + dangle), polar_to_y(centery, diam, tampli + dampli, tangle + dangle)); - glVertex2f(polar_to_x(centerx, diam, tampli + dampli, tangle + dangle - dangle2), polar_to_y(centery, diam, tampli + dampli, tangle + dangle - dangle2)); - glEnd(); - glBegin(GL_LINE_STRIP); - glVertex2f(polar_to_x(centerx, diam, tampli - dampli + dampli2, tangle + dangle), polar_to_y(centery, diam, tampli - dampli + dampli2, tangle + dangle)); - glVertex2f(polar_to_x(centerx, diam, tampli - dampli, tangle + dangle), polar_to_y(centery, diam, tampli - dampli, tangle + dangle)); - glVertex2f(polar_to_x(centerx, diam, tampli - dampli, tangle + dangle - dangle2), polar_to_y(centery, diam, tampli - dampli, tangle + dangle - dangle2)); - glEnd(); - glBegin(GL_LINE_STRIP); - glVertex2f(polar_to_x(centerx, diam, tampli - dampli + dampli2, tangle - dangle), polar_to_y(centery, diam, tampli - dampli + dampli2, tangle - dangle)); - glVertex2f(polar_to_x(centerx, diam, tampli - dampli, tangle - dangle), polar_to_y(centery, diam, tampli - dampli, tangle - dangle)); - glVertex2f(polar_to_x(centerx, diam, tampli - dampli, tangle - dangle + dangle2), polar_to_y(centery, diam, tampli - dampli, tangle - dangle + dangle2)); - glEnd(); - glBegin(GL_LINE_STRIP); - glVertex2f(polar_to_x(centerx, diam, tampli + dampli - dampli2, tangle - dangle), polar_to_y(centery, diam, tampli + dampli - dampli2, tangle - dangle)); - glVertex2f(polar_to_x(centerx, diam, tampli + dampli, tangle - dangle), polar_to_y(centery, diam, tampli + dampli, tangle - dangle)); - glVertex2f(polar_to_x(centerx, diam, tampli + dampli, tangle - dangle + dangle2), polar_to_y(centery, diam, tampli + dampli, tangle - dangle + dangle2)); - glEnd(); + gpuBegin(GL_LINE_STRIP); + gpuVertex2f(polar_to_x(centerx, diam, tampli + dampli - dampli2, tangle + dangle), polar_to_y(centery, diam, tampli + dampli - dampli2, tangle + dangle)); + gpuVertex2f(polar_to_x(centerx, diam, tampli + dampli, tangle + dangle), polar_to_y(centery, diam, tampli + dampli, tangle + dangle)); + gpuVertex2f(polar_to_x(centerx, diam, tampli + dampli, tangle + dangle - dangle2), polar_to_y(centery, diam, tampli + dampli, tangle + dangle - dangle2)); + gpuEnd(); + gpuBegin(GL_LINE_STRIP); + gpuVertex2f(polar_to_x(centerx, diam, tampli - dampli + dampli2, tangle + dangle), polar_to_y(centery, diam, tampli - dampli + dampli2, tangle + dangle)); + gpuVertex2f(polar_to_x(centerx, diam, tampli - dampli, tangle + dangle), polar_to_y(centery, diam, tampli - dampli, tangle + dangle)); + gpuVertex2f(polar_to_x(centerx, diam, tampli - dampli, tangle + dangle - dangle2), polar_to_y(centery, diam, tampli - dampli, tangle + dangle - dangle2)); + gpuEnd(); + gpuBegin(GL_LINE_STRIP); + gpuVertex2f(polar_to_x(centerx, diam, tampli - dampli + dampli2, tangle - dangle), polar_to_y(centery, diam, tampli - dampli + dampli2, tangle - dangle)); + gpuVertex2f(polar_to_x(centerx, diam, tampli - dampli, tangle - dangle), polar_to_y(centery, diam, tampli - dampli, tangle - dangle)); + gpuVertex2f(polar_to_x(centerx, diam, tampli - dampli, tangle - dangle + dangle2), polar_to_y(centery, diam, tampli - dampli, tangle - dangle + dangle2)); + gpuEnd(); + gpuBegin(GL_LINE_STRIP); + gpuVertex2f(polar_to_x(centerx, diam, tampli + dampli - dampli2, tangle - dangle), polar_to_y(centery, diam, tampli + dampli - dampli2, tangle - dangle)); + gpuVertex2f(polar_to_x(centerx, diam, tampli + dampli, tangle - dangle), polar_to_y(centery, diam, tampli + dampli, tangle - dangle)); + gpuVertex2f(polar_to_x(centerx, diam, tampli + dampli, tangle - dangle + dangle2), polar_to_y(centery, diam, tampli + dampli, tangle - dangle + dangle2)); + gpuEnd(); } void ui_draw_but_VECTORSCOPE(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *recti) @@ -1027,78 +1058,94 @@ void ui_draw_but_VECTORSCOPE(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wco {0.75, 0.0, 0.0}, {0.75, 0.75, 0.0}, {0.0, 0.75, 0.0}, {0.0, 0.75, 0.75}, {0.0, 0.0, 0.75}, {0.75, 0.0, 0.75}}; GLint scissor[4]; - + rect.xmin = (float)recti->xmin + 1; rect.xmax = (float)recti->xmax - 1; rect.ymin = (float)recti->ymin + SCOPE_RESIZE_PAD + 2; rect.ymax = (float)recti->ymax - 1; - + w = BLI_rctf_size_x(&rect); h = BLI_rctf_size_y(&rect); centerx = rect.xmin + w / 2; centery = rect.ymin + h / 2; diam = (w < h) ? w : h; - + alpha = scopes->vecscope_alpha * scopes->vecscope_alpha * scopes->vecscope_alpha; - + glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - glColor4f(0.f, 0.f, 0.f, 0.3f); + + gpuCurrentColor4x(CPACK_BLACK, 0.300f); uiSetRoundBox(UI_CNR_ALL); - uiDrawBox(GL_POLYGON, rect.xmin - 1, rect.ymin - 1, rect.xmax + 1, rect.ymax + 1, 3.0f); + uiDrawBox(GL_TRIANGLE_FAN, rect.xmin - 1, rect.ymin - 1, rect.xmax + 1, rect.ymax + 1, 3.0f); /* need scissor test, hvectorscope can draw outside of boundary */ - glGetIntegerv(GL_VIEWPORT, scissor); - glScissor(ar->winrct.xmin + (rect.xmin - 1), + gpuGetSizeBox(GL_VIEWPORT, scissor); + gpuScissor(ar->winrct.xmin + (rect.xmin - 1), ar->winrct.ymin + (rect.ymin - 1), (rect.xmax + 1) - (rect.xmin - 1), (rect.ymax + 1) - (rect.ymin - 1)); - - glColor4f(1.f, 1.f, 1.f, 0.08f); + + gpuCurrentColor4x(CPACK_WHITE, 0.080f); + /* draw grid elements */ + /* cross */ - fdrawline(centerx - (diam / 2) - 5, centery, centerx + (diam / 2) + 5, centery); - fdrawline(centerx, centery - (diam / 2) - 5, centerx, centery + (diam / 2) + 5); + gpuImmediateFormat_V2(); // DOODLE: cross, fixed number of lines, and 5 circles + + gpuBegin(GL_LINES); + gpuAppendLinef(centerx - (diam / 2) - 5, centery, centerx + (diam / 2) + 5, centery); + gpuAppendLinef(centerx, centery - (diam / 2) - 5, centerx, centery + (diam / 2) + 5); + gpuEnd(); + /* circles */ for (j = 0; j < 5; j++) { - glBegin(GL_LINE_STRIP); + gpuBegin(GL_LINE_STRIP); for (i = 0; i <= 360; i = i + 15) { const float a = DEG2RADF((float)i); const float r = (j + 1) / 10.0f; - glVertex2f(polar_to_x(centerx, diam, r, a), polar_to_y(centery, diam, r, a)); + gpuVertex2f(polar_to_x(centerx, diam, r, a), polar_to_y(centery, diam, r, a)); } - glEnd(); + gpuEnd(); } + /* skin tone line */ - glColor4f(1.f, 0.4f, 0.f, 0.2f); - fdrawline(polar_to_x(centerx, diam, 0.5f, skin_rad), polar_to_y(centery, diam, 0.5, skin_rad), - polar_to_x(centerx, diam, 0.1f, skin_rad), polar_to_y(centery, diam, 0.1, skin_rad)); + gpuCurrentColor4f(1.0f, 0.4f, 0.0f, 0.200f); + gpuDrawLinef( + 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)); + /* saturation points */ - for (i = 0; i < 6; i++) + for (i = 0; i < 6; i++) { vectorscope_draw_target(centerx, centery, diam, colors[i]); - + } + if (scopes->ok && scopes->vecscope != NULL) { + GPUarrays arrays = GPU_ARRAYS_V2F; + + glBlendFunc(GL_ONE, GL_ONE); /* non-standard blendfunc */ + /* pixel point cloud */ - glBlendFunc(GL_ONE, GL_ONE); - glColor3f(alpha, alpha, alpha); + gpuCurrentGray3f(alpha); - glPushMatrix(); - glEnableClientState(GL_VERTEX_ARRAY); + gpuPushMatrix(); + gpuTranslate(centerx, centery, 0); + gpuScale(diam, diam, 0); - glTranslatef(centerx, centery, 0.f); - glScalef(diam, diam, 0.f); + arrays.vertexPointer = scopes->vecscope; + gpuDrawClientArrays(GL_POINTS, &arrays, 0, scopes->waveform_tot); - glVertexPointer(2, GL_FLOAT, 0, scopes->vecscope); - glDrawArrays(GL_POINTS, 0, scopes->waveform_tot); - - glDisableClientState(GL_VERTEX_ARRAY); - glPopMatrix(); + gpuPopMatrix(); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); /* reset blender default */ } + gpuImmediateUnformat(); + /* outline, scale gripper */ draw_scope_end(&rect, scissor); - + glDisable(GL_BLEND); } @@ -1123,52 +1170,54 @@ void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *rect) sizex = rect->xmax - x1; sizey = rect->ymax - y1; + gpuImmediateFormat_C4_V2(); + /* first background, to show tranparency */ - glColor4ub(UI_TRANSP_DARK, UI_TRANSP_DARK, UI_TRANSP_DARK, 255); - glRectf(x1, y1, x1 + sizex, y1 + sizey); + gpuCurrentColor4ub(UI_TRANSP_DARK, UI_TRANSP_DARK, UI_TRANSP_DARK, 255); + gpuDrawFilledRectf(x1, y1, x1 + sizex, y1 + sizey); glEnable(GL_POLYGON_STIPPLE); - glColor4ub(UI_TRANSP_LIGHT, UI_TRANSP_LIGHT, UI_TRANSP_LIGHT, 255); + gpuCurrentColor4ub(UI_TRANSP_LIGHT, UI_TRANSP_LIGHT, UI_TRANSP_LIGHT, 255); glPolygonStipple(checker_stipple_sml); - glRectf(x1, y1, x1 + sizex, y1 + sizey); + gpuDrawFilledRectf(x1, y1, x1 + sizex, y1 + sizey); glDisable(GL_POLYGON_STIPPLE); glShadeModel(GL_FLAT); glEnable(GL_BLEND); - + cbd = coba->data; - + v1[0] = v2[0] = x1; v1[1] = y1; v2[1] = y1 + sizey; - - glBegin(GL_QUAD_STRIP); - - glColor4fv(&cbd->r); - glVertex2fv(v1); - glVertex2fv(v2); + + gpuBegin(GL_TRIANGLE_STRIP); + + gpuColor4fv(&cbd->r); + gpuVertex2fv(v1); + gpuVertex2fv(v2); for (a = 1; a <= sizex; a++) { pos = ((float)a) / (sizex - 1); do_colorband(coba, pos, colf); if (display) IMB_colormanagement_scene_linear_to_display_v3(colf, display); - + v1[0] = v2[0] = x1 + a; - - glColor4fv(colf); - glVertex2fv(v1); - glVertex2fv(v2); + + gpuColor4fv(colf); + gpuVertex2fv(v1); + gpuVertex2fv(v2); } - - glEnd(); + + gpuEnd(); glShadeModel(GL_FLAT); glDisable(GL_BLEND); - + /* outline */ - glColor4f(0.0, 0.0, 0.0, 1.0); - fdrawbox(x1, y1, x1 + sizex, y1 + sizey); - + gpuCurrentColor3x(CPACK_BLACK); + gpuDrawWireRectf(x1, y1, x1 + sizex, y1 + sizey); + /* help lines */ v1[0] = v2[0] = v3[0] = x1; v1[1] = y1; @@ -1176,146 +1225,159 @@ void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *rect) v2[1] = y1 + 0.5f * sizey; v2a[1] = y1 + 0.75f * sizey; v3[1] = y1 + sizey; - - + + cbd = coba->data; - glBegin(GL_LINES); + gpuBegin(GL_LINES); for (a = 0; a < coba->tot; a++, cbd++) { v1[0] = v2[0] = v3[0] = v1a[0] = v2a[0] = x1 + cbd->pos * sizex; - + if (a == coba->cur) { - glColor3ub(0, 0, 0); - glVertex2fv(v1); - glVertex2fv(v3); - glEnd(); - + gpuColor3x(CPACK_BLACK); + gpuVertex2fv(v1); + gpuVertex2fv(v3); + gpuEnd(); + setlinestyle(2); - glBegin(GL_LINES); - glColor3ub(255, 255, 255); - glVertex2fv(v1); - glVertex2fv(v3); - glEnd(); + gpuBegin(GL_LINES); + gpuColor3x(CPACK_WHITE); + gpuVertex2fv(v1); + gpuVertex2fv(v3); + gpuEnd(); setlinestyle(0); - glBegin(GL_LINES); - + gpuBegin(GL_LINES); + #if 0 - glColor3ub(0, 0, 0); - glVertex2fv(v1); - glVertex2fv(v1a); - glColor3ub(255, 255, 255); - glVertex2fv(v1a); - glVertex2fv(v2); - glColor3ub(0, 0, 0); - glVertex2fv(v2); - glVertex2fv(v2a); - glColor3ub(255, 255, 255); - glVertex2fv(v2a); - glVertex2fv(v3); + gpuColor3x(CPACK_BLACK); + + gpuVertex2fv(v1); + gpuVertex2fv(v1a); + + gpuVertex2fv(v2); + gpuVertex2fv(v2a); + + gpuColor3x(CPACK_WHITE); + + gpuVertex2fv(v1a); + gpuVertex2fv(v2); + + gpuVertex2fv(v2a); + gpuVertex2fv(v3); #endif } else { - glColor3ub(0, 0, 0); - glVertex2fv(v1); - glVertex2fv(v2); - - glColor3ub(255, 255, 255); - glVertex2fv(v2); - glVertex2fv(v3); + gpuColor3x(CPACK_BLACK); + gpuVertex2fv(v1); + gpuVertex2fv(v2); + + gpuColor3x(CPACK_WHITE); + gpuVertex2fv(v2); + gpuVertex2fv(v3); } } - glEnd(); + gpuEnd(); + gpuImmediateUnformat(); } void ui_draw_but_NORMAL(uiBut *but, uiWidgetColors *wcol, rcti *rect) { - static GLuint displist = 0; + static GPUimmediate *displist = NULL; + static GPUindex *index = NULL; + int a, old[8]; GLfloat diff[4], diffn[4] = {1.0f, 1.0f, 1.0f, 1.0f}; float vec0[4] = {0.0f, 0.0f, 0.0f, 0.0f}; float dir[4], size; - + /* store stuff */ - glGetMaterialfv(GL_FRONT, GL_DIFFUSE, diff); + gpuGetMaterialfv(GL_FRONT, GL_DIFFUSE, diff); /* backdrop */ - glColor3ubv((unsigned char *)wcol->inner); + gpuCurrentColor3ubv((unsigned char *)wcol->inner); uiSetRoundBox(UI_CNR_ALL); - uiDrawBox(GL_POLYGON, rect->xmin, rect->ymin, rect->xmax, rect->ymax, 5.0f); + uiDrawBox(GL_TRIANGLE_FAN, rect->xmin, rect->ymin, rect->xmax, rect->ymax, 5.0f); /* sphere color */ - glMaterialfv(GL_FRONT, GL_DIFFUSE, diffn); + gpuMaterialfv(GL_FRONT, GL_DIFFUSE, diffn); glCullFace(GL_BACK); glEnable(GL_CULL_FACE); /* disable blender light */ for (a = 0; a < 8; a++) { - old[a] = glIsEnabled(GL_LIGHT0 + a); - glDisable(GL_LIGHT0 + a); + old[a] = gpuIsLightEnabled(a); + gpuDisableLight(a); } /* own light */ - glEnable(GL_LIGHT7); - glEnable(GL_LIGHTING); + gpuEnableLight(7); + gpuEnableLighting(); ui_get_but_vectorf(but, dir); dir[3] = 0.0f; /* glLightfv needs 4 args, 0.0 is sun */ - glLightfv(GL_LIGHT7, GL_POSITION, dir); - glLightfv(GL_LIGHT7, GL_DIFFUSE, diffn); - glLightfv(GL_LIGHT7, GL_SPECULAR, vec0); - glLightf(GL_LIGHT7, GL_CONSTANT_ATTENUATION, 1.0f); - glLightf(GL_LIGHT7, GL_LINEAR_ATTENUATION, 0.0f); + gpuLightfv(7, GL_POSITION, dir); + gpuLightfv(7, GL_DIFFUSE, diffn); + gpuLightfv(7, GL_SPECULAR, vec0); + gpuLightf(7, GL_CONSTANT_ATTENUATION, 1.0f); + gpuLightf(7, GL_LINEAR_ATTENUATION, 0.0f); /* transform to button */ - glPushMatrix(); - glTranslatef(rect->xmin + 0.5f * BLI_rcti_size_x(rect), rect->ymin + 0.5f * BLI_rcti_size_y(rect), 0.0f); + gpuPushMatrix(); + gpuTranslate(rect->xmin + 0.5f * BLI_rcti_size_x(rect), rect->ymin + 0.5f * BLI_rcti_size_y(rect), 0.0f); if (BLI_rcti_size_x(rect) < BLI_rcti_size_y(rect)) size = BLI_rcti_size_x(rect) / 200.f; else size = BLI_rcti_size_y(rect) / 200.f; - glScalef(size, size, size); + gpuScale(size, size, size); - if (displist == 0) { - GLUquadricObj *qobj; - - displist = glGenLists(1); - glNewList(displist, GL_COMPILE_AND_EXECUTE); - - qobj = gluNewQuadric(); - gluQuadricDrawStyle(qobj, GLU_FILL); - glShadeModel(GL_SMOOTH); - gluSphere(qobj, 100.0, 32, 24); - glShadeModel(GL_FLAT); - gluDeleteQuadric(qobj); + glShadeModel(GL_SMOOTH); + + if (!displist) { + GPUprim3 prim = GPU_PRIM_HIFI_SOLID; + prim.usegs = 32; + prim.vsegs = 24; + + gpuPushImmediate(); + gpuImmediateMaxVertexCount(800); - glEndList(); + index = gpuNewIndex(); + gpuImmediateIndex(index); + gpuImmediateMaxIndexCount(4608); + + gpuSingleSphere(&prim, 100); + + displist = gpuPopImmediate(); } - else glCallList(displist); - + else { + gpuImmediateSingleRepeatElements(displist); + } + + glShadeModel(GL_FLAT); + /* restore */ - glDisable(GL_LIGHTING); + gpuDisableLighting(); glDisable(GL_CULL_FACE); - glMaterialfv(GL_FRONT, GL_DIFFUSE, diff); - glDisable(GL_LIGHT7); + gpuMaterialfv(GL_FRONT, GL_DIFFUSE, diff); + gpuDisableLight(7); /* AA circle */ glEnable(GL_BLEND); glEnable(GL_LINE_SMOOTH); - glColor3ubv((unsigned char *)wcol->inner); - glutil_draw_lined_arc(0.0f, M_PI * 2.0, 100.0f, 32); + gpuCurrentColor3ubv((unsigned char *)wcol->inner); + gpuSingleFastCircleXY(100.0f); glDisable(GL_BLEND); glDisable(GL_LINE_SMOOTH); /* matrix after circle */ - glPopMatrix(); + gpuPopMatrix(); /* enable blender light */ for (a = 0; a < 8; a++) { if (old[a]) - glEnable(GL_LIGHT0 + a); + gpuEnableLight(a); } } @@ -1323,13 +1385,13 @@ static void ui_draw_but_curve_grid(rcti *rect, float zoomx, float zoomy, float o { float dx, dy, fx, fy; - glBegin(GL_LINES); + gpuBegin(GL_LINES); dx = step * zoomx; fx = rect->xmin + zoomx * (-offsx); if (fx > rect->xmin) fx -= dx * (floorf(fx - rect->xmin)); while (fx < rect->xmax) { - glVertex2f(fx, rect->ymin); - glVertex2f(fx, rect->ymax); + gpuVertex2f(fx, rect->ymin); + gpuVertex2f(fx, rect->ymax); fx += dx; } @@ -1337,17 +1399,17 @@ static void ui_draw_but_curve_grid(rcti *rect, float zoomx, float zoomy, float o fy = rect->ymin + zoomy * (-offsy); if (fy > rect->ymin) fy -= dy * (floorf(fy - rect->ymin)); while (fy < rect->ymax) { - glVertex2f(rect->xmin, fy); - glVertex2f(rect->xmax, fy); + gpuVertex2f(rect->xmin, fy); + gpuVertex2f(rect->xmax, fy); fy += dy; } - glEnd(); + gpuEnd(); } static void gl_shaded_color(unsigned char *col, int shade) { - glColor3ub(col[0] - shade > 0 ? col[0] - shade : 0, + gpuCurrentColor3ub(col[0] - shade > 0 ? col[0] - shade : 0, col[1] - shade > 0 ? col[1] - shade : 0, col[2] - shade > 0 ? col[2] - shade : 0); } @@ -1372,13 +1434,13 @@ void ui_draw_but_CURVE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *rect cuma = &cumap->cm[cumap->cur]; /* need scissor test, curve can draw outside of boundary */ - glGetIntegerv(GL_VIEWPORT, scissor); + gpuGetSizeBox(GL_VIEWPORT, scissor); scissor_new.xmin = ar->winrct.xmin + rect->xmin; scissor_new.ymin = ar->winrct.ymin + rect->ymin; scissor_new.xmax = ar->winrct.xmin + rect->xmax; scissor_new.ymax = ar->winrct.ymin + rect->ymax; BLI_rcti_isect(&scissor_new, &ar->winrct, &scissor_new); - glScissor(scissor_new.xmin, + gpuScissor(scissor_new.xmin, scissor_new.ymin, BLI_rcti_size_x(&scissor_new), BLI_rcti_size_y(&scissor_new)); @@ -1393,7 +1455,7 @@ void ui_draw_but_CURVE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *rect if (but->a1 == UI_GRAD_H) { /* magic trigger for curve backgrounds */ rcti grid; - float col[3] = {0.0f, 0.0f, 0.0f}; /* dummy arg */ + float col[3] = {0,0,0}; /* dummy arg */ grid.xmin = rect->xmin + zoomx * (-offsx); grid.xmax = rect->xmax + zoomx * (-offsx); @@ -1404,24 +1466,23 @@ void ui_draw_but_CURVE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *rect /* grid, hsv uses different grid */ glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glColor4ub(0, 0, 0, 48); + gpuCurrentColor4x(CPACK_BLACK, 0.188f); ui_draw_but_curve_grid(rect, zoomx, zoomy, offsx, offsy, 0.1666666f); glDisable(GL_BLEND); } else { if (cumap->flag & CUMA_DO_CLIP) { gl_shaded_color((unsigned char *)wcol->inner, -20); - glRectf(rect->xmin, rect->ymin, rect->xmax, rect->ymax); - glColor3ubv((unsigned char *)wcol->inner); - glRectf(rect->xmin + zoomx * (cumap->clipr.xmin - offsx), - rect->ymin + zoomy * (cumap->clipr.ymin - offsy), - rect->xmin + zoomx * (cumap->clipr.xmax - offsx), - rect->ymin + zoomy * (cumap->clipr.ymax - offsy)); + gpuSingleFilledRectf(rect->xmin, rect->ymin, rect->xmax, rect->ymax); + gpuCurrentColor3ubv((unsigned char *)wcol->inner); + gpuSingleFilledRectf(rect->xmin + zoomx * (cumap->clipr.xmin - offsx), + rect->ymin + zoomy * (cumap->clipr.ymin - offsy), + rect->xmin + zoomx * (cumap->clipr.xmax - offsx), + rect->ymin + zoomy * (cumap->clipr.ymax - offsy)); } else { - glColor3ubv((unsigned char *)wcol->inner); - glRectf(rect->xmin, rect->ymin, rect->xmax, rect->ymax); + gpuCurrentColor3ubv((unsigned char *)wcol->inner); + gpuSingleFilledRectf(rect->xmin, rect->ymin, rect->xmax, rect->ymax); } /* grid, every 0.25 step */ @@ -1432,23 +1493,23 @@ void ui_draw_but_CURVE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *rect ui_draw_but_curve_grid(rect, zoomx, zoomy, offsx, offsy, 1.0f); /* axes */ gl_shaded_color((unsigned char *)wcol->inner, -50); - glBegin(GL_LINES); - glVertex2f(rect->xmin, rect->ymin + zoomy * (-offsy)); - glVertex2f(rect->xmax, rect->ymin + zoomy * (-offsy)); - glVertex2f(rect->xmin + zoomx * (-offsx), rect->ymin); - glVertex2f(rect->xmin + zoomx * (-offsx), rect->ymax); - glEnd(); + gpuBegin(GL_LINES); + gpuVertex2f(rect->xmin, rect->ymin + zoomy * (-offsy)); + gpuVertex2f(rect->xmax, rect->ymin + zoomy * (-offsy)); + gpuVertex2f(rect->xmin + zoomx * (-offsx), rect->ymin); + gpuVertex2f(rect->xmin + zoomx * (-offsx), rect->ymax); + gpuEnd(); } /* cfra option */ /* XXX 2.48 */ #if 0 if (cumap->flag & CUMA_DRAW_CFRA) { - glColor3ub(0x60, 0xc0, 0x40); - glBegin(GL_LINES); - glVertex2f(rect->xmin + zoomx * (cumap->sample[0] - offsx), rect->ymin); - glVertex2f(rect->xmin + zoomx * (cumap->sample[0] - offsx), rect->ymax); - glEnd(); + gpuCurrentColor3ub(0x60, 0xc0, 0x40); + gpuBegin(GL_LINES); + gpuVertex2f(rect->xmin + zoomx * (cumap->sample[0] - offsx), rect->ymin); + gpuVertex2f(rect->xmin + zoomx * (cumap->sample[0] - offsx), rect->ymax); + gpuEnd(); } #endif /* sample option */ @@ -1457,44 +1518,43 @@ void ui_draw_but_CURVE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *rect if (but->a1 == UI_GRAD_H) { float tsample[3]; float hsv[3]; + gpuCurrentGray3f(0.941f); linearrgb_to_srgb_v3_v3(tsample, cumap->sample); rgb_to_hsv_v(tsample, hsv); - glColor3ub(240, 240, 240); - glBegin(GL_LINES); - glVertex2f(rect->xmin + zoomx * (hsv[0] - offsx), rect->ymin); - glVertex2f(rect->xmin + zoomx * (hsv[0] - offsx), rect->ymax); - glEnd(); + gpuBegin(GL_LINES); + gpuVertex2f(rect->xmin + zoomx * (hsv[0] - offsx), rect->ymin); + gpuVertex2f(rect->xmin + zoomx * (hsv[0] - offsx), rect->ymax); + gpuEnd(); } else if (cumap->cur == 3) { float lum = rgb_to_bw(cumap->sample); - glColor3ub(240, 240, 240); - glBegin(GL_LINES); - glVertex2f(rect->xmin + zoomx * (lum - offsx), rect->ymin); - glVertex2f(rect->xmin + zoomx * (lum - offsx), rect->ymax); - glEnd(); + gpuBegin(GL_LINES); + gpuVertex2f(rect->xmin + zoomx * (lum - offsx), rect->ymin); + gpuVertex2f(rect->xmin + zoomx * (lum - offsx), rect->ymax); + gpuEnd(); } else { if (cumap->cur == 0) - glColor3ub(240, 100, 100); + gpuCurrentColor3ub(240, 100, 100); else if (cumap->cur == 1) - glColor3ub(100, 240, 100); + gpuCurrentColor3ub(100, 240, 100); else - glColor3ub(100, 100, 240); + gpuCurrentColor3ub(100, 100, 240); - glBegin(GL_LINES); - glVertex2f(rect->xmin + zoomx * (cumap->sample[cumap->cur] - offsx), rect->ymin); - glVertex2f(rect->xmin + zoomx * (cumap->sample[cumap->cur] - offsx), rect->ymax); - glEnd(); + gpuBegin(GL_LINES); + gpuVertex2f(rect->xmin + zoomx * (cumap->sample[cumap->cur] - offsx), rect->ymin); + gpuVertex2f(rect->xmin + zoomx * (cumap->sample[cumap->cur] - offsx), rect->ymax); + gpuEnd(); } } /* the curve */ - glColor3ubv((unsigned char *)wcol->item); + gpuCurrentColor3ubv((unsigned char *)wcol->item); glEnable(GL_LINE_SMOOTH); glEnable(GL_BLEND); - glBegin(GL_LINE_STRIP); + gpuBegin(GL_LINE_STRIP); if (cuma->table == NULL) curvemapping_changed(cumap, FALSE); @@ -1502,35 +1562,35 @@ void ui_draw_but_CURVE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *rect /* first point */ if ((cuma->flag & CUMA_EXTEND_EXTRAPOLATE) == 0) { - glVertex2f(rect->xmin, rect->ymin + zoomy * (cmp[0].y - offsy)); + gpuVertex2f(rect->xmin, rect->ymin + zoomy * (cmp[0].y - offsy)); } else { fx = rect->xmin + zoomx * (cmp[0].x - offsx + cuma->ext_in[0]); fy = rect->ymin + zoomy * (cmp[0].y - offsy + cuma->ext_in[1]); - glVertex2f(fx, fy); + gpuVertex2f(fx, fy); } for (a = 0; a <= CM_TABLE; a++) { fx = rect->xmin + zoomx * (cmp[a].x - offsx); fy = rect->ymin + zoomy * (cmp[a].y - offsy); - glVertex2f(fx, fy); + gpuVertex2f(fx, fy); } /* last point */ if ((cuma->flag & CUMA_EXTEND_EXTRAPOLATE) == 0) { - glVertex2f(rect->xmax, rect->ymin + zoomy * (cmp[CM_TABLE].y - offsy)); + gpuVertex2f(rect->xmax, rect->ymin + zoomy * (cmp[CM_TABLE].y - offsy)); } else { fx = rect->xmin + zoomx * (cmp[CM_TABLE].x - offsx - cuma->ext_out[0]); fy = rect->ymin + zoomy * (cmp[CM_TABLE].y - offsy - cuma->ext_out[1]); - glVertex2f(fx, fy); + gpuVertex2f(fx, fy); } - glEnd(); + gpuEnd(); glDisable(GL_LINE_SMOOTH); glDisable(GL_BLEND); /* the points, use aspect to make them visible on edges */ cmp = cuma->curve; glPointSize(3.0f); - bglBegin(GL_POINTS); + gpuBeginSprites(); for (a = 0; a < cuma->totpoint; a++) { if (cmp[a].flag & CUMA_SELECT) UI_ThemeColor(TH_TEXT_HI); @@ -1538,17 +1598,17 @@ void ui_draw_but_CURVE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, rcti *rect UI_ThemeColor(TH_TEXT); fac[0] = rect->xmin + zoomx * (cmp[a].x - offsx); fac[1] = rect->ymin + zoomy * (cmp[a].y - offsy); - bglVertex2fv(fac); + gpuSprite2fv(fac); } - bglEnd(); + gpuEndSprites(); glPointSize(1.0f); /* restore scissortest */ - glScissor(scissor[0], scissor[1], scissor[2], scissor[3]); + gpuScissor(scissor[0], scissor[1], scissor[2], scissor[3]); /* outline */ - glColor3ubv((unsigned char *)wcol->outline); - fdrawbox(rect->xmin, rect->ymin, rect->xmax, rect->ymax); + gpuCurrentColor3ubv((unsigned char *)wcol->outline); + gpuSingleWireRectf(rect->xmin, rect->ymin, rect->xmax, rect->ymax); } void ui_draw_but_TRACKPREVIEW(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *recti) @@ -1567,19 +1627,18 @@ void ui_draw_but_TRACKPREVIEW(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wc height = BLI_rctf_size_y(&rect); glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); /* need scissor test, preview image can draw outside of boundary */ - glGetIntegerv(GL_VIEWPORT, scissor); - glScissor(ar->winrct.xmin + (rect.xmin - 1), + gpuGetSizeBox(GL_VIEWPORT, scissor); + gpuScissor(ar->winrct.xmin + (rect.xmin - 1), ar->winrct.ymin + (rect.ymin - 1), (rect.xmax + 1) - (rect.xmin - 1), (rect.ymax + 1) - (rect.ymin - 1)); if (scopes->track_disabled) { - glColor4f(0.7f, 0.3f, 0.3f, 0.3f); + gpuCurrentColor4f(0.7f, 0.3f, 0.3f, 0.3f); uiSetRoundBox(15); - uiDrawBox(GL_POLYGON, rect.xmin - 1, rect.ymin, rect.xmax + 1, rect.ymax + 1, 3.0f); + uiDrawBox(GL_TRIANGLE_FAN, rect.xmin - 1, rect.ymin, rect.xmax + 1, rect.ymax + 1, 3.0f); ok = 1; } @@ -1613,29 +1672,29 @@ void ui_draw_but_TRACKPREVIEW(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wc int a; ImBuf *drawibuf; - glPushMatrix(); + gpuPushMatrix(); track_pos[0] = scopes->track_pos[0]; track_pos[1] = scopes->track_pos[1]; /* draw content of pattern area */ - glScissor(ar->winrct.xmin + rect.xmin, ar->winrct.ymin + rect.ymin, scissor[2], scissor[3]); + gpuScissor(ar->winrct.xmin + rect.xmin, ar->winrct.ymin + rect.ymin, scissor[2], scissor[3]); if (width > 0 && height > 0) { drawibuf = scopes->track_preview; if (scopes->use_track_mask) { - glColor4f(0.0f, 0.0f, 0.0f, 0.3f); + gpuCurrentColor4x(CPACK_BLACK, 0.300f); uiSetRoundBox(15); - uiDrawBox(GL_POLYGON, rect.xmin - 1, rect.ymin, rect.xmax + 1, rect.ymax + 1, 3.0f); + uiDrawBox(GL_TRIANGLE_FAN, rect.xmin - 1, rect.ymin, rect.xmax + 1, rect.ymax + 1, 3.0f); } glaDrawPixelsSafe(rect.xmin, rect.ymin + 1, drawibuf->x, drawibuf->y, drawibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, drawibuf->rect); /* draw cross for pizel position */ - glTranslatef(rect.xmin + track_pos[0], rect.ymin + track_pos[1], 0.f); - glScissor(ar->winrct.xmin + rect.xmin, + gpuTranslate(rect.xmin + track_pos[0], rect.ymin + track_pos[1], 0.f); + gpuScissor(ar->winrct.xmin + rect.xmin, ar->winrct.ymin + rect.ymin, BLI_rctf_size_x(&rect), BLI_rctf_size_y(&rect)); @@ -1650,25 +1709,25 @@ void ui_draw_but_TRACKPREVIEW(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wc UI_ThemeColor(TH_MARKER_OUTLINE); } - glBegin(GL_LINES); - glVertex2f(-10.0f, 0.0f); - glVertex2f(10.0f, 0.0f); - glVertex2f(0.0f, -10.0f); - glVertex2f(0.0f, 10.0f); - glEnd(); + gpuBegin(GL_LINES); + gpuVertex2f(-10.0f, 0.0f); + gpuVertex2f(10.0f, 0.0f); + gpuVertex2f(0.0f, -10.0f); + gpuVertex2f(0.0f, 10.0f); + gpuEnd(); } } glDisable(GL_LINE_STIPPLE); - glPopMatrix(); + gpuPopMatrix(); ok = 1; } if (!ok) { - glColor4f(0.f, 0.f, 0.f, 0.3f); + gpuCurrentColor4x(CPACK_BLACK, 0.300f); uiSetRoundBox(15); - uiDrawBox(GL_POLYGON, rect.xmin - 1, rect.ymin, rect.xmax + 1, rect.ymax + 1, 3.0f); + uiDrawBox(GL_TRIANGLE_FAN, rect.xmin - 1, rect.ymin, rect.xmax + 1, rect.ymax + 1, 3.0f); } /* outline, scale gripper */ @@ -1686,34 +1745,43 @@ static void ui_shadowbox(float minx, float miny, float maxx, float maxy, float s glShadeModel(GL_SMOOTH); /* right quad */ - glBegin(GL_POLYGON); - glColor4ub(0, 0, 0, alpha); - glVertex2f(maxx, miny); - glVertex2f(maxx, maxy - 0.3f * shadsize); - glColor4ub(0, 0, 0, 0); - glVertex2f(maxx + shadsize, maxy - 0.75f * shadsize); - glVertex2f(maxx + shadsize, miny); - glEnd(); + gpuBegin(GL_TRIANGLE_FAN); + + gpuColor4x(CPACK_BLACK, alpha); + gpuVertex2f(maxx, miny); + gpuVertex2f(maxx, maxy - 0.3f * shadsize); + + gpuColor4x(CPACK_BLACK, 0.000f); + gpuVertex2f(maxx + shadsize, maxy - 0.75f * shadsize); + gpuVertex2f(maxx + shadsize, miny); + + gpuEnd(); /* corner shape */ - glBegin(GL_POLYGON); - glColor4ub(0, 0, 0, alpha); - glVertex2f(maxx, miny); - glColor4ub(0, 0, 0, 0); - glVertex2f(maxx + shadsize, miny); - glVertex2f(maxx + 0.7f * shadsize, miny - 0.7f * shadsize); - glVertex2f(maxx, miny - shadsize); - glEnd(); + gpuBegin(GL_TRIANGLE_FAN); + + gpuColor4x(CPACK_BLACK, alpha); + gpuVertex2f(maxx, miny); + + gpuColor4x(CPACK_BLACK, 0.000f); + gpuVertex2f(maxx + shadsize, miny); + gpuVertex2f(maxx + 0.7f * shadsize, miny - 0.7f * shadsize); + gpuVertex2f(maxx, miny - shadsize); + + gpuEnd(); /* bottom quad */ - glBegin(GL_POLYGON); - glColor4ub(0, 0, 0, alpha); - glVertex2f(minx + 0.3f * shadsize, miny); - glVertex2f(maxx, miny); - glColor4ub(0, 0, 0, 0); - glVertex2f(maxx, miny - shadsize); - glVertex2f(minx + 0.5f * shadsize, miny - shadsize); - glEnd(); + gpuBegin(GL_TRIANGLE_FAN); + + gpuColor4x(CPACK_BLACK, alpha); + gpuVertex2f(minx + 0.3f * shadsize, miny); + gpuVertex2f(maxx, miny); + + gpuColor4x(CPACK_BLACK, 0.000f); + gpuVertex2f(maxx, miny - shadsize); + gpuVertex2f(minx + 0.5f * shadsize, miny - shadsize); + + gpuEnd(); glDisable(GL_BLEND); glShadeModel(GL_FLAT); @@ -1757,18 +1825,18 @@ void ui_dropshadow(const rctf *rct, float radius, float aspect, float alpha, int calpha = dalpha; for (; i--; a -= aspect) { /* alpha ranges from 2 to 20 or so */ - glColor4f(0.0f, 0.0f, 0.0f, calpha); + gpuCurrentColor4x(CPACK_BLACK, calpha); calpha += dalpha; - - uiDrawBox(GL_POLYGON, rct->xmin - a, rct->ymin - a, rct->xmax + a, rct->ymax - 10.0f + a, rad + a); + + uiDrawBox(GL_TRIANGLE_FAN, rct->xmin - a, rct->ymin - a, rct->xmax + a, rct->ymax - 10.0f + a, rad + a); } - + /* outline emphasis */ glEnable(GL_LINE_SMOOTH); - glColor4ub(0, 0, 0, 100); + gpuCurrentColor4x(CPACK_BLACK, 0.392f); uiDrawBox(GL_LINE_LOOP, rct->xmin - 0.5f, rct->ymin - 0.5f, rct->xmax + 0.5f, rct->ymax + 0.5f, radius + 0.5f); glDisable(GL_LINE_SMOOTH); - + glDisable(GL_BLEND); } diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c index bb0cc1176d8..a0aadedf7a5 100644 --- a/source/blender/editors/interface/interface_icons.c +++ b/source/blender/editors/interface/interface_icons.c @@ -63,7 +63,9 @@ #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" -#include "BIF_gl.h" +#include "GPU_colors.h" +#include "GPU_compatibility.h" + #include "BIF_glutil.h" #include "ED_datafiles.h" @@ -206,22 +208,22 @@ static void viconutil_set_point(GLint pt[2], int x, int y) static void viconutil_draw_tri(GLint(*pts)[2]) { - glBegin(GL_TRIANGLES); - glVertex2iv(pts[0]); - glVertex2iv(pts[1]); - glVertex2iv(pts[2]); - glEnd(); + gpuBegin(GL_TRIANGLES); + gpuVertex2iv(pts[0]); + gpuVertex2iv(pts[1]); + gpuVertex2iv(pts[2]); + gpuEnd(); } static void viconutil_draw_lineloop(GLint(*pts)[2], int numPoints) { int i; - glBegin(GL_LINE_LOOP); + gpuBegin(GL_LINE_LOOP); for (i = 0; i < numPoints; i++) { - glVertex2iv(pts[i]); + gpuVertex2iv(pts[i]); } - glEnd(); + gpuEnd(); } static void viconutil_draw_lineloop_smooth(GLint(*pts)[2], int numPoints) @@ -235,16 +237,16 @@ static void viconutil_draw_points(GLint(*pts)[2], int numPoints, int pointSize) { int i; - glBegin(GL_QUADS); + gpuBegin(GL_QUADS); for (i = 0; i < numPoints; i++) { int x = pts[i][0], y = pts[i][1]; - glVertex2i(x - pointSize, y - pointSize); - glVertex2i(x + pointSize, y - pointSize); - glVertex2i(x + pointSize, y + pointSize); - glVertex2i(x - pointSize, y + pointSize); + gpuVertex2i(x - pointSize, y - pointSize); + gpuVertex2i(x + pointSize, y - pointSize); + gpuVertex2i(x + pointSize, y + pointSize); + gpuVertex2i(x - pointSize, y + pointSize); } - glEnd(); + gpuEnd(); } /* Drawing functions */ @@ -259,14 +261,15 @@ static void vicon_x_draw(int x, int y, int w, int h, float alpha) glEnable(GL_LINE_SMOOTH); glLineWidth(2.5); - - glColor4f(0.0, 0.0, 0.0, alpha); - glBegin(GL_LINES); - glVertex2i(x, y); - glVertex2i(x + w, y + h); - glVertex2i(x + w, y); - glVertex2i(x, y + h); - glEnd(); + + gpuCurrentColor4x(CPACK_BLACK, alpha); + + gpuBegin(GL_LINES); + gpuVertex2i(x, y); + gpuVertex2i(x + w, y + h); + gpuVertex2i(x + w, y); + gpuVertex2i(x, y + h); + gpuEnd(); glLineWidth(1.0); @@ -279,26 +282,32 @@ static void vicon_view3d_draw(int x, int y, int w, int h, float alpha) int cy = y + h / 2; int d = MAX2(2, h / 3); - glColor4f(0.5, 0.5, 0.5, alpha); - glBegin(GL_LINES); - glVertex2i(x, cy - d); - glVertex2i(x + w, cy - d); - glVertex2i(x, cy + d); - glVertex2i(x + w, cy + d); - - glVertex2i(cx - d, y); - glVertex2i(cx - d, y + h); - glVertex2i(cx + d, y); - glVertex2i(cx + d, y + h); - glEnd(); - - glColor4f(0.0, 0.0, 0.0, alpha); - glBegin(GL_LINES); - glVertex2i(x, cy); - glVertex2i(x + w, cy); - glVertex2i(cx, y); - glVertex2i(cx, y + h); - glEnd(); + gpuCurrentGray4f(0.500f, alpha); + + gpuBegin(GL_LINES); + + gpuVertex2i(x, cy - d); + gpuVertex2i(x + w, cy - d); + gpuVertex2i(x, cy + d); + gpuVertex2i(x + w, cy + d); + + gpuVertex2i(cx - d, y); + gpuVertex2i(cx - d, y + h); + gpuVertex2i(cx + d, y); + gpuVertex2i(cx + d, y + h); + + gpuEnd(); + + gpuCurrentColor4x(CPACK_BLACK, alpha); + + gpuBegin(GL_LINES); + + gpuVertex2i(x, cy); + gpuVertex2i(x + w, cy); + gpuVertex2i(cx, y); + gpuVertex2i(cx, y + h); + + gpuEnd(); } static void vicon_edit_draw(int x, int y, int w, int h, float alpha) @@ -310,10 +319,10 @@ static void vicon_edit_draw(int x, int y, int w, int h, float alpha) viconutil_set_point(pts[2], x + w - 3, y + h - 3); viconutil_set_point(pts[3], x + 3, y + h - 3); - glColor4f(0.0, 0.0, 0.0, alpha); + gpuCurrentColor4x(CPACK_BLACK, alpha); viconutil_draw_lineloop(pts, 4); - glColor3f(1, 1, 0.0); + gpuCurrentColor3x(CPACK_YELLOW); viconutil_draw_points(pts, 4, 1); } @@ -325,13 +334,13 @@ static void vicon_editmode_hlt_draw(int x, int y, int w, int h, float alpha) viconutil_set_point(pts[1], x + 3, y + 4); viconutil_set_point(pts[2], x + w - 3, y + 4); - glColor4f(0.5, 0.5, 0.5, alpha); + gpuCurrentGray4f(0.500f, alpha); viconutil_draw_tri(pts); - glColor4f(0.0, 0.0, 0.0, 1); + gpuCurrentColor4x(CPACK_BLACK, 1); viconutil_draw_lineloop_smooth(pts, 3); - glColor3f(1, 1, 0.0); + gpuCurrentColor3x(CPACK_YELLOW); viconutil_draw_points(pts, 3, 1); } @@ -343,10 +352,10 @@ static void vicon_editmode_dehlt_draw(int x, int y, int w, int h, float UNUSED(a viconutil_set_point(pts[1], x + 3, y + 4); viconutil_set_point(pts[2], x + w - 3, y + 4); - glColor4f(0.0f, 0.0f, 0.0f, 1); + gpuCurrentColor3x(CPACK_BLACK); viconutil_draw_lineloop_smooth(pts, 3); - glColor3f(0.9f, 0.9f, 0.9f); + gpuCurrentGray3f(0.900f); viconutil_draw_points(pts, 3, 1); } @@ -362,16 +371,21 @@ static void vicon_disclosure_tri_right_draw(int x, int y, int w, int UNUSED(h), viconutil_set_point(pts[2], cx + d2, cy); glShadeModel(GL_SMOOTH); - glBegin(GL_TRIANGLES); - glColor4f(0.8f, 0.8f, 0.8f, alpha); - glVertex2iv(pts[0]); - glVertex2iv(pts[1]); - glColor4f(0.3f, 0.3f, 0.3f, alpha); - glVertex2iv(pts[2]); - glEnd(); + + gpuBegin(GL_TRIANGLES); + + gpuGray4f(0.800f, alpha); + gpuVertex2iv(pts[0]); + gpuVertex2iv(pts[1]); + + gpuGray4f(0.300f, alpha); + gpuVertex2iv(pts[2]); + + gpuEnd(); + glShadeModel(GL_FLAT); - glColor4f(0.0f, 0.0f, 0.0f, 1); + gpuCurrentColor3x(CPACK_BLACK); viconutil_draw_lineloop_smooth(pts, 3); } @@ -386,15 +400,15 @@ static void vicon_small_tri_right_draw(int x, int y, int w, int UNUSED(h), float viconutil_set_point(pts[1], cx - d2, cy - d); viconutil_set_point(pts[2], cx + d2, cy); - glColor4f(0.2f, 0.2f, 0.2f, alpha); + gpuCurrentGray4f(0.200f, alpha); - glShadeModel(GL_SMOOTH); - glBegin(GL_TRIANGLES); - glVertex2iv(pts[0]); - glVertex2iv(pts[1]); - glVertex2iv(pts[2]); - glEnd(); - glShadeModel(GL_FLAT); + gpuImmediateFormat_V3(); + gpuBegin(GL_TRIANGLES); + gpuVertex2iv(pts[0]); + gpuVertex2iv(pts[1]); + gpuVertex2iv(pts[2]); + gpuEnd(); + gpuImmediateUnformat(); } static void vicon_disclosure_tri_down_draw(int x, int y, int w, int UNUSED(h), float alpha) @@ -409,16 +423,21 @@ static void vicon_disclosure_tri_down_draw(int x, int y, int w, int UNUSED(h), f viconutil_set_point(pts[2], cx, cy - d2); glShadeModel(GL_SMOOTH); - glBegin(GL_TRIANGLES); - glColor4f(0.8f, 0.8f, 0.8f, alpha); - glVertex2iv(pts[0]); - glVertex2iv(pts[1]); - glColor4f(0.3f, 0.3f, 0.3f, alpha); - glVertex2iv(pts[2]); - glEnd(); + + gpuBegin(GL_TRIANGLES); + + gpuGray4f(0.800f, alpha); + gpuVertex2iv(pts[0]); + gpuVertex2iv(pts[1]); + + gpuGray4f(0.300f, alpha); + gpuVertex2iv(pts[2]); + + gpuEnd(); + glShadeModel(GL_FLAT); - glColor4f(0.0f, 0.0f, 0.0f, 1); + gpuCurrentColor3x(CPACK_BLACK); viconutil_draw_lineloop_smooth(pts, 3); } @@ -428,13 +447,13 @@ static void vicon_move_up_draw(int x, int y, int w, int h, float UNUSED(alpha)) glEnable(GL_LINE_SMOOTH); glLineWidth(1); - glColor3f(0.0, 0.0, 0.0); + gpuCurrentColor3x(CPACK_BLACK); - glBegin(GL_LINE_STRIP); - glVertex2i(x + w / 2 - d * 2, y + h / 2 + d); - glVertex2i(x + w / 2, y + h / 2 - d + 1); - glVertex2i(x + w / 2 + d * 2, y + h / 2 + d); - glEnd(); + gpuBegin(GL_LINE_STRIP); + gpuVertex2i(x + w / 2 - d * 2, y + h / 2 + d); + gpuVertex2i(x + w / 2, y + h / 2 - d + 1); + gpuVertex2i(x + w / 2 + d * 2, y + h / 2 + d); + gpuEnd(); glLineWidth(1.0); glDisable(GL_LINE_SMOOTH); @@ -446,13 +465,13 @@ static void vicon_move_down_draw(int x, int y, int w, int h, float UNUSED(alpha) glEnable(GL_LINE_SMOOTH); glLineWidth(1); - glColor3f(0.0, 0.0, 0.0); + gpuCurrentColor3x(CPACK_BLACK); - glBegin(GL_LINE_STRIP); - glVertex2i(x + w / 2 - d * 2, y + h / 2 + d); - glVertex2i(x + w / 2, y + h / 2 - d - 1); - glVertex2i(x + w / 2 + d * 2, y + h / 2 + d); - glEnd(); + gpuBegin(GL_LINE_STRIP); + gpuVertex2i(x + w / 2 - d * 2, y + h / 2 + d); + gpuVertex2i(x + w / 2, y + h / 2 - d - 1); + gpuVertex2i(x + w / 2 + d * 2, y + h / 2 + d); + gpuEnd(); glLineWidth(1.0); glDisable(GL_LINE_SMOOTH); @@ -508,7 +527,7 @@ static void init_brush_icons(void) #undef INIT_BRUSH_ICON } - +#include REAL_GL_MODE static void init_internal_icons(void) { bTheme *btheme = UI_GetTheme(); @@ -595,8 +614,11 @@ static void init_internal_icons(void) IMB_freeImBuf(bbuf); } +#include FAKE_GL_MODE + #endif /* WITH_HEADLESS */ + static void init_iconfile_list(struct ListBase *list) { IconFile *ifile; @@ -919,32 +941,41 @@ static void icon_draw_texture(float x, float y, float w, float h, int ix, int iy { float x1, x2, y1, y2; - if (rgb) glColor4f(rgb[0], rgb[1], rgb[2], alpha); - else glColor4f(1.0f, 1.0f, 1.0f, alpha); + if (rgb) { + gpuCurrentColor4f(rgb[0], rgb[1], rgb[2], alpha); + } + else { + gpuCurrentColor4x(CPACK_WHITE, alpha); + } x1 = ix * icongltex.invw; x2 = (ix + ih) * icongltex.invw; y1 = iy * icongltex.invh; y2 = (iy + ih) * icongltex.invh; - +#include REAL_GL_MODE glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, icongltex.id); - glBegin(GL_QUADS); - glTexCoord2f(x1, y1); - glVertex2f(x, y); + gpuImmediateFormat_T2_V2(); // DOODLE: icon, single quad with texture + gpuBegin(GL_TRIANGLE_FAN); + + gpuTexCoord2f(x1, y1); + gpuVertex2f(x, y); + + gpuTexCoord2f(x2, y1); + gpuVertex2f(x + w, y); - glTexCoord2f(x2, y1); - glVertex2f(x + w, y); + gpuTexCoord2f(x2, y2); + gpuVertex2f(x + w, y + h); - glTexCoord2f(x2, y2); - glVertex2f(x + w, y + h); + gpuTexCoord2f(x1, y2); + gpuVertex2f(x, y + h); - glTexCoord2f(x1, y2); - glVertex2f(x, y + h); - glEnd(); + gpuEnd(); + gpuImmediateUnformat(); glBindTexture(GL_TEXTURE_2D, 0); +#include FAKE_GL_MODE glDisable(GL_TEXTURE_2D); } @@ -1015,9 +1046,9 @@ static void icon_draw_size(float x, float y, int icon_id, float aspect, float al if (!pi->rect[size]) return; /* something has gone wrong! */ /* preview images use premul alpha ... */ - glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); /* non-standard blend function */ icon_draw_rect(x, y, w, h, aspect, pi->w[size], pi->h[size], pi->rect[size], 1.0f, NULL, is_preview); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); /* reset blender default */ } } } diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c index e7a5f993d32..f2c14d005af 100644 --- a/source/blender/editors/interface/interface_ops.c +++ b/source/blender/editors/interface/interface_ops.c @@ -54,7 +54,7 @@ #include "RNA_access.h" #include "RNA_define.h" -#include "BIF_gl.h" +#include "GPU_compatibility.h" #include "UI_interface.h" diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c index 2b170ea546b..3afdf3361d8 100644 --- a/source/blender/editors/interface/interface_panel.c +++ b/source/blender/editors/interface/interface_panel.c @@ -50,7 +50,9 @@ #include "BKE_context.h" #include "BKE_screen.h" -#include "BIF_gl.h" +#include "GPU_colors.h" +#include "GPU_primitives.h" + #include "BIF_glutil.h" #include "WM_api.h" @@ -330,15 +332,15 @@ static void ui_offset_panel_block(uiBlock *block) #if 0 /*UNUSED 2.5*/ static void uiPanelPush(uiBlock *block) { - glPushMatrix(); + gpuPushMatrix(); if (block->panel) - glTranslatef((float)block->panel->ofsx, (float)block->panel->ofsy, 0.0); + gpuTranslate((float)block->panel->ofsx, (float)block->panel->ofsy, 0.0); } static void uiPanelPop(uiBlock *UNUSED(block)) { - glPopMatrix(); + gpuPopMatrix(); } #endif @@ -371,18 +373,21 @@ static void ui_draw_tria_rect(const rctf *rect, char dir) static void ui_draw_anti_x(float x1, float y1, float x2, float y2) { - /* set antialias line */ glEnable(GL_LINE_SMOOTH); glEnable(GL_BLEND); glLineWidth(2.0); - - fdrawline(x1, y1, x2, y2); - fdrawline(x1, y2, x2, y1); - + + gpuImmediateFormat_V2(); // DOODLE: an X, two thick lines, mono + gpuBegin(GL_LINES); + gpuAppendLinef(x1, y1, x2, y2); + gpuAppendLinef(x1, y2, x2, y1); + gpuEnd(); + gpuImmediateUnformat(); + glLineWidth(1.0); - + glDisable(GL_LINE_SMOOTH); glDisable(GL_BLEND); @@ -412,13 +417,21 @@ static void ui_draw_panel_scalewidget(rcti *rect) dy = 0.5f * (ymax - ymin); glEnable(GL_BLEND); - glColor4ub(255, 255, 255, 50); - fdrawline(xmin, ymin, xmax, ymax); - fdrawline(xmin + dx, ymin, xmax, ymax - dy); + + gpuImmediateFormat_C4_V2(); // DOODLE: scale widget, fixed number of colored lines + gpuBegin(GL_LINES); + + gpuColor4x(CPACK_WHITE, 0.196f); + gpuAppendLinef(xmin, ymin, xmax, ymax); + gpuAppendLinef(xmin + dx, ymin, xmax, ymax - dy); - glColor4ub(0, 0, 0, 50); - fdrawline(xmin, ymin + 1, xmax, ymax + 1); - fdrawline(xmin + dx, ymin + 1, xmax, ymax - dy + 1); + gpuColor4x(CPACK_BLACK, 0.196f); + gpuAppendLinef(xmin, ymin + 1, xmax, ymax + 1); + gpuAppendLinef(xmin + dx, ymin + 1, xmax, ymax - dy + 1); + + gpuEnd(); + gpuImmediateUnformat(); + glDisable(GL_BLEND); } @@ -436,15 +449,23 @@ static void ui_draw_panel_dragwidget(const rctf *rect) dy = 0.333f * (ymax - ymin); glEnable(GL_BLEND); - glColor4ub(255, 255, 255, 50); - fdrawline(xmin, ymax, xmax, ymin); - fdrawline(xmin + dx, ymax, xmax, ymin + dy); - fdrawline(xmin + 2 * dx, ymax, xmax, ymin + 2 * dy); - - glColor4ub(0, 0, 0, 50); - fdrawline(xmin, ymax + 1, xmax, ymin + 1); - fdrawline(xmin + dx, ymax + 1, xmax, ymin + dy + 1); - fdrawline(xmin + 2 * dx, ymax + 1, xmax, ymin + 2 * dy + 1); + + gpuImmediateFormat_C4_V2(); // DOODLE: draw widge, 6 mono lines + gpuBegin(GL_LINES); + + gpuColor4x(CPACK_WHITE, 0.196f); + gpuAppendLinef(xmin, ymax, xmax, ymin); + gpuAppendLinef(xmin + dx, ymax, xmax, ymin + dy); + gpuAppendLinef(xmin + 2 * dx, ymax, xmax, ymin + 2 * dy); + + gpuColor4x(CPACK_BLACK, 0.196f); + gpuAppendLinef(xmin, ymax + 1, xmax, ymin + 1); + gpuAppendLinef(xmin + dx, ymax + 1, xmax, ymin + dy + 1); + gpuAppendLinef(xmin + 2 * dx, ymax + 1, xmax, ymin + 2 * dy + 1); + + gpuEnd(); + gpuImmediateUnformat(); + glDisable(GL_BLEND); } @@ -519,32 +540,44 @@ void ui_draw_aligned_panel(uiStyle *style, uiBlock *block, rcti *rect) if (btheme->tui.panel.show_header) { /* draw with background color */ - glEnable(GL_BLEND); - glColor4ubv((unsigned char *)btheme->tui.panel.header); - glRectf(minx, headrect.ymin + 1, maxx, y); + gpuCurrentColor4ubv((unsigned char *)btheme->tui.panel.header); + gpuSingleFilledRectf(minx, headrect.ymin + 1, maxx, y); + + gpuImmediateFormat_V2(); // DOODLE: 2 lines, mono + gpuBegin(GL_LINES); - fdrawline(minx, y, maxx, y); - fdrawline(minx, y, maxx, y); + gpuAppendLinef(minx, y, maxx, y); + + gpuAppendLinef(minx, y, maxx, y); + + gpuEnd(); + gpuImmediateUnformat(); } else if (!(panel->runtime_flag & PNL_FIRST)) { /* draw embossed separator */ minx += 5.0f / block->aspect; maxx -= 5.0f / block->aspect; - - glColor4f(0.0f, 0.0f, 0.0f, 0.5f); - fdrawline(minx, y, maxx, y); - glColor4f(1.0f, 1.0f, 1.0f, 0.25f); - fdrawline(minx, y - 1, maxx, y - 1); - glDisable(GL_BLEND); + + gpuImmediateFormat_C4_V2(); // DOODLE: 2 lines, colored + gpuBegin(GL_LINES); + + gpuColor4x(CPACK_BLACK, 0.500f); + gpuAppendLinef(minx, y, maxx, y); + + gpuColor4x(CPACK_WHITE, 0.250f); + gpuAppendLinef(minx, y - 1, maxx, y - 1); + + gpuEnd(); + gpuImmediateUnformat(); } glDisable(GL_BLEND); } - + /* horizontal title */ if (!(panel->flag & PNL_CLOSEDX)) { ui_draw_aligned_panel_header(style, block, &headrect, 'h'); - + /* itemrect smaller */ itemrect.xmax = headrect.xmax - 5.0f / block->aspect; itemrect.xmin = itemrect.xmax - BLI_rcti_size_y(&headrect); diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index 9b77072dee1..9e7e50d69ac 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -56,7 +56,9 @@ #include "RNA_access.h" -#include "BIF_gl.h" +#include "GPU_compatibility.h" +#include "GPU_utility.h" + #include "UI_interface.h" #include "UI_interface_icons.h" @@ -397,10 +399,12 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *ar) bbox.ymin = bbox.ymax - data->lineh; for (i = 0; i < data->totline; i++) { - glColor3fv(tip_colors[data->color_id[i]]); + GPU_STRING_MARKER("tooltip text start"); + gpuCurrentColor3fv(tip_colors[data->color_id[i]]); uiStyleFontDraw(&data->fstyle, &bbox, data->lines[i]); bbox.ymin -= data->lineh + data->spaceh; bbox.ymax -= data->lineh + data->spaceh; + GPU_STRING_MARKER("tooltip text end"); } } diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index c836d62021e..bef8fff4ae3 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -49,7 +49,9 @@ #include "RNA_access.h" -#include "BIF_gl.h" +#include "GPU_colors.h" +#include "GPU_primitives.h" + #include "BIF_glutil.h" #include "BLF_api.h" @@ -195,43 +197,40 @@ GLubyte checker_stipple_sml[32 * 32 / 8] = void ui_draw_anti_tria(float x1, float y1, float x2, float y2, float x3, float y3) { - float tri_arr[3][2] = {{x1, y1}, {x2, y2}, {x3, y3}}; - float color[4]; int j; - + glEnable(GL_BLEND); - glGetFloatv(GL_CURRENT_COLOR, color); - color[3] *= 0.125f; - glColor4fv(color); + gpuMultCurrentAlpha(0.125f); - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(2, GL_FLOAT, 0, tri_arr); + gpuImmediateFormat_V2(); + gpuBegin(GL_TRIANGLES); /* for each AA step */ for (j = 0; j < WIDGET_AA_JITTER; j++) { - glTranslatef(1.0f * jit[j][0], 1.0f * jit[j][1], 0.0f); - glDrawArrays(GL_TRIANGLES, 0, 3); - glTranslatef(-1.0f * jit[j][0], -1.0f * jit[j][1], 0.0f); + const GLfloat dx = jit[j][0]; + const GLfloat dy = jit[j][1]; + gpuVertex2f(x1 + dx, y1 + dy); + gpuVertex2f(x2 + dx, y2 + dy); + gpuVertex2f(x3 + dx, y3 + dy); } - glDisableClientState(GL_VERTEX_ARRAY); + gpuEnd(); + gpuImmediateUnformat(); + glDisable(GL_BLEND); } void ui_draw_anti_roundbox(int mode, float minx, float miny, float maxx, float maxy, float rad) { - float color[4]; int j; - + glEnable(GL_BLEND); - glGetFloatv(GL_CURRENT_COLOR, color); - color[3] *= 0.125f; - glColor4fv(color); - + gpuMultCurrentAlpha(0.125f); + for (j = 0; j < WIDGET_AA_JITTER; j++) { - glTranslatef(1.0f * jit[j][0], 1.0f * jit[j][1], 0.0f); + gpuTranslate(1.0f * jit[j][0], 1.0f * jit[j][1], 0.0f); uiDrawBox(mode, minx, miny, maxx, maxy, rad); - glTranslatef(-1.0f * jit[j][0], -1.0f * jit[j][1], 0.0f); + gpuTranslate(-1.0f * jit[j][0], -1.0f * jit[j][1], 0.0f); } glDisable(GL_BLEND); @@ -556,12 +555,30 @@ static void widget_scroll_circle(uiWidgetTrias *tria, rcti *rect, float triasize tria->index = scroll_circle_face; } -static void widget_trias_draw(uiWidgetTrias *tria) +static void widget_trias_append(uiWidgetTrias *tria) { - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(2, GL_FLOAT, 0, tria->vec); - glDrawElements(GL_TRIANGLES, tria->tot * 3, GL_UNSIGNED_INT, tria->index); - glDisableClientState(GL_VERTEX_ARRAY); + int i, j; + + if (tria->tot > 0) { + for (j = 0; j < WIDGET_AA_JITTER; j++) { + const float dx = jit[j][0]; + const float dy = jit[j][1]; + + for (i = 0; i < tria->tot; i++) { + float *v; + unsigned *index = tria->index[i]; + + v = tria->vec[index[0]]; + gpuVertex2f(v[0]+dx, v[1]+dy); + + v = tria->vec[index[1]]; + gpuVertex2f(v[0]+dx, v[1]+dy); + + v = tria->vec[index[2]]; + gpuVertex2f(v[0]+dx, v[1]+dy); + } + } + } } static void widget_menu_trias(uiWidgetTrias *tria, rcti *rect) @@ -661,106 +678,93 @@ static void widgetbase_outline(uiWidgetBase *wtb) float quad_strip[WIDGET_SIZE_MAX * 2 + 2][2]; /* + 2 because the last pair is wrapped */ widget_verts_to_quad_strip(wtb, wtb->totvert, quad_strip); - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(2, GL_FLOAT, 0, quad_strip); - glDrawArrays(GL_QUAD_STRIP, 0, wtb->totvert * 2 + 2); - glDisableClientState(GL_VERTEX_ARRAY); + gpuSingleClientArrays_V2F(GL_TRIANGLE_STRIP, quad_strip, 0, 0, 2*(wtb->totvert) + 2); } static void widgetbase_draw(uiWidgetBase *wtb, uiWidgetColors *wcol) { int j, a; - + glEnable(GL_BLEND); + // DOODLE: widgetbase_draw + /* backdrop non AA */ if (wtb->inner) { if (wcol->shaded == 0) { + GPUarrays arrays = GPU_ARRAYS_V2F; + + gpuImmediateFormat_V2(); + if (wcol->alpha_check) { float inner_v_half[WIDGET_SIZE_MAX][2]; - float x_mid = 0.0f; /* used for dumb clamping of values */ + float x_mid = 0; /* used for dumb clamping of values */ /* dark checkers */ - glColor4ub(UI_TRANSP_DARK, UI_TRANSP_DARK, UI_TRANSP_DARK, 255); - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(2, GL_FLOAT, 0, wtb->inner_v); - glDrawArrays(GL_POLYGON, 0, wtb->totvert); - glDisableClientState(GL_VERTEX_ARRAY); + gpuCurrentColor4ub(UI_TRANSP_DARK, UI_TRANSP_DARK, UI_TRANSP_DARK, 255); + arrays.vertexPointer = wtb->inner_v; + gpuDrawClientArrays(GL_TRIANGLE_FAN, &arrays, 0, wtb->totvert); /* light checkers */ glEnable(GL_POLYGON_STIPPLE); - glColor4ub(UI_TRANSP_LIGHT, UI_TRANSP_LIGHT, UI_TRANSP_LIGHT, 255); + gpuCurrentColor4ub(UI_TRANSP_LIGHT, UI_TRANSP_LIGHT, UI_TRANSP_LIGHT, 255); glPolygonStipple(checker_stipple_sml); - - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(2, GL_FLOAT, 0, wtb->inner_v); - glDrawArrays(GL_POLYGON, 0, wtb->totvert); - glDisableClientState(GL_VERTEX_ARRAY); - + gpuRepeat(); glDisable(GL_POLYGON_STIPPLE); - /* alpha fill */ - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - glColor4ubv((unsigned char *)wcol->inner); - glEnableClientState(GL_VERTEX_ARRAY); + gpuCurrentColor4ubv((unsigned char *)wcol->inner); + gpuRepeat(); for (a = 0; a < wtb->totvert; a++) { x_mid += wtb->inner_v[a][0]; } - x_mid /= wtb->totvert; - - glVertexPointer(2, GL_FLOAT, 0, wtb->inner_v); - glDrawArrays(GL_POLYGON, 0, wtb->totvert); - glDisableClientState(GL_VERTEX_ARRAY); - /* 1/2 solid color */ - glColor4ub(wcol->inner[0], wcol->inner[1], wcol->inner[2], 255); + x_mid /= wtb->totvert; for (a = 0; a < wtb->totvert; a++) { inner_v_half[a][0] = MIN2(wtb->inner_v[a][0], x_mid); inner_v_half[a][1] = wtb->inner_v[a][1]; } - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(2, GL_FLOAT, 0, inner_v_half); - glDrawArrays(GL_POLYGON, 0, wtb->totvert); - glDisableClientState(GL_VERTEX_ARRAY); + /* 1/2 solid color */ + gpuCurrentColor4ub(wcol->inner[0], wcol->inner[1], wcol->inner[2], 255); + arrays.vertexPointer = inner_v_half; + gpuDrawClientArrays(GL_TRIANGLE_FAN, &arrays, 0, wtb->totvert); } else { /* simple fill */ - glColor4ubv((unsigned char *)wcol->inner); - - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(2, GL_FLOAT, 0, wtb->inner_v); - glDrawArrays(GL_POLYGON, 0, wtb->totvert); - glDisableClientState(GL_VERTEX_ARRAY); + gpuCurrentColor4ubv((unsigned char *)wcol->inner); + arrays.vertexPointer = wtb->inner_v; + gpuDrawClientArrays(GL_TRIANGLE_FAN, &arrays, 0, wtb->totvert); } + + gpuImmediateUnformat(); } else { char col1[4], col2[4]; unsigned char col_array[WIDGET_SIZE_MAX * 4]; unsigned char *col_pt = col_array; - + shadecolors4(col1, col2, wcol->inner, wcol->shadetop, wcol->shadedown); - + glShadeModel(GL_SMOOTH); for (a = 0; a < wtb->totvert; a++, col_pt += 4) { round_box_shade_col4_r(col_pt, col1, col2, wtb->inner_uv[a][wtb->shadedir]); } - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); - glVertexPointer(2, GL_FLOAT, 0, wtb->inner_v); - glColorPointer(4, GL_UNSIGNED_BYTE, 0, col_array); - glDrawArrays(GL_POLYGON, 0, wtb->totvert); - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); + gpuSingleClientArrays_C4UB_V2F( + GL_TRIANGLE_FAN, + col_array, + 0, + wtb->inner_v, + 0, + 0, + wtb->totvert); glShadeModel(GL_FLAT); } } - + /* for each AA step */ if (wtb->outline) { float quad_strip[WIDGET_SIZE_MAX * 2 + 2][2]; /* + 2 because the last pair is wrapped */ @@ -777,56 +781,83 @@ static void widgetbase_draw(uiWidgetBase *wtb, uiWidgetColors *wcol) widget_verts_to_quad_strip_open(wtb, wtb->halfwayvert, quad_strip_emboss); } - glEnableClientState(GL_VERTEX_ARRAY); + gpuImmediateFormat_C4_V2(); + gpuBegin(GL_QUADS); for (j = 0; j < WIDGET_AA_JITTER; j++) { - glTranslatef(1.0f * jit[j][0], 1.0f * jit[j][1], 0.0f); - + float dx = jit[j][0]; + float dy = jit[j][1]; + int i; + /* outline */ - glColor4ubv(tcol); + gpuColor4ubv(tcol); + for (i = 0; i < 2*wtb->totvert; i += 2) { + gpuVertex2f( + quad_strip[i+0][0] + dx, + quad_strip[i+0][1] + dy); + + gpuVertex2f( + quad_strip[i+1][0] + dx, + quad_strip[i+1][1] + dy); + + gpuVertex2f( + quad_strip[i+3][0] + dx, + quad_strip[i+3][1] + dy); + + gpuVertex2f( + quad_strip[i+2][0] + dx, + quad_strip[i+2][1] + dy); + } - glVertexPointer(2, GL_FLOAT, 0, quad_strip); - glDrawArrays(GL_QUAD_STRIP, 0, wtb->totvert * 2 + 2); - /* emboss bottom shadow */ - if (wtb->emboss) { - glColor4f(1.0f, 1.0f, 1.0f, 0.02f); - - glVertexPointer(2, GL_FLOAT, 0, quad_strip_emboss); - glDrawArrays(GL_QUAD_STRIP, 0, wtb->halfwayvert * 2); + if (0 && wtb->emboss) { + gpuColor4x(CPACK_WHITE, 0.020f); + for (i = 0; i < 2*wtb->halfwayvert - 1; i += 2) { + gpuVertex2f( + quad_strip_emboss[i+0][0] + dx, + quad_strip_emboss[i+0][1] + dy); + + gpuVertex2f( + quad_strip_emboss[i+1][0] + dx, + quad_strip_emboss[i+1][1] + dy); + + gpuVertex2f( + quad_strip_emboss[i+3][0] + dx, + quad_strip_emboss[i+3][1] + dy); + + gpuVertex2f( + quad_strip_emboss[i+2][0] + dx, + quad_strip_emboss[i+2][1] + dy); + } } - - glTranslatef(-1.0f * jit[j][0], -1.0f * jit[j][1], 0.0f); } - glDisableClientState(GL_VERTEX_ARRAY); + gpuEnd(); + gpuImmediateUnformat(); } - + /* decoration */ - if (wtb->tria1.tot || wtb->tria2.tot) { - const unsigned char tcol[4] = {wcol->item[0], - wcol->item[1], - wcol->item[2], - (unsigned char)((float)wcol->item[3] / WIDGET_AA_JITTER)}; - /* for each AA step */ - for (j = 0; j < WIDGET_AA_JITTER; j++) { - glTranslatef(1.0f * jit[j][0], 1.0f * jit[j][1], 0.0f); - if (wtb->tria1.tot) { - glColor4ubv(tcol); - widget_trias_draw(&wtb->tria1); - } - if (wtb->tria2.tot) { - glColor4ubv(tcol); - widget_trias_draw(&wtb->tria2); - } - - glTranslatef(-1.0f * jit[j][0], -1.0f * jit[j][1], 0.0f); - } + gpuImmediateFormat_V2(); + + if (wtb->tria1.tot > 0 || wtb->tria2.tot > 0) { + unsigned char tcol[4]; + tcol[0] = wcol->item[0]; + tcol[1] = wcol->item[1]; + tcol[2] = wcol->item[2]; + tcol[3] = (unsigned char)((float)wcol->item[3] / WIDGET_AA_JITTER); + + gpuCurrentColor4ubv(tcol); + + gpuBegin(GL_TRIANGLES); + widget_trias_append(&wtb->tria1); + widget_trias_append(&wtb->tria2); + gpuEnd(); } + gpuImmediateUnformat(); + glDisable(GL_BLEND); - } /* *********************** text/icon ************************************** */ @@ -1190,8 +1221,8 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b but->drawstr[selend_tmp] = ch; - glColor3ubv((unsigned char *)wcol->item); - glRects(rect->xmin + selsta_draw, rect->ymin + 2, rect->xmin + selwidth_draw, rect->ymax - 2); + gpuCurrentColor3ubv((unsigned char *)wcol->item); + gpuSingleFilledRecti(rect->xmin + selsta_draw, rect->ymin + 2, rect->xmin + selwidth_draw, rect->ymax - 2); } } else { @@ -1207,8 +1238,8 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b but->drawstr[pos] = ch; } - glColor3f(0.20, 0.6, 0.9); - glRects(rect->xmin + t, rect->ymin + 2, rect->xmin + t + 2, rect->ymax - 2); + gpuCurrentColor3f(0.2f, 0.6f, 0.9f); + gpuSingleFilledRecti(rect->xmin + t, rect->ymin + 2, rect->xmin + t + 2, rect->ymax - 2); } } } @@ -1230,7 +1261,7 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b } } - glColor3ubv((unsigned char *)wcol->text); + gpuCurrentColor3ubv((unsigned char *)wcol->text); uiStyleFontDrawExt(fstyle, rect, but->drawstr + but->ofs, &font_xofs, &font_yofs); @@ -1825,23 +1856,28 @@ static void widget_softshadow(rcti *rect, int roundboxalign, float radin, float totvert = round_box_shadow_edges(wtb.inner_v, &rect1, radin, roundboxalign & (UI_CNR_BOTTOM_RIGHT | UI_CNR_BOTTOM_LEFT), 0.0f); /* inverse linear shadow alpha */ - alpha = 0.15; - alphastep = 0.67; - - glEnableClientState(GL_VERTEX_ARRAY); + alpha = 0.15f; + alphastep = 0.67f; + + gpuImmediateFormat_C4_V2(); + gpuBegin(GL_TRIANGLE_STRIP); for (step = 1; step <= radout; step++, alpha *= alphastep) { - round_box_shadow_edges(wtb.outer_v, &rect1, radin, UI_CNR_ALL, (float)step); - - glColor4f(0.0f, 0.0f, 0.0f, alpha); + int i; + const int count = 2 * totvert; + round_box_shadow_edges(wtb.outer_v, &rect1, radin, UI_CNR_ALL, (float)step); widget_verts_to_quad_strip_open(&wtb, totvert, quad_strip); - glVertexPointer(2, GL_FLOAT, 0, quad_strip); - glDrawArrays(GL_QUAD_STRIP, 0, totvert * 2); + gpuColor4x(CPACK_BLACK, alpha); + + for (i = 0; i < count; i++) { + gpuVertex2fv(quad_strip[i]); + } } - glDisableClientState(GL_VERTEX_ARRAY); + gpuEnd(); + gpuImmediateUnformat(); } static void widget_menu_back(uiWidgetColors *wcol, rcti *rect, int flag, int direction) @@ -1875,25 +1911,17 @@ static void widget_menu_back(uiWidgetColors *wcol, rcti *rect, int flag, int dir glDisable(GL_BLEND); } - static void ui_hsv_cursor(float x, float y) { - - glPushMatrix(); - glTranslatef(x, y, 0.0f); - - glColor3f(1.0f, 1.0f, 1.0f); - glutil_draw_filled_arc(0.0f, M_PI * 2.0, 3.0f, 8); - + gpuCurrentColor3x(CPACK_WHITE); + gpuDrawDisk(x, y, 3.0f, 12); + glEnable(GL_BLEND); glEnable(GL_LINE_SMOOTH); - glColor3f(0.0f, 0.0f, 0.0f); - glutil_draw_lined_arc(0.0f, M_PI * 2.0, 3.0f, 12); + gpuCurrentColor3x(CPACK_BLACK); + gpuDrawCircle(x, y, 3.0f, 12); glDisable(GL_BLEND); glDisable(GL_LINE_SMOOTH); - - glPopMatrix(); - } void ui_hsvcircle_vals_from_pos(float *val_rad, float *val_dist, const rcti *rect, @@ -1926,10 +1954,12 @@ static void ui_draw_but_HSVCIRCLE(uiBut *but, uiWidgetColors *wcol, const rcti * float rgb[3], hsvo[3], hsv[3], col[3], colcent[3]; int a; int color_profile = but->block->color_profile; - + + gpuImmediateFormat_C4_V3(); + if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) color_profile = FALSE; - + /* color */ ui_get_but_vectorf(but, rgb); @@ -1944,46 +1974,43 @@ static void ui_draw_but_HSVCIRCLE(uiBut *but, uiWidgetColors *wcol, const rcti * ui_block_to_display_space_v3(but->block, rgb); rgb_to_hsv_compat_v(rgb, hsv); - + /* exception: if 'lock' is set * lock the value of the color wheel to 1. * Useful for color correction tools where you're only interested in hue. */ if (but->flag & UI_BUT_COLOR_LOCK) hsv[2] = 1.f; - + hsv_to_rgb(0.f, 0.f, hsv[2], colcent, colcent + 1, colcent + 2); - + glShadeModel(GL_SMOOTH); - glBegin(GL_TRIANGLE_FAN); - glColor3fv(colcent); - glVertex2f(centx, centy); - + gpuBegin(GL_TRIANGLE_FAN); + gpuColor3fv(colcent); + gpuVertex2f(centx, centy); + for (a = 0; a <= tot; a++, ang += radstep) { float si = sin(ang); float co = cos(ang); - + ui_hsvcircle_vals_from_pos(hsv, hsv + 1, rect, centx + co * radius, centy + si * radius); CLAMP(hsv[2], 0.0f, 1.0f); /* for display only */ hsv_to_rgb_v(hsv, col); - glColor3fv(col); - glVertex2f(centx + co * radius, centy + si * radius); + gpuColor3fv(col); + gpuVertex2f(centx + co * radius, centy + si * radius); } - glEnd(); - + gpuEnd(); + glShadeModel(GL_FLAT); - + /* fully rounded outline */ - glPushMatrix(); - glTranslatef(centx, centy, 0.0f); glEnable(GL_BLEND); glEnable(GL_LINE_SMOOTH); - glColor3ubv((unsigned char *)wcol->outline); - glutil_draw_lined_arc(0.0f, M_PI * 2.0, radius, tot + 1); - glDisable(GL_BLEND); + gpuCurrentColor3ubv((unsigned char *)wcol->outline); + gpuDrawCircle(centx, centy, radius, tot + 1); glDisable(GL_LINE_SMOOTH); - glPopMatrix(); + glDisable(GL_BLEND); /* cursor */ ang = 2.0f * (float)M_PI * hsvo[0] + 0.5f * (float)M_PI; @@ -1995,6 +2022,8 @@ static void ui_draw_but_HSVCIRCLE(uiBut *but, uiWidgetColors *wcol, const rcti * radius = CLAMPIS(cursor_radius, 0.0f, 1.0f) * radius; ui_hsv_cursor(centx + cosf(-ang) * radius, centy + sinf(-ang) * radius); + + gpuImmediateUnformat(); } /* ************ custom buttons, old stuff ************** */ @@ -2004,7 +2033,7 @@ void ui_draw_gradient(rcti *rect, const float hsv[3], const int type, const floa { const float color_step = (type == UI_GRAD_H) ? 0.02f : 0.05f; int a; - float h = hsv[0], s = hsv[1], v = hsv[2]; + const float h = hsv[0], s = hsv[1], v = hsv[2]; float dx, dy, sx1, sx2, sy; float col0[4][3]; /* left half, rect bottom to top */ float col1[4][3]; /* right half, rect bottom to top */ @@ -2116,21 +2145,21 @@ void ui_draw_gradient(rcti *rect, const float hsv[3], const int type, const floa sy = rect->ymin; dy = (float)BLI_rcti_size_y(rect) / 3.0f; - glBegin(GL_QUADS); + gpuBegin(GL_QUADS); for (a = 0; a < 3; a++, sy += dy) { - glColor4f(col0[a][0], col0[a][1], col0[a][2], alpha); - glVertex2f(sx1, sy); + gpuColor4f(col0[a][0], col0[a][1], col0[a][2], alpha); + gpuVertex2f(sx1, sy); - glColor4f(col1[a][0], col1[a][1], col1[a][2], alpha); - glVertex2f(sx2, sy); + gpuColor4f(col1[a][0], col1[a][1], col1[a][2], alpha); + gpuVertex2f(sx2, sy); - glColor4f(col1[a + 1][0], col1[a + 1][1], col1[a + 1][2], alpha); - glVertex2f(sx2, sy + dy); + gpuColor4f(col1[a + 1][0], col1[a + 1][1], col1[a + 1][2], alpha); + gpuVertex2f(sx2, sy + dy); - glColor4f(col0[a + 1][0], col0[a + 1][1], col0[a + 1][2], alpha); - glVertex2f(sx1, sy + dy); + gpuColor4f(col0[a + 1][0], col0[a + 1][1], col0[a + 1][2], alpha); + gpuVertex2f(sx1, sy + dy); } - glEnd(); + gpuEnd(); } glShadeModel(GL_FLAT); @@ -2145,14 +2174,16 @@ static void ui_draw_but_HSVCUBE(uiBut *but, rcti *rect) float x = 0.0f, y = 0.0f; float *hsv = ui_block_hsv_get(but->block); float hsv_n[3]; - + + gpuImmediateFormat_C4_V3(); + copy_v3_v3(hsv_n, hsv); - + ui_get_but_vectorf(but, rgb); rgb_to_hsv_compat_v(rgb, hsv_n); - + ui_draw_gradient(rect, hsv_n, but->a1, 1.0f); - + switch ((int)but->a1) { case UI_GRAD_SV: x = hsv_n[2]; y = hsv_n[1]; break; @@ -2167,18 +2198,20 @@ static void ui_draw_but_HSVCUBE(uiBut *but, rcti *rect) case UI_GRAD_V: x = hsv_n[2]; y = 0.5; break; } - + /* cursor */ x = rect->xmin + x * BLI_rcti_size_x(rect); y = rect->ymin + y * BLI_rcti_size_y(rect); CLAMP(x, rect->xmin + 3.0f, rect->xmax - 3.0f); CLAMP(y, rect->ymin + 3.0f, rect->ymax - 3.0f); - + ui_hsv_cursor(x, y); - + /* outline */ - glColor3ub(0, 0, 0); - fdrawbox((rect->xmin), (rect->ymin), (rect->xmax), (rect->ymax)); + gpuCurrentColor3x(CPACK_BLACK); + gpuDrawWireRectf((rect->xmin), (rect->ymin), (rect->xmax), (rect->ymax)); + + gpuImmediateUnformat(); } /* vertical 'value' slider, using new widget code */ @@ -2189,7 +2222,7 @@ static void ui_draw_but_HSV_v(uiBut *but, rcti *rect) float x, y; float rgb[3], hsv[3], v, range; int color_profile = but->block->color_profile; - + if (but->rnaprop && RNA_property_subtype(but->rnaprop) == PROP_COLOR_GAMMA) color_profile = FALSE; @@ -2204,12 +2237,12 @@ static void ui_draw_but_HSV_v(uiBut *but, rcti *rect) /* map v from property range to [0,1] */ range = but->softmax - but->softmin; v = (v - but->softmin) / range; - + widget_init(&wtb); - + /* fully rounded */ round_box_edges(&wtb, UI_CNR_ALL, rect, rad); - + /* setup temp colors */ wcol_tmp.outline[0] = wcol_tmp.outline[1] = wcol_tmp.outline[2] = 0; wcol_tmp.inner[0] = wcol_tmp.inner[1] = wcol_tmp.inner[2] = 128; @@ -2223,9 +2256,10 @@ static void ui_draw_but_HSV_v(uiBut *but, rcti *rect) x = rect->xmin + 0.5f * BLI_rcti_size_x(rect); y = rect->ymin + v * BLI_rcti_size_y(rect); CLAMP(y, rect->ymin + 3.0f, rect->ymax - 3.0f); - + + gpuImmediateFormat_C4_V3(); ui_hsv_cursor(x, y); - + gpuImmediateUnformat(); } @@ -2234,15 +2268,15 @@ static void ui_draw_separator(rcti *rect, uiWidgetColors *wcol) { int y = rect->ymin + BLI_rcti_size_y(rect) / 2 - 1; unsigned char col[4]; - + col[0] = wcol->text[0]; col[1] = wcol->text[1]; col[2] = wcol->text[2]; col[3] = 7; - + glEnable(GL_BLEND); - glColor4ubv(col); - sdrawline(rect->xmin, y, rect->xmax, y); + gpuCurrentColor4ubv(col); + gpuSingleLinei(rect->xmin, y, rect->xmax, y); // DOODLE: single line glDisable(GL_BLEND); } @@ -2302,22 +2336,13 @@ int ui_link_bezier_points(rcti *rect, float coord_array[][2], int resol) void ui_draw_link_bezier(rcti *rect) { float coord_array[LINK_RESOL + 1][2]; - - if (ui_link_bezier_points(rect, coord_array, LINK_RESOL)) { - /* we can reuse the dist variable here to increment the GL curve eval amount*/ - // const float dist = 1.0f / (float)LINK_RESOL; // UNUSED + if (ui_link_bezier_points(rect, coord_array, LINK_RESOL)) { glEnable(GL_BLEND); glEnable(GL_LINE_SMOOTH); - - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(2, GL_FLOAT, 0, coord_array); - glDrawArrays(GL_LINE_STRIP, 0, LINK_RESOL); - glDisableClientState(GL_VERTEX_ARRAY); - - glDisable(GL_BLEND); + gpuSingleClientArrays_V2F(GL_LINE_STRIP, coord_array, 0, 0, LINK_RESOL); glDisable(GL_LINE_SMOOTH); - + glDisable(GL_BLEND); } } @@ -2820,7 +2845,7 @@ static void widget_box(uiBut *but, uiWidgetColors *wcol, rcti *rect, int UNUSED( /* store the box bg as gl clearcolor, to retrieve later when drawing semi-transparent rects * over the top to indicate disabled buttons */ /* XXX, this doesnt work right since the color applies to buttons outside the box too. */ - glClearColor(wcol->inner[0] / 255.0, wcol->inner[1] / 255.0, wcol->inner[2] / 255.0, 1.0); + gpuSetClearColor(wcol->inner[0] / 255.0, wcol->inner[1] / 255.0, wcol->inner[2] / 255.0, 1.0); copy_v3_v3_char(wcol->inner, old_col); } @@ -2867,7 +2892,7 @@ static void widget_draw_extra_mask(const bContext *C, uiBut *but, uiWidgetType * /* make mask to draw over image */ UI_GetThemeColor3ubv(TH_BACK, col); - glColor3ubv(col); + gpuCurrentColor3ubv(col); round_box__edges(&wtb, UI_CNR_ALL, rect, 0.0f, 4.0); widgetbase_outline(&wtb); @@ -2889,12 +2914,12 @@ static void widget_disabled(rcti *rect) glEnable(GL_BLEND); /* can't use theme TH_BACK or TH_PANEL... undefined */ - glGetFloatv(GL_COLOR_CLEAR_VALUE, col); - glColor4f(col[0], col[1], col[2], 0.5f); + gpuGetClearColor(col); + gpuCurrentColor4f(col[0], col[1], col[2], 0.5f); /* need -1 and +1 to make it work right for aligned buttons, * but problem may be somewhere else? */ - glRectf(rect->xmin - 1, rect->ymin - 1, rect->xmax, rect->ymax + 1); + gpuSingleFilledRectf(rect->xmin - 1, rect->ymin - 1, rect->xmax, rect->ymax + 1); glDisable(GL_BLEND); } @@ -3345,12 +3370,12 @@ void ui_draw_menu_back(uiStyle *UNUSED(style), uiBlock *block, rcti *rect) if (block) { if (block->flag & UI_BLOCK_CLIPTOP) { /* XXX no scaling for UI here yet */ - glColor3ubv((unsigned char *)wt->wcol.text); + gpuCurrentColor3ubv((unsigned char *)wt->wcol.text); UI_DrawTriIcon(BLI_rcti_cent_x(rect), rect->ymax - 8, 't'); } if (block->flag & UI_BLOCK_CLIPBOTTOM) { /* XXX no scaling for UI here yet */ - glColor3ubv((unsigned char *)wt->wcol.text); + gpuCurrentColor3ubv((unsigned char *)wt->wcol.text); UI_DrawTriIcon(BLI_rcti_cent_x(rect), rect->ymin + 10, 'v'); } } @@ -3412,7 +3437,7 @@ void ui_draw_menu_item(uiFontStyle *fstyle, rcti *rect, const char *name, int ic rect->xmax -= BLF_width(fstyle->uifont_id, cpoin + 1) + 10; } - glColor3ubv((unsigned char *)wt->wcol.text); + gpuCurrentColor3ubv((unsigned char *)wt->wcol.text); uiStyleFontDraw(fstyle, rect, name); /* part text right aligned */ @@ -3467,15 +3492,15 @@ void ui_draw_preview_item(uiFontStyle *fstyle, rcti *rect, const char *name, int bg_rect.xmax = rect->xmax - PREVIEW_PAD; UI_GetThemeColor3ubv(TH_BUTBACK, bg_col); - glColor4ubv((unsigned char *)wt->wcol.item); + gpuCurrentColor4ubv((unsigned char *)wt->wcol.item); glEnable(GL_BLEND); - glRecti(bg_rect.xmin, bg_rect.ymin, bg_rect.xmax, bg_rect.ymax); + gpuSingleFilledRecti(bg_rect.xmin, bg_rect.ymin, bg_rect.xmax, bg_rect.ymax); glDisable(GL_BLEND); if (state == UI_ACTIVE) - glColor3ubv((unsigned char *)wt->wcol.text); + gpuCurrentColor3ubv((unsigned char *)wt->wcol.text); else - glColor3ubv((unsigned char *)wt->wcol.text_sel); + gpuCurrentColor3ubv((unsigned char *)wt->wcol.text_sel); uiStyleFontDraw(fstyle, &trect, name); } diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c index fa5d5806bb8..a845ed27d0d 100644 --- a/source/blender/editors/interface/resources.c +++ b/source/blender/editors/interface/resources.c @@ -51,13 +51,14 @@ #include "BKE_texture.h" -#include "BIF_gl.h" #include "UI_interface.h" #include "UI_interface_icons.h" #include "interface_intern.h" +#include "GPU_compatibility.h" + /* global for themes */ typedef void (*VectorDrawFunc)(int x, int y, int w, int h, float alpha); @@ -968,8 +969,15 @@ void UI_ThemeColor(int colorid) const unsigned char *cp; cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid); - glColor3ubv(cp); + gpuCurrentColor3ubv(cp); +} +void UI_ThemeAppendColor(int colorid) +{ + const unsigned char *cp; + + cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid); + gpuColor3ubv(cp); } /* plus alpha */ @@ -978,8 +986,7 @@ void UI_ThemeColor4(int colorid) const unsigned char *cp; cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid); - glColor4ubv(cp); - + gpuCurrentColor4ubv(cp); } /* set the color with offset for shades */ @@ -987,17 +994,41 @@ void UI_ThemeColorShade(int colorid, int offset) { int r, g, b; const unsigned char *cp; - + cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid); + r = offset + (int) cp[0]; CLAMP(r, 0, 255); + g = offset + (int) cp[1]; CLAMP(g, 0, 255); + b = offset + (int) cp[2]; CLAMP(b, 0, 255); - //glColor3ub(r, g, b); - glColor4ub(r, g, b, cp[3]); + + gpuCurrentColor4ub(r, g, b, cp[3]); } + +// set the color with offset for shades +void UI_ThemeAppendColorShade(int colorid, int offset) +{ + int r, g, b; + const unsigned char *cp; + + cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid); + + r = offset + (int) cp[0]; + CLAMP(r, 0, 255); + + g = offset + (int) cp[1]; + CLAMP(g, 0, 255); + + b = offset + (int) cp[2]; + CLAMP(b, 0, 255); + + gpuColor4ub(r, g, b, cp[3]); +} + void UI_ThemeColorShadeAlpha(int colorid, int coloffset, int alphaoffset) { int r, g, b, a; @@ -1012,7 +1043,24 @@ void UI_ThemeColorShadeAlpha(int colorid, int coloffset, int alphaoffset) CLAMP(b, 0, 255); a = alphaoffset + (int) cp[3]; CLAMP(a, 0, 255); - glColor4ub(r, g, b, a); + gpuCurrentColor4ub(r, g, b, a); +} + +void UI_ThemeAppendColorShadeAlpha(int colorid, int coloffset, int alphaoffset) +{ + int r, g, b, a; + const unsigned char *cp; + + cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid); + r = coloffset + (int) cp[0]; + CLAMP(r, 0, 255); + g = coloffset + (int) cp[1]; + CLAMP(g, 0, 255); + b = coloffset + (int) cp[2]; + CLAMP(b, 0, 255); + a = alphaoffset + (int) cp[3]; + CLAMP(a, 0, 255); + gpuColor4ub(r, g, b, a); } /* blend between to theme colors, and set it */ @@ -1029,7 +1077,23 @@ void UI_ThemeColorBlend(int colorid1, int colorid2, float fac) g = floorf((1.0f - fac) * cp1[1] + fac * cp2[1]); b = floorf((1.0f - fac) * cp1[2] + fac * cp2[2]); - glColor3ub(r, g, b); + gpuCurrentColor3ub(r, g, b); +} + +void UI_ThemeAppendColorBlend(int colorid1, int colorid2, float fac) +{ + int r, g, b; + const unsigned char *cp1, *cp2; + + cp1 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1); + cp2 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2); + + CLAMP(fac, 0.0f, 1.0f); + r = floorf((1.0f - fac) * cp1[0] + fac * cp2[0]); + g = floorf((1.0f - fac) * cp1[1] + fac * cp2[1]); + b = floorf((1.0f - fac) * cp1[2] + fac * cp2[2]); + + gpuColor3ub(r, g, b); } /* blend between to theme colors, shade it, and set it */ @@ -1037,7 +1101,7 @@ void UI_ThemeColorBlendShade(int colorid1, int colorid2, float fac, int offset) { int r, g, b; const unsigned char *cp1, *cp2; - + cp1 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1); cp2 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2); @@ -1045,12 +1109,33 @@ void UI_ThemeColorBlendShade(int colorid1, int colorid2, float fac, int offset) r = offset + floorf((1.0f - fac) * cp1[0] + fac * cp2[0]); g = offset + floorf((1.0f - fac) * cp1[1] + fac * cp2[1]); b = offset + floorf((1.0f - fac) * cp1[2] + fac * cp2[2]); - + CLAMP(r, 0, 255); CLAMP(g, 0, 255); CLAMP(b, 0, 255); - - glColor3ub(r, g, b); + + gpuCurrentColor3ub(r, g, b); +} + +// blend between to theme colors, shade it, and set it +void UI_ThemeAppendColorBlendShade(int colorid1, int colorid2, float fac, int offset) +{ + int r, g, b; + const unsigned char *cp1, *cp2; + + cp1 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1); + cp2 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2); + + CLAMP(fac, 0.0f, 1.0f); + r = offset + floorf((1.0f - fac) * cp1[0] + fac * cp2[0]); + g = offset + floorf((1.0f - fac) * cp1[1] + fac * cp2[1]); + b = offset + floorf((1.0f - fac) * cp1[2] + fac * cp2[2]); + + CLAMP(r, 0, 255); + CLAMP(g, 0, 255); + CLAMP(b, 0, 255); + + gpuColor3ub(r, g, b); } /* blend between to theme colors, shade it, and set it */ @@ -1073,7 +1158,7 @@ void UI_ThemeColorBlendShadeAlpha(int colorid1, int colorid2, float fac, int off CLAMP(b, 0, 255); CLAMP(a, 0, 255); - glColor4ub(r, g, b, a); + gpuCurrentColor4ub(r, g, b, a); } @@ -1204,7 +1289,7 @@ void UI_ColorPtrBlendShade3ubv(const unsigned char cp1[3], const unsigned char c g = g < 0 ? 0 : (g > 255 ? 255 : g); b = b < 0 ? 0 : (b > 255 ? 255 : b); - glColor3ub(r, g, b); + gpuCurrentColor3ub(r, g, b); } void UI_GetColorPtrShade3ubv(const unsigned char cp[3], unsigned char col[3], int offset) @@ -1247,9 +1332,8 @@ void UI_GetColorPtrBlendShade3ubv(const unsigned char cp1[3], const unsigned cha void UI_ThemeClearColor(int colorid) { float col[3]; - UI_GetThemeColor3fv(colorid, col); - glClearColor(col[0], col[1], col[2], 0.0); + gpuSetClearColorvf(col, 0.0); } void UI_make_axis_color(const unsigned char src_col[3], unsigned char dst_col[3], const char axis) diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c index f1a3f59bc22..b022d4121f4 100644 --- a/source/blender/editors/interface/view2d.c +++ b/source/blender/editors/interface/view2d.c @@ -48,7 +48,7 @@ #include "WM_api.h" -#include "BIF_gl.h" +#include "GPU_primitives.h" #include "BLF_api.h" @@ -1013,7 +1013,7 @@ void UI_view2d_view_ortho(View2D *v2d) wmOrtho2(curmasked.xmin - xofs, curmasked.xmax - xofs, curmasked.ymin - yofs, curmasked.ymax - yofs); /* XXX is this necessary? */ - glLoadIdentity(); + gpuLoadIdentity(); } /* Set view matrices to only use one axis of 'cur' only @@ -1041,7 +1041,7 @@ void UI_view2d_view_orthoSpecial(ARegion *ar, View2D *v2d, short xaxis) wmOrtho2(-xofs, ar->winx - xofs, curmasked.ymin - yofs, curmasked.ymax - yofs); /* XXX is this necessary? */ - glLoadIdentity(); + gpuLoadIdentity(); } @@ -1053,7 +1053,7 @@ void UI_view2d_view_restore(const bContext *C) int height = BLI_rcti_size_y(&ar->winrct) + 1; wmOrtho2(0.0f, (float)width, 0.0f, (float)height); - glLoadIdentity(); + gpuLoadIdentity(); // ED_region_pixelspace(CTX_wm_region(C)); } @@ -1199,42 +1199,43 @@ void UI_view2d_grid_draw(View2D *v2d, View2DGrid *grid, int flag) { float vec1[2], vec2[2]; int a, step; - + /* check for grid first, as it may not exist */ - if (grid == NULL) + if (grid == NULL) { return; - + } + + gpuImmediateFormat_C4_V2(); // DOODLE: 2D grid, multiple colored lines + gpuBegin(GL_LINES); + /* vertical lines */ if (flag & V2D_VERTICAL_LINES) { /* initialize initial settings */ vec1[0] = vec2[0] = grid->startx; vec1[1] = grid->starty; vec2[1] = v2d->cur.ymax; - + /* minor gridlines */ step = (BLI_rcti_size_x(&v2d->mask) + 1) / U.v2d_min_gridsize; - UI_ThemeColor(TH_GRID); - + + UI_ThemeAppendColor(TH_GRID); + for (a = 0; a < step; a++) { - glBegin(GL_LINE_STRIP); - glVertex2fv(vec1); - glVertex2fv(vec2); - glEnd(); - + gpuVertex2fv(vec1); + gpuVertex2fv(vec2); + vec2[0] = vec1[0] += grid->dx; } - + /* major gridlines */ vec2[0] = vec1[0] -= 0.5f * grid->dx; - UI_ThemeColorShade(TH_GRID, 16); - + UI_ThemeAppendColorShade(TH_GRID, 16); + step++; for (a = 0; a <= step; a++) { - glBegin(GL_LINE_STRIP); - glVertex2fv(vec1); - glVertex2fv(vec2); - glEnd(); - + gpuVertex2fv(vec1); + gpuVertex2fv(vec2); + vec2[0] = vec1[0] -= grid->dx; } } @@ -1245,16 +1246,14 @@ void UI_view2d_grid_draw(View2D *v2d, View2DGrid *grid, int flag) vec1[1] = vec2[1] = grid->starty; vec1[0] = grid->startx; vec2[0] = v2d->cur.xmax; - + step = (BLI_rcti_size_y(&v2d->mask) + 1) / U.v2d_min_gridsize; - - UI_ThemeColor(TH_GRID); + + UI_ThemeAppendColor(TH_GRID); for (a = 0; a <= step; a++) { - glBegin(GL_LINE_STRIP); - glVertex2fv(vec1); - glVertex2fv(vec2); - glEnd(); - + gpuVertex2fv(vec1); + gpuVertex2fv(vec2); + vec2[1] = vec1[1] += grid->dy; } @@ -1263,44 +1262,41 @@ void UI_view2d_grid_draw(View2D *v2d, View2DGrid *grid, int flag) step++; if (flag & V2D_HORIZONTAL_FINELINES) { - UI_ThemeColorShade(TH_GRID, 16); + UI_ThemeAppendColorShade(TH_GRID, 16); for (a = 0; a < step; a++) { - glBegin(GL_LINE_STRIP); - glVertex2fv(vec1); - glVertex2fv(vec2); - glEnd(); + gpuVertex2fv(vec1); + gpuVertex2fv(vec2); vec2[1] = vec1[1] -= grid->dy; } } } - + /* Axes are drawn as darker lines */ - UI_ThemeColorShade(TH_GRID, -50); - + UI_ThemeAppendColorShade(TH_GRID, -50); + /* horizontal axis */ if (flag & V2D_HORIZONTAL_AXIS) { vec1[0] = v2d->cur.xmin; vec2[0] = v2d->cur.xmax; vec1[1] = vec2[1] = 0.0f; - - glBegin(GL_LINE_STRIP); - glVertex2fv(vec1); - glVertex2fv(vec2); - glEnd(); + + gpuVertex2fv(vec1); + gpuVertex2fv(vec2); } - + /* vertical axis */ if (flag & V2D_VERTICAL_AXIS) { vec1[1] = v2d->cur.ymin; vec2[1] = v2d->cur.ymax; vec1[0] = vec2[0] = 0.0f; - - glBegin(GL_LINE_STRIP); - glVertex2fv(vec1); - glVertex2fv(vec2); - glEnd(); + + gpuVertex2fv(vec1); + gpuVertex2fv(vec2); } + + gpuEnd(); + gpuImmediateUnformat(); } /* Draw a constant grid in given 2d-region */ @@ -1308,30 +1304,33 @@ void UI_view2d_constant_grid_draw(View2D *v2d) { float start, step = 25.0f; - UI_ThemeColorShade(TH_BACK, -10); - + gpuImmediateFormat_C4_V2(); // DOODLE: 2D constant grid, multiple colored lines + gpuBegin(GL_LINES); + start = v2d->cur.xmin - (float)fmod(v2d->cur.xmin, step); - glBegin(GL_LINES); + UI_ThemeAppendColorShade(TH_BACK, -10); + for (; start < v2d->cur.xmax; start += step) { - glVertex2f(start, v2d->cur.ymin); - glVertex2f(start, v2d->cur.ymax); + gpuVertex2f(start, v2d->cur.ymin); + gpuVertex2f(start, v2d->cur.ymax); } start = v2d->cur.ymin - (float)fmod(v2d->cur.ymin, step); for (; start < v2d->cur.ymax; start += step) { - glVertex2f(v2d->cur.xmin, start); - glVertex2f(v2d->cur.xmax, start); + gpuVertex2f(v2d->cur.xmin, start); + gpuVertex2f(v2d->cur.xmax, start); } - + /* X and Y axis */ - UI_ThemeColorShade(TH_BACK, -18); - glVertex2f(0.0f, v2d->cur.ymin); - glVertex2f(0.0f, v2d->cur.ymax); - glVertex2f(v2d->cur.xmin, 0.0f); - glVertex2f(v2d->cur.xmax, 0.0f); - - glEnd(); + UI_ThemeAppendColorShade(TH_BACK, -18); + gpuVertex2f(0.0f, v2d->cur.ymin); + gpuVertex2f(0.0f, v2d->cur.ymax); + gpuVertex2f(v2d->cur.xmin, 0.0f); + gpuVertex2f(v2d->cur.xmax, 0.0f); + + gpuEnd(); + gpuImmediateUnformat(); } /* Draw a multi-level grid in given 2d-region */ @@ -1340,46 +1339,51 @@ void UI_view2d_multi_grid_draw(View2D *v2d, float step, int level_size, int totl int offset = -10; float lstep = step; int level; - + + gpuImmediateFormat_V2(); + for (level = 0; level < totlevels; ++level) { int i; float start; - + UI_ThemeColorShade(TH_BACK, offset); i = (v2d->cur.xmin >= 0.0f ? -(int)(-v2d->cur.xmin / lstep) : (int)(v2d->cur.xmin / lstep)); start = i * lstep; - - glBegin(GL_LINES); + + gpuBegin(GL_LINES); + for (; start < v2d->cur.xmax; start += lstep, ++i) { if (i == 0 || (level < totlevels - 1 && i % level_size == 0)) continue; - glVertex2f(start, v2d->cur.ymin); - glVertex2f(start, v2d->cur.ymax); + gpuVertex2f(start, v2d->cur.ymin); + gpuVertex2f(start, v2d->cur.ymax); } - + i = (v2d->cur.ymin >= 0.0f ? -(int)(-v2d->cur.ymin / lstep) : (int)(v2d->cur.ymin / lstep)); start = i * lstep; for (; start < v2d->cur.ymax; start += lstep, ++i) { if (i == 0 || (level < totlevels - 1 && i % level_size == 0)) continue; - glVertex2f(v2d->cur.xmin, start); - glVertex2f(v2d->cur.xmax, start); + gpuVertex2f(v2d->cur.xmin, start); + gpuVertex2f(v2d->cur.xmax, start); } - + /* X and Y axis */ - UI_ThemeColorShade(TH_BACK, offset - 8); - glVertex2f(0.0f, v2d->cur.ymin); - glVertex2f(0.0f, v2d->cur.ymax); - glVertex2f(v2d->cur.xmin, 0.0f); - glVertex2f(v2d->cur.xmax, 0.0f); - - glEnd(); - + UI_ThemeAppendColorShade(TH_BACK, offset - 8); + gpuVertex2f(0.0f, v2d->cur.ymin); + gpuVertex2f(0.0f, v2d->cur.ymax); + gpuVertex2f(v2d->cur.xmin, 0.0f); + gpuVertex2f(v2d->cur.xmax, 0.0f); + + gpuEnd(); + lstep *= level_size; offset -= 6; } + + gpuImmediateUnformat(); } /* the price we pay for not exposting structs :( */ @@ -1644,7 +1648,7 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v } UI_ThemeColor(TH_BACK); - glRecti(v2d->hor.xmin, v2d->hor.ymin, v2d->hor.xmax, v2d->hor.ymax); + gpuSingleFilledRecti(v2d->hor.xmin, v2d->hor.ymin, v2d->hor.xmax, v2d->hor.ymax); uiWidgetScrollDraw(&wcol, &hor, &slider, state); } @@ -1755,7 +1759,7 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v } UI_ThemeColor(TH_BACK); - glRecti(v2d->vert.xmin, v2d->vert.ymin, v2d->vert.xmax, v2d->vert.ymax); + gpuSingleFilledRecti(v2d->vert.xmin, v2d->vert.ymin, v2d->vert.xmax, v2d->vert.ymax); uiWidgetScrollDraw(&wcol, &vert, &slider, state); } @@ -2141,10 +2145,10 @@ void UI_view2d_text_cache_draw(ARegion *ar) /* investigate using BLF_ascender() */ const float default_height = strings.first ? BLF_height_default("28") : 0.0f; - // glMatrixMode(GL_PROJECTION); - // glPushMatrix(); - // glMatrixMode(GL_MODELVIEW); - // glPushMatrix(); + // gpuMatrixMode(GL_PROJECTION); + // gpuPushMatrix(); + // gpuMatrixMode(GL_MODELVIEW); + // gpuPushMatrix(); ED_region_pixelspace(ar); for (v2s = strings.first; v2s; v2s = v2s->next) { @@ -2155,7 +2159,7 @@ void UI_view2d_text_cache_draw(ARegion *ar) if (yofs < 1) yofs = 1; if (col_pack_prev != v2s->col.pack) { - glColor3ubv(v2s->col.ub); + gpuCurrentColor3ubv(v2s->col.ub); col_pack_prev = v2s->col.pack; } @@ -2169,10 +2173,10 @@ void UI_view2d_text_cache_draw(ARegion *ar) } } - // glMatrixMode(GL_PROJECTION); - // glPopMatrix(); - // glMatrixMode(GL_MODELVIEW); - // glPopMatrix(); + // gpuMatrixMode(GL_PROJECTION); + // gpuPopMatrix(); + // gpuMatrixMode(GL_MODELVIEW); + // gpuPopMatrix(); if (strings.first) BLI_freelistN(&strings); |