Merge branch 'master' into blender2.8
authorLuca Rood <dev@lucarood.com>
Wed, 5 Jul 2017 13:50:01 +0000 (15:50 +0200)
committerLuca Rood <dev@lucarood.com>
Wed, 5 Jul 2017 13:50:01 +0000 (15:50 +0200)
1  2 
intern/cycles/device/device_cuda.cpp
source/blender/blenkernel/intern/particle.c
source/blender/makesrna/intern/rna_particle.c

index 19e68007934483239e1f0657b47c90cd9df87dc3,3a29538aa1353686301c0499629a902e575f41aa..e53aec0fbb97a61c1fd04a45bc0e1bce665b1906
@@@ -105,7 -105,8 +105,8 @@@ public
                                                    device_memory& use_queues_flag,
                                                    device_memory& work_pool_wgs);
  
-       virtual SplitKernelFunction* get_split_kernel_function(string kernel_name, const DeviceRequestedFeatures&);
+       virtual SplitKernelFunction* get_split_kernel_function(const string& kernel_name,
+                                                              const DeviceRequestedFeatures&);
        virtual int2 split_kernel_local_size();
        virtual int2 split_kernel_global_size(device_memory& kg, device_memory& data, DeviceTask *task);
  };
@@@ -1631,14 -1632,10 +1632,14 @@@ public
                }
        }
  
 -      void draw_pixels(device_memory& mem, int y, int w, int h, int dx, int dy, int width, int height, bool transparent,
 +      void draw_pixels(
 +          device_memory& mem, int y,
 +          int w, int h, int width, int height,
 +          int dx, int dy, int dw, int dh, bool transparent,
                const DeviceDrawParams &draw_params)
        {
                if(!background) {
 +                      const bool use_fallback_shader = (draw_params.bind_display_space_shader_cb == NULL);
                        PixelMem pmem = pixel_mem_map[mem.device_pointer];
                        float *vpointer;
  
  
                        glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pmem.cuPBO);
                        glBindTexture(GL_TEXTURE_2D, pmem.cuTexId);
 -                      if(mem.data_type == TYPE_HALF)
 +                      if(mem.data_type == TYPE_HALF) {
                                glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_HALF_FLOAT, (void*)offset);
 -                      else
 +                      }
 +                      else {
                                glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, (void*)offset);
 +                      }
                        glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
  
                        glEnable(GL_TEXTURE_2D);
                                glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
                        }
  
 -                      glColor3f(1.0f, 1.0f, 1.0f);
 -
 -                      if(draw_params.bind_display_space_shader_cb) {
 +                      GLint shader_program;
 +                      if(use_fallback_shader) {
 +                              if(!bind_fallback_display_space_shader(dw, dh)) {
 +                                      return;
 +                              }
 +                              shader_program = fallback_shader_program;
 +                      }
 +                      else {
                                draw_params.bind_display_space_shader_cb();
 +                              glGetIntegerv(GL_CURRENT_PROGRAM, &shader_program);
                        }
  
 -                      if(!vertex_buffer)
 +                      if(!vertex_buffer) {
                                glGenBuffers(1, &vertex_buffer);
 +                      }
  
                        glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
                        /* invalidate old contents - avoids stalling if buffer is still waiting in queue to be rendered */
                                glUnmapBuffer(GL_ARRAY_BUFFER);
                        }
  
 -                      glTexCoordPointer(2, GL_FLOAT, 4 * sizeof(float), 0);
 -                      glVertexPointer(2, GL_FLOAT, 4 * sizeof(float), (char *)NULL + 2 * sizeof(float));
 +                      GLuint vertex_array_object;
 +                      GLuint position_attribute, texcoord_attribute;
  
 -                      glEnableClientState(GL_VERTEX_ARRAY);
 -                      glEnableClientState(GL_TEXTURE_COORD_ARRAY);
 +                      glGenVertexArrays(1, &vertex_array_object);
 +                      glBindVertexArray(vertex_array_object);
  
 -                      glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
 +                      texcoord_attribute = glGetAttribLocation(shader_program, "texCoord");
 +                      position_attribute = glGetAttribLocation(shader_program, "pos");
  
 -                      glDisableClientState(GL_TEXTURE_COORD_ARRAY);
 -                      glDisableClientState(GL_VERTEX_ARRAY);
 +                      glEnableVertexAttribArray(texcoord_attribute);
 +                      glEnableVertexAttribArray(position_attribute);
  
 -                      glBindBuffer(GL_ARRAY_BUFFER, 0);
 +                      glVertexAttribPointer(texcoord_attribute, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (const GLvoid *)0);
 +                      glVertexAttribPointer(position_attribute, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (const GLvoid *)(sizeof(float) * 2));
 +
 +                      glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
  
 -                      if(draw_params.unbind_display_space_shader_cb) {
 +                      if(use_fallback_shader) {
 +                              glUseProgram(0);
 +                      }
 +                      else {
                                draw_params.unbind_display_space_shader_cb();
                        }
  
 -                      if(transparent)
 +                      if(transparent) {
                                glDisable(GL_BLEND);
 +                      }
  
                        glBindTexture(GL_TEXTURE_2D, 0);
                        glDisable(GL_TEXTURE_2D);
                        return;
                }
  
 -              Device::draw_pixels(mem, y, w, h, dx, dy, width, height, transparent, draw_params);
 +              Device::draw_pixels(mem, y, w, h, width, height, dx, dy, dw, dh, transparent, draw_params);
        }
  
        void thread_run(DeviceTask *task)
@@@ -2058,7 -2038,8 +2059,8 @@@ bool CUDASplitKernel::enqueue_split_ker
        return !device->have_error();
  }
  
- SplitKernelFunction* CUDASplitKernel::get_split_kernel_function(string kernel_name, const DeviceRequestedFeatures&)
+ SplitKernelFunction* CUDASplitKernel::get_split_kernel_function(const string& kernel_name,
+                                                                 const DeviceRequestedFeatures&)
  {
        CUfunction func;
  
index dabade5649082c7a72f0a25364486db93a2983e4,e101bd649317475f411eee0bd6db84ef16fe8947..f34a680b52da559626fd31f43488d584dc194ec6
@@@ -78,6 -78,7 +78,6 @@@
  #include "BKE_library.h"
  #include "BKE_library_query.h"
  #include "BKE_library_remap.h"
 -#include "BKE_depsgraph.h"
  #include "BKE_modifier.h"
  #include "BKE_mesh.h"
  #include "BKE_cdderivedmesh.h"
@@@ -85,9 -86,6 +85,9 @@@
  #include "BKE_scene.h"
  #include "BKE_deform.h"
  
 +#include "DEG_depsgraph.h"
 +#include "DEG_depsgraph_build.h"
 +
  #include "RE_render_ext.h"
  
  unsigned int PSYS_FRAND_SEED_OFFSET[PSYS_FRAND_COUNT];
@@@ -608,8 -606,6 +608,8 @@@ void psys_free(Object *ob, ParticleSyst
                        MEM_freeN(psys->pdd);
                }
  
 +              BKE_particle_batch_cache_free(psys);
 +
                MEM_freeN(psys);
        }
  }
@@@ -3162,8 -3158,8 +3162,8 @@@ ModifierData *object_add_particle_syste
        psys->flag = PSYS_CURRENT;
        psys->cfra = BKE_scene_frame_get_from_ctime(scene, CFRA + 1);
  
 -      DAG_relations_tag_update(G.main);
 -      DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
 +      DEG_relations_tag_update(G.main);
 +      DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
  
        return md;
  }
@@@ -3208,8 -3204,8 +3208,8 @@@ void object_remove_particle_system(Scen
        else
                ob->mode &= ~OB_MODE_PARTICLE_EDIT;
  
 -      DAG_relations_tag_update(G.main);
 -      DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
 +      DEG_relations_tag_update(G.main);
 +      DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
  }
  
  static void default_particle_settings(ParticleSettings *part)
  
        part->omat = 1;
        part->use_modifier_stack = false;
 +      part->draw_size = 0.1f;
  }
  
  
@@@ -3379,7 -3374,8 +3379,8 @@@ void BKE_particlesettings_make_local(Ma
  /*                    Textures                                                        */
  /************************************************/
  
- static int get_particle_uv(DerivedMesh *dm, ParticleData *pa, int face_index, const float fuv[4], char *name, float *texco)
+ static int get_particle_uv(DerivedMesh *dm, ParticleData *pa, int index, const float fuv[4],
+                            char *name, float *texco, bool from_vert)
  {
        MFace *mf;
        MTFace *tf;
  
        if (pa) {
                i = ELEM(pa->num_dmcache, DMCACHE_NOTFOUND, DMCACHE_ISCHILD) ? pa->num : pa->num_dmcache;
-               if (i >= dm->getNumTessFaces(dm))
+               if ((!from_vert && i >= dm->getNumTessFaces(dm)) ||
+                   (from_vert && i >= dm->getNumVerts(dm)))
+               {
                        i = -1;
+               }
+       }
+       else {
+               i = index;
        }
-       else
-               i = face_index;
  
        if (i == -1) {
                texco[0] = 0.0f;
                texco[2] = 0.0f;
        }
        else {
-               mf = dm->getTessFaceData(dm, i, CD_MFACE);
+               if (from_vert) {
+                       mf = dm->getTessFaceDataArray(dm, CD_MFACE);
+                       for (int j = 0; j < dm->getNumTessFaces(dm); j++, mf++) {
+                               if (ELEM(i, mf->v1, mf->v2, mf->v3, mf->v4)) {
+                                       i = j;
+                                       break;
+                               }
+                       }
+               }
+               else {
+                       mf = dm->getTessFaceData(dm, i, CD_MFACE);
+               }
  
                psys_interpolate_uvs(&tf[i], mf->v4, fuv, texco);
  
@@@ -3474,8 -3486,11 +3491,11 @@@ static void get_cpa_texture(DerivedMes
                                                mul_m4_v3(mtex->object->imat, texvec);
                                        break;
                                case TEXCO_UV:
-                                       if (fw && get_particle_uv(dm, NULL, face_index, fw, mtex->uvname, texvec))
+                                       if (fw && get_particle_uv(dm, NULL, face_index, fw, mtex->uvname,
+                                                                 texvec, (part->from == PART_FROM_VERT)))
+                                       {
                                                break;
+                                       }
                                        /* no break, failed to get uv's, so let's try orco's */
                                        ATTR_FALLTHROUGH;
                                case TEXCO_ORCO:
@@@ -3547,8 -3562,11 +3567,11 @@@ void psys_get_texture(ParticleSimulatio
                                                mul_m4_v3(mtex->object->imat, texvec);
                                        break;
                                case TEXCO_UV:
-                                       if (get_particle_uv(sim->psmd->dm_final, pa, 0, pa->fuv, mtex->uvname, texvec))
+                                       if (get_particle_uv(sim->psmd->dm_final, pa, 0, pa->fuv, mtex->uvname,
+                                                           texvec, (part->from == PART_FROM_VERT)))
+                                       {
                                                break;
+                                       }
                                        /* no break, failed to get uv's, so let's try orco's */
                                        ATTR_FALLTHROUGH;
                                case TEXCO_ORCO:
@@@ -4315,22 -4333,3 +4338,22 @@@ void psys_apply_hair_lattice(Scene *sce
                psys->flag |= PSYS_EDITED;
        }
  }
 +
 +
 +
 +/* Draw Engine */
 +void (*BKE_particle_batch_cache_dirty_cb)(ParticleSystem *psys, int mode) = NULL;
 +void (*BKE_particle_batch_cache_free_cb)(ParticleSystem *psys) = NULL;
 +
 +void BKE_particle_batch_cache_dirty(ParticleSystem *psys, int mode)
 +{
 +      if (psys->batch_cache) {
 +              BKE_particle_batch_cache_dirty_cb(psys, mode);
 +      }
 +}
 +void BKE_particle_batch_cache_free(ParticleSystem *psys)
 +{
 +      if (psys->batch_cache) {
 +              BKE_particle_batch_cache_free_cb(psys);
 +      }
 +}
index 29f33907d395b59d6af832acb536441fabf4c502,0dac797824d35b3fedbcc6a37791d40651ec12b0..b40519386cc9e1745784ba89132aca446671ea52
@@@ -135,6 -135,7 +135,6 @@@ static EnumPropertyItem part_hair_ren_a
  #include "BKE_cloth.h"
  #include "BKE_colortools.h"
  #include "BKE_deform.h"
 -#include "BKE_depsgraph.h"
  #include "BKE_DerivedMesh.h"
  #include "BKE_cdderivedmesh.h"
  #include "BKE_effect.h"
  #include "BKE_pointcache.h"
  #include "BKE_texture.h"
  
 +#include "DEG_depsgraph.h"
 +#include "DEG_depsgraph_build.h"
 +
  /* use for object space hair get/set */
  static void rna_ParticleHairKey_location_object_info(PointerRNA *ptr, ParticleSystemModifierData **psmd_pt,
                                                       ParticleData **pa_pt)
@@@ -448,10 -446,12 +448,12 @@@ static int rna_ParticleSystem_tessfacei
        int totpart;
        int totchild = 0;
        int totface;
+       int totvert;
        int num = -1;
  
        DM_ensure_tessface(modifier->dm_final); /* BMESH - UNTIL MODIFIER IS UPDATED FOR MPoly */
        totface = modifier->dm_final->getNumTessFaces(modifier->dm_final);
+       totvert = modifier->dm_final->getNumVerts(modifier->dm_final);
  
        /* 1. check that everything is ok & updated */
        if (!particlesystem || !totface) {
                                return num;
                        }
                }
+               else if (part->from == PART_FROM_VERT) {
+                       if (num != DMCACHE_NOTFOUND && num < totvert) {
+                               MFace *mface = modifier->dm_final->getTessFaceDataArray(modifier->dm_final, CD_MFACE);
+                               *r_fuv = &particle->fuv;
+                               for (int i = 0; i < totface; i++, mface++) {
+                                       if (ELEM(num, mface->v1, mface->v2, mface->v3, mface->v4)) {
+                                               return i;
+                                       }
+                               }
+                       }
+               }
        }
        else {
                ChildParticle *cpa = particlesystem->child + particle_no - totpart;
                num = cpa->num;
  
                if (part->childtype == PART_CHILD_FACES) {
-                       if (ELEM(part->from, PART_FROM_FACE, PART_FROM_VOLUME)) {
+                       if (ELEM(part->from, PART_FROM_FACE, PART_FROM_VOLUME, PART_FROM_VERT)) {
                                if (num != DMCACHE_NOTFOUND && num < totface) {
                                        *r_fuv = &cpa->fuv;
                                        return num;
                                        return num;
                                }
                        }
+                       else if (part->from == PART_FROM_VERT) {
+                               if (num != DMCACHE_NOTFOUND && num < totvert) {
+                                       MFace *mface = modifier->dm_final->getTessFaceDataArray(modifier->dm_final, CD_MFACE);
+                                       *r_fuv = &parent->fuv;
+                                       for (int i = 0; i < totface; i++, mface++) {
+                                               if (ELEM(num, mface->v1, mface->v2, mface->v3, mface->v4)) {
+                                                       return i;
+                                               }
+                                       }
+                               }
+                       }
                }
        }
  
@@@ -611,10 -637,10 +639,10 @@@ static void particle_recalc(Main *UNUSE
                
                psys->recalc = flag;
  
 -              DAG_id_tag_update(ptr->id.data, OB_RECALC_DATA);
 +              DEG_id_tag_update(ptr->id.data, OB_RECALC_DATA);
        }
        else
 -              DAG_id_tag_update(ptr->id.data, OB_RECALC_DATA | flag);
 +              DEG_id_tag_update(ptr->id.data, OB_RECALC_DATA | flag);
  
        WM_main_add_notifier(NC_OBJECT | ND_PARTICLE | NA_EDITED, NULL);
  }
@@@ -625,7 -651,7 +653,7 @@@ static void rna_Particle_redo(Main *bma
  
  static void rna_Particle_redo_dependency(Main *bmain, Scene *scene, PointerRNA *ptr)
  {
 -      DAG_relations_tag_update(bmain);
 +      DEG_relations_tag_update(bmain);
        rna_Particle_redo(bmain, scene, ptr);
  }
  
@@@ -636,7 -662,7 +664,7 @@@ static void rna_Particle_reset(Main *bm
  
  static void rna_Particle_reset_dependency(Main *bmain, Scene *scene, PointerRNA *ptr)
  {
 -      DAG_relations_tag_update(bmain);
 +      DEG_relations_tag_update(bmain);
        rna_Particle_reset(bmain, scene, ptr);
  }
  
@@@ -659,7 -685,7 +687,7 @@@ static void rna_Particle_cloth_update(M
  {
        Object *ob = (Object *)ptr->id.data;
  
 -      DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
 +      DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
        WM_main_add_notifier(NC_OBJECT | ND_MODIFIER, ob);
  }
  
@@@ -704,8 -730,8 +732,8 @@@ static void rna_Particle_target_reset(M
                
                psys->recalc = PSYS_RECALC_RESET;
  
 -              DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
 -              DAG_relations_tag_update(bmain);
 +              DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
 +              DEG_relations_tag_update(bmain);
        }
  
        WM_main_add_notifier(NC_OBJECT | ND_PARTICLE | NA_EDITED, NULL);
@@@ -720,7 -746,7 +748,7 @@@ static void rna_Particle_target_redo(Ma
                
                psys->recalc = PSYS_RECALC_REDO;
  
 -              DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
 +              DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
                WM_main_add_notifier(NC_OBJECT | ND_PARTICLE | NA_EDITED, NULL);
        }
  }
@@@ -740,7 -766,7 +768,7 @@@ static void rna_Particle_hair_dynamics(
        else
                WM_main_add_notifier(NC_OBJECT | ND_PARTICLE | NA_EDITED, NULL);
  
 -      DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
 +      DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
  }
  static PointerRNA rna_particle_settings_get(PointerRNA *ptr)
  {
@@@ -2340,10 -2366,10 +2368,10 @@@ static void rna_def_particle_settings(B
        RNA_def_property_ui_text(prop, "Draw Color", "Draw additional particle data as a color");
        RNA_def_property_update(prop, 0, "rna_Particle_redo");
  
 -      prop = RNA_def_property(srna, "draw_size", PROP_INT, PROP_PIXEL);
 +      prop = RNA_def_property(srna, "draw_size", PROP_FLOAT, PROP_NONE);
        RNA_def_property_range(prop, 0, 1000);
        RNA_def_property_ui_range(prop, 0, 100, 1, -1);
 -      RNA_def_property_ui_text(prop, "Draw Size", "Size of particles on viewport in pixels (0=default)");
 +      RNA_def_property_ui_text(prop, "Draw Size", "Size of particles on viewport in BU (0.1 = default)");
        RNA_def_property_update(prop, 0, "rna_Particle_redo");
  
        prop = RNA_def_property(srna, "child_type", PROP_ENUM, PROP_NONE);