Clay: Simplify matcap manipulation
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 7 May 2018 13:28:25 +0000 (15:28 +0200)
committerSergey Sharybin <sergey.vfx@gmail.com>
Tue, 8 May 2018 09:56:58 +0000 (11:56 +0200)
No need to hard-coded handling of every individual matcap.

They are in the continuous index range anyway.

source/blender/draw/engines/clay/clay_engine.c

index fe8da3c488800fa32daaa4e08d63e4bb952a6e83..82a2e808f4cfd23f42dccdf3be75b966bb4b276b 100644 (file)
@@ -273,34 +273,7 @@ static struct GPUTexture *load_matcaps(PreviewImage *prv[24], int nbr)
 
 static int matcap_to_index(int matcap)
 {
-       switch (matcap) {
-               case ICON_MATCAP_01: return 0;
-               case ICON_MATCAP_02: return 1;
-               case ICON_MATCAP_03: return 2;
-               case ICON_MATCAP_04: return 3;
-               case ICON_MATCAP_05: return 4;
-               case ICON_MATCAP_06: return 5;
-               case ICON_MATCAP_07: return 6;
-               case ICON_MATCAP_08: return 7;
-               case ICON_MATCAP_09: return 8;
-               case ICON_MATCAP_10: return 9;
-               case ICON_MATCAP_11: return 10;
-               case ICON_MATCAP_12: return 11;
-               case ICON_MATCAP_13: return 12;
-               case ICON_MATCAP_14: return 13;
-               case ICON_MATCAP_15: return 14;
-               case ICON_MATCAP_16: return 15;
-               case ICON_MATCAP_17: return 16;
-               case ICON_MATCAP_18: return 17;
-               case ICON_MATCAP_19: return 18;
-               case ICON_MATCAP_20: return 19;
-               case ICON_MATCAP_21: return 20;
-               case ICON_MATCAP_22: return 21;
-               case ICON_MATCAP_23: return 22;
-               case ICON_MATCAP_24: return 23;
-       }
-       BLI_assert(!"Should not happen");
-       return 0;
+       return (int)matcap - (int)ICON_MATCAP_01;
 }
 
 /* Using Hammersley distribution */
@@ -357,34 +330,14 @@ static void clay_engine_init(void *vedata)
        /* Create Texture Array */
        if (!e_data.matcap_array) {
                PreviewImage *prv[24]; /* For now use all of the 24 internal matcaps */
+               const int num_matcap = ARRAY_SIZE(prv);
 
                /* TODO only load used matcaps */
-               prv[0]  = UI_icon_to_preview(ICON_MATCAP_01);
-               prv[1]  = UI_icon_to_preview(ICON_MATCAP_02);
-               prv[2]  = UI_icon_to_preview(ICON_MATCAP_03);
-               prv[3]  = UI_icon_to_preview(ICON_MATCAP_04);
-               prv[4]  = UI_icon_to_preview(ICON_MATCAP_05);
-               prv[5]  = UI_icon_to_preview(ICON_MATCAP_06);
-               prv[6]  = UI_icon_to_preview(ICON_MATCAP_07);
-               prv[7]  = UI_icon_to_preview(ICON_MATCAP_08);
-               prv[8]  = UI_icon_to_preview(ICON_MATCAP_09);
-               prv[9]  = UI_icon_to_preview(ICON_MATCAP_10);
-               prv[10] = UI_icon_to_preview(ICON_MATCAP_11);
-               prv[11] = UI_icon_to_preview(ICON_MATCAP_12);
-               prv[12] = UI_icon_to_preview(ICON_MATCAP_13);
-               prv[13] = UI_icon_to_preview(ICON_MATCAP_14);
-               prv[14] = UI_icon_to_preview(ICON_MATCAP_15);
-               prv[15] = UI_icon_to_preview(ICON_MATCAP_16);
-               prv[16] = UI_icon_to_preview(ICON_MATCAP_17);
-               prv[17] = UI_icon_to_preview(ICON_MATCAP_18);
-               prv[18] = UI_icon_to_preview(ICON_MATCAP_19);
-               prv[19] = UI_icon_to_preview(ICON_MATCAP_20);
-               prv[20] = UI_icon_to_preview(ICON_MATCAP_21);
-               prv[21] = UI_icon_to_preview(ICON_MATCAP_22);
-               prv[22] = UI_icon_to_preview(ICON_MATCAP_23);
-               prv[23] = UI_icon_to_preview(ICON_MATCAP_24);
-
-               e_data.matcap_array = load_matcaps(prv, 24);
+               for (int i = 0; i < num_matcap; ++i) {
+                       prv[i] = UI_icon_to_preview((int)ICON_MATCAP_01 + i);
+               }
+
+               e_data.matcap_array = load_matcaps(prv, num_matcap);
        }
 
        /* Shading pass */