Merge branch 'master' into blender2.8
authorSergey Sharybin <sergey.vfx@gmail.com>
Tue, 11 Jul 2017 10:30:30 +0000 (12:30 +0200)
committerSergey Sharybin <sergey.vfx@gmail.com>
Tue, 11 Jul 2017 10:30:30 +0000 (12:30 +0200)
1  2 
intern/opensubdiv/opensubdiv_capi.cc
source/blender/blenkernel/intern/node.c
source/blender/editors/interface/interface_utils.c

index aed5d4fbd14dd628ccc1920568ddcc3b495b7c55,0a55a432cc69431ff86b00c8e193256bf45ad500..bb865bc0e0f1e950cf37590f8f5b5e3e57998140
  
  #include "MEM_guardedalloc.h"
  
+ #include <string>
+ #include <vector>
+ using std::string;
+ using std::vector;
+ #define STRINGIFY_ARG(x) "" #x
+ #define STRINGIFY_APPEND(a, b) "" a #b
+ #define STRINGIFY(x) STRINGIFY_APPEND("", x)
  /* **************** Types declaration **************** */
  
  using OpenSubdiv::Osd::GLMeshInterface;
@@@ -147,6 -157,38 +157,38 @@@ typedef Mesh<GLVertexBuffer
  
  namespace {
  
+ #if !defined(OPENSUBDIV_VERSION_NUMBER) && !defined(OPENSUBDIV_VERSION_MINOR)
+ void stringSplit(vector<string>* tokens,
+                  const string& str,
+                  const string& separators,
+                  bool skip_empty) {
+       size_t token_start = 0, token_length = 0;
+       for (size_t i = 0; i < str.length(); ++i) {
+               const char ch = str[i];
+               if (separators.find(ch) == string::npos) {
+                       /* Append non-separator char to a token. */
+                       ++token_length;
+               } else {
+                       /* Append current token to the list (if any). */
+                       if (token_length > 0 || !skip_empty) {
+                               string token = str.substr(token_start, token_length);
+                               tokens->push_back(token);
+                       }
+                       /* Re-set token pointers, */
+                       token_start = i + 1;
+                       token_length = 0;
+               }
+       }
+       /* Append token which might be at the end of the string. */
+       if ((token_length != 0) ||
+           (!skip_empty && token_start > 0 &&
+            separators.find(str[token_start-1]) != string::npos)) {
+               string token = str.substr(token_start, token_length);
+               tokens->push_back(token);
+       }
+ }
+ #endif
  struct FVarVertex {
        float u, v;
        void Clear() {
@@@ -370,7 -412,42 +412,29 @@@ const struct OpenSubdiv_TopologyRefiner
        return gl_mesh->topology_refiner;
  }
  
 -int openSubdiv_supportGPUDisplay(void)
 -{
 -      // TODO: simplify extension check once Blender adopts GL 3.2
 -      return openSubdiv_gpu_legacy_support() &&
 -             (GLEW_VERSION_3_2 ||
 -             (GLEW_VERSION_3_1 && GLEW_EXT_geometry_shader4) ||
 -             (GLEW_VERSION_3_0 &&
 -              GLEW_EXT_geometry_shader4 &&
 -              GLEW_ARB_uniform_buffer_object &&
 -              (GLEW_ARB_texture_buffer_object || GLEW_EXT_texture_buffer_object)));
 -      /* also ARB_explicit_attrib_location? */
 -}
 -
  int openSubdiv_getVersionHex(void)
  {
+ #if defined(OPENSUBDIV_VERSION_NUMBER)
        return OPENSUBDIV_VERSION_NUMBER;
+ #elif defined(OPENSUBDIV_VERSION_MAJOR)
+       return OPENSUBDIV_VERSION_MAJOR * 10000 +
+              OPENSUBDIV_VERSION_MINOR * 100 +
+              OPENSUBDIV_VERSION_PATCH;
+ #elif defined(OPENSUBDIV_VERSION)
+       const char* version = STRINGIFY(OPENSUBDIV_VERSION);
+       if (version[0] == 'v') {
+               version += 1;
+       }
+       int major = 0, minor = 0, patch = 0;
+       vector<string> tokens;
+       stringSplit(&tokens, version, "_", true);
+       if (tokens.size() == 3) {
+               major = atoi(tokens[0].c_str());
+               minor = atoi(tokens[1].c_str());
+               patch = atoi(tokens[2].c_str());
+       }
+       return major * 10000 + minor * 100 + patch;
+ #else
+       return 0;
+ #endif
  }
index 82092fedbe3605836984addf2ac99980219d7104,5acfe4a0aa44490d5e3801039ef8347384c3caf9..0ec6d930e070323b962ab5fa148ef1eb46d8d14f
@@@ -1700,11 -1700,12 +1700,12 @@@ static void node_free_node_ex(bNodeTre
                        ntreeTexEndExecTree(ntree->execdata);
                        ntree->execdata = NULL;
                }
-               
-               if (node->typeinfo->freefunc)
-                       node->typeinfo->freefunc(node);
        }
-       
+       if (node->typeinfo->freefunc) {
+               node->typeinfo->freefunc(node);
+       }
        for (sock = node->inputs.first; sock; sock = nextsock) {
                nextsock = sock->next;
                node_socket_free(ntree, sock, node);
@@@ -3595,12 -3596,9 +3596,12 @@@ static void registerShaderNodes(void
        register_node_type_sh_add_shader();
        register_node_type_sh_uvmap();
        register_node_type_sh_uvalongstroke();
 +      register_node_type_sh_eevee_metallic();
 +      register_node_type_sh_eevee_specular();
  
        register_node_type_sh_output_lamp();
        register_node_type_sh_output_material();
 +      register_node_type_sh_output_eevee_material();
        register_node_type_sh_output_world();
        register_node_type_sh_output_linestyle();
  
@@@ -3790,20 -3788,3 +3791,20 @@@ bool BKE_node_tree_iter_step(struct Nod
  
        return true;
  }
 +
 +/* -------------------------------------------------------------------- */
 +/* NodeTree kernel functions */
 +
 +void BKE_nodetree_remove_layer_n(bNodeTree *ntree, Scene *scene, const int layer_index)
 +{
 +      for (bNode *node = ntree->nodes.first; node; node = node->next) {
 +              if (node->type == CMP_NODE_R_LAYERS && (Scene *)node->id == scene) {
 +                      if (node->custom1 == layer_index) {
 +                              node->custom1 = 0;
 +                      }
 +                      else if (node->custom1 > layer_index) {
 +                              node->custom1--;
 +                      }
 +              }
 +      }
 +}
index fd1569ae42e91ba441edc43d39dbaf33f0ddd6fe,cf16cc9f50d01218f5fc99f661a3f75bee843b51..869be844b05aa544b0a5a7686358ccf2f5d09415
@@@ -215,90 -215,8 +215,90 @@@ int uiDefAutoButsRNA
        return tot;
  }
  
 -/***************************** ID Utilities *******************************/
 +/* *** RNA collection search menu *** */
  
 +typedef struct CollItemSearch {
 +      struct CollItemSearch *next, *prev;
 +      void *data;
 +      char *name;
 +      int index;
 +      int iconid;
 +} CollItemSearch;
 +
 +static int sort_search_items_list(const void *a, const void *b)
 +{
 +      const CollItemSearch *cis1 = a;
 +      const CollItemSearch *cis2 = b;
 +
 +      if (BLI_strcasecmp(cis1->name, cis2->name) > 0)
 +              return 1;
 +      else
 +              return 0;
 +}
 +
 +void ui_rna_collection_search_cb(const struct bContext *C, void *arg, const char *str, uiSearchItems *items)
 +{
 +      uiRNACollectionSearch *data = arg;
 +      char *name;
 +      int i = 0, iconid = 0, flag = RNA_property_flag(data->target_prop);
 +      ListBase *items_list = MEM_callocN(sizeof(ListBase), "items_list");
 +      CollItemSearch *cis;
 +      const bool skip_filter = !(data->but_changed && *data->but_changed);
 +
 +      /* build a temporary list of relevant items first */
 +      RNA_PROP_BEGIN (&data->search_ptr, itemptr, data->search_prop)
 +      {
 +
 +              if (flag & PROP_ID_SELF_CHECK)
 +                      if (itemptr.data == data->target_ptr.id.data)
 +                              continue;
 +
 +              /* use filter */
 +              if (RNA_property_type(data->target_prop) == PROP_POINTER) {
 +                      if (RNA_property_pointer_poll(&data->target_ptr, data->target_prop, &itemptr) == 0)
 +                              continue;
 +              }
 +
 +              name = RNA_struct_name_get_alloc(&itemptr, NULL, 0, NULL); /* could use the string length here */
 +              iconid = 0;
 +              if (itemptr.type && RNA_struct_is_ID(itemptr.type)) {
 +                      iconid = ui_id_icon_get(C, itemptr.data, false);
 +              }
 +
 +              if (name) {
 +                      if (skip_filter || BLI_strcasestr(name, str)) {
 +                              cis = MEM_callocN(sizeof(CollItemSearch), "CollectionItemSearch");
 +                              cis->data = itemptr.data;
 +                              cis->name = MEM_dupallocN(name);
 +                              cis->index = i;
 +                              cis->iconid = iconid;
 +                              BLI_addtail(items_list, cis);
 +                      }
 +                      MEM_freeN(name);
 +              }
 +
 +              i++;
 +      }
 +      RNA_PROP_END;
 +
 +      BLI_listbase_sort(items_list, sort_search_items_list);
 +
 +      /* add search items from temporary list */
 +      for (cis = items_list->first; cis; cis = cis->next) {
 +              if (UI_search_item_add(items, cis->name, cis->data, cis->iconid) == false) {
 +                      break;
 +              }
 +      }
 +
 +      for (cis = items_list->first; cis; cis = cis->next) {
 +              MEM_freeN(cis->name);
 +      }
 +      BLI_freelistN(items_list);
 +      MEM_freeN(items_list);
 +}
 +
 +
 +/***************************** ID Utilities *******************************/ 
  int UI_icon_from_id(ID *id)
  {
        Object *ob;
@@@ -462,6 -380,17 +462,17 @@@ uiButStore *UI_butstore_create(uiBlock 
  
  void UI_butstore_free(uiBlock *block, uiButStore *bs_handle)
  {
+       /* Workaround for button store being moved into new block,
+        * which then can't use the previous buttons state ('ui_but_update_from_old_block' fails to find a match),
+        * keeping the active button in the old block holding a reference to the button-state in the new block: see T49034.
+        *
+        * Ideally we would manage moving the 'uiButStore', keeping a correct state.
+        * All things considered this is the most straightforward fix - Campbell.
+        */
+       if (block != bs_handle->block && bs_handle->block != NULL) {
+               block = bs_handle->block;
+       }
        BLI_freelistN(&bs_handle->items);
        BLI_remlink(&block->butstore, bs_handle);