Merge branch 'master' into blender2.8
authorCampbell Barton <ideasman42@gmail.com>
Wed, 12 Sep 2018 06:21:00 +0000 (16:21 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 12 Sep 2018 06:21:00 +0000 (16:21 +1000)
1  2 
source/blender/editors/interface/interface_widgets.c
source/blender/makesdna/DNA_userdef_types.h

index e81af2755b15567e533155df241cd2e46b0637b1,a655dea921568855721ebbcf75502542ff70e0dc..a8f5d5e7977d164b331fdee6b8a0ac569340539a
@@@ -1030,210 -674,180 +1030,219 @@@ static void widgetbase_outline(uiWidget
        float triangle_strip[WIDGET_SIZE_MAX * 2 + 2][2]; /* + 2 because the last pair is wrapped */
        widget_verts_to_triangle_strip(wtb, wtb->totvert, triangle_strip);
  
 -      glEnableClientState(GL_VERTEX_ARRAY);
 -      glVertexPointer(2, GL_FLOAT, 0, triangle_strip);
 -      glDrawArrays(GL_TRIANGLE_STRIP, 0, wtb->totvert * 2 + 2);
 -      glDisableClientState(GL_VERTEX_ARRAY);
 +      widget_draw_vertex_buffer(pos, 0, GL_TRIANGLE_STRIP, triangle_strip, NULL, wtb->totvert * 2 + 2);
  }
  
 -static void widgetbase_draw_ex(
 -        uiWidgetBase *wtb, uiWidgetColors *wcol,
 -        const bool show_alpha_checkers)
 +static void widgetbase_set_uniform_alpha_discard(
 +        uiWidgetBase *wtb,
 +        const bool alpha_check,
 +        const float discard_factor)
  {
 -      int j, a;
 +      if (alpha_check) {
 +              wtb->uniform_params.alpha_discard = -discard_factor;
 +      }
 +      else {
 +              wtb->uniform_params.alpha_discard = discard_factor;
 +      }
 +}
  
 -      glEnable(GL_BLEND);
 +static void widgetbase_set_uniform_alpha_check(
 +        uiWidgetBase *wtb,
 +        const bool alpha_check)
 +{
 +      const float discard_factor = fabs(wtb->uniform_params.alpha_discard);
 +      widgetbase_set_uniform_alpha_discard(wtb, alpha_check, discard_factor);
 +}
  
 -      /* backdrop non AA */
 -      if (wtb->draw_inner) {
 -              BLI_assert(wtb->totvert != 0);
 -              if (wcol->shaded == 0) {
 -                      if (show_alpha_checkers) {
 -                              float inner_v_half[WIDGET_SIZE_MAX][2];
 -                              float x_mid = 0.0f; /* used for dumb clamping of values */
 +static void widgetbase_set_uniform_discard_factor(
 +        uiWidgetBase *wtb,
 +        const float discard_factor)
 +{
 +      bool alpha_check = wtb->uniform_params.alpha_discard < 0.0f;
 +      widgetbase_set_uniform_alpha_discard(wtb, alpha_check, discard_factor);
 +}
  
 -                              /* dark checkers */
 -                              glColor4ub(UI_ALPHA_CHECKER_DARK, UI_ALPHA_CHECKER_DARK, UI_ALPHA_CHECKER_DARK, 255);
 -                              glEnableClientState(GL_VERTEX_ARRAY);
 -                              glVertexPointer(2, GL_FLOAT, 0, wtb->inner_v);
 -                              glDrawArrays(GL_POLYGON, 0, wtb->totvert);
 +static void widgetbase_set_uniform_colors_ubv(
 +        uiWidgetBase *wtb,
 +        const unsigned char *col1, const unsigned char *col2,
 +        const unsigned char *outline,
 +        const unsigned char *emboss,
 +        const unsigned char *tria,
 +        const bool alpha_check)
 +{
 +      widgetbase_set_uniform_alpha_check(wtb, alpha_check);
 +      rgba_float_args_set_ch(wtb->uniform_params.color_inner1, col1[0], col1[1], col1[2], col1[3]);
 +      rgba_float_args_set_ch(wtb->uniform_params.color_inner2, col2[0], col2[1], col2[2], col2[3]);
 +      rgba_float_args_set_ch(wtb->uniform_params.color_outline, outline[0], outline[1], outline[2], outline[3]);
 +      rgba_float_args_set_ch(wtb->uniform_params.color_emboss, emboss[0], emboss[1], emboss[2], emboss[3]);
 +      rgba_float_args_set_ch(wtb->uniform_params.color_tria, tria[0], tria[1], tria[2], tria[3]);
 +}
  
 -                              /* light checkers */
 -                              GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
 -                              glColor4ub(UI_ALPHA_CHECKER_LIGHT, UI_ALPHA_CHECKER_LIGHT, UI_ALPHA_CHECKER_LIGHT, 255);
 -                              GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_CHECKER_8PX);
 +/* keep in sync with shader */
 +#define MAX_WIDGET_BASE_BATCH 6
 +#define MAX_WIDGET_PARAMETERS 11
  
 -                              glVertexPointer(2, GL_FLOAT, 0, wtb->inner_v);
 -                              glDrawArrays(GL_POLYGON, 0, wtb->totvert);
 +static struct {
 +      GPUBatch *batch; /* Batch type */
 +      uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH];
 +      int count;
 +      bool enabled;
 +} g_widget_base_batch = {0};
  
 -                              GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
 +void UI_widgetbase_draw_cache_flush(void)
 +{
 +      float checker_params[3] = {UI_ALPHA_CHECKER_DARK / 255.0f, UI_ALPHA_CHECKER_LIGHT / 255.0f, 8.0f};
  
 -                              /* alpha fill */
 -                              glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 +      if (g_widget_base_batch.count == 0)
 +              return;
  
 -                              glColor4ubv((unsigned char *)wcol->inner);
 +      GPUBatch *batch = g_widget_base_batch.batch;
 +      if (g_widget_base_batch.count == 1) {
 +              /* draw single */
 +              GPU_batch_program_set_builtin(batch, GPU_SHADER_2D_WIDGET_BASE);
 +              GPU_batch_uniform_4fv_array(batch, "parameters", MAX_WIDGET_PARAMETERS, (float *)g_widget_base_batch.params);
 +              GPU_batch_uniform_3fv(batch, "checkerColorAndSize", checker_params);
 +              GPU_batch_draw(batch);
 +      }
 +      else {
 +              GPU_batch_program_set_builtin(batch, GPU_SHADER_2D_WIDGET_BASE_INST);
 +              GPU_batch_uniform_4fv_array(batch, "parameters", MAX_WIDGET_PARAMETERS * MAX_WIDGET_BASE_BATCH,
 +                                          (float *)g_widget_base_batch.params);
 +              GPU_batch_uniform_3fv(batch, "checkerColorAndSize", checker_params);
 +              GPU_matrix_bind(batch->interface);
 +              GPU_batch_draw_range_ex(batch, 0, g_widget_base_batch.count, true);
 +              GPU_batch_program_use_end(batch);
 +      }
 +      g_widget_base_batch.count = 0;
 +}
  
 -                              for (a = 0; a < wtb->totvert; a++) {
 -                                      x_mid += wtb->inner_v[a][0];
 -                              }
 -                              x_mid /= wtb->totvert;
 +void UI_widgetbase_draw_cache_begin(void)
 +{
 +      BLI_assert(g_widget_base_batch.enabled == false);
 +      g_widget_base_batch.enabled = true;
 +}
  
 -                              glVertexPointer(2, GL_FLOAT, 0, wtb->inner_v);
 -                              glDrawArrays(GL_POLYGON, 0, wtb->totvert);
 +void UI_widgetbase_draw_cache_end(void)
 +{
 +      BLI_assert(g_widget_base_batch.enabled == true);
 +      g_widget_base_batch.enabled = false;
  
 -                              /* 1/2 solid color */
 -                              glColor4ub(wcol->inner[0], wcol->inner[1], wcol->inner[2], 255);
 +      GPU_blend(true);
  
 -                              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];
 -                              }
 +      UI_widgetbase_draw_cache_flush();
  
 -                              glVertexPointer(2, GL_FLOAT, 0, inner_v_half);
 -                              glDrawArrays(GL_POLYGON, 0, wtb->totvert);
 -                              glDisableClientState(GL_VERTEX_ARRAY);
 -                      }
 -                      else {
 -                              /* simple fill */
 -                              glColor4ubv((unsigned char *)wcol->inner);
 +      GPU_blend(false);
 +}
  
 -                              glEnableClientState(GL_VERTEX_ARRAY);
 -                              glVertexPointer(2, GL_FLOAT, 0, wtb->inner_v);
 -                              glDrawArrays(GL_POLYGON, 0, wtb->totvert);
 -                              glDisableClientState(GL_VERTEX_ARRAY);
 -                      }
 +static void draw_widgetbase_batch(GPUBatch *batch, uiWidgetBase *wtb)
 +{
 +      wtb->uniform_params.tria1_size = wtb->tria1.size;
 +      wtb->uniform_params.tria2_size = wtb->tria2.size;
 +      copy_v2_v2(wtb->uniform_params.tria1_center, wtb->tria1.center);
 +      copy_v2_v2(wtb->uniform_params.tria2_center, wtb->tria2.center);
 +
 +      if (g_widget_base_batch.enabled) {
 +              if (g_widget_base_batch.batch == NULL) {
 +                      g_widget_base_batch.batch = ui_batch_roundbox_widget_get(ROUNDBOX_TRIA_ARROWS);
                }
 -              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);
  
 -                      for (a = 0; a < wtb->totvert; a++, col_pt += 4) {
 -                              round_box_shade_col4_r(col_pt, col1, col2, wtb->inner_uv[a][wtb->draw_shadedir ? 1 : 0]);
 -                      }
 -
 -                      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);
 +              /* draw multi */
 +              if (batch != g_ui_batch_cache.roundbox_widget[ROUNDBOX_TRIA_NONE] &&
 +                  batch != g_widget_base_batch.batch)
 +              {
 +                      /* issue previous calls before changing batch type. */
 +                      UI_widgetbase_draw_cache_flush();
 +                      g_widget_base_batch.batch = batch;
                }
 -      }
  
 -      /* for each AA step */
 -      if (wtb->draw_outline) {
 -              BLI_assert(wtb->totvert != 0);
 -              float triangle_strip[WIDGET_SIZE_MAX * 2 + 2][2]; /* + 2 because the last pair is wrapped */
 -              float triangle_strip_emboss[WIDGET_SIZE_MAX * 2][2]; /* only for emboss */
 -
 -              const unsigned char tcol[4] = {
 -                      wcol->outline[0],
 -                      wcol->outline[1],
 -                      wcol->outline[2],
 -                      wcol->outline[3] / WIDGET_AA_JITTER,
 -              };
 -              unsigned char emboss[4];
 +              /* No need to change batch if tria is not visible. Just scale it to 0. */
 +              if (batch == g_ui_batch_cache.roundbox_widget[ROUNDBOX_TRIA_NONE]) {
 +                      wtb->uniform_params.tria1_size = wtb->uniform_params.tria2_size = 0;
 +              }
  
 -              widget_verts_to_triangle_strip(wtb, wtb->totvert, triangle_strip);
 +              g_widget_base_batch.params[g_widget_base_batch.count] = wtb->uniform_params;
 +              g_widget_base_batch.count++;
  
 -              if (wtb->draw_emboss) {
 -                      widget_verts_to_triangle_strip_open(wtb, wtb->halfwayvert, triangle_strip_emboss);
 -                      UI_GetThemeColor4ubv(TH_WIDGET_EMBOSS, emboss);
 +              if (g_widget_base_batch.count == MAX_WIDGET_BASE_BATCH) {
 +                      UI_widgetbase_draw_cache_flush();
                }
 +      }
 +      else {
 +              float checker_params[3] = {UI_ALPHA_CHECKER_DARK / 255.0f, UI_ALPHA_CHECKER_LIGHT / 255.0f, 8.0f};
 +              /* draw single */
 +              GPU_batch_program_set_builtin(batch, GPU_SHADER_2D_WIDGET_BASE);
 +              GPU_batch_uniform_4fv_array(batch, "parameters", MAX_WIDGET_PARAMETERS, (float *)&wtb->uniform_params);
 +              GPU_batch_uniform_3fv(batch, "checkerColorAndSize", checker_params);
 +              GPU_batch_draw(batch);
 +      }
 +}
  
- static void widgetbase_draw(uiWidgetBase *wtb, const uiWidgetColors *wcol)
 -              glEnableClientState(GL_VERTEX_ARRAY);
 -
 -              for (j = 0; j < WIDGET_AA_JITTER; j++) {
 -                      glTranslate2fv(jit[j]);
++static void widgetbase_draw_ex(
++        uiWidgetBase *wtb, const uiWidgetColors *wcol,
++        bool show_alpha_checkers)
 +{
 +      unsigned char inner_col1[4] = {0};
 +      unsigned char inner_col2[4] = {0};
 +      unsigned char emboss_col[4] = {0};
 +      unsigned char outline_col[4] = {0};
 +      unsigned char tria_col[4] = {0};
 +      /* For color widget. */
-       bool alpha_check = (wcol->alpha_check && (wcol->shaded == 0));
++      if (wcol->shaded != 0) {
++              show_alpha_checkers = false;
++      }
  
 -                      /* outline */
 -                      glColor4ubv(tcol);
 +      GPU_blend(true);
  
 -                      glVertexPointer(2, GL_FLOAT, 0, triangle_strip);
 -                      glDrawArrays(GL_TRIANGLE_STRIP, 0, wtb->totvert * 2 + 2);
 +      /* backdrop non AA */
 +      if (wtb->draw_inner) {
 +              if (wcol->shaded == 0) {
 +                      /* simple fill */
 +                      inner_col1[0] = inner_col2[0] = (unsigned char)wcol->inner[0];
 +                      inner_col1[1] = inner_col2[1] = (unsigned char)wcol->inner[1];
 +                      inner_col1[2] = inner_col2[2] = (unsigned char)wcol->inner[2];
 +                      inner_col1[3] = inner_col2[3] = (unsigned char)wcol->inner[3];
 +              }
 +              else {
 +                      /* gradient fill */
 +                      shadecolors4((char *)inner_col1, (char *)inner_col2, wcol->inner, wcol->shadetop, wcol->shadedown);
 +              }
 +      }
  
 -                      /* emboss bottom shadow */
 -                      if (wtb->draw_emboss) {
 -                              if (emboss[3]) {
 -                                      glColor4ubv(emboss);
 -                                      glVertexPointer(2, GL_FLOAT, 0, triangle_strip_emboss);
 -                                      glDrawArrays(GL_TRIANGLE_STRIP, 0, wtb->halfwayvert * 2);
 -                              }
 -                      }
 +      if (wtb->draw_outline) {
 +              outline_col[0] = wcol->outline[0];
 +              outline_col[1] = wcol->outline[1];
 +              outline_col[2] = wcol->outline[2];
 +              outline_col[3] = wcol->outline[3] / WIDGET_AA_JITTER;
  
 -                      glTranslatef(-jit[j][0], -jit[j][1], 0.0f);
 +              /* emboss bottom shadow */
 +              if (wtb->draw_emboss) {
 +                      UI_GetThemeColor4ubv(TH_WIDGET_EMBOSS, emboss_col);
                }
 +      }
  
 -              glDisableClientState(GL_VERTEX_ARRAY);
 +      if (wtb->tria1.type != ROUNDBOX_TRIA_NONE) {
 +              tria_col[0] = wcol->item[0];
 +              tria_col[1] = wcol->item[1];
 +              tria_col[2] = wcol->item[2];
 +              tria_col[3] = (unsigned char)((float)wcol->item[3] / WIDGET_AA_JITTER);
        }
  
 -      /* 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),
 -              };
 -              glColor4ubv(tcol);
 -
 -              /* for each AA step */
 -              for (j = 0; j < WIDGET_AA_JITTER; j++) {
 -                      glTranslate2fv(jit[j]);
 -
 -                      if (wtb->tria1.tot) {
 -                              shape_preset_draw_trias(&wtb->tria1);
 -                      }
 -                      if (wtb->tria2.tot) {
 -                              shape_preset_draw_trias(&wtb->tria2);
 -                      }
 +      /* Draw everything in one drawcall */
-       if (inner_col1[3] || inner_col2[3] || outline_col[3] || emboss_col[3] || tria_col[3] || alpha_check) {
-               widgetbase_set_uniform_colors_ubv(wtb, inner_col1, inner_col2, outline_col, emboss_col, tria_col, alpha_check);
++      if (inner_col1[3] || inner_col2[3] || outline_col[3] || emboss_col[3] || tria_col[3] || show_alpha_checkers) {
++              widgetbase_set_uniform_colors_ubv(wtb, inner_col1, inner_col2, outline_col, emboss_col, tria_col, show_alpha_checkers);
  
 -                      glTranslatef(-jit[j][0], -jit[j][1], 0.0f);
 -              }
 +              GPUBatch *roundbox_batch = ui_batch_roundbox_widget_get(wtb->tria1.type);
 +              draw_widgetbase_batch(roundbox_batch, wtb);
        }
  
 -      glDisable(GL_BLEND);
 +      GPU_blend(false);
  }
  
 -static void widgetbase_draw(uiWidgetBase *wtb, uiWidgetColors *wcol)
++static void widgetbase_draw(uiWidgetBase *wtb, const uiWidgetColors *wcol)
+ {
+       widgetbase_draw_ex(wtb, wcol, false);
+ }
  /* *********************** text/icon ************************************** */
  
  #define UI_TEXT_CLIP_MARGIN (0.25f * U.widget_unit / but->block->aspect)
@@@ -3389,7 -3120,8 +3398,7 @@@ static void widget_swatch(uiBut *but, u
                wcol->inner[3] /= 2;
        }
  
-       widgetbase_draw(&wtb, wcol);
+       widgetbase_draw_ex(&wtb, wcol, show_alpha_checkers);
 -
        if (but->a1 == UI_PALETTE_COLOR && ((Palette *)but->rnapoin.id.data)->active_color == (int)but->a2) {
                float width = rect->xmax - rect->xmin;
                float height = rect->ymax - rect->ymin;
index 362a923255397996233648541a84271091387247,e8cc4fbe38fae74a9ded4d8e1c47a45b15ea281a..10ffabd033dce6e99c852d7bb8baf4c7620992ce
@@@ -133,11 -128,9 +133,10 @@@ typedef struct uiWidgetColors 
        char item[4];
        char text[4];
        char text_sel[4];
--      short shaded;
++      char shaded;
++      char _pad0[7];
        short shadetop, shadedown;
-       short alpha_check;
 -      char _pad0[2];
 +      float roundness;
-       float pad;
  } uiWidgetColors;
  
  typedef struct uiWidgetStateColors {