diff options
Diffstat (limited to 'source')
497 files changed, 4698 insertions, 3618 deletions
diff --git a/source/blender/alembic/intern/abc_customdata.cc b/source/blender/alembic/intern/abc_customdata.cc index 20ca659d32f..63887d36381 100644 --- a/source/blender/alembic/intern/abc_customdata.cc +++ b/source/blender/alembic/intern/abc_customdata.cc @@ -353,7 +353,7 @@ static void read_custom_data_mcols(const std::string &iobject_full_name, /* Read the vertex colors */ void *cd_data = config.add_customdata_cb( - config.user_data, prop_header.getName().c_str(), CD_MLOOPCOL); + config.mesh, prop_header.getName().c_str(), CD_MLOOPCOL); MCol *cfaces = static_cast<MCol *>(cd_data); MPoly *mpolys = config.mpoly; MLoop *mloops = config.mloop; @@ -437,8 +437,7 @@ static void read_custom_data_uvs(const ICompoundProperty &prop, return; } - void *cd_data = config.add_customdata_cb( - config.user_data, prop_header.getName().c_str(), CD_MLOOPUV); + void *cd_data = config.add_customdata_cb(config.mesh, prop_header.getName().c_str(), CD_MLOOPUV); read_uvs(config, cd_data, sample.getVals(), sample.getIndices()); } diff --git a/source/blender/alembic/intern/abc_customdata.h b/source/blender/alembic/intern/abc_customdata.h index c36029d5116..0ffafa8848e 100644 --- a/source/blender/alembic/intern/abc_customdata.h +++ b/source/blender/alembic/intern/abc_customdata.h @@ -28,6 +28,7 @@ #include <Alembic/AbcGeom/All.h> struct CustomData; +struct Mesh; struct MLoop; struct MLoopUV; struct MPoly; @@ -60,8 +61,8 @@ struct CDStreamConfig { /* TODO(kevin): might need a better way to handle adding and/or updating * custom datas such that it updates the custom data holder and its pointers * properly. */ - void *user_data; - void *(*add_customdata_cb)(void *user_data, const char *name, int data_type); + Mesh *mesh; + void *(*add_customdata_cb)(Mesh *mesh, const char *name, int data_type); float weight; float time; @@ -75,7 +76,7 @@ struct CDStreamConfig { totpoly(0), totvert(0), pack_uvs(false), - user_data(NULL), + mesh(NULL), add_customdata_cb(NULL), weight(0.0f), time(0.0f), diff --git a/source/blender/alembic/intern/abc_mesh.cc b/source/blender/alembic/intern/abc_mesh.cc index b0129a358ec..6647ca83bd6 100644 --- a/source/blender/alembic/intern/abc_mesh.cc +++ b/source/blender/alembic/intern/abc_mesh.cc @@ -46,6 +46,8 @@ extern "C" { #include "BKE_modifier.h" #include "BKE_object.h" +#include "MEM_guardedalloc.h" + #include "WM_api.h" #include "WM_types.h" @@ -122,7 +124,7 @@ static void get_vertices(struct Mesh *mesh, std::vector<Imath::V3f> &points) static void get_topology(struct Mesh *mesh, std::vector<int32_t> &poly_verts, std::vector<int32_t> &loop_counts, - bool &smooth_normal) + bool &r_export_loop_normals) { const int num_poly = mesh->totpoly; const int num_loops = mesh->totloop; @@ -139,7 +141,7 @@ static void get_topology(struct Mesh *mesh, MPoly &poly = mpoly[i]; loop_counts.push_back(poly.totloop); - smooth_normal |= ((poly.flag & ME_SMOOTH) != 0); + r_export_loop_normals |= (poly.flag & ME_SMOOTH) != 0; MLoop *loop = mloop + poly.loopstart + (poly.totloop - 1); @@ -203,17 +205,14 @@ static void get_loop_normals(struct Mesh *mesh, std::vector<Imath::V3f> &normals normals.clear(); normals.resize(mesh->totloop); - unsigned loop_index = 0; - /* NOTE: data needs to be written in the reverse order. */ + int abc_index = 0; if (lnors) { for (int i = 0, e = mesh->totpoly; i < e; ++i, ++mp) { - ml = mloop + mp->loopstart + (mp->totloop - 1); - - for (int j = 0; j < mp->totloop; --ml, ++j, ++loop_index) { - const int index = ml->v; - copy_yup_from_zup(normals[loop_index].getValue(), lnors[index]); + for (int j = mp->totloop - 1; j >= 0; --j, ++abc_index) { + int blender_index = mp->loopstart + j; + copy_yup_from_zup(normals[abc_index].getValue(), lnors[blender_index]); } } } @@ -227,15 +226,15 @@ static void get_loop_normals(struct Mesh *mesh, std::vector<Imath::V3f> &normals if ((mp->flag & ME_SMOOTH) == 0) { BKE_mesh_calc_poly_normal(mp, ml - (mp->totloop - 1), verts, no); - for (int j = 0; j < mp->totloop; --ml, ++j, ++loop_index) { - copy_yup_from_zup(normals[loop_index].getValue(), no); + for (int j = 0; j < mp->totloop; --ml, ++j, ++abc_index) { + copy_yup_from_zup(normals[abc_index].getValue(), no); } } else { /* Smooth shaded, use individual vert normals. */ - for (int j = 0; j < mp->totloop; --ml, ++j, ++loop_index) { + for (int j = 0; j < mp->totloop; --ml, ++j, ++abc_index) { normal_short_to_float_v3(no, verts[ml->v].no); - copy_yup_from_zup(normals[loop_index].getValue(), no); + copy_yup_from_zup(normals[abc_index].getValue(), no); } } } @@ -411,10 +410,10 @@ void AbcGenericMeshWriter::writeMesh(struct Mesh *mesh) std::vector<int32_t> poly_verts, loop_counts; std::vector<Imath::V3f> velocities; - bool smooth_normal = false; + bool export_loop_normals = (mesh->flag & ME_AUTOSMOOTH) != 0; get_vertices(mesh, points); - get_topology(mesh, poly_verts, loop_counts, smooth_normal); + get_topology(mesh, poly_verts, loop_counts, export_loop_normals); if (m_first_frame && m_settings.export_face_sets) { writeFaceSets(mesh, m_mesh_schema); @@ -442,7 +441,7 @@ void AbcGenericMeshWriter::writeMesh(struct Mesh *mesh) } if (m_settings.export_normals) { - if (smooth_normal) { + if (export_loop_normals) { get_loop_normals(mesh, normals); } else { @@ -451,7 +450,7 @@ void AbcGenericMeshWriter::writeMesh(struct Mesh *mesh) ON3fGeomParam::Sample normals_sample; if (!normals.empty()) { - normals_sample.setScope((smooth_normal) ? kFacevaryingScope : kVertexScope); + normals_sample.setScope(export_loop_normals ? kFacevaryingScope : kVertexScope); normals_sample.setVals(V3fArraySample(normals)); } @@ -477,10 +476,10 @@ void AbcGenericMeshWriter::writeSubD(struct Mesh *mesh) std::vector<int32_t> poly_verts, loop_counts; std::vector<int32_t> crease_indices, crease_lengths; - bool smooth_normal = false; + bool export_loop_normals = false; get_vertices(mesh, points); - get_topology(mesh, poly_verts, loop_counts, smooth_normal); + get_topology(mesh, poly_verts, loop_counts, export_loop_normals); get_creases(mesh, crease_indices, crease_lengths, crease_sharpness); if (m_first_frame && m_settings.export_face_sets) { @@ -758,7 +757,8 @@ struct AbcMeshData { P3fArraySamplePtr ceil_positions; N3fArraySamplePtr vertex_normals; - N3fArraySamplePtr face_normals; + N3fArraySamplePtr loop_normals; + bool poly_flag_smooth; V2fArraySamplePtr uvs; UInt32ArraySamplePtr uvs_indices; @@ -832,7 +832,6 @@ static void read_mpolys(CDStreamConfig &config, const AbcMeshData &mesh_data) const size_t uvs_size = uvs == nullptr ? 0 : uvs->size(); const UInt32ArraySamplePtr &uvs_indices = mesh_data.uvs_indices; - const N3fArraySamplePtr &normals = mesh_data.face_normals; const bool do_uvs = (mloopuvs && uvs && uvs_indices) && (uvs_indices->size() == face_indices->size()); @@ -847,9 +846,12 @@ static void read_mpolys(CDStreamConfig &config, const AbcMeshData &mesh_data) poly.loopstart = loop_index; poly.totloop = face_size; - if (normals != NULL) { + if (mesh_data.poly_flag_smooth) { poly.flag |= ME_SMOOTH; } + else { + poly.flag &= ~ME_SMOOTH; + } /* NOTE: Alembic data is stored in the reverse order. */ rev_loop_index = loop_index + (face_size - 1); @@ -873,6 +875,40 @@ static void read_mpolys(CDStreamConfig &config, const AbcMeshData &mesh_data) } } } + + BKE_mesh_calc_edges(config.mesh, false, false); +} + +static void process_normals(CDStreamConfig &config, const AbcMeshData &mesh_data) +{ + Mesh *mesh = config.mesh; + + if (!mesh_data.loop_normals) { + BKE_mesh_calc_normals(config.mesh); + config.mesh->flag &= ~ME_AUTOSMOOTH; + return; + } + + config.mesh->flag |= ME_AUTOSMOOTH; + + const Alembic::AbcGeom::N3fArraySample &loop_normals = *mesh_data.loop_normals; + long int loop_count = loop_normals.size(); + + float(*lnors)[3] = static_cast<float(*)[3]>( + MEM_malloc_arrayN(loop_count, sizeof(float[3]), "ABC::FaceNormals")); + + MPoly *mpoly = mesh->mpoly; + int abc_index = 0; + for (int i = 0, e = mesh->totpoly; i < e; ++i, ++mpoly) { + /* As usual, ABC orders the loops in reverse. */ + for (int j = mpoly->totloop - 1; j >= 0; --j, ++abc_index) { + int blender_index = mpoly->loopstart + j; + copy_zup_from_yup(lnors[blender_index], loop_normals[abc_index].getValue()); + } + } + BKE_mesh_set_custom_normals(config.mesh, lnors); + + MEM_freeN(lnors); } ABC_INLINE void read_uvs_params(CDStreamConfig &config, @@ -900,15 +936,11 @@ ABC_INLINE void read_uvs_params(CDStreamConfig &config, name = uv.getName(); } - void *cd_ptr = config.add_customdata_cb(config.user_data, name.c_str(), CD_MLOOPUV); + void *cd_ptr = config.add_customdata_cb(config.mesh, name.c_str(), CD_MLOOPUV); config.mloopuv = static_cast<MLoopUV *>(cd_ptr); } } -/* TODO(kevin): normals from Alembic files are not read in anymore, this is due - * to the fact that there are many issues that are not so easy to solve, mainly - * regarding the way normals are handled in Blender (MPoly.flag vs loop normals). - */ ABC_INLINE void read_normals_params(AbcMeshData &abc_data, const IN3fGeomParam &normals, const ISampleSelector &selector) @@ -919,42 +951,26 @@ ABC_INLINE void read_normals_params(AbcMeshData &abc_data, IN3fGeomParam::Sample normsamp = normals.getExpandedValue(selector); - if (normals.getScope() == kFacevaryingScope) { - abc_data.face_normals = normsamp.getVals(); - } - else if ((normals.getScope() == kVertexScope) || (normals.getScope() == kVaryingScope)) { - abc_data.vertex_normals = N3fArraySamplePtr(); - } -} - -static bool check_smooth_poly_flag(Mesh *mesh) -{ - MPoly *mpolys = mesh->mpoly; - - for (int i = 0, e = mesh->totpoly; i < e; ++i) { - MPoly &poly = mpolys[i]; - - if ((poly.flag & ME_SMOOTH) != 0) { - return true; - } - } - - return false; -} - -static void set_smooth_poly_flag(Mesh *mesh) -{ - MPoly *mpolys = mesh->mpoly; - - for (int i = 0, e = mesh->totpoly; i < e; ++i) { - MPoly &poly = mpolys[i]; - poly.flag |= ME_SMOOTH; + Alembic::AbcGeom::GeometryScope scope = normals.getScope(); + switch (scope) { + case Alembic::AbcGeom::kFacevaryingScope: + abc_data.loop_normals = normsamp.getVals(); + break; + case Alembic::AbcGeom::kVertexScope: + case Alembic::AbcGeom::kVaryingScope: + /* Vertex normals from ABC aren't handled for now. */ + abc_data.poly_flag_smooth = true; + abc_data.vertex_normals = N3fArraySamplePtr(); + break; + case Alembic::AbcGeom::kConstantScope: + case Alembic::AbcGeom::kUniformScope: + case Alembic::AbcGeom::kUnknownScope: + break; } } -static void *add_customdata_cb(void *user_data, const char *name, int data_type) +static void *add_customdata_cb(Mesh *mesh, const char *name, int data_type) { - Mesh *mesh = static_cast<Mesh *>(user_data); CustomDataType cd_data_type = static_cast<CustomDataType>(data_type); void *cd_ptr; CustomData *loopdata; @@ -994,8 +1010,7 @@ static void read_mesh_sample(const std::string &iobject_full_name, ImportSettings *settings, const IPolyMeshSchema &schema, const ISampleSelector &selector, - CDStreamConfig &config, - bool &do_normals) + CDStreamConfig &config) { const IPolyMeshSchema::Sample sample = schema.getValue(selector); @@ -1003,11 +1018,10 @@ static void read_mesh_sample(const std::string &iobject_full_name, abc_mesh_data.face_counts = sample.getFaceCounts(); abc_mesh_data.face_indices = sample.getFaceIndices(); abc_mesh_data.positions = sample.getPositions(); + abc_mesh_data.poly_flag_smooth = false; read_normals_params(abc_mesh_data, schema.getNormalsParam(), selector); - do_normals = (abc_mesh_data.face_normals != NULL); - get_weight_and_index(config, schema.getTimeSampling(), schema.getNumSamples()); if (config.weight != 0.0f) { @@ -1026,6 +1040,7 @@ static void read_mesh_sample(const std::string &iobject_full_name, if ((settings->read_flag & MOD_MESHSEQ_READ_POLY) != 0) { read_mpolys(config, abc_mesh_data); + process_normals(config, abc_mesh_data); } if ((settings->read_flag & (MOD_MESHSEQ_READ_UV | MOD_MESHSEQ_READ_COLOR)) != 0) { @@ -1039,7 +1054,7 @@ CDStreamConfig get_config(Mesh *mesh) BLI_assert(mesh->mvert || mesh->totvert == 0); - config.user_data = mesh; + config.mesh = mesh; config.mvert = mesh->mvert; config.mloop = mesh->mloop; config.mpoly = mesh->mpoly; @@ -1078,14 +1093,18 @@ void AbcMeshReader::readObjectData(Main *bmain, const Alembic::Abc::ISampleSelec Mesh *read_mesh = this->read_mesh(mesh, sample_sel, MOD_MESHSEQ_READ_ALL, NULL); if (read_mesh != mesh) { + /* XXX fixme after 2.80; mesh->flag isn't copied by BKE_mesh_nomain_to_mesh() */ + /* read_mesh can be freed by BKE_mesh_nomain_to_mesh(), so get the flag before that happens. */ + short autosmooth = (read_mesh->flag & ME_AUTOSMOOTH); BKE_mesh_nomain_to_mesh(read_mesh, mesh, m_object, &CD_MASK_MESH, true); + mesh->flag |= autosmooth; } if (m_settings->validate_meshes) { BKE_mesh_validate(mesh, false, false); } - readFaceSetsSample(bmain, mesh, 0, sample_sel); + readFaceSetsSample(bmain, mesh, sample_sel); if (has_animations(m_schema, m_settings)) { addCacheModifier(); @@ -1151,6 +1170,8 @@ Mesh *AbcMeshReader::read_mesh(Mesh *existing_mesh, existing_mesh, positions->size(), 0, 0, face_indices->size(), face_counts->size()); settings.read_flag |= MOD_MESHSEQ_READ_ALL; + /* XXX fixme after 2.80; mesh->flag isn't copied by BKE_mesh_new_nomain_from_template() */ + new_mesh->flag |= (existing_mesh->flag & ME_AUTOSMOOTH); } else { /* If the face count changed (e.g. by triangulation), only read points. @@ -1171,39 +1192,25 @@ Mesh *AbcMeshReader::read_mesh(Mesh *existing_mesh, CDStreamConfig config = get_config(new_mesh ? new_mesh : existing_mesh); config.time = sample_sel.getRequestedTime(); - bool do_normals = false; - read_mesh_sample(m_iobject.getFullName(), &settings, m_schema, sample_sel, config, do_normals); + read_mesh_sample(m_iobject.getFullName(), &settings, m_schema, sample_sel, config); if (new_mesh) { - /* Check if we had ME_SMOOTH flag set to restore it. */ - if (!do_normals && check_smooth_poly_flag(existing_mesh)) { - set_smooth_poly_flag(new_mesh); - } - - BKE_mesh_calc_normals(new_mesh); - BKE_mesh_calc_edges(new_mesh, false, false); - /* Here we assume that the number of materials doesn't change, i.e. that * the material slots that were created when the object was loaded from * Alembic are still valid now. */ size_t num_polys = new_mesh->totpoly; if (num_polys > 0) { std::map<std::string, int> mat_map; - assign_facesets_to_mpoly(sample_sel, 0, new_mesh->mpoly, num_polys, mat_map); + assign_facesets_to_mpoly(sample_sel, new_mesh->mpoly, num_polys, mat_map); } return new_mesh; } - if (do_normals) { - BKE_mesh_calc_normals(existing_mesh); - } - return existing_mesh; } void AbcMeshReader::assign_facesets_to_mpoly(const ISampleSelector &sample_sel, - size_t poly_start, MPoly *mpoly, int totpoly, std::map<std::string, int> &r_mat_map) @@ -1239,7 +1246,7 @@ void AbcMeshReader::assign_facesets_to_mpoly(const ISampleSelector &sample_sel, const size_t num_group_faces = group_faces->size(); for (size_t l = 0; l < num_group_faces; l++) { - size_t pos = (*group_faces)[l] + poly_start; + size_t pos = (*group_faces)[l]; if (pos >= totpoly) { std::cerr << "Faceset overflow on " << faceset.getName() << '\n'; @@ -1252,13 +1259,10 @@ void AbcMeshReader::assign_facesets_to_mpoly(const ISampleSelector &sample_sel, } } -void AbcMeshReader::readFaceSetsSample(Main *bmain, - Mesh *mesh, - size_t poly_start, - const ISampleSelector &sample_sel) +void AbcMeshReader::readFaceSetsSample(Main *bmain, Mesh *mesh, const ISampleSelector &sample_sel) { std::map<std::string, int> mat_map; - assign_facesets_to_mpoly(sample_sel, poly_start, mesh->mpoly, mesh->totpoly, mat_map); + assign_facesets_to_mpoly(sample_sel, mesh->mpoly, mesh->totpoly, mat_map); utils::assign_materials(bmain, m_object, mat_map); } @@ -1289,7 +1293,7 @@ static void read_subd_sample(const std::string &iobject_full_name, abc_mesh_data.face_counts = sample.getFaceCounts(); abc_mesh_data.face_indices = sample.getFaceIndices(); abc_mesh_data.vertex_normals = N3fArraySamplePtr(); - abc_mesh_data.face_normals = N3fArraySamplePtr(); + abc_mesh_data.loop_normals = N3fArraySamplePtr(); abc_mesh_data.positions = sample.getPositions(); get_weight_and_index(config, schema.getTimeSampling(), schema.getNumSamples()); @@ -1309,7 +1313,14 @@ static void read_subd_sample(const std::string &iobject_full_name, } if ((settings->read_flag & MOD_MESHSEQ_READ_POLY) != 0) { + /* Alembic's 'SubD' scheme is used to store subdivision surfaces, i.e. the pre-subdivision + * mesh. Currently we don't add a subdivison modifier when we load such data. This code is + * assuming that the subdivided surface should be smooth, and sets a flag that will eventually + * mark all polygons as such. */ + abc_mesh_data.poly_flag_smooth = true; + read_mpolys(config, abc_mesh_data); + process_normals(config, abc_mesh_data); } if ((settings->read_flag & (MOD_MESHSEQ_READ_UV | MOD_MESHSEQ_READ_COLOR)) != 0) { @@ -1397,9 +1408,6 @@ void AbcSubDReader::readObjectData(Main *bmain, const Alembic::Abc::ISampleSelec mesh->cd_flag |= ME_CDFLAG_EDGE_CREASE; } - BKE_mesh_calc_normals(mesh); - BKE_mesh_calc_edges(mesh, false, false); - if (m_settings->validate_meshes) { BKE_mesh_validate(mesh, false, false); } @@ -1466,17 +1474,5 @@ Mesh *AbcSubDReader::read_mesh(Mesh *existing_mesh, config.time = sample_sel.getRequestedTime(); read_subd_sample(m_iobject.getFullName(), &settings, m_schema, sample_sel, config); - if (new_mesh) { - /* Check if we had ME_SMOOTH flag set to restore it. */ - if (check_smooth_poly_flag(existing_mesh)) { - set_smooth_poly_flag(new_mesh); - } - - BKE_mesh_calc_normals(new_mesh); - BKE_mesh_calc_edges(new_mesh, false, false); - - return new_mesh; - } - - return existing_mesh; + return config.mesh; } diff --git a/source/blender/alembic/intern/abc_mesh.h b/source/blender/alembic/intern/abc_mesh.h index 6cbaeea6536..859ab121eb6 100644 --- a/source/blender/alembic/intern/abc_mesh.h +++ b/source/blender/alembic/intern/abc_mesh.h @@ -114,11 +114,9 @@ class AbcMeshReader : public AbcObjectReader { private: void readFaceSetsSample(Main *bmain, Mesh *mesh, - size_t poly_start, const Alembic::AbcGeom::ISampleSelector &sample_sel); void assign_facesets_to_mpoly(const Alembic::Abc::ISampleSelector &sample_sel, - size_t poly_start, MPoly *mpoly, int totpoly, std::map<std::string, int> &r_mat_map); diff --git a/source/blender/alembic/intern/abc_object.cc b/source/blender/alembic/intern/abc_object.cc index 54450ce1cb2..f863fe4fee7 100644 --- a/source/blender/alembic/intern/abc_object.cc +++ b/source/blender/alembic/intern/abc_object.cc @@ -335,16 +335,17 @@ void AbcObjectReader::read_matrix(float r_mat[4][4], mul_m4_m4m4(r_mat, m_object->parent->obmat, r_mat); } else { - /* This can happen if the user deleted the parent object. */ - unit_m4(r_mat); + /* This can happen if the user deleted the parent object, but also if the Alembic parent was + * not imported (because of unknown/unsupported schema, for example). In that case just use + * the local matrix as if it is the world matrix. This allows us to import Alembic files from + * MeshRoom, see T61935. */ } } else { /* Only apply scaling to root objects, parenting will propagate it. */ float scale_mat[4][4]; scale_m4_fl(scale_mat, scale); - scale_mat[3][3] = scale; /* scale translations too */ - mul_m4_m4m4(r_mat, r_mat, scale_mat); + mul_m4_m4m4(r_mat, scale_mat, r_mat); } is_constant = schema.isConstant(); diff --git a/source/blender/alembic/intern/alembic_capi.cc b/source/blender/alembic/intern/alembic_capi.cc index b502692d0e5..d63b310fef7 100644 --- a/source/blender/alembic/intern/alembic_capi.cc +++ b/source/blender/alembic/intern/alembic_capi.cc @@ -19,7 +19,6 @@ */ #include "../ABC_alembic.h" -#include <boost/foreach.hpp> #include <Alembic/AbcMaterial/IMaterial.h> @@ -567,11 +566,10 @@ static std::pair<bool, AbcObjectReader *> visit_object( /* We can now assign this reader as parent for our children. */ if (nonclaiming_child_readers.size() + assign_as_parent.size() > 0) { - /* TODO: When we only support C++11, use for (a: b) instead. */ - BOOST_FOREACH (AbcObjectReader *child_reader, nonclaiming_child_readers) { + for (AbcObjectReader *child_reader : nonclaiming_child_readers) { child_reader->parent_reader = reader; } - BOOST_FOREACH (AbcObjectReader *child_reader, assign_as_parent) { + for (AbcObjectReader *child_reader : assign_as_parent) { child_reader->parent_reader = reader; } } @@ -582,14 +580,14 @@ static std::pair<bool, AbcObjectReader *> visit_object( * our non-claiming children. Since all claiming children share * the same XForm, it doesn't really matter which one we pick. */ AbcObjectReader *claiming_child = claiming_child_readers[0]; - BOOST_FOREACH (AbcObjectReader *child_reader, nonclaiming_child_readers) { + for (AbcObjectReader *child_reader : nonclaiming_child_readers) { child_reader->parent_reader = claiming_child; } - BOOST_FOREACH (AbcObjectReader *child_reader, assign_as_parent) { + for (AbcObjectReader *child_reader : assign_as_parent) { child_reader->parent_reader = claiming_child; } /* Claiming children should have our parent set as their parent. */ - BOOST_FOREACH (AbcObjectReader *child_reader, claiming_child_readers) { + for (AbcObjectReader *child_reader : claiming_child_readers) { r_assign_as_parent.push_back(child_reader); } } @@ -597,13 +595,13 @@ static std::pair<bool, AbcObjectReader *> visit_object( /* This object isn't claimed by any child, and didn't produce * a reader. Odd situation, could be the top Alembic object, or * an unsupported Alembic schema. Delegate to our parent. */ - BOOST_FOREACH (AbcObjectReader *child_reader, claiming_child_readers) { + for (AbcObjectReader *child_reader : claiming_child_readers) { r_assign_as_parent.push_back(child_reader); } - BOOST_FOREACH (AbcObjectReader *child_reader, nonclaiming_child_readers) { + for (AbcObjectReader *child_reader : nonclaiming_child_readers) { r_assign_as_parent.push_back(child_reader); } - BOOST_FOREACH (AbcObjectReader *child_reader, assign_as_parent) { + for (AbcObjectReader *child_reader : assign_as_parent) { r_assign_as_parent.push_back(child_reader); } } @@ -782,7 +780,7 @@ static void import_endjob(void *user_data) std::vector<AbcObjectReader *>::iterator iter; - /* Delete objects on cancelation. */ + /* Delete objects on cancellation. */ if (data->was_cancelled) { for (iter = data->readers.begin(); iter != data->readers.end(); ++iter) { Object *ob = (*iter)->object(); diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h index 448bb0d621a..bf0aa96df84 100644 --- a/source/blender/blenfont/BLF_api.h +++ b/source/blender/blenfont/BLF_api.h @@ -223,6 +223,7 @@ void BLF_dir_free(char **dirs, int count) ATTR_NONNULL(); /* blf_thumbs.c */ void BLF_thumb_preview(const char *filename, const char **draw_str, + const char **i18n_draw_str, const unsigned char draw_str_lines, const float font_color[4], const int font_size, diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c index 049af7678d5..66be94aaa06 100644 --- a/source/blender/blenfont/intern/blf_glyph.c +++ b/source/blender/blenfont/intern/blf_glyph.c @@ -96,7 +96,7 @@ KerningCacheBLF *blf_kerning_cache_new(FontBLF *font) .x = 0, .y = 0, }; - if (g_prev && FT_Get_Kerning(font->face, g_prev->idx, g->idx, kc->mode, &delta) == 0) { + if (g && g_prev && FT_Get_Kerning(font->face, g_prev->idx, g->idx, kc->mode, &delta) == 0) { kc->table[i][j] = (int)delta.x >> 6; } else { diff --git a/source/blender/blenfont/intern/blf_thumbs.c b/source/blender/blenfont/intern/blf_thumbs.c index 802f97fc5f5..d6710b91539 100644 --- a/source/blender/blenfont/intern/blf_thumbs.c +++ b/source/blender/blenfont/intern/blf_thumbs.c @@ -50,6 +50,7 @@ */ void BLF_thumb_preview(const char *filename, const char **draw_str, + const char **i18n_draw_str, const unsigned char draw_str_lines, const float font_color[4], const int font_size, @@ -90,7 +91,7 @@ void BLF_thumb_preview(const char *filename, blf_draw_buffer__start(font); for (i = 0; i < draw_str_lines; i++) { - const char *draw_str_i18n = BLT_translate_do(BLT_I18NCONTEXT_DEFAULT, draw_str[i]); + const char *draw_str_i18n = i18n_draw_str[i] != NULL ? i18n_draw_str[i] : draw_str[i]; const size_t draw_str_i18n_len = strlen(draw_str_i18n); int draw_str_i18n_nbr = 0; diff --git a/source/blender/blenkernel/BKE_animsys.h b/source/blender/blenkernel/BKE_animsys.h index 64a8c78cfef..fa8e294bdc1 100644 --- a/source/blender/blenkernel/BKE_animsys.h +++ b/source/blender/blenkernel/BKE_animsys.h @@ -217,10 +217,10 @@ void BKE_fcurves_id_cb(struct ID *id, ID_FCurve_Edit_Callback func, void *user_d typedef struct NlaKeyframingContext NlaKeyframingContext; struct NlaKeyframingContext *BKE_animsys_get_nla_keyframing_context(struct ListBase *cache, - struct Depsgraph *depsgraph, struct PointerRNA *ptr, struct AnimData *adt, - float ctime); + float ctime, + const bool flush_to_original); bool BKE_animsys_nla_remap_keyframe_values(struct NlaKeyframingContext *context, struct PointerRNA *prop_ptr, struct PropertyRNA *prop, @@ -244,12 +244,12 @@ typedef enum eAnimData_Recalc { } eAnimData_Recalc; /* Evaluation loop for evaluating animation data */ -void BKE_animsys_evaluate_animdata(struct Depsgraph *depsgraph, - struct Scene *scene, +void BKE_animsys_evaluate_animdata(struct Scene *scene, struct ID *id, struct AnimData *adt, float ctime, - short recalc); + short recalc, + const bool flush_to_original); /* Evaluation of all ID-blocks with Animation Data blocks - Animation Data Only */ void BKE_animsys_evaluate_all_animation(struct Main *main, @@ -269,10 +269,10 @@ bool BKE_animsys_execute_fcurve(struct PointerRNA *ptr, struct FCurve *fcu, floa */ /* Evaluate Action (F-Curve Bag) */ -void animsys_evaluate_action(struct Depsgraph *depsgraph, - struct PointerRNA *ptr, +void animsys_evaluate_action(struct PointerRNA *ptr, struct bAction *act, - float ctime); + float ctime, + const bool flush_to_original); /* Evaluate Action Group */ void animsys_evaluate_action_group(struct PointerRNA *ptr, diff --git a/source/blender/blenkernel/BKE_armature.h b/source/blender/blenkernel/BKE_armature.h index 73e62f6a7b3..99c6bb405b5 100644 --- a/source/blender/blenkernel/BKE_armature.h +++ b/source/blender/blenkernel/BKE_armature.h @@ -75,6 +75,9 @@ void BKE_armature_copy_data(struct Main *bmain, const int flag); struct bArmature *BKE_armature_copy(struct Main *bmain, const struct bArmature *arm); +void BKE_armature_copy_bone_transforms(struct bArmature *armature_dst, + const struct bArmature *armature_src); + /* Bounding box. */ struct BoundBox *BKE_armature_boundbox_get(struct Object *ob); diff --git a/source/blender/blenkernel/BKE_blender_version.h b/source/blender/blenkernel/BKE_blender_version.h index a400e4411cf..ced9f4a3153 100644 --- a/source/blender/blenkernel/BKE_blender_version.h +++ b/source/blender/blenkernel/BKE_blender_version.h @@ -26,8 +26,8 @@ * * \note Use #STRINGIFY() rather than defining with quotes. */ -#define BLENDER_VERSION 280 -#define BLENDER_SUBVERSION 75 +#define BLENDER_VERSION 281 +#define BLENDER_SUBVERSION 1 /** Several breakages with 280, e.g. collections vs layers. */ #define BLENDER_MINVERSION 280 #define BLENDER_MINSUBVERSION 0 @@ -36,7 +36,7 @@ /** Can be left blank, otherwise a,b,c... etc with no quotes. */ #define BLENDER_VERSION_CHAR /** alpha/beta/rc/release, docs use this. */ -#define BLENDER_VERSION_CYCLE beta +#define BLENDER_VERSION_CYCLE alpha /** Defined in from blender.c */ extern char versionstr[]; diff --git a/source/blender/blenkernel/BKE_blendfile.h b/source/blender/blenkernel/BKE_blendfile.h index 76c05b0411a..2bff684948d 100644 --- a/source/blender/blenkernel/BKE_blendfile.h +++ b/source/blender/blenkernel/BKE_blendfile.h @@ -32,12 +32,6 @@ struct ReportList; struct UserDef; struct bContext; -enum { - BKE_BLENDFILE_READ_FAIL = 0, /* no load */ - BKE_BLENDFILE_READ_OK = 1, /* OK */ - BKE_BLENDFILE_READ_OK_USERPREFS = 2, /* OK, and with new user settings */ -}; - int BKE_blendfile_read(struct bContext *C, const char *filepath, const struct BlendFileReadParams *params, @@ -58,6 +52,7 @@ struct UserDef *BKE_blendfile_userdef_read(const char *filepath, struct ReportLi struct UserDef *BKE_blendfile_userdef_read_from_memory(const void *filebuf, int filelength, struct ReportList *reports); +struct UserDef *BKE_blendfile_userdef_from_defaults(void); bool BKE_blendfile_userdef_write(const char *filepath, struct ReportList *reports); bool BKE_blendfile_userdef_write_app_template(const char *filepath, struct ReportList *reports); diff --git a/source/blender/blenkernel/BKE_context.h b/source/blender/blenkernel/BKE_context.h index 0d2998cc51e..53976b4c1ad 100644 --- a/source/blender/blenkernel/BKE_context.h +++ b/source/blender/blenkernel/BKE_context.h @@ -318,7 +318,14 @@ int CTX_data_editable_gpencil_strokes(const bContext *C, ListBase *list); * evaluated data points of view. * * NOTE: Can not be used if access to a fully evaluated datablock is needed. */ -struct Depsgraph *CTX_data_depsgraph(const bContext *C); +struct Depsgraph *CTX_data_depsgraph_pointer(const bContext *C); + +/* Get dependency graph which is expected to be fully evaluated. + * + * In the release builds it is the same as CTX_data_depsgraph_pointer(). In the debug builds extra + * sanity checks are done. Additionally, this provides more semantic meaning to what is exactly + * expected to happen. */ +struct Depsgraph *CTX_data_expect_evaluated_depsgraph(const bContext *C); /* Gets fully updated and evaluated dependency graph. * @@ -326,7 +333,7 @@ struct Depsgraph *CTX_data_depsgraph(const bContext *C); * * NOTE: Will be expensive if there are relations or objects tagged for update. * NOTE: If there are pending updates depsgraph hooks will be invoked. */ -struct Depsgraph *CTX_data_evaluated_depsgraph(const bContext *C); +struct Depsgraph *CTX_data_ensure_evaluated_depsgraph(const bContext *C); /* Will Return NULL if depsgraph is not allocated yet. * Only used by handful of operators which are run on file load. diff --git a/source/blender/blenkernel/BKE_curve.h b/source/blender/blenkernel/BKE_curve.h index df1e7a7baea..51ff4673aba 100644 --- a/source/blender/blenkernel/BKE_curve.h +++ b/source/blender/blenkernel/BKE_curve.h @@ -109,6 +109,7 @@ void BKE_curve_transform(struct Curve *cu, const bool do_props); void BKE_curve_translate(struct Curve *cu, float offset[3], const bool do_keys); void BKE_curve_material_index_remove(struct Curve *cu, int index); +bool BKE_curve_material_index_used(struct Curve *cu, int index); void BKE_curve_material_index_clear(struct Curve *cu); bool BKE_curve_material_index_validate(struct Curve *cu); void BKE_curve_material_remap(struct Curve *cu, const unsigned int *remap, unsigned int remap_len); diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h index ae1000d1b99..60e9e6b91d3 100644 --- a/source/blender/blenkernel/BKE_gpencil.h +++ b/source/blender/blenkernel/BKE_gpencil.h @@ -87,6 +87,7 @@ void BKE_gpencil_frame_delete_laststroke(struct bGPDlayer *gpl, struct bGPDframe /* materials */ void BKE_gpencil_material_index_reassign(struct bGPdata *gpd, int totcol, int index); +bool BKE_gpencil_material_index_used(struct bGPdata *gpd, int index); void BKE_gpencil_material_remap(struct bGPdata *gpd, const unsigned int *remap, unsigned int remap_len); diff --git a/source/blender/blenkernel/BKE_material.h b/source/blender/blenkernel/BKE_material.h index 9d8b9218a79..b1200c7e608 100644 --- a/source/blender/blenkernel/BKE_material.h +++ b/source/blender/blenkernel/BKE_material.h @@ -28,6 +28,7 @@ extern "C" { #endif +struct bNode; struct ID; struct Main; struct Material; @@ -89,11 +90,13 @@ void assign_matarar(struct Main *bmain, struct Object *ob, struct Material ***ma short BKE_object_material_slot_find_index(struct Object *ob, struct Material *ma); bool BKE_object_material_slot_add(struct Main *bmain, struct Object *ob); bool BKE_object_material_slot_remove(struct Main *bmain, struct Object *ob); +bool BKE_object_material_slot_used(struct ID *id, short actcol); struct MaterialGPencilStyle *BKE_material_gpencil_settings_get(struct Object *ob, short act); void BKE_texpaint_slot_refresh_cache(struct Scene *scene, struct Material *ma); void BKE_texpaint_slots_refresh_object(struct Scene *scene, struct Object *ob); +struct bNode *BKE_texpaint_slot_material_find_node(struct Material *ma, short texpaint_slot); /* rna api */ void BKE_material_resize_id(struct Main *bmain, struct ID *id, short totcol, bool do_id_user); diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h index 54fbda1fa31..59812df246f 100644 --- a/source/blender/blenkernel/BKE_mesh.h +++ b/source/blender/blenkernel/BKE_mesh.h @@ -105,6 +105,7 @@ void BKE_mesh_looptri_get_real_edges(const struct Mesh *mesh, void BKE_mesh_free(struct Mesh *me); void BKE_mesh_init(struct Mesh *me); +void BKE_mesh_clear_geometry(struct Mesh *me); struct Mesh *BKE_mesh_add(struct Main *bmain, const char *name); void BKE_mesh_copy_data(struct Main *bmain, struct Mesh *me_dst, @@ -123,6 +124,8 @@ struct Mesh *BKE_mesh_new_nomain_from_template(const struct Mesh *me_src, int loops_len, int polys_len); +void BKE_mesh_eval_delete(struct Mesh *me_eval); + /* Performs copy for use during evaluation, * optional referencing original arrays to reduce memory. */ struct Mesh *BKE_mesh_copy_for_eval(struct Mesh *source, bool reference); @@ -179,6 +182,7 @@ void BKE_mesh_to_curve(struct Main *bmain, struct Scene *scene, struct Object *ob); void BKE_mesh_material_index_remove(struct Mesh *me, short index); +bool BKE_mesh_material_index_used(struct Mesh *me, short index); void BKE_mesh_material_index_clear(struct Mesh *me); void BKE_mesh_material_remap(struct Mesh *me, const unsigned int *remap, unsigned int remap_len); void BKE_mesh_smooth_flag_set(struct Object *meshOb, int enableSmooth); diff --git a/source/blender/blenkernel/BKE_movieclip.h b/source/blender/blenkernel/BKE_movieclip.h index 9425f396bc5..14d7784f93e 100644 --- a/source/blender/blenkernel/BKE_movieclip.h +++ b/source/blender/blenkernel/BKE_movieclip.h @@ -118,7 +118,9 @@ bool BKE_movieclip_put_frame_if_possible(struct MovieClip *clip, /* Dependency graph evaluation. */ -void BKE_movieclip_eval_update(struct Depsgraph *depsgraph, struct MovieClip *clip); +void BKE_movieclip_eval_update(struct Depsgraph *depsgraph, + struct Main *bmain, + struct MovieClip *clip); void BKE_movieclip_eval_selection_update(struct Depsgraph *depsgraph, struct MovieClip *clip); /* caching flags */ diff --git a/source/blender/blenkernel/BKE_text.h b/source/blender/blenkernel/BKE_text.h index 6509788932c..f018e912945 100644 --- a/source/blender/blenkernel/BKE_text.h +++ b/source/blender/blenkernel/BKE_text.h @@ -90,10 +90,10 @@ void txt_backspace_word(struct Text *text); bool txt_add_char(struct Text *text, unsigned int add); bool txt_add_raw_char(struct Text *text, unsigned int add); bool txt_replace_char(struct Text *text, unsigned int add); -void txt_unindent(struct Text *text); +bool txt_unindent(struct Text *text); void txt_comment(struct Text *text); void txt_indent(struct Text *text); -void txt_uncomment(struct Text *text); +bool txt_uncomment(struct Text *text); void txt_move_lines(struct Text *text, const int direction); void txt_duplicate_line(struct Text *text); int txt_setcurr_tab_spaces(struct Text *text, int space); diff --git a/source/blender/blenkernel/BKE_tracking.h b/source/blender/blenkernel/BKE_tracking.h index 6b6eb24d5fa..bf417403d43 100644 --- a/source/blender/blenkernel/BKE_tracking.h +++ b/source/blender/blenkernel/BKE_tracking.h @@ -355,6 +355,12 @@ void BKE_tracking_reconstruction_solve(struct MovieReconstructContext *context, bool BKE_tracking_reconstruction_finish(struct MovieReconstructContext *context, struct MovieTracking *tracking); +void BKE_tracking_reconstruction_report_error_message(struct MovieReconstructContext *context, + const char *error_message); + +const char *BKE_tracking_reconstruction_error_message_get( + const struct MovieReconstructContext *context); + void BKE_tracking_reconstruction_scale(struct MovieTracking *tracking, float scale[3]); /* **** Feature detection **** */ diff --git a/source/blender/blenkernel/BKE_undo_system.h b/source/blender/blenkernel/BKE_undo_system.h index 50c29c456d1..6d8e04336ac 100644 --- a/source/blender/blenkernel/BKE_undo_system.h +++ b/source/blender/blenkernel/BKE_undo_system.h @@ -48,6 +48,7 @@ UNDO_REF_ID_TYPE(Mesh); UNDO_REF_ID_TYPE(Object); UNDO_REF_ID_TYPE(Scene); UNDO_REF_ID_TYPE(Text); +UNDO_REF_ID_TYPE(Image); typedef struct UndoStack { ListBase steps; @@ -194,24 +195,6 @@ void BKE_undosys_foreach_ID_ref(UndoStack *ustack, void *user_data); #endif -/* Use when the undo step stores many arbitrary pointers. */ -struct UndoIDPtrMap; -struct UndoIDPtrMap *BKE_undosys_ID_map_create(void); -void BKE_undosys_ID_map_destroy(struct UndoIDPtrMap *map); -void BKE_undosys_ID_map_add(struct UndoIDPtrMap *map, ID *id); -struct ID *BKE_undosys_ID_map_lookup(const struct UndoIDPtrMap *map, const struct ID *id_src); - -void BKE_undosys_ID_map_add_with_prev(struct UndoIDPtrMap *map, - struct ID *id, - struct ID **id_prev); -struct ID *BKE_undosys_ID_map_lookup_with_prev(const struct UndoIDPtrMap *map, - struct ID *id_src, - struct ID *id_prev_match[2]); - -void BKE_undosys_ID_map_foreach_ID_ref(struct UndoIDPtrMap *map, - UndoTypeForEachIDRefFn foreach_ID_ref_fn, - void *user_data); - void BKE_undosys_print(UndoStack *ustack); #endif /* __BKE_UNDO_SYSTEM_H__ */ diff --git a/source/blender/blenkernel/BKE_writeffmpeg.h b/source/blender/blenkernel/BKE_writeffmpeg.h index 4d008f8d249..9da28c849d9 100644 --- a/source/blender/blenkernel/BKE_writeffmpeg.h +++ b/source/blender/blenkernel/BKE_writeffmpeg.h @@ -43,6 +43,7 @@ enum { FFMPEG_MKV = 9, FFMPEG_OGG = 10, FFMPEG_INVALID = 11, + FFMPEG_WEBM = 12, }; enum { diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index e564e91749c..d9bd87d97b5 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -58,6 +58,7 @@ set(INC_SYS ) set(SRC + ${CMAKE_SOURCE_DIR}/release/datafiles/userdef/userdef_default.c intern/CCGSubSurf.c intern/CCGSubSurf_legacy.c intern/CCGSubSurf_opensubdiv.c diff --git a/source/blender/blenkernel/intern/CCGSubSurf_legacy.c b/source/blender/blenkernel/intern/CCGSubSurf_legacy.c index 720c828664a..d8b30c9d4ef 100644 --- a/source/blender/blenkernel/intern/CCGSubSurf_legacy.c +++ b/source/blender/blenkernel/intern/CCGSubSurf_legacy.c @@ -135,7 +135,7 @@ typedef struct CCGSubSurfCalcSubdivData { } CCGSubSurfCalcSubdivData; static void ccgSubSurf__calcVertNormals_faces_accumulate_cb( - void *__restrict userdata, const int ptrIdx, const ParallelRangeTLS *__restrict UNUSED(tls)) + void *__restrict userdata, const int ptrIdx, const TaskParallelTLS *__restrict UNUSED(tls)) { CCGSubSurfCalcSubdivData *data = userdata; @@ -234,7 +234,7 @@ static void ccgSubSurf__calcVertNormals_faces_accumulate_cb( } static void ccgSubSurf__calcVertNormals_faces_finalize_cb( - void *__restrict userdata, const int ptrIdx, const ParallelRangeTLS *__restrict UNUSED(tls)) + void *__restrict userdata, const int ptrIdx, const TaskParallelTLS *__restrict UNUSED(tls)) { CCGSubSurfCalcSubdivData *data = userdata; @@ -273,7 +273,7 @@ static void ccgSubSurf__calcVertNormals_faces_finalize_cb( } static void ccgSubSurf__calcVertNormals_edges_accumulate_cb( - void *__restrict userdata, const int ptrIdx, const ParallelRangeTLS *__restrict UNUSED(tls)) + void *__restrict userdata, const int ptrIdx, const TaskParallelTLS *__restrict UNUSED(tls)) { CCGSubSurfCalcSubdivData *data = userdata; @@ -347,7 +347,7 @@ static void ccgSubSurf__calcVertNormals(CCGSubSurf *ss, }; { - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.min_iter_per_thread = CCG_TASK_LIMIT; BLI_task_parallel_range( @@ -379,7 +379,7 @@ static void ccgSubSurf__calcVertNormals(CCGSubSurf *ss, } { - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.min_iter_per_thread = CCG_TASK_LIMIT; BLI_task_parallel_range( @@ -387,7 +387,7 @@ static void ccgSubSurf__calcVertNormals(CCGSubSurf *ss, } { - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.min_iter_per_thread = CCG_TASK_LIMIT; BLI_task_parallel_range( @@ -425,7 +425,7 @@ static void ccgSubSurf__calcVertNormals(CCGSubSurf *ss, } static void ccgSubSurf__calcSubdivLevel_interior_faces_edges_midpoints_cb( - void *__restrict userdata, const int ptrIdx, const ParallelRangeTLS *__restrict UNUSED(tls)) + void *__restrict userdata, const int ptrIdx, const TaskParallelTLS *__restrict UNUSED(tls)) { CCGSubSurfCalcSubdivData *data = userdata; @@ -513,7 +513,7 @@ static void ccgSubSurf__calcSubdivLevel_interior_faces_edges_midpoints_cb( } static void ccgSubSurf__calcSubdivLevel_interior_faces_edges_centerpoints_shift_cb( - void *__restrict userdata, const int ptrIdx, const ParallelRangeTLS *__restrict UNUSED(tls)) + void *__restrict userdata, const int ptrIdx, const TaskParallelTLS *__restrict UNUSED(tls)) { CCGSubSurfCalcSubdivData *data = userdata; @@ -619,7 +619,7 @@ static void ccgSubSurf__calcSubdivLevel_interior_faces_edges_centerpoints_shift_ } static void ccgSubSurf__calcSubdivLevel_verts_copydata_cb( - void *__restrict userdata, const int ptrIdx, const ParallelRangeTLS *__restrict UNUSED(tls)) + void *__restrict userdata, const int ptrIdx, const TaskParallelTLS *__restrict UNUSED(tls)) { CCGSubSurfCalcSubdivData *data = userdata; @@ -691,7 +691,7 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss, }; { - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.min_iter_per_thread = CCG_TASK_LIMIT; BLI_task_parallel_range(0, @@ -991,7 +991,7 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss, } { - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.min_iter_per_thread = CCG_TASK_LIMIT; BLI_task_parallel_range(0, @@ -1012,7 +1012,7 @@ static void ccgSubSurf__calcSubdivLevel(CCGSubSurf *ss, } { - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.min_iter_per_thread = CCG_TASK_LIMIT; BLI_task_parallel_range( diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c index a7159f85dc2..984de700ce7 100644 --- a/source/blender/blenkernel/intern/action.c +++ b/source/blender/blenkernel/intern/action.c @@ -1612,6 +1612,6 @@ void what_does_obaction( adt.action = act; /* execute effects of Action on to workob (or it's PoseChannels) */ - BKE_animsys_evaluate_animdata(NULL, NULL, &workob->id, &adt, cframe, ADT_RECALC_ANIM); + BKE_animsys_evaluate_animdata(NULL, &workob->id, &adt, cframe, ADT_RECALC_ANIM, false); } } diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c index 08faae9874b..26a2018f015 100644 --- a/source/blender/blenkernel/intern/anim_sys.c +++ b/source/blender/blenkernel/intern/anim_sys.c @@ -330,7 +330,7 @@ AnimData *BKE_animdata_copy(Main *bmain, AnimData *adt, const int flag) /** * \param flag: Control ID pointers management, * see LIB_ID_CREATE_.../LIB_ID_COPY_... flags in BKE_library.h - * \return true is succesfully copied. + * \return true is successfully copied. */ bool BKE_animdata_copy_id(Main *bmain, ID *id_to, ID *id_from, const int flag) { @@ -1882,12 +1882,11 @@ static void animsys_write_orig_anim_rna(PointerRNA *ptr, * This performs a set of standard checks. If extra checks are required, * separate code should be used. */ -static void animsys_evaluate_fcurves(Depsgraph *depsgraph, - PointerRNA *ptr, +static void animsys_evaluate_fcurves(PointerRNA *ptr, ListBase *list, - float ctime) + float ctime, + bool flush_to_original) { - const bool is_active_depsgraph = DEG_is_active(depsgraph); /* Calculate then execute each curve. */ for (FCurve *fcu = list->first; fcu; fcu = fcu->next) { /* Check if this F-Curve doesn't belong to a muted group. */ @@ -1906,7 +1905,7 @@ static void animsys_evaluate_fcurves(Depsgraph *depsgraph, if (animsys_store_rna_setting(ptr, fcu->rna_path, fcu->array_index, &anim_rna)) { const float curval = calculate_fcurve(&anim_rna, fcu, ctime); animsys_write_rna_setting(&anim_rna, curval); - if (is_active_depsgraph) { + if (flush_to_original) { animsys_write_orig_anim_rna(ptr, fcu->rna_path, fcu->array_index, curval); } } @@ -2025,10 +2024,10 @@ void animsys_evaluate_action_group(PointerRNA *ptr, bAction *act, bActionGroup * } /* Evaluate Action (F-Curve Bag) */ -static void animsys_evaluate_action_ex(Depsgraph *depsgraph, - PointerRNA *ptr, +static void animsys_evaluate_action_ex(PointerRNA *ptr, bAction *act, - float ctime) + float ctime, + const bool flush_to_original) { /* check if mapper is appropriate for use here (we set to NULL if it's inappropriate) */ if (act == NULL) { @@ -2038,12 +2037,15 @@ static void animsys_evaluate_action_ex(Depsgraph *depsgraph, action_idcode_patch_check(ptr->id.data, act); /* calculate then execute each curve */ - animsys_evaluate_fcurves(depsgraph, ptr, &act->curves, ctime); + animsys_evaluate_fcurves(ptr, &act->curves, ctime, flush_to_original); } -void animsys_evaluate_action(Depsgraph *depsgraph, PointerRNA *ptr, bAction *act, float ctime) +void animsys_evaluate_action(PointerRNA *ptr, + bAction *act, + float ctime, + const bool flush_to_original) { - animsys_evaluate_action_ex(depsgraph, ptr, act, ctime); + animsys_evaluate_action_ex(ptr, act, ctime, flush_to_original); } /* ***************************************** */ @@ -2072,7 +2074,7 @@ static float nlastrip_get_influence(NlaStrip *strip, float cframe) } /* evaluate the evaluation time and influence for the strip, storing the results in the strip */ -static void nlastrip_evaluate_controls(Depsgraph *depsgraph, NlaStrip *strip, float ctime) +static void nlastrip_evaluate_controls(NlaStrip *strip, float ctime, const bool flush_to_original) { /* now strip's evaluate F-Curves for these settings (if applicable) */ if (strip->fcurves.first) { @@ -2082,7 +2084,7 @@ static void nlastrip_evaluate_controls(Depsgraph *depsgraph, NlaStrip *strip, fl RNA_pointer_create(NULL, &RNA_NlaStrip, strip, &strip_ptr); /* execute these settings as per normal */ - animsys_evaluate_fcurves(depsgraph, &strip_ptr, &strip->fcurves, ctime); + animsys_evaluate_fcurves(&strip_ptr, &strip->fcurves, ctime, flush_to_original); } /* analytically generate values for influence and time (if applicable) @@ -2115,7 +2117,7 @@ static void nlastrip_evaluate_controls(Depsgraph *depsgraph, NlaStrip *strip, fl /* gets the strip active at the current time for a list of strips for evaluation purposes */ NlaEvalStrip *nlastrips_ctime_get_strip( - Depsgraph *depsgraph, ListBase *list, ListBase *strips, short index, float ctime) + ListBase *list, ListBase *strips, short index, float ctime, const bool flush_to_original) { NlaStrip *strip, *estrip = NULL; NlaEvalStrip *nes; @@ -2198,7 +2200,7 @@ NlaEvalStrip *nlastrips_ctime_get_strip( */ /* TODO: this sounds a bit hacky having a few isolated F-Curves * stuck on some data it operates on... */ - nlastrip_evaluate_controls(depsgraph, estrip, ctime); + nlastrip_evaluate_controls(estrip, ctime, flush_to_original); if (estrip->influence <= 0.0f) { return NULL; } @@ -2220,8 +2222,8 @@ NlaEvalStrip *nlastrips_ctime_get_strip( } /* evaluate controls for the relevant extents of the bordering strips... */ - nlastrip_evaluate_controls(depsgraph, estrip->prev, estrip->start); - nlastrip_evaluate_controls(depsgraph, estrip->next, estrip->end); + nlastrip_evaluate_controls(estrip->prev, estrip->start, flush_to_original); + nlastrip_evaluate_controls(estrip->next, estrip->end, flush_to_original); break; } @@ -3141,12 +3143,12 @@ static void nlastrip_evaluate_actionclip(PointerRNA *ptr, } /* evaluate transition strip */ -static void nlastrip_evaluate_transition(Depsgraph *depsgraph, - PointerRNA *ptr, +static void nlastrip_evaluate_transition(PointerRNA *ptr, NlaEvalData *channels, ListBase *modifiers, NlaEvalStrip *nes, - NlaEvalSnapshot *snapshot) + NlaEvalSnapshot *snapshot, + const bool flush_to_original) { ListBase tmp_modifiers = {NULL, NULL}; NlaEvalSnapshot snapshot1, snapshot2; @@ -3187,13 +3189,13 @@ static void nlastrip_evaluate_transition(Depsgraph *depsgraph, tmp_nes.strip_mode = NES_TIME_TRANSITION_START; tmp_nes.strip = s1; nlaeval_snapshot_init(&snapshot1, channels, snapshot); - nlastrip_evaluate(depsgraph, ptr, channels, &tmp_modifiers, &tmp_nes, &snapshot1); + nlastrip_evaluate(ptr, channels, &tmp_modifiers, &tmp_nes, &snapshot1, flush_to_original); /* second strip */ tmp_nes.strip_mode = NES_TIME_TRANSITION_END; tmp_nes.strip = s2; nlaeval_snapshot_init(&snapshot2, channels, snapshot); - nlastrip_evaluate(depsgraph, ptr, channels, &tmp_modifiers, &tmp_nes, &snapshot2); + nlastrip_evaluate(ptr, channels, &tmp_modifiers, &tmp_nes, &snapshot2, flush_to_original); /* accumulate temp-buffer and full-buffer, using the 'real' strip */ nlaeval_snapshot_mix_and_free(channels, snapshot, &snapshot1, &snapshot2, nes->strip_time); @@ -3203,12 +3205,12 @@ static void nlastrip_evaluate_transition(Depsgraph *depsgraph, } /* evaluate meta-strip */ -static void nlastrip_evaluate_meta(Depsgraph *depsgraph, - PointerRNA *ptr, +static void nlastrip_evaluate_meta(PointerRNA *ptr, NlaEvalData *channels, ListBase *modifiers, NlaEvalStrip *nes, - NlaEvalSnapshot *snapshot) + NlaEvalSnapshot *snapshot, + const bool flush_to_original) { ListBase tmp_modifiers = {NULL, NULL}; NlaStrip *strip = nes->strip; @@ -3228,13 +3230,13 @@ static void nlastrip_evaluate_meta(Depsgraph *depsgraph, /* find the child-strip to evaluate */ evaltime = (nes->strip_time * (strip->end - strip->start)) + strip->start; - tmp_nes = nlastrips_ctime_get_strip(depsgraph, NULL, &strip->strips, -1, evaltime); + tmp_nes = nlastrips_ctime_get_strip(NULL, &strip->strips, -1, evaltime, flush_to_original); /* directly evaluate child strip into accumulation buffer... * - there's no need to use a temporary buffer (as it causes issues [T40082]) */ if (tmp_nes) { - nlastrip_evaluate(depsgraph, ptr, channels, &tmp_modifiers, tmp_nes, snapshot); + nlastrip_evaluate(ptr, channels, &tmp_modifiers, tmp_nes, snapshot, flush_to_original); /* free temp eval-strip */ MEM_freeN(tmp_nes); @@ -3245,12 +3247,12 @@ static void nlastrip_evaluate_meta(Depsgraph *depsgraph, } /* evaluates the given evaluation strip */ -void nlastrip_evaluate(Depsgraph *depsgraph, - PointerRNA *ptr, +void nlastrip_evaluate(PointerRNA *ptr, NlaEvalData *channels, ListBase *modifiers, NlaEvalStrip *nes, - NlaEvalSnapshot *snapshot) + NlaEvalSnapshot *snapshot, + const bool flush_to_original) { NlaStrip *strip = nes->strip; @@ -3272,10 +3274,10 @@ void nlastrip_evaluate(Depsgraph *depsgraph, nlastrip_evaluate_actionclip(ptr, channels, modifiers, nes, snapshot); break; case NLASTRIP_TYPE_TRANSITION: /* transition */ - nlastrip_evaluate_transition(depsgraph, ptr, channels, modifiers, nes, snapshot); + nlastrip_evaluate_transition(ptr, channels, modifiers, nes, snapshot, flush_to_original); break; case NLASTRIP_TYPE_META: /* meta */ - nlastrip_evaluate_meta(depsgraph, ptr, channels, modifiers, nes, snapshot); + nlastrip_evaluate_meta(ptr, channels, modifiers, nes, snapshot, flush_to_original); break; default: /* do nothing */ @@ -3287,18 +3289,16 @@ void nlastrip_evaluate(Depsgraph *depsgraph, } /* write the accumulated settings to */ -void nladata_flush_channels(Depsgraph *depsgraph, - PointerRNA *ptr, +void nladata_flush_channels(PointerRNA *ptr, NlaEvalData *channels, - NlaEvalSnapshot *snapshot) + NlaEvalSnapshot *snapshot, + const bool flush_to_original) { /* sanity checks */ if (channels == NULL) { return; } - const bool is_active_depsgraph = DEG_is_active(depsgraph); - /* for each channel with accumulated values, write its value on the property it affects */ for (NlaEvalChannel *nec = channels->channels.first; nec; nec = nec->next) { NlaEvalChannelSnapshot *nec_snapshot = nlaeval_snapshot_find_channel(snapshot, nec); @@ -3312,7 +3312,7 @@ void nladata_flush_channels(Depsgraph *depsgraph, rna.prop_index = i; } animsys_write_rna_setting(&rna, value); - if (is_active_depsgraph) { + if (flush_to_original) { animsys_write_orig_anim_rna(ptr, nec->rna_path, rna.prop_index, value); } } @@ -3422,11 +3422,11 @@ static void animsys_evaluate_nla_domain(PointerRNA *ptr, NlaEvalData *channels, * data about the currently edited strip is stored here and excluded from value calculation. * \return false if NLA evaluation isn't actually applicable. */ -static bool animsys_evaluate_nla(Depsgraph *depsgraph, - NlaEvalData *echannels, +static bool animsys_evaluate_nla(NlaEvalData *echannels, PointerRNA *ptr, AnimData *adt, float ctime, + const bool flush_to_original, NlaKeyframingContext *r_context) { NlaTrack *nlt; @@ -3473,7 +3473,7 @@ static bool animsys_evaluate_nla(Depsgraph *depsgraph, } /* otherwise, get strip to evaluate for this channel */ - nes = nlastrips_ctime_get_strip(depsgraph, &estrips, &nlt->strips, track_index, ctime); + nes = nlastrips_ctime_get_strip(&estrips, &nlt->strips, track_index, ctime, flush_to_original); if (nes) { nes->track = nlt; } @@ -3539,7 +3539,7 @@ static bool animsys_evaluate_nla(Depsgraph *depsgraph, /* add this to our list of evaluation strips */ if (r_context == NULL) { - nlastrips_ctime_get_strip(depsgraph, &estrips, &dummy_trackslist, -1, ctime); + nlastrips_ctime_get_strip(&estrips, &dummy_trackslist, -1, ctime, flush_to_original); } /* If computing the context for keyframing, store data there instead of the list. */ else { @@ -3549,7 +3549,7 @@ static bool animsys_evaluate_nla(Depsgraph *depsgraph, NLASTRIP_EXTEND_HOLD; r_context->eval_strip = nes = nlastrips_ctime_get_strip( - depsgraph, NULL, &dummy_trackslist, -1, ctime); + NULL, &dummy_trackslist, -1, ctime, flush_to_original); /* These setting combinations require no data from strips below, so exit immediately. */ if ((nes == NULL) || @@ -3574,7 +3574,7 @@ static bool animsys_evaluate_nla(Depsgraph *depsgraph, /* 2. for each strip, evaluate then accumulate on top of existing channels, * but don't set values yet. */ for (nes = estrips.first; nes; nes = nes->next) { - nlastrip_evaluate(depsgraph, ptr, echannels, NULL, nes, &echannels->eval_snapshot); + nlastrip_evaluate(ptr, echannels, NULL, nes, &echannels->eval_snapshot, flush_to_original); } /* 3. free temporary evaluation data that's not used elsewhere */ @@ -3586,22 +3586,22 @@ static bool animsys_evaluate_nla(Depsgraph *depsgraph, * - All channels that will be affected are not cleared anymore. Instead, we just evaluate into * some temp channels, where values can be accumulated in one go. */ -static void animsys_calculate_nla(Depsgraph *depsgraph, - PointerRNA *ptr, +static void animsys_calculate_nla(PointerRNA *ptr, AnimData *adt, - float ctime) + float ctime, + const bool flush_to_original) { NlaEvalData echannels; nlaeval_init(&echannels); /* evaluate the NLA stack, obtaining a set of values to flush */ - if (animsys_evaluate_nla(depsgraph, &echannels, ptr, adt, ctime, NULL)) { + if (animsys_evaluate_nla(&echannels, ptr, adt, ctime, flush_to_original, NULL)) { /* reset any channels touched by currently inactive actions to default value */ animsys_evaluate_nla_domain(ptr, &echannels, adt); /* flush effects of accumulating channels in NLA to the actual data they affect */ - nladata_flush_channels(depsgraph, ptr, &echannels, &echannels.eval_snapshot); + nladata_flush_channels(ptr, &echannels, &echannels.eval_snapshot, flush_to_original); } else { /* special case - evaluate as if there isn't any NLA data */ @@ -3610,7 +3610,7 @@ static void animsys_calculate_nla(Depsgraph *depsgraph, CLOG_WARN(&LOG, "NLA Eval: Stopgap for active action on NLA Stack - no strips case"); } - animsys_evaluate_action(depsgraph, ptr, adt->action, ctime); + animsys_evaluate_action(ptr, adt->action, ctime, flush_to_original); } /* free temp data */ @@ -3629,10 +3629,10 @@ static void animsys_calculate_nla(Depsgraph *depsgraph, * \return Keyframing context, or NULL if not necessary. */ NlaKeyframingContext *BKE_animsys_get_nla_keyframing_context(struct ListBase *cache, - struct Depsgraph *depsgraph, struct PointerRNA *ptr, struct AnimData *adt, - float ctime) + float ctime, + const bool flush_to_original) { /* No remapping needed if NLA is off or no action. */ if ((adt == NULL) || (adt->action == NULL) || (adt->nla_tracks.first == NULL) || @@ -3655,7 +3655,7 @@ NlaKeyframingContext *BKE_animsys_get_nla_keyframing_context(struct ListBase *ca ctx->adt = adt; nlaeval_init(&ctx->nla_channels); - animsys_evaluate_nla(depsgraph, &ctx->nla_channels, ptr, adt, ctime, ctx); + animsys_evaluate_nla(&ctx->nla_channels, ptr, adt, ctime, flush_to_original, ctx); BLI_assert(ELEM(ctx->strip.act, NULL, adt->action)); BLI_addtail(cache, ctx); @@ -3846,7 +3846,7 @@ static void animsys_evaluate_overrides(PointerRNA *ptr, AnimData *adt) * have been set already by the depsgraph. Now, we use the recalc */ void BKE_animsys_evaluate_animdata( - Depsgraph *depsgraph, Scene *scene, ID *id, AnimData *adt, float ctime, short recalc) + Scene *scene, ID *id, AnimData *adt, float ctime, short recalc, const bool flush_to_original) { PointerRNA id_ptr; @@ -3869,11 +3869,11 @@ void BKE_animsys_evaluate_animdata( /* evaluate NLA-stack * - active action is evaluated as part of the NLA stack as the last item */ - animsys_calculate_nla(depsgraph, &id_ptr, adt, ctime); + animsys_calculate_nla(&id_ptr, adt, ctime, flush_to_original); } /* evaluate Active Action only */ else if (adt->action) { - animsys_evaluate_action_ex(depsgraph, &id_ptr, adt->action, ctime); + animsys_evaluate_action_ex(&id_ptr, adt->action, ctime, flush_to_original); } } @@ -3920,6 +3920,8 @@ void BKE_animsys_evaluate_all_animation(Main *main, printf("Evaluate all animation - %f\n", ctime); } + const bool flush_to_original = DEG_is_active(depsgraph); + /* macros for less typing * - only evaluate animation data for id if it has users (and not just fake ones) * - whether animdata exists is checked for by the evaluation function, though taking @@ -3929,7 +3931,7 @@ void BKE_animsys_evaluate_all_animation(Main *main, for (id = first; id; id = id->next) { \ if (ID_REAL_USERS(id) > 0) { \ AnimData *adt = BKE_animdata_from_id(id); \ - BKE_animsys_evaluate_animdata(depsgraph, scene, id, adt, ctime, aflag); \ + BKE_animsys_evaluate_animdata(scene, id, adt, ctime, aflag, flush_to_original); \ } \ } \ (void)0 @@ -3948,9 +3950,9 @@ void BKE_animsys_evaluate_all_animation(Main *main, if (ntp->nodetree) { \ AnimData *adt2 = BKE_animdata_from_id((ID *)ntp->nodetree); \ BKE_animsys_evaluate_animdata( \ - depsgraph, scene, (ID *)ntp->nodetree, adt2, ctime, ADT_RECALC_ANIM); \ + scene, (ID *)ntp->nodetree, adt2, ctime, ADT_RECALC_ANIM, flush_to_original); \ } \ - BKE_animsys_evaluate_animdata(depsgraph, scene, id, adt, ctime, aflag); \ + BKE_animsys_evaluate_animdata(scene, id, adt, ctime, aflag, flush_to_original); \ } \ } \ (void)0 @@ -4055,7 +4057,8 @@ void BKE_animsys_eval_animdata(Depsgraph *depsgraph, ID *id) * which should get handled as part of the dependency graph instead. */ Scene *scene = NULL; DEG_debug_print_eval_time(depsgraph, __func__, id->name, id, ctime); - BKE_animsys_evaluate_animdata(depsgraph, scene, id, adt, ctime, ADT_RECALC_ANIM); + const bool flush_to_original = DEG_is_active(depsgraph); + BKE_animsys_evaluate_animdata(scene, id, adt, ctime, ADT_RECALC_ANIM, flush_to_original); } void BKE_animsys_update_driver_array(ID *id) diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index c36acd1eae1..742e3634bf1 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -239,6 +239,35 @@ bArmature *BKE_armature_copy(Main *bmain, const bArmature *arm) return arm_copy; } +static void copy_bone_transform(Bone *bone_dst, const Bone *bone_src) +{ + bone_dst->roll = bone_src->roll; + + copy_v3_v3(bone_dst->head, bone_src->head); + copy_v3_v3(bone_dst->tail, bone_src->tail); + + copy_m3_m3(bone_dst->bone_mat, bone_src->bone_mat); + + copy_v3_v3(bone_dst->arm_head, bone_src->arm_head); + copy_v3_v3(bone_dst->arm_tail, bone_src->arm_tail); + + copy_m4_m4(bone_dst->arm_mat, bone_src->arm_mat); + + bone_dst->arm_roll = bone_src->arm_roll; +} + +void BKE_armature_copy_bone_transforms(bArmature *armature_dst, const bArmature *armature_src) +{ + Bone *bone_dst = armature_dst->bonebase.first; + const Bone *bone_src = armature_src->bonebase.first; + while (bone_dst != NULL) { + BLI_assert(bone_src != NULL); + copy_bone_transform(bone_dst, bone_src); + bone_dst = bone_dst->next; + bone_src = bone_src->next; + } +} + static Bone *get_named_bone_bonechildren(ListBase *lb, const char *name) { Bone *curBone, *rbone; @@ -1350,7 +1379,7 @@ typedef struct ArmatureUserdata { static void armature_vert_task(void *__restrict userdata, const int i, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { const ArmatureUserdata *data = userdata; float(*const vertexCos)[3] = data->vertexCos; @@ -1648,7 +1677,7 @@ void armature_deform_verts(Object *armOb, mul_m4_m4m4(data.postmat, obinv, armOb->obmat); invert_m4_m4(data.premat, data.postmat); - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.min_iter_per_thread = 32; BLI_task_parallel_range(0, numVerts, &data, armature_vert_task, &settings); @@ -2374,6 +2403,9 @@ static void pose_proxy_synchronize(Object *ob, Object *from, int layer_protected pchanw.mpath = pchan->mpath; pchan->mpath = NULL; + /* Reset runtime data, we don't want to share that with the proxy. */ + BKE_pose_channel_runtime_reset(&pchanw.runtime); + /* this is freed so copy a copy, else undo crashes */ if (pchanw.prop) { pchanw.prop = IDP_CopyProperty(pchanw.prop); diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c index 9fd3c24092c..805c098d238 100644 --- a/source/blender/blenkernel/intern/blender.c +++ b/source/blender/blenkernel/intern/blender.c @@ -306,6 +306,7 @@ void BKE_blender_userdef_app_template_data_swap(UserDef *userdef_a, UserDef *use LIST_SWAP(themes); LIST_SWAP(addons); LIST_SWAP(user_keymaps); + LIST_SWAP(user_keyconfig_prefs); DATA_SWAP(font_path_ui); DATA_SWAP(font_path_ui_mono); diff --git a/source/blender/blenkernel/intern/blender_undo.c b/source/blender/blenkernel/intern/blender_undo.c index 6c077ac75ba..7c12747283c 100644 --- a/source/blender/blenkernel/intern/blender_undo.c +++ b/source/blender/blenkernel/intern/blender_undo.c @@ -73,7 +73,7 @@ bool BKE_memfile_undo_decode(MemFileUndoData *mfu, bContext *C) G.fileflags |= G_FILE_NO_UI; if (UNDO_DISK) { - success = (BKE_blendfile_read(C, mfu->filename, NULL, 0) != BKE_BLENDFILE_READ_FAIL); + success = BKE_blendfile_read(C, mfu->filename, NULL, 0); } else { success = BKE_blendfile_read_from_memfile( diff --git a/source/blender/blenkernel/intern/blendfile.c b/source/blender/blenkernel/intern/blendfile.c index afbd2627a2a..bc62ad685ef 100644 --- a/source/blender/blenkernel/intern/blendfile.c +++ b/source/blender/blenkernel/intern/blendfile.c @@ -32,25 +32,30 @@ #include "BLI_listbase.h" #include "BLI_string.h" +#include "BLI_system.h" #include "BLI_path_util.h" #include "BLI_utildefines.h" #include "IMB_colormanagement.h" +#include "BKE_addon.h" #include "BKE_appdir.h" #include "BKE_blender.h" #include "BKE_blender_version.h" #include "BKE_blendfile.h" #include "BKE_bpath.h" +#include "BKE_colorband.h" #include "BKE_context.h" #include "BKE_global.h" #include "BKE_ipo.h" +#include "BKE_keyconfig.h" #include "BKE_layer.h" #include "BKE_library.h" #include "BKE_main.h" #include "BKE_report.h" #include "BKE_scene.h" #include "BKE_screen.h" +#include "BKE_studiolight.h" #include "BKE_workspace.h" #include "BLO_readfile.h" @@ -405,35 +410,31 @@ int BKE_blendfile_read(bContext *C, ReportList *reports) { BlendFileData *bfd; - int retval = BKE_BLENDFILE_READ_OK; + bool success = false; - /* don't print user-pref loading */ - if (strstr(filepath, BLENDER_STARTUP_FILE) == NULL) { + /* Don't print startup file loading. */ + if (params->is_startup == false) { printf("Read blend: %s\n", filepath); } bfd = BLO_read_from_file(filepath, params->skip_flags, reports); if (bfd) { - if (bfd->user) { - retval = BKE_BLENDFILE_READ_OK_USERPREFS; - } - if (0 == handle_subversion_warning(bfd->main, reports)) { BKE_main_free(bfd->main); MEM_freeN(bfd); bfd = NULL; - retval = BKE_BLENDFILE_READ_FAIL; } else { setup_app_blend_file_data(C, bfd, filepath, params, reports); BLO_blendfiledata_free(bfd); + success = true; } } else { BKE_reports_prependf(reports, "Loading '%s' failed: ", filepath); } - return (bfd ? retval : BKE_BLENDFILE_READ_FAIL); + return success; } bool BKE_blendfile_read_from_memory(bContext *C, @@ -556,6 +557,62 @@ UserDef *BKE_blendfile_userdef_read_from_memory(const void *filebuf, return userdef; } +UserDef *BKE_blendfile_userdef_from_defaults(void) +{ + UserDef *userdef = MEM_mallocN(sizeof(*userdef), __func__); + memcpy(userdef, &U_default, sizeof(*userdef)); + + /* Add-ons. */ + { + const char *addons[] = { + "io_anim_bvh", + "io_curve_svg", + "io_mesh_ply", + "io_mesh_stl", + "io_mesh_uv_layout", + "io_scene_fbx", + "io_scene_gltf2", + "io_scene_obj", + "io_scene_x3d", + }; + for (int i = 0; i < ARRAY_SIZE(addons); i++) { + bAddon *addon = BKE_addon_new(); + STRNCPY(addon->module, addons[i]); + BLI_addtail(&userdef->addons, addon); + } + } + + /* Theme. */ + { + bTheme *btheme = MEM_mallocN(sizeof(*btheme), __func__); + memcpy(btheme, &U_theme_default, sizeof(*btheme)); + + BLI_addtail(&userdef->themes, btheme); + } + +#ifdef WITH_PYTHON_SECURITY + /* use alternative setting for security nuts + * otherwise we'd need to patch the binary blob - startup.blend.c */ + userdef->flag |= USER_SCRIPT_AUTOEXEC_DISABLE; +#else + userdef->flag &= ~USER_SCRIPT_AUTOEXEC_DISABLE; +#endif + + /* System-specific fonts directory. */ + BKE_appdir_font_folder_default(userdef->fontdir); + + userdef->memcachelimit = min_ii(BLI_system_memory_max_in_megabytes_int() / 2, + userdef->memcachelimit); + + /* Init weight paint range. */ + BKE_colorband_init(&userdef->coba_weight, true); + + /* Default studio light. */ + BKE_studiolight_default(userdef->light_param, userdef->light_ambient); + + return userdef; +} + /** * Only write the userdef in a .blend * \return success diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index ec9a774a65c..709f74808a3 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -1400,16 +1400,45 @@ void BKE_brush_randomize_texture_coords(UnifiedPaintSettings *ups, bool mask) /* Uses the brush curve control to find a strength value */ float BKE_brush_curve_strength(const Brush *br, float p, const float len) { - float strength; + float strength = 1.0f; if (p >= len) { return 0; } else { p = p / len; + p = 1.0f - p; } - strength = curvemapping_evaluateF(br->curve, 0, p); + switch (br->curve_preset) { + case BRUSH_CURVE_CUSTOM: + strength = curvemapping_evaluateF(br->curve, 0, 1.0f - p); + break; + case BRUSH_CURVE_SHARP: + strength = p * p; + break; + case BRUSH_CURVE_SMOOTH: + strength = 3.0f * p * p - 2.0f * p * p * p; + break; + case BRUSH_CURVE_ROOT: + strength = sqrtf(p); + break; + case BRUSH_CURVE_LIN: + strength = p; + break; + case BRUSH_CURVE_CONSTANT: + strength = 1.0f; + break; + case BRUSH_CURVE_SPHERE: + strength = sqrtf(2 * p - p * p); + break; + case BRUSH_CURVE_POW4: + strength = p * p * p * p; + break; + case BRUSH_CURVE_INVSQUARE: + strength = p * (2.0f - p); + break; + } return strength; } diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c index a8f38c3c4ce..a563a8d581c 100644 --- a/source/blender/blenkernel/intern/camera.c +++ b/source/blender/blenkernel/intern/camera.c @@ -375,7 +375,7 @@ void BKE_camera_view_frame_ex(const Scene *scene, float facx, facy; float depth; - /* aspect correcton */ + /* aspect correction */ if (scene) { float aspx = (float)scene->r.xsch * scene->r.xasp; float aspy = (float)scene->r.ysch * scene->r.yasp; diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c index 965f6e4bc51..25f2797915a 100644 --- a/source/blender/blenkernel/intern/collection.c +++ b/source/blender/blenkernel/intern/collection.c @@ -1100,7 +1100,7 @@ void BKE_collection_parent_relations_rebuild(Collection *collection) static void collection_parents_rebuild_recursive(Collection *collection) { BKE_collection_parent_relations_rebuild(collection); - collection->id.tag &= ~LIB_TAG_DOIT; + collection->tag &= ~COLLECTION_TAG_RELATION_REBUILD; for (CollectionChild *child = collection->children.first; child != NULL; child = child->next) { collection_parents_rebuild_recursive(child->collection); @@ -1109,8 +1109,6 @@ static void collection_parents_rebuild_recursive(Collection *collection) /** * Rebuild parent relationships from child ones, for all collections in given \a bmain. - * - * \note Uses LIB_TAG_DOIT internally... */ void BKE_main_collections_parent_relations_rebuild(Main *bmain) { @@ -1119,7 +1117,7 @@ void BKE_main_collections_parent_relations_rebuild(Main *bmain) collection = collection->id.next) { BLI_freelistN(&collection->parents); - collection->id.tag |= LIB_TAG_DOIT; + collection->tag |= COLLECTION_TAG_RELATION_REBUILD; } /* Scene's master collections will be 'root' parent of most of our collections, so start with @@ -1132,7 +1130,7 @@ void BKE_main_collections_parent_relations_rebuild(Main *bmain) * lib_link_collection_data() seems to assume that, so do the same here. */ for (Collection *collection = bmain->collections.first; collection != NULL; collection = collection->id.next) { - if (collection->id.tag & LIB_TAG_DOIT) { + if (collection->tag & COLLECTION_TAG_RELATION_REBUILD) { /* Note: we do not have easy access to 'which collections is root' info in that case, which * means test for cycles in collection relationships may fail here. I don't think that is an * issue in practice here, but worth keeping in mind... */ diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c index ff6258ac339..69afda9997a 100644 --- a/source/blender/blenkernel/intern/collision.c +++ b/source/blender/blenkernel/intern/collision.c @@ -851,7 +851,7 @@ static int cloth_selfcollision_response_static(ClothModifierData *clmd, static void cloth_collision(void *__restrict userdata, const int index, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { ColDetectData *data = (ColDetectData *)userdata; @@ -908,7 +908,7 @@ static void cloth_collision(void *__restrict userdata, static void cloth_selfcollision(void *__restrict userdata, const int index, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { SelfColDetectData *data = (SelfColDetectData *)userdata; @@ -1154,7 +1154,7 @@ static bool cloth_bvh_objcollisions_nearcheck(ClothModifierData *clmd, .collided = false, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = true; BLI_task_parallel_range(0, numresult, &data, cloth_collision, &settings); @@ -1174,7 +1174,7 @@ static bool cloth_bvh_selfcollisions_nearcheck(ClothModifierData *clmd, .collided = false, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = true; BLI_task_parallel_range(0, numresult, &data, cloth_selfcollision, &settings); diff --git a/source/blender/blenkernel/intern/colortools.c b/source/blender/blenkernel/intern/colortools.c index 863d6351738..aa5f74c6297 100644 --- a/source/blender/blenkernel/intern/colortools.c +++ b/source/blender/blenkernel/intern/colortools.c @@ -1385,7 +1385,7 @@ typedef struct ScopesUpdateDataChunk { static void scopes_update_cb(void *__restrict userdata, const int y, - const ParallelRangeTLS *__restrict tls) + const TaskParallelTLS *__restrict tls) { const ScopesUpdateData *data = userdata; @@ -1634,7 +1634,7 @@ void scopes_update(Scopes *scopes, ScopesUpdateDataChunk data_chunk = {{0}}; INIT_MINMAX(data_chunk.min, data_chunk.max); - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (ibuf->y > 256); settings.userdata_chunk = &data_chunk; diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index 793dc910394..e1e4d138fd9 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -5273,7 +5273,7 @@ static void constraint_copy_data_ex(bConstraint *dst, } } -/** Allocate and duplicate a single constraint, ouside of any object/pose context. */ +/** Allocate and duplicate a single constraint, outside of any object/pose context. */ bConstraint *BKE_constraint_duplicate_ex(bConstraint *src, const int flag, const bool do_extern) { bConstraint *dst = MEM_dupallocN(src); diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c index 4ae87713aa5..2cb98d8d90b 100644 --- a/source/blender/blenkernel/intern/context.c +++ b/source/blender/blenkernel/intern/context.c @@ -1348,7 +1348,7 @@ int CTX_data_editable_gpencil_strokes(const bContext *C, ListBase *list) return ctx_data_collection_get(C, "editable_gpencil_strokes", list); } -Depsgraph *CTX_data_depsgraph(const bContext *C) +Depsgraph *CTX_data_depsgraph_pointer(const bContext *C) { Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); @@ -1361,9 +1361,18 @@ Depsgraph *CTX_data_depsgraph(const bContext *C) return depsgraph; } -Depsgraph *CTX_data_evaluated_depsgraph(const bContext *C) +Depsgraph *CTX_data_expect_evaluated_depsgraph(const bContext *C) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); + /* TODO(sergey): Assert that the dependency graph is fully evaluated. + * Note that first the depsgraph and scene post-eval hooks needs to run extra round of updates + * first to make check here really reliable. */ + return depsgraph; +} + +Depsgraph *CTX_data_ensure_evaluated_depsgraph(const bContext *C) +{ + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); Main *bmain = CTX_data_main(C); BKE_scene_graph_evaluated_ensure(depsgraph, bmain); return depsgraph; diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index 931c0ed73d3..efdfa2c19bb 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -5313,6 +5313,32 @@ void BKE_curve_material_index_remove(Curve *cu, int index) } } +bool BKE_curve_material_index_used(Curve *cu, int index) +{ + const int curvetype = BKE_curve_type_get(cu); + + if (curvetype == OB_FONT) { + struct CharInfo *info = cu->strinfo; + int i; + for (i = cu->len_wchar - 1; i >= 0; i--, info++) { + if (info->mat_nr == index) { + return true; + } + } + } + else { + Nurb *nu; + + for (nu = cu->nurb.first; nu; nu = nu->next) { + if (nu->mat_nr == index) { + return true; + } + } + } + + return false; +} + void BKE_curve_material_index_clear(Curve *cu) { const int curvetype = BKE_curve_type_get(cu); diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index 1fb29745dba..3c7ac5d8d2e 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -4756,7 +4756,8 @@ void CustomData_data_transfer(const MeshPairRemap *me_remap, for (i = 0; i < totelem; i++, data_dst = POINTER_OFFSET(data_dst, data_step), mapit++) { const int sources_num = mapit->sources_num; - const float mix_factor = laymap->mix_weights ? laymap->mix_weights[i] : laymap->mix_factor; + const float mix_factor = laymap->mix_factor * + (laymap->mix_weights ? laymap->mix_weights[i] : 1.0f); int j; if (!sources_num) { diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c index cf6f1fdeec1..83a10344b96 100644 --- a/source/blender/blenkernel/intern/displist.c +++ b/source/blender/blenkernel/intern/displist.c @@ -477,7 +477,7 @@ static void curve_to_displist(Curve *cu, } /** - * \param normal_proj: Optional normal thats used to project the scanfill verts into 2d coords. + * \param normal_proj: Optional normal that's used to project the scanfill verts into 2d coords. * Pass this along if known since it saves time calculating the normal. * \param flipnormal: Flip the normal (same as passing \a normal_proj negated) */ @@ -1857,7 +1857,7 @@ void BKE_displist_minmax(ListBase *dispbase, float min[3], float max[3]) } } -/* this is confusing, there's also min_max_object, appplying the obmat... */ +/* this is confusing, there's also min_max_object, applying the obmat... */ static void boundbox_displist_object(Object *ob) { if (ELEM(ob->type, OB_CURVE, OB_SURF, OB_FONT)) { diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c index 7e916feac24..03530fc76b6 100644 --- a/source/blender/blenkernel/intern/dynamicpaint.c +++ b/source/blender/blenkernel/intern/dynamicpaint.c @@ -645,7 +645,7 @@ static void freeGrid(PaintSurfaceData *data) static void grid_bound_insert_cb_ex(void *__restrict userdata, const int i, - const ParallelRangeTLS *__restrict tls) + const TaskParallelTLS *__restrict tls) { PaintBakeData *bData = userdata; @@ -667,7 +667,7 @@ static void grid_bound_insert_finalize(void *__restrict userdata, void *__restri static void grid_cell_points_cb_ex(void *__restrict userdata, const int i, - const ParallelRangeTLS *__restrict tls) + const TaskParallelTLS *__restrict tls) { PaintBakeData *bData = userdata; VolumeGrid *grid = bData->grid; @@ -702,7 +702,7 @@ static void grid_cell_points_finalize(void *__restrict userdata, void *__restric static void grid_cell_bounds_cb(void *__restrict userdata, const int x, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { PaintBakeData *bData = userdata; VolumeGrid *grid = bData->grid; @@ -749,7 +749,7 @@ static void surfaceGenerateGrid(struct DynamicPaintSurface *surface) /* Important to init correctly our ref grid_bound... */ boundInsert(&grid->grid_bounds, bData->realCoord[bData->s_pos[0]].v); { - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (sData->total_points > 1000); settings.userdata_chunk = &grid->grid_bounds; @@ -810,7 +810,7 @@ static void surfaceGenerateGrid(struct DynamicPaintSurface *surface) if (!error) { /* calculate number of points within each cell */ { - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (sData->total_points > 1000); settings.userdata_chunk = grid->s_num; @@ -834,7 +834,7 @@ static void surfaceGenerateGrid(struct DynamicPaintSurface *surface) /* calculate cell bounds */ { - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (grid_cells > 1000); BLI_task_parallel_range(0, grid->dim[0], bData, grid_cell_bounds_cb, &settings); @@ -1508,7 +1508,7 @@ typedef struct DynamicPaintSetInitColorData { } DynamicPaintSetInitColorData; static void dynamic_paint_set_init_color_tex_to_vcol_cb( - void *__restrict userdata, const int i, const ParallelRangeTLS *__restrict UNUSED(tls)) + void *__restrict userdata, const int i, const TaskParallelTLS *__restrict UNUSED(tls)) { const DynamicPaintSetInitColorData *data = userdata; @@ -1543,7 +1543,7 @@ static void dynamic_paint_set_init_color_tex_to_vcol_cb( } static void dynamic_paint_set_init_color_tex_to_imseq_cb( - void *__restrict userdata, const int i, const ParallelRangeTLS *__restrict UNUSED(tls)) + void *__restrict userdata, const int i, const TaskParallelTLS *__restrict UNUSED(tls)) { const DynamicPaintSetInitColorData *data = userdata; @@ -1582,7 +1582,7 @@ static void dynamic_paint_set_init_color_tex_to_imseq_cb( } static void dynamic_paint_set_init_color_vcol_to_imseq_cb( - void *__restrict userdata, const int i, const ParallelRangeTLS *__restrict UNUSED(tls)) + void *__restrict userdata, const int i, const TaskParallelTLS *__restrict UNUSED(tls)) { const DynamicPaintSetInitColorData *data = userdata; @@ -1667,7 +1667,7 @@ static void dynamicPaint_setInitialColor(const Scene *scene, DynamicPaintSurface .pool = pool, .scene_color_manage = scene_color_manage, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (tottri > 1000); BLI_task_parallel_range( @@ -1681,7 +1681,7 @@ static void dynamicPaint_setInitialColor(const Scene *scene, DynamicPaintSurface .mloopuv = mloopuv, .scene_color_manage = scene_color_manage, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (sData->total_points > 1000); BLI_task_parallel_range( @@ -1718,7 +1718,7 @@ static void dynamicPaint_setInitialColor(const Scene *scene, DynamicPaintSurface .mlooptri = mlooptri, .mloopcol = col, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (sData->total_points > 1000); BLI_task_parallel_range( @@ -1820,7 +1820,7 @@ typedef struct DynamicPaintModifierApplyData { static void dynamic_paint_apply_surface_displace_cb(void *__restrict userdata, const int i, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { const DynamicPaintModifierApplyData *data = userdata; @@ -1854,7 +1854,7 @@ static void dynamicPaint_applySurfaceDisplace(DynamicPaintSurface *surface, Mesh .surface = surface, .mvert = mvert, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (sData->total_points > 10000); BLI_task_parallel_range( @@ -1863,7 +1863,7 @@ static void dynamicPaint_applySurfaceDisplace(DynamicPaintSurface *surface, Mesh } static void dynamic_paint_apply_surface_vpaint_blend_cb( - void *__restrict userdata, const int i, const ParallelRangeTLS *__restrict UNUSED(tls)) + void *__restrict userdata, const int i, const TaskParallelTLS *__restrict UNUSED(tls)) { const DynamicPaintModifierApplyData *data = userdata; @@ -1877,7 +1877,7 @@ static void dynamic_paint_apply_surface_vpaint_blend_cb( static void dynamic_paint_apply_surface_vpaint_cb(void *__restrict userdata, const int p_index, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { const DynamicPaintModifierApplyData *data = userdata; @@ -1913,7 +1913,7 @@ static void dynamic_paint_apply_surface_vpaint_cb(void *__restrict userdata, static void dynamic_paint_apply_surface_wave_cb(void *__restrict userdata, const int i, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { const DynamicPaintModifierApplyData *data = userdata; @@ -1966,7 +1966,7 @@ static Mesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData *pmd, Object * .fcolor = fcolor, }; { - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (sData->total_points > 1000); BLI_task_parallel_range(0, @@ -2001,7 +2001,7 @@ static Mesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData *pmd, Object * data.mloopcol_wet = mloopcol_wet; { - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (totpoly > 1000); BLI_task_parallel_range( @@ -2053,7 +2053,7 @@ static Mesh *dynamicPaint_Modifier_apply(DynamicPaintModifierData *pmd, Object * .surface = surface, .mvert = mvert, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (sData->total_points > 1000); BLI_task_parallel_range( @@ -2236,7 +2236,7 @@ typedef struct DynamicPaintCreateUVSurfaceData { } DynamicPaintCreateUVSurfaceData; static void dynamic_paint_create_uv_surface_direct_cb( - void *__restrict userdata, const int ty, const ParallelRangeTLS *__restrict UNUSED(tls)) + void *__restrict userdata, const int ty, const TaskParallelTLS *__restrict UNUSED(tls)) { const DynamicPaintCreateUVSurfaceData *data = userdata; @@ -2330,7 +2330,7 @@ static void dynamic_paint_create_uv_surface_direct_cb( } static void dynamic_paint_create_uv_surface_neighbor_cb( - void *__restrict userdata, const int ty, const ParallelRangeTLS *__restrict UNUSED(tls)) + void *__restrict userdata, const int ty, const TaskParallelTLS *__restrict UNUSED(tls)) { const DynamicPaintCreateUVSurfaceData *data = userdata; @@ -2739,7 +2739,7 @@ static bool dynamicPaint_symmetrizeAdjData(PaintAdjData *ed, int active_points) int *new_n_num = MEM_callocN(sizeof(int) * active_points, "Surface Adj Counts"); if (new_n_num && new_n_index) { - /* Count symmetrized neigbors */ + /* Count symmetrized neighbors */ int total_targets = 0; for (int index = 0; index < active_points; index++) { @@ -2948,7 +2948,7 @@ int dynamicPaint_createUVSurface(Scene *scene, .faceBB = faceBB, }; { - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (h > 64 || tottri > 1000); BLI_task_parallel_range(0, h, &data, dynamic_paint_create_uv_surface_direct_cb, &settings); @@ -2965,7 +2965,7 @@ int dynamicPaint_createUVSurface(Scene *scene, */ data.active_points = &active_points; { - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (h > 64); BLI_task_parallel_range(0, h, &data, dynamic_paint_create_uv_surface_neighbor_cb, &settings); @@ -3216,7 +3216,7 @@ typedef struct DynamicPaintOutputSurfaceImageData { } DynamicPaintOutputSurfaceImageData; static void dynamic_paint_output_surface_image_paint_cb( - void *__restrict userdata, const int index, const ParallelRangeTLS *__restrict UNUSED(tls)) + void *__restrict userdata, const int index, const TaskParallelTLS *__restrict UNUSED(tls)) { const DynamicPaintOutputSurfaceImageData *data = userdata; @@ -3238,7 +3238,7 @@ static void dynamic_paint_output_surface_image_paint_cb( } static void dynamic_paint_output_surface_image_displace_cb( - void *__restrict userdata, const int index, const ParallelRangeTLS *__restrict UNUSED(tls)) + void *__restrict userdata, const int index, const TaskParallelTLS *__restrict UNUSED(tls)) { const DynamicPaintOutputSurfaceImageData *data = userdata; @@ -3264,7 +3264,7 @@ static void dynamic_paint_output_surface_image_displace_cb( } static void dynamic_paint_output_surface_image_wave_cb( - void *__restrict userdata, const int index, const ParallelRangeTLS *__restrict UNUSED(tls)) + void *__restrict userdata, const int index, const TaskParallelTLS *__restrict UNUSED(tls)) { const DynamicPaintOutputSurfaceImageData *data = userdata; @@ -3288,7 +3288,7 @@ static void dynamic_paint_output_surface_image_wave_cb( } static void dynamic_paint_output_surface_image_wetmap_cb( - void *__restrict userdata, const int index, const ParallelRangeTLS *__restrict UNUSED(tls)) + void *__restrict userdata, const int index, const TaskParallelTLS *__restrict UNUSED(tls)) { const DynamicPaintOutputSurfaceImageData *data = userdata; @@ -3346,7 +3346,7 @@ void dynamicPaint_outputSurfaceImage(DynamicPaintSurface *surface, case MOD_DPAINT_SURFACE_T_PAINT: switch (output_layer) { case 0: { - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (sData->total_points > 10000); BLI_task_parallel_range(0, @@ -3357,7 +3357,7 @@ void dynamicPaint_outputSurfaceImage(DynamicPaintSurface *surface, break; } case 1: { - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (sData->total_points > 10000); BLI_task_parallel_range(0, @@ -3375,7 +3375,7 @@ void dynamicPaint_outputSurfaceImage(DynamicPaintSurface *surface, case MOD_DPAINT_SURFACE_T_DISPLACE: switch (output_layer) { case 0: { - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (sData->total_points > 10000); BLI_task_parallel_range(0, @@ -3395,7 +3395,7 @@ void dynamicPaint_outputSurfaceImage(DynamicPaintSurface *surface, case MOD_DPAINT_SURFACE_T_WAVE: switch (output_layer) { case 0: { - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (sData->total_points > 10000); BLI_task_parallel_range(0, @@ -3758,7 +3758,7 @@ typedef struct DynamicPaintBrushVelocityData { static void dynamic_paint_brush_velocity_compute_cb(void *__restrict userdata, const int i, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { const DynamicPaintBrushVelocityData *data = userdata; @@ -3857,7 +3857,7 @@ static void dynamicPaint_brushMeshCalculateVelocity(Depsgraph *depsgraph, .prev_obmat = prev_obmat, .timescale = timescale, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (numOfVerts_c > 10000); BLI_task_parallel_range( @@ -3942,7 +3942,7 @@ typedef struct DynamicPaintPaintData { * Paint a brush object mesh to the surface */ static void dynamic_paint_paint_mesh_cell_point_cb_ex( - void *__restrict userdata, const int id, const ParallelRangeTLS *__restrict UNUSED(tls)) + void *__restrict userdata, const int id, const TaskParallelTLS *__restrict UNUSED(tls)) { const DynamicPaintPaintData *data = userdata; @@ -4365,7 +4365,7 @@ static int dynamicPaint_paintMesh(Depsgraph *depsgraph, .brushVelocity = brushVelocity, .treeData = &treeData, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (grid->s_num[c_index] > 250); BLI_task_parallel_range(0, @@ -4393,7 +4393,7 @@ static int dynamicPaint_paintMesh(Depsgraph *depsgraph, * Paint a particle system to the surface */ static void dynamic_paint_paint_particle_cell_point_cb_ex( - void *__restrict userdata, const int id, const ParallelRangeTLS *__restrict UNUSED(tls)) + void *__restrict userdata, const int id, const TaskParallelTLS *__restrict UNUSED(tls)) { const DynamicPaintPaintData *data = userdata; @@ -4666,7 +4666,7 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, .c_index = c_index, .treeData = tree, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (grid->s_num[c_index] > 250); BLI_task_parallel_range(0, @@ -4685,7 +4685,7 @@ static int dynamicPaint_paintParticles(DynamicPaintSurface *surface, /* paint a single point of defined proximity radius to the surface */ static void dynamic_paint_paint_single_point_cb_ex(void *__restrict userdata, const int index, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { const DynamicPaintPaintData *data = userdata; @@ -4808,7 +4808,7 @@ static int dynamicPaint_paintSinglePoint(Depsgraph *depsgraph, .brushVelocity = &brushVel, .pointCoord = pointCoord, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (sData->total_points > 1000); BLI_task_parallel_range( @@ -4825,7 +4825,7 @@ static int dynamicPaint_paintSinglePoint(Depsgraph *depsgraph, static void dynamic_paint_prepare_adjacency_cb(void *__restrict userdata, const int index, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { PaintSurfaceData *sData = userdata; PaintBakeData *bData = sData->bData; @@ -4870,7 +4870,7 @@ static void dynamicPaint_prepareAdjacencyData(DynamicPaintSurface *surface, cons return; } - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (sData->total_points > 1000); BLI_task_parallel_range( @@ -5085,7 +5085,7 @@ typedef struct DynamicPaintEffectData { */ static void dynamic_paint_prepare_effect_cb(void *__restrict userdata, const int index, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { const DynamicPaintEffectData *data = userdata; @@ -5167,7 +5167,7 @@ static int dynamicPaint_prepareEffectStep(struct Depsgraph *depsgraph, .force = *force, .effectors = effectors, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (sData->total_points > 1000); BLI_task_parallel_range( @@ -5207,7 +5207,7 @@ static int dynamicPaint_prepareEffectStep(struct Depsgraph *depsgraph, */ static void dynamic_paint_effect_spread_cb(void *__restrict userdata, const int index, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { const DynamicPaintEffectData *data = userdata; @@ -5266,7 +5266,7 @@ static void dynamic_paint_effect_spread_cb(void *__restrict userdata, static void dynamic_paint_effect_shrink_cb(void *__restrict userdata, const int index, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { const DynamicPaintEffectData *data = userdata; @@ -5327,7 +5327,7 @@ static void dynamic_paint_effect_shrink_cb(void *__restrict userdata, static void dynamic_paint_effect_drip_cb(void *__restrict userdata, const int index, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { const DynamicPaintEffectData *data = userdata; @@ -5481,7 +5481,7 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, .prevPoint = prevPoint, .eff_scale = eff_scale, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (sData->total_points > 1000); BLI_task_parallel_range( @@ -5503,7 +5503,7 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, .prevPoint = prevPoint, .eff_scale = eff_scale, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (sData->total_points > 1000); BLI_task_parallel_range( @@ -5530,7 +5530,7 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, .force = force, .point_locks = point_locks, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (sData->total_points > 1000); BLI_task_parallel_range( @@ -5542,7 +5542,7 @@ static void dynamicPaint_doEffectStep(DynamicPaintSurface *surface, static void dynamic_paint_border_cb(void *__restrict userdata, const int b_index, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { const DynamicPaintEffectData *data = userdata; @@ -5613,7 +5613,7 @@ static void dynamicPaint_doBorderStep(DynamicPaintSurface *surface) .surface = surface, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (sData->adj_data->total_border > 1000); BLI_task_parallel_range( @@ -5622,7 +5622,7 @@ static void dynamicPaint_doBorderStep(DynamicPaintSurface *surface) static void dynamic_paint_wave_step_cb(void *__restrict userdata, const int index, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { const DynamicPaintEffectData *data = userdata; @@ -5777,7 +5777,7 @@ static void dynamicPaint_doWaveStep(DynamicPaintSurface *surface, float timescal .damp_factor = damp_factor, .reset_wave = (ss == steps - 1), }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (sData->total_points > 1000); BLI_task_parallel_range(0, sData->total_points, &data, dynamic_paint_wave_step_cb, &settings); @@ -5802,7 +5802,7 @@ typedef struct DynamicPaintDissolveDryData { static void dynamic_paint_surface_pre_step_cb(void *__restrict userdata, const int index, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { const DynamicPaintDissolveDryData *data = userdata; @@ -5938,7 +5938,7 @@ typedef struct DynamicPaintGenerateBakeData { static void dynamic_paint_generate_bake_data_cb(void *__restrict userdata, const int index, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { const DynamicPaintGenerateBakeData *data = userdata; @@ -6170,7 +6170,7 @@ static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, .do_velocity_data = do_velocity_data, .new_bdata = new_bdata, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (sData->total_points > 1000); BLI_task_parallel_range( @@ -6217,7 +6217,7 @@ static int dynamicPaint_doStep(Depsgraph *depsgraph, .surface = surface, .timescale = timescale, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (sData->total_points > 1000); BLI_task_parallel_range( diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c index 754b3f5876d..140d1f0d26c 100644 --- a/source/blender/blenkernel/intern/fcurve.c +++ b/source/blender/blenkernel/intern/fcurve.c @@ -1113,7 +1113,7 @@ void calchandles_fcurve(FCurve *fcu) first->f5 = last->f5 = HD_AUTOTYPE_SPECIAL; } - /* do a second pass for auto handle: compute the handle to have 0 accelaration step */ + /* do a second pass for auto handle: compute the handle to have 0 acceleration step */ if (fcu->auto_smoothing != FCURVE_SMOOTH_NONE) { BKE_nurb_handle_smooth_fcurve(fcu->bezt, fcu->totvert, cycle); } @@ -1744,7 +1744,7 @@ static float dvar_eval_transChan(ChannelDriver *driver, DriverVar *dvar) /* ......... */ -/* Table of Driver Varaiable Type Info Data */ +/* Table of Driver Variable Type Info Data */ static DriverVarTypeInfo dvar_types[MAX_DVAR_TYPES] = { BEGIN_DVAR_TYPEDEF(DVAR_TYPE_SINGLE_PROP) dvar_eval_singleProp, /* eval callback */ 1, /* number of targets used */ diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c index a0216e9b413..78117a4f615 100644 --- a/source/blender/blenkernel/intern/font.c +++ b/source/blender/blenkernel/intern/font.c @@ -1408,7 +1408,9 @@ static bool vfont_to_curve(Object *ob, cha = towupper(cha); } - if (ob == NULL || info->mat_nr > (ob->totcol)) { + /* Only do that check in case we do have an object, otherwise all materials get erased every + * time that code is called without an object... */ + if (ob != NULL && (info->mat_nr > (ob->totcol))) { // CLOG_ERROR( // &LOG, "Illegal material index (%d) in text object, setting to 0", info->mat_nr); info->mat_nr = 0; diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c index 058c0d10b8e..133c6e7297b 100644 --- a/source/blender/blenkernel/intern/gpencil.c +++ b/source/blender/blenkernel/intern/gpencil.c @@ -414,7 +414,7 @@ bGPdata *BKE_gpencil_data_addnew(Main *bmain, const char name[]) /* general flags */ gpd->flag |= GP_DATA_VIEWALIGN; gpd->flag |= GP_DATA_STROKE_FORCE_RECALC; - /* always enable object onion skin swith */ + /* always enable object onion skin switch */ gpd->flag |= GP_DATA_SHOW_ONIONSKINS; /* GP object specific settings */ ARRAY_SET_ITEMS(gpd->line_color, 0.6f, 0.6f, 0.6f, 0.5f); @@ -1662,6 +1662,22 @@ void BKE_gpencil_material_index_reassign(bGPdata *gpd, int totcol, int index) } } +/* remove strokes using a material */ +bool BKE_gpencil_material_index_used(bGPdata *gpd, int index) +{ + for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { + for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) { + for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) { + if (gps->mat_nr == index) { + return true; + } + } + } + } + + return false; +} + void BKE_gpencil_material_remap(struct bGPdata *gpd, const unsigned int *remap, unsigned int remap_len) diff --git a/source/blender/blenkernel/intern/gpencil_modifier.c b/source/blender/blenkernel/intern/gpencil_modifier.c index 7907be40984..34daba385f6 100644 --- a/source/blender/blenkernel/intern/gpencil_modifier.c +++ b/source/blender/blenkernel/intern/gpencil_modifier.c @@ -361,7 +361,7 @@ void BKE_gpencil_stroke_modifiers(Depsgraph *depsgraph, if (mti && mti->deformStroke) { mti->deformStroke(md, depsgraph, ob, gpl, gps); - /* subdivide allways requires update */ + /* subdivide always requires update */ if (md->type == eGpencilModifierType_Subdiv) { gps->flag |= GP_STROKE_RECALC_GEOMETRY; } diff --git a/source/blender/blenkernel/intern/idcode.c b/source/blender/blenkernel/intern/idcode.c index 0a9178a8b6d..6b7cb181374 100644 --- a/source/blender/blenkernel/intern/idcode.c +++ b/source/blender/blenkernel/intern/idcode.c @@ -47,8 +47,8 @@ typedef struct { /* Keep alignment for readability. */ /* clang-format off */ /** - * When editing enusre that: - * - Plural need to match rna_main.c's #MainCollectionDef. + * When editing ensure that: + * - Plural needs to match rna_main.c's #MainCollectionDef. * - Keep it in sync with i18n contexts in BLT_translation.h */ static IDType idtypes[] = { diff --git a/source/blender/blenkernel/intern/ipo.c b/source/blender/blenkernel/intern/ipo.c index e03b61bfba1..adf5d55efaa 100644 --- a/source/blender/blenkernel/intern/ipo.c +++ b/source/blender/blenkernel/intern/ipo.c @@ -1097,7 +1097,7 @@ static char *get_rna_access(ID *id, BLI_dynstr_append(path, buf); - /* need to add dot before property if there was anything precceding this */ + /* need to add dot before property if there was anything preceding this */ if (buf[0]) { BLI_dynstr_append(path, "."); } diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c index b8178bec52f..83b354ffb4a 100644 --- a/source/blender/blenkernel/intern/lattice.c +++ b/source/blender/blenkernel/intern/lattice.c @@ -889,7 +889,7 @@ typedef struct LatticeDeformUserdata { static void lattice_deform_vert_task(void *__restrict userdata, const int index, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { const LatticeDeformUserdata *data = userdata; @@ -948,7 +948,7 @@ void lattice_deform_verts(Object *laOb, .defgrp_index = defgrp_index, .fac = fac}; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.min_iter_per_thread = 32; BLI_task_parallel_range(0, numVerts, &data, lattice_deform_vert_task, &settings); diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c index 7dc04214ba5..40608285785 100644 --- a/source/blender/blenkernel/intern/layer.c +++ b/source/blender/blenkernel/intern/layer.c @@ -797,7 +797,7 @@ void BKE_layer_collection_sync(const Scene *scene, ViewLayer *view_layer) parent_restrict, parent_layer_restrict); - /* Any remaning object bases are to be removed. */ + /* Any remaining object bases are to be removed. */ for (Base *base = view_layer->object_bases.first; base; base = base->next) { if (view_layer->basact == base) { view_layer->basact = NULL; diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index b62ec88ed24..3f095d923b1 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -1130,7 +1130,7 @@ void BKE_main_lib_objects_recalc_all(Main *bmain) * **************************** */ /** - * Get allocation size fo a given data-block type and optionally allocation name. + * Get allocation size of a given data-block type and optionally allocation name. */ size_t BKE_libblock_get_alloc_info(short type, const char **name) { diff --git a/source/blender/blenkernel/intern/library_idmap.c b/source/blender/blenkernel/intern/library_idmap.c index cc7e2e31d07..ab0ff5b0096 100644 --- a/source/blender/blenkernel/intern/library_idmap.c +++ b/source/blender/blenkernel/intern/library_idmap.c @@ -85,7 +85,7 @@ static struct IDNameLib_TypeMap *main_idmap_from_idcode(struct IDNameLib_Map *id * * \note When used during undo/redo, there is no guaranty that ID pointers from UI area * are not pointing to freed memory (when some IDs have been deleted). To avoid crashes - * in those cases, one can provide the 'old' (aka current) Main databse as reference. + * in those cases, one can provide the 'old' (aka current) Main database as reference. * #BKE_main_idmap_lookup_id will then check that given ID does exist in \a old_bmain * before trying to use it. * diff --git a/source/blender/blenkernel/intern/library_query.c b/source/blender/blenkernel/intern/library_query.c index 691ef4a4dba..db4265d0894 100644 --- a/source/blender/blenkernel/intern/library_query.c +++ b/source/blender/blenkernel/intern/library_query.c @@ -376,7 +376,7 @@ static void library_foreach_ID_link(Main *bmain, int i; if (flag & IDWALK_RECURSE) { - /* For now, recusion implies read-only. */ + /* For now, recursion implies read-only. */ flag |= IDWALK_READONLY; data.ids_handled = BLI_gset_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, __func__); diff --git a/source/blender/blenkernel/intern/mask_rasterize.c b/source/blender/blenkernel/intern/mask_rasterize.c index 2ab5b69a022..e03903c05e4 100644 --- a/source/blender/blenkernel/intern/mask_rasterize.c +++ b/source/blender/blenkernel/intern/mask_rasterize.c @@ -1462,7 +1462,7 @@ typedef struct MaskRasterizeBufferData { static void maskrasterize_buffer_cb(void *__restrict userdata, const int y, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { MaskRasterizeBufferData *data = userdata; @@ -1503,7 +1503,7 @@ void BKE_maskrasterize_buffer(MaskRasterHandle *mr_handle, .width = width, .buffer = buffer, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((size_t)height * width > 10000); BLI_task_parallel_range(0, (int)height, &data, maskrasterize_buffer_cb, &settings); diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index e845271d802..b01c1189fd1 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -366,6 +366,26 @@ static void material_data_index_remove_id(ID *id, short index) } } +bool BKE_object_material_slot_used(ID *id, short actcol) +{ + /* ensure we don't try get materials from non-obdata */ + BLI_assert(OB_DATA_SUPPORT_ID(GS(id->name))); + + switch (GS(id->name)) { + case ID_ME: + return BKE_mesh_material_index_used((Mesh *)id, actcol - 1); + case ID_CU: + return BKE_curve_material_index_used((Curve *)id, actcol - 1); + case ID_MB: + /* meta-elems don't have materials atm */ + return false; + case ID_GD: + return BKE_gpencil_material_index_used((bGPdata *)id, actcol - 1); + default: + return false; + } +} + static void material_data_index_clear_id(ID *id) { /* ensure we don't try get materials from non-obdata */ @@ -496,6 +516,7 @@ void BKE_material_clear_id(Main *bmain, ID *id, bool update_data) MEM_freeN(*matar); *matar = NULL; } + test_all_objects_materials(bmain, id); if (update_data) { /* decrease mat_nr index */ @@ -1085,65 +1106,93 @@ static bNode *nodetree_uv_node_recursive(bNode *node) return NULL; } -static int count_texture_nodes_recursive(bNodeTree *nodetree) +typedef bool (*ForEachTexNodeCallback)(bNode *node, void *userdata); +static bool ntree_foreach_texnode_recursive(bNodeTree *nodetree, + ForEachTexNodeCallback callback, + void *userdata) { - int tex_nodes = 0; - for (bNode *node = nodetree->nodes.first; node; node = node->next) { if (node->typeinfo->nclass == NODE_CLASS_TEXTURE && node->typeinfo->type == SH_NODE_TEX_IMAGE && node->id) { - tex_nodes++; + if (!callback(node, userdata)) { + return false; + } } else if (ELEM(node->type, NODE_GROUP, NODE_CUSTOM_GROUP) && node->id) { /* recurse into the node group and see if it contains any textures */ - tex_nodes += count_texture_nodes_recursive((bNodeTree *)node->id); + if (!ntree_foreach_texnode_recursive((bNodeTree *)node->id, callback, userdata)) { + return false; + } } } + return true; +} + +static bool count_texture_nodes_cb(bNode *UNUSED(node), void *userdata) +{ + (*((int *)userdata))++; + return true; +} + +static int count_texture_nodes_recursive(bNodeTree *nodetree) +{ + int tex_nodes = 0; + ntree_foreach_texnode_recursive(nodetree, count_texture_nodes_cb, &tex_nodes); return tex_nodes; } -static void fill_texpaint_slots_recursive(bNodeTree *nodetree, - bNode *active_node, - Material *ma, - int *index) +struct FillTexPaintSlotsData { + bNode *active_node; + Material *ma; + int index; + int slot_len; +}; + +static bool fill_texpaint_slots_cb(bNode *node, void *userdata) { - for (bNode *node = nodetree->nodes.first; node; node = node->next) { - if (node->typeinfo->nclass == NODE_CLASS_TEXTURE && - node->typeinfo->type == SH_NODE_TEX_IMAGE && node->id) { - if (active_node == node) { - ma->paint_active_slot = *index; - } + struct FillTexPaintSlotsData *fill_data = userdata; - ma->texpaintslot[*index].ima = (Image *)node->id; - ma->texpaintslot[*index].interp = ((NodeTexImage *)node->storage)->interpolation; + Material *ma = fill_data->ma; + int index = fill_data->index; + fill_data->index++; - /* for new renderer, we need to traverse the treeback in search of a UV node */ - bNode *uvnode = nodetree_uv_node_recursive(node); + if (fill_data->active_node == node) { + ma->paint_active_slot = index; + } - if (uvnode) { - NodeShaderUVMap *storage = (NodeShaderUVMap *)uvnode->storage; - ma->texpaintslot[*index].uvname = storage->uv_map; - /* set a value to index so UI knows that we have a valid pointer for the mesh */ - ma->texpaintslot[*index].valid = true; - } - else { - /* just invalidate the index here so UV map does not get displayed on the UI */ - ma->texpaintslot[*index].valid = false; - } - (*index)++; - } - else if (ELEM(node->type, NODE_GROUP, NODE_CUSTOM_GROUP) && node->id) { - /* recurse into the node group and see if it contains any textures */ - fill_texpaint_slots_recursive((bNodeTree *)node->id, active_node, ma, index); - } + ma->texpaintslot[index].ima = (Image *)node->id; + ma->texpaintslot[index].interp = ((NodeTexImage *)node->storage)->interpolation; + + /* for new renderer, we need to traverse the treeback in search of a UV node */ + bNode *uvnode = nodetree_uv_node_recursive(node); + + if (uvnode) { + NodeShaderUVMap *storage = (NodeShaderUVMap *)uvnode->storage; + ma->texpaintslot[index].uvname = storage->uv_map; + /* set a value to index so UI knows that we have a valid pointer for the mesh */ + ma->texpaintslot[index].valid = true; } + else { + /* just invalidate the index here so UV map does not get displayed on the UI */ + ma->texpaintslot[index].valid = false; + } + + return fill_data->index != fill_data->slot_len; +} + +static void fill_texpaint_slots_recursive(bNodeTree *nodetree, + bNode *active_node, + Material *ma, + int slot_len) +{ + struct FillTexPaintSlotsData fill_data = {active_node, ma, 0, slot_len}; + ntree_foreach_texnode_recursive(nodetree, fill_texpaint_slots_cb, &fill_data); } void BKE_texpaint_slot_refresh_cache(Scene *scene, Material *ma) { int count = 0; - int index = 0; if (!ma) { return; @@ -1182,7 +1231,7 @@ void BKE_texpaint_slot_refresh_cache(Scene *scene, Material *ma) bNode *active_node = nodeGetActiveTexture(ma->nodetree); - fill_texpaint_slots_recursive(ma->nodetree, active_node, ma, &index); + fill_texpaint_slots_recursive(ma->nodetree, active_node, ma, count); ma->tot_slots = count; @@ -1207,6 +1256,31 @@ void BKE_texpaint_slots_refresh_object(Scene *scene, struct Object *ob) } } +struct FindTexPaintNodeData { + bNode *node; + short iter_index; + short index; +}; + +static bool texpaint_slot_node_find_cb(bNode *node, void *userdata) +{ + struct FindTexPaintNodeData *find_data = userdata; + if (find_data->iter_index++ == find_data->index) { + find_data->node = node; + return false; + } + + return true; +} + +bNode *BKE_texpaint_slot_material_find_node(Material *ma, short texpaint_slot) +{ + struct FindTexPaintNodeData find_data = {NULL, 0, texpaint_slot}; + ntree_foreach_texnode_recursive(ma->nodetree, texpaint_slot_node_find_cb, &find_data); + + return find_data.node; +} + /* r_col = current value, col = new value, (fac == 0) is no change */ void ramp_blend(int type, float r_col[3], const float fac, const float col[3]) { diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index f5e93dcf9b7..7e755e54eaa 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -40,6 +40,7 @@ #include "BKE_idcode.h" #include "BKE_main.h" #include "BKE_global.h" +#include "BKE_key.h" #include "BKE_mesh.h" #include "BKE_mesh_runtime.h" #include "BKE_library.h" @@ -479,20 +480,38 @@ bool BKE_mesh_has_custom_loop_normals(Mesh *me) /** Free (or release) any data used by this mesh (does not free the mesh itself). */ void BKE_mesh_free(Mesh *me) { - BKE_animdata_free(&me->id, false); + BKE_mesh_clear_geometry(me); + MEM_SAFE_FREE(me->mat); +} - BKE_mesh_runtime_clear_cache(me); +void BKE_mesh_clear_geometry(Mesh *mesh) +{ + BKE_animdata_free(&mesh->id, false); + BKE_mesh_runtime_clear_cache(mesh); - CustomData_free(&me->vdata, me->totvert); - CustomData_free(&me->edata, me->totedge); - CustomData_free(&me->fdata, me->totface); - CustomData_free(&me->ldata, me->totloop); - CustomData_free(&me->pdata, me->totpoly); + CustomData_free(&mesh->vdata, mesh->totvert); + CustomData_free(&mesh->edata, mesh->totedge); + CustomData_free(&mesh->fdata, mesh->totface); + CustomData_free(&mesh->ldata, mesh->totloop); + CustomData_free(&mesh->pdata, mesh->totpoly); - MEM_SAFE_FREE(me->mat); - MEM_SAFE_FREE(me->bb); - MEM_SAFE_FREE(me->mselect); - MEM_SAFE_FREE(me->edit_mesh); + MEM_SAFE_FREE(mesh->bb); + MEM_SAFE_FREE(mesh->mselect); + MEM_SAFE_FREE(mesh->edit_mesh); + + /* Note that materials and shape keys are not freed here. This is intentional, as freeing + * shape keys requires tagging the depsgraph for updated relations, which is expensive. + * Material slots should be kept in sync with the object.*/ + + mesh->totvert = 0; + mesh->totedge = 0; + mesh->totface = 0; + mesh->totloop = 0; + mesh->totpoly = 0; + mesh->act_face = -1; + mesh->totselect = 0; + + BKE_mesh_update_customdata_pointers(mesh, false); } static void mesh_tessface_clear_intern(Mesh *mesh, int free_customdata) @@ -697,6 +716,15 @@ Mesh *BKE_mesh_new_nomain_from_template(const Mesh *me_src, me_src, verts_len, edges_len, tessface_len, loops_len, polys_len, CD_MASK_EVERYTHING); } +void BKE_mesh_eval_delete(struct Mesh *mesh_eval) +{ + /* Evaluated mesh may point to edit mesh, but never owns it. */ + mesh_eval->edit_mesh = NULL; + BKE_mesh_free(mesh_eval); + BKE_libblock_free_data(&mesh_eval->id, false); + MEM_freeN(mesh_eval); +} + Mesh *BKE_mesh_copy_for_eval(struct Mesh *source, bool reference) { int flags = LIB_ID_COPY_LOCALIZE; @@ -1178,6 +1206,27 @@ void BKE_mesh_material_index_remove(Mesh *me, short index) } } +bool BKE_mesh_material_index_used(Mesh *me, short index) +{ + MPoly *mp; + MFace *mf; + int i; + + for (mp = me->mpoly, i = 0; i < me->totpoly; i++, mp++) { + if (mp->mat_nr == index) { + return true; + } + } + + for (mf = me->mface, i = 0; i < me->totface; i++, mf++) { + if (mf->mat_nr == index) { + return true; + } + } + + return false; +} + void BKE_mesh_material_index_clear(Mesh *me) { MPoly *mp; diff --git a/source/blender/blenkernel/intern/mesh_evaluate.c b/source/blender/blenkernel/intern/mesh_evaluate.c index 17b22a6d095..e28d50cbde4 100644 --- a/source/blender/blenkernel/intern/mesh_evaluate.c +++ b/source/blender/blenkernel/intern/mesh_evaluate.c @@ -220,7 +220,7 @@ typedef struct MeshCalcNormalsData { static void mesh_calc_normals_poly_cb(void *__restrict userdata, const int pidx, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { MeshCalcNormalsData *data = userdata; const MPoly *mp = &data->mpolys[pidx]; @@ -230,7 +230,7 @@ static void mesh_calc_normals_poly_cb(void *__restrict userdata, static void mesh_calc_normals_poly_prepare_cb(void *__restrict userdata, const int pidx, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { MeshCalcNormalsData *data = userdata; const MPoly *mp = &data->mpolys[pidx]; @@ -294,7 +294,7 @@ static void mesh_calc_normals_poly_prepare_cb(void *__restrict userdata, static void mesh_calc_normals_poly_finalize_cb(void *__restrict userdata, const int vidx, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { MeshCalcNormalsData *data = userdata; @@ -321,7 +321,7 @@ void BKE_mesh_calc_normals_poly(MVert *mverts, { float(*pnors)[3] = r_polynors; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.min_iter_per_thread = 1024; diff --git a/source/blender/blenkernel/intern/mesh_validate.c b/source/blender/blenkernel/intern/mesh_validate.c index dac12233539..c8e75532075 100644 --- a/source/blender/blenkernel/intern/mesh_validate.c +++ b/source/blender/blenkernel/intern/mesh_validate.c @@ -1200,7 +1200,7 @@ void BKE_mesh_strip_loose_polysloops(Mesh *me) int i = p->loopstart; int stop = i + p->totloop; - if (stop > me->totloop || stop < i) { + if (stop > me->totloop || stop < i || p->loopstart < 0) { invalid = true; } else { diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c index c23fe30d311..656ec50f31b 100644 --- a/source/blender/blenkernel/intern/modifier.c +++ b/source/blender/blenkernel/intern/modifier.c @@ -802,7 +802,7 @@ bool modifiers_usesSubsurfFacedots(struct Scene *scene, Object *ob) } } else if (mti->type == eModifierTypeType_OnlyDeform) { - /* Theses modifiers do not reset the subdiv flag nor change the topology. + /* These modifiers do not reset the subdiv flag nor change the topology. * We can still search for a subsurf modifier. */ } else { diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index 6bc83f8dd09..f67bc419210 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -53,6 +53,7 @@ #include "BKE_animsys.h" #include "BKE_colortools.h" +#include "BKE_global.h" #include "BKE_library.h" #include "BKE_main.h" #include "BKE_movieclip.h" @@ -1772,9 +1773,17 @@ static void movieclip_selection_synchronize(MovieClip *clip_dst, const MovieClip } } -void BKE_movieclip_eval_update(struct Depsgraph *depsgraph, MovieClip *clip) +static void movieclip_eval_update_reload(struct Depsgraph *depsgraph, Main *bmain, MovieClip *clip) +{ + BKE_movieclip_reload(bmain, clip); + if (DEG_is_active(depsgraph)) { + MovieClip *clip_orig = (MovieClip *)DEG_get_original_id(&clip->id); + BKE_movieclip_reload(bmain, clip_orig); + } +} + +static void movieclip_eval_update_generic(struct Depsgraph *depsgraph, MovieClip *clip) { - DEG_debug_print_eval(depsgraph, __func__, clip->id.name, clip); BKE_tracking_dopesheet_tag_update(&clip->tracking); if (DEG_is_active(depsgraph)) { MovieClip *clip_orig = (MovieClip *)DEG_get_original_id(&clip->id); @@ -1782,6 +1791,17 @@ void BKE_movieclip_eval_update(struct Depsgraph *depsgraph, MovieClip *clip) } } +void BKE_movieclip_eval_update(struct Depsgraph *depsgraph, Main *bmain, MovieClip *clip) +{ + DEG_debug_print_eval(depsgraph, __func__, clip->id.name, clip); + if (clip->id.recalc & ID_RECALC_SOURCE) { + movieclip_eval_update_reload(depsgraph, bmain, clip); + } + else { + movieclip_eval_update_generic(depsgraph, clip); + } +} + void BKE_movieclip_eval_selection_update(struct Depsgraph *depsgraph, MovieClip *clip) { DEG_debug_print_eval(depsgraph, __func__, clip->id.name, clip); diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c index 29337ca9985..bbae1f4d3bc 100644 --- a/source/blender/blenkernel/intern/multires.c +++ b/source/blender/blenkernel/intern/multires.c @@ -1078,7 +1078,7 @@ typedef struct MultiresThreadedData { static void multires_disp_run_cb(void *__restrict userdata, const int pidx, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { MultiresThreadedData *tdata = userdata; @@ -1230,7 +1230,7 @@ static void multiresModifier_disp_run( } } - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.min_iter_per_thread = CCG_TASK_LIMIT; diff --git a/source/blender/blenkernel/intern/multires_reshape.c b/source/blender/blenkernel/intern/multires_reshape.c index 749cedb5388..d939267ac5a 100644 --- a/source/blender/blenkernel/intern/multires_reshape.c +++ b/source/blender/blenkernel/intern/multires_reshape.c @@ -955,7 +955,7 @@ typedef struct ReshapeFromCCGTaskData { static void reshape_from_ccg_task(void *__restrict userdata, const int coarse_poly_index, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { ReshapeFromCCGTaskData *data = userdata; const CCGKey *key = data->key; @@ -1045,7 +1045,7 @@ bool multiresModifier_reshapeFromCCG(const int tot_level, Mesh *coarse_mesh, Sub MultiresPropagateData propagate_data; multires_reshape_propagate_prepare(&propagate_data, coarse_mesh, key.level, top_level); /* Threaded grids iteration. */ - ParallelRangeSettings parallel_range_settings; + TaskParallelSettings parallel_range_settings; BLI_parallel_range_settings_defaults(¶llel_range_settings); BLI_task_parallel_range( 0, coarse_mesh->totpoly, &data, reshape_from_ccg_task, ¶llel_range_settings); diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index d7256cc9604..eb2f23a7b2a 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -442,19 +442,13 @@ void BKE_object_free_derived_caches(Object *ob) if (ob->runtime.mesh_eval != NULL) { if (ob->runtime.is_mesh_eval_owned) { Mesh *mesh_eval = ob->runtime.mesh_eval; - /* Evaluated mesh points to edit mesh, but does not own it. */ - mesh_eval->edit_mesh = NULL; - BKE_mesh_free(mesh_eval); - BKE_libblock_free_data(&mesh_eval->id, false); - MEM_freeN(mesh_eval); + BKE_mesh_eval_delete(mesh_eval); } ob->runtime.mesh_eval = NULL; } if (ob->runtime.mesh_deform_eval != NULL) { Mesh *mesh_deform_eval = ob->runtime.mesh_deform_eval; - BKE_mesh_free(mesh_deform_eval); - BKE_libblock_free_data(&mesh_deform_eval->id, false); - MEM_freeN(mesh_deform_eval); + BKE_mesh_eval_delete(mesh_deform_eval); ob->runtime.mesh_deform_eval = NULL; } @@ -1829,7 +1823,7 @@ void BKE_object_copy_proxy_drivers(Object *ob, Object *target) else { /* only on local objects because this causes indirect links * 'a -> b -> c', blend to point directly to a.blend - * when a.blend has a proxy thats linked into c.blend */ + * when a.blend has a proxy that's linked into c.blend */ if (!ID_IS_LINKED(ob)) { id_lib_extern((ID *)dtar->id); } @@ -2568,7 +2562,8 @@ static void object_where_is_calc_ex(Depsgraph *depsgraph, void BKE_object_where_is_calc_time(Depsgraph *depsgraph, Scene *scene, Object *ob, float ctime) { /* Execute drivers and animation. */ - BKE_animsys_evaluate_animdata(depsgraph, scene, &ob->id, ob->adt, ctime, ADT_RECALC_ALL); + const bool flush_to_original = DEG_is_active(depsgraph); + BKE_animsys_evaluate_animdata(scene, &ob->id, ob->adt, ctime, ADT_RECALC_ALL, flush_to_original); object_where_is_calc_ex(depsgraph, scene, ob, ctime, NULL, NULL); } @@ -4341,6 +4336,7 @@ bool BKE_object_modifier_update_subframe(Depsgraph *depsgraph, float frame, int type) { + const bool flush_to_original = DEG_is_active(depsgraph); ModifierData *md = modifiers_findByType(ob, (ModifierType)type); bConstraint *con; @@ -4405,7 +4401,8 @@ bool BKE_object_modifier_update_subframe(Depsgraph *depsgraph, /* TODO(sergey): What about animation? */ ob->id.recalc |= ID_RECALC_ALL; if (update_mesh) { - BKE_animsys_evaluate_animdata(depsgraph, scene, &ob->id, ob->adt, frame, ADT_RECALC_ANIM); + BKE_animsys_evaluate_animdata( + scene, &ob->id, ob->adt, frame, ADT_RECALC_ANIM, flush_to_original); /* ignore cache clear during subframe updates * to not mess up cache validity */ object_cacheIgnoreClear(ob, 1); @@ -4419,12 +4416,14 @@ bool BKE_object_modifier_update_subframe(Depsgraph *depsgraph, /* for curve following objects, parented curve has to be updated too */ if (ob->type == OB_CURVE) { Curve *cu = ob->data; - BKE_animsys_evaluate_animdata(depsgraph, scene, &cu->id, cu->adt, frame, ADT_RECALC_ANIM); + BKE_animsys_evaluate_animdata( + scene, &cu->id, cu->adt, frame, ADT_RECALC_ANIM, flush_to_original); } /* and armatures... */ if (ob->type == OB_ARMATURE) { bArmature *arm = ob->data; - BKE_animsys_evaluate_animdata(depsgraph, scene, &arm->id, arm->adt, frame, ADT_RECALC_ANIM); + BKE_animsys_evaluate_animdata( + scene, &arm->id, arm->adt, frame, ADT_RECALC_ANIM, flush_to_original); BKE_pose_where_is(depsgraph, scene, ob); } diff --git a/source/blender/blenkernel/intern/ocean.c b/source/blender/blenkernel/intern/ocean.c index b5df7d5fe9b..39fb668c873 100644 --- a/source/blender/blenkernel/intern/ocean.c +++ b/source/blender/blenkernel/intern/ocean.c @@ -510,7 +510,7 @@ typedef struct OceanSimulateData { static void ocean_compute_htilda(void *__restrict userdata, const int i, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { OceanSimulateData *osd = userdata; const Ocean *o = osd->o; @@ -779,7 +779,7 @@ void BKE_ocean_simulate(struct Ocean *o, float t, float scale, float chop_amount * but remains reasonably simple and should be OK most of the time. */ /* compute a new htilda */ - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (o->_M > 16); BLI_task_parallel_range(0, o->_M, &osd, ocean_compute_htilda, &settings); diff --git a/source/blender/blenkernel/intern/paint_toolslots.c b/source/blender/blenkernel/intern/paint_toolslots.c index fbf586e3f49..a252329b635 100644 --- a/source/blender/blenkernel/intern/paint_toolslots.c +++ b/source/blender/blenkernel/intern/paint_toolslots.c @@ -67,11 +67,21 @@ void BKE_paint_toolslots_init_from_main(struct Main *bmain) for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) { ToolSettings *ts = scene->toolsettings; paint_toolslots_init(bmain, &ts->imapaint.paint); - paint_toolslots_init(bmain, &ts->sculpt->paint); - paint_toolslots_init(bmain, &ts->vpaint->paint); - paint_toolslots_init(bmain, &ts->wpaint->paint); - paint_toolslots_init(bmain, &ts->uvsculpt->paint); - paint_toolslots_init(bmain, &ts->gp_paint->paint); + if (ts->sculpt) { + paint_toolslots_init(bmain, &ts->sculpt->paint); + } + if (ts->vpaint) { + paint_toolslots_init(bmain, &ts->vpaint->paint); + } + if (ts->wpaint) { + paint_toolslots_init(bmain, &ts->wpaint->paint); + } + if (ts->uvsculpt) { + paint_toolslots_init(bmain, &ts->uvsculpt->paint); + } + if (ts->gp_paint) { + paint_toolslots_init(bmain, &ts->gp_paint->paint); + } } } diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index 079a348745c..64616af945f 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -3112,7 +3112,7 @@ typedef struct CacheEditrPathsIterData { static void psys_cache_edit_paths_iter(void *__restrict iter_data_v, const int iter, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { CacheEditrPathsIterData *iter_data = (CacheEditrPathsIterData *)iter_data_v; PTCacheEdit *edit = iter_data->edit; @@ -3334,7 +3334,7 @@ void psys_cache_edit_paths(Depsgraph *depsgraph, iter_data.nosel_col[2] = (float)edit->nosel_col[2] / 255.0f; } - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.scheduling_mode = TASK_SCHEDULING_DYNAMIC; BLI_task_parallel_range(0, edit->totpoint, &iter_data, psys_cache_edit_paths_iter, &settings); @@ -4259,7 +4259,7 @@ static void get_child_modifier_parameters(ParticleSettings *part, ctx->mesh, cpa_from, cpa_num, cpa_fuv, ctx->vg_twist); } } -/* get's hair (or keyed) particles state at the "path time" specified in state->time */ +/* gets hair (or keyed) particles state at the "path time" specified in state->time */ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey *state, diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index 27722aab2d9..5685e5cd05e 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -3685,7 +3685,7 @@ typedef struct DynamicStepSolverTaskData { static void dynamics_step_sph_ddr_task_cb_ex(void *__restrict userdata, const int p, - const ParallelRangeTLS *__restrict tls) + const TaskParallelTLS *__restrict tls) { DynamicStepSolverTaskData *data = userdata; ParticleSimulationData *sim = data->sim; @@ -3720,7 +3720,7 @@ static void dynamics_step_sph_ddr_task_cb_ex(void *__restrict userdata, } static void dynamics_step_sph_classical_basic_integrate_task_cb_ex( - void *__restrict userdata, const int p, const ParallelRangeTLS *__restrict UNUSED(tls)) + void *__restrict userdata, const int p, const TaskParallelTLS *__restrict UNUSED(tls)) { DynamicStepSolverTaskData *data = userdata; ParticleSimulationData *sim = data->sim; @@ -3736,7 +3736,7 @@ static void dynamics_step_sph_classical_basic_integrate_task_cb_ex( } static void dynamics_step_sph_classical_calc_density_task_cb_ex( - void *__restrict userdata, const int p, const ParallelRangeTLS *__restrict tls) + void *__restrict userdata, const int p, const TaskParallelTLS *__restrict tls) { DynamicStepSolverTaskData *data = userdata; ParticleSimulationData *sim = data->sim; @@ -3753,8 +3753,9 @@ static void dynamics_step_sph_classical_calc_density_task_cb_ex( sphclassical_calc_dens(pa, pa->state.time, sphdata); } -static void dynamics_step_sph_classical_integrate_task_cb_ex( - void *__restrict userdata, const int p, const ParallelRangeTLS *__restrict tls) +static void dynamics_step_sph_classical_integrate_task_cb_ex(void *__restrict userdata, + const int p, + const TaskParallelTLS *__restrict tls) { DynamicStepSolverTaskData *data = userdata; ParticleSimulationData *sim = data->sim; @@ -3963,7 +3964,7 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra) /* Apply SPH forces using double-density relaxation algorithm * (Clavat et. al.) */ - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (psys->totpart > 100); settings.userdata_chunk = &sphdata; @@ -3980,7 +3981,7 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra) * this algorithm is separated into distinct loops. */ { - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (psys->totpart > 100); BLI_task_parallel_range(0, @@ -3994,7 +3995,7 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra) /* Note that we could avoid copying sphdata for each thread here (it's only read here), * but doubt this would gain us anything except confusion... */ { - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (psys->totpart > 100); settings.userdata_chunk = &sphdata; @@ -4008,7 +4009,7 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra) /* do global forces & effectors */ { - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (psys->totpart > 100); settings.userdata_chunk = &sphdata; @@ -4662,7 +4663,7 @@ void particle_system_update(struct Depsgraph *depsgraph, hcfra = 100.0f * (float)i / (float)psys->part->hair_step; if ((part->flag & PART_HAIR_REGROW) == 0) { BKE_animsys_evaluate_animdata( - depsgraph, scene, &part_local->id, part_local->adt, hcfra, ADT_RECALC_ANIM); + scene, &part_local->id, part_local->adt, hcfra, ADT_RECALC_ANIM, false); } system_step(&sim, hcfra, use_render_params); psys->cfra = hcfra; diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c index ffc4ec65d4d..860e2bdaa93 100644 --- a/source/blender/blenkernel/intern/pbvh.c +++ b/source/blender/blenkernel/intern/pbvh.c @@ -995,7 +995,7 @@ typedef struct PBVHUpdateData { static void pbvh_update_normals_accum_task_cb(void *__restrict userdata, const int n, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { PBVHUpdateData *data = userdata; @@ -1045,7 +1045,7 @@ static void pbvh_update_normals_accum_task_cb(void *__restrict userdata, static void pbvh_update_normals_store_task_cb(void *__restrict userdata, const int n, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { PBVHUpdateData *data = userdata; PBVH *bvh = data->bvh; @@ -1094,7 +1094,7 @@ static void pbvh_faces_update_normals(PBVH *bvh, PBVHNode **nodes, int totnode) .vnors = vnors, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (totnode > PBVH_THREADED_LIMIT); @@ -1107,7 +1107,7 @@ static void pbvh_faces_update_normals(PBVH *bvh, PBVHNode **nodes, int totnode) static void pbvh_update_BB_redraw_task_cb(void *__restrict userdata, const int n, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { PBVHUpdateData *data = userdata; PBVH *bvh = data->bvh; @@ -1138,7 +1138,7 @@ void pbvh_update_BB_redraw(PBVH *bvh, PBVHNode **nodes, int totnode, int flag) .flag = flag, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (totnode > PBVH_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, pbvh_update_BB_redraw_task_cb, &settings); diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index b577efd2a22..bf33e076e32 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -3810,7 +3810,7 @@ void BKE_ptcache_remove(void) closedir(dir); } else { - rmdir = 0; /* path dosnt exist */ + rmdir = 0; /* path doesn't exist */ } if (rmdir) { diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c index c2d51b72b29..b29e07bb56d 100644 --- a/source/blender/blenkernel/intern/sequencer.c +++ b/source/blender/blenkernel/intern/sequencer.c @@ -3336,8 +3336,7 @@ static ImBuf *seq_render_mask(const SeqRenderData *context, Mask *mask, float nr /* anim-data */ adt = BKE_animdata_from_id(&mask->id); - BKE_animsys_evaluate_animdata( - context->depsgraph, context->scene, &mask_temp->id, adt, nr, ADT_RECALC_ANIM); + BKE_animsys_evaluate_animdata(context->scene, &mask_temp->id, adt, nr, ADT_RECALC_ANIM, false); maskbuf = MEM_mallocN(sizeof(float) * context->rectx * context->recty, __func__); @@ -3711,7 +3710,7 @@ static ImBuf *do_render_strip_uncached(const SeqRenderData *context, case SEQ_TYPE_SCENE: { if (seq->flag & SEQ_SCENE_STRIPS) { if (seq->scene && (context->scene != seq->scene)) { - /* recusrive check */ + /* recursive check */ if (BLI_linklist_index(state->scene_parents, seq->scene) != -1) { break; } @@ -4645,7 +4644,7 @@ void BKE_sequence_tx_handle_xlimits(Sequence *seq, int leftflag, int rightflag) BKE_sequence_tx_set_final_left(seq, seq_tx_get_end(seq) - 1); } - /* dosnt work now - TODO */ + /* doesn't work now - TODO */ #if 0 if (seq_tx_get_start(seq) >= seq_tx_get_final_right(seq, 0)) { int ofs; @@ -5836,7 +5835,7 @@ static Sequence *seq_dupli(const Scene *scene_src, /* When using SEQ_DUPE_UNIQUE_NAME, it is mandatory to add new sequences in relevant container * (scene or meta's one), *before* checking for unique names. Otherwise the meta's list is empty * and hence we miss all seqs in that meta that have already been duplicated (see T55668). - * Note that unique name check itslef could be done at a later step in calling code, once all + * Note that unique name check itself could be done at a later step in calling code, once all * seqs have bee duplicated (that was first, simpler solution), but then handling of animation * data will be broken (see T60194). */ if (new_seq_list != NULL) { diff --git a/source/blender/blenkernel/intern/shrinkwrap.c b/source/blender/blenkernel/intern/shrinkwrap.c index 6a72b46a8f2..9b9fd33f52d 100644 --- a/source/blender/blenkernel/intern/shrinkwrap.c +++ b/source/blender/blenkernel/intern/shrinkwrap.c @@ -344,7 +344,7 @@ void BKE_shrinkwrap_compute_boundary_data(struct Mesh *mesh) */ static void shrinkwrap_calc_nearest_vertex_cb_ex(void *__restrict userdata, const int i, - const ParallelRangeTLS *__restrict tls) + const TaskParallelTLS *__restrict tls) { ShrinkwrapCalcCBData *data = userdata; @@ -416,7 +416,7 @@ static void shrinkwrap_calc_nearest_vertex(ShrinkwrapCalcData *calc) .calc = calc, .tree = calc->tree, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (calc->numVerts > BKE_MESH_OMP_LIMIT); settings.userdata_chunk = &nearest; @@ -510,7 +510,7 @@ bool BKE_shrinkwrap_project_normal(char options, static void shrinkwrap_calc_normal_projection_cb_ex(void *__restrict userdata, const int i, - const ParallelRangeTLS *__restrict tls) + const TaskParallelTLS *__restrict tls) { ShrinkwrapCalcCBData *data = userdata; @@ -703,7 +703,7 @@ static void shrinkwrap_calc_normal_projection(ShrinkwrapCalcData *calc) .proj_axis = proj_axis, .local2aux = &local2aux, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (calc->numVerts > BKE_MESH_OMP_LIMIT); settings.userdata_chunk = &hit; @@ -1115,7 +1115,7 @@ void BKE_shrinkwrap_find_nearest_surface(struct ShrinkwrapTreeData *tree, */ static void shrinkwrap_calc_nearest_surface_point_cb_ex(void *__restrict userdata, const int i, - const ParallelRangeTLS *__restrict tls) + const TaskParallelTLS *__restrict tls) { ShrinkwrapCalcCBData *data = userdata; @@ -1363,7 +1363,7 @@ static void shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *calc) .calc = calc, .tree = calc->tree, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (calc->numVerts > BKE_MESH_OMP_LIMIT); settings.userdata_chunk = &nearest; diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c index bb8fd18ea58..688af539bbb 100644 --- a/source/blender/blenkernel/intern/smoke.c +++ b/source/blender/blenkernel/intern/smoke.c @@ -819,7 +819,7 @@ typedef struct ObstaclesFromDMData { static void obstacles_from_mesh_task_cb(void *__restrict userdata, const int z, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { ObstaclesFromDMData *data = userdata; SmokeDomainSettings *sds = data->sds; @@ -974,7 +974,7 @@ static void obstacles_from_mesh(Object *coll_ob, .velocityZ = velocityZ, .num_obstacles = num_obstacles, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.scheduling_mode = TASK_SCHEDULING_DYNAMIC; BLI_task_parallel_range( @@ -1328,7 +1328,7 @@ typedef struct EmitFromParticlesData { static void emit_from_particles_task_cb(void *__restrict userdata, const int z, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { EmitFromParticlesData *data = userdata; SmokeFlowSettings *sfs = data->sfs; @@ -1567,7 +1567,7 @@ static void emit_from_particles(Object *flow_ob, .hr_smooth = hr_smooth, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.scheduling_mode = TASK_SCHEDULING_DYNAMIC; BLI_task_parallel_range(min[2], max[2], &data, emit_from_particles_task_cb, &settings); @@ -1770,7 +1770,7 @@ typedef struct EmitFromDMData { static void emit_from_mesh_task_cb(void *__restrict userdata, const int z, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { EmitFromDMData *data = userdata; EmissionMap *em = data->em; @@ -1975,7 +1975,7 @@ static void emit_from_mesh( .res = res, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.scheduling_mode = TASK_SCHEDULING_DYNAMIC; BLI_task_parallel_range(min[2], max[2], &data, emit_from_mesh_task_cb, &settings); @@ -2893,7 +2893,7 @@ typedef struct UpdateEffectorsData { static void update_effectors_task_cb(void *__restrict userdata, const int x, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { UpdateEffectorsData *data = userdata; SmokeDomainSettings *sds = data->sds; @@ -2967,7 +2967,7 @@ static void update_effectors( data.velocity_z = smoke_get_velocity_z(sds->fluid); data.obstacle = smoke_get_obstacle(sds->fluid); - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.scheduling_mode = TASK_SCHEDULING_DYNAMIC; BLI_task_parallel_range(0, sds->res[0], &data, update_effectors_task_cb, &settings); @@ -3523,7 +3523,7 @@ static void smoke_calc_transparency(SmokeDomainSettings *sds, ViewLayer *view_la // get starting cell (light pos) if (BLI_bvhtree_bb_raycast(bv, light, voxelCenter, pos) > FLT_EPSILON) { - // we're ouside -> use point on side of domain + // we're outside -> use point on side of domain cell[0] = (int)floor(pos[0]); cell[1] = (int)floor(pos[1]); cell[2] = (int)floor(pos[2]); diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c index 03fbdc24ce4..2024a507ebb 100644 --- a/source/blender/blenkernel/intern/softbody.c +++ b/source/blender/blenkernel/intern/softbody.c @@ -258,7 +258,7 @@ static float _final_mass(Object *ob, BodyPoint *bp) /* just an ID here to reduce the prob for killing objects * ob->sumohandle points to we should not kill :) */ -static const int CCD_SAVETY = 190561; +static const int CCD_SAFETY = 190561; typedef struct ccdf_minmax { float minx, miny, minz, maxx, maxy, maxz; @@ -269,7 +269,7 @@ typedef struct ccd_Mesh { const MVert *mvert; const MVert *mprevvert; const MVertTri *tri; - int savety; + int safety; ccdf_minmax *mima; /* Axis Aligned Bounding Box AABB */ float bbmin[3]; @@ -298,7 +298,7 @@ static ccd_Mesh *ccd_mesh_make(Object *ob) pccd_M = MEM_mallocN(sizeof(ccd_Mesh), "ccd_Mesh"); pccd_M->mvert_num = cmd->mvert_num; pccd_M->tri_num = cmd->tri_num; - pccd_M->savety = CCD_SAVETY; + pccd_M->safety = CCD_SAFETY; pccd_M->bbmin[0] = pccd_M->bbmin[1] = pccd_M->bbmin[2] = 1e30f; pccd_M->bbmax[0] = pccd_M->bbmax[1] = pccd_M->bbmax[2] = -1e30f; pccd_M->mprevvert = NULL; @@ -486,7 +486,8 @@ static void ccd_mesh_update(Object *ob, ccd_Mesh *pccd_M) static void ccd_mesh_free(ccd_Mesh *ccdm) { - if (ccdm && (ccdm->savety == CCD_SAVETY)) { /*make sure we're not nuking objects we don't know*/ + /* Make sure we're not nuking objects we don't know. */ + if (ccdm && (ccdm->safety == CCD_SAFETY)) { MEM_freeN((void *)ccdm->mvert); MEM_freeN((void *)ccdm->tri); if (ccdm->mprevvert) { @@ -751,7 +752,7 @@ static void build_bps_springlist(Object *ob) int a, b; if (sb == NULL) { - return; /* paranoya check */ + return; /* paranoia check */ } for (a = sb->totpoint, bp = sb->bpoint; a > 0; a--, bp++) { @@ -781,7 +782,7 @@ static void calculate_collision_balls(Object *ob) float min, max, akku; if (sb == NULL) { - return; /* paranoya check */ + return; /* paranoia check */ } for (a = sb->totpoint, bp = sb->bpoint; a > 0; a--, bp++) { @@ -3322,7 +3323,7 @@ static void softbody_reset(Object *ob, SoftBody *sb, float (*vertexCos)[3], int copy_v3_v3(bp->prevdv, bp->vec); } - /* make a nice clean scratch struc */ + /* make a nice clean scratch struct */ free_scratch(sb); /* clear if any */ sb_new_scratch(sb); /* make a new */ sb->scratch->needstobuildcollider = 1; diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c index 6d782726e07..6cbb01861e2 100644 --- a/source/blender/blenkernel/intern/sound.c +++ b/source/blender/blenkernel/intern/sound.c @@ -898,7 +898,7 @@ void BKE_sound_read_waveform(Main *bmain, bSound *sound, short *stop) { bool need_close_audio_handles = false; if (sound->playback_handle == NULL) { - /* TOOD(sergey): Make it fully independent audio handle. */ + /* TODO(sergey): Make it fully independent audio handle. */ sound_load_audio(bmain, sound); need_close_audio_handles = true; } @@ -1092,7 +1092,7 @@ bool BKE_sound_info_get(struct Main *main, struct bSound *sound, SoundInfo *soun if (sound->playback_handle != NULL) { return sound_info_from_playback_handle(sound->playback_handle, sound_info); } - /* TOOD(sergey): Make it fully independent audio handle. */ + /* TODO(sergey): Make it fully independent audio handle. */ sound_load_audio(main, sound); const bool result = sound_info_from_playback_handle(sound->playback_handle, sound_info); sound_free_audio(sound); diff --git a/source/blender/blenkernel/intern/subdiv_ccg.c b/source/blender/blenkernel/intern/subdiv_ccg.c index fac1e1dbe75..d346d4d6f8d 100644 --- a/source/blender/blenkernel/intern/subdiv_ccg.c +++ b/source/blender/blenkernel/intern/subdiv_ccg.c @@ -267,7 +267,7 @@ static void subdiv_ccg_eval_special_grid(CCGEvalGridsData *data, const int face_ static void subdiv_ccg_eval_grids_task(void *__restrict userdata_v, const int face_index, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { CCGEvalGridsData *data = userdata_v; SubdivCCG *subdiv_ccg = data->subdiv_ccg; @@ -295,7 +295,7 @@ static bool subdiv_ccg_evaluate_grids(SubdivCCG *subdiv_ccg, data.mask_evaluator = mask_evaluator; data.material_flags_evaluator = material_flags_evaluator; /* Threaded grids evaluation. */ - ParallelRangeSettings parallel_range_settings; + TaskParallelSettings parallel_range_settings; BLI_parallel_range_settings_defaults(¶llel_range_settings); BLI_task_parallel_range( 0, num_faces, &data, subdiv_ccg_eval_grids_task, ¶llel_range_settings); @@ -747,7 +747,7 @@ static void subdiv_ccg_average_inner_face_normals(SubdivCCG *subdiv_ccg, static void subdiv_ccg_recalc_inner_normal_task(void *__restrict userdata_v, const int grid_index, - const ParallelRangeTLS *__restrict tls_v) + const TaskParallelTLS *__restrict tls_v) { RecalcInnerNormalsData *data = userdata_v; RecalcInnerNormalsTLSData *tls = tls_v->userdata_chunk; @@ -772,7 +772,7 @@ static void subdiv_ccg_recalc_inner_grid_normals(SubdivCCG *subdiv_ccg) .key = &key, }; RecalcInnerNormalsTLSData tls_data = {NULL}; - ParallelRangeSettings parallel_range_settings; + TaskParallelSettings parallel_range_settings; BLI_parallel_range_settings_defaults(¶llel_range_settings); parallel_range_settings.userdata_chunk = &tls_data; parallel_range_settings.userdata_chunk_size = sizeof(tls_data); @@ -802,7 +802,7 @@ typedef struct RecalcModifiedInnerNormalsData { static void subdiv_ccg_recalc_modified_inner_normal_task(void *__restrict userdata_v, const int face_index, - const ParallelRangeTLS *__restrict tls_v) + const TaskParallelTLS *__restrict tls_v) { RecalcModifiedInnerNormalsData *data = userdata_v; SubdivCCG *subdiv_ccg = data->subdiv_ccg; @@ -838,7 +838,7 @@ static void subdiv_ccg_recalc_modified_inner_grid_normals(SubdivCCG *subdiv_ccg, .effected_ccg_faces = (SubdivCCGFace **)effected_faces, }; RecalcInnerNormalsTLSData tls_data = {NULL}; - ParallelRangeSettings parallel_range_settings; + TaskParallelSettings parallel_range_settings; BLI_parallel_range_settings_defaults(¶llel_range_settings); parallel_range_settings.userdata_chunk = &tls_data; parallel_range_settings.userdata_chunk_size = sizeof(tls_data); @@ -973,7 +973,7 @@ static void subdiv_ccg_average_inner_face_grids(SubdivCCG *subdiv_ccg, prev_grid = grid; } /* Average all grids centers into a single accumulator, and share it. - * Guarantees corrent and smooth averaging in the center. */ + * Guarantees correct and smooth averaging in the center. */ GridElementAccumulator center_accumulator; element_accumulator_init(¢er_accumulator); for (int corner = 0; corner < num_face_grids; corner++) { @@ -991,7 +991,7 @@ static void subdiv_ccg_average_inner_face_grids(SubdivCCG *subdiv_ccg, static void subdiv_ccg_average_inner_grids_task(void *__restrict userdata_v, const int face_index, - const ParallelRangeTLS *__restrict UNUSED(tls_v)) + const TaskParallelTLS *__restrict UNUSED(tls_v)) { AverageInnerGridsData *data = userdata_v; SubdivCCG *subdiv_ccg = data->subdiv_ccg; @@ -1050,7 +1050,7 @@ static void subdiv_ccg_average_grids_boundary(SubdivCCG *subdiv_ccg, static void subdiv_ccg_average_grids_boundaries_task(void *__restrict userdata_v, const int adjacent_edge_index, - const ParallelRangeTLS *__restrict tls_v) + const TaskParallelTLS *__restrict tls_v) { AverageGridsBoundariesData *data = userdata_v; AverageGridsBoundariesTLSData *tls = tls_v->userdata_chunk; @@ -1097,7 +1097,7 @@ static void subdiv_ccg_average_grids_corners(SubdivCCG *subdiv_ccg, static void subdiv_ccg_average_grids_corners_task(void *__restrict userdata_v, const int adjacent_vertex_index, - const ParallelRangeTLS *__restrict UNUSED(tls_v)) + const TaskParallelTLS *__restrict UNUSED(tls_v)) { AverageGridsCornerData *data = userdata_v; SubdivCCG *subdiv_ccg = data->subdiv_ccg; @@ -1108,7 +1108,7 @@ static void subdiv_ccg_average_grids_corners_task(void *__restrict userdata_v, static void subdiv_ccg_average_all_boundaries(SubdivCCG *subdiv_ccg, CCGKey *key) { - ParallelRangeSettings parallel_range_settings; + TaskParallelSettings parallel_range_settings; BLI_parallel_range_settings_defaults(¶llel_range_settings); AverageGridsBoundariesData boundaries_data = { .subdiv_ccg = subdiv_ccg, @@ -1127,7 +1127,7 @@ static void subdiv_ccg_average_all_boundaries(SubdivCCG *subdiv_ccg, CCGKey *key static void subdiv_ccg_average_all_corners(SubdivCCG *subdiv_ccg, CCGKey *key) { - ParallelRangeSettings parallel_range_settings; + TaskParallelSettings parallel_range_settings; BLI_parallel_range_settings_defaults(¶llel_range_settings); AverageGridsCornerData corner_data = { .subdiv_ccg = subdiv_ccg, @@ -1150,7 +1150,7 @@ void BKE_subdiv_ccg_average_grids(SubdivCCG *subdiv_ccg) { CCGKey key; BKE_subdiv_ccg_key_top_level(&key, subdiv_ccg); - ParallelRangeSettings parallel_range_settings; + TaskParallelSettings parallel_range_settings; BLI_parallel_range_settings_defaults(¶llel_range_settings); /* Average inner boundaries of grids (within one face), across faces * from different face-corners. */ @@ -1175,7 +1175,7 @@ typedef struct StitchFacesInnerGridsData { static void subdiv_ccg_stitch_face_inner_grids_task( void *__restrict userdata_v, const int face_index, - const ParallelRangeTLS *__restrict UNUSED(tls_v)) + const TaskParallelTLS *__restrict UNUSED(tls_v)) { StitchFacesInnerGridsData *data = userdata_v; SubdivCCG *subdiv_ccg = data->subdiv_ccg; @@ -1197,7 +1197,7 @@ void BKE_subdiv_ccg_average_stitch_faces(SubdivCCG *subdiv_ccg, .key = &key, .effected_ccg_faces = effected_faces, }; - ParallelRangeSettings parallel_range_settings; + TaskParallelSettings parallel_range_settings; BLI_parallel_range_settings_defaults(¶llel_range_settings); BLI_task_parallel_range(0, num_effected_faces, diff --git a/source/blender/blenkernel/intern/subdiv_foreach.c b/source/blender/blenkernel/intern/subdiv_foreach.c index 98afbef6c0a..f9039767f53 100644 --- a/source/blender/blenkernel/intern/subdiv_foreach.c +++ b/source/blender/blenkernel/intern/subdiv_foreach.c @@ -172,7 +172,7 @@ static void subdiv_foreach_ctx_count(SubdivForeachTaskContext *ctx) const MPoly *coarse_mpoly = coarse_mesh->mpoly; ctx->num_subdiv_vertices = coarse_mesh->totvert; ctx->num_subdiv_edges = coarse_mesh->totedge * (num_subdiv_vertices_per_coarse_edge + 1); - /* Calculate extra vertices and edges createdd by non-loose geometry. */ + /* Calculate extra vertices and edges created by non-loose geometry. */ for (int poly_index = 0; poly_index < coarse_mesh->totpoly; poly_index++) { const MPoly *coarse_poly = &coarse_mpoly[poly_index]; const int num_ptex_faces_per_poly = num_ptex_faces_per_poly_get(coarse_poly); @@ -206,7 +206,7 @@ static void subdiv_foreach_ctx_count(SubdivForeachTaskContext *ctx) num_polys_per_ptex_get(no_quad_patch_resolution); } } - /* Calculate extra vertices createdd by loose edges. */ + /* Calculate extra vertices created by loose edges. */ for (int edge_index = 0; edge_index < coarse_mesh->totedge; edge_index++) { if (!BLI_BITMAP_TEST_BOOL(ctx->coarse_edges_used_map, edge_index)) { ctx->num_subdiv_vertices += num_subdiv_vertices_per_coarse_edge; @@ -1681,7 +1681,7 @@ static void subdiv_foreach_polys(SubdivForeachTaskContext *ctx, void *tls, int p static void subdiv_foreach_loose_vertices_task(void *__restrict userdata, const int coarse_vertex_index, - const ParallelRangeTLS *__restrict tls) + const TaskParallelTLS *__restrict tls) { SubdivForeachTaskContext *ctx = userdata; if (BLI_BITMAP_TEST_BOOL(ctx->coarse_vertices_used_map, coarse_vertex_index)) { @@ -1695,7 +1695,7 @@ static void subdiv_foreach_loose_vertices_task(void *__restrict userdata, static void subdiv_foreach_vertices_of_loose_edges_task(void *__restrict userdata, const int coarse_edge_index, - const ParallelRangeTLS *__restrict tls) + const TaskParallelTLS *__restrict tls) { SubdivForeachTaskContext *ctx = userdata; if (BLI_BITMAP_TEST_BOOL(ctx->coarse_edges_used_map, coarse_edge_index)) { @@ -1767,7 +1767,7 @@ static void subdiv_foreach_single_thread_tasks(SubdivForeachTaskContext *ctx) static void subdiv_foreach_task(void *__restrict userdata, const int poly_index, - const ParallelRangeTLS *__restrict tls) + const TaskParallelTLS *__restrict tls) { SubdivForeachTaskContext *ctx = userdata; /* Traverse hi-poly vertex coordinates and normals. */ @@ -1786,7 +1786,7 @@ static void subdiv_foreach_task(void *__restrict userdata, static void subdiv_foreach_boundary_edges_task(void *__restrict userdata, const int edge_index, - const ParallelRangeTLS *__restrict tls) + const TaskParallelTLS *__restrict tls) { SubdivForeachTaskContext *ctx = userdata; subdiv_foreach_boundary_edges(ctx, tls->userdata_chunk, edge_index); @@ -1821,7 +1821,7 @@ bool BKE_subdiv_foreach_subdiv_geometry(Subdiv *subdiv, /* Run all the code which is not supposed to be run from threads. */ subdiv_foreach_single_thread_tasks(&ctx); /* Threaded traversal of the rest of topology. */ - ParallelRangeSettings parallel_range_settings; + TaskParallelSettings parallel_range_settings; BLI_parallel_range_settings_defaults(¶llel_range_settings); parallel_range_settings.userdata_chunk = context->user_data_tls; parallel_range_settings.userdata_chunk_size = context->user_data_tls_size; diff --git a/source/blender/blenkernel/intern/subdiv_mesh.c b/source/blender/blenkernel/intern/subdiv_mesh.c index 75e05f8ffab..1ff9140681f 100644 --- a/source/blender/blenkernel/intern/subdiv_mesh.c +++ b/source/blender/blenkernel/intern/subdiv_mesh.c @@ -1086,20 +1086,27 @@ static void subdiv_mesh_vertex_of_loose_edge(const struct SubdivForeachContext * const MEdge *coarse_edge = &coarse_mesh->medge[coarse_edge_index]; Mesh *subdiv_mesh = ctx->subdiv_mesh; MVert *subdiv_mvert = subdiv_mesh->mvert; + const bool is_simple = ctx->subdiv->settings.is_simple; /* Find neighbors of the current loose edge. */ const MEdge *neighbors[2]; find_edge_neighbors(ctx, coarse_edge, neighbors); - /* Get points for b-spline interpolation. */ - float points[4][3]; - points_for_loose_edges_interpolation_get(ctx, coarse_edge, neighbors, points); - /* Perform interpolation. */ - float weights[4]; - key_curve_position_weights(u, weights, KEY_BSPLINE); /* Interpolate custom data. */ subdiv_mesh_vertex_of_loose_edge_interpolate(ctx, coarse_edge, u, subdiv_vertex_index); - /* Initialize */ + /* Interpolate coordinate. */ MVert *subdiv_vertex = &subdiv_mvert[subdiv_vertex_index]; - interp_v3_v3v3v3v3(subdiv_vertex->co, points[0], points[1], points[2], points[3], weights); + if (is_simple) { + const MVert *coarse_mvert = coarse_mesh->mvert; + const MVert *vert_1 = &coarse_mvert[coarse_edge->v1]; + const MVert *vert_2 = &coarse_mvert[coarse_edge->v2]; + interp_v3_v3v3(subdiv_vertex->co, vert_1->co, vert_2->co, u); + } + else { + float points[4][3]; + points_for_loose_edges_interpolation_get(ctx, coarse_edge, neighbors, points); + float weights[4]; + key_curve_position_weights(u, weights, KEY_BSPLINE); + interp_v3_v3v3v3v3(subdiv_vertex->co, points[0], points[1], points[2], points[3], weights); + } /* Reset flags and such. */ subdiv_vertex->flag = 0; /* TODO(sergey): This matches old behavior, but we can as well interpolate diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index 4171c1aac4f..09a073e3ca6 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -1459,7 +1459,7 @@ typedef struct CopyFinalLoopArrayData { static void copyFinalLoopArray_task_cb(void *__restrict userdata, const int iter, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { CopyFinalLoopArrayData *data = userdata; CCGDerivedMesh *ccgdm = data->ccgdm; @@ -1536,7 +1536,7 @@ static void ccgDM_copyFinalLoopArray(DerivedMesh *dm, MLoop *mloop) */ data.mloop_index = data.grid_size >= 5 ? 1 : 8; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.min_iter_per_thread = 1; diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index 056229ceb1c..29aa3ca1659 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -2045,11 +2045,12 @@ static void txt_select_prefix(Text *text, const char *add) * * \note caller must handle undo. */ -static void txt_select_unprefix(Text *text, const char *remove) +static bool txt_select_unprefix(Text *text, const char *remove) { int num = 0; const int indentlen = strlen(remove); bool unindented_first = false; + bool changed_any = false; BLI_assert(!ELEM(NULL, text->curl, text->sell)); @@ -2062,6 +2063,7 @@ static void txt_select_unprefix(Text *text, const char *remove) text->curl->len -= indentlen; memmove(text->curl->line, text->curl->line + indentlen, text->curl->len + 1); changed = true; + changed_any = true; } txt_make_dirty(text); @@ -2089,6 +2091,7 @@ static void txt_select_unprefix(Text *text, const char *remove) } /* caller must handle undo */ + return changed_any; } void txt_comment(Text *text) @@ -2102,15 +2105,15 @@ void txt_comment(Text *text) txt_select_prefix(text, prefix); } -void txt_uncomment(Text *text) +bool txt_uncomment(Text *text) { const char *prefix = "#"; if (ELEM(NULL, text->curl, text->sell)) { - return; + return false; } - txt_select_unprefix(text, prefix); + return txt_select_unprefix(text, prefix); } void txt_indent(Text *text) @@ -2124,15 +2127,15 @@ void txt_indent(Text *text) txt_select_prefix(text, prefix); } -void txt_unindent(Text *text) +bool txt_unindent(Text *text) { const char *prefix = (text->flags & TXT_TABSTOSPACES) ? tab_to_spaces : "\t"; if (ELEM(NULL, text->curl, text->sell)) { - return; + return false; } - txt_select_unprefix(text, prefix); + return txt_select_unprefix(text, prefix); } void txt_move_lines(struct Text *text, const int direction) diff --git a/source/blender/blenkernel/intern/tracking_auto.c b/source/blender/blenkernel/intern/tracking_auto.c index 8a474725b0c..47c12b329dc 100644 --- a/source/blender/blenkernel/intern/tracking_auto.c +++ b/source/blender/blenkernel/intern/tracking_auto.c @@ -42,7 +42,7 @@ #include "tracking_private.h" typedef struct AutoTrackOptions { - int clip_index; /** Index of the clip this track belogs to. */ + int clip_index; /** Index of the clip this track belongs to. */ int track_index; /* Index of the track in AutoTrack tracks structure. */ MovieTrackingTrack *track; /* Pointer to an original track/ */ libmv_TrackRegionOptions track_region_options; /* Options for the region tracker. */ @@ -50,7 +50,7 @@ typedef struct AutoTrackOptions { /* TODO(sergey): A bit awkward to keep it in here, only used to * place a disabled marker once the tracking fails, - * Wither find a more clear way to do it or call it track context + * Either find a clearer way to do it or call it track context * or state, not options. */ bool is_failed; @@ -377,7 +377,7 @@ AutoTrackContext *BKE_autotrack_context_new(MovieClip *clip, static void autotrack_context_step_cb(void *__restrict userdata, const int track, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { AutoTrackContext *context = userdata; const int frame_delta = context->backwards ? -1 : 1; @@ -446,7 +446,7 @@ bool BKE_autotrack_context_step(AutoTrackContext *context) const int frame_delta = context->backwards ? -1 : 1; context->step_ok = false; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (context->num_tracks > 1); BLI_task_parallel_range(0, context->num_tracks, context, autotrack_context_step_cb, &settings); diff --git a/source/blender/blenkernel/intern/tracking_solver.c b/source/blender/blenkernel/intern/tracking_solver.c index cfa41cb7d92..7e7a839b645 100644 --- a/source/blender/blenkernel/intern/tracking_solver.c +++ b/source/blender/blenkernel/intern/tracking_solver.c @@ -65,6 +65,9 @@ typedef struct MovieReconstructContext { TracksMap *tracks_map; int sfra, efra; + + /* Details about reconstruction error, reported by Libmv. */ + char error_message[1024]; } MovieReconstructContext; typedef struct ReconstructProgressData { @@ -426,9 +429,26 @@ MovieReconstructContext *BKE_tracking_reconstruction_context_new(MovieClip *clip context->keyframe2 = keyframe2; context->refine_flags = reconstruct_refine_intrinsics_get_flags(tracking, object); + context->error_message[0] = '\0'; + return context; } +void BKE_tracking_reconstruction_report_error_message(MovieReconstructContext *context, + const char *error_message) +{ + if (context->error_message[0]) { + /* Only keep initial error message, the rest are inducted ones. */ + return; + } + BLI_strncpy(context->error_message, error_message, sizeof(context->error_message)); +} + +const char *BKE_tracking_reconstruction_error_message_get(const MovieReconstructContext *context) +{ + return context->error_message; +} + /* Free memory used by a reconstruction process. */ void BKE_tracking_reconstruction_context_free(MovieReconstructContext *context) { @@ -534,7 +554,8 @@ bool BKE_tracking_reconstruction_finish(MovieReconstructContext *context, MovieT MovieTrackingObject *object; if (!libmv_reconstructionIsValid(context->reconstruction)) { - printf("Failed solve the motion: most likely there are no good keyframes\n"); + BKE_tracking_reconstruction_report_error_message( + context, "Failed to solve the motion: most likely there are no good keyframes"); return false; } diff --git a/source/blender/blenkernel/intern/tracking_stabilize.c b/source/blender/blenkernel/intern/tracking_stabilize.c index b852e8a12cd..03229c654fb 100644 --- a/source/blender/blenkernel/intern/tracking_stabilize.c +++ b/source/blender/blenkernel/intern/tracking_stabilize.c @@ -611,16 +611,19 @@ static bool average_track_contributions(StabContext *ctx, float rotation, scale, quality; quality = rotation_contribution( stabilization_base, marker, aspect, r_pivot, &rotation, &scale); - weight *= quality; - weight_sum += weight; - *r_angle += rotation * weight; + const float quality_weight = weight * quality; + weight_sum += quality_weight; + *r_angle += rotation * quality_weight; if (stab->flag & TRACKING_STABILIZE_SCALE) { - *r_scale_step += logf(scale) * weight; + *r_scale_step += logf(scale) * quality_weight; } else { *r_scale_step = 0; } - ok |= (weight_sum > EPSILON_WEIGHT); + /* NOTE: Use original marker weight and not the scaled one with the proximity here to allow + * simple stabilization setups when there is a single track in a close proximity of the + * center. */ + ok |= (weight > EPSILON_WEIGHT); } } } @@ -1338,7 +1341,7 @@ typedef struct TrackingStabilizeFrameInterpolationData { } TrackingStabilizeFrameInterpolationData; static void tracking_stabilize_frame_interpolation_cb( - void *__restrict userdata, const int j, const ParallelRangeTLS *__restrict UNUSED(tls)) + void *__restrict userdata, const int j, const TaskParallelTLS *__restrict UNUSED(tls)) { TrackingStabilizeFrameInterpolationData *data = userdata; ImBuf *ibuf = data->ibuf; @@ -1443,7 +1446,7 @@ ImBuf *BKE_tracking_stabilize_frame( .interpolation = interpolation, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (tmpibuf->y > 128); BLI_task_parallel_range( diff --git a/source/blender/blenkernel/intern/undo_system.c b/source/blender/blenkernel/intern/undo_system.c index 8ea5b47de5f..07cf5205cab 100644 --- a/source/blender/blenkernel/intern/undo_system.c +++ b/source/blender/blenkernel/intern/undo_system.c @@ -560,12 +560,15 @@ bool BKE_undosys_step_push_with_type(UndoStack *ustack, } if (use_memfile_step) { - const char *name_internal = "MemFile Internal (post)"; + /* Make this the user visible undo state, so redo always applies + * on top of the mem-file undo instead of skipping it. see: T67256. */ + UndoStep *us_prev = ustack->step_active; + const char *name_internal = us_prev->name; const bool ok = undosys_stack_push_main(ustack, name_internal, G_MAIN); if (ok) { UndoStep *us = ustack->steps.last; BLI_assert(STREQ(us->name, name_internal)); - us->skip = true; + us_prev->skip = true; #ifdef WITH_GLOBAL_UNDO_CORRECT_ORDER ustack->step_active_memfile = us; #endif @@ -845,10 +848,6 @@ void BKE_undosys_type_free_all(void) * Unfortunately we need this for a handful of places. */ -/* Disable for now since it accesses freed memory. - * The pointer can only be a key, we can't read it's contents. */ -#define USE_LIB_SKIP - static void UNUSED_FUNCTION(BKE_undosys_foreach_ID_ref(UndoStack *ustack, UndoTypeForEachIDRefFn foreach_ID_ref_fn, void *user_data)) @@ -861,176 +860,6 @@ static void UNUSED_FUNCTION(BKE_undosys_foreach_ID_ref(UndoStack *ustack, } } -typedef struct UndoIDPtrMapItem { - /** Never changes (matches undo data). Use as sort key for binary search. */ - const void *ptr; - /** Write the new pointers here. */ - uint index; -} UndoIDPtrMapItem; - -typedef struct UndoIDPtrMap { - UndoRefID *refs; - /** - * Pointer map, update 'dst' members before use. - * This is always sorted (adds some overhead when adding, in practice it's acceptable since). - */ - UndoIDPtrMapItem *pmap; - - /** Length for both 'refs' & 'pmap' */ - uint len; - uint len_alloc; -} UndoIDPtrMap; - -#ifdef DEBUG -# define PMAP_DEFAULT_ALLOC 1 -#else -# define PMAP_DEFAULT_ALLOC 32 -#endif - -void BKE_undosys_ID_map_foreach_ID_ref(UndoIDPtrMap *map, - UndoTypeForEachIDRefFn foreach_ID_ref_fn, - void *user_data) -{ - for (uint i = 0; i < map->len; i++) { - foreach_ID_ref_fn(user_data, &map->refs[i]); - } -} - -/** - * Return true when found, otherwise index is set to the index we should insert. - */ -static bool undosys_ID_map_lookup_index(const UndoIDPtrMap *map, const void *key, uint *r_index) -{ - const UndoIDPtrMapItem *pmap = map->pmap; - const uint len = map->len; - if (len == 0) { - if (r_index) { - *r_index = 0; - } - return false; - } - int min = 0, max = len - 1; - while (min <= max) { - const uint mid = (min + max) / 2; - if (pmap[mid].ptr < key) { - min = mid + 1; - } - else if (pmap[mid].ptr == key) { - if (r_index) { - *r_index = mid; - } - return true; - } - else if (pmap[mid].ptr > key) { - max = mid - 1; - } - } - if (r_index) { - *r_index = min; - } - return false; -} - -/** - * A set of ID's use for efficient decoding, so we can map pointers back to the newly loaded data - * without performing full look ups each time. - * - * This can be used as an old_pointer -> new_pointer lookup. - */ -UndoIDPtrMap *BKE_undosys_ID_map_create(void) -{ - UndoIDPtrMap *map = MEM_mallocN(sizeof(*map), __func__); - map->len_alloc = PMAP_DEFAULT_ALLOC; - map->refs = MEM_mallocN(sizeof(*map->refs) * map->len_alloc, __func__); - map->pmap = MEM_mallocN(sizeof(*map->pmap) * map->len_alloc, __func__); - map->len = 0; - return map; -} -void BKE_undosys_ID_map_destroy(UndoIDPtrMap *idpmap) -{ - MEM_SAFE_FREE(idpmap->refs); - MEM_SAFE_FREE(idpmap->pmap); - MEM_freeN(idpmap); -} - -void BKE_undosys_ID_map_add(UndoIDPtrMap *map, ID *id) -{ - uint index; -#ifdef USE_LIB_SKIP - if (id->lib != NULL) { - return; - } -#endif - - if (undosys_ID_map_lookup_index(map, id, &index)) { - return; /* exists. */ - } - - const uint len_src = map->len; - const uint len_dst = map->len + 1; - if (len_dst > map->len_alloc) { - map->len_alloc *= 2; - BLI_assert(map->len_alloc >= len_dst); - map->pmap = MEM_reallocN(map->pmap, sizeof(*map->pmap) * map->len_alloc); - map->refs = MEM_reallocN(map->refs, sizeof(*map->refs) * map->len_alloc); - } - -#if 0 /* Will be done automatically in callback. */ - BLI_strncpy(map->refs[len_src].name, id->name, sizeof(id->name)); -#else - map->refs[len_src].name[0] = '\0'; -#endif - map->refs[len_src].ptr = id; - - if (len_src != 0 && index != len_src) { - memmove(&map->pmap[index + 1], &map->pmap[index], sizeof(*map->pmap) * (len_src - index)); - } - map->pmap[index].ptr = id; - map->pmap[index].index = len_src; - - map->len = len_dst; -} - -ID *BKE_undosys_ID_map_lookup(const UndoIDPtrMap *map, const ID *id_src) -{ - /* We should only ever lookup indices which exist! */ - uint index; - if (!undosys_ID_map_lookup_index(map, id_src, &index)) { - BLI_assert(0); - } - index = map->pmap[index].index; - ID *id_dst = map->refs[index].ptr; - BLI_assert(id_dst != NULL); - BLI_assert(STREQ(id_dst->name, map->refs[index].name)); - return id_dst; -} - -void BKE_undosys_ID_map_add_with_prev(UndoIDPtrMap *map, ID *id, ID **id_prev) -{ - if (id == *id_prev) { - return; - } - *id_prev = id; - BKE_undosys_ID_map_add(map, id); -} - -ID *BKE_undosys_ID_map_lookup_with_prev(const UndoIDPtrMap *map, ID *id_src, ID *id_prev_match[2]) -{ - if (id_src == id_prev_match[0]) { - return id_prev_match[1]; - } - else { -#ifdef USE_LIB_SKIP - ID *id_dst = BKE_undosys_ID_map_lookup(map, id_src); -#else - ID *id_dst = (id_src->lib == NULL) ? BKE_undosys_ID_map_lookup(map, id_src) : id_src; -#endif - id_prev_match[0] = id_src; - id_prev_match[1] = id_dst; - return id_dst; - } -} - /** \} */ /* -------------------------------------------------------------------- */ diff --git a/source/blender/blenkernel/intern/unit.c b/source/blender/blenkernel/intern/unit.c index 7e7d5c82654..375721057c3 100644 --- a/source/blender/blenkernel/intern/unit.c +++ b/source/blender/blenkernel/intern/unit.c @@ -112,6 +112,8 @@ enum { B_UNIT_DEF_TENTH = 2, /** Short unit name is case sensitive, for example to distinguish mW and MW */ B_UNIT_DEF_CASE_SENSITIVE = 4, + /** Short unit name does not have space between it and preceding number */ + B_UNIT_DEF_NO_SPACE = 8, }; /* define a single unit */ @@ -161,8 +163,8 @@ static struct bUnitDef buImperialLenDef[] = { {"furlong", "furlongs", "fur", NULL, "Furlongs", "FURLONGS", UN_SC_FUR, 0.0, B_UNIT_DEF_SUPPRESS}, {"chain", "chains", "ch", NULL, "Chains", "CHAINS", UN_SC_CH, 0.0, B_UNIT_DEF_SUPPRESS}, {"yard", "yards", "yd", NULL, "Yards", "YARDS", UN_SC_YD, 0.0, B_UNIT_DEF_SUPPRESS}, - {"foot", "feet", "'", "ft", "Feet", "FEET", UN_SC_FT, 0.0, B_UNIT_DEF_NONE}, /* base unit */ - {"inch", "inches", "\"", "in", "Inches", "INCHES", UN_SC_IN, 0.0, B_UNIT_DEF_NONE}, + {"foot", "feet", "'", "ft", "Feet", "FEET", UN_SC_FT, 0.0, B_UNIT_DEF_NONE | B_UNIT_DEF_NO_SPACE}, /* base unit */ + {"inch", "inches", "\"", "in", "Inches", "INCHES", UN_SC_IN, 0.0, B_UNIT_DEF_NONE | B_UNIT_DEF_NO_SPACE}, {"thou", "thou", "thou", "mil", "Thou", "THOU", UN_SC_MIL, 0.0, B_UNIT_DEF_NONE}, /* plural for thou has no 's' */ NULL_UNIT, }; @@ -289,10 +291,10 @@ static struct bUnitCollection buNaturalTimeCollection = {buNaturalTimeDef, 3, 0, static struct bUnitDef buNaturalRotDef[] = { - {"degree", "degrees", "°", "d", "Degrees", "DEGREES", M_PI / 180.0, 0.0, B_UNIT_DEF_NONE}, + {"degree", "degrees", "°", "d", "Degrees", "DEGREES", M_PI / 180.0, 0.0, B_UNIT_DEF_NONE | B_UNIT_DEF_NO_SPACE}, /* arcminutes/arcseconds are used in Astronomy/Navigation areas... */ - {"arcminute", "arcminutes", "'", NULL, "Arcminutes", "ARCMINUTES", (M_PI / 180.0) / 60.0, 0.0, B_UNIT_DEF_SUPPRESS}, - {"arcsecond", "arcseconds", "\"", NULL, "Arcseconds", "ARCSECONDS", (M_PI / 180.0) / 3600.0, 0.0, B_UNIT_DEF_SUPPRESS}, + {"arcminute", "arcminutes", "'", NULL, "Arcminutes", "ARCMINUTES", (M_PI / 180.0) / 60.0, 0.0, B_UNIT_DEF_SUPPRESS | B_UNIT_DEF_NO_SPACE}, + {"arcsecond", "arcseconds", "\"", NULL, "Arcseconds", "ARCSECONDS", (M_PI / 180.0) / 3600.0, 0.0, B_UNIT_DEF_SUPPRESS | B_UNIT_DEF_NO_SPACE}, {"radian", "radians", "r", NULL, "Radians", "RADIANS", 1.0, 0.0, B_UNIT_DEF_NONE}, // {"turn", "turns", "t", NULL, "Turns", NULL, 1.0 / (M_PI * 2.0), 0.0, B_UNIT_DEF_NONE}, NULL_UNIT, @@ -451,6 +453,11 @@ static size_t unit_as_string(char *str, } } + /* Now add a space for all units except foot, inch, degree, arcminute, arcsecond */ + if (!(unit->flag & B_UNIT_DEF_NO_SPACE)) { + str[++i] = ' '; + } + /* Now add the suffix */ if (i < len_max) { int j = 0; diff --git a/source/blender/blenkernel/intern/writeffmpeg.c b/source/blender/blenkernel/intern/writeffmpeg.c index f3336adda30..5152643aaa1 100644 --- a/source/blender/blenkernel/intern/writeffmpeg.c +++ b/source/blender/blenkernel/intern/writeffmpeg.c @@ -54,6 +54,7 @@ * like M_SQRT1_2 leading to warnings with MSVC */ # include <libavformat/avformat.h> # include <libavcodec/avcodec.h> +# include <libavutil/imgutils.h> # include <libavutil/rational.h> # include <libavutil/samplefmt.h> # include <libswscale/swscale.h> @@ -80,7 +81,10 @@ typedef struct FFMpegContext { AVFormatContext *outfile; AVStream *video_stream; AVStream *audio_stream; - AVFrame *current_frame; + AVFrame *current_frame; /* Image frame in output pixel format. */ + + /* Image frame in Blender's own pixel format, may need conversion to the output pixel format. */ + AVFrame *img_convert_frame; struct SwsContext *img_convert_ctx; uint8_t *audio_input_buffer; @@ -264,6 +268,10 @@ static AVFrame *alloc_picture(int pix_fmt, int width, int height) return NULL; } avpicture_fill((AVPicture *)f, buf, pix_fmt, width, height); + f->format = pix_fmt; + f->width = width; + f->height = height; + return f; } @@ -319,6 +327,10 @@ static const char **get_file_extensions(int format) static const char *rv[] = {".ogv", ".ogg", NULL}; return rv; } + case FFMPEG_WEBM: { + static const char *rv[] = {".webm", NULL}; + return rv; + } default: return NULL; } @@ -371,67 +383,52 @@ static int write_video_frame( } /* read and encode a frame of audio from the buffer */ -static AVFrame *generate_video_frame(FFMpegContext *context, uint8_t *pixels, ReportList *reports) +static AVFrame *generate_video_frame(FFMpegContext *context, + const uint8_t *pixels, + ReportList *reports) { - uint8_t *rendered_frame; - AVCodecContext *c = context->video_stream->codec; - int width = c->width; int height = c->height; AVFrame *rgb_frame; - if (c->pix_fmt != AV_PIX_FMT_BGR32) { - rgb_frame = alloc_picture(AV_PIX_FMT_BGR32, width, height); - if (!rgb_frame) { - BKE_report(reports, RPT_ERROR, "Could not allocate temporary frame"); - return NULL; - } + if (context->img_convert_frame != NULL) { + /* Pixel format conversion is needed. */ + rgb_frame = context->img_convert_frame; } else { + /* The output pixel format is Blender's internal pixel format. */ rgb_frame = context->current_frame; } - rendered_frame = pixels; + /* Copy the Blender pixels into the FFmpeg datastructure, taking care of endianness and flipping + * the image vertically. */ + int linesize = rgb_frame->linesize[0]; + for (int y = 0; y < height; y++) { + uint8_t *target = rgb_frame->data[0] + linesize * (height - y - 1); + const uint8_t *src = pixels + linesize * y; - /* Do RGBA-conversion and flipping in one step depending - * on CPU-Endianess */ +# if ENDIAN_ORDER == L_ENDIAN + memcpy(target, src, linesize); - if (ENDIAN_ORDER == L_ENDIAN) { - int y; - for (y = 0; y < height; y++) { - uint8_t *target = rgb_frame->data[0] + width * 4 * (height - y - 1); - uint8_t *src = rendered_frame + width * 4 * y; - uint8_t *end = src + width * 4; - while (src != end) { - target[3] = src[3]; - target[2] = src[2]; - target[1] = src[1]; - target[0] = src[0]; +# elif ENDIAN_ORDER == B_ENDIAN + const uint8_t *end = src + linesize; + while (src != end) { + target[3] = src[0]; + target[2] = src[1]; + target[1] = src[2]; + target[0] = src[3]; - target += 4; - src += 4; - } - } - } - else { - int y; - for (y = 0; y < height; y++) { - uint8_t *target = rgb_frame->data[0] + width * 4 * (height - y - 1); - uint8_t *src = rendered_frame + width * 4 * y; - uint8_t *end = src + width * 4; - while (src != end) { - target[3] = src[0]; - target[2] = src[1]; - target[1] = src[2]; - target[0] = src[3]; - - target += 4; - src += 4; - } + target += 4; + src += 4; } +# else +# error ENDIAN_ORDER should either be L_ENDIAN or B_ENDIAN. +# endif } - if (c->pix_fmt != AV_PIX_FMT_BGR32) { + /* Convert to the output pixel format, if it's different that Blender's internal one. */ + if (context->img_convert_frame != NULL) { + BLI_assert(context->img_convert_ctx != NULL); sws_scale(context->img_convert_ctx, (const uint8_t *const *)rgb_frame->data, rgb_frame->linesize, @@ -439,13 +436,8 @@ static AVFrame *generate_video_frame(FFMpegContext *context, uint8_t *pixels, Re c->height, context->current_frame->data, context->current_frame->linesize); - delete_picture(rgb_frame); } - context->current_frame->format = AV_PIX_FMT_BGR32; - context->current_frame->width = width; - context->current_frame->height = height; - return context->current_frame; } @@ -696,9 +688,15 @@ static AVStream *alloc_video_stream(FFMpegContext *context, } if (codec_id == AV_CODEC_ID_QTRLE) { - /* Always write to ARGB. The default pixel format of QTRLE is RGB24, which uses 3 bytes per - * pixels, which breaks the export. */ - c->pix_fmt = AV_PIX_FMT_ARGB; + if (rd->im_format.planes == R_IMF_PLANES_RGBA) { + c->pix_fmt = AV_PIX_FMT_ARGB; + } + } + + if (codec_id == AV_CODEC_ID_VP9) { + if (rd->im_format.planes == R_IMF_PLANES_RGBA) { + c->pix_fmt = AV_PIX_FMT_YUVA420P; + } } if (codec_id == AV_CODEC_ID_PNG) { @@ -727,18 +725,29 @@ static AVStream *alloc_video_stream(FFMpegContext *context, } av_dict_free(&opts); + /* FFmpeg expects its data in the output pixel format. */ context->current_frame = alloc_picture(c->pix_fmt, c->width, c->height); - context->img_convert_ctx = sws_getContext(c->width, - c->height, - AV_PIX_FMT_BGR32, - c->width, - c->height, - c->pix_fmt, - SWS_BICUBIC, - NULL, - NULL, - NULL); + if (c->pix_fmt == AV_PIX_FMT_RGBA) { + /* Output pixel format is the same we use internally, no conversion necessary. */ + context->img_convert_frame = NULL; + context->img_convert_ctx = NULL; + } + else { + /* Output pixel format is different, allocate frame for conversion. */ + context->img_convert_frame = alloc_picture(AV_PIX_FMT_RGBA, c->width, c->height); + context->img_convert_ctx = sws_getContext(c->width, + c->height, + AV_PIX_FMT_RGBA, + c->width, + c->height, + c->pix_fmt, + SWS_BICUBIC, + NULL, + NULL, + NULL); + } + return st; } @@ -1427,6 +1436,11 @@ static void end_ffmpeg_impl(FFMpegContext *context, int is_autosplit) delete_picture(context->current_frame); context->current_frame = NULL; } + if (context->img_convert_frame != NULL) { + delete_picture(context->img_convert_frame); + context->img_convert_frame = NULL; + } + if (context->outfile != NULL && context->outfile->oformat) { if (!(context->outfile->oformat->flags & AVFMT_NOFILE)) { avio_close(context->outfile->pb); @@ -1836,25 +1850,14 @@ bool BKE_ffmpeg_alpha_channel_is_supported(RenderData *rd) { int codec = rd->ffcodecdata.codec; - if (codec == AV_CODEC_ID_QTRLE) { - return true; - } - - if (codec == AV_CODEC_ID_PNG) { - return true; - } - - if (codec == AV_CODEC_ID_HUFFYUV) { - return true; - } - # ifdef FFMPEG_FFV1_ALPHA_SUPPORTED + /* Visual Studio 2019 doesn't like #ifdef within ELEM(). */ if (codec == AV_CODEC_ID_FFV1) { return true; } # endif - return false; + return ELEM(codec, AV_CODEC_ID_QTRLE, AV_CODEC_ID_PNG, AV_CODEC_ID_VP9, AV_CODEC_ID_HUFFYUV); } void *BKE_ffmpeg_context_create(void) diff --git a/source/blender/blenkernel/nla_private.h b/source/blender/blenkernel/nla_private.h index dc086987e21..1705cd4effc 100644 --- a/source/blender/blenkernel/nla_private.h +++ b/source/blender/blenkernel/nla_private.h @@ -167,16 +167,16 @@ float nlastrip_get_frame(NlaStrip *strip, float cframe, short mode); * in which they get defined. */ NlaEvalStrip *nlastrips_ctime_get_strip( - struct Depsgraph *depsgraph, ListBase *list, ListBase *strips, short index, float ctime); -void nlastrip_evaluate(struct Depsgraph *depsgraph, - PointerRNA *ptr, + ListBase *list, ListBase *strips, short index, float ctime, const bool flush_to_original); +void nlastrip_evaluate(PointerRNA *ptr, NlaEvalData *channels, ListBase *modifiers, NlaEvalStrip *nes, - NlaEvalSnapshot *snapshot); -void nladata_flush_channels(struct Depsgraph *depsgraph, - PointerRNA *ptr, + NlaEvalSnapshot *snapshot, + const bool flush_to_original); +void nladata_flush_channels(PointerRNA *ptr, NlaEvalData *channels, - NlaEvalSnapshot *snapshot); + NlaEvalSnapshot *snapshot, + const bool flush_to_original); #endif /* __NLA_PRIVATE_H__ */ diff --git a/source/blender/blenlib/BLI_listbase.h b/source/blender/blenlib/BLI_listbase.h index aa3d7520506..c235a72e7e4 100644 --- a/source/blender/blenlib/BLI_listbase.h +++ b/source/blender/blenlib/BLI_listbase.h @@ -171,7 +171,7 @@ struct LinkData *BLI_genericNodeN(void *data); #define LISTBASE_FOREACH(type, var, list) \ for (type var = (type)((list)->first); var != NULL; var = (type)(((Link *)(var))->next)) -/** A verion of #LISTBASE_FOREACH that supports removing the item we're looping over. */ +/** A version of #LISTBASE_FOREACH that supports removing the item we're looping over. */ #define LISTBASE_FOREACH_MUTABLE(type, var, list) \ for (type var = (type)((list)->first), *var##_iter_next; \ ((var != NULL) ? ((void)(var##_iter_next = (type)(((Link *)(var))->next)), 1) : 0); \ diff --git a/source/blender/blenlib/BLI_math_base.h b/source/blender/blenlib/BLI_math_base.h index 177a1a84b16..5b941f570de 100644 --- a/source/blender/blenlib/BLI_math_base.h +++ b/source/blender/blenlib/BLI_math_base.h @@ -197,7 +197,7 @@ double double_round(double x, int ndigits); * check the vector is unit length, or zero length (which can't be helped in some cases). */ #ifndef NDEBUG -/** \note 0.0001 is too small becaues normals may be converted from short's: see T34322. */ +/** \note 0.0001 is too small because normals may be converted from short's: see T34322. */ # define BLI_ASSERT_UNIT_EPSILON 0.0002f /** * \note Checks are flipped so NAN doesn't assert. diff --git a/source/blender/blenlib/BLI_task.h b/source/blender/blenlib/BLI_task.h index d11ba15a7e0..568d6c9a84a 100644 --- a/source/blender/blenlib/BLI_task.h +++ b/source/blender/blenlib/BLI_task.h @@ -142,22 +142,23 @@ typedef enum eTaskSchedulingMode { } eTaskSchedulingMode; /* Per-thread specific data passed to the callback. */ -typedef struct ParallelRangeTLS { +typedef struct TaskParallelTLS { /* Identifier of the thread who this data belongs to. */ int thread_id; /* Copy of user-specifier chunk, which is copied from original chunk to all * worker threads. This is similar to OpenMP's firstprivate. */ void *userdata_chunk; -} ParallelRangeTLS; +} TaskParallelTLS; + +typedef void (*TaskParallelFinalizeFunc)(void *__restrict userdata, + void *__restrict userdata_chunk); typedef void (*TaskParallelRangeFunc)(void *__restrict userdata, const int iter, - const ParallelRangeTLS *__restrict tls); -typedef void (*TaskParallelRangeFuncFinalize)(void *__restrict userdata, - void *__restrict userdata_chunk); + const TaskParallelTLS *__restrict tls); -typedef struct ParallelRangeSettings { +typedef struct TaskParallelSettings { /* Whether caller allows to do threading of the particular range. * Usually set by some equation, which forces threading off when threading * overhead becomes higher than speed benefit. @@ -175,7 +176,7 @@ typedef struct ParallelRangeSettings { /* Function called from calling thread once whole range have been * processed. */ - TaskParallelRangeFuncFinalize func_finalize; + TaskParallelFinalizeFunc func_finalize; /* Minimum allowed number of range iterators to be handled by a single * thread. This allows to achieve following: * - Reduce amount of threading overhead. @@ -187,15 +188,15 @@ typedef struct ParallelRangeSettings { * having a global use_threading switch based on just range size. */ int min_iter_per_thread; -} ParallelRangeSettings; +} TaskParallelSettings; -BLI_INLINE void BLI_parallel_range_settings_defaults(ParallelRangeSettings *settings); +BLI_INLINE void BLI_parallel_range_settings_defaults(TaskParallelSettings *settings); void BLI_task_parallel_range(const int start, const int stop, void *userdata, TaskParallelRangeFunc func, - const ParallelRangeSettings *settings); + const TaskParallelSettings *settings); typedef void (*TaskParallelListbaseFunc)(void *userdata, struct Link *iter, int index); void BLI_task_parallel_listbase(struct ListBase *listbase, @@ -211,16 +212,13 @@ void BLI_task_parallel_mempool(struct BLI_mempool *mempool, const bool use_threading); /* TODO(sergey): Think of a better place for this. */ -BLI_INLINE void BLI_parallel_range_settings_defaults(ParallelRangeSettings *settings) +BLI_INLINE void BLI_parallel_range_settings_defaults(TaskParallelSettings *settings) { memset(settings, 0, sizeof(*settings)); settings->use_threading = true; settings->scheduling_mode = TASK_SCHEDULING_STATIC; - /* NOTE: Current value mimics old behavior, but it's not ideal by any - * means. Would be cool to find a common value which will work good enough - * for both static and dynamic scheduling. - */ - settings->min_iter_per_thread = 1; + /* Use default heuristic to define actual chunk size. */ + settings->min_iter_per_thread = 0; } #ifdef __cplusplus diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h index 216e409aee6..5d80da6de77 100644 --- a/source/blender/blenlib/BLI_utildefines.h +++ b/source/blender/blenlib/BLI_utildefines.h @@ -788,7 +788,7 @@ extern bool BLI_memory_is_zero(const void *arr, const size_t arr_size); /** Useful for debugging. */ #define AT __FILE__ ":" STRINGIFY(__LINE__) -/** No-op for expressions we don't want to instansiate, but must remian valid. */ +/** No-op for expressions we don't want to instantiate, but must remain valid. */ #define EXPR_NOP(expr) (void)(0 ? ((void)(expr), 1) : 0) /** \} */ diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c index f43f55a352b..0e93fd8e13b 100644 --- a/source/blender/blenlib/intern/BLI_kdopbvh.c +++ b/source/blender/blenlib/intern/BLI_kdopbvh.c @@ -561,7 +561,7 @@ static void bvhtree_verify(BVHTree *tree) /* Helper data and structures to build a min-leaf generalized implicit tree * This code can be easily reduced - * (basicly this is only method to calculate pow(k, n) in O(1).. and stuff like that) */ + * (basically this is only method to calculate pow(k, n) in O(1).. and stuff like that) */ typedef struct BVHBuildHelper { int tree_type; int totleafs; @@ -626,7 +626,7 @@ static int implicit_leafs_index(const BVHBuildHelper *data, const int depth, con * * An implicit tree is a tree where its structure is implied, * thus there is no need to store child pointers or indexes. - * Its possible to find the position of the child or the parent with simple maths + * It's possible to find the position of the child or the parent with simple maths * (multiplication and addition). * This type of tree is for example used on heaps.. * where node N has its child at indices N*2 and N*2+1. @@ -700,7 +700,7 @@ typedef struct BVHDivNodesData { static void non_recursive_bvh_div_nodes_task_cb(void *__restrict userdata, const int j, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { BVHDivNodesData *data = userdata; @@ -841,14 +841,14 @@ static void non_recursive_bvh_div_nodes(const BVHTree *tree, cb_data.depth = depth; if (true) { - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (num_leafs > KDOPBVH_THREAD_LEAF_THRESHOLD); BLI_task_parallel_range(i, i_stop, &cb_data, non_recursive_bvh_div_nodes_task_cb, &settings); } else { /* Less hassle for debugging. */ - ParallelRangeTLS tls = {0}; + TaskParallelTLS tls = {0}; for (int i_task = i; i_task < i_stop; i_task++) { non_recursive_bvh_div_nodes_task_cb(&cb_data, i_task, &tls); } @@ -1195,7 +1195,7 @@ int BLI_bvhtree_overlap_thread_num(const BVHTree *tree) static void bvhtree_overlap_task_cb(void *__restrict userdata, const int j, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { BVHOverlapData_Thread *data = &((BVHOverlapData_Thread *)userdata)[j]; BVHOverlapData_Shared *data_shared = data->shared; @@ -1262,7 +1262,7 @@ BVHTreeOverlap *BLI_bvhtree_overlap( data[j].thread = j; } - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (tree1->totleaf > KDOPBVH_THREAD_LEAF_THRESHOLD); BLI_task_parallel_range(0, thread_num, data, bvhtree_overlap_task_cb, &settings); diff --git a/source/blender/blenlib/intern/BLI_memblock.c b/source/blender/blenlib/intern/BLI_memblock.c index ec9b74f2b50..f26860afe77 100644 --- a/source/blender/blenlib/intern/BLI_memblock.c +++ b/source/blender/blenlib/intern/BLI_memblock.c @@ -55,9 +55,9 @@ struct BLI_memblock { int chunk_max_ofs; /** Id of the chunk used for the next allocation. */ int chunk_next; - /** Chunck size in bytes. */ + /** Chunk size in bytes. */ int chunk_size; - /** Number of allocated chunck. */ + /** Number of allocated chunk. */ int chunk_len; }; @@ -123,7 +123,7 @@ void BLI_memblock_clear(BLI_memblock *mblk, MemblockValFreeFP free_callback) void *BLI_memblock_alloc(BLI_memblock *mblk) { - /* Bookeeping. */ + /* Bookkeeping. */ if (mblk->elem_last < mblk->elem_next) { mblk->elem_last = mblk->elem_next; } diff --git a/source/blender/blenlib/intern/BLI_mempool.c b/source/blender/blenlib/intern/BLI_mempool.c index 5765540a8f1..2b931507633 100644 --- a/source/blender/blenlib/intern/BLI_mempool.c +++ b/source/blender/blenlib/intern/BLI_mempool.c @@ -65,7 +65,7 @@ * Important that this value is an is _not_ aligned with ``sizeof(void *)``. * So having a pointer to 2/4/8... aligned memory is enough to ensure * the freeword will never be used. - * To be safe, use a word thats the same in both directions. + * To be safe, use a word that's the same in both directions. */ #define FREEWORD \ ((sizeof(void *) > sizeof(int32_t)) ? MAKE_ID_8('e', 'e', 'r', 'f', 'f', 'r', 'e', 'e') : \ diff --git a/source/blender/blenlib/intern/array_store.c b/source/blender/blenlib/intern/array_store.c index 825f2e36c6e..c87dbee0f0e 100644 --- a/source/blender/blenlib/intern/array_store.c +++ b/source/blender/blenlib/intern/array_store.c @@ -82,7 +82,7 @@ * matching chunks from this state are re-used in the new state. * * First matches at either end of the array are detected. - * For identical arrays this is all thats needed. + * For identical arrays this is all that's needed. * * De-duplication is performed on any remaining chunks, by hashing the first few bytes of the chunk * (see: BCHUNK_HASH_TABLE_ACCUMULATE_STEPS). @@ -301,7 +301,7 @@ typedef struct BChunkRef { * used for lookups. * * Point to the #BChunkRef, not the #BChunk, - * to allow talking down the chunks in-order until a mis-match is found, + * to allow talking down the chunks in-order until a mismatch is found, * this avoids having to do so many table lookups. */ typedef struct BTableRef { diff --git a/source/blender/blenlib/intern/boxpack_2d.c b/source/blender/blenlib/intern/boxpack_2d.c index f05523b8897..196d45967be 100644 --- a/source/blender/blenlib/intern/boxpack_2d.c +++ b/source/blender/blenlib/intern/boxpack_2d.c @@ -651,7 +651,7 @@ void BLI_box_pack_2d(BoxPack *boxarray, const uint len, float *r_tot_x, float *r } } /* The Box verts are only used internally - * Update the box x and y since thats what external + * Update the box x and y since that's what external * functions will see */ box->x = box_xmin_get(box); box->y = box_ymin_get(box); diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c index 8fff9603a88..0e3987eefc9 100644 --- a/source/blender/blenlib/intern/fileops.c +++ b/source/blender/blenlib/intern/fileops.c @@ -105,7 +105,7 @@ int BLI_file_gzip(const char *from, const char *to) #endif /* gzip the file in from_file and write it to memory to_mem, at most size bytes. - * return the unziped size + * return the unzipped size */ char *BLI_file_ungzip_to_mem(const char *from_file, int *r_size) { @@ -519,7 +519,7 @@ enum { /* operation requested not to perform recursive digging for current path */ RecursiveOp_Callback_StopRecurs = 1, - /* error occured in callback and recursive walking should stop immediately */ + /* error occurred in callback and recursive walking should stop immediately */ RecursiveOp_Callback_Error = 2, }; diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index 8b715ebf87b..7cdac6b1497 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -2826,12 +2826,12 @@ bool isect_ray_ray_v3(const float ray_origin_a[3], sub_v3_v3v3(c, n, t); if (r_lambda_a != NULL) { - cross_v3_v3v3(cray, c, ray_direction_a); + cross_v3_v3v3(cray, c, ray_direction_b); *r_lambda_a = dot_v3v3(cray, n) / nlen; } if (r_lambda_b != NULL) { - cross_v3_v3v3(cray, c, ray_direction_b); + cross_v3_v3v3(cray, c, ray_direction_a); *r_lambda_b = dot_v3v3(cray, n) / nlen; } @@ -4914,7 +4914,7 @@ void vcloud_estimate_transform_v3(const int list_size, unit_m3(lscale); } /* do com for both clouds */ - if (pos && rpos && (list_size > 0)) { /* paranoya check */ + if (pos && rpos && (list_size > 0)) { /* paranoia check */ /* do com for both clouds */ for (a = 0; a < list_size; a++) { if (weight) { diff --git a/source/blender/blenlib/intern/math_statistics.c b/source/blender/blenlib/intern/math_statistics.c index 7c461120520..d4fcb32ce37 100644 --- a/source/blender/blenlib/intern/math_statistics.c +++ b/source/blender/blenlib/intern/math_statistics.c @@ -42,7 +42,7 @@ typedef struct CovarianceData { static void covariance_m_vn_ex_task_cb(void *__restrict userdata, const int a, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { CovarianceData *data = userdata; const float *cos_vn = data->cos_vn; @@ -122,7 +122,7 @@ void BLI_covariance_m_vn_ex(const int n, .nbr_cos_vn = nbr_cos_vn, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((nbr_cos_vn * n * n) >= 10000); BLI_task_parallel_range(0, n * n, &data, covariance_m_vn_ex_task_cb, &settings); diff --git a/source/blender/blenlib/intern/polyfill_2d.c b/source/blender/blenlib/intern/polyfill_2d.c index 1538b5922b1..575a4a06d6a 100644 --- a/source/blender/blenlib/intern/polyfill_2d.c +++ b/source/blender/blenlib/intern/polyfill_2d.c @@ -780,7 +780,7 @@ static void polyfill_prepare(PolyFill *pf, coords_sign = (cross_poly_v2(coords, coords_tot) >= 0.0f) ? 1 : -1; } else { - /* check we're passing in correcty args */ + /* check we're passing in correct args */ #ifdef USE_STRICT_ASSERT # ifndef NDEBUG if (coords_sign == 1) { diff --git a/source/blender/blenlib/intern/rct.c b/source/blender/blenlib/intern/rct.c index 99288abb38c..ecff2ebffef 100644 --- a/source/blender/blenlib/intern/rct.c +++ b/source/blender/blenlib/intern/rct.c @@ -285,12 +285,12 @@ bool BLI_rcti_isect_segment(const rcti *rect, const int s1[2], const int s2[2]) return false; } - /* if either points intersect then we definetly intersect */ + /* if either points intersect then we definitely intersect */ if (BLI_rcti_isect_pt_v(rect, s1) || BLI_rcti_isect_pt_v(rect, s2)) { return true; } else { - /* both points are outside but may insersect the rect */ + /* both points are outside but may intersect the rect */ int tvec1[2]; int tvec2[2]; /* diagonal: [/] */ @@ -332,12 +332,12 @@ bool BLI_rctf_isect_segment(const rctf *rect, const float s1[2], const float s2[ return false; } - /* if either points intersect then we definetly intersect */ + /* if either points intersect then we definitely intersect */ if (BLI_rctf_isect_pt_v(rect, s1) || BLI_rctf_isect_pt_v(rect, s2)) { return true; } else { - /* both points are outside but may insersect the rect */ + /* both points are outside but may intersect the rect */ float tvec1[2]; float tvec2[2]; /* diagonal: [/] */ diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c index 39af73ac175..8d921b062dc 100644 --- a/source/blender/blenlib/intern/storage.c +++ b/source/blender/blenlib/intern/storage.c @@ -297,56 +297,72 @@ bool BLI_is_file(const char *path) return (mode && !S_ISDIR(mode)); } -void *BLI_file_read_text_as_mem(const char *filepath, size_t pad_bytes, size_t *r_size) +/** + * Use for both text and binary file reading. + */ +static void *file_read_data_as_mem_impl(FILE *fp, + bool read_size_exact, + size_t pad_bytes, + size_t *r_size) { - FILE *fp = BLI_fopen(filepath, "r"); - void *mem = NULL; + struct stat st; + if (fstat(fileno(fp), &st) == -1) { + return NULL; + } + if (S_ISDIR(st.st_mode)) { + return NULL; + } + if (fseek(fp, 0L, SEEK_END) == -1) { + return NULL; + } + /* Don't use the 'st_size' because it may be the symlink. */ + const long int filelen = ftell(fp); + if (filelen == -1) { + return NULL; + } + if (fseek(fp, 0L, SEEK_SET) == -1) { + return NULL; + } - if (fp) { - struct stat st; - if (fstat(fileno(fp), &st) == -1) { - goto finally; - } - if (S_ISDIR(st.st_mode)) { - goto finally; - } - if (fseek(fp, 0L, SEEK_END) == -1) { - goto finally; - } - /* Don't use the 'st_size' because it may be the symlink. */ - const long int filelen = ftell(fp); - if (filelen == -1) { - goto finally; - } - if (fseek(fp, 0L, SEEK_SET) == -1) { - goto finally; - } + void *mem = MEM_mallocN(filelen + pad_bytes, __func__); + if (mem == NULL) { + return NULL; + } - mem = MEM_mallocN(filelen + pad_bytes, __func__); - if (mem == NULL) { - goto finally; - } + const long int filelen_read = fread(mem, 1, filelen, fp); + if ((filelen_read < 0) || ferror(fp)) { + MEM_freeN(mem); + return NULL; + } - const long int filelen_read = fread(mem, 1, filelen, fp); - if ((filelen_read < 0) || ferror(fp)) { + if (read_size_exact) { + if (filelen_read != filelen) { MEM_freeN(mem); - mem = NULL; - goto finally; + return NULL; } - + } + else { if (filelen_read < filelen) { mem = MEM_reallocN(mem, filelen_read + pad_bytes); if (mem == NULL) { - goto finally; + return NULL; } } + } - *r_size = filelen_read; + *r_size = filelen_read; + + return mem; +} - finally: +void *BLI_file_read_text_as_mem(const char *filepath, size_t pad_bytes, size_t *r_size) +{ + FILE *fp = BLI_fopen(filepath, "r"); + void *mem = NULL; + if (fp) { + mem = file_read_data_as_mem_impl(fp, false, pad_bytes, r_size); fclose(fp); } - return mem; } @@ -354,45 +370,10 @@ void *BLI_file_read_binary_as_mem(const char *filepath, size_t pad_bytes, size_t { FILE *fp = BLI_fopen(filepath, "rb"); void *mem = NULL; - if (fp) { - struct stat st; - if (fstat(fileno(fp), &st) == -1) { - goto finally; - } - if (S_ISDIR(st.st_mode)) { - goto finally; - } - if (fseek(fp, 0L, SEEK_END) == -1) { - goto finally; - } - /* Don't use the 'st_size' because it may be the symlink. */ - const long int filelen = ftell(fp); - if (filelen == -1) { - goto finally; - } - if (fseek(fp, 0L, SEEK_SET) == -1) { - goto finally; - } - - mem = MEM_mallocN(filelen + pad_bytes, __func__); - if (mem == NULL) { - goto finally; - } - - const long int filelen_read = fread(mem, 1, filelen, fp); - if ((filelen_read != filelen) || ferror(fp)) { - MEM_freeN(mem); - mem = NULL; - goto finally; - } - - *r_size = filelen_read; - - finally: + mem = file_read_data_as_mem_impl(fp, true, pad_bytes, r_size); fclose(fp); } - return mem; } diff --git a/source/blender/blenlib/intern/string_cursor_utf8.c b/source/blender/blenlib/intern/string_cursor_utf8.c index 1526a052aad..f0113a7028a 100644 --- a/source/blender/blenlib/intern/string_cursor_utf8.c +++ b/source/blender/blenlib/intern/string_cursor_utf8.c @@ -104,7 +104,7 @@ static eStrCursorDelimType cursor_delim_type_unicode(const uint uch) static eStrCursorDelimType cursor_delim_type_utf8(const char *ch_utf8) { /* for full unicode support we really need to have large lookup tables to figure - * out whats what in every possible char set - and python, glib both have these. */ + * out what's what in every possible char set - and python, glib both have these. */ uint uch = BLI_str_utf8_as_unicode(ch_utf8); return cursor_delim_type_unicode(uch); } diff --git a/source/blender/blenlib/intern/task.c b/source/blender/blenlib/intern/task.c index 85d39f2f98e..bea38a232cc 100644 --- a/source/blender/blenlib/intern/task.c +++ b/source/blender/blenlib/intern/task.c @@ -1054,6 +1054,49 @@ typedef struct ParallelRangeState { int chunk_size; } ParallelRangeState; +BLI_INLINE void task_parallel_range_calc_chunk_size(const TaskParallelSettings *settings, + const int num_tasks, + ParallelRangeState *state) +{ + const int tot_items = state->stop - state->start; + int chunk_size = 0; + + if (settings->min_iter_per_thread > 0) { + /* Already set by user, no need to do anything here. */ + chunk_size = settings->min_iter_per_thread; + } + else { + /* Basic heuristic to avoid threading on low amount of items. We could make that limit + * configurable in settings too... */ + if (tot_items > 0 && tot_items < 256) { + chunk_size = tot_items; + } + /* NOTE: The idea here is to compensate for rather measurable threading + * overhead caused by fetching tasks. With too many CPU threads we are starting + * to spend too much time in those overheads. */ + else if (num_tasks > 32) { + chunk_size = 128; + } + else if (num_tasks > 16) { + chunk_size = 64; + } + else { + chunk_size = 32; + } + } + + BLI_assert(chunk_size > 0); + + switch (settings->scheduling_mode) { + case TASK_SCHEDULING_STATIC: + state->chunk_size = max_ii(chunk_size, tot_items / (num_tasks)); + break; + case TASK_SCHEDULING_DYNAMIC: + state->chunk_size = chunk_size; + break; + } +} + BLI_INLINE bool parallel_range_next_iter_get(ParallelRangeState *__restrict state, int *__restrict iter, int *__restrict count) @@ -1069,7 +1112,7 @@ BLI_INLINE bool parallel_range_next_iter_get(ParallelRangeState *__restrict stat static void parallel_range_func(TaskPool *__restrict pool, void *userdata_chunk, int thread_id) { ParallelRangeState *__restrict state = BLI_task_pool_userdata(pool); - ParallelRangeTLS tls = { + TaskParallelTLS tls = { .thread_id = thread_id, .userdata_chunk = userdata_chunk, }; @@ -1085,7 +1128,7 @@ static void parallel_range_single_thread(const int start, int const stop, void *userdata, TaskParallelRangeFunc func, - const ParallelRangeSettings *settings) + const TaskParallelSettings *settings) { void *userdata_chunk = settings->userdata_chunk; const size_t userdata_chunk_size = settings->userdata_chunk_size; @@ -1095,7 +1138,7 @@ static void parallel_range_single_thread(const int start, userdata_chunk_local = MALLOCA(userdata_chunk_size); memcpy(userdata_chunk_local, userdata_chunk, userdata_chunk_size); } - ParallelRangeTLS tls = { + TaskParallelTLS tls = { .thread_id = 0, .userdata_chunk = userdata_chunk_local, }; @@ -1118,7 +1161,7 @@ void BLI_task_parallel_range(const int start, const int stop, void *userdata, TaskParallelRangeFunc func, - const ParallelRangeSettings *settings) + const TaskParallelSettings *settings) { TaskScheduler *task_scheduler; TaskPool *task_pool; @@ -1162,16 +1205,8 @@ void BLI_task_parallel_range(const int start, state.userdata = userdata; state.func = func; state.iter = start; - switch (settings->scheduling_mode) { - case TASK_SCHEDULING_STATIC: - state.chunk_size = max_ii(settings->min_iter_per_thread, (stop - start) / (num_tasks)); - break; - case TASK_SCHEDULING_DYNAMIC: - /* TODO(sergey): Make it configurable from min_iter_per_thread. */ - state.chunk_size = 32; - break; - } + task_parallel_range_calc_chunk_size(settings, num_tasks, &state); num_tasks = min_ii(num_tasks, max_ii(1, (stop - start) / state.chunk_size)); if (num_tasks == 1) { diff --git a/source/blender/blenloader/BLO_readfile.h b/source/blender/blenloader/BLO_readfile.h index 8769ed37d16..8944dfdb711 100644 --- a/source/blender/blenloader/BLO_readfile.h +++ b/source/blender/blenloader/BLO_readfile.h @@ -165,7 +165,6 @@ void BLO_main_expander(BLOExpandDoitCallback expand_doit_func); void BLO_expand_main(void *fdhandle, struct Main *mainvar); /* Update defaults in startup.blend & userprefs.blend, without having to save and embed it */ -void BLO_update_defaults_userpref_blend(void); void BLO_update_defaults_startup_blend(struct Main *mainvar, const char *app_template); void BLO_update_defaults_workspace(struct WorkSpace *workspace, const char *app_template); @@ -176,6 +175,7 @@ struct BlendThumbnail *BLO_thumbnail_from_file(const char *filepath); /* datafiles (generated theme) */ extern const struct bTheme U_theme_default; +extern const struct UserDef U_default; #ifdef __cplusplus } diff --git a/source/blender/blenloader/CMakeLists.txt b/source/blender/blenloader/CMakeLists.txt index 8ab93ba382c..1520c7b82b8 100644 --- a/source/blender/blenloader/CMakeLists.txt +++ b/source/blender/blenloader/CMakeLists.txt @@ -77,12 +77,6 @@ if(WITH_BUILDINFO) add_definitions(-DWITH_BUILDINFO) endif() -if(WITH_PYTHON) - if(WITH_PYTHON_SECURITY) - add_definitions(-DWITH_PYTHON_SECURITY) - endif() -endif() - if(WITH_INTERNATIONAL) add_definitions(-DWITH_INTERNATIONAL) endif() diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 44039ad59ee..44bb07d87f8 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -2419,7 +2419,7 @@ static void IDP_DirectLinkIDPArray(IDProperty *prop, int switch_endian, FileData array = (IDProperty *)prop->data.pointer; /* note!, idp-arrays didn't exist in 2.4x, so the pointer will be cleared - * theres not really anything we can do to correct this, at least don't crash */ + * there's not really anything we can do to correct this, at least don't crash */ if (array == NULL) { prop->len = 0; prop->totallen = 0; @@ -6220,6 +6220,7 @@ static void direct_link_collection(FileData *fd, Collection *collection) collection->preview = direct_link_preview_image(fd, collection->preview); collection->flag &= ~COLLECTION_HAS_OBJECT_CACHE; + collection->tag = 0; BLI_listbase_clear(&collection->object_cache); BLI_listbase_clear(&collection->parents); @@ -6412,12 +6413,22 @@ static void lib_link_scene(FileData *fd, Main *main) sce->set = newlibadr(fd, sce->id.lib, sce->set); sce->gpd = newlibadr_us(fd, sce->id.lib, sce->gpd); - link_paint(fd, sce, &sce->toolsettings->sculpt->paint); - link_paint(fd, sce, &sce->toolsettings->vpaint->paint); - link_paint(fd, sce, &sce->toolsettings->wpaint->paint); link_paint(fd, sce, &sce->toolsettings->imapaint.paint); - link_paint(fd, sce, &sce->toolsettings->uvsculpt->paint); - link_paint(fd, sce, &sce->toolsettings->gp_paint->paint); + if (sce->toolsettings->sculpt) { + link_paint(fd, sce, &sce->toolsettings->sculpt->paint); + } + if (sce->toolsettings->vpaint) { + link_paint(fd, sce, &sce->toolsettings->vpaint->paint); + } + if (sce->toolsettings->wpaint) { + link_paint(fd, sce, &sce->toolsettings->wpaint->paint); + } + if (sce->toolsettings->uvsculpt) { + link_paint(fd, sce, &sce->toolsettings->uvsculpt->paint); + } + if (sce->toolsettings->gp_paint) { + link_paint(fd, sce, &sce->toolsettings->gp_paint->paint); + } if (sce->toolsettings->sculpt) { sce->toolsettings->sculpt->gravity_object = newlibadr( @@ -7038,6 +7049,7 @@ static void direct_link_gpencil(FileData *fd, bGPdata *gpd) /* init stroke buffer */ gpd->runtime.sbuffer = NULL; + gpd->runtime.sbuffer_used = 0; gpd->runtime.sbuffer_size = 0; gpd->runtime.tot_cp_points = 0; @@ -7125,7 +7137,7 @@ static void direct_link_region(FileData *fd, ARegion *ar, int spacetype) link_list(fd, &ar->ui_previews); if (spacetype == SPACE_EMPTY) { - /* unkown space type, don't leak regiondata */ + /* unknown space type, don't leak regiondata */ ar->regiondata = NULL; } else if (ar->flag & RGN_FLAG_TEMP_REGIONDATA) { @@ -9137,7 +9149,18 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, const int ta id->icon_id = 0; id->newid = NULL; /* Needed because .blend may have been saved with crap value here... */ id->orig_id = NULL; - id->recalc = 0; + + /* NOTE: It is important to not clear the recalc flags for undo/redo. + * Preserving recalc flags on redo/undo is the only way to make dependency graph detect + * that animation is to be evaluated on undo/redo. If this is not enforced by the recalc + * flags dependency graph does not do animation update to avoid loss of unkeyed changes., + * which conflicts with undo/redo of changes to animation data itself. + * + * But for regular file load we clear the flag, since the flags might have been changed sinde + * the version the file has been saved with. */ + if (!fd->memfile) { + id->recalc = 0; + } /* this case cannot be direct_linked: it's just the ID part */ if (bhead->code == ID_LINK_PLACEHOLDER) { diff --git a/source/blender/blenloader/intern/versioning_250.c b/source/blender/blenloader/intern/versioning_250.c index 17facb3ae20..81751a6ed07 100644 --- a/source/blender/blenloader/intern/versioning_250.c +++ b/source/blender/blenloader/intern/versioning_250.c @@ -960,7 +960,7 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain) bPoseChannel *pchan; for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) { - /* just need to initalise rotation axis properly... */ + /* just need to initialise rotation axis properly... */ pchan->rotAxis[1] = 1.0f; } } diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c index 9d9906fc3e0..3dc79308f64 100644 --- a/source/blender/blenloader/intern/versioning_270.c +++ b/source/blender/blenloader/intern/versioning_270.c @@ -888,7 +888,7 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain) } } - /* hysteresis setted to 10% but not actived */ + /* hysteresis set to 10% but not activated */ if (!DNA_struct_elem_find(fd->filesdna, "LodLevel", "int", "obhysteresis")) { Object *ob; for (ob = bmain->objects.first; ob; ob = ob->id.next) { diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c index cb2b64957f0..1a79b7c9b5a 100644 --- a/source/blender/blenloader/intern/versioning_280.c +++ b/source/blender/blenloader/intern/versioning_280.c @@ -3533,6 +3533,22 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) } } + if (!MAIN_VERSION_ATLEAST(bmain, 281, 1)) { + LISTBASE_FOREACH (Object *, ob, &bmain->objects) { + for (ModifierData *md = ob->modifiers.first; md; md = md->next) { + if (md->type == eModifierType_DataTransfer) { + /* Now datatransfer's mix factor is multiplied with weights when any, + * instead of being ignored, + * we need to take care of that to keep 'old' files compatible. */ + DataTransferModifierData *dtmd = (DataTransferModifierData *)md; + if (dtmd->defgrp_name[0] != '\0') { + dtmd->mix_factor = 1.0f; + } + } + } + } + } + { /* Versioning code until next subversion bump goes here. */ } diff --git a/source/blender/blenloader/intern/versioning_defaults.c b/source/blender/blenloader/intern/versioning_defaults.c index 57c674ae1b1..14230752d1f 100644 --- a/source/blender/blenloader/intern/versioning_defaults.c +++ b/source/blender/blenloader/intern/versioning_defaults.c @@ -36,94 +36,21 @@ #include "DNA_userdef_types.h" #include "DNA_windowmanager_types.h" #include "DNA_workspace_types.h" +#include "DNA_mesh_types.h" +#include "DNA_meshdata_types.h" #include "BKE_appdir.h" -#include "BKE_brush.h" -#include "BKE_colorband.h" #include "BKE_colortools.h" -#include "BKE_idprop.h" -#include "BKE_keyconfig.h" #include "BKE_layer.h" #include "BKE_library.h" #include "BKE_main.h" #include "BKE_node.h" -#include "BKE_paint.h" #include "BKE_screen.h" -#include "BKE_studiolight.h" #include "BKE_workspace.h" #include "BLO_readfile.h" /** - * Override values in in-memory startup.blend, avoids re-saving for small changes. - */ -void BLO_update_defaults_userpref_blend(void) -{ - /* default so DPI is detected automatically */ - U.dpi = 0; - U.ui_scale = 1.0f; - -#ifdef WITH_PYTHON_SECURITY - /* use alternative setting for security nuts - * otherwise we'd need to patch the binary blob - startup.blend.c */ - U.flag |= USER_SCRIPT_AUTOEXEC_DISABLE; -#else - U.flag &= ~USER_SCRIPT_AUTOEXEC_DISABLE; -#endif - - /* Transform tweak with single click and drag. */ - U.flag |= USER_RELEASECONFIRM; - - U.flag &= ~(USER_DEVELOPER_UI | USER_TOOLTIPS_PYTHON); - - /* Clear addon preferences. */ - for (bAddon *addon = U.addons.first, *addon_next; addon != NULL; addon = addon_next) { - addon_next = addon->next; - - if (addon->prop) { - IDP_FreeProperty(addon->prop); - addon->prop = NULL; - } - } - - /* Ignore the theme saved in the blend file, - * instead use the theme from 'userdef_default_theme.c' */ - { - bTheme *theme = U.themes.first; - memcpy(theme, &U_theme_default, sizeof(bTheme)); - } - - /* Leave temp directory empty, will then get appropriate value per OS. */ - U.tempdir[0] = '\0'; - - /* System-specific fonts directory. */ - BKE_appdir_font_folder_default(U.fontdir); - - /* Only enable tooltips translation by default, - * without actually enabling translation itself, for now. */ - U.transopts = USER_TR_TOOLTIPS; - U.memcachelimit = min_ii(BLI_system_memory_max_in_megabytes_int() / 2, 4096); - - /* Auto perspective. */ - U.uiflag |= USER_AUTOPERSP; - - /* Init weight paint range. */ - BKE_colorband_init(&U.coba_weight, true); - - /* Default visible section. */ - U.userpref = USER_SECTION_INTERFACE; - - /* Default to left click select. */ - BKE_keyconfig_pref_set_select_mouse(&U, 0, true); - - /* Increase a little for new scrubbing area. */ - U.v2d_min_gridsize = 45; - - /* Default studio light. */ - BKE_studiolight_default(U.light_param, U.light_ambient); -} - -/** * Rename if the ID doesn't exist. */ static ID *rename_id_for_versioning(Main *bmain, @@ -358,6 +285,20 @@ static void blo_update_defaults_scene(Main *bmain, Scene *scene) CURVE_PRESET_BELL, CURVEMAP_SLOPE_POSITIVE); } + + /* Correct default startup UV's. */ + Mesh *me = BLI_findstring(&bmain->meshes, "Cube", offsetof(ID, name) + 2); + if (me && (me->totloop == 24) && (me->mloopuv != NULL)) { + const float uv_values[24][2] = { + {0.625, 0.50}, {0.875, 0.50}, {0.875, 0.75}, {0.625, 0.75}, {0.375, 0.75}, {0.625, 0.75}, + {0.625, 1.00}, {0.375, 1.00}, {0.375, 0.00}, {0.625, 0.00}, {0.625, 0.25}, {0.375, 0.25}, + {0.125, 0.50}, {0.375, 0.50}, {0.375, 0.75}, {0.125, 0.75}, {0.375, 0.50}, {0.625, 0.50}, + {0.625, 0.75}, {0.375, 0.75}, {0.375, 0.25}, {0.625, 0.25}, {0.625, 0.50}, {0.375, 0.50}, + }; + for (int i = 0; i < ARRAY_SIZE(uv_values); i++) { + copy_v2_v2(me->mloopuv[i].uv, uv_values[i]); + } + } } /** diff --git a/source/blender/blenloader/intern/versioning_legacy.c b/source/blender/blenloader/intern/versioning_legacy.c index 69802b35ff9..0f1d7cbf70f 100644 --- a/source/blender/blenloader/intern/versioning_legacy.c +++ b/source/blender/blenloader/intern/versioning_legacy.c @@ -1181,7 +1181,7 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) } /* new variable blockscale, for panels in any area, do again because new - * areas didnt initialize it to 0.7 yet + * areas didn't initialize it to 0.7 yet */ for (sc = bmain->screens.first; sc; sc = sc->id.next) { ScrArea *sa; @@ -1782,7 +1782,7 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain) } } - /* copy old object level track settings to curve modifers */ + /* copy old object level track settings to curve modifiers */ for (md = ob->modifiers.first; md; md = md->next) { if (md->type == eModifierType_Curve) { CurveModifierData *cmd = (CurveModifierData *)md; diff --git a/source/blender/blentranslation/CMakeLists.txt b/source/blender/blentranslation/CMakeLists.txt index 34952911dce..70e68ca06d7 100644 --- a/source/blender/blentranslation/CMakeLists.txt +++ b/source/blender/blentranslation/CMakeLists.txt @@ -22,6 +22,7 @@ set(INC . ../blenkernel ../blenlib + ../imbuf ../makesdna ../makesrna ../../../intern/guardedalloc diff --git a/source/blender/blentranslation/intern/blt_lang.c b/source/blender/blentranslation/intern/blt_lang.c index 75a4681deb2..82386a17776 100644 --- a/source/blender/blentranslation/intern/blt_lang.c +++ b/source/blender/blentranslation/intern/blt_lang.c @@ -42,6 +42,8 @@ #include "BKE_appdir.h" +#include "IMB_thumbs.h" + #include "DNA_userdef_types.h" #include "MEM_guardedalloc.h" @@ -288,6 +290,7 @@ void BLT_lang_set(const char *str) (void)str; #endif blt_lang_check_ime_supported(); + IMB_thumb_clear_translations(); } /* Get the current locale (short code, e.g. es_ES). */ diff --git a/source/blender/blentranslation/msgfmt/msgfmt.c b/source/blender/blentranslation/msgfmt/msgfmt.c index 500ae2df4b5..f226699d8bf 100644 --- a/source/blender/blentranslation/msgfmt/msgfmt.c +++ b/source/blender/blentranslation/msgfmt/msgfmt.c @@ -362,7 +362,7 @@ static int make(const char *input_file_name, const char *output_file_name) else if (strstr(l, msgid_plural_kw) == l) { /* This is a message with plural forms. */ if (section != SECTION_ID) { - printf("msgid_plural not preceeded by msgid on %s:%d\n", input_file_name, lno); + printf("msgid_plural not preceded by msgid on %s:%d\n", input_file_name, lno); return EXIT_FAILURE; } l = l + msgid_plural_len; diff --git a/source/blender/bmesh/bmesh_class.h b/source/blender/bmesh/bmesh_class.h index 8349dee06e2..1393e24e48e 100644 --- a/source/blender/bmesh/bmesh_class.h +++ b/source/blender/bmesh/bmesh_class.h @@ -23,7 +23,7 @@ /* bmesh data structures */ -/* dissable holes for now, +/* disable holes for now, * these are ifdef'd because they use more memory and cant be saved in DNA currently */ // #define USE_BMESH_HOLES diff --git a/source/blender/bmesh/intern/bmesh_construct.c b/source/blender/bmesh/intern/bmesh_construct.c index 224f6ad1e5c..760b0aa00ae 100644 --- a/source/blender/bmesh/intern/bmesh_construct.c +++ b/source/blender/bmesh/intern/bmesh_construct.c @@ -487,7 +487,7 @@ static void bm_vert_attrs_copy(BMesh *source_mesh, uint64_t cd_mask) { if ((source_mesh == target_mesh) && (source_vertex == target_vertex)) { - BLI_assert(!"BMVert: source and targer match"); + BLI_assert(!"BMVert: source and target match"); return; } if ((cd_mask & CD_MASK_NORMAL) == 0) { @@ -507,7 +507,7 @@ static void bm_edge_attrs_copy(BMesh *source_mesh, uint64_t UNUSED(cd_mask)) { if ((source_mesh == target_mesh) && (source_edge == target_edge)) { - BLI_assert(!"BMEdge: source and targer match"); + BLI_assert(!"BMEdge: source and target match"); return; } CustomData_bmesh_free_block_data(&target_mesh->edata, target_edge->head.data); @@ -522,7 +522,7 @@ static void bm_loop_attrs_copy(BMesh *source_mesh, uint64_t UNUSED(cd_mask)) { if ((source_mesh == target_mesh) && (source_loop == target_loop)) { - BLI_assert(!"BMLoop: source and targer match"); + BLI_assert(!"BMLoop: source and target match"); return; } CustomData_bmesh_free_block_data(&target_mesh->ldata, target_loop->head.data); @@ -537,7 +537,7 @@ static void bm_face_attrs_copy(BMesh *source_mesh, uint64_t cd_mask) { if ((source_mesh == target_mesh) && (source_face == target_face)) { - BLI_assert(!"BMFace: source and targer match"); + BLI_assert(!"BMFace: source and target match"); return; } if ((cd_mask & CD_MASK_NORMAL) == 0) { diff --git a/source/blender/bmesh/intern/bmesh_core.c b/source/blender/bmesh/intern/bmesh_core.c index 6ece32e57e8..68b30912041 100644 --- a/source/blender/bmesh/intern/bmesh_core.c +++ b/source/blender/bmesh/intern/bmesh_core.c @@ -209,7 +209,7 @@ BMEdge *BM_edge_create( /** * \note In most cases a \a l_example should be NULL, - * since this is a low level API and we shouldn't attempt to be clever and guess whats intended. + * since this is a low level API and we shouldn't attempt to be clever and guess what's intended. * In cases where copying adjacent loop-data is useful, see #BM_face_copy_shared. */ static BMLoop *bm_loop_create(BMesh *bm, diff --git a/source/blender/bmesh/intern/bmesh_interp.c b/source/blender/bmesh/intern/bmesh_interp.c index c58521297dd..48d6bcd7b03 100644 --- a/source/blender/bmesh/intern/bmesh_interp.c +++ b/source/blender/bmesh/intern/bmesh_interp.c @@ -39,7 +39,7 @@ #include "bmesh.h" #include "intern/bmesh_private.h" -/* edge and vertex share, currently theres no need to have different logic */ +/* edge and vertex share, currently there's no need to have different logic */ static void bm_data_interp_from_elem(CustomData *data_layer, const BMElem *ele_src_1, const BMElem *ele_src_2, @@ -461,7 +461,7 @@ typedef struct BMLoopInterpMultiresData { static void loop_interp_multires_cb(void *__restrict userdata, const int ix, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { BMLoopInterpMultiresData *data = userdata; @@ -561,7 +561,7 @@ void BM_loop_interp_multires_ex(BMesh *UNUSED(bm), .res = res, .d = 1.0f / (float)(res - 1), }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (res > 5); BLI_task_parallel_range(0, res, &data, loop_interp_multires_cb, &settings); diff --git a/source/blender/bmesh/intern/bmesh_marking.c b/source/blender/bmesh/intern/bmesh_marking.c index bb55365f619..5aec59ccd5d 100644 --- a/source/blender/bmesh/intern/bmesh_marking.c +++ b/source/blender/bmesh/intern/bmesh_marking.c @@ -884,8 +884,8 @@ void BM_editselection_plane(BMEditSelection *ese, float r_plane[3]) sub_v3_v3v3(r_plane, vec, eve->co); } else { - /* make a fake plane thats at rightangles to the normal - * we cant make a crossvec from a vec thats the same as the vec + /* make a fake plane that's at rightangles to the normal + * we can't make a crossvec from a vec that's the same as the vec * unlikely but possible, so make sure if the normal is (0, 0, 1) * that vec isn't the same or in the same direction even. */ if (eve->no[0] < 0.5f) { diff --git a/source/blender/bmesh/intern/bmesh_mesh.c b/source/blender/bmesh/intern/bmesh_mesh.c index c796bdea688..f44b758ef6b 100644 --- a/source/blender/bmesh/intern/bmesh_mesh.c +++ b/source/blender/bmesh/intern/bmesh_mesh.c @@ -1345,7 +1345,7 @@ void BM_normals_loops_edges_tag(BMesh *bm, const bool do_edges) } /** - * Auxillary function only used by rebuild to detect if any spaces were not marked as invalid. + * Auxiliary function only used by rebuild to detect if any spaces were not marked as invalid. * Reports error if any of the lnor spaces change after rebuilding, meaning that all the possible * lnor spaces to be rebuilt were not correctly marked. */ diff --git a/source/blender/bmesh/intern/bmesh_mods.c b/source/blender/bmesh/intern/bmesh_mods.c index c28d748b2eb..53f68804bd3 100644 --- a/source/blender/bmesh/intern/bmesh_mods.c +++ b/source/blender/bmesh/intern/bmesh_mods.c @@ -1029,7 +1029,7 @@ BMEdge *BM_edge_rotate(BMesh *bm, BMEdge *e, const bool ccw, const short check_f /* Rotate The Edge */ /* first create the new edge, this is so we can copy the customdata from the old one - * if splice if disabled, always add in a new edge even if theres one there. */ + * if splice if disabled, always add in a new edge even if there's one there. */ e_new = BM_edge_create( bm, v1, v2, e, (check_flag & BM_EDGEROT_CHECK_SPLICE) ? BM_CREATE_NO_DOUBLE : BM_CREATE_NOP); diff --git a/source/blender/bmesh/intern/bmesh_opdefines.c b/source/blender/bmesh/intern/bmesh_opdefines.c index 2114f9ebd3d..e8b35afdcb1 100644 --- a/source/blender/bmesh/intern/bmesh_opdefines.c +++ b/source/blender/bmesh/intern/bmesh_opdefines.c @@ -1545,7 +1545,7 @@ static BMOpDefine bmo_split_edges_def = { "split_edges", /* slots_in */ {{"edges", BMO_OP_SLOT_ELEMENT_BUF, {BM_EDGE}}, /* input edges */ - /* needed for vertex rip so we can rip only half an edge at a boundary wich would otherwise split off */ + /* needed for vertex rip so we can rip only half an edge at a boundary which would otherwise split off */ {"verts", BMO_OP_SLOT_ELEMENT_BUF, {BM_VERT}}, /* optional tag verts, use to have greater control of splits */ {"use_verts", BMO_OP_SLOT_BOOL}, /* use 'verts' for splitting, else just find verts to split from edges */ {{'\0'}}, diff --git a/source/blender/bmesh/intern/bmesh_operator_api.h b/source/blender/bmesh/intern/bmesh_operator_api.h index f06a5fb8b13..2039289dcd7 100644 --- a/source/blender/bmesh/intern/bmesh_operator_api.h +++ b/source/blender/bmesh/intern/bmesh_operator_api.h @@ -100,7 +100,7 @@ BLI_INLINE BMFlagLayer *BMO_elem_flag_from_header(BMHeader *ele_head) _bmo_elem_flag_toggle( \ bm, (BM_CHECK_TYPE_ELEM_NONCONST(ele), BMO_elem_flag_from_header(&(ele)->head)), oflag) -/* take care not to instansiate args multiple times */ +/* take care not to instantiate args multiple times */ #ifdef __GNUC___ # define _BMO_CAST_V_CONST(e) \ ({ \ @@ -203,7 +203,7 @@ typedef enum eBMOpSlotType { /* normally store pointers to object, scene, * _never_ store arrays corresponding to mesh elements with this */ - BMO_OP_SLOT_PTR = 4, /* requres subtype BMO_OP_SLOT_SUBTYPE_PTR_xxx */ + BMO_OP_SLOT_PTR = 4, /* requires subtype BMO_OP_SLOT_SUBTYPE_PTR_xxx */ BMO_OP_SLOT_MAT = 5, BMO_OP_SLOT_VEC = 8, @@ -212,7 +212,7 @@ typedef enum eBMOpSlotType { * * it's very important this remain a power of two */ BMO_OP_SLOT_ELEMENT_BUF = 9, /* list of verts/edges/faces */ - BMO_OP_SLOT_MAPPING = 10 /* simple hash map, requres subtype BMO_OP_SLOT_SUBTYPE_MAP_xxx */ + BMO_OP_SLOT_MAPPING = 10 /* simple hash map, requires subtype BMO_OP_SLOT_SUBTYPE_MAP_xxx */ } eBMOpSlotType; #define BMO_OP_SLOT_TOTAL_TYPES 11 diff --git a/source/blender/bmesh/intern/bmesh_polygon_edgenet.c b/source/blender/bmesh/intern/bmesh_polygon_edgenet.c index 14b73693b03..83ac7df058a 100644 --- a/source/blender/bmesh/intern/bmesh_polygon_edgenet.c +++ b/source/blender/bmesh/intern/bmesh_polygon_edgenet.c @@ -495,13 +495,16 @@ bool BM_face_split_edgenet(BMesh *bm, return false; } + /* These arrays used to be stack memory, however they can be + * large for single faces with complex edgenets, see: T65980. */ + /* over-alloc (probably 2-4 is only used in most cases), for the biggest-fan */ - edge_order = BLI_array_alloca(edge_order, edge_order_len); + edge_order = MEM_mallocN(sizeof(*edge_order) * edge_order_len, __func__); /* use later */ - face_verts = BLI_array_alloca(face_verts, edge_net_len + f->len); + face_verts = MEM_mallocN(sizeof(*face_verts) * (edge_net_len + f->len), __func__); - vert_queue = BLI_array_alloca(vert_queue, edge_net_len + f->len); + vert_queue = MEM_mallocN(sizeof(vert_queue) * (edge_net_len + f->len), __func__); STACK_INIT(vert_queue, f->len + edge_net_len); BLI_assert(BM_ELEM_API_FLAG_TEST(f, FACE_NET) == 0); @@ -687,6 +690,10 @@ bool BM_face_split_edgenet(BMesh *bm, } } + MEM_freeN(edge_order); + MEM_freeN(face_verts); + MEM_freeN(vert_queue); + return true; } @@ -758,8 +765,8 @@ struct EdgeGroupIsland { /* Set the following vars once we have >1 groups */ - /* when when an edge in a previous group connects to this one, - * so theres no need to create one pointing back. */ + /* when an edge in a previous group connects to this one, + * so there's no need to create one pointing back. */ uint has_prev_edge : 1; /* verts in the group which has the lowest & highest values, @@ -993,7 +1000,7 @@ static int bm_face_split_edgenet_find_connection(const struct EdgeGroup_FindConn * until a vertex is found which isn't blocked by an edge. * * \note It's possible none of the verts can be accessed (with self-intersecting lines). - * In that case theres no right answer (without subdividing edges), + * In that case there's no right answer (without subdividing edges), * so return a fall-back vertex in that case. */ @@ -1247,7 +1254,7 @@ bool BM_face_split_edgenet_connect_islands(BMesh *bm, */ const uint edge_arr_len = (uint)edge_net_init_len + (uint)f->len; - BMEdge **edge_arr = BLI_array_alloca(edge_arr, edge_arr_len); + BMEdge **edge_arr = BLI_memarena_alloc(mem_arena, sizeof(*edge_arr) * edge_arr_len); bool ok = false; uint edge_net_new_len = (uint)edge_net_init_len; @@ -1342,7 +1349,7 @@ bool BM_face_split_edgenet_connect_islands(BMesh *bm, BM_elem_flag_disable(e_iter, EDGE_NOT_IN_STACK); unique_edges_in_group++; - BLI_linklist_prepend_alloca(&edge_links, e_iter); + BLI_linklist_prepend_arena(&edge_links, e_iter, mem_arena); BMVert *v_other = BM_edge_other_vert(e_iter, v_iter); if (BM_elem_flag_test(v_other, VERT_NOT_IN_STACK)) { @@ -1353,7 +1360,7 @@ bool BM_face_split_edgenet_connect_islands(BMesh *bm, } while ((e_iter = BM_DISK_EDGE_NEXT(e_iter, v_iter)) != v_iter->e); } - struct EdgeGroupIsland *g = alloca(sizeof(*g)); + struct EdgeGroupIsland *g = BLI_memarena_alloc(mem_arena, sizeof(*g)); g->vert_len = unique_verts_in_group; g->edge_len = unique_edges_in_group; edge_in_group_tot += unique_edges_in_group; @@ -1474,7 +1481,7 @@ bool BM_face_split_edgenet_connect_islands(BMesh *bm, if (!BM_elem_flag_test(v_iter, VERT_IN_ARRAY)) { BM_elem_flag_enable(v_iter, VERT_IN_ARRAY); - /* not nice, but alternatives arent much better :S */ + /* not nice, but alternatives aren't much better :S */ { copy_v3_v3(vert_coords_backup[v_index], v_iter->co); diff --git a/source/blender/bmesh/intern/bmesh_structure.h b/source/blender/bmesh/intern/bmesh_structure.h index 7ae55a5fa6f..38c75dec354 100644 --- a/source/blender/bmesh/intern/bmesh_structure.h +++ b/source/blender/bmesh/intern/bmesh_structure.h @@ -34,7 +34,7 @@ /* LOOP CYCLE MANAGEMENT */ bool bmesh_loop_validate(BMFace *f) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); -/* DISK CYCLE MANAGMENT */ +/* DISK CYCLE MANAGEMENT */ void bmesh_disk_edge_append(BMEdge *e, BMVert *v) ATTR_NONNULL(); void bmesh_disk_edge_remove(BMEdge *e, BMVert *v) ATTR_NONNULL(); BLI_INLINE BMEdge *bmesh_disk_edge_next_safe(const BMEdge *e, @@ -60,7 +60,7 @@ BMLoop *bmesh_disk_faceloop_find_first_visible(const BMEdge *e, BMEdge *bmesh_disk_faceedge_find_next(const BMEdge *e, const BMVert *v) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); -/* RADIAL CYCLE MANAGMENT */ +/* RADIAL CYCLE MANAGEMENT */ void bmesh_radial_loop_append(BMEdge *e, BMLoop *l) ATTR_NONNULL(); void bmesh_radial_loop_remove(BMEdge *e, BMLoop *l) ATTR_NONNULL(); void bmesh_radial_loop_unlink(BMLoop *l) ATTR_NONNULL(); diff --git a/source/blender/bmesh/intern/bmesh_walkers_impl.c b/source/blender/bmesh/intern/bmesh_walkers_impl.c index 20042e65287..ade6fdfcbed 100644 --- a/source/blender/bmesh/intern/bmesh_walkers_impl.c +++ b/source/blender/bmesh/intern/bmesh_walkers_impl.c @@ -805,7 +805,7 @@ static void *bmw_IslandWalker_step_ex(BMWalker *walker, bool only_manifold) continue; } - /* saves checking BLI_gset_haskey below (manifold edges theres a 50% chance) */ + /* saves checking BLI_gset_haskey below (manifold edges there's a 50% chance) */ if (f == iwalk->cur) { continue; } diff --git a/source/blender/bmesh/operators/bmo_bridge.c b/source/blender/bmesh/operators/bmo_bridge.c index 7ec73412373..5403043efb4 100644 --- a/source/blender/bmesh/operators/bmo_bridge.c +++ b/source/blender/bmesh/operators/bmo_bridge.c @@ -59,7 +59,7 @@ static void bm_bridge_splice_loops(BMesh *bm, /* get the 2 loops matching 2 verts. * first attempt to get the face corners that use the edge defined by v1 & v2, - * if that fails just get any loop thats on the vert (the first one) */ + * if that fails just get any loop that's on the vert (the first one) */ static void bm_vert_loop_pair(BMesh *bm, BMVert *v1, BMVert *v2, BMLoop **l1, BMLoop **l2) { BMEdge *e = BM_edge_exists(v1, v2); @@ -515,7 +515,7 @@ static void bridge_loop_pair(BMesh *bm, } BMO_op_exec(bm, &op_sub); - /* there may also be tagged faces that didnt rotate, mark input */ + /* there may also be tagged faces that didn't rotate, mark input */ if (use_edgeout) { BMOIter siter; diff --git a/source/blender/bmesh/operators/bmo_dupe.c b/source/blender/bmesh/operators/bmo_dupe.c index 6dd361d62b3..d9a7aa626e4 100644 --- a/source/blender/bmesh/operators/bmo_dupe.c +++ b/source/blender/bmesh/operators/bmo_dupe.c @@ -449,7 +449,7 @@ void bmo_split_exec(BMesh *bm, BMOperator *op) } } - /* connect outputs of dupe to delete, exluding keep geometry */ + /* connect outputs of dupe to delete, excluding keep geometry */ BMO_mesh_delete_oflag_context(bm, SPLIT_INPUT, DEL_FACES); /* now we make our outputs by copying the dupe output */ diff --git a/source/blender/bmesh/operators/bmo_edgenet.c b/source/blender/bmesh/operators/bmo_edgenet.c index 7ab8406a3ec..d38a1be7a8d 100644 --- a/source/blender/bmesh/operators/bmo_edgenet.c +++ b/source/blender/bmesh/operators/bmo_edgenet.c @@ -132,7 +132,7 @@ void bmo_edgenet_prepare_exec(BMesh *bm, BMOperator *op) } } - /* we don't have valid edge layouts, retur */ + /* we don't have valid edge layouts, return */ if (!ok) { return; } diff --git a/source/blender/bmesh/operators/bmo_inset.c b/source/blender/bmesh/operators/bmo_inset.c index 323bb5a7748..f23c420295b 100644 --- a/source/blender/bmesh/operators/bmo_inset.c +++ b/source/blender/bmesh/operators/bmo_inset.c @@ -549,7 +549,7 @@ void bmo_inset_region_exec(BMesh *bm, BMOperator *op) SplitEdgeInfo *es; /* Interpolation Vars */ - /* an array alligned with faces but only fill items which are used. */ + /* an array aligned with faces but only fill items which are used. */ InterpFace **iface_array = NULL; int iface_array_len; MemArena *interp_arena = NULL; diff --git a/source/blender/bmesh/operators/bmo_primitive.c b/source/blender/bmesh/operators/bmo_primitive.c index cf3d6b8bf56..287a7e93470 100644 --- a/source/blender/bmesh/operators/bmo_primitive.c +++ b/source/blender/bmesh/operators/bmo_primitive.c @@ -807,6 +807,7 @@ void BM_mesh_calc_uvs_grid(BMesh *bm, const float dx = 1.0f / (float)(x_segments - 1); const float dy = 1.0f / (float)(y_segments - 1); + const float dx_wrap = 1.0 - (dx / 2.0f); float x = 0.0f; float y = dy; @@ -844,7 +845,7 @@ void BM_mesh_calc_uvs_grid(BMesh *bm, } x += dx; - if (x >= 1.0f) { + if (x >= dx_wrap) { x = 0.0f; y += dy; } @@ -1091,7 +1092,7 @@ static void bm_mesh_calc_uvs_sphere_face(BMFace *f, const int cd_loop_uv_offset) float z = l->v->co[2]; float len = len_v3(l->v->co); - /* Use neigboring point to compute angle for poles. */ + /* Use neighboring point to compute angle for poles. */ float theta; if (f->len == 3 && fabsf(x) < 0.0001f && fabsf(y) < 0.0001f) { theta = atan2f(avgy, avgx); diff --git a/source/blender/bmesh/operators/bmo_subdivide.c b/source/blender/bmesh/operators/bmo_subdivide.c index 74635be4681..41f65dd6f5a 100644 --- a/source/blender/bmesh/operators/bmo_subdivide.c +++ b/source/blender/bmesh/operators/bmo_subdivide.c @@ -138,7 +138,7 @@ static BMEdge *connect_smallest_face(BMesh *bm, BMVert *v_a, BMVert *v_b, BMFace * multiple faces yet. that might require a convexity test to figure out which * face is "best" and who knows what for non-manifold conditions. * - * note: we allow adjacent here, since theres no chance this happens. + * note: we allow adjacent here, since there's no chance this happens. */ f = BM_vert_pair_share_face_by_len(v_a, v_b, &l_a, &l_b, true); diff --git a/source/blender/bmesh/operators/bmo_subdivide_edgering.c b/source/blender/bmesh/operators/bmo_subdivide_edgering.c index 6baf56f1723..cfbff105d70 100644 --- a/source/blender/bmesh/operators/bmo_subdivide_edgering.c +++ b/source/blender/bmesh/operators/bmo_subdivide_edgering.c @@ -1145,7 +1145,7 @@ void bmo_subdivide_edgering_exec(BMesh *bm, BMOperator *op) } else if (count == 2) { /* this case could be removed, - * but simple to avoid 'bm_edgering_pair_calc' in this case since theres only one. */ + * but simple to avoid 'bm_edgering_pair_calc' in this case since there's only one. */ struct BMEdgeLoopStore *el_store_a = eloops_rim.first; struct BMEdgeLoopStore *el_store_b = eloops_rim.last; LoopPairStore *lpair; diff --git a/source/blender/bmesh/tools/bmesh_bevel.c b/source/blender/bmesh/tools/bmesh_bevel.c index 90df3cd225e..94935f2090b 100644 --- a/source/blender/bmesh/tools/bmesh_bevel.c +++ b/source/blender/bmesh/tools/bmesh_bevel.c @@ -1357,7 +1357,7 @@ static void set_profile_params(BevelParams *bp, BevVert *bv, BoundVert *bndv) copy_v3_v3(pro->plane_co, co1); } else if (bndv->is_arc_start) { - /* assume pro->midco was alredy set */ + /* assume pro->midco was already set */ copy_v3_v3(pro->coa, co1); copy_v3_v3(pro->cob, co2); pro->super_r = PRO_CIRCLE_R; @@ -2295,7 +2295,7 @@ static void build_boundary_terminal_edge(BevelParams *bp, else { adjust_bound_vert(e->rightv, co); } - /* make artifical extra point along unbeveled edge, and form triangle */ + /* make artificial extra point along unbeveled edge, and form triangle */ slide_dist(e->next, bv->v, e->offset_l, co); if (construct) { v = add_new_bound_vert(mem_arena, vm, co); @@ -3837,7 +3837,7 @@ static VMesh *make_cube_corner_adj_vmesh(BevelParams *bp) /* Is this a good candidate for using tri_corner_adj_vmesh? */ static int tri_corner_test(BevelParams *bp, BevVert *bv) { - float ang, totang, angdiff; + float ang, absang, totang, angdiff; EdgeHalf *e; int i; int in_plane_e = 0; @@ -3852,10 +3852,11 @@ static int tri_corner_test(BevelParams *bp, BevVert *bv) for (i = 0; i < bv->edgecount; i++) { e = &bv->edges[i]; ang = BM_edge_calc_face_angle_signed_ex(e->e, 0.0f); - if (ang <= M_PI_4) { + absang = fabsf(ang); + if (absang <= M_PI_4) { in_plane_e++; } - else if (ang >= 3.0f * (float)M_PI_4) { + else if (absang >= 3.0f * (float)M_PI_4) { return -1; } totang += ang; @@ -3863,7 +3864,7 @@ static int tri_corner_test(BevelParams *bp, BevVert *bv) if (in_plane_e != bv->edgecount - 3) { return -1; } - angdiff = fabsf(totang - 3.0f * (float)M_PI_2); + angdiff = fabsf(fabsf(totang) - 3.0f * (float)M_PI_2); if ((bp->pro_super_r == PRO_SQUARE_R && angdiff > (float)M_PI / 16.0f) || (angdiff > (float)M_PI_4)) { return -1; diff --git a/source/blender/bmesh/tools/bmesh_decimate_collapse.c b/source/blender/bmesh/tools/bmesh_decimate_collapse.c index da525becc78..e32a9334343 100644 --- a/source/blender/bmesh/tools/bmesh_decimate_collapse.c +++ b/source/blender/bmesh/tools/bmesh_decimate_collapse.c @@ -698,7 +698,7 @@ static void bm_edge_collapse_loop_customdata( const bool is_manifold = BM_edge_is_manifold(l->e); int side; - /* first find the loop of 'v_other' thats attached to the face of 'l' */ + /* first find the loop of 'v_other' that's attached to the face of 'l' */ if (l->v == v_clear) { l_clear = l; l_other = l->next; @@ -882,7 +882,7 @@ static bool bm_edge_collapse_is_degenerate_topology(BMEdge *e_first) bm_edge_tag_enable(e_iter); } while ((e_iter = bmesh_disk_edge_next(e_iter, e_first->v1)) != e_first); - /* ... except for the edge we will collapse, we know thats shared, + /* ... except for the edge we will collapse, we know that's shared, * disable this to avoid false positive. We could be smart and never enable these * face/edge tags in the first place but easier to do this */ // bm_edge_tag_disable(e_first); diff --git a/source/blender/bmesh/tools/bmesh_path_region.c b/source/blender/bmesh/tools/bmesh_path_region.c index 8b139e6a5ff..841109a251f 100644 --- a/source/blender/bmesh/tools/bmesh_path_region.c +++ b/source/blender/bmesh/tools/bmesh_path_region.c @@ -224,7 +224,7 @@ static LinkNode *mesh_calc_path_region_elem(BMesh *bm, #endif /* USE_EDGE_CHAIN */ /* Keep walking over connected geometry until we find all the vertices in - * `ele_verts[side_other]`, or exit the loop when theres no connection. */ + * `ele_verts[side_other]`, or exit the loop when there's no connection. */ found_all = false; for (pass = 1; (STACK_SIZE(stack) != 0); pass++) { while (STACK_SIZE(stack) != 0) { @@ -268,7 +268,7 @@ static LinkNode *mesh_calc_path_region_elem(BMesh *bm, } while ((e = BM_DISK_EDGE_NEXT(e, v_a)) != v_a->e); } - /* Stop searching once theres none left. + /* Stop searching once there's none left. * Note that this looks in-efficient, however until the target elements reached, * it will exit immediately. * After that, it takes as many passes as the element has edges to finish off. */ diff --git a/source/blender/bmesh/tools/bmesh_region_match.c b/source/blender/bmesh/tools/bmesh_region_match.c index 8b9a9de3988..943f7532960 100644 --- a/source/blender/bmesh/tools/bmesh_region_match.c +++ b/source/blender/bmesh/tools/bmesh_region_match.c @@ -43,7 +43,7 @@ #include "bmesh.h" -#include "tools/bmesh_region_match.h" /* own incldue */ +#include "tools/bmesh_region_match.h" /* own include */ /* avoid re-creating ghash and pools for each search */ #define USE_WALKER_REUSE @@ -95,13 +95,13 @@ typedef struct UUIDWalk { BLI_mempool *step_pool; BLI_mempool *step_pool_items; - /* Optionaly use face-tag to isolate search */ + /* Optionally use face-tag to isolate search */ bool use_face_isolate; /* Increment for each pass added */ UUID_Int pass; - /* runtime vars, aviod re-creating each pass */ + /* runtime vars, avoid re-creating each pass */ struct { GHash *verts_uuid; /* BMVert -> UUID */ GSet *faces_step; /* BMFace */ diff --git a/source/blender/collada/AnimationImporter.cpp b/source/blender/collada/AnimationImporter.cpp index be748110fb9..3bdc11291d5 100644 --- a/source/blender/collada/AnimationImporter.cpp +++ b/source/blender/collada/AnimationImporter.cpp @@ -751,7 +751,7 @@ float AnimationImporter::convert_to_focal_length(float in_xfov, float aspect, float sensorx) { - /* NOTE: Needs more testing (As we curretnly have no official test data for this) */ + /* NOTE: Needs more testing (As we currently have no official test data for this) */ float xfov = (fov_type == CAMERA_YFOV) ? (2.0f * atanf(aspect * tanf(DEG2RADF(in_xfov) * 0.5f))) : DEG2RADF(in_xfov); diff --git a/source/blender/collada/DocumentImporter.cpp b/source/blender/collada/DocumentImporter.cpp index eabd9469582..98b166716c3 100644 --- a/source/blender/collada/DocumentImporter.cpp +++ b/source/blender/collada/DocumentImporter.cpp @@ -917,7 +917,7 @@ bool DocumentImporter::writeCamera(const COLLADAFW::Camera *camera) double yfov = camera->getYFov().getValue(); double aspect = camera->getAspectRatio().getValue(); - /* NOTE: Needs more testing (As we curretnly have no official test data for this) */ + /* NOTE: Needs more testing (As we currently have no official test data for this) */ double xfov = 2.0f * atanf(aspect * tanf(DEG2RADF(yfov) * 0.5f)); cam->lens = fov_to_focallength(xfov, cam->sensor_x); diff --git a/source/blender/collada/Materials.cpp b/source/blender/collada/Materials.cpp index e1d5b2e9d5c..3b2c68ef95e 100644 --- a/source/blender/collada/Materials.cpp +++ b/source/blender/collada/Materials.cpp @@ -196,7 +196,7 @@ void MaterialNode::set_alpha(COLLADAFW::EffectCommon::OpaqueMode mode, } float alpha = transparent_alpha * transparency_alpha; - if (mode == COLLADASW::EffectProfile::RGB_ZERO) { + if (mode == COLLADAFW::EffectCommon::RGB_ZERO) { alpha = 1 - alpha; } diff --git a/source/blender/collada/MeshImporter.cpp b/source/blender/collada/MeshImporter.cpp index 2ab6d12d96d..657cce24a82 100644 --- a/source/blender/collada/MeshImporter.cpp +++ b/source/blender/collada/MeshImporter.cpp @@ -695,7 +695,7 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh, Mesh *me) first_vertex, position_indices[1], position_indices[2]}; set_poly_indices(mpoly, mloop, loop_index, triangle_vertex_indices, 3); - if (mp_has_normals) { // vertex normals, same inplementation as for the triangles + if (mp_has_normals) { // vertex normals, same implementation as for the triangles // the same for vertces normals unsigned int vertex_normal_indices[3] = { first_normal, normal_indices[1], normal_indices[2]}; diff --git a/source/blender/compositor/operations/COM_BrightnessOperation.cpp b/source/blender/compositor/operations/COM_BrightnessOperation.cpp index 81df85daf28..d0bab5aa4d9 100644 --- a/source/blender/compositor/operations/COM_BrightnessOperation.cpp +++ b/source/blender/compositor/operations/COM_BrightnessOperation.cpp @@ -56,19 +56,19 @@ void BrightnessOperation::executePixelSampled(float output[4], float contrast = inputContrast[0]; brightness /= 100.0f; float delta = contrast / 200.0f; - a = 1.0f - delta * 2.0f; /* * The algorithm is by Werner D. Streidt * (http://visca.com/ffactory/archives/5-99/msg00021.html) * Extracted of OpenCV demhist.c */ if (contrast > 0) { - a = 1.0f / a; + a = 1.0f / (1.0f - delta * 2.0f); b = a * (brightness - delta); } else { delta *= -1; - b = a * (brightness + delta); + a = 1.0f - delta * 2.0f; + b = a * brightness + delta; } if (this->m_use_premultiply) { premul_to_straight_v4(inputValue); diff --git a/source/blender/datatoc/datatoc_icon_split.py b/source/blender/datatoc/datatoc_icon_split.py index 44fedca4398..e58dbb1a61f 100755 --- a/source/blender/datatoc/datatoc_icon_split.py +++ b/source/blender/datatoc/datatoc_icon_split.py @@ -268,7 +268,7 @@ def main(): parser.add_argument( "--name_style", dest="name_style", metavar='ENUM', type=str, choices=('', 'UI_ICONS'), - help="The metod used for naming output data", + help="The method used for naming output data", ) # Options for dicing up the image diff --git a/source/blender/depsgraph/CMakeLists.txt b/source/blender/depsgraph/CMakeLists.txt index c3099c9486d..49c510d9d3e 100644 --- a/source/blender/depsgraph/CMakeLists.txt +++ b/source/blender/depsgraph/CMakeLists.txt @@ -115,11 +115,4 @@ set(SRC set(LIB ) -if(WITH_BOOST) - list(APPEND INC_SYS - ${BOOST_INCLUDE_DIR} - ) - add_definitions(-DHAVE_BOOST_FUNCTION_BINDINGS) -endif() - blender_add_lib(bf_depsgraph "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") diff --git a/source/blender/depsgraph/intern/builder/deg_builder.cc b/source/blender/depsgraph/intern/builder/deg_builder.cc index 36c6d246097..4cbdd169980 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder.cc @@ -204,7 +204,7 @@ void deg_graph_build_finalize(Main *bmain, Depsgraph *graph) /* Re-tag IDs for update if it was tagged before the relations * update tag. */ for (IDNode *id_node : graph->id_nodes) { - ID *id = id_node->id_orig; + ID *id_orig = id_node->id_orig; id_node->finalize_build(graph); int flag = 0; /* Tag rebuild if special evaluation flags changed. */ @@ -219,10 +219,13 @@ void deg_graph_build_finalize(Main *bmain, Depsgraph *graph) flag |= ID_RECALC_COPY_ON_WRITE; /* This means ID is being added to the dependency graph first * time, which is similar to "ob-visible-change" */ - if (GS(id->name) == ID_OB) { + if (GS(id_orig->name) == ID_OB) { flag |= ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY; } } + /* Restore recalc flags from original ID, which could possibly contain recalc flags set by + * an operator and then were carried on by the undo system. */ + flag |= id_orig->recalc; if (flag != 0) { graph_id_tag_update(bmain, graph, id_node->id_orig, flag, DEG_UPDATE_SOURCE_RELATIONS); } diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc index fa6d7bc6028..986f65df3fc 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc @@ -623,7 +623,7 @@ void DepsgraphNodeBuilder::build_object(int base_index, is_parent_collection_visible_ = is_current_parent_collection_visible; add_operation_node(&object->id, NodeType::DUPLI, OperationCode::DUPLI); } - /* Syncronization back to original object. */ + /* Synchronization back to original object. */ add_operation_node(&object->id, NodeType::SYNCHRONIZATION, OperationCode::SYNCHRONIZE_TO_ORIGINAL, @@ -1557,7 +1557,7 @@ void DepsgraphNodeBuilder::build_movieclip(MovieClip *clip) add_operation_node(clip_id, NodeType::PARAMETERS, OperationCode::MOVIECLIP_EVAL, - function_bind(BKE_movieclip_eval_update, _1, clip_cow)); + function_bind(BKE_movieclip_eval_update, _1, bmain_, clip_cow)); add_operation_node(clip_id, NodeType::BATCH_CACHE, diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc index 86cbb330170..0e608bdf903 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc @@ -677,7 +677,7 @@ void DepsgraphRelationBuilder::build_object(Base *base, Object *object) } /* Point caches. */ build_object_pointcache(object); - /* Syncronization back to original object. */ + /* Synchronization back to original object. */ OperationKey synchronize_key( &object->id, NodeType::SYNCHRONIZATION, OperationCode::SYNCHRONIZE_TO_ORIGINAL); add_relation(final_transform_key, synchronize_key, "Synchronize to Original"); @@ -695,7 +695,7 @@ void DepsgraphRelationBuilder::build_object_flags(Base *base, Object *object) OperationKey object_flags_key( &object->id, NodeType::OBJECT_FROM_LAYER, OperationCode::OBJECT_BASE_FLAGS); add_relation(view_layer_done_key, object_flags_key, "Base flags flush"); - /* Syncronization back to original object. */ + /* Synchronization back to original object. */ OperationKey synchronize_key( &object->id, NodeType::SYNCHRONIZATION, OperationCode::SYNCHRONIZE_TO_ORIGINAL); add_relation(object_flags_key, synchronize_key, "Synchronize to Original"); @@ -1321,7 +1321,7 @@ void DepsgraphRelationBuilder::build_animdata_drivers(ID *id) void DepsgraphRelationBuilder::build_animation_images(ID *id) { - /* TODO: can we check for existance of node for performance? */ + /* TODO: can we check for existence of node for performance? */ if (BKE_image_user_id_has_animation(id)) { OperationKey image_animation_key(id, NodeType::ANIMATION, OperationCode::IMAGE_ANIMATION); TimeSourceKey time_src_key; @@ -1999,7 +1999,7 @@ void DepsgraphRelationBuilder::build_object_data_geometry(Object *object) } } } - /* Syncronization back to original object. */ + /* Synchronization back to original object. */ ComponentKey final_geometry_key(&object->id, NodeType::GEOMETRY); OperationKey synchronize_key( &object->id, NodeType::SYNCHRONIZATION, OperationCode::SYNCHRONIZE_TO_ORIGINAL); @@ -2536,7 +2536,7 @@ void DepsgraphRelationBuilder::build_copy_on_write_relations(IDNode *id_node) * copied by copy-on-write, and not preserved. PROBABLY it is better * to preserve that cache in copy-on-write, but for the time being * we allow flush to layer collections component which will ensure - * that cached array fo bases exists and is up-to-date. */ + * that cached array of bases exists and is up-to-date. */ if (comp_node->type == NodeType::PARAMETERS || comp_node->type == NodeType::LAYER_COLLECTIONS) { rel_flag &= ~RELATION_FLAG_NO_FLUSH; diff --git a/source/blender/depsgraph/intern/builder/deg_builder_rna.cc b/source/blender/depsgraph/intern/builder/deg_builder_rna.cc index 5bb3ebf40c4..be494104522 100644 --- a/source/blender/depsgraph/intern/builder/deg_builder_rna.cc +++ b/source/blender/depsgraph/intern/builder/deg_builder_rna.cc @@ -279,7 +279,8 @@ RNANodeIdentifier RNANodeQuery::construct_node_identifier(const PointerRNA *ptr, } else if (RNA_struct_is_a(ptr->type, &RNA_Mesh) || RNA_struct_is_a(ptr->type, &RNA_Modifier) || RNA_struct_is_a(ptr->type, &RNA_GpencilModifier) || - RNA_struct_is_a(ptr->type, &RNA_Spline) || RNA_struct_is_a(ptr->type, &RNA_TextBox)) { + RNA_struct_is_a(ptr->type, &RNA_Spline) || RNA_struct_is_a(ptr->type, &RNA_TextBox) || + RNA_struct_is_a(ptr->type, &RNA_GPencilLayer)) { /* When modifier is used as FROM operation this is likely referencing to * the property (for example, modifier's influence). * But when it's used as TO operation, this is geometry component. */ diff --git a/source/blender/depsgraph/intern/depsgraph.cc b/source/blender/depsgraph/intern/depsgraph.cc index d8a9b41206b..6d3aed65a14 100644 --- a/source/blender/depsgraph/intern/depsgraph.cc +++ b/source/blender/depsgraph/intern/depsgraph.cc @@ -68,6 +68,7 @@ template<typename T> static void remove_from_vector(vector<T> *vector, const T & Depsgraph::Depsgraph(Scene *scene, ViewLayer *view_layer, eEvaluationMode mode) : time_source(NULL), need_update(true), + need_update_time(false), scene(scene), view_layer(view_layer), mode(mode), diff --git a/source/blender/depsgraph/intern/depsgraph.h b/source/blender/depsgraph/intern/depsgraph.h index f194a44346b..15ce57cb169 100644 --- a/source/blender/depsgraph/intern/depsgraph.h +++ b/source/blender/depsgraph/intern/depsgraph.h @@ -73,7 +73,7 @@ enum RelationFlag { RELATION_FLAG_FLUSH_USER_EDIT_ONLY = (1 << 2), /* The relation can not be killed by the cyclic dependencies solver. */ RELATION_FLAG_GODMODE = (1 << 4), - /* Relation will check existance before being added. */ + /* Relation will check existence before being added. */ RELATION_CHECK_BEFORE_ADD = (1 << 5), }; @@ -160,6 +160,10 @@ struct Depsgraph { /* Nodes which have been tagged as "directly modified". */ GSet *entry_tags; + /* Special entry tag for time source. Allows to tag invisible dependency graphs for update when + * scene frame changes, so then when dependency graph becomes visible it is on a proper state. */ + bool need_update_time; + /* Convenience Data ................... */ /* XXX: should be collected after building (if actually needed?) */ diff --git a/source/blender/depsgraph/intern/depsgraph_eval.cc b/source/blender/depsgraph/intern/depsgraph_eval.cc index 6f3262174b4..55241d03e94 100644 --- a/source/blender/depsgraph/intern/depsgraph_eval.cc +++ b/source/blender/depsgraph/intern/depsgraph_eval.cc @@ -61,6 +61,7 @@ void DEG_evaluate_on_refresh(Depsgraph *graph) BKE_scene_frame_set(deg_graph->scene_cow, deg_graph->ctime); } DEG::deg_evaluate_on_refresh(deg_graph); + deg_graph->need_update_time = false; } /* Frame-change happened for root scene that graph belongs to. */ @@ -79,10 +80,11 @@ void DEG_evaluate_on_framechange(Main *bmain, Depsgraph *graph, float ctime) } /* Perform recalculation updates. */ DEG::deg_evaluate_on_refresh(deg_graph); + deg_graph->need_update_time = false; } bool DEG_needs_eval(Depsgraph *graph) { DEG::Depsgraph *deg_graph = reinterpret_cast<DEG::Depsgraph *>(graph); - return BLI_gset_len(deg_graph->entry_tags) != 0; + return BLI_gset_len(deg_graph->entry_tags) != 0 || deg_graph->need_update_time; } diff --git a/source/blender/depsgraph/intern/depsgraph_tag.cc b/source/blender/depsgraph/intern/depsgraph_tag.cc index 583191490d2..392514990e3 100644 --- a/source/blender/depsgraph/intern/depsgraph_tag.cc +++ b/source/blender/depsgraph/intern/depsgraph_tag.cc @@ -229,6 +229,12 @@ void depsgraph_tag_to_component_opcode(const ID *id, case ID_RECALC_PARAMETERS: *component_type = NodeType::PARAMETERS; break; + case ID_RECALC_SOURCE: + *component_type = NodeType::PARAMETERS; + break; + case ID_RECALC_TIME: + BLI_assert(!"Should be handled outside of this function"); + break; case ID_RECALC_ALL: case ID_RECALC_PSYS_ALL: BLI_assert(!"Should not happen"); @@ -319,25 +325,31 @@ void deg_graph_id_tag_legacy_compat( * tagging here. */ case ID_ME: { Mesh *mesh = (Mesh *)id; - ID *key_id = &mesh->key->id; - if (key_id != NULL) { - graph_id_tag_update(bmain, depsgraph, key_id, 0, update_source); + if (mesh->key != NULL) { + ID *key_id = &mesh->key->id; + if (key_id != NULL) { + graph_id_tag_update(bmain, depsgraph, key_id, 0, update_source); + } } break; } case ID_LT: { Lattice *lattice = (Lattice *)id; - ID *key_id = &lattice->key->id; - if (key_id != NULL) { - graph_id_tag_update(bmain, depsgraph, key_id, 0, update_source); + if (lattice->key != NULL) { + ID *key_id = &lattice->key->id; + if (key_id != NULL) { + graph_id_tag_update(bmain, depsgraph, key_id, 0, update_source); + } } break; } case ID_CU: { Curve *curve = (Curve *)id; - ID *key_id = &curve->key->id; - if (key_id != NULL) { - graph_id_tag_update(bmain, depsgraph, key_id, 0, update_source); + if (curve->key != NULL) { + ID *key_id = &curve->key->id; + if (key_id != NULL) { + graph_id_tag_update(bmain, depsgraph, key_id, 0, update_source); + } } break; } @@ -360,6 +372,12 @@ static void graph_id_tag_update_single_flag(Main *bmain, } return; } + else if (tag == ID_RECALC_TIME) { + if (graph != NULL) { + graph->need_update_time = true; + } + return; + } /* Get description of what is to be tagged. */ NodeType component_type; OperationCode operation_code; @@ -438,6 +456,24 @@ const char *update_source_as_string(eUpdateSource source) return "UNKNOWN"; } +int deg_recalc_flags_for_legacy_zero() +{ + return ID_RECALC_ALL & ~(ID_RECALC_PSYS_ALL | ID_RECALC_ANIMATION | ID_RECALC_SOURCE); +} + +int deg_recalc_flags_effective(Depsgraph *graph, int flags) +{ + if (graph != NULL) { + if (!graph->is_active) { + return 0; + } + } + if (flags == 0) { + return deg_recalc_flags_for_legacy_zero(); + } + return flags; +} + /* Special tag function which tags all components which needs to be tagged * for update flag=0. * @@ -453,7 +489,7 @@ void deg_graph_node_tag_zero(Main *bmain, } ID *id = id_node->id_orig; /* TODO(sergey): Which recalc flags to set here? */ - id_node->id_cow->recalc |= ID_RECALC_ALL & ~(ID_RECALC_PSYS_ALL | ID_RECALC_ANIMATION); + id_node->id_cow->recalc |= deg_recalc_flags_for_legacy_zero(); GHASH_FOREACH_BEGIN (ComponentNode *, comp_node, id_node->components) { if (comp_node->type == NodeType::ANIMATION) { continue; @@ -598,6 +634,16 @@ void graph_id_tag_update( if (id_node != NULL) { id_node->id_cow->recalc |= flag; } + /* When ID is tagged for update based on an user edits store the recalc flags in the original ID. + * This way IDs in the undo steps will have this flag preserved, making it possible to restore + * all needed tags when new dependency graph is created on redo. + * This is the only way to ensure modifications to animation data (such as keyframes i.e.) + * properly triggers animation update for the newely constructed dependency graph on redo (while + * usually newly created dependency graph skips animation update to avoid loss of unkeyed + * changes). */ + if (update_source == DEG_UPDATE_SOURCE_USER_EDIT) { + id->recalc |= deg_recalc_flags_effective(graph, flag); + } int current_flag = flag; while (current_flag != 0) { IDRecalcFlag tag = (IDRecalcFlag)(1 << bitscan_forward_clear_i(¤t_flag)); @@ -664,6 +710,10 @@ const char *DEG_update_tag_as_string(IDRecalcFlag flag) return "AUDIO"; case ID_RECALC_PARAMETERS: return "PARAMETERS"; + case ID_RECALC_TIME: + return "TIME"; + case ID_RECALC_SOURCE: + return "SOURCE"; case ID_RECALC_ALL: return "ALL"; } @@ -768,9 +818,19 @@ void DEG_ids_check_recalc( DEG::deg_editors_scene_update(&update_ctx, updated); } +static void deg_graph_clear_id_recalc_flags(ID *id) +{ + id->recalc &= ~ID_RECALC_ALL; + bNodeTree *ntree = ntreeFromID(id); + /* Clear embedded node trees too. */ + if (ntree) { + ntree->id.recalc &= ~ID_RECALC_ALL; + } +} + static void deg_graph_clear_id_node_func(void *__restrict data_v, const int i, - const ParallelRangeTLS *__restrict /*tls*/) + const TaskParallelTLS *__restrict /*tls*/) { /* TODO: we clear original ID recalc flags here, but this may not work * correctly when there are multiple depsgraph with others still using @@ -779,12 +839,10 @@ static void deg_graph_clear_id_node_func(void *__restrict data_v, DEG::IDNode *id_node = deg_graph->id_nodes[i]; id_node->is_user_modified = false; - id_node->id_cow->recalc &= ~ID_RECALC_ALL; - /* Clear embedded node trees too. */ - bNodeTree *ntree_cow = ntreeFromID(id_node->id_cow); - if (ntree_cow) { - ntree_cow->id.recalc &= ~ID_RECALC_ALL; + deg_graph_clear_id_recalc_flags(id_node->id_cow); + if (deg_graph->is_active) { + deg_graph_clear_id_recalc_flags(id_node->id_orig); } } @@ -798,7 +856,7 @@ void DEG_ids_clear_recalc(Main *UNUSED(bmain), Depsgraph *depsgraph) } /* Go over all ID nodes nodes, clearing tags. */ const int num_id_nodes = deg_graph->id_nodes.size(); - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.min_iter_per_thread = 1024; BLI_task_parallel_range(0, num_id_nodes, deg_graph, deg_graph_clear_id_node_func, &settings); diff --git a/source/blender/depsgraph/intern/eval/deg_eval.cc b/source/blender/depsgraph/intern/eval/deg_eval.cc index 950deee2b07..b2415c9e89d 100644 --- a/source/blender/depsgraph/intern/eval/deg_eval.cc +++ b/source/blender/depsgraph/intern/eval/deg_eval.cc @@ -108,7 +108,7 @@ static bool check_operation_node_visible(OperationNode *op_node) static void calculate_pending_func(void *__restrict data_v, const int i, - const ParallelRangeTLS *__restrict /*tls*/) + const TaskParallelTLS *__restrict /*tls*/) { CalculatePendingData *data = (CalculatePendingData *)data_v; Depsgraph *graph = data->graph; @@ -148,7 +148,7 @@ static void calculate_pending_parents(Depsgraph *graph) const int num_operations = graph->operations.size(); CalculatePendingData data; data.graph = graph; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.min_iter_per_thread = 1024; BLI_task_parallel_range(0, num_operations, &data, calculate_pending_func, &settings); diff --git a/source/blender/depsgraph/intern/eval/deg_eval_flush.cc b/source/blender/depsgraph/intern/eval/deg_eval_flush.cc index 83fcf4c6ea1..2479373b687 100644 --- a/source/blender/depsgraph/intern/eval/deg_eval_flush.cc +++ b/source/blender/depsgraph/intern/eval/deg_eval_flush.cc @@ -29,16 +29,18 @@ #include <deque> #include <cmath> -#include "BKE_object.h" - #include "BLI_utildefines.h" #include "BLI_listbase.h" #include "BLI_math_vector.h" #include "BLI_task.h" #include "BLI_ghash.h" +#include "BKE_object.h" +#include "BKE_scene.h" + extern "C" { #include "DNA_object_types.h" +#include "DNA_scene_types.h" #include "DRW_engine.h" } /* extern "C" */ @@ -53,6 +55,7 @@ extern "C" { #include "intern/node/deg_node_factory.h" #include "intern/node/deg_node_id.h" #include "intern/node/deg_node_operation.h" +#include "intern/node/deg_node_time.h" #include "intern/eval/deg_eval_copy_on_write.h" @@ -86,7 +89,7 @@ namespace { void flush_init_operation_node_func(void *__restrict data_v, const int i, - const ParallelRangeTLS *__restrict /*tls*/) + const TaskParallelTLS *__restrict /*tls*/) { Depsgraph *graph = (Depsgraph *)data_v; OperationNode *node = graph->operations[i]; @@ -95,7 +98,7 @@ void flush_init_operation_node_func(void *__restrict data_v, void flush_init_id_node_func(void *__restrict data_v, const int i, - const ParallelRangeTLS *__restrict /*tls*/) + const TaskParallelTLS *__restrict /*tls*/) { Depsgraph *graph = (Depsgraph *)data_v; IDNode *id_node = graph->id_nodes[i]; @@ -109,14 +112,14 @@ BLI_INLINE void flush_prepare(Depsgraph *graph) { { const int num_operations = graph->operations.size(); - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.min_iter_per_thread = 1024; BLI_task_parallel_range(0, num_operations, graph, flush_init_operation_node_func, &settings); } { const int num_id_nodes = graph->id_nodes.size(); - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.min_iter_per_thread = 1024; BLI_task_parallel_range(0, num_id_nodes, graph, flush_init_id_node_func, &settings); @@ -348,9 +351,16 @@ void deg_graph_flush_updates(Main *bmain, Depsgraph *graph) BLI_assert(bmain != NULL); BLI_assert(graph != NULL); /* Nothing to update, early out. */ - if (BLI_gset_len(graph->entry_tags) == 0) { + if (BLI_gset_len(graph->entry_tags) == 0 && !graph->need_update_time) { return; } + if (graph->need_update_time) { + const Scene *scene_orig = graph->scene; + const float ctime = BKE_scene_frame_get(scene_orig); + DEG::TimeSourceNode *time_source = graph->find_time_source(); + graph->ctime = ctime; + time_source->tag_update(graph, DEG::DEG_UPDATE_SOURCE_TIME); + } /* Reset all flags, get ready for the flush. */ flush_prepare(graph); /* Starting from the tagged "entry" nodes, flush outwards. */ @@ -387,7 +397,7 @@ void deg_graph_flush_updates(Main *bmain, Depsgraph *graph) static void graph_clear_operation_func(void *__restrict data_v, const int i, - const ParallelRangeTLS *__restrict /*tls*/) + const TaskParallelTLS *__restrict /*tls*/) { Depsgraph *graph = (Depsgraph *)data_v; OperationNode *node = graph->operations[i]; @@ -402,7 +412,7 @@ void deg_graph_clear_tags(Depsgraph *graph) /* Go over all operation nodes, clearing tags. */ { const int num_operations = graph->operations.size(); - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.min_iter_per_thread = 1024; BLI_task_parallel_range(0, num_operations, graph, graph_clear_operation_func, &settings); diff --git a/source/blender/depsgraph/intern/node/deg_node_id.cc b/source/blender/depsgraph/intern/node/deg_node_id.cc index 8dd01050753..e14513a1aa2 100644 --- a/source/blender/depsgraph/intern/node/deg_node_id.cc +++ b/source/blender/depsgraph/intern/node/deg_node_id.cc @@ -58,7 +58,7 @@ const char *linkedStateAsString(eDepsNode_LinkedState_Type linked_state) return "DIRECTLY"; } BLI_assert(!"Unhandled linked state, should never happen."); - return "UNKNOW"; + return "UNKNOWN"; } IDNode::ComponentIDKey::ComponentIDKey(NodeType type, const char *name) : type(type), name(name) diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt index 9c81db7670f..3129b9e23d6 100644 --- a/source/blender/draw/CMakeLists.txt +++ b/source/blender/draw/CMakeLists.txt @@ -126,6 +126,8 @@ set(SRC engines/gpencil/gpencil_engine.h engines/gpencil/gpencil_render.c engines/gpencil/gpencil_shader_fx.c + engines/select/select_engine.c + engines/select/select_draw_utils.c DRW_engine.h intern/DRW_render.h @@ -150,6 +152,8 @@ set(SRC engines/external/external_engine.h engines/workbench/workbench_engine.h engines/workbench/workbench_private.h + engines/select/select_engine.h + engines/select/select_private.h ) set(LIB @@ -364,6 +368,9 @@ data_to_c_simple(engines/gpencil/shaders/fx/gpencil_fx_shadow_resolve_frag.glsl data_to_c_simple(engines/gpencil/shaders/fx/gpencil_fx_swirl_frag.glsl SRC) data_to_c_simple(engines/gpencil/shaders/fx/gpencil_fx_wave_frag.glsl SRC) +data_to_c_simple(engines/select/shaders/selection_id_3D_vert.glsl SRC) +data_to_c_simple(engines/select/shaders/selection_id_frag.glsl SRC) + list(APPEND INC ) diff --git a/source/blender/draw/DRW_engine.h b/source/blender/draw/DRW_engine.h index 5919e100ddd..491717d0137 100644 --- a/source/blender/draw/DRW_engine.h +++ b/source/blender/draw/DRW_engine.h @@ -26,6 +26,7 @@ #include "BLI_sys_types.h" /* for bool */ struct ARegion; +struct Base; struct DRWInstanceDataList; struct DRWPass; struct Depsgraph; @@ -128,7 +129,8 @@ void DRW_draw_select_loop(struct Depsgraph *depsgraph, void DRW_draw_depth_loop(struct Depsgraph *depsgraph, struct ARegion *ar, struct View3D *v3d, - struct GPUViewport *viewport); + struct GPUViewport *viewport, + bool use_opengl_context); void DRW_draw_depth_loop_gpencil(struct Depsgraph *depsgraph, struct ARegion *ar, struct View3D *v3d, @@ -136,19 +138,12 @@ void DRW_draw_depth_loop_gpencil(struct Depsgraph *depsgraph, void DRW_draw_depth_object(struct ARegion *ar, struct GPUViewport *viewport, struct Object *object); -void DRW_draw_select_id_object(struct Scene *scene, - struct RegionView3D *rv3d, - struct Object *ob, - short select_mode, - bool draw_facedot, - uint initial_offset, - uint *r_vert_offset, - uint *r_edge_offset, - uint *r_face_offset); - -void DRW_framebuffer_select_id_setup(struct ARegion *ar, const bool clear); -void DRW_framebuffer_select_id_release(struct ARegion *ar); -void DRW_framebuffer_select_id_read(const struct rcti *rect, uint *r_buf); +void DRW_draw_select_id(struct Depsgraph *depsgraph, + struct ARegion *ar, + struct View3D *v3d, + struct Base **bases, + const uint bases_len, + short select_mode); /* grease pencil render */ bool DRW_render_check_grease_pencil(struct Depsgraph *depsgraph); @@ -181,4 +176,19 @@ void DRW_deferred_shader_remove(struct GPUMaterial *mat); struct DrawDataList *DRW_drawdatalist_from_id(struct ID *id); void DRW_drawdata_free(struct ID *id); +/* select_engine.c */ +void DRW_select_context_create(struct Base **bases, + const uint bases_len, + short select_mode); +bool DRW_select_elem_get(const uint sel_id, uint *r_elem, uint *r_base_index, char *r_elem_type); +uint DRW_select_context_offset_for_object_elem(const uint base_index, char elem_type); +uint DRW_select_context_elem_len(void); +void DRW_framebuffer_select_id_read(const struct rcti *rect, uint *r_buf); +void DRW_draw_select_id_object(struct Depsgraph *depsgraph, + struct ViewLayer *view_layer, + struct ARegion *ar, + struct View3D *v3d, + struct Object *ob, + short select_mode); + #endif /* __DRW_ENGINE_H__ */ diff --git a/source/blender/draw/engines/eevee/eevee_effects.c b/source/blender/draw/engines/eevee/eevee_effects.c index 1b152afa3bf..93521c71127 100644 --- a/source/blender/draw/engines/eevee/eevee_effects.c +++ b/source/blender/draw/engines/eevee/eevee_effects.c @@ -47,7 +47,7 @@ static struct { struct GPUShader *downsample_sh; struct GPUShader *downsample_cube_sh; - /* Theses are just references, not actually allocated */ + /* These are just references, not actually allocated */ struct GPUTexture *depth_src; struct GPUTexture *color_src; diff --git a/source/blender/draw/engines/eevee/eevee_lightcache.c b/source/blender/draw/engines/eevee/eevee_lightcache.c index 3977fd160fc..c82a112b343 100644 --- a/source/blender/draw/engines/eevee/eevee_lightcache.c +++ b/source/blender/draw/engines/eevee/eevee_lightcache.c @@ -266,7 +266,8 @@ static bool EEVEE_lightcache_validate(const LightCache *light_cache, (irr_size[2] == light_cache->grid_tx.tex_size[2]) && (grid_len == light_cache->grid_len)) { int mip_len = (int)(floorf(log2f(cube_res)) - MIN_CUBE_LOD_LEVEL); if ((cube_res == light_cache->cube_tx.tex_size[0]) && - (cube_len == light_cache->cube_tx.tex_size[2]) && (mip_len == light_cache->mips_len)) { + (cube_len == light_cache->cube_tx.tex_size[2]) && (cube_len == light_cache->cube_len) && + (mip_len == light_cache->mips_len)) { return true; } } diff --git a/source/blender/draw/engines/eevee/eevee_lightprobes.c b/source/blender/draw/engines/eevee/eevee_lightprobes.c index 5341661735f..2026b44fe87 100644 --- a/source/blender/draw/engines/eevee/eevee_lightprobes.c +++ b/source/blender/draw/engines/eevee/eevee_lightprobes.c @@ -1275,7 +1275,7 @@ void EEVEE_lightprobes_refresh_planar(EEVEE_ViewLayerData *sldata, EEVEE_Data *v /* Rendering happens here! */ eevee_lightbake_render_scene_to_planars(sldata, vedata); - /* Make sure no aditionnal visibility check runs after this. */ + /* Make sure no additional visibility check runs after this. */ pinfo->vis_data.collection = NULL; DRW_uniformbuffer_update(sldata->planar_ubo, &sldata->probes->planar_data); diff --git a/source/blender/draw/engines/eevee/eevee_lights.c b/source/blender/draw/engines/eevee/eevee_lights.c index f6e8cefd165..d23287264b3 100644 --- a/source/blender/draw/engines/eevee/eevee_lights.c +++ b/source/blender/draw/engines/eevee/eevee_lights.c @@ -1347,7 +1347,7 @@ void EEVEE_draw_shadows(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata, DRWView int saved_ray_type = sldata->common_data.ray_type; - /* TODO: make it optionnal if we don't draw shadows. */ + /* TODO: make it optional if we don't draw shadows. */ sldata->common_data.ray_type = EEVEE_RAY_SHADOW; DRW_uniformbuffer_update(sldata->common_ubo, &sldata->common_data); diff --git a/source/blender/draw/engines/eevee/eevee_motion_blur.c b/source/blender/draw/engines/eevee/eevee_motion_blur.c index abd5bb82815..670201555bd 100644 --- a/source/blender/draw/engines/eevee/eevee_motion_blur.c +++ b/source/blender/draw/engines/eevee/eevee_motion_blur.c @@ -74,7 +74,7 @@ static void eevee_motion_blur_camera_get_matrix_at_time(Scene *scene, /* FIXME : This is a temporal solution that does not take care of parent animations */ /* Recalc Anim manually */ BKE_animsys_evaluate_animdata( - draw_ctx->depsgraph, scene, &camdata_cpy.id, camdata_cpy.adt, time, ADT_RECALC_ALL); + scene, &camdata_cpy.id, camdata_cpy.adt, time, ADT_RECALC_ALL, false); BKE_object_where_is_calc_time(draw_ctx->depsgraph, scene, &cam_cpy, time); /* Compute winmat */ diff --git a/source/blender/draw/engines/eevee/eevee_private.h b/source/blender/draw/engines/eevee/eevee_private.h index bd08a61e3b8..8aeddc72316 100644 --- a/source/blender/draw/engines/eevee/eevee_private.h +++ b/source/blender/draw/engines/eevee/eevee_private.h @@ -633,7 +633,7 @@ typedef struct EEVEE_EffectsInfo { struct GPUTexture *source_buffer; /* latest updated texture */ struct GPUFrameBuffer *target_buffer; /* next target to render to */ struct GPUTexture *final_tx; /* Final color to transform to display color space. */ - struct GPUFrameBuffer *final_fb; /* Framebuffer with final_tx as attachement. */ + struct GPUFrameBuffer *final_fb; /* Framebuffer with final_tx as attachment. */ } EEVEE_EffectsInfo; /* ***************** COMMON DATA **************** */ @@ -761,8 +761,8 @@ typedef struct EEVEE_ShadowCascadeData { float radius[MAX_CASCADE_NUM]; } EEVEE_ShadowCascadeData; -/* Theses are the structs stored inside Objects. - * It works with even if the object is in multiple layers +/* These are the structs stored inside Objects. + * It works even if the object is in multiple layers * because we don't get the same "Object *" for each layer. */ typedef struct EEVEE_LightEngineData { DrawData dd; diff --git a/source/blender/draw/engines/eevee/eevee_render.c b/source/blender/draw/engines/eevee/eevee_render.c index 286bcd8f738..ebd13ef1cf5 100644 --- a/source/blender/draw/engines/eevee/eevee_render.c +++ b/source/blender/draw/engines/eevee/eevee_render.c @@ -91,7 +91,7 @@ void EEVEE_render_init(EEVEE_Data *ved, RenderEngine *engine, struct Depsgraph * copy_v4_fl4(camtexcofac, 1.0f, 1.0f, 0.0f, 0.0f); } - /* XXX overiding viewport size. Simplify things but is not really 100% safe. */ + /* XXX overriding viewport size. Simplify things but is not really 100% safe. */ DRW_render_viewport_size_set((int[2]){size_orig[0] + g_data->overscan_pixels * 2.0f, size_orig[1] + g_data->overscan_pixels * 2.0f}); diff --git a/source/blender/draw/engines/eevee/eevee_screen_raytrace.c b/source/blender/draw/engines/eevee/eevee_screen_raytrace.c index d53ed239f4e..3d1b64422a4 100644 --- a/source/blender/draw/engines/eevee/eevee_screen_raytrace.c +++ b/source/blender/draw/engines/eevee/eevee_screen_raytrace.c @@ -44,7 +44,7 @@ static struct { /* Screen Space Reflection */ struct GPUShader *ssr_sh[SSR_MAX_SHADER]; - /* Theses are just references, not actually allocated */ + /* These are just references, not actually allocated */ struct GPUTexture *depth_src; struct GPUTexture *color_src; } e_data = {{NULL}}; /* Engine data */ diff --git a/source/blender/draw/engines/eevee/eevee_volumes.c b/source/blender/draw/engines/eevee/eevee_volumes.c index f85c30044a9..7fb5c25ffc6 100644 --- a/source/blender/draw/engines/eevee/eevee_volumes.c +++ b/source/blender/draw/engines/eevee/eevee_volumes.c @@ -554,7 +554,7 @@ void EEVEE_volumes_draw_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata) /* Final integration: We compute for each froxel the * amount of scattered light and extinction coef at this - * given depth. We use theses textures as double buffer + * given depth. We use these textures as double buffer * for the volumetric history. */ txl->volume_scatter_history = DRW_texture_create_3d( tex_size[0], tex_size[1], tex_size[2], GPU_R11F_G11F_B10F, DRW_TEX_FILTER, NULL); diff --git a/source/blender/draw/engines/eevee/shaders/effect_dof_frag.glsl b/source/blender/draw/engines/eevee/shaders/effect_dof_frag.glsl index d8cec17af58..ca4940ceffb 100644 --- a/source/blender/draw/engines/eevee/shaders/effect_dof_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/effect_dof_frag.glsl @@ -121,7 +121,7 @@ void main(void) /* Circle Dof */ float dist = length(particlecoord); - /* Ouside of bokeh shape */ + /* Outside of bokeh shape */ if (dist > 1.0) { discard; } @@ -141,7 +141,7 @@ void main(void) * Giving us the new linear radius to the shape edge. */ dist /= r; - /* Ouside of bokeh shape */ + /* Outside of bokeh shape */ if (dist > 1.0) { discard; } diff --git a/source/blender/draw/engines/eevee/shaders/effect_temporal_aa.glsl b/source/blender/draw/engines/eevee/shaders/effect_temporal_aa.glsl index ac6751fb5fb..428318e3c68 100644 --- a/source/blender/draw/engines/eevee/shaders/effect_temporal_aa.glsl +++ b/source/blender/draw/engines/eevee/shaders/effect_temporal_aa.glsl @@ -96,7 +96,7 @@ void main() FragColor = safe_color(color_history); /* There is some ghost issue if we use the alpha - * in the viewport. Overwritting alpha fixes it. */ + * in the viewport. Overwriting alpha fixes it. */ FragColor.a = color.a; } diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_lib.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_lib.glsl index a70ac686efd..56c05e3c036 100644 --- a/source/blender/draw/engines/eevee/shaders/lightprobe_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/lightprobe_lib.glsl @@ -261,7 +261,7 @@ vec3 probe_evaluate_grid(GridData gd, vec3 W, vec3 N, vec3 localpos) float weight_accum = 0.0; vec3 irradiance_accum = vec3(0.0); - /* For each neighboor cells */ + /* For each neighbor cells */ for (int i = 0; i < 8; ++i) { ivec3 offset = ivec3(i, i >> 1, i >> 2) & ivec3(1); vec3 cell_cos = clamp(localpos_floored + vec3(offset), vec3(0.0), vec3(gd.g_resolution) - 1.0); diff --git a/source/blender/draw/engines/eevee/shaders/raytrace_lib.glsl b/source/blender/draw/engines/eevee/shaders/raytrace_lib.glsl index 82581f2327b..14e0c947b47 100644 --- a/source/blender/draw/engines/eevee/shaders/raytrace_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/raytrace_lib.glsl @@ -83,8 +83,8 @@ void prepare_raycast(vec3 ray_origin, ss_start.w = project_point(ProjectionMatrix, ray_origin).z; ss_end.w = project_point(ProjectionMatrix, ray_end).z; - /* XXX This is a hack a better method is welcome ! */ - /* We take the delta between the offseted depth and the depth and substract it from the ray + /* XXX This is a hack. A better method is welcome! */ + /* We take the delta between the offsetted depth and the depth and subtract it from the ray * depth. This will change the world space thickness appearance a bit but we can have negative * values without worries. We cannot do this in viewspace because of the perspective division. */ ss_start.w = 2.0 * ss_start.z - ss_start.w; diff --git a/source/blender/draw/engines/eevee/shaders/shadow_copy_frag.glsl b/source/blender/draw/engines/eevee/shaders/shadow_copy_frag.glsl index 54f7dc10222..5646c257562 100644 --- a/source/blender/draw/engines/eevee/shaders/shadow_copy_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/shadow_copy_frag.glsl @@ -3,7 +3,7 @@ layout(std140) uniform shadow_render_block { - /* Use vectors to avoid alignement padding. */ + /* Use vectors to avoid alignment padding. */ ivec4 shadowSampleCount; vec4 shadowInvSampleCount; vec4 filterSize; diff --git a/source/blender/draw/engines/eevee/shaders/shadow_process_geom.glsl b/source/blender/draw/engines/eevee/shaders/shadow_process_geom.glsl index 131cecd5db6..591666560c4 100644 --- a/source/blender/draw/engines/eevee/shaders/shadow_process_geom.glsl +++ b/source/blender/draw/engines/eevee/shaders/shadow_process_geom.glsl @@ -4,7 +4,7 @@ layout(triangle_strip, max_vertices = 3) out; layout(std140) uniform shadow_render_block { - /* Use vectors to avoid alignement padding. */ + /* Use vectors to avoid alignment padding. */ ivec4 shadowSampleCount; vec4 shadowInvSampleCount; vec4 filterSize; diff --git a/source/blender/draw/engines/eevee/shaders/shadow_process_vert.glsl b/source/blender/draw/engines/eevee/shaders/shadow_process_vert.glsl index 01e0db97482..95e6a48b81f 100644 --- a/source/blender/draw/engines/eevee/shaders/shadow_process_vert.glsl +++ b/source/blender/draw/engines/eevee/shaders/shadow_process_vert.glsl @@ -1,7 +1,7 @@ layout(std140) uniform shadow_render_block { - /* Use vectors to avoid alignement padding. */ + /* Use vectors to avoid alignment padding. */ ivec4 shadowSampleCount; vec4 shadowInvSampleCount; vec4 filterSize; diff --git a/source/blender/draw/engines/eevee/shaders/shadow_store_frag.glsl b/source/blender/draw/engines/eevee/shaders/shadow_store_frag.glsl index e2982358e52..5c19ccd5ce1 100644 --- a/source/blender/draw/engines/eevee/shaders/shadow_store_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/shadow_store_frag.glsl @@ -1,7 +1,7 @@ layout(std140) uniform shadow_render_block { - /* Use vectors to avoid alignement padding. */ + /* Use vectors to avoid alignment padding. */ ivec4 shadowSampleCount; vec4 shadowInvSampleCount; vec4 filterSize; diff --git a/source/blender/draw/engines/eevee/shaders/volumetric_frag.glsl b/source/blender/draw/engines/eevee/shaders/volumetric_frag.glsl index 4096fc2d511..2b1ae60654e 100644 --- a/source/blender/draw/engines/eevee/shaders/volumetric_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/volumetric_frag.glsl @@ -11,7 +11,7 @@ uniform vec3 volumeOrcoSize; flat in int slice; -/* Warning: theses are not attributes, theses are global vars. */ +/* Warning: these are not attributes, these are global vars. */ vec3 worldPosition = vec3(0.0); vec3 viewPosition = vec3(0.0); vec3 viewNormal = vec3(0.0); diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c index 18950f00823..d5f8d062593 100644 --- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c +++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c @@ -375,7 +375,7 @@ GPUBatch *gpencil_get_buffer_stroke_geom(bGPdata *gpd, short thickness) Object *ob = draw_ctx->obact; tGPspoint *points = gpd->runtime.sbuffer; - int totpoints = gpd->runtime.sbuffer_size; + int totpoints = gpd->runtime.sbuffer_used; /* if cyclic needs more vertex */ int cyclic_add = (gpd->runtime.sbuffer_sflag & GP_STROKE_CYCLIC) ? 1 : 0; int totvertex = totpoints + cyclic_add + 2; @@ -477,7 +477,7 @@ GPUBatch *gpencil_get_buffer_point_geom(bGPdata *gpd, short thickness) Object *ob = draw_ctx->obact; tGPspoint *points = gpd->runtime.sbuffer; - int totpoints = gpd->runtime.sbuffer_size; + int totpoints = gpd->runtime.sbuffer_used; static GPUVertFormat format = {0}; static uint pos_id, color_id, thickness_id, uvdata_id, prev_pos_id; @@ -621,7 +621,7 @@ GPUBatch *gpencil_get_buffer_fill_geom(bGPdata *gpd) } const tGPspoint *points = gpd->runtime.sbuffer; - int totpoints = gpd->runtime.sbuffer_size; + int totpoints = gpd->runtime.sbuffer_used; if (totpoints < 3) { return NULL; } diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c index 181d2efbabb..9b755217946 100644 --- a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c +++ b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c @@ -1493,7 +1493,7 @@ void gpencil_populate_buffer_strokes(GPENCIL_e_data *e_data, /* Check if may need to draw the active stroke cache, only if this layer is the active layer * that is being edited. (Stroke buffer is currently stored in gp-data) */ - if (gpd->runtime.sbuffer_size > 0) { + if (gpd->runtime.sbuffer_used > 0) { if ((gpd->runtime.sbuffer_sflag & GP_STROKE_ERASER) == 0) { /* It should also be noted that sbuffer contains temporary point types * i.e. tGPspoints NOT bGPDspoints @@ -1506,7 +1506,7 @@ void gpencil_populate_buffer_strokes(GPENCIL_e_data *e_data, stl->storage->alignment_mode = (gp_style) ? gp_style->alignment_mode : GP_STYLE_FOLLOW_PATH; /* if only one point, don't need to draw buffer because the user has no time to see it */ - if (gpd->runtime.sbuffer_size > 1) { + if (gpd->runtime.sbuffer_used > 1) { if ((gp_style) && (gp_style->mode == GP_STYLE_MODE_LINE)) { stl->g_data->shgrps_drawing_stroke = gpencil_shgroup_stroke_create( vedata, @@ -1562,7 +1562,7 @@ void gpencil_populate_buffer_strokes(GPENCIL_e_data *e_data, DRW_shgroup_call( stl->g_data->shgrps_drawing_stroke, stl->g_data->batch_buffer_stroke, NULL); - if ((gpd->runtime.sbuffer_size >= 3) && + if ((gpd->runtime.sbuffer_used >= 3) && (gpd->runtime.sfill[3] > GPENCIL_ALPHA_OPACITY_THRESH) && ((gpd->runtime.sbuffer_sflag & GP_STROKE_NOFILL) == 0) && ((brush->gpencil_settings->flag & GP_BRUSH_DISSABLE_LASSO) == 0) && diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c index 408c9759682..5f6f5650ca7 100644 --- a/source/blender/draw/engines/gpencil/gpencil_engine.c +++ b/source/blender/draw/engines/gpencil/gpencil_engine.c @@ -435,7 +435,7 @@ void GPENCIL_cache_init(void *vedata) /* need the original to avoid cow overhead while drawing */ bGPdata *gpd_orig = (bGPdata *)DEG_get_original_id(&obact_gpd->id); if (((gpd_orig->runtime.sbuffer_sflag & GP_STROKE_ERASER) == 0) && - (gpd_orig->runtime.sbuffer_size > 0) && + (gpd_orig->runtime.sbuffer_used > 0) && ((gpd_orig->flag & GP_DATA_STROKE_POLYGON) == 0) && !DRW_state_is_depth() && (stl->storage->background_ready == true)) { stl->g_data->session_flag |= GP_DRW_PAINT_PAINTING; diff --git a/source/blender/draw/engines/gpencil/gpencil_shader_fx.c b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c index 379b4e77514..327765c07b2 100644 --- a/source/blender/draw/engines/gpencil/gpencil_shader_fx.c +++ b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c @@ -463,12 +463,11 @@ static void gpencil_fx_shadow(ShaderFxData *fx, DRW_shgroup_uniform_vec3(fx_shgrp, "loc", fxd->runtime.loc, 1); } - const int nowave = -1; if (fxd->flag & FX_SHADOW_USE_WAVE) { DRW_shgroup_uniform_int(fx_shgrp, "orientation", &fxd->orientation, 1); } else { - DRW_shgroup_uniform_int(fx_shgrp, "orientation", &nowave, 1); + DRW_shgroup_uniform_int_copy(fx_shgrp, "orientation", -1); } DRW_shgroup_uniform_float(fx_shgrp, "amplitude", &fxd->amplitude, 1); DRW_shgroup_uniform_float(fx_shgrp, "period", &fxd->period, 1); diff --git a/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_swirl_frag.glsl b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_swirl_frag.glsl index b226d4f93bc..01d4fe40195 100644 --- a/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_swirl_frag.glsl +++ b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_swirl_frag.glsl @@ -42,7 +42,11 @@ void main() vec2 tc = uv - center; float dist = length(tc); - float pxradius = (ProjectionMatrix[3][3] == 0.0) ? (radius / (loc.z * defaultpixsize)) : + float locpixsize = abs((loc.z * defaultpixsize)); + if (locpixsize == 0) { + locpixsize = 1; + } + float pxradius = (ProjectionMatrix[3][3] == 0.0) ? (radius / locpixsize) : (radius / defaultpixsize); pxradius = max(pxradius, 1); diff --git a/source/blender/draw/engines/select/select_draw_utils.c b/source/blender/draw/engines/select/select_draw_utils.c new file mode 100644 index 00000000000..08c6c2ac865 --- /dev/null +++ b/source/blender/draw/engines/select/select_draw_utils.c @@ -0,0 +1,215 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright 2019, Blender Foundation. + */ + +/** \file + * \ingroup draw_engine + * + * Engine for drawing a selection map where the pixels indicate the selection indices. + */ + +#include "BKE_editmesh.h" + +#include "DNA_mesh_types.h" +#include "DNA_scene_types.h" + +#include "ED_view3d.h" + +#include "DEG_depsgraph.h" +#include "DEG_depsgraph_query.h" + +#include "draw_cache_impl.h" + +#include "select_private.h" + +/* -------------------------------------------------------------------- */ +/** \name Draw Utilities + * \{ */ + +static bool check_ob_drawface_dot(short select_mode, const View3D *v3d, char dt) +{ + if (select_mode & SCE_SELECT_FACE) { + if ((dt < OB_SOLID) || XRAY_FLAG_ENABLED(v3d)) { + return true; + } + if (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_FACE_DOT) { + return true; + } + if ((v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_EDGES) == 0) { + /* Since we can't deduce face selection when edges aren't visible - show dots. */ + return true; + } + } + return false; +} + +static void draw_select_id_edit_mesh(SELECTID_StorageList *stl, + Object *ob, + short select_mode, + bool draw_facedot, + uint initial_offset, + uint *r_vert_offset, + uint *r_edge_offset, + uint *r_face_offset) +{ + Mesh *me = ob->data; + BMEditMesh *em = me->edit_mesh; + + BM_mesh_elem_table_ensure(em->bm, BM_VERT | BM_EDGE | BM_FACE); + + struct GPUBatch *geom_faces = DRW_mesh_batch_cache_get_triangles_with_select_id(me); + DRWShadingGroup *face_shgrp; + if (select_mode & SCE_SELECT_FACE) { + face_shgrp = DRW_shgroup_create_sub(stl->g_data->shgrp_face_flat); + DRW_shgroup_uniform_int_copy(face_shgrp, "offset", *(int *)&initial_offset); + + if (draw_facedot) { + struct GPUBatch *geom_facedots = DRW_mesh_batch_cache_get_facedots_with_select_id(me); + DRW_shgroup_call(face_shgrp, geom_facedots, ob); + } + *r_face_offset = initial_offset + em->bm->totface; + } + else { + face_shgrp = DRW_shgroup_create_sub(stl->g_data->shgrp_face_unif); + DRW_shgroup_uniform_int_copy(face_shgrp, "id", 0); + + *r_face_offset = initial_offset; + } + DRW_shgroup_call(face_shgrp, geom_faces, ob); + + /* Unlike faces, only draw edges if edge select mode. */ + if (select_mode & SCE_SELECT_EDGE) { + struct GPUBatch *geom_edges = DRW_mesh_batch_cache_get_edges_with_select_id(me); + DRWShadingGroup *edge_shgrp = DRW_shgroup_create_sub(stl->g_data->shgrp_edge); + DRW_shgroup_uniform_int_copy(edge_shgrp, "offset", *(int *)r_face_offset); + DRW_shgroup_call(edge_shgrp, geom_edges, ob); + *r_edge_offset = *r_face_offset + em->bm->totedge; + } + else { + /* Note that `r_vert_offset` is calculated from `r_edge_offset`. + * Otherwise the first vertex is never selected, see: T53512. */ + *r_edge_offset = *r_face_offset; + } + + /* Unlike faces, only verts if vert select mode. */ + if (select_mode & SCE_SELECT_VERTEX) { + struct GPUBatch *geom_verts = DRW_mesh_batch_cache_get_verts_with_select_id(me); + DRWShadingGroup *vert_shgrp = DRW_shgroup_create_sub(stl->g_data->shgrp_vert); + DRW_shgroup_uniform_int_copy(vert_shgrp, "offset", *(int *)r_edge_offset); + DRW_shgroup_call(vert_shgrp, geom_verts, ob); + *r_vert_offset = *r_edge_offset + em->bm->totvert; + } + else { + *r_vert_offset = *r_edge_offset; + } +} + +static void draw_select_id_mesh(SELECTID_StorageList *stl, + Object *ob, + short select_mode, + uint initial_offset, + uint *r_vert_offset, + uint *r_edge_offset, + uint *r_face_offset) +{ + Mesh *me = ob->data; + + struct GPUBatch *geom_faces = DRW_mesh_batch_cache_get_triangles_with_select_id(me); + DRWShadingGroup *face_shgrp; + if (select_mode & SCE_SELECT_FACE) { + face_shgrp = DRW_shgroup_create_sub(stl->g_data->shgrp_face_flat); + DRW_shgroup_uniform_int_copy(face_shgrp, "offset", *(int *)&initial_offset); + *r_face_offset = initial_offset + me->totpoly; + } + else { + /* Only draw faces to mask out verts, we don't want their selection ID's. */ + face_shgrp = DRW_shgroup_create_sub(stl->g_data->shgrp_face_unif); + DRW_shgroup_uniform_int_copy(face_shgrp, "id", 0); + *r_face_offset = initial_offset; + } + DRW_shgroup_call(face_shgrp, geom_faces, ob); + + if (select_mode & SCE_SELECT_EDGE) { + struct GPUBatch *geom_edges = DRW_mesh_batch_cache_get_edges_with_select_id(me); + DRWShadingGroup *edge_shgrp = DRW_shgroup_create_sub(stl->g_data->shgrp_edge); + DRW_shgroup_uniform_int_copy(edge_shgrp, "offset", *(int *)r_face_offset); + DRW_shgroup_call(edge_shgrp, geom_edges, ob); + *r_edge_offset = *r_face_offset + me->totedge; + } + else { + *r_edge_offset = *r_face_offset; + } + + if (select_mode & SCE_SELECT_VERTEX) { + struct GPUBatch *geom_verts = DRW_mesh_batch_cache_get_verts_with_select_id(me); + DRWShadingGroup *vert_shgrp = DRW_shgroup_create_sub(stl->g_data->shgrp_vert); + DRW_shgroup_uniform_int_copy(vert_shgrp, "offset", 1); + DRW_shgroup_call(vert_shgrp, geom_verts, ob); + *r_vert_offset = *r_edge_offset + me->totvert; + } +} + +void select_id_draw_object(void *vedata, + View3D *v3d, + Object *ob, + short select_mode, + uint initial_offset, + uint *r_vert_offset, + uint *r_edge_offset, + uint *r_face_offset) +{ + SELECTID_StorageList *stl = ((SELECTID_Data *)vedata)->stl; + + BLI_assert(initial_offset > 0); + + switch (ob->type) { + case OB_MESH: + if (ob->mode & OB_MODE_EDIT) { + bool draw_facedot = check_ob_drawface_dot(select_mode, v3d, ob->dt); + draw_select_id_edit_mesh(stl, + ob, + select_mode, + draw_facedot, + initial_offset, + r_vert_offset, + r_edge_offset, + r_face_offset); + } + else { + if (ob->mode & (OB_MODE_WEIGHT_PAINT | OB_MODE_VERTEX_PAINT | OB_MODE_TEXTURE_PAINT)) { + Mesh *me_orig = DEG_get_original_object(ob)->data; + select_mode = 0; + if (me_orig->editflag & ME_EDIT_PAINT_FACE_SEL) { + select_mode = SCE_SELECT_FACE; + } + if (me_orig->editflag & ME_EDIT_PAINT_VERT_SEL) { + select_mode |= SCE_SELECT_VERTEX; + } + } + draw_select_id_mesh( + stl, ob, select_mode, initial_offset, r_vert_offset, r_edge_offset, r_face_offset); + } + break; + case OB_CURVE: + case OB_SURF: + break; + } +} + +/** \} */ + +#undef SELECT_ENGINE diff --git a/source/blender/draw/engines/select/select_engine.c b/source/blender/draw/engines/select/select_engine.c new file mode 100644 index 00000000000..68b4a8084f0 --- /dev/null +++ b/source/blender/draw/engines/select/select_engine.c @@ -0,0 +1,435 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright 2019, Blender Foundation. + */ + +/** \file + * \ingroup draw_engine + * + * Engine for drawing a selection map where the pixels indicate the selection indices. + */ + +#include "BLI_rect.h" + +#include "DNA_screen_types.h" + +#include "GPU_shader.h" +#include "GPU_select.h" + +#include "UI_resources.h" + +#include "DRW_engine.h" + +#include "select_private.h" +#include "select_engine.h" + +#define SELECT_ENGINE "SELECT_ENGINE" + +/* *********** STATIC *********** */ + +static struct { + SELECTID_Shaders sh_data[GPU_SHADER_CFG_LEN]; + + struct GPUFrameBuffer *framebuffer_select_id; + struct GPUTexture *texture_u32; + + struct { + struct BaseOffset *base_array_index_offsets; + uint bases_len; + uint last_base_drawn; + /** Total number of items `base_array_index_offsets[bases_len - 1].vert`. */ + uint last_index_drawn; + + short select_mode; + } context; +} e_data = {{{NULL}}}; /* Engine data */ + +/* Shaders */ +extern char datatoc_common_view_lib_glsl[]; +extern char datatoc_selection_id_3D_vert_glsl[]; +extern char datatoc_selection_id_frag_glsl[]; + +/* -------------------------------------------------------------------- */ +/** \name Selection Utilities + * \{ */ + +static void draw_select_framebuffer_select_id_setup(void) +{ + DefaultTextureList *dtxl = DRW_viewport_texture_list_get(); + int size[2]; + size[0] = GPU_texture_width(dtxl->depth); + size[1] = GPU_texture_height(dtxl->depth); + + if (e_data.framebuffer_select_id == NULL) { + e_data.framebuffer_select_id = GPU_framebuffer_create(); + } + + if ((e_data.texture_u32 != NULL) && ((GPU_texture_width(e_data.texture_u32) != size[0]) || + (GPU_texture_height(e_data.texture_u32) != size[1]))) { + + GPU_texture_free(e_data.texture_u32); + e_data.texture_u32 = NULL; + } + + /* Make sure the depth texture is attached. + * It may disappear when loading another Blender session. */ + GPU_framebuffer_texture_attach(e_data.framebuffer_select_id, dtxl->depth, 0, 0); + + if (e_data.texture_u32 == NULL) { + e_data.texture_u32 = GPU_texture_create_2d(size[0], size[1], GPU_R32UI, NULL, NULL); + GPU_framebuffer_texture_attach(e_data.framebuffer_select_id, e_data.texture_u32, 0, 0); + GPU_framebuffer_check_valid(e_data.framebuffer_select_id, NULL); + } +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Engine Functions + * \{ */ + +static void select_engine_init(void *vedata) +{ + const DRWContextState *draw_ctx = DRW_context_state_get(); + eGPUShaderConfig sh_cfg = draw_ctx->sh_cfg; + + SELECTID_StorageList *stl = ((SELECTID_Data *)vedata)->stl; + SELECTID_Shaders *sh_data = &e_data.sh_data[sh_cfg]; + + /* Prepass */ + if (!sh_data->select_id_flat) { + const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[sh_cfg]; + sh_data->select_id_flat = GPU_shader_create_from_arrays({ + .vert = (const char *[]){sh_cfg_data->lib, + datatoc_common_view_lib_glsl, + datatoc_selection_id_3D_vert_glsl, + NULL}, + .frag = (const char *[]){datatoc_selection_id_frag_glsl, NULL}, + .defs = (const char *[]){sh_cfg_data->def, NULL}, + }); + } + if (!sh_data->select_id_uniform) { + const GPUShaderConfigData *sh_cfg_data = &GPU_shader_cfg_data[sh_cfg]; + sh_data->select_id_uniform = GPU_shader_create_from_arrays({ + .vert = (const char *[]){sh_cfg_data->lib, + datatoc_common_view_lib_glsl, + datatoc_selection_id_3D_vert_glsl, + NULL}, + .frag = (const char *[]){datatoc_selection_id_frag_glsl, NULL}, + .defs = (const char *[]){sh_cfg_data->def, "#define UNIFORM_ID\n", NULL}, + }); + } + + if (!stl->g_data) { + /* Alloc transient pointers */ + stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__); + } + + { + /* Create view with depth offset */ + stl->g_data->view_faces = (DRWView *)DRW_view_default_get(); + stl->g_data->view_edges = DRW_view_create_with_zoffset(draw_ctx->rv3d, 1.0f); + stl->g_data->view_verts = DRW_view_create_with_zoffset(draw_ctx->rv3d, 1.1f); + } +} + +static void select_cache_init(void *vedata) +{ + SELECTID_PassList *psl = ((SELECTID_Data *)vedata)->psl; + SELECTID_StorageList *stl = ((SELECTID_Data *)vedata)->stl; + + const DRWContextState *draw_ctx = DRW_context_state_get(); + SELECTID_Shaders *sh_data = &e_data.sh_data[draw_ctx->sh_cfg]; + { + psl->select_id_face_pass = DRW_pass_create("Face Pass", DRW_STATE_DEFAULT); + stl->g_data->shgrp_face_unif = DRW_shgroup_create(sh_data->select_id_uniform, + psl->select_id_face_pass); + + stl->g_data->shgrp_face_flat = DRW_shgroup_create(sh_data->select_id_flat, + psl->select_id_face_pass); + + psl->select_id_edge_pass = DRW_pass_create( + "Edge Pass", DRW_STATE_DEFAULT | DRW_STATE_FIRST_VERTEX_CONVENTION); + + stl->g_data->shgrp_edge = DRW_shgroup_create(sh_data->select_id_flat, + psl->select_id_edge_pass); + + psl->select_id_vert_pass = DRW_pass_create("Vert Pass", DRW_STATE_DEFAULT); + stl->g_data->shgrp_vert = DRW_shgroup_create(sh_data->select_id_flat, + psl->select_id_vert_pass); + + DRW_shgroup_uniform_float_copy(stl->g_data->shgrp_vert, "sizeVertex", G_draw.block.sizeVertex); + + if (draw_ctx->sh_cfg == GPU_SHADER_CFG_CLIPPED) { + DRW_shgroup_state_enable(stl->g_data->shgrp_face_unif, DRW_STATE_CLIP_PLANES); + DRW_shgroup_state_enable(stl->g_data->shgrp_face_flat, DRW_STATE_CLIP_PLANES); + DRW_shgroup_state_enable(stl->g_data->shgrp_edge, DRW_STATE_CLIP_PLANES); + DRW_shgroup_state_enable(stl->g_data->shgrp_vert, DRW_STATE_CLIP_PLANES); + } + } + + e_data.context.last_base_drawn = 0; + e_data.context.last_index_drawn = 1; +} + +static void select_cache_populate(void *vedata, Object *ob) +{ + const DRWContextState *draw_ctx = DRW_context_state_get(); + short select_mode = e_data.context.select_mode; + + if (select_mode == -1) { + ToolSettings *ts = draw_ctx->scene->toolsettings; + select_mode = ts->selectmode; + } + + struct BaseOffset *base_ofs = + &e_data.context.base_array_index_offsets[e_data.context.last_base_drawn++]; + + uint offset = e_data.context.last_index_drawn; + + select_id_draw_object(vedata, + draw_ctx->v3d, + ob, + select_mode, + offset, + &base_ofs->vert, + &base_ofs->edge, + &base_ofs->face); + + base_ofs->offset = offset; + e_data.context.last_index_drawn = base_ofs->vert; +} + +static void select_draw_scene(void *vedata) +{ + SELECTID_StorageList *stl = ((SELECTID_Data *)vedata)->stl; + SELECTID_PassList *psl = ((SELECTID_Data *)vedata)->psl; + + /* Setup framebuffer */ + draw_select_framebuffer_select_id_setup(); + GPU_framebuffer_bind(e_data.framebuffer_select_id); + + /* dithering and AA break color coding, so disable */ + glDisable(GL_DITHER); + + GPU_framebuffer_clear_color_depth(e_data.framebuffer_select_id, (const float[4]){0.0f}, 1.0f); + + DRW_view_set_active(stl->g_data->view_faces); + DRW_draw_pass(psl->select_id_face_pass); + + DRW_view_set_active(stl->g_data->view_edges); + DRW_draw_pass(psl->select_id_edge_pass); + + DRW_view_set_active(stl->g_data->view_verts); + DRW_draw_pass(psl->select_id_vert_pass); +} + +static void select_engine_free(void) +{ + for (int sh_data_index = 0; sh_data_index < ARRAY_SIZE(e_data.sh_data); sh_data_index++) { + SELECTID_Shaders *sh_data = &e_data.sh_data[sh_data_index]; + DRW_SHADER_FREE_SAFE(sh_data->select_id_flat); + DRW_SHADER_FREE_SAFE(sh_data->select_id_uniform); + } + + DRW_TEXTURE_FREE_SAFE(e_data.texture_u32); + GPU_FRAMEBUFFER_FREE_SAFE(e_data.framebuffer_select_id); + MEM_SAFE_FREE(e_data.context.base_array_index_offsets); +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Exposed `DRW_engine.h` functions + * \{ */ + +bool DRW_select_elem_get(const uint sel_id, uint *r_elem, uint *r_base_index, char *r_elem_type) +{ + char elem_type = 0; + uint elem_id; + uint base_index = 0; + + for (; base_index < e_data.context.bases_len; base_index++) { + struct BaseOffset *base_ofs = &e_data.context.base_array_index_offsets[base_index]; + + if (base_ofs->face > sel_id) { + elem_id = sel_id - base_ofs->face_start; + elem_type = SCE_SELECT_FACE; + break; + } + if (base_ofs->edge > sel_id) { + elem_id = sel_id - base_ofs->edge_start; + elem_type = SCE_SELECT_EDGE; + break; + } + if (base_ofs->vert > sel_id) { + elem_id = sel_id - base_ofs->vert_start; + elem_type = SCE_SELECT_VERTEX; + break; + } + } + + if (base_index == e_data.context.bases_len) { + return false; + } + + *r_elem = elem_id; + + if (r_base_index) { + *r_base_index = base_index; + } + + if (r_elem_type) { + *r_elem_type = elem_type; + } + + return true; +} + +uint DRW_select_context_offset_for_object_elem(const uint base_index, char elem_type) +{ + struct BaseOffset *base_ofs = &e_data.context.base_array_index_offsets[base_index]; + + if (elem_type == SCE_SELECT_VERTEX) { + return base_ofs->vert_start - 1; + } + if (elem_type == SCE_SELECT_EDGE) { + return base_ofs->edge_start - 1; + } + if (elem_type == SCE_SELECT_FACE) { + return base_ofs->face_start - 1; + } + BLI_assert(0); + return 0; +} + +uint DRW_select_context_elem_len(void) +{ + return e_data.context.last_index_drawn; +} + +/* Read a block of pixels from the select frame buffer. */ +void DRW_framebuffer_select_id_read(const rcti *rect, uint *r_buf) +{ + /* clamp rect by texture */ + rcti r = { + .xmin = 0, + .xmax = GPU_texture_width(e_data.texture_u32), + .ymin = 0, + .ymax = GPU_texture_height(e_data.texture_u32), + }; + + rcti rect_clamp = *rect; + if (BLI_rcti_isect(&r, &rect_clamp, &rect_clamp)) { + DRW_opengl_context_enable(); + GPU_framebuffer_bind(e_data.framebuffer_select_id); + glReadBuffer(GL_COLOR_ATTACHMENT0); + glReadPixels(rect_clamp.xmin, + rect_clamp.ymin, + BLI_rcti_size_x(&rect_clamp), + BLI_rcti_size_y(&rect_clamp), + GL_RED_INTEGER, + GL_UNSIGNED_INT, + r_buf); + + GPU_framebuffer_restore(); + DRW_opengl_context_disable(); + + if (!BLI_rcti_compare(rect, &rect_clamp)) { + GPU_select_buffer_stride_realign(rect, &rect_clamp, r_buf); + } + } + else { + size_t buf_size = BLI_rcti_size_x(rect) * BLI_rcti_size_y(rect) * sizeof(*r_buf); + + memset(r_buf, 0, buf_size); + } +} + +void DRW_select_context_create(Base **UNUSED(bases), const uint bases_len, short select_mode) +{ + e_data.context.select_mode = select_mode; + e_data.context.bases_len = bases_len; + + MEM_SAFE_FREE(e_data.context.base_array_index_offsets); + e_data.context.base_array_index_offsets = MEM_mallocN( + sizeof(*e_data.context.base_array_index_offsets) * bases_len, __func__); +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Legacy + * \{ */ + +void DRW_draw_select_id_object(Depsgraph *depsgraph, + ViewLayer *view_layer, + ARegion *ar, + View3D *v3d, + Object *ob, + short select_mode) +{ + Base *base = BKE_view_layer_base_find(view_layer, ob); + DRW_draw_select_id(depsgraph, ar, v3d, &base, 1, select_mode); +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Engine Type + * \{ */ + +static const DrawEngineDataSize select_data_size = DRW_VIEWPORT_DATA_SIZE(SELECTID_Data); + +DrawEngineType draw_engine_select_type = { + NULL, + NULL, + N_("Select ID"), + &select_data_size, + &select_engine_init, + &select_engine_free, + &select_cache_init, + &select_cache_populate, + NULL, + NULL, + &select_draw_scene, + NULL, + NULL, + NULL, +}; + +/* Note: currently unused, we may want to register so we can see this when debugging the view. */ + +RenderEngineType DRW_engine_viewport_select_type = { + NULL, + NULL, + SELECT_ENGINE, + N_("Select ID"), + RE_INTERNAL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + &draw_engine_select_type, + {NULL, NULL, NULL}, +}; + +/** \} */ + +#undef SELECT_ENGINE diff --git a/source/blender/draw/engines/select/select_engine.h b/source/blender/draw/engines/select/select_engine.h new file mode 100644 index 00000000000..5b900ccaf27 --- /dev/null +++ b/source/blender/draw/engines/select/select_engine.h @@ -0,0 +1,29 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright 2019, Blender Foundation. + */ + +/** \file + * \ingroup draw_engine + */ + +#ifndef __SELECT_ENGINE_H__ +#define __SELECT_ENGINE_H__ + +extern DrawEngineType draw_engine_select_type; +extern RenderEngineType DRW_engine_viewport_select_type; + +#endif /* __SELECT_ID_ENGINE_H__ */ diff --git a/source/blender/draw/engines/select/select_private.h b/source/blender/draw/engines/select/select_private.h new file mode 100644 index 00000000000..9b0addb0fb8 --- /dev/null +++ b/source/blender/draw/engines/select/select_private.h @@ -0,0 +1,91 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Copyright 2019, Blender Foundation. + */ + +/** \file + * \ingroup draw_engine + */ + +#ifndef __SELECT_PRIVATE_H__ +#define __SELECT_PRIVATE_H__ + +#include "DRW_render.h" + +/* GPUViewport.storage + * Is freed everytime the viewport engine changes */ +typedef struct SELECTID_StorageList { + struct SELECTID_PrivateData *g_data; +} SELECTID_StorageList; + +typedef struct SELECTID_PassList { + struct DRWPass *select_id_face_pass; + struct DRWPass *select_id_edge_pass; + struct DRWPass *select_id_vert_pass; +} SELECTID_PassList; + +typedef struct SELECTID_Data { + void *engine_type; + DRWViewportEmptyList *fbl; + DRWViewportEmptyList *txl; + SELECTID_PassList *psl; + SELECTID_StorageList *stl; +} SELECTID_Data; + +typedef struct SELECTID_Shaders { + /* Depth Pre Pass */ + struct GPUShader *select_id_flat; + struct GPUShader *select_id_uniform; +} SELECTID_Shaders; + +typedef struct SELECTID_PrivateData { + DRWShadingGroup *shgrp_face_unif; + DRWShadingGroup *shgrp_face_flat; + DRWShadingGroup *shgrp_edge; + DRWShadingGroup *shgrp_vert; + + DRWView *view_faces; + DRWView *view_edges; + DRWView *view_verts; +} SELECTID_PrivateData; /* Transient data */ + +struct BaseOffset { + /* For convenience only. */ + union { + uint offset; + uint face_start; + }; + union { + uint face; + uint edge_start; + }; + union { + uint edge; + uint vert_start; + }; + uint vert; +}; + +void select_id_draw_object(void *vedata, + View3D *v3d, + Object *ob, + short select_mode, + uint initial_offset, + uint *r_vert_offset, + uint *r_edge_offset, + uint *r_face_offset); + +#endif /* __SELECT_PRIVATE_H__ */ diff --git a/source/blender/draw/engines/select/shaders/selection_id_3D_vert.glsl b/source/blender/draw/engines/select/shaders/selection_id_3D_vert.glsl new file mode 100644 index 00000000000..9b0107cffdb --- /dev/null +++ b/source/blender/draw/engines/select/shaders/selection_id_3D_vert.glsl @@ -0,0 +1,26 @@ + +uniform float sizeVertex; + +in vec3 pos; + +#ifndef UNIFORM_ID +uniform int offset; +in uint color; + +flat out uint id; +#endif + +void main() +{ +#ifndef UNIFORM_ID + id = floatBitsToUint(intBitsToFloat(offset)) + color; +#endif + + vec3 world_pos = point_object_to_world(pos); + gl_Position = point_world_to_ndc(world_pos); + gl_PointSize = sizeVertex; + +#ifdef USE_WORLD_CLIP_PLANES + world_clip_planes_calc_clip_distance(world_pos); +#endif +} diff --git a/source/blender/gpu/shaders/gpu_shader_selection_id_frag.glsl b/source/blender/draw/engines/select/shaders/selection_id_frag.glsl index 1f22b9cb0b4..ea86ddc7301 100644 --- a/source/blender/gpu/shaders/gpu_shader_selection_id_frag.glsl +++ b/source/blender/draw/engines/select/shaders/selection_id_frag.glsl @@ -1,6 +1,7 @@ #ifdef UNIFORM_ID -uniform uint id; +uniform int id; +# define id floatBitsToUint(intBitsToFloat(id)) #else flat in uint id; #endif diff --git a/source/blender/draw/engines/workbench/shaders/workbench_cavity_frag.glsl b/source/blender/draw/engines/workbench/shaders/workbench_cavity_frag.glsl index 8d66cd7b26c..a0e04f252e2 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_cavity_frag.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_cavity_frag.glsl @@ -46,7 +46,7 @@ vec3 get_view_space_from_depth(in vec2 uvcoords, in float depth) } } -/* forward declartion */ +/* forward declaration */ void ssao_factors(in float depth, in vec3 normal, in vec3 position, diff --git a/source/blender/draw/engines/workbench/shaders/workbench_cavity_lib.glsl b/source/blender/draw/engines/workbench/shaders/workbench_cavity_lib.glsl index 1af786b648c..376b19cdd1b 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_cavity_lib.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_cavity_lib.glsl @@ -58,7 +58,7 @@ void ssao_factors(in float depth, /* Handle Background case */ bool is_background = (depth_new == 1.0); - /* This trick provide good edge effect even if no neighboor is found. */ + /* This trick provide good edge effect even if no neighbor is found. */ vec3 pos_new = get_view_space_from_depth(uvcoords, (is_background) ? depth : depth_new); if (is_background) { diff --git a/source/blender/draw/engines/workbench/workbench_volume.c b/source/blender/draw/engines/workbench/workbench_volume.c index 575da1f9683..1beb02ea3a0 100644 --- a/source/blender/draw/engines/workbench/workbench_volume.c +++ b/source/blender/draw/engines/workbench/workbench_volume.c @@ -161,7 +161,7 @@ void workbench_volume_cache_populate(WORKBENCH_Data *vedata, sds->slice_axis - 1; float dim[3]; BKE_object_dimensions_get(ob, dim); - /* 0.05f to acheive somewhat the same opacity as the full view. */ + /* 0.05f to achieve somewhat the same opacity as the full view. */ float step_length = max_ff(1e-16f, dim[axis] * 0.05f); grp = DRW_shgroup_create(sh, vedata->psl->volume_pass); diff --git a/source/blender/draw/intern/draw_cache_impl_curve.c b/source/blender/draw/intern/draw_cache_impl_curve.c index 75c498dfd88..241cd68bc3a 100644 --- a/source/blender/draw/intern/draw_cache_impl_curve.c +++ b/source/blender/draw/intern/draw_cache_impl_curve.c @@ -463,7 +463,7 @@ static void curve_batch_cache_init(Curve *cu) __func__); cache->surf_per_mat = MEM_mallocN(sizeof(*cache->surf_per_mat) * cache->mat_len, __func__); - /* TODO Might be wiser to alloc in one chunck. */ + /* TODO Might be wiser to alloc in one chunk. */ for (int i = 0; i < cache->mat_len; ++i) { cache->surf_per_mat_tris[i] = MEM_callocN(sizeof(GPUIndexBuf), "GPUIndexBuf"); cache->surf_per_mat[i] = MEM_callocN(sizeof(GPUBatch), "GPUBatch"); @@ -679,7 +679,7 @@ static void curve_create_edit_curves_nor(CurveRenderData *rdata, GPUVertBuf *vbo GPU_vertbuf_attr_set(vbo_curves_nor, attr_id.tan, vbo_len_used, &ptan); vbo_len_used++; - /* Skip the other vertex (it does not need to be offseted). */ + /* Skip the other vertex (it does not need to be offsetted). */ GPU_vertbuf_attr_set(vbo_curves_nor, attr_id.pos, vbo_len_used, bevp->vec); vbo_len_used++; diff --git a/source/blender/draw/intern/draw_cache_impl_displist.c b/source/blender/draw/intern/draw_cache_impl_displist.c index d1c214c2aa6..90bbf996851 100644 --- a/source/blender/draw/intern/draw_cache_impl_displist.c +++ b/source/blender/draw/intern/draw_cache_impl_displist.c @@ -693,7 +693,7 @@ void DRW_displist_indexbuf_create_edges_adjacency_lines(struct ListBase *lb, v_idx += dl_vert_len(dl); } - /* Create edges for remaning non manifold edges. */ + /* Create edges for remaining non manifold edges. */ EdgeHashIterator *ehi; for (ehi = BLI_edgehashIterator_new(eh); BLI_edgehashIterator_isDone(ehi) == false; BLI_edgehashIterator_step(ehi)) { diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.c b/source/blender/draw/intern/draw_cache_impl_mesh.c index 306031809d1..ba58dc3d9de 100644 --- a/source/blender/draw/intern/draw_cache_impl_mesh.c +++ b/source/blender/draw/intern/draw_cache_impl_mesh.c @@ -3229,7 +3229,7 @@ static void mesh_create_loop_orco(MeshRenderData *rdata, GPUVertBuf *vbo) /* FIXME(fclem): We use the last component as a way to differentiate from generic vertex attribs. * This is a substential waste of Vram and should be done another way. Unfortunately, - * at the time of writting, I did not found any other "non disruptive" alternative. */ + * at the time of writing, I did not found any other "non disruptive" alternative. */ uint attr_id = GPU_vertformat_attr_add(&format, "orco", GPU_COMP_F32, 4, GPU_FETCH_FLOAT); GPU_vertbuf_init_with_format(vbo, &format); @@ -3715,7 +3715,7 @@ static void mesh_create_edges_adjacency_lines(MeshRenderData *rdata, } } } - /* Create edges for remaning non manifold edges. */ + /* Create edges for remaining non manifold edges. */ EdgeHashIterator *ehi; for (ehi = BLI_edgehashIterator_new(eh); BLI_edgehashIterator_isDone(ehi) == false; BLI_edgehashIterator_step(ehi)) { @@ -4830,7 +4830,7 @@ static void uvedit_fill_buffer_data(MeshRenderData *rdata, /* Tag hidden faces */ BM_elem_flag_set(efa, BM_ELEM_TAG, uvedit_face_visible_nolocal_ex(rdata->toolsettings, efa)); - if (vbo_area && BM_elem_flag_test(efa, BM_ELEM_TAG)) { + if (vbo_area) { edit_uv_preprocess_stretch_area( efa, cd_loop_uv_offset, fidx++, &totarea, &totuvarea, faces_areas); } diff --git a/source/blender/draw/intern/draw_cache_inline.h b/source/blender/draw/intern/draw_cache_inline.h index d94ef5b90d3..12dc0a47a68 100644 --- a/source/blender/draw/intern/draw_cache_inline.h +++ b/source/blender/draw/intern/draw_cache_inline.h @@ -47,7 +47,7 @@ BLI_INLINE GPUBatch *DRW_batch_request(GPUBatch **batch) { - /* XXX TODO(fclem): We are writting to batch cache here. Need to make this thread safe. */ + /* XXX TODO(fclem): We are writing to batch cache here. Need to make this thread safe. */ if (*batch == NULL) { *batch = MEM_callocN(sizeof(GPUBatch), "GPUBatch"); } diff --git a/source/blender/draw/intern/draw_common.c b/source/blender/draw/intern/draw_common.c index 9e494cdad88..ac3e7e4ce67 100644 --- a/source/blender/draw/intern/draw_common.c +++ b/source/blender/draw/intern/draw_common.c @@ -939,7 +939,7 @@ struct DRWCallBuffer *buffer_instance_bone_stick(DRWPass *pass, eGPUShaderConfig { {"boneStart", DRW_ATTR_FLOAT, 3}, {"boneEnd", DRW_ATTR_FLOAT, 3}, - {"wireColor", DRW_ATTR_FLOAT, 4}, /* TODO port theses to uchar color */ + {"wireColor", DRW_ATTR_FLOAT, 4}, /* TODO port these to uchar color */ {"boneColor", DRW_ATTR_FLOAT, 4}, {"headColor", DRW_ATTR_FLOAT, 4}, {"tailColor", DRW_ATTR_FLOAT, 4}, diff --git a/source/blender/draw/intern/draw_hair.c b/source/blender/draw/intern/draw_hair.c index 20d5ae096c9..fa1f1f2aab4 100644 --- a/source/blender/draw/intern/draw_hair.c +++ b/source/blender/draw/intern/draw_hair.c @@ -249,7 +249,7 @@ void DRW_hair_update(void) { #ifndef USE_TRANSFORM_FEEDBACK /** - * Workaround to tranform feedback not working on mac. + * Workaround to transform feedback not working on mac. * On some system it crashes (see T58489) and on some other it renders garbage (see T60171). * * So instead of using transform feedback we render to a texture, diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c index 2841e017ef6..a6c671a631a 100644 --- a/source/blender/draw/intern/draw_manager.c +++ b/source/blender/draw/intern/draw_manager.c @@ -89,6 +89,7 @@ #include "engines/workbench/workbench_engine.h" #include "engines/external/external_engine.h" #include "engines/gpencil/gpencil_engine.h" +#include "engines/select/select_engine.h" #include "GPU_context.h" @@ -1131,7 +1132,7 @@ static void drw_engines_cache_populate(Object *ob) drw_batch_cache_generate_requested(ob); } - /* ... and clearing it here too because theses draw data are + /* ... and clearing it here too because this draw data is * from a mempool and must not be free individually by depsgraph. */ drw_drawdata_unlink_dupli((ID *)ob); } @@ -1527,7 +1528,7 @@ void DRW_notify_view_update(const DRWUpdateContext *update_ctx) * for each relevant engine / mode engine. */ void DRW_draw_view(const bContext *C) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_expect_evaluated_depsgraph(C); ARegion *ar = CTX_wm_region(C); View3D *v3d = CTX_wm_view3d(C); Scene *scene = DEG_get_evaluated_scene(depsgraph); @@ -2136,16 +2137,13 @@ void DRW_custom_pipeline(DrawEngineType *draw_engine_type, static struct DRWSelectBuffer { struct GPUFrameBuffer *framebuffer_depth_only; - struct GPUFrameBuffer *framebuffer_select_id; struct GPUTexture *texture_depth; - struct GPUTexture *texture_u32; } g_select_buffer = {NULL}; static void draw_select_framebuffer_depth_only_setup(const int size[2]) { if (g_select_buffer.framebuffer_depth_only == NULL) { g_select_buffer.framebuffer_depth_only = GPU_framebuffer_create(); - g_select_buffer.framebuffer_select_id = GPU_framebuffer_create(); } if ((g_select_buffer.texture_depth != NULL) && @@ -2162,32 +2160,7 @@ static void draw_select_framebuffer_depth_only_setup(const int size[2]) GPU_framebuffer_texture_attach( g_select_buffer.framebuffer_depth_only, g_select_buffer.texture_depth, 0, 0); - GPU_framebuffer_texture_attach( - g_select_buffer.framebuffer_select_id, g_select_buffer.texture_depth, 0, 0); - GPU_framebuffer_check_valid(g_select_buffer.framebuffer_depth_only, NULL); - GPU_framebuffer_check_valid(g_select_buffer.framebuffer_select_id, NULL); - } -} - -static void draw_select_framebuffer_select_id_setup(const int size[2]) -{ - draw_select_framebuffer_depth_only_setup(size); - - if ((g_select_buffer.texture_u32 != NULL) && - ((GPU_texture_width(g_select_buffer.texture_u32) != size[0]) || - (GPU_texture_height(g_select_buffer.texture_u32) != size[1]))) { - GPU_texture_free(g_select_buffer.texture_u32); - g_select_buffer.texture_u32 = NULL; - } - - if (g_select_buffer.texture_u32 == NULL) { - g_select_buffer.texture_u32 = GPU_texture_create_2d(size[0], size[1], GPU_R32UI, NULL, NULL); - - GPU_framebuffer_texture_attach( - g_select_buffer.framebuffer_select_id, g_select_buffer.texture_u32, 0, 0); - - GPU_framebuffer_check_valid(g_select_buffer.framebuffer_select_id, NULL); } } @@ -2479,14 +2452,17 @@ static void drw_draw_depth_loop_imp(void) void DRW_draw_depth_loop(struct Depsgraph *depsgraph, ARegion *ar, View3D *v3d, - GPUViewport *viewport) + GPUViewport *viewport, + bool use_opengl_context) { Scene *scene = DEG_get_evaluated_scene(depsgraph); RenderEngineType *engine_type = ED_view3d_engine_type(scene, v3d->shading.type); ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph); RegionView3D *rv3d = ar->regiondata; - DRW_opengl_context_enable(); + if (use_opengl_context) { + DRW_opengl_context_enable(); + } /* Reset before using it. */ drw_state_prepare_clean_for_draw(&DST); @@ -2525,7 +2501,9 @@ void DRW_draw_depth_loop(struct Depsgraph *depsgraph, #endif /* Changin context */ - DRW_opengl_context_disable(); + if (use_opengl_context) { + DRW_opengl_context_disable(); + } } /** @@ -2575,6 +2553,78 @@ void DRW_draw_depth_loop_gpencil(struct Depsgraph *depsgraph, DRW_opengl_context_disable(); } +void DRW_draw_select_id(Depsgraph *depsgraph, + ARegion *ar, + View3D *v3d, + Base **bases, + const uint bases_len, + short select_mode) +{ + Scene *scene = DEG_get_evaluated_scene(depsgraph); + ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph); + + DRW_select_context_create(bases, bases_len, select_mode); + + DRW_opengl_context_enable(); + + /* Reset before using it. */ + drw_state_prepare_clean_for_draw(&DST); + DST.buffer_finish_called = true; + + /* Instead of 'DRW_context_state_init(C, &DST.draw_ctx)', assign from args */ + DST.draw_ctx = (DRWContextState){ + .ar = ar, + .rv3d = ar->regiondata, + .v3d = v3d, + .scene = scene, + .view_layer = view_layer, + .obact = OBACT(view_layer), + .depsgraph = depsgraph, + }; + + use_drw_engine(&draw_engine_select_type); + drw_context_state_init(); + + /* Setup viewport */ + DST.viewport = WM_draw_region_get_viewport(ar, 0); + drw_viewport_var_init(); + + /* Update ubos */ + DRW_globals_update(); + + /* Init engines */ + drw_engines_init(); + + { + drw_engines_cache_init(); + + /* Keep `base_index` in sync with `e_data.context.last_base_drawn`. + * So don't skip objects. */ + for (uint base_index = 0; base_index < bases_len; base_index++) { + Object *obj_eval = DEG_get_evaluated_object(depsgraph, bases[base_index]->object); + drw_engines_cache_populate(obj_eval); + } + + drw_engines_cache_finish(); + } + + /* Start Drawing */ + DRW_state_reset(); + drw_engines_draw_scene(); + DRW_state_reset(); + + drw_engines_disable(); + +#ifdef DEBUG + /* Avoid accidental reuse. */ + drw_state_ensure_not_reused(&DST); +#endif + + /* Changin context */ + GPU_framebuffer_restore(); + DRW_opengl_context_disable(); +} + /** See #DRW_shgroup_world_clip_planes_from_rv3d. */ static void draw_world_clip_planes_from_rv3d(GPUBatch *batch, const float world_clip_planes[6][4]) { @@ -2646,294 +2696,6 @@ void DRW_draw_depth_object(ARegion *ar, GPUViewport *viewport, Object *object) DRW_opengl_context_disable(); } -static void draw_mesh_verts(GPUBatch *batch, uint offset, const float world_clip_planes[6][4]) -{ - GPU_point_size(UI_GetThemeValuef(TH_VERTEX_SIZE)); - - const eGPUShaderConfig sh_cfg = world_clip_planes ? GPU_SHADER_CFG_CLIPPED : - GPU_SHADER_CFG_DEFAULT; - GPU_batch_program_set_builtin_with_config(batch, GPU_SHADER_3D_FLAT_SELECT_ID, sh_cfg); - GPU_batch_uniform_1ui(batch, "offset", offset); - if (world_clip_planes != NULL) { - draw_world_clip_planes_from_rv3d(batch, world_clip_planes); - } - GPU_batch_draw(batch); -} - -static void draw_mesh_edges(GPUBatch *batch, uint offset, const float world_clip_planes[6][4]) -{ - GPU_line_width(1.0f); - glProvokingVertex(GL_FIRST_VERTEX_CONVENTION); - - const eGPUShaderConfig sh_cfg = world_clip_planes ? GPU_SHADER_CFG_CLIPPED : - GPU_SHADER_CFG_DEFAULT; - GPU_batch_program_set_builtin_with_config(batch, GPU_SHADER_3D_FLAT_SELECT_ID, sh_cfg); - GPU_batch_uniform_1ui(batch, "offset", offset); - if (world_clip_planes != NULL) { - draw_world_clip_planes_from_rv3d(batch, world_clip_planes); - } - GPU_batch_draw(batch); - - glProvokingVertex(GL_LAST_VERTEX_CONVENTION); -} - -/* two options, facecolors or black */ -static void draw_mesh_face(GPUBatch *batch, - uint offset, - const bool use_select, - const float world_clip_planes[6][4]) -{ - if (use_select) { - const eGPUShaderConfig sh_cfg = world_clip_planes ? GPU_SHADER_CFG_CLIPPED : - GPU_SHADER_CFG_DEFAULT; - GPU_batch_program_set_builtin_with_config(batch, GPU_SHADER_3D_FLAT_SELECT_ID, sh_cfg); - GPU_batch_uniform_1ui(batch, "offset", offset); - if (world_clip_planes != NULL) { - draw_world_clip_planes_from_rv3d(batch, world_clip_planes); - } - GPU_batch_draw(batch); - } - else { - const eGPUShaderConfig sh_cfg = world_clip_planes ? GPU_SHADER_CFG_CLIPPED : - GPU_SHADER_CFG_DEFAULT; - GPU_batch_program_set_builtin_with_config(batch, GPU_SHADER_3D_UNIFORM_SELECT_ID, sh_cfg); - GPU_batch_uniform_1ui(batch, "id", 0); - if (world_clip_planes != NULL) { - draw_world_clip_planes_from_rv3d(batch, world_clip_planes); - } - GPU_batch_draw(batch); - } -} - -static void draw_mesh_face_dot(GPUBatch *batch, uint offset, const float world_clip_planes[6][4]) -{ - const eGPUShaderConfig sh_cfg = world_clip_planes ? GPU_SHADER_CFG_CLIPPED : - GPU_SHADER_CFG_DEFAULT; - GPU_batch_program_set_builtin_with_config(batch, GPU_SHADER_3D_FLAT_SELECT_ID, sh_cfg); - GPU_batch_uniform_1ui(batch, "offset", offset); - if (world_clip_planes != NULL) { - draw_world_clip_planes_from_rv3d(batch, world_clip_planes); - } - GPU_batch_draw(batch); -} - -void DRW_draw_select_id_object(Scene *scene, - RegionView3D *rv3d, - Object *ob, - short select_mode, - bool draw_facedot, - uint initial_offset, - uint *r_vert_offset, - uint *r_edge_offset, - uint *r_face_offset) -{ - ToolSettings *ts = scene->toolsettings; - if (select_mode == -1) { - select_mode = ts->selectmode; - } - - /* Init the scene of the draw context. When using face dot selection on - * when the subsurf modifier is active on the cage, the scene needs to be - * valid. It is read from the context in the - * `DRW_mesh_batch_cache_create_requested` and used in the `isDisabled` - * method of the SubSurfModifier. */ - DRWContextState *draw_ctx = &DST.draw_ctx; - draw_ctx->scene = scene; - - GPU_matrix_mul(ob->obmat); - - const float(*world_clip_planes)[4] = NULL; - if (rv3d->rflag & RV3D_CLIPPING) { - ED_view3d_clipping_local(rv3d, ob->obmat); - world_clip_planes = rv3d->clip_local; - } - - BLI_assert(initial_offset > 0); - - switch (ob->type) { - case OB_MESH: - if (ob->mode & OB_MODE_EDIT) { - Mesh *me = ob->data; - BMEditMesh *em = me->edit_mesh; - const bool use_faceselect = (select_mode & SCE_SELECT_FACE) != 0; - - DRW_mesh_batch_cache_validate(me); - - BM_mesh_elem_table_ensure(em->bm, BM_VERT | BM_EDGE | BM_FACE); - - GPUBatch *geom_faces, *geom_edges, *geom_verts, *geom_facedots; - geom_faces = DRW_mesh_batch_cache_get_triangles_with_select_id(me); - if (select_mode & SCE_SELECT_EDGE) { - geom_edges = DRW_mesh_batch_cache_get_edges_with_select_id(me); - } - if (select_mode & SCE_SELECT_VERTEX) { - geom_verts = DRW_mesh_batch_cache_get_verts_with_select_id(me); - } - if (use_faceselect && draw_facedot) { - geom_facedots = DRW_mesh_batch_cache_get_facedots_with_select_id(me); - } - DRW_mesh_batch_cache_create_requested(ob, me, NULL, false, true); - - draw_mesh_face(geom_faces, initial_offset, use_faceselect, world_clip_planes); - - if (use_faceselect && draw_facedot) { - draw_mesh_face_dot(geom_facedots, initial_offset, world_clip_planes); - } - - if (select_mode & SCE_SELECT_FACE) { - *r_face_offset = initial_offset + em->bm->totface; - } - else { - *r_face_offset = initial_offset; - } - - ED_view3d_polygon_offset(rv3d, 1.0); - - /* Unlike faces, only draw edges if edge select mode. */ - if (select_mode & SCE_SELECT_EDGE) { - draw_mesh_edges(geom_edges, *r_face_offset, world_clip_planes); - *r_edge_offset = *r_face_offset + em->bm->totedge; - } - else { - /* Note that `r_vert_offset` is calculated from `r_edge_offset`. - * Otherwise the first vertex is never selected, see: T53512. */ - *r_edge_offset = *r_face_offset; - } - - ED_view3d_polygon_offset(rv3d, 1.1); - - /* Unlike faces, only verts if vert select mode. */ - if (select_mode & SCE_SELECT_VERTEX) { - draw_mesh_verts(geom_verts, *r_edge_offset, world_clip_planes); - *r_vert_offset = *r_edge_offset + em->bm->totvert; - } - else { - *r_vert_offset = *r_edge_offset; - } - - ED_view3d_polygon_offset(rv3d, 0.0); - } - else { - Mesh *me_orig = DEG_get_original_object(ob)->data; - Mesh *me_eval = ob->data; - - DRW_mesh_batch_cache_validate(me_eval); - GPUBatch *geom_faces = DRW_mesh_batch_cache_get_triangles_with_select_id(me_eval); - if ((me_orig->editflag & ME_EDIT_PAINT_VERT_SEL) && - /* Currently vertex select supports weight paint and vertex paint. */ - ((ob->mode & OB_MODE_WEIGHT_PAINT) || (ob->mode & OB_MODE_VERTEX_PAINT))) { - - GPUBatch *geom_verts = DRW_mesh_batch_cache_get_verts_with_select_id(me_eval); - DRW_mesh_batch_cache_create_requested(ob, me_eval, NULL, false, true); - - /* Only draw faces to mask out verts, we don't want their selection ID's. */ - draw_mesh_face(geom_faces, 0, false, world_clip_planes); - draw_mesh_verts(geom_verts, 1, world_clip_planes); - - *r_face_offset = *r_edge_offset = initial_offset; - *r_vert_offset = me_eval->totvert + 1; - } - else { - const bool use_hide = (me_orig->editflag & ME_EDIT_PAINT_FACE_SEL); - DRW_mesh_batch_cache_create_requested(ob, me_eval, NULL, false, use_hide); - - draw_mesh_face(geom_faces, initial_offset, true, world_clip_planes); - - *r_face_offset = initial_offset + me_eval->totpoly; - *r_edge_offset = *r_vert_offset = *r_face_offset; - } - } - break; - case OB_CURVE: - case OB_SURF: - break; - } - - GPU_matrix_set(rv3d->viewmat); -} - -/* Set an opengl context to be used with shaders that draw on U32 colors. */ -void DRW_framebuffer_select_id_setup(ARegion *ar, const bool clear) -{ - RegionView3D *rv3d = ar->regiondata; - - DRW_opengl_context_enable(); - - /* Setup framebuffer */ - int viewport_size[2] = {ar->winx, ar->winy}; - draw_select_framebuffer_select_id_setup(viewport_size); - GPU_framebuffer_bind(g_select_buffer.framebuffer_select_id); - - /* dithering and AA break color coding, so disable */ - glDisable(GL_DITHER); - - GPU_depth_test(true); - GPU_program_point_size(false); - - if (clear) { - GPU_framebuffer_clear_color_depth( - g_select_buffer.framebuffer_select_id, (const float[4]){0.0f}, 1.0f); - } - - if (rv3d->rflag & RV3D_CLIPPING) { - ED_view3d_clipping_set(rv3d); - } -} - -/* Ends the context for selection and restoring the previous one. */ -void DRW_framebuffer_select_id_release(ARegion *ar) -{ - RegionView3D *rv3d = ar->regiondata; - - if (rv3d->rflag & RV3D_CLIPPING) { - ED_view3d_clipping_disable(); - } - - GPU_depth_test(false); - - GPU_framebuffer_restore(); - - DRW_opengl_context_disable(); -} - -/* Read a block of pixels from the select frame buffer. */ -void DRW_framebuffer_select_id_read(const rcti *rect, uint *r_buf) -{ - /* clamp rect by texture */ - rcti r = { - .xmin = 0, - .xmax = GPU_texture_width(g_select_buffer.texture_u32), - .ymin = 0, - .ymax = GPU_texture_height(g_select_buffer.texture_u32), - }; - - rcti rect_clamp = *rect; - if (BLI_rcti_isect(&r, &rect_clamp, &rect_clamp)) { - DRW_opengl_context_enable(); - GPU_framebuffer_bind(g_select_buffer.framebuffer_select_id); - glReadBuffer(GL_COLOR_ATTACHMENT0); - glReadPixels(rect_clamp.xmin, - rect_clamp.ymin, - BLI_rcti_size_x(&rect_clamp), - BLI_rcti_size_y(&rect_clamp), - GL_RED_INTEGER, - GL_UNSIGNED_INT, - r_buf); - - GPU_framebuffer_restore(); - DRW_opengl_context_disable(); - - if (!BLI_rcti_compare(rect, &rect_clamp)) { - GPU_select_buffer_stride_realign(rect, &rect_clamp, r_buf); - } - } - else { - size_t buf_size = BLI_rcti_size_x(rect) * BLI_rcti_size_y(rect) * sizeof(*r_buf); - - memset(r_buf, 0, buf_size); - } -} - /** \} */ /* -------------------------------------------------------------------- */ @@ -3089,6 +2851,7 @@ void DRW_engines_register(void) DRW_engine_register(&draw_engine_pose_type); DRW_engine_register(&draw_engine_sculpt_type); DRW_engine_register(&draw_engine_gpencil_type); + DRW_engine_register(&draw_engine_select_type); /* setup callbacks */ { @@ -3123,9 +2886,7 @@ void DRW_engines_free(void) DRW_opengl_context_enable(); - DRW_TEXTURE_FREE_SAFE(g_select_buffer.texture_u32); DRW_TEXTURE_FREE_SAFE(g_select_buffer.texture_depth); - GPU_FRAMEBUFFER_FREE_SAFE(g_select_buffer.framebuffer_select_id); GPU_FRAMEBUFFER_FREE_SAFE(g_select_buffer.framebuffer_depth_only); DRW_hair_free(); diff --git a/source/blender/draw/intern/draw_manager.h b/source/blender/draw/intern/draw_manager.h index 424d06a3e56..f37e713e374 100644 --- a/source/blender/draw/intern/draw_manager.h +++ b/source/blender/draw/intern/draw_manager.h @@ -225,7 +225,7 @@ typedef struct DRWViewUboStorage { float wininv[4][4]; float clipplanes[6][4]; - /* Should not be here. Not view dependant (only main view). */ + /* Should not be here. Not view dependent (only main view). */ float viewcamtexcofac[4]; } DRWViewUboStorage; diff --git a/source/blender/draw/modes/edit_curve_mode.c b/source/blender/draw/modes/edit_curve_mode.c index e3c120e80cb..e68e03c2438 100644 --- a/source/blender/draw/modes/edit_curve_mode.c +++ b/source/blender/draw/modes/edit_curve_mode.c @@ -335,7 +335,7 @@ static void EDIT_CURVE_draw_scene(void *vedata) MULTISAMPLE_SYNC_DISABLE_NO_DEPTH(dfbl, dtxl); } - /* Thoses passes don't write to depth and are AA'ed using other tricks. */ + /* These passes don't write to depth and are AA'ed using other tricks. */ DRW_draw_pass(psl->overlay_edge_pass); DRW_draw_pass(psl->overlay_vert_pass); } diff --git a/source/blender/draw/modes/edit_mesh_mode.c b/source/blender/draw/modes/edit_mesh_mode.c index 272aa552d38..f0e35e47a66 100644 --- a/source/blender/draw/modes/edit_mesh_mode.c +++ b/source/blender/draw/modes/edit_mesh_mode.c @@ -371,7 +371,7 @@ static void edit_mesh_create_overlay_passes(float face_alpha, DRW_shgroup_state_enable(grp, DRW_STATE_CLIP_PLANES); } - /* Cage geom needs to be offseted to avoid Z-fighting. */ + /* Cage geom needs to be offsetted to avoid Z-fighting. */ passes->faces_cage = DRW_pass_create("Edit Mesh Faces Cage", DRW_STATE_WRITE_COLOR | statemod); grp = shgrps->faces_cage = DRW_shgroup_create(face_sh, passes->faces_cage); DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo); diff --git a/source/blender/draw/modes/object_mode.c b/source/blender/draw/modes/object_mode.c index 9fc11e4f36f..148a4951dc6 100644 --- a/source/blender/draw/modes/object_mode.c +++ b/source/blender/draw/modes/object_mode.c @@ -1242,7 +1242,7 @@ static void DRW_shgroup_camera_background_images(OBJECT_Shaders *sh_data, unit_m4(win_m4_scale); unit_m4(win_m4_translate); unit_m4(scale_m4); - axis_angle_to_mat4_single(rot_m4, 'Z', bgpic->rotation); + axis_angle_to_mat4_single(rot_m4, 'Z', -bgpic->rotation); unit_m4(translate_m4); const float *size = DRW_viewport_size_get(); @@ -1256,7 +1256,7 @@ static void DRW_shgroup_camera_background_images(OBJECT_Shaders *sh_data, if (!DRW_state_is_image_render()) { rctf render_border; - ED_view3d_calc_camera_border(scene, depsgraph, ar, v3d, rv3d, &render_border, true); + ED_view3d_calc_camera_border(scene, depsgraph, ar, v3d, rv3d, &render_border, false); camera_width = render_border.xmax - render_border.xmin; camera_height = render_border.ymax - render_border.ymin; camera_aspect = camera_width / camera_height; @@ -1311,9 +1311,9 @@ static void DRW_shgroup_camera_background_images(OBJECT_Shaders *sh_data, scale_m4[0][0] = scale_x; scale_m4[1][1] = scale_y; - // translate - translate_m4[3][0] = bgpic->offset[0]; - translate_m4[3][1] = bgpic->offset[1]; + /* Translate, using coordinates that aren't squashed by the aspect. */ + translate_m4[3][0] = bgpic->offset[0] * 2.0f * max_ff(1.0f, 1.0f / camera_aspect); + translate_m4[3][1] = bgpic->offset[1] * 2.0f * max_ff(1.0f, camera_aspect); mul_m4_series(bg_data->transform_mat, win_m4_translate, @@ -2862,7 +2862,7 @@ static void DRW_shgroup_lightprobe(OBJECT_Shaders *sh_data, DRWCallBuffer *buf = buffer_theme_id_to_probe_cube_outline_shgrp( stl, theme_id, ob->base_flag); - /* TODO remove or change the drawing of the cube probes. Theses line draws nothing on purpose + /* TODO remove or change the drawing of the cube probes. This line draws nothing on purpose * to keep the call ids correct. */ zero_m4(probe_cube_mat); DRW_buffer_add_entry(buf, call_id, &draw_size, probe_cube_mat); diff --git a/source/blender/draw/modes/shaders/common_globals_lib.glsl b/source/blender/draw/modes/shaders/common_globals_lib.glsl index 3cc6ac9a5a4..f75ef06b6d9 100644 --- a/source/blender/draw/modes/shaders/common_globals_lib.glsl +++ b/source/blender/draw/modes/shaders/common_globals_lib.glsl @@ -83,7 +83,7 @@ layout(std140) uniform globalsBlock float pad_globalsBlock; }; -/* data[0] (1nd byte flags) */ +/* data[0] (1st byte flags) */ #define FACE_ACTIVE (1 << 0) #define FACE_SELECTED (1 << 1) #define FACE_FREESTYLE (1 << 2) diff --git a/source/blender/draw/modes/shaders/common_hair_lib.glsl b/source/blender/draw/modes/shaders/common_hair_lib.glsl index f9c3df34658..cbcdc947bc7 100644 --- a/source/blender/draw/modes/shaders/common_hair_lib.glsl +++ b/source/blender/draw/modes/shaders/common_hair_lib.glsl @@ -1,8 +1,8 @@ /** * Library to create hairs dynamically from control points. * This is less bandwidth intensive than fetching the vertex attributes - * but does more ALU work per vertex. This also reduce the number - * of data the CPU has to precompute and transfert for each update. + * but does more ALU work per vertex. This also reduces the amount + * of data the CPU has to precompute and transfer for each update. */ /** @@ -44,7 +44,7 @@ uniform usamplerBuffer hairStrandSegBuffer; /* R16UI */ /* -- Subdivision stage -- */ /** * We use a transform feedback to preprocess the strands and add more subdivision to it. - * For the moment theses are simple smooth interpolation but one could hope to see the full + * For the moment these are simple smooth interpolation but one could hope to see the full * children particle modifiers being evaluated at this stage. * * If no more subdivision is needed, we can skip this step. diff --git a/source/blender/editors/animation/anim_channels_defines.c b/source/blender/editors/animation/anim_channels_defines.c index 7a7769ccc90..3d7178a4114 100644 --- a/source/blender/editors/animation/anim_channels_defines.c +++ b/source/blender/editors/animation/anim_channels_defines.c @@ -4340,7 +4340,6 @@ static void achannel_setting_slider_cb(bContext *C, void *id_poin, void *fcu_poi AnimData *adt = BKE_animdata_from_id(id); FCurve *fcu = (FCurve *)fcu_poin; - Depsgraph *depsgraph = CTX_data_depsgraph(C); ReportList *reports = CTX_wm_reports(C); Scene *scene = CTX_data_scene(C); ToolSettings *ts = scene->toolsettings; @@ -4356,7 +4355,7 @@ static void achannel_setting_slider_cb(bContext *C, void *id_poin, void *fcu_poi /* Get NLA context for value remapping */ NlaKeyframingContext *nla_context = BKE_animsys_get_nla_keyframing_context( - &nla_cache, depsgraph, &id_ptr, adt, (float)CFRA); + &nla_cache, &id_ptr, adt, (float)CFRA, false); /* get current frame and apply NLA-mapping to it (if applicable) */ cfra = BKE_nla_tweakedit_remap(adt, (float)CFRA, NLATIME_CONVERT_UNMAP); @@ -4373,7 +4372,7 @@ static void achannel_setting_slider_cb(bContext *C, void *id_poin, void *fcu_poi /* insert a keyframe for this F-Curve */ done = insert_keyframe_direct( - depsgraph, reports, ptr, prop, fcu, cfra, ts->keyframe_type, nla_context, flag); + reports, ptr, prop, fcu, cfra, ts->keyframe_type, nla_context, flag); if (done) { if (adt->action != NULL) { @@ -4395,7 +4394,6 @@ static void achannel_setting_slider_shapekey_cb(bContext *C, void *key_poin, voi KeyBlock *kb = (KeyBlock *)kb_poin; char *rna_path = BKE_keyblock_curval_rnapath_get(key, kb); - Depsgraph *depsgraph = CTX_data_depsgraph(C); ReportList *reports = CTX_wm_reports(C); Scene *scene = CTX_data_scene(C); ToolSettings *ts = scene->toolsettings; @@ -4411,7 +4409,7 @@ static void achannel_setting_slider_shapekey_cb(bContext *C, void *key_poin, voi /* Get NLA context for value remapping */ NlaKeyframingContext *nla_context = BKE_animsys_get_nla_keyframing_context( - &nla_cache, depsgraph, &id_ptr, key->adt, (float)CFRA); + &nla_cache, &id_ptr, key->adt, (float)CFRA, false); /* get current frame and apply NLA-mapping to it (if applicable) */ cfra = BKE_nla_tweakedit_remap(key->adt, (float)CFRA, NLATIME_CONVERT_UNMAP); @@ -4433,7 +4431,7 @@ static void achannel_setting_slider_shapekey_cb(bContext *C, void *key_poin, voi /* insert a keyframe for this F-Curve */ done = insert_keyframe_direct( - depsgraph, reports, ptr, prop, fcu, cfra, ts->keyframe_type, nla_context, flag); + reports, ptr, prop, fcu, cfra, ts->keyframe_type, nla_context, flag); if (done) { WM_event_add_notifier(C, NC_ANIMATION | ND_ANIMCHAN | NA_EDITED, NULL); @@ -4460,7 +4458,6 @@ static void achannel_setting_slider_nla_curve_cb(bContext *C, PropertyRNA *prop; int index; - Depsgraph *depsgraph = CTX_data_depsgraph(C); ReportList *reports = CTX_wm_reports(C); Scene *scene = CTX_data_scene(C); ToolSettings *ts = scene->toolsettings; @@ -4485,8 +4482,7 @@ static void achannel_setting_slider_nla_curve_cb(bContext *C, } /* insert a keyframe for this F-Curve */ - done = insert_keyframe_direct( - depsgraph, reports, ptr, prop, fcu, cfra, ts->keyframe_type, NULL, flag); + done = insert_keyframe_direct(reports, ptr, prop, fcu, cfra, ts->keyframe_type, NULL, flag); if (done) { WM_event_add_notifier(C, NC_ANIMATION | ND_ANIMCHAN | NA_EDITED, NULL); diff --git a/source/blender/editors/animation/anim_channels_edit.c b/source/blender/editors/animation/anim_channels_edit.c index b93d52a1b2d..7e913014a87 100644 --- a/source/blender/editors/animation/anim_channels_edit.c +++ b/source/blender/editors/animation/anim_channels_edit.c @@ -1705,7 +1705,7 @@ static void ANIM_OT_channels_ungroup(wmOperatorType *ot) /* ******************** Delete Channel Operator *********************** */ -static void update_dependencies_on_delete(bAnimListElem *ale) +static void tag_update_animation_element(bAnimListElem *ale) { ID *id = ale->id; AnimData *adt = BKE_animdata_from_id(id); @@ -1801,7 +1801,7 @@ static int animchannels_delete_exec(bContext *C, wmOperator *UNUSED(op)) /* try to free F-Curve */ ANIM_fcurve_delete_from_animdata(&ac, adt, fcu); - update_dependencies_on_delete(ale); + tag_update_animation_element(ale); break; } case ANIMTYPE_NLACURVE: { @@ -1823,7 +1823,7 @@ static int animchannels_delete_exec(bContext *C, wmOperator *UNUSED(op)) /* unlink and free the F-Curve */ BLI_remlink(&strip->fcurves, fcu); free_fcurve(fcu); - update_dependencies_on_delete(ale); + tag_update_animation_element(ale); break; } case ANIMTYPE_GPLAYER: { @@ -1967,6 +1967,7 @@ static void setflag_anim_channels(bAnimContext *ac, /* set the setting in the appropriate way */ ANIM_channel_setting_set(ac, ale, setting, mode); + tag_update_animation_element(ale); /* if flush status... */ if (flush) { diff --git a/source/blender/editors/animation/anim_draw.c b/source/blender/editors/animation/anim_draw.c index 61bf7f95340..7ab50afe3a1 100644 --- a/source/blender/editors/animation/anim_draw.c +++ b/source/blender/editors/animation/anim_draw.c @@ -422,23 +422,16 @@ static float normalization_factor_get(Scene *scene, FCurve *fcu, short flag, flo } else { const BezTriple *prev_bezt = bezt - 1; - if (prev_bezt->ipo == BEZT_IPO_CONST) { - /* Constant interpolation: previous CV value is used up - * to the current keyframe. - */ - max_coord = max_ff(max_coord, bezt->vec[1][1]); - min_coord = min_ff(min_coord, bezt->vec[1][1]); - } - else if (prev_bezt->ipo == BEZT_IPO_LIN) { - /* Linear interpolation: min/max using both previous and - * and current CV. + if (!ELEM(prev_bezt->ipo, BEZT_IPO_BEZ, BEZT_IPO_BACK, BEZT_IPO_ELASTIC)) { + /* The points on the curve will lie inside the start and end points. + * Calculate min/max using both previous and current CV. */ max_coord = max_ff(max_coord, bezt->vec[1][1]); min_coord = min_ff(min_coord, bezt->vec[1][1]); max_coord = max_ff(max_coord, prev_bezt->vec[1][1]); min_coord = min_ff(min_coord, prev_bezt->vec[1][1]); } - else if (prev_bezt->ipo == BEZT_IPO_BEZ) { + else { const int resol = fcu->driver ? 32 : min_ii((int)(5.0f * len_v2v2(bezt->vec[1], prev_bezt->vec[1])), @@ -448,30 +441,12 @@ static float normalization_factor_get(Scene *scene, FCurve *fcu, short flag, flo min_coord = min_ff(min_coord, prev_bezt->vec[1][1]); } else { - float data[120]; - float v1[2], v2[2], v3[2], v4[2]; - - v1[0] = prev_bezt->vec[1][0]; - v1[1] = prev_bezt->vec[1][1]; - v2[0] = prev_bezt->vec[2][0]; - v2[1] = prev_bezt->vec[2][1]; - - v3[0] = bezt->vec[0][0]; - v3[1] = bezt->vec[0][1]; - v4[0] = bezt->vec[1][0]; - v4[1] = bezt->vec[1][1]; - - correct_bezpart(v1, v2, v3, v4); - - BKE_curve_forward_diff_bezier( - v1[0], v2[0], v3[0], v4[0], data, resol, sizeof(float) * 3); - BKE_curve_forward_diff_bezier( - v1[1], v2[1], v3[1], v4[1], data + 1, resol, sizeof(float) * 3); - + float step_size = (bezt->vec[1][0] - prev_bezt->vec[1][0]) / resol; for (int j = 0; j <= resol; ++j) { - const float *fp = &data[j * 3]; - max_coord = max_ff(max_coord, fp[1]); - min_coord = min_ff(min_coord, fp[1]); + float eval_time = prev_bezt->vec[1][0] + step_size * j; + float eval_value = evaluate_fcurve_only_curve(fcu, eval_time); + max_coord = max_ff(max_coord, eval_value); + min_coord = min_ff(min_coord, eval_value); } } } diff --git a/source/blender/editors/animation/anim_filter.c b/source/blender/editors/animation/anim_filter.c index 2d16ce30d31..625a52fc800 100644 --- a/source/blender/editors/animation/anim_filter.c +++ b/source/blender/editors/animation/anim_filter.c @@ -412,7 +412,6 @@ bool ANIM_animdata_get_context(const bContext *C, bAnimContext *ac) if (scene) { ac->markers = ED_context_get_markers(C); } - ac->depsgraph = CTX_data_depsgraph(C); ac->view_layer = CTX_data_view_layer(C); ac->obact = (ac->view_layer->basact) ? ac->view_layer->basact->object : NULL; ac->sa = sa; diff --git a/source/blender/editors/animation/anim_ipo_utils.c b/source/blender/editors/animation/anim_ipo_utils.c index f5bd7a47248..fad9a1a8e49 100644 --- a/source/blender/editors/animation/anim_ipo_utils.c +++ b/source/blender/editors/animation/anim_ipo_utils.c @@ -238,6 +238,6 @@ void getcolor_fcurve_rainbow(int cur, int tot, float out[3]) /* value is fixed at 1.0f, otherwise we cannot clearly see the curves... */ hsv[2] = 1.0f; - /* finally, conver this to RGB colors */ + /* finally, convert this to RGB colors */ hsv_to_rgb_v(hsv, out); } diff --git a/source/blender/editors/animation/anim_markers.c b/source/blender/editors/animation/anim_markers.c index 2bbb8e5888c..ded59466370 100644 --- a/source/blender/editors/animation/anim_markers.c +++ b/source/blender/editors/animation/anim_markers.c @@ -470,7 +470,7 @@ static void draw_marker_line_if_necessary(TimeMarker *marker, int flag, int xpos } static void draw_marker( - const uiFontStyle *fstyle, TimeMarker *marker, int xpos, int flag, int region_height) + const uiFontStyle *fstyle, TimeMarker *marker, int cfra, int xpos, int flag, int region_height) { GPU_blend(true); GPU_blend_set_func_separate( @@ -484,7 +484,9 @@ static void draw_marker( GPU_blend(false); float name_y = UI_DPI_FAC * 18; - if (marker->flag & SELECT) { + /* Give an offset to the marker name when selected, + * or when near the current frame (5 frames range, starting from the current one). */ + if ((marker->flag & SELECT) || (IN_RANGE_INCL(marker->frame, cfra, cfra - 4))) { name_y += UI_DPI_FAC * 10; } draw_marker_name(fstyle, marker, xpos, name_y); @@ -547,6 +549,7 @@ void ED_markers_draw(const bContext *C, int flag) ARegion *ar = CTX_wm_region(C); View2D *v2d = UI_view2d_fromcontext(C); + int cfra = CTX_data_scene(C)->r.cfra; rctf markers_region_rect; get_marker_region_rect(v2d, &markers_region_rect); @@ -564,17 +567,18 @@ void ED_markers_draw(const bContext *C, int flag) const uiFontStyle *fstyle = UI_FSTYLE_WIDGET; + /* Separate loops in order to draw selected markers on top */ for (TimeMarker *marker = markers->first; marker; marker = marker->next) { if ((marker->flag & SELECT) == 0) { if (marker_is_in_frame_range(marker, clip_frame_range)) { - draw_marker(fstyle, marker, marker->frame * xscale, flag, ar->winy); + draw_marker(fstyle, marker, cfra, marker->frame * xscale, flag, ar->winy); } } } for (TimeMarker *marker = markers->first; marker; marker = marker->next) { if (marker->flag & SELECT) { if (marker_is_in_frame_range(marker, clip_frame_range)) { - draw_marker(fstyle, marker, marker->frame * xscale, flag, ar->winy); + draw_marker(fstyle, marker, cfra, marker->frame * xscale, flag, ar->winy); } } } diff --git a/source/blender/editors/animation/keyframing.c b/source/blender/editors/animation/keyframing.c index 2e7ed7eae34..de6e4c2fd0d 100644 --- a/source/blender/editors/animation/keyframing.c +++ b/source/blender/editors/animation/keyframing.c @@ -721,23 +721,12 @@ static short new_key_needed(FCurve *fcu, float cFrame, float nValue) /* ------------------ RNA Data-Access Functions ------------------ */ /* Try to read value using RNA-properties obtained already */ -static float *setting_get_rna_values(Depsgraph *depsgraph, - PointerRNA *ptr, - PropertyRNA *prop, - const bool get_evaluated, - float *buffer, - int buffer_size, - int *r_count) +static float *setting_get_rna_values( + PointerRNA *ptr, PropertyRNA *prop, float *buffer, int buffer_size, int *r_count) { BLI_assert(buffer_size >= 1); float *values = buffer; - PointerRNA ptr_eval; - - if (get_evaluated) { - DEG_get_evaluated_rna_pointer(depsgraph, ptr, &ptr_eval); - ptr = &ptr_eval; - } if (RNA_property_array_check(prop)) { int length = *r_count = RNA_property_array_length(ptr, prop); @@ -977,12 +966,8 @@ static bool visualkey_can_use(PointerRNA *ptr, PropertyRNA *prop) * In the event that it is not possible to perform visual keying, try to fall-back * to using the default method. Assumes that all data it has been passed is valid. */ -static float *visualkey_get_values(Depsgraph *depsgraph, - PointerRNA *ptr, - PropertyRNA *prop, - float *buffer, - int buffer_size, - int *r_count) +static float *visualkey_get_values( + PointerRNA *ptr, PropertyRNA *prop, float *buffer, int buffer_size, int *r_count) { BLI_assert(buffer_size >= 4); @@ -999,27 +984,21 @@ static float *visualkey_get_values(Depsgraph *depsgraph, */ if (ptr->type == &RNA_Object) { Object *ob = (Object *)ptr->data; - const Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); - /* Loc code is specific... */ if (strstr(identifier, "location")) { - copy_v3_v3(buffer, ob_eval->obmat[3]); + copy_v3_v3(buffer, ob->obmat[3]); *r_count = 3; return buffer; } - copy_m4_m4(tmat, ob_eval->obmat); - rotmode = ob_eval->rotmode; + copy_m4_m4(tmat, ob->obmat); + rotmode = ob->rotmode; } else if (ptr->type == &RNA_PoseBone) { - Object *ob = (Object *)ptr->id.data; bPoseChannel *pchan = (bPoseChannel *)ptr->data; - const Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); - bPoseChannel *pchan_eval = BKE_pose_channel_find_name(ob_eval->pose, pchan->name); - - BKE_armature_mat_pose_to_bone(pchan_eval, pchan_eval->pose_mat, tmat); - rotmode = pchan_eval->rotmode; + BKE_armature_mat_pose_to_bone(pchan, pchan->pose_mat, tmat); + rotmode = pchan->rotmode; /* Loc code is specific... */ if (strstr(identifier, "location")) { @@ -1032,7 +1011,7 @@ static float *visualkey_get_values(Depsgraph *depsgraph, } } else { - return setting_get_rna_values(depsgraph, ptr, prop, true, buffer, buffer_size, r_count); + return setting_get_rna_values(ptr, prop, buffer, buffer_size, r_count); } /* Rot/Scale code are common! */ @@ -1066,7 +1045,7 @@ static float *visualkey_get_values(Depsgraph *depsgraph, } /* as the function hasn't returned yet, read value from system in the default way */ - return setting_get_rna_values(depsgraph, ptr, prop, true, buffer, buffer_size, r_count); + return setting_get_rna_values(ptr, prop, buffer, buffer_size, r_count); } /* ------------------------- Insert Key API ------------------------- */ @@ -1075,8 +1054,7 @@ static float *visualkey_get_values(Depsgraph *depsgraph, * Retrieve current property values to keyframe, * possibly applying NLA correction when necessary. */ -static float *get_keyframe_values(Depsgraph *depsgraph, - ReportList *reports, +static float *get_keyframe_values(ReportList *reports, PointerRNA ptr, PropertyRNA *prop, int index, @@ -1094,11 +1072,11 @@ static float *get_keyframe_values(Depsgraph *depsgraph, * it works by keyframing using a value extracted from the final matrix * instead of using the kt system to extract a value. */ - values = visualkey_get_values(depsgraph, &ptr, prop, buffer, buffer_size, r_count); + values = visualkey_get_values(&ptr, prop, buffer, buffer_size, r_count); } else { /* read value from system */ - values = setting_get_rna_values(depsgraph, &ptr, prop, false, buffer, buffer_size, r_count); + values = setting_get_rna_values(&ptr, prop, buffer, buffer_size, r_count); } /* adjust the value for NLA factors */ @@ -1207,8 +1185,7 @@ static bool insert_keyframe_value(ReportList *reports, * the keyframe insertion. These include the 'visual' keyframing modes, quick refresh, * and extra keyframe filtering. */ -bool insert_keyframe_direct(Depsgraph *depsgraph, - ReportList *reports, +bool insert_keyframe_direct(ReportList *reports, PointerRNA ptr, PropertyRNA *prop, FCurve *fcu, @@ -1261,8 +1238,7 @@ bool insert_keyframe_direct(Depsgraph *depsgraph, int value_count; int index = fcu->array_index; - float *values = get_keyframe_values(depsgraph, - reports, + float *values = get_keyframe_values(reports, ptr, prop, index, @@ -1347,7 +1323,6 @@ static bool insert_keyframe_fcurve_value(Main *bmain, * index of -1 keys all array indices */ short insert_keyframe(Main *bmain, - Depsgraph *depsgraph, ReportList *reports, ID *id, bAction *act, @@ -1405,7 +1380,7 @@ short insert_keyframe(Main *bmain, if (adt && adt->action == act) { /* Get NLA context for value remapping. */ nla_context = BKE_animsys_get_nla_keyframing_context( - nla_cache ? nla_cache : &tmp_nla_cache, depsgraph, &id_ptr, adt, cfra); + nla_cache ? nla_cache : &tmp_nla_cache, &id_ptr, adt, cfra, false); /* Apply NLA-mapping to frame. */ cfra = BKE_nla_tweakedit_remap(adt, cfra, NLATIME_CONVERT_UNMAP); @@ -1416,8 +1391,7 @@ short insert_keyframe(Main *bmain, int value_count; bool force_all; - float *values = get_keyframe_values(depsgraph, - reports, + float *values = get_keyframe_values(reports, ptr, prop, array_index, @@ -2373,7 +2347,6 @@ void ANIM_OT_keyframe_delete_v3d(wmOperatorType *ot) static int insert_key_button_exec(bContext *C, wmOperator *op) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); ToolSettings *ts = scene->toolsettings; @@ -2407,7 +2380,7 @@ static int insert_key_button_exec(bContext *C, wmOperator *op) if (fcu) { success = insert_keyframe_direct( - depsgraph, op->reports, ptr, prop, fcu, cfra, ts->keyframe_type, NULL, 0); + op->reports, ptr, prop, fcu, cfra, ts->keyframe_type, NULL, 0); } else { BKE_report(op->reports, @@ -2423,15 +2396,8 @@ static int insert_key_button_exec(bContext *C, wmOperator *op) fcu = rna_get_fcurve_context_ui(C, &ptr, prop, index, NULL, NULL, &driven, &special); if (fcu && driven) { - success = insert_keyframe_direct(depsgraph, - op->reports, - ptr, - prop, - fcu, - cfra, - ts->keyframe_type, - NULL, - INSERTKEY_DRIVER); + success = insert_keyframe_direct( + op->reports, ptr, prop, fcu, cfra, ts->keyframe_type, NULL, INSERTKEY_DRIVER); } } else { @@ -2468,7 +2434,6 @@ static int insert_key_button_exec(bContext *C, wmOperator *op) } success = insert_keyframe(bmain, - depsgraph, op->reports, ptr.id.data, NULL, @@ -2794,8 +2759,7 @@ bool fcurve_is_changed(PointerRNA ptr, PropertyRNA *prop, FCurve *fcu, float fra float buffer[RNA_MAX_ARRAY_LENGTH]; int count, index = fcu->array_index; - float *values = setting_get_rna_values( - NULL, &ptr, prop, false, buffer, RNA_MAX_ARRAY_LENGTH, &count); + float *values = setting_get_rna_values(&ptr, prop, buffer, RNA_MAX_ARRAY_LENGTH, &count); float fcurve_val = calculate_fcurve(&anim_rna, fcu, frame); float cur_val = (index >= 0 && index < count) ? values[index] : 0.0f; diff --git a/source/blender/editors/animation/keyingsets.c b/source/blender/editors/animation/keyingsets.c index 0cb83c79c85..ccd0fc54611 100644 --- a/source/blender/editors/animation/keyingsets.c +++ b/source/blender/editors/animation/keyingsets.c @@ -1030,7 +1030,6 @@ static short keyingset_apply_keying_flags(const short base_flags, int ANIM_apply_keyingset( bContext *C, ListBase *dsources, bAction *act, KeyingSet *ks, short mode, float cfra) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); ReportList *reports = CTX_wm_reports(C); @@ -1125,7 +1124,6 @@ int ANIM_apply_keyingset( /* action to take depends on mode */ if (mode == MODIFYKEY_MODE_INSERT) { success += insert_keyframe(bmain, - depsgraph, reports, ksp->id, act, diff --git a/source/blender/editors/armature/pose_edit.c b/source/blender/editors/armature/pose_edit.c index 5daf6b584e5..8f4896c0b82 100644 --- a/source/blender/editors/armature/pose_edit.c +++ b/source/blender/editors/armature/pose_edit.c @@ -195,7 +195,9 @@ void ED_pose_recalculate_paths(bContext *C, Scene *scene, Object *ob, bool curre } Main *bmain = CTX_data_main(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + /* NOTE: Dependency graph will be evaluated at all the frames, but we first need to access some + * nested pointers, like animation data. */ + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); ListBase targets = {NULL, NULL}; bool free_depsgraph = false; @@ -384,7 +386,7 @@ void POSE_OT_paths_update(wmOperatorType *ot) ot->idname = "POSE_OT_paths_update"; ot->description = "Recalculate paths for bones that already have them"; - /* api callbakcs */ + /* api callbacks */ ot->exec = pose_update_paths_exec; ot->poll = pose_update_paths_poll; diff --git a/source/blender/editors/armature/pose_lib.c b/source/blender/editors/armature/pose_lib.c index 3407b3e6b7f..4cda7f264aa 100644 --- a/source/blender/editors/armature/pose_lib.c +++ b/source/blender/editors/armature/pose_lib.c @@ -1731,9 +1731,6 @@ static void poselib_preview_cleanup(bContext *C, wmOperator *op) if (IS_AUTOKEY_MODE(scene, NORMAL)) { // remake_action_ipos(ob->action); } - else { - BKE_pose_where_is(CTX_data_depsgraph(C), scene, ob); - } } /* Request final redraw of the view. */ diff --git a/source/blender/editors/armature/pose_slide.c b/source/blender/editors/armature/pose_slide.c index 4c5a42cade6..c8e79b879a4 100644 --- a/source/blender/editors/armature/pose_slide.c +++ b/source/blender/editors/armature/pose_slide.c @@ -1122,7 +1122,7 @@ static int pose_slide_modal(bContext *C, wmOperator *op, const wmEvent *event) break; } - /* Percentage Chane... */ + /* Percentage Change... */ case MOUSEMOVE: /* calculate new position */ { /* only handle mousemove if not doing numinput */ @@ -1373,7 +1373,7 @@ void POSE_OT_push(wmOperatorType *ot) ot->poll = ED_operator_posemode; /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING | OPTYPE_USE_EVAL_DATA; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING; /* Properties */ pose_slide_opdef_properties(ot); @@ -1435,7 +1435,7 @@ void POSE_OT_relax(wmOperatorType *ot) ot->poll = ED_operator_posemode; /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING | OPTYPE_USE_EVAL_DATA; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING; /* Properties */ pose_slide_opdef_properties(ot); @@ -1496,7 +1496,7 @@ void POSE_OT_push_rest(wmOperatorType *ot) ot->poll = ED_operator_posemode; /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING | OPTYPE_USE_EVAL_DATA; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING; /* Properties */ pose_slide_opdef_properties(ot); @@ -1558,7 +1558,7 @@ void POSE_OT_relax_rest(wmOperatorType *ot) ot->poll = ED_operator_posemode; /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING | OPTYPE_USE_EVAL_DATA; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING; /* Properties */ pose_slide_opdef_properties(ot); @@ -1620,7 +1620,7 @@ void POSE_OT_breakdown(wmOperatorType *ot) ot->poll = ED_operator_posemode; /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING | OPTYPE_USE_EVAL_DATA; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING; /* Properties */ pose_slide_opdef_properties(ot); @@ -2025,7 +2025,7 @@ void POSE_OT_propagate(wmOperatorType *ot) ot->poll = ED_operator_posemode; /* XXX: needs selected bones! */ /* flag */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ /* TODO: add "fade out" control for tapering off amount of propagation as time goes by? */ diff --git a/source/blender/editors/armature/pose_transform.c b/source/blender/editors/armature/pose_transform.c index 325e6eaee2a..854fb237929 100644 --- a/source/blender/editors/armature/pose_transform.c +++ b/source/blender/editors/armature/pose_transform.c @@ -71,7 +71,15 @@ * that are bone-parented to armature */ static void applyarmature_fix_boneparents(const bContext *C, Scene *scene, Object *armob) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + /* Depsgraph has been ensured to be evaluated at the beginning of the operator. + * + * Must not evaluate depsgraph here yet, since this will ruin object matrix which we want to + * preserve after other changes has been done in the operator. + * + * TODO(sergey): This seems very similar to `ignore_parent_tx()`, which was now ensured to work + * quite reliably. Can we de-duplicate the code? Or at least verify we don't need an extra logic + * in this function. */ + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); Main *bmain = CTX_data_main(C); Object workob, *ob; @@ -318,7 +326,7 @@ static void applyarmature_process_selected_rec(bArmature *arm, static int apply_armature_pose2bones_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene = CTX_data_scene(C); // must be active object, not edit-object Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C)); @@ -422,7 +430,7 @@ void POSE_OT_armature_apply(wmOperatorType *ot) ot->ui = apply_armature_pose2bones_ui; /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; RNA_def_boolean(ot->srna, "selected", @@ -436,7 +444,7 @@ static int pose_visual_transform_apply_exec(bContext *C, wmOperator *UNUSED(op)) { ViewLayer *view_layer = CTX_data_view_layer(C); View3D *v3d = CTX_wm_view3d(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, v3d, OB_ARMATURE, OB_MODE_POSE, ob) { /* loop over all selected pchans @@ -1026,6 +1034,7 @@ static int pose_clear_transform_generic_exec(bContext *C, void (*clear_func)(bPoseChannel *), const char default_ksName[]) { + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene = CTX_data_scene(C); bool changed_multi = false; @@ -1041,8 +1050,8 @@ static int pose_clear_transform_generic_exec(bContext *C, ViewLayer *view_layer = CTX_data_view_layer(C); View3D *v3d = CTX_wm_view3d(C); FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, v3d, OB_ARMATURE, OB_MODE_POSE, ob_iter) { - Object *ob_eval = DEG_get_evaluated_object( - CTX_data_depsgraph(C), ob_iter); // XXX: UGLY HACK (for autokey + clear transforms) + // XXX: UGLY HACK (for autokey + clear transforms) + Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob_iter); ListBase dsources = {NULL, NULL}; bool changed = false; @@ -1217,7 +1226,7 @@ static int pose_clear_user_transforms_exec(bContext *C, wmOperator *op) workob.adt = ob->adt; workob.pose = dummyPose; - BKE_animsys_evaluate_animdata(NULL, scene, &workob.id, workob.adt, cframe, ADT_RECALC_ANIM); + BKE_animsys_evaluate_animdata(scene, &workob.id, workob.adt, cframe, ADT_RECALC_ANIM, false); /* copy back values, but on selected bones only */ for (pchan = dummyPose->chanbase.first; pchan; pchan = pchan->next) { diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c index d1d43a49826..047b78af7b1 100644 --- a/source/blender/editors/curve/editcurve.c +++ b/source/blender/editors/curve/editcurve.c @@ -7094,16 +7094,17 @@ static bool match_texture_space_poll(bContext *C) static int match_texture_space_exec(bContext *C, wmOperator *UNUSED(op)) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); - Scene *scene = CTX_data_scene(C); + /* Need to ensure the dependency graph is fully evaluated, so the display list is at a correct + * state. */ + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); + (void)depsgraph; + Object *object = CTX_data_active_object(C); Curve *curve = (Curve *)object->data; float min[3], max[3], size[3], loc[3]; int a; - if (object->runtime.curve_cache == NULL) { - BKE_displist_make_curveTypes(depsgraph, scene, object, false, false); - } + BLI_assert(object->runtime.curve_cache != NULL); INIT_MINMAX(min, max); BKE_displist_minmax(&object->runtime.curve_cache->disp, min, max); diff --git a/source/blender/editors/curve/editcurve_paint.c b/source/blender/editors/curve/editcurve_paint.c index 6811e32cc2a..5e0053782d4 100644 --- a/source/blender/editors/curve/editcurve_paint.c +++ b/source/blender/editors/curve/editcurve_paint.c @@ -89,8 +89,6 @@ struct StrokeElem { }; struct CurveDrawData { - Depsgraph *depsgraph; - short init_event_type; short curve_type; @@ -578,8 +576,6 @@ static bool curve_draw_init(bContext *C, wmOperator *op, bool is_invoke) struct CurveDrawData *cdd = MEM_callocN(sizeof(*cdd), __func__); - cdd->depsgraph = CTX_data_depsgraph(C); - if (is_invoke) { ED_view3d_viewcontext_init(C, &cdd->vc); if (ELEM(NULL, cdd->vc.ar, cdd->vc.rv3d, cdd->vc.v3d, cdd->vc.win, cdd->vc.scene)) { @@ -590,7 +586,7 @@ static bool curve_draw_init(bContext *C, wmOperator *op, bool is_invoke) } else { cdd->vc.bmain = CTX_data_main(C); - cdd->vc.depsgraph = CTX_data_depsgraph(C); + cdd->vc.depsgraph = CTX_data_ensure_evaluated_depsgraph(C); cdd->vc.scene = CTX_data_scene(C); cdd->vc.view_layer = CTX_data_view_layer(C); cdd->vc.obedit = CTX_data_edit_object(C); diff --git a/source/blender/editors/curve/editfont.c b/source/blender/editors/curve/editfont.c index db3d5ad401d..c912cea5937 100644 --- a/source/blender/editors/curve/editfont.c +++ b/source/blender/editors/curve/editfont.c @@ -407,7 +407,6 @@ static int insert_into_textbuf(Object *obedit, uintptr_t c) static void text_update_edited(bContext *C, Object *obedit, int mode) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); Curve *cu = obedit->data; EditFont *ef = cu->editfont; @@ -421,6 +420,7 @@ static void text_update_edited(bContext *C, Object *obedit, int mode) else { /* depsgraph runs above, but since we're not tagging for update, call direct */ /* We need evaluated data here. */ + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); BKE_vfont_to_curve(DEG_get_evaluated_object(depsgraph, obedit), mode); } @@ -590,7 +590,7 @@ void FONT_OT_text_paste_from_file(wmOperatorType *ot) static void txt_add_object(bContext *C, TextLine *firstline, int totline, const float offset[3]) { Main *bmain = CTX_data_main(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); Curve *cu; @@ -1084,7 +1084,7 @@ static const EnumPropertyItem move_type_items[] = { static int move_cursor(bContext *C, int type, const bool select) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Object *obedit = CTX_data_edit_object(C); Curve *cu = obedit->data; EditFont *ef = cu->editfont; diff --git a/source/blender/editors/gizmo_library/gizmo_library_presets.c b/source/blender/editors/gizmo_library/gizmo_library_presets.c index ce62171ccb0..ae43894b7b6 100644 --- a/source/blender/editors/gizmo_library/gizmo_library_presets.c +++ b/source/blender/editors/gizmo_library/gizmo_library_presets.c @@ -125,6 +125,8 @@ void ED_gizmo_draw_preset_circle(const struct wmGizmo *gz, void ED_gizmo_draw_preset_facemap( const bContext *C, const struct wmGizmo *gz, Object *ob, const int facemap, int select_id) { + /* Dependency graph is supposed to be evaluated prior to draw. */ + Depsgraph *depsgraph = CTX_data_expect_evaluated_depsgraph(C); const bool is_select = (select_id != -1); const bool is_highlight = is_select && (gz->state & WM_GIZMO_STATE_HIGHLIGHT) != 0; @@ -137,7 +139,7 @@ void ED_gizmo_draw_preset_facemap( GPU_matrix_push(); GPU_matrix_mul(ob->obmat); - ED_draw_object_facemap(CTX_data_depsgraph(C), ob, color, facemap); + ED_draw_object_facemap(depsgraph, ob, color, facemap); GPU_matrix_pop(); if (is_select) { diff --git a/source/blender/editors/gizmo_library/gizmo_types/move3d_gizmo.c b/source/blender/editors/gizmo_library/gizmo_types/move3d_gizmo.c index f9ad836b054..21f779b72b1 100644 --- a/source/blender/editors/gizmo_library/gizmo_types/move3d_gizmo.c +++ b/source/blender/editors/gizmo_library/gizmo_types/move3d_gizmo.c @@ -363,7 +363,7 @@ static int gizmo_move_invoke(bContext *C, wmGizmo *gz, const wmEvent *event) inter->snap_context_v3d = ED_transform_snap_object_context_create_view3d( CTX_data_main(C), CTX_data_scene(C), - CTX_data_depsgraph(C), + CTX_data_ensure_evaluated_depsgraph(C), 0, CTX_wm_region(C), CTX_wm_view3d(C)); diff --git a/source/blender/editors/gpencil/annotate_draw.c b/source/blender/editors/gpencil/annotate_draw.c index e8f97290173..dce6ed29c05 100644 --- a/source/blender/editors/gpencil/annotate_draw.c +++ b/source/blender/editors/gpencil/annotate_draw.c @@ -924,7 +924,7 @@ static void annotation_draw_data_layers( * i.e. tGPspoints NOT bGPDspoints */ annotation_draw_stroke_buffer(gpd->runtime.sbuffer, - gpd->runtime.sbuffer_size, + gpd->runtime.sbuffer_used, lthick, dflag, gpd->runtime.sbuffer_sflag, diff --git a/source/blender/editors/gpencil/annotate_paint.c b/source/blender/editors/gpencil/annotate_paint.c index 5962d95c5af..e59e5d6a878 100644 --- a/source/blender/editors/gpencil/annotate_paint.c +++ b/source/blender/editors/gpencil/annotate_paint.c @@ -281,7 +281,7 @@ static bool gp_stroke_filtermval(tGPsdata *p, const float mval[2], float pmval[2 int dy = (int)fabsf(mval[1] - pmval[1]); /* if buffer is empty, just let this go through (i.e. so that dots will work) */ - if (p->gpd->runtime.sbuffer_size == 0) { + if (p->gpd->runtime.sbuffer_used == 0) { return true; /* check if mouse moved at least certain distance on both axes (best case) @@ -382,7 +382,7 @@ static void gp_stroke_convertcoords(tGPsdata *p, const float mval[2], float out[ static void gp_smooth_buffer(tGPsdata *p, float inf, int idx) { bGPdata *gpd = p->gpd; - short num_points = gpd->runtime.sbuffer_size; + short num_points = gpd->runtime.sbuffer_used; /* Do nothing if not enough points to smooth out */ if ((num_points < 3) || (idx < 3) || (inf == 0.0f)) { @@ -437,7 +437,7 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure /* check painting mode */ if (p->paintmode == GP_PAINTMODE_DRAW_STRAIGHT) { /* straight lines only - i.e. only store start and end point in buffer */ - if (gpd->runtime.sbuffer_size == 0) { + if (gpd->runtime.sbuffer_used == 0) { /* first point in buffer (start point) */ pt = (tGPspoint *)(gpd->runtime.sbuffer); @@ -449,7 +449,7 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure pt->time = (float)(curtime - p->inittime); /* increment buffer size */ - gpd->runtime.sbuffer_size++; + gpd->runtime.sbuffer_used++; } else { /* just reset the endpoint to the latest value @@ -465,20 +465,19 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure pt->time = (float)(curtime - p->inittime); /* now the buffer has 2 points (and shouldn't be allowed to get any larger) */ - gpd->runtime.sbuffer_size = 2; + gpd->runtime.sbuffer_used = 2; } /* can keep carrying on this way :) */ return GP_STROKEADD_NORMAL; } else if (p->paintmode == GP_PAINTMODE_DRAW) { /* normal drawing */ - /* check if still room in buffer */ - if (gpd->runtime.sbuffer_size >= GP_STROKE_BUFFER_MAX) { - return GP_STROKEADD_OVERFLOW; - } + /* check if still room in buffer or add more */ + gpd->runtime.sbuffer = ED_gpencil_sbuffer_ensure( + gpd->runtime.sbuffer, &gpd->runtime.sbuffer_size, &gpd->runtime.sbuffer_used, false); /* get pointer to destination point */ - pt = ((tGPspoint *)(gpd->runtime.sbuffer) + gpd->runtime.sbuffer_size); + pt = ((tGPspoint *)(gpd->runtime.sbuffer) + gpd->runtime.sbuffer_used); /* store settings */ copy_v2_v2(&pt->x, mval); @@ -490,19 +489,13 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure pt->time = (float)(curtime - p->inittime); /* increment counters */ - gpd->runtime.sbuffer_size++; + gpd->runtime.sbuffer_used++; /* smooth while drawing previous points with a reduction factor for previous */ for (int s = 0; s < 3; s++) { - gp_smooth_buffer(p, 0.5f * ((3.0f - s) / 3.0f), gpd->runtime.sbuffer_size - s); + gp_smooth_buffer(p, 0.5f * ((3.0f - s) / 3.0f), gpd->runtime.sbuffer_used - s); } - /* check if another operation can still occur */ - if (gpd->runtime.sbuffer_size == GP_STROKE_BUFFER_MAX) { - return GP_STROKEADD_FULL; - } - else { - return GP_STROKEADD_NORMAL; - } + return GP_STROKEADD_NORMAL; } else if (p->paintmode == GP_PAINTMODE_DRAW_POLY) { /* get pointer to destination point */ @@ -524,7 +517,7 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure bGPDspoint *pts; /* first time point is adding to temporary buffer -- need to allocate new point in stroke */ - if (gpd->runtime.sbuffer_size == 0) { + if (gpd->runtime.sbuffer_used == 0) { gps->points = MEM_reallocN(gps->points, sizeof(bGPDspoint) * (gps->totpoints + 1)); gps->totpoints++; } @@ -557,8 +550,8 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure } /* increment counters */ - if (gpd->runtime.sbuffer_size == 0) { - gpd->runtime.sbuffer_size++; + if (gpd->runtime.sbuffer_used == 0) { + gpd->runtime.sbuffer_used++; } return GP_STROKEADD_NORMAL; @@ -576,7 +569,7 @@ static void gp_stroke_simplify(tGPsdata *p) { bGPdata *gpd = p->gpd; tGPspoint *old_points = (tGPspoint *)gpd->runtime.sbuffer; - short num_points = gpd->runtime.sbuffer_size; + short num_points = gpd->runtime.sbuffer_used; short flag = gpd->runtime.sbuffer_sflag; short i, j; @@ -668,17 +661,17 @@ static void gp_stroke_newfrombuffer(tGPsdata *p) * - drawing straight-lines only requires the endpoints */ if (p->paintmode == GP_PAINTMODE_DRAW_STRAIGHT) { - totelem = (gpd->runtime.sbuffer_size >= 2) ? 2 : gpd->runtime.sbuffer_size; + totelem = (gpd->runtime.sbuffer_used >= 2) ? 2 : gpd->runtime.sbuffer_used; } else { - totelem = gpd->runtime.sbuffer_size; + totelem = gpd->runtime.sbuffer_used; } /* exit with error if no valid points from this stroke */ if (totelem == 0) { if (G.debug & G_DEBUG) { printf("Error: No valid points in stroke buffer to convert (tot=%d)\n", - gpd->runtime.sbuffer_size); + gpd->runtime.sbuffer_used); } return; } @@ -736,7 +729,7 @@ static void gp_stroke_newfrombuffer(tGPsdata *p) if (totelem == 2) { /* last point if applicable */ - ptc = ((tGPspoint *)gpd->runtime.sbuffer) + (gpd->runtime.sbuffer_size - 1); + ptc = ((tGPspoint *)gpd->runtime.sbuffer) + (gpd->runtime.sbuffer_used - 1); /* convert screen-coordinates to appropriate coordinates (and store them) */ gp_stroke_convertcoords(p, &ptc->x, &pt->x, NULL); @@ -769,9 +762,9 @@ static void gp_stroke_newfrombuffer(tGPsdata *p) int interp_depth = 0; int found_depth = 0; - depth_arr = MEM_mallocN(sizeof(float) * gpd->runtime.sbuffer_size, "depth_points"); + depth_arr = MEM_mallocN(sizeof(float) * gpd->runtime.sbuffer_used, "depth_points"); - for (i = 0, ptc = gpd->runtime.sbuffer; i < gpd->runtime.sbuffer_size; i++, ptc++, pt++) { + for (i = 0, ptc = gpd->runtime.sbuffer; i < gpd->runtime.sbuffer_used; i++, ptc++, pt++) { round_v2i_v2fl(mval_i, &ptc->x); if ((ED_view3d_autodist_depth(p->ar, mval_i, depth_margin, depth_arr + i) == 0) && @@ -788,7 +781,7 @@ static void gp_stroke_newfrombuffer(tGPsdata *p) if (found_depth == false) { /* eeh... not much we can do.. :/, ignore depth in this case, use the 3D cursor */ - for (i = gpd->runtime.sbuffer_size - 1; i >= 0; i--) { + for (i = gpd->runtime.sbuffer_used - 1; i >= 0; i--) { depth_arr[i] = 0.9999f; } } @@ -798,14 +791,14 @@ static void gp_stroke_newfrombuffer(tGPsdata *p) int first_valid = 0; int last_valid = 0; - for (i = 0; i < gpd->runtime.sbuffer_size; i++) { + for (i = 0; i < gpd->runtime.sbuffer_used; i++) { if (depth_arr[i] != FLT_MAX) { break; } } first_valid = i; - for (i = gpd->runtime.sbuffer_size - 1; i >= 0; i--) { + for (i = gpd->runtime.sbuffer_used - 1; i >= 0; i--) { if (depth_arr[i] != FLT_MAX) { break; } @@ -821,7 +814,7 @@ static void gp_stroke_newfrombuffer(tGPsdata *p) } if (interp_depth) { - interp_sparse_array(depth_arr, gpd->runtime.sbuffer_size, FLT_MAX); + interp_sparse_array(depth_arr, gpd->runtime.sbuffer_used, FLT_MAX); } } } @@ -829,7 +822,7 @@ static void gp_stroke_newfrombuffer(tGPsdata *p) pt = gps->points; /* convert all points (normal behavior) */ - for (i = 0, ptc = gpd->runtime.sbuffer; i < gpd->runtime.sbuffer_size && ptc; + for (i = 0, ptc = gpd->runtime.sbuffer; i < gpd->runtime.sbuffer_used && ptc; i++, ptc++, pt++) { /* convert screen-coordinates to appropriate coordinates (and store them) */ gp_stroke_convertcoords(p, &ptc->x, &pt->x, depth_arr ? depth_arr + i : NULL); @@ -1049,19 +1042,8 @@ static void gp_session_validatebuffer(tGPsdata *p) { bGPdata *gpd = p->gpd; - /* clear memory of buffer (or allocate it if starting a new session) */ - if (gpd->runtime.sbuffer) { - /* printf("\t\tGP - reset sbuffer\n"); */ - memset(gpd->runtime.sbuffer, 0, sizeof(tGPspoint) * GP_STROKE_BUFFER_MAX); - } - else { - /* printf("\t\tGP - allocate sbuffer\n"); */ - gpd->runtime.sbuffer = MEM_callocN(sizeof(tGPspoint) * GP_STROKE_BUFFER_MAX, - "gp_session_strokebuffer"); - } - - /* reset indices */ - gpd->runtime.sbuffer_size = 0; + gpd->runtime.sbuffer = ED_gpencil_sbuffer_ensure( + gpd->runtime.sbuffer, &gpd->runtime.sbuffer_size, &gpd->runtime.sbuffer_used, true); /* reset flags */ gpd->runtime.sbuffer_sflag = 0; @@ -1091,7 +1073,7 @@ static bool gp_session_initdata(bContext *C, tGPsdata *p) /* pass on current scene and window */ p->bmain = CTX_data_main(C); p->scene = CTX_data_scene(C); - p->depsgraph = CTX_data_depsgraph(C); + p->depsgraph = CTX_data_ensure_evaluated_depsgraph(C); p->win = CTX_wm_window(C); unit_m4(p->imat); @@ -1295,6 +1277,7 @@ static void gp_session_cleanup(tGPsdata *p) } /* clear flags */ + gpd->runtime.sbuffer_used = 0; gpd->runtime.sbuffer_size = 0; gpd->runtime.sbuffer_sflag = 0; p->inittime = 0.0; @@ -1647,7 +1630,7 @@ static int gpencil_draw_init(bContext *C, wmOperator *op, const wmEvent *event) } /* init painting data */ - gp_paint_initstroke(p, paintmode, CTX_data_depsgraph(C)); + gp_paint_initstroke(p, paintmode, CTX_data_ensure_evaluated_depsgraph(C)); if (p->status == GP_STATUS_ERROR) { gpencil_draw_exit(C, op); return 0; @@ -1920,7 +1903,7 @@ static void annotation_draw_apply_event( static int gpencil_draw_exec(bContext *C, wmOperator *op) { tGPsdata *p = NULL; - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); /* printf("GPencil - Starting Re-Drawing\n"); */ @@ -2074,7 +2057,7 @@ static int gpencil_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event p->status = GP_STATUS_PAINTING; /* handle the initial drawing - i.e. for just doing a simple dot */ - annotation_draw_apply_event(op, event, CTX_data_depsgraph(C), 0.0f, 0.0f); + annotation_draw_apply_event(op, event, CTX_data_ensure_evaluated_depsgraph(C), 0.0f, 0.0f); op->flag |= OP_IS_MODAL_CURSOR_REGION; } else { @@ -2115,7 +2098,7 @@ static tGPsdata *gpencil_stroke_begin(bContext *C, wmOperator *op) * it'd be nice to allow changing paint-mode when in sketching-sessions */ if (gp_session_initdata(C, p)) { - gp_paint_initstroke(p, p->paintmode, CTX_data_depsgraph(C)); + gp_paint_initstroke(p, p->paintmode, CTX_data_ensure_evaluated_depsgraph(C)); } if (p->status != GP_STATUS_ERROR) { @@ -2150,6 +2133,7 @@ static void annotation_add_missing_events(bContext *C, const wmEvent *event, tGPsdata *p) { + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); float pt[2], a[2], b[2]; float factor = 10.0f; @@ -2165,7 +2149,7 @@ static void annotation_add_missing_events(bContext *C, interp_v2_v2v2(pt, a, b, 0.5f); sub_v2_v2v2(pt, b, pt); /* create fake event */ - annotation_draw_apply_event(op, event, CTX_data_depsgraph(C), pt[0], pt[1]); + annotation_draw_apply_event(op, event, depsgraph, pt[0], pt[1]); } else if (dist >= factor) { int slices = 2 + (int)((dist - 1.0) / factor); @@ -2174,7 +2158,7 @@ static void annotation_add_missing_events(bContext *C, interp_v2_v2v2(pt, a, b, n * i); sub_v2_v2v2(pt, b, pt); /* create fake event */ - annotation_draw_apply_event(op, event, CTX_data_depsgraph(C), pt[0], pt[1]); + annotation_draw_apply_event(op, event, depsgraph, pt[0], pt[1]); } } } @@ -2404,7 +2388,8 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event) annotation_add_missing_events(C, op, event, p); } - annotation_draw_apply_event(op, event, CTX_data_depsgraph(C), 0.0f, 0.0f); + /* TODO(sergey): Possibly evaluating dependency graph from modal operator? */ + annotation_draw_apply_event(op, event, CTX_data_ensure_evaluated_depsgraph(C), 0.0f, 0.0f); /* finish painting operation if anything went wrong just now */ if (p->status == GP_STATUS_ERROR) { diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c index 809acc3b322..0c2af982279 100644 --- a/source/blender/editors/gpencil/drawgpencil.c +++ b/source/blender/editors/gpencil/drawgpencil.c @@ -1117,7 +1117,8 @@ void ED_gp_draw_interpolation(const bContext *C, tGPDinterpolate *tgpi, const in RegionView3D *rv3d = ar->regiondata; tGPDinterpolate_layer *tgpil; Object *obact = CTX_data_active_object(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + /* Drawing code is expected to run with fully evaluated depsgraph. */ + Depsgraph *depsgraph = CTX_data_expect_evaluated_depsgraph(C); float color[4]; diff --git a/source/blender/editors/gpencil/gpencil_add_monkey.c b/source/blender/editors/gpencil/gpencil_add_monkey.c index 4d62d169bf8..c4528518009 100644 --- a/source/blender/editors/gpencil/gpencil_add_monkey.c +++ b/source/blender/editors/gpencil/gpencil_add_monkey.c @@ -829,8 +829,7 @@ static const ColorTemplate gp_monkey_pct_pupils = { void ED_gpencil_create_monkey(bContext *C, Object *ob, float mat[4][4]) { Main *bmain = CTX_data_main(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); - int cfra_eval = (int)DEG_get_ctime(depsgraph); + Scene *scene = CTX_data_scene(C); bGPdata *gpd = (bGPdata *)ob->data; bGPDstroke *gps; @@ -852,8 +851,8 @@ void ED_gpencil_create_monkey(bContext *C, Object *ob, float mat[4][4]) /* frames */ /* NOTE: No need to check for existing, as this will take care of it for us */ - bGPDframe *frameFills = BKE_gpencil_frame_addnew(Fills, cfra_eval); - bGPDframe *frameLines = BKE_gpencil_frame_addnew(Lines, cfra_eval); + bGPDframe *frameFills = BKE_gpencil_frame_addnew(Fills, CFRA); + bGPDframe *frameLines = BKE_gpencil_frame_addnew(Lines, CFRA); /* generate strokes */ gps = BKE_gpencil_add_stroke(frameFills, color_Skin, 270, 75); diff --git a/source/blender/editors/gpencil/gpencil_add_stroke.c b/source/blender/editors/gpencil/gpencil_add_stroke.c index f6ff5ed4f13..80e239c9ae5 100644 --- a/source/blender/editors/gpencil/gpencil_add_stroke.c +++ b/source/blender/editors/gpencil/gpencil_add_stroke.c @@ -215,8 +215,7 @@ static const ColorTemplate gp_stroke_material_grey = { void ED_gpencil_create_stroke(bContext *C, Object *ob, float mat[4][4]) { Main *bmain = CTX_data_main(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); - int cfra_eval = (int)DEG_get_ctime(depsgraph); + Scene *scene = CTX_data_scene(C); bGPdata *gpd = (bGPdata *)ob->data; bGPDstroke *gps; @@ -236,8 +235,8 @@ void ED_gpencil_create_stroke(bContext *C, Object *ob, float mat[4][4]) bGPDlayer *lines = BKE_gpencil_layer_addnew(gpd, "Lines", true); /* frames */ - bGPDframe *frame_color = BKE_gpencil_frame_addnew(colors, cfra_eval); - bGPDframe *frame_lines = BKE_gpencil_frame_addnew(lines, cfra_eval); + bGPDframe *frame_color = BKE_gpencil_frame_addnew(colors, CFRA); + bGPDframe *frame_lines = BKE_gpencil_frame_addnew(lines, CFRA); UNUSED_VARS(frame_color); /* generate stroke */ diff --git a/source/blender/editors/gpencil/gpencil_armature.c b/source/blender/editors/gpencil/gpencil_armature.c index 08f752bb72e..9e70be323eb 100644 --- a/source/blender/editors/gpencil/gpencil_armature.c +++ b/source/blender/editors/gpencil/gpencil_armature.c @@ -554,7 +554,7 @@ static bool gpencil_generate_weights_poll(bContext *C) static int gpencil_generate_weights_exec(bContext *C, wmOperator *op) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); ViewLayer *view_layer = CTX_data_view_layer(C); Object *ob = CTX_data_active_object(C); Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); diff --git a/source/blender/editors/gpencil/gpencil_brush.c b/source/blender/editors/gpencil/gpencil_brush.c index 7d866aedd87..1a7422cd174 100644 --- a/source/blender/editors/gpencil/gpencil_brush.c +++ b/source/blender/editors/gpencil/gpencil_brush.c @@ -87,7 +87,6 @@ typedef struct tGP_BrushEditData { /* Current editor/region/etc. */ /* NOTE: This stuff is mainly needed to handle 3D view projection stuff... */ - Depsgraph *depsgraph; struct Main *bmain; Scene *scene; Object *object; @@ -1051,11 +1050,8 @@ static void gp_brush_clone_add(bContext *C, tGP_BrushEditData *gso) tGPSB_CloneBrushData *data = gso->customdata; Object *ob = CTX_data_active_object(C); - bGPDlayer *gpl = CTX_data_active_gpencil_layer(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); - int cfra_eval = (int)DEG_get_ctime(depsgraph); - - bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, cfra_eval, GP_GETFRAME_ADD_NEW); + bGPdata *gpd = (bGPdata *)ob->data; + Scene *scene = CTX_data_scene(C); bGPDstroke *gps; float delta[3]; @@ -1074,6 +1070,18 @@ static void gp_brush_clone_add(bContext *C, tGP_BrushEditData *gso) bGPDspoint *pt; int i; + bGPDlayer *gpl = NULL; + /* Try to use original layer. */ + if (gps->runtime.tmp_layerinfo != NULL) { + gpl = BLI_findstring(&gpd->layers, gps->runtime.tmp_layerinfo, offsetof(bGPDlayer, info)); + } + + /* if not available, use active layer. */ + if (gpl == NULL) { + gpl = CTX_data_active_gpencil_layer(C); + } + bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, CFRA, GP_GETFRAME_ADD_NEW); + /* Make a new stroke */ new_stroke = MEM_dupallocN(gps); @@ -1088,10 +1096,10 @@ static void gp_brush_clone_add(bContext *C, tGP_BrushEditData *gso) BLI_addtail(&gpf->strokes, new_stroke); /* Fix color references */ - Material *ma = BLI_ghash_lookup(data->new_colors, &new_stroke->mat_nr); - gps->mat_nr = BKE_gpencil_object_material_get_index(ob, ma); - if (!ma || gps->mat_nr) { - gps->mat_nr = 0; + Material *ma = BLI_ghash_lookup(data->new_colors, POINTER_FROM_INT(new_stroke->mat_nr)); + new_stroke->mat_nr = BKE_gpencil_object_material_get_index(ob, ma); + if (!ma || new_stroke->mat_nr < 0) { + new_stroke->mat_nr = 0; } /* Adjust all the stroke's points, so that the strokes * get pasted relative to where the cursor is now @@ -1224,7 +1232,6 @@ static bool gpsculpt_brush_init(bContext *C, wmOperator *op) gso = MEM_callocN(sizeof(tGP_BrushEditData), "tGP_BrushEditData"); op->customdata = gso; - gso->depsgraph = CTX_data_depsgraph(C); gso->bmain = CTX_data_main(C); /* store state */ gso->settings = gpsculpt_get_settings(scene); @@ -1400,10 +1407,11 @@ static void gpsculpt_brush_init_stroke(tGP_BrushEditData *gso) bGPdata *gpd = gso->gpd; bGPDlayer *gpl; - int cfra_eval = (int)DEG_get_ctime(gso->depsgraph); + Scene *scene = gso->scene; + int cfra = CFRA; /* only try to add a new frame if this is the first stroke, or the frame has changed */ - if ((gpd == NULL) || (cfra_eval == gso->cfra)) { + if ((gpd == NULL) || (cfra == gso->cfra)) { return; } @@ -1419,14 +1427,14 @@ static void gpsculpt_brush_init_stroke(tGP_BrushEditData *gso) * spent too much time editing the wrong frame. */ // XXX: should this be allowed when framelock is enabled? - if (gpf->framenum != cfra_eval) { - BKE_gpencil_frame_addcopy(gpl, cfra_eval); + if (gpf->framenum != cfra) { + BKE_gpencil_frame_addcopy(gpl, cfra); } } } /* save off new current frame, so that next update works fine */ - gso->cfra = cfra_eval; + gso->cfra = cfra; } /* Apply ----------------------------------------------- */ @@ -1478,7 +1486,7 @@ static bool gpsculpt_brush_do_stroke(tGP_BrushEditData *gso, /* Skip if neither one is selected * (and we are only allowed to edit/consider selected points) */ - if (gso->settings->flag & GP_SCULPT_SETT_FLAG_SELECT_MASK) { + if ((gso->settings->flag & GP_SCULPT_SETT_FLAG_SELECT_MASK) && (!gso->is_weight_mode)) { if (!(pt1->flag & GP_SPOINT_SELECT) && !(pt2->flag & GP_SPOINT_SELECT)) { include_last = false; continue; @@ -1642,7 +1650,7 @@ static bool gpsculpt_brush_do_frame( static bool gpsculpt_brush_apply_standard(bContext *C, tGP_BrushEditData *gso) { ToolSettings *ts = CTX_data_tool_settings(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Object *obact = gso->object; bGPdata *gpd = gso->gpd; bool changed = false; diff --git a/source/blender/editors/gpencil/gpencil_convert.c b/source/blender/editors/gpencil/gpencil_convert.c index 5afa379e04f..4a91a90c075 100644 --- a/source/blender/editors/gpencil/gpencil_convert.c +++ b/source/blender/editors/gpencil/gpencil_convert.c @@ -162,7 +162,10 @@ static void gp_strokepoint_convertcoords(bContext *C, Scene *scene = CTX_data_scene(C); View3D *v3d = CTX_wm_view3d(C); ARegion *ar = CTX_wm_region(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + /* TODO(sergey): This function might be called from a loop, but no tagging is happening in it, + * so it's not that expensive to ensure evaluated depsgraph here. However, ideally all the + * parameters are to wrapped into a context style struct and queried from Context once.*/ + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Object *obact = CTX_data_active_object(C); bGPDspoint mypt, *pt; @@ -387,8 +390,7 @@ static void gp_stroke_path_animation_preprocess_gaps(tGpTimingData *gtd, } } -static void gp_stroke_path_animation_add_keyframes(Depsgraph *depsgraph, - ReportList *reports, +static void gp_stroke_path_animation_add_keyframes(ReportList *reports, PointerRNA ptr, PropertyRNA *prop, FCurve *fcu, @@ -446,7 +448,7 @@ static void gp_stroke_path_animation_add_keyframes(Depsgraph *depsgraph, cfra = last_valid_time + MIN_TIME_DELTA; } insert_keyframe_direct( - depsgraph, reports, ptr, prop, fcu, cfra, BEZT_KEYTYPE_KEYFRAME, NULL, INSERTKEY_FAST); + reports, ptr, prop, fcu, cfra, BEZT_KEYTYPE_KEYFRAME, NULL, INSERTKEY_FAST); last_valid_time = cfra; } else if (G.debug & G_DEBUG) { @@ -459,7 +461,7 @@ static void gp_stroke_path_animation_add_keyframes(Depsgraph *depsgraph, cfra = last_valid_time + MIN_TIME_DELTA; } insert_keyframe_direct( - depsgraph, reports, ptr, prop, fcu, cfra, BEZT_KEYTYPE_KEYFRAME, NULL, INSERTKEY_FAST); + reports, ptr, prop, fcu, cfra, BEZT_KEYTYPE_KEYFRAME, NULL, INSERTKEY_FAST); last_valid_time = cfra; } else { @@ -467,15 +469,8 @@ static void gp_stroke_path_animation_add_keyframes(Depsgraph *depsgraph, * and also far enough from (not yet added!) end_stroke keyframe! */ if ((cfra - last_valid_time) > MIN_TIME_DELTA && (end_stroke_time - cfra) > MIN_TIME_DELTA) { - insert_keyframe_direct(depsgraph, - reports, - ptr, - prop, - fcu, - cfra, - BEZT_KEYTYPE_BREAKDOWN, - NULL, - INSERTKEY_FAST); + insert_keyframe_direct( + reports, ptr, prop, fcu, cfra, BEZT_KEYTYPE_BREAKDOWN, NULL, INSERTKEY_FAST); last_valid_time = cfra; } else if (G.debug & G_DEBUG) { @@ -493,7 +488,6 @@ static void gp_stroke_path_animation(bContext *C, Curve *cu, tGpTimingData *gtd) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); bAction *act; @@ -538,7 +532,7 @@ static void gp_stroke_path_animation(bContext *C, cu->ctime = 0.0f; cfra = (float)gtd->start_frame; insert_keyframe_direct( - depsgraph, reports, ptr, prop, fcu, cfra, BEZT_KEYTYPE_KEYFRAME, NULL, INSERTKEY_FAST); + reports, ptr, prop, fcu, cfra, BEZT_KEYTYPE_KEYFRAME, NULL, INSERTKEY_FAST); cu->ctime = cu->pathlen; if (gtd->realtime) { @@ -548,7 +542,7 @@ static void gp_stroke_path_animation(bContext *C, cfra = (float)gtd->end_frame; } insert_keyframe_direct( - depsgraph, reports, ptr, prop, fcu, cfra, BEZT_KEYTYPE_KEYFRAME, NULL, INSERTKEY_FAST); + reports, ptr, prop, fcu, cfra, BEZT_KEYTYPE_KEYFRAME, NULL, INSERTKEY_FAST); } else { /* Use actual recorded timing! */ @@ -575,7 +569,7 @@ static void gp_stroke_path_animation(bContext *C, } gp_stroke_path_animation_add_keyframes( - depsgraph, reports, ptr, prop, fcu, cu, gtd, rng, time_range, nbr_gaps, tot_gaps_time); + reports, ptr, prop, fcu, cu, gtd, rng, time_range, nbr_gaps, tot_gaps_time); BLI_rng_free(rng); } @@ -1250,7 +1244,7 @@ static int gp_camera_view_subrect(bContext *C, rctf *subrect) /* for camera view set the subrect */ if (rv3d->persp == RV3D_CAMOB) { Scene *scene = CTX_data_scene(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); ED_view3d_calc_camera_border(scene, depsgraph, ar, v3d, rv3d, subrect, true); return 1; } @@ -1274,10 +1268,9 @@ static void gp_layer_to_curve(bContext *C, struct Main *bmain = CTX_data_main(C); ViewLayer *view_layer = CTX_data_view_layer(C); Collection *collection = CTX_data_collection(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); - int cfra_eval = (int)DEG_get_ctime(depsgraph); + Scene *scene = CTX_data_scene(C); - bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, cfra_eval, GP_GETFRAME_USE_PREV); + bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, CFRA, GP_GETFRAME_USE_PREV); bGPDstroke *gps, *prev_gps = NULL; Object *ob; Curve *cu; @@ -1406,8 +1399,7 @@ static void gp_layer_to_curve(bContext *C, */ static bool gp_convert_check_has_valid_timing(bContext *C, bGPDlayer *gpl, wmOperator *op) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); - int cfra_eval = (int)DEG_get_ctime(depsgraph); + Scene *scene = CTX_data_scene(C); bGPDframe *gpf = NULL; bGPDstroke *gps = NULL; @@ -1416,7 +1408,7 @@ static bool gp_convert_check_has_valid_timing(bContext *C, bGPDlayer *gpl, wmOpe int i; bool valid = true; - if (!gpl || !(gpf = BKE_gpencil_layer_getframe(gpl, cfra_eval, GP_GETFRAME_USE_PREV)) || + if (!gpl || !(gpf = BKE_gpencil_layer_getframe(gpl, CFRA, GP_GETFRAME_USE_PREV)) || !(gps = gpf->strokes.first)) { return false; } @@ -1468,8 +1460,7 @@ static void gp_convert_set_end_frame(struct Main *UNUSED(main), static bool gp_convert_poll(bContext *C) { Object *ob = CTX_data_active_object(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); - int cfra_eval = (int)DEG_get_ctime(depsgraph); + Scene *scene = CTX_data_scene(C); if ((ob == NULL) || (ob->type != OB_GPENCIL)) { return false; @@ -1484,7 +1475,7 @@ static bool gp_convert_poll(bContext *C) * and if we are not in edit mode! */ return ((sa && sa->spacetype == SPACE_VIEW3D) && (gpl = BKE_gpencil_layer_getactive(gpd)) && - (gpf = BKE_gpencil_layer_getframe(gpl, cfra_eval, GP_GETFRAME_USE_PREV)) && + (gpf = BKE_gpencil_layer_getframe(gpl, CFRA, GP_GETFRAME_USE_PREV)) && (gpf->strokes.first) && (!GPENCIL_ANY_EDIT_MODE(gpd))); } diff --git a/source/blender/editors/gpencil/gpencil_data.c b/source/blender/editors/gpencil/gpencil_data.c index 90a2b2d613c..696c98c6646 100644 --- a/source/blender/editors/gpencil/gpencil_data.c +++ b/source/blender/editors/gpencil/gpencil_data.c @@ -594,8 +594,7 @@ static int gp_frame_duplicate_exec(bContext *C, wmOperator *op) { bGPdata *gpd = ED_gpencil_data_get_active(C); bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd); - Depsgraph *depsgraph = CTX_data_depsgraph(C); - int cfra_eval = (int)DEG_get_ctime(depsgraph); + Scene *scene = CTX_data_scene(C); int mode = RNA_enum_get(op->ptr, "mode"); @@ -605,12 +604,12 @@ static int gp_frame_duplicate_exec(bContext *C, wmOperator *op) } if (mode == 0) { - BKE_gpencil_frame_addcopy(gpl, cfra_eval); + BKE_gpencil_frame_addcopy(gpl, CFRA); } else { for (gpl = gpd->layers.first; gpl; gpl = gpl->next) { if ((gpl->flag & GP_LAYER_LOCKED) == 0) { - BKE_gpencil_frame_addcopy(gpl, cfra_eval); + BKE_gpencil_frame_addcopy(gpl, CFRA); } } } @@ -2201,7 +2200,7 @@ int ED_gpencil_join_objects_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Object *ob_active = CTX_data_active_object(C); bGPdata *gpd_dst = NULL; bool ok = false; diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c index 0c1c24a9432..c6d0d6e3ce2 100644 --- a/source/blender/editors/gpencil/gpencil_edit.c +++ b/source/blender/editors/gpencil/gpencil_edit.c @@ -139,7 +139,6 @@ static int gpencil_editmode_toggle_exec(bContext *C, wmOperator *op) const int back = RNA_boolean_get(op->ptr, "back"); struct wmMsgBus *mbus = CTX_wm_message_bus(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); bGPdata *gpd = ED_gpencil_data_get_active(C); bool is_object = false; short mode; @@ -159,6 +158,7 @@ static int gpencil_editmode_toggle_exec(bContext *C, wmOperator *op) gpd->flag ^= GP_DATA_STROKE_EDITMODE; /* recalculate parent matrix */ if (gpd->flag & GP_DATA_STROKE_EDITMODE) { + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); ED_gpencil_reset_layers_parent(depsgraph, ob, gpd); } /* set mode */ @@ -1237,8 +1237,7 @@ static int gp_strokes_paste_exec(bContext *C, wmOperator *op) Object *ob = CTX_data_active_object(C); bGPdata *gpd = ED_gpencil_data_get_active(C); bGPDlayer *gpl = CTX_data_active_gpencil_layer(C); /* only use active for copy merge */ - Depsgraph *depsgraph = CTX_data_depsgraph(C); - int cfra_eval = (int)DEG_get_ctime(depsgraph); + Scene *scene = CTX_data_scene(C); bGPDframe *gpf; eGP_PasteMode type = RNA_enum_get(op->ptr, "type"); @@ -1329,7 +1328,7 @@ static int gp_strokes_paste_exec(bContext *C, wmOperator *op) * we are obliged to add a new frame if one * doesn't exist already */ - gpf = BKE_gpencil_layer_getframe(gpl, cfra_eval, GP_GETFRAME_ADD_NEW); + gpf = BKE_gpencil_layer_getframe(gpl, CFRA, GP_GETFRAME_ADD_NEW); if (gpf) { /* Create new stroke */ bGPDstroke *new_stroke = MEM_dupallocN(gps); @@ -1382,7 +1381,7 @@ void GPENCIL_OT_paste(wmOperatorType *ot) ot->poll = gp_strokes_paste_poll; /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ ot->prop = RNA_def_enum(ot->srna, "type", copy_type, 0, "Type", ""); @@ -1408,8 +1407,7 @@ static int gp_move_to_layer_invoke(bContext *C, wmOperator *op, const wmEvent *U static int gp_move_to_layer_exec(bContext *C, wmOperator *op) { bGPdata *gpd = CTX_data_gpencil_data(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); - int cfra_eval = (int)DEG_get_ctime(depsgraph); + Scene *scene = CTX_data_scene(C); bGPDlayer *target_layer = NULL; ListBase strokes = {NULL, NULL}; int layer_num = RNA_enum_get(op->ptr, "layer"); @@ -1482,7 +1480,7 @@ static int gp_move_to_layer_exec(bContext *C, wmOperator *op) /* Paste them all in one go */ if (strokes.first) { - bGPDframe *gpf = BKE_gpencil_layer_getframe(target_layer, cfra_eval, GP_GETFRAME_ADD_NEW); + bGPDframe *gpf = BKE_gpencil_layer_getframe(target_layer, CFRA, GP_GETFRAME_ADD_NEW); BLI_movelisttolist(&gpf->strokes, &strokes); BLI_assert((strokes.first == strokes.last) && (strokes.first == NULL)); @@ -1545,8 +1543,8 @@ static bool UNUSED_FUNCTION(gp_blank_frame_add_poll)(bContext *C) static int gp_blank_frame_add_exec(bContext *C, wmOperator *op) { bGPdata *gpd = ED_gpencil_data_get_active(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); - int cfra_eval = (int)DEG_get_ctime(depsgraph); + Scene *scene = CTX_data_scene(C); + int cfra = CFRA; bGPDlayer *active_gpl = BKE_gpencil_layer_getactive(gpd); @@ -1568,7 +1566,7 @@ static int gp_blank_frame_add_exec(bContext *C, wmOperator *op) } /* 1) Check for an existing frame on the current frame */ - bGPDframe *gpf = BKE_gpencil_layer_find_frame(gpl, cfra_eval); + bGPDframe *gpf = BKE_gpencil_layer_find_frame(gpl, cfra); if (gpf) { /* Shunt all frames after (and including) the existing one later by 1-frame */ for (; gpf; gpf = gpf->next) { @@ -1577,7 +1575,7 @@ static int gp_blank_frame_add_exec(bContext *C, wmOperator *op) } /* 2) Now add a new frame, with nothing in it */ - gpl->actframe = BKE_gpencil_layer_getframe(gpl, cfra_eval, GP_GETFRAME_ADD_NEW); + gpl->actframe = BKE_gpencil_layer_getframe(gpl, cfra, GP_GETFRAME_ADD_NEW); } CTX_DATA_END; @@ -1627,10 +1625,9 @@ static int gp_actframe_delete_exec(bContext *C, wmOperator *op) bGPdata *gpd = ED_gpencil_data_get_active(C); bGPDlayer *gpl = BKE_gpencil_layer_getactive(gpd); - Depsgraph *depsgraph = CTX_data_depsgraph(C); - int cfra_eval = (int)DEG_get_ctime(depsgraph); + Scene *scene = CTX_data_scene(C); - bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, cfra_eval, GP_GETFRAME_USE_PREV); + bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, CFRA, GP_GETFRAME_USE_PREV); /* if there's no existing Grease-Pencil data there, add some */ if (gpd == NULL) { @@ -1681,14 +1678,13 @@ static bool gp_actframe_delete_all_poll(bContext *C) static int gp_actframe_delete_all_exec(bContext *C, wmOperator *op) { bGPdata *gpd = ED_gpencil_data_get_active(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); - int cfra_eval = (int)DEG_get_ctime(depsgraph); + Scene *scene = CTX_data_scene(C); bool success = false; CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) { /* try to get the "active" frame - but only if it actually occurs on this frame */ - bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, cfra_eval, GP_GETFRAME_USE_PREV); + bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, CFRA, GP_GETFRAME_USE_PREV); if (gpf == NULL) { continue; @@ -1940,9 +1936,11 @@ static int gp_dissolve_selected_points(bContext *C, eGP_DissolveMode mode) *ndvert = *dvert; ndvert->dw = MEM_dupallocN(dvert->dw); ndvert++; - dvert++; } } + if (gps->dvert != NULL) { + dvert++; + } } break; case GP_DISSOLVE_BETWEEN: @@ -1970,9 +1968,11 @@ static int gp_dissolve_selected_points(bContext *C, eGP_DissolveMode mode) *ndvert = *dvert; ndvert->dw = MEM_dupallocN(dvert->dw); ndvert++; - dvert++; } } + if (gps->dvert != NULL) { + dvert++; + } } /* copy last segment */ (gps->dvert != NULL) ? dvert = gps->dvert + last : NULL; @@ -2001,9 +2001,11 @@ static int gp_dissolve_selected_points(bContext *C, eGP_DissolveMode mode) *ndvert = *dvert; ndvert->dw = MEM_dupallocN(dvert->dw); ndvert++; - dvert++; } } + if (gps->dvert != NULL) { + dvert++; + } } break; } @@ -2493,7 +2495,7 @@ static int gp_snap_to_grid(bContext *C, wmOperator *UNUSED(op)) RegionView3D *rv3d = CTX_wm_region_data(C); View3D *v3d = CTX_wm_view3d(C); Scene *scene = CTX_data_scene(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Object *obact = CTX_data_active_object(C); const float gridf = ED_view3d_grid_view_scale(scene, v3d, rv3d, NULL); @@ -2568,7 +2570,7 @@ static int gp_snap_to_cursor(bContext *C, wmOperator *op) bGPdata *gpd = ED_gpencil_data_get_active(C); Scene *scene = CTX_data_scene(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Object *obact = CTX_data_active_object(C); const bool use_offset = RNA_boolean_get(op->ptr, "use_offset"); @@ -2661,7 +2663,7 @@ static int gp_snap_cursor_to_sel(bContext *C, wmOperator *UNUSED(op)) Scene *scene = CTX_data_scene(C); View3D *v3d = CTX_wm_view3d(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Object *obact = CTX_data_active_object(C); float *cursor = scene->cursor.location; @@ -3142,10 +3144,7 @@ static void gpencil_stroke_join_strokes(bGPDstroke *gps_a, /* 3rd: add all points */ for (i = 0, pt = gps_b->points; i < gps_b->totpoints && pt; i++, pt++) { - /* check if still room in buffer */ - if (gps_a->totpoints <= GP_STROKE_BUFFER_MAX - 2) { - gpencil_stroke_copy_point(gps_a, pt, i, delta, pt->pressure, pt->strength, deltatime); - } + gpencil_stroke_copy_point(gps_a, pt, i, delta, pt->pressure, pt->strength, deltatime); } } @@ -3375,7 +3374,7 @@ static int gp_strokes_reproject_exec(bContext *C, wmOperator *op) bGPdata *gpd = ED_gpencil_data_get_active(C); Scene *scene = CTX_data_scene(C); ToolSettings *ts = CTX_data_tool_settings(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Object *ob = CTX_data_active_object(C); ARegion *ar = CTX_wm_region(C); RegionView3D *rv3d = ar->regiondata; @@ -3401,12 +3400,6 @@ static int gp_strokes_reproject_exec(bContext *C, wmOperator *op) if (gps->flag & GP_STROKE_SELECT) { bGPDspoint *pt; int i; - float inverse_diff_mat[4][4]; - - /* Compute inverse matrix for unapplying parenting once instead of doing per-point */ - /* TODO: add this bit to the iteration macro? */ - invert_m4_m4(inverse_diff_mat, gpstroke_iter.diff_mat); - /* Adjust each point */ for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) { float xy[2]; @@ -3493,7 +3486,7 @@ static int gp_strokes_reproject_exec(bContext *C, wmOperator *op) /* Unapply parent corrections */ if (!ELEM(mode, GP_REPROJECT_FRONT, GP_REPROJECT_SIDE, GP_REPROJECT_TOP)) { - mul_m4_v3(inverse_diff_mat, &pt->x); + mul_m4_v3(gpstroke_iter.inverse_diff_mat, &pt->x); } } } @@ -3526,7 +3519,7 @@ void GPENCIL_OT_reproject(wmOperatorType *ot) "CURSOR", 0, "Cursor", - "Reproject the strokes using the orienation of 3D cursor"}, + "Reproject the strokes using the orientation of 3D cursor"}, {0, NULL, 0, NULL, NULL}, }; @@ -3544,7 +3537,7 @@ void GPENCIL_OT_reproject(wmOperatorType *ot) ot->poll = gp_strokes_edit3d_poll; /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ ot->prop = RNA_def_enum( @@ -4534,7 +4527,7 @@ void GPENCIL_OT_stroke_cutter(wmOperatorType *ot) ot->cancel = WM_gesture_lasso_cancel; /* flag */ - ot->flag = OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA; + ot->flag = OPTYPE_UNDO; /* properties */ WM_operator_properties_gesture_lasso(ot); diff --git a/source/blender/editors/gpencil/gpencil_fill.c b/source/blender/editors/gpencil/gpencil_fill.c index d914cdea442..5637e755198 100644 --- a/source/blender/editors/gpencil/gpencil_fill.c +++ b/source/blender/editors/gpencil/gpencil_fill.c @@ -135,7 +135,7 @@ typedef struct tGPDfill { short fill_factor; /** number of elements currently in cache */ - short sbuffer_size; + short sbuffer_used; /** temporary points */ void *sbuffer; /** depth array for reproject */ @@ -918,7 +918,7 @@ static void gpencil_get_depth_array(tGPDfill *tgpf) { tGPspoint *ptc; ToolSettings *ts = tgpf->scene->toolsettings; - int totpoints = tgpf->sbuffer_size; + int totpoints = tgpf->sbuffer_used; int i = 0; if (totpoints == 0) { @@ -984,7 +984,7 @@ static void gpencil_points_from_stack(tGPDfill *tgpf) return; } - tgpf->sbuffer_size = (short)totpoints; + tgpf->sbuffer_used = (short)totpoints; tgpf->sbuffer = MEM_callocN(sizeof(tGPspoint) * totpoints, __func__); point2D = tgpf->sbuffer; @@ -1020,7 +1020,7 @@ static void gpencil_stroke_from_buffer(tGPDfill *tgpf) MDeformVert *dvert = NULL; tGPspoint *point2D; - if (tgpf->sbuffer_size == 0) { + if (tgpf->sbuffer_used == 0) { return; } @@ -1041,8 +1041,8 @@ static void gpencil_stroke_from_buffer(tGPDfill *tgpf) gps->mat_nr = BKE_gpencil_object_material_ensure(tgpf->bmain, tgpf->ob, tgpf->mat); /* allocate memory for storage points */ - gps->totpoints = tgpf->sbuffer_size; - gps->points = MEM_callocN(sizeof(bGPDspoint) * tgpf->sbuffer_size, "gp_stroke_points"); + gps->totpoints = tgpf->sbuffer_used; + gps->points = MEM_callocN(sizeof(bGPDspoint) * tgpf->sbuffer_used, "gp_stroke_points"); /* initialize triangle memory to dummy data */ gps->tot_triangles = 0; @@ -1069,7 +1069,7 @@ static void gpencil_stroke_from_buffer(tGPDfill *tgpf) dvert = gps->dvert; } - for (int i = 0; i < tgpf->sbuffer_size && point2D; i++, point2D++, pt++) { + for (int i = 0; i < tgpf->sbuffer_used && point2D; i++, point2D++, pt++) { /* convert screen-coordinates to 3D coordinates */ gp_stroke_convertcoords_tpoint(tgpf->scene, tgpf->ar, @@ -1120,7 +1120,7 @@ static void gpencil_stroke_from_buffer(tGPDfill *tgpf) } /* if parented change position relative to parent object */ - for (int a = 0; a < tgpf->sbuffer_size; a++) { + for (int a = 0; a < tgpf->sbuffer_used; a++) { pt = &gps->points[a]; gp_apply_parent_point(tgpf->depsgraph, tgpf->ob, tgpf->gpd, tgpf->gpl, pt); } @@ -1213,7 +1213,7 @@ static tGPDfill *gp_session_init_fill(bContext *C, wmOperator *UNUSED(op)) tgpf->ar = CTX_wm_region(C); tgpf->rv3d = tgpf->ar->regiondata; tgpf->v3d = tgpf->sa->spacedata.first; - tgpf->depsgraph = CTX_data_depsgraph(C); + tgpf->depsgraph = CTX_data_ensure_evaluated_depsgraph(C); tgpf->win = CTX_wm_window(C); /* set GP datablock */ @@ -1225,7 +1225,7 @@ static tGPDfill *gp_session_init_fill(bContext *C, wmOperator *UNUSED(op)) tgpf->lock_axis = ts->gp_sculpt.lock_axis; tgpf->oldkey = -1; - tgpf->sbuffer_size = 0; + tgpf->sbuffer_used = 0; tgpf->sbuffer = NULL; tgpf->depth_arr = NULL; diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h index df9cb2e9a01..a8a3c2f9306 100644 --- a/source/blender/editors/gpencil/gpencil_intern.h +++ b/source/blender/editors/gpencil/gpencil_intern.h @@ -378,8 +378,8 @@ typedef enum eGPencil_PaintModes { GP_PAINTMODE_SET_CP, } eGPencil_PaintModes; -/* maximum sizes of gp-session buffer */ -#define GP_STROKE_BUFFER_MAX 5000 +/* chunk size for gp-session buffer (the total size is a multiple of this number) */ +#define GP_STROKE_BUFFER_CHUNK 2048 /* stroke editing ----- */ @@ -583,6 +583,7 @@ typedef enum ACTCONT_TYPES { struct GP_EditableStrokes_Iter { float diff_mat[4][4]; + float inverse_diff_mat[4][4]; }; /** @@ -598,7 +599,7 @@ struct GP_EditableStrokes_Iter { #define GP_EDITABLE_STROKES_BEGIN(gpstroke_iter, C, gpl, gps) \ { \ struct GP_EditableStrokes_Iter gpstroke_iter = {{{0}}}; \ - Depsgraph *depsgraph_ = CTX_data_depsgraph(C); \ + Depsgraph *depsgraph_ = CTX_data_ensure_evaluated_depsgraph(C); \ Object *obact_ = CTX_data_active_object(C); \ bGPdata *gpd_ = CTX_data_gpencil_data(C); \ const bool is_multiedit_ = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd_); \ @@ -607,6 +608,7 @@ struct GP_EditableStrokes_Iter { for (bGPDframe *gpf_ = init_gpf_; gpf_; gpf_ = gpf_->next) { \ if ((gpf_ == gpl->actframe) || ((gpf_->flag & GP_FRAME_SELECT) && is_multiedit_)) { \ ED_gpencil_parent_location(depsgraph_, obact_, gpd_, gpl, gpstroke_iter.diff_mat); \ + invert_m4_m4(gpstroke_iter.inverse_diff_mat, gpstroke_iter.diff_mat); \ /* loop over strokes */ \ for (bGPDstroke *gps = gpf_->strokes.first; gps; gps = gps->next) { \ /* skip strokes that are invalid for current view */ \ diff --git a/source/blender/editors/gpencil/gpencil_interpolate.c b/source/blender/editors/gpencil/gpencil_interpolate.c index 4d5548dcdf3..698e508a2a5 100644 --- a/source/blender/editors/gpencil/gpencil_interpolate.c +++ b/source/blender/editors/gpencil/gpencil_interpolate.c @@ -511,8 +511,8 @@ static int gpencil_interpolate_invoke(bContext *C, wmOperator *op, const wmEvent wmWindow *win = CTX_wm_window(C); bGPdata *gpd = CTX_data_gpencil_data(C); bGPDlayer *gpl = CTX_data_active_gpencil_layer(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); - int cfra_eval = (int)DEG_get_ctime(depsgraph); + Scene *scene = CTX_data_scene(C); + int cfra = CFRA; bGPDframe *actframe = gpl->actframe; tGPDinterpolate *tgpi = NULL; @@ -526,7 +526,7 @@ static int gpencil_interpolate_invoke(bContext *C, wmOperator *op, const wmEvent } /* cannot interpolate in extremes */ - if (ELEM(cfra_eval, actframe->framenum, actframe->next->framenum)) { + if (ELEM(cfra, actframe->framenum, actframe->next->framenum)) { BKE_report(op->reports, RPT_ERROR, "Cannot interpolate as current frame already has existing grease pencil frames"); @@ -949,8 +949,8 @@ static int gpencil_interpolate_seq_exec(bContext *C, wmOperator *op) Object *ob = CTX_data_active_object(C); ToolSettings *ts = CTX_data_tool_settings(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); - int cfra_eval = (int)DEG_get_ctime(depsgraph); + Scene *scene = CTX_data_scene(C); + int cfra = CFRA; GP_Interpolate_Settings *ipo_settings = &ts->gp_interpolate; eGP_Interpolate_SettingsFlag flag = ipo_settings->flag; @@ -964,7 +964,7 @@ static int gpencil_interpolate_seq_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } /* cannot interpolate in extremes */ - if (ELEM(cfra_eval, actframe->framenum, actframe->next->framenum)) { + if (ELEM(cfra, actframe->framenum, actframe->next->framenum)) { BKE_report(op->reports, RPT_ERROR, "Cannot interpolate as current frame already has existing grease pencil frames"); diff --git a/source/blender/editors/gpencil/gpencil_merge.c b/source/blender/editors/gpencil/gpencil_merge.c index 93d8555e014..cb11bb4cd63 100644 --- a/source/blender/editors/gpencil/gpencil_merge.c +++ b/source/blender/editors/gpencil/gpencil_merge.c @@ -98,11 +98,10 @@ static void gpencil_insert_points_to_stroke(bGPDstroke *gps, static bGPDstroke *gpencil_prepare_stroke(bContext *C, wmOperator *op, int totpoints) { ToolSettings *ts = CTX_data_tool_settings(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); Object *ob = CTX_data_active_object(C); bGPDlayer *gpl = CTX_data_active_gpencil_layer(C); - int cfra_eval = (int)DEG_get_ctime(depsgraph); + Scene *scene = CTX_data_scene(C); const bool back = RNA_boolean_get(op->ptr, "back"); const bool additive = RNA_boolean_get(op->ptr, "additive"); @@ -124,7 +123,7 @@ static bGPDstroke *gpencil_prepare_stroke(bContext *C, wmOperator *op, int totpo else { add_frame_mode = GP_GETFRAME_ADD_NEW; } - bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, cfra_eval, add_frame_mode); + bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, CFRA, add_frame_mode); /* stroke */ bGPDstroke *gps = MEM_callocN(sizeof(bGPDstroke), "gp_stroke"); diff --git a/source/blender/editors/gpencil/gpencil_ops.c b/source/blender/editors/gpencil/gpencil_ops.c index db4c601709c..d259bb9183c 100644 --- a/source/blender/editors/gpencil/gpencil_ops.c +++ b/source/blender/editors/gpencil/gpencil_ops.c @@ -81,9 +81,15 @@ static bool gp_stroke_paintmode_poll_with_tool(bContext *C, const char gpencil_t { /* TODO: limit this to mode, but review 2D editors */ bGPdata *gpd = CTX_data_gpencil_data(C); + if (!gpd) + return false; + ToolSettings *ts = CTX_data_tool_settings(C); + if (!ts || !ts->gp_paint) + return false; + Brush *brush = BKE_paint_brush(&ts->gp_paint->paint); - return ((gpd) && (gpd->flag & GP_DATA_STROKE_PAINTMODE) && (brush && brush->gpencil_settings) && + return ((gpd->flag & GP_DATA_STROKE_PAINTMODE) && (brush && brush->gpencil_settings) && WM_toolsystem_active_tool_is_brush(C) && (brush->gpencil_tool == gpencil_tool)); } diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c index b49094c4fd6..a271274fa71 100644 --- a/source/blender/editors/gpencil/gpencil_paint.c +++ b/source/blender/editors/gpencil/gpencil_paint.c @@ -349,7 +349,7 @@ static bool gp_stroke_filtermval(tGPsdata *p, const float mval[2], float mvalo[2 brush->gpencil_settings->flag &= ~GP_BRUSH_STABILIZE_MOUSE_TEMP; /* if buffer is empty, just let this go through (i.e. so that dots will work) */ - if (p->gpd->runtime.sbuffer_size == 0) { + if (p->gpd->runtime.sbuffer_used == 0) { return true; } /* if lazy mouse, check minimum distance */ @@ -486,7 +486,7 @@ static void gp_brush_jitter(bGPdata *gpd, /* Jitter is applied perpendicular to the mouse movement vector (2D space) */ float mvec[2], svec[2]; /* mouse movement in ints -> floats */ - if (gpd->runtime.sbuffer_size > 1) { + if (gpd->runtime.sbuffer_used > 1) { mvec[0] = (mval[0] - (pt - 1)->x); mvec[1] = (mval[1] - (pt - 1)->y); normalize_v2(mvec); @@ -524,7 +524,7 @@ static void gp_brush_angle(bGPdata *gpd, Brush *brush, tGPspoint *pt, const floa float v0[2] = {cos(angle), sin(angle)}; /* Apply to first point (only if there are 2 points because before no data to do it ) */ - if (gpd->runtime.sbuffer_size == 1) { + if (gpd->runtime.sbuffer_used == 1) { mvec[0] = (mval[0] - (pt - 1)->x); mvec[1] = (mval[1] - (pt - 1)->y); normalize_v2(mvec); @@ -537,7 +537,7 @@ static void gp_brush_angle(bGPdata *gpd, Brush *brush, tGPspoint *pt, const floa } /* apply from second point */ - if (gpd->runtime.sbuffer_size >= 1) { + if (gpd->runtime.sbuffer_used >= 1) { mvec[0] = (mval[0] - (pt - 1)->x); mvec[1] = (mval[1] - (pt - 1)->y); normalize_v2(mvec); @@ -563,7 +563,7 @@ static void gp_brush_angle(bGPdata *gpd, Brush *brush, tGPspoint *pt, const floa static void gp_smooth_buffer(tGPsdata *p, float inf, int idx) { bGPdata *gpd = p->gpd; - short num_points = gpd->runtime.sbuffer_size; + short num_points = gpd->runtime.sbuffer_used; /* Do nothing if not enough points to smooth out */ if ((num_points < 3) || (idx < 3) || (inf == 0.0f)) { @@ -626,7 +626,7 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure /* check painting mode */ if (p->paintmode == GP_PAINTMODE_DRAW_STRAIGHT) { /* straight lines only - i.e. only store start and end point in buffer */ - if (gpd->runtime.sbuffer_size == 0) { + if (gpd->runtime.sbuffer_used == 0) { /* first point in buffer (start point) */ pt = (tGPspoint *)(gpd->runtime.sbuffer); @@ -638,7 +638,7 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure pt->time = (float)(curtime - p->inittime); /* increment buffer size */ - gpd->runtime.sbuffer_size++; + gpd->runtime.sbuffer_used++; } else { /* just reset the endpoint to the latest value @@ -654,20 +654,19 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure pt->time = (float)(curtime - p->inittime); /* now the buffer has 2 points (and shouldn't be allowed to get any larger) */ - gpd->runtime.sbuffer_size = 2; + gpd->runtime.sbuffer_used = 2; } /* can keep carrying on this way :) */ return GP_STROKEADD_NORMAL; } else if (p->paintmode == GP_PAINTMODE_DRAW) { /* normal drawing */ - /* check if still room in buffer */ - if (gpd->runtime.sbuffer_size >= GP_STROKE_BUFFER_MAX) { - return GP_STROKEADD_OVERFLOW; - } + /* check if still room in buffer or add more */ + gpd->runtime.sbuffer = ED_gpencil_sbuffer_ensure( + gpd->runtime.sbuffer, &gpd->runtime.sbuffer_size, &gpd->runtime.sbuffer_used, false); /* get pointer to destination point */ - pt = ((tGPspoint *)(gpd->runtime.sbuffer) + gpd->runtime.sbuffer_size); + pt = ((tGPspoint *)(gpd->runtime.sbuffer) + gpd->runtime.sbuffer_used); /* store settings */ /* pressure */ @@ -760,9 +759,9 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure pt->time = (float)(curtime - p->inittime); /* point uv (only 3d view) */ - if ((p->sa->spacetype == SPACE_VIEW3D) && (gpd->runtime.sbuffer_size > 0)) { + if ((p->sa->spacetype == SPACE_VIEW3D) && (gpd->runtime.sbuffer_used > 0)) { float pixsize = gp_style->texture_pixsize / 1000000.0f; - tGPspoint *ptb = (tGPspoint *)gpd->runtime.sbuffer + gpd->runtime.sbuffer_size - 1; + tGPspoint *ptb = (tGPspoint *)gpd->runtime.sbuffer + gpd->runtime.sbuffer_used - 1; bGPDspoint spt, spt2; /* get origin to reproject point */ @@ -787,24 +786,18 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure } /* increment counters */ - gpd->runtime.sbuffer_size++; + gpd->runtime.sbuffer_used++; /* smooth while drawing previous points with a reduction factor for previous */ if (brush->gpencil_settings->active_smooth > 0.0f) { for (int s = 0; s < 3; s++) { gp_smooth_buffer(p, brush->gpencil_settings->active_smooth * ((3.0f - s) / 3.0f), - gpd->runtime.sbuffer_size - s); + gpd->runtime.sbuffer_used - s); } } - /* check if another operation can still occur */ - if (gpd->runtime.sbuffer_size == GP_STROKE_BUFFER_MAX) { - return GP_STROKEADD_FULL; - } - else { - return GP_STROKEADD_NORMAL; - } + return GP_STROKEADD_NORMAL; } else if (p->paintmode == GP_PAINTMODE_DRAW_POLY) { @@ -832,7 +825,7 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure MDeformVert *dvert = NULL; /* first time point is adding to temporary buffer -- need to allocate new point in stroke */ - if (gpd->runtime.sbuffer_size == 0) { + if (gpd->runtime.sbuffer_used == 0) { gps->points = MEM_reallocN(gps->points, sizeof(bGPDspoint) * (gps->totpoints + 1)); if (gps->dvert != NULL) { gps->dvert = MEM_reallocN(gps->dvert, sizeof(MDeformVert) * (gps->totpoints + 1)); @@ -889,8 +882,8 @@ static short gp_stroke_addpoint(tGPsdata *p, const float mval[2], float pressure } /* increment counters */ - if (gpd->runtime.sbuffer_size == 0) { - gpd->runtime.sbuffer_size++; + if (gpd->runtime.sbuffer_used == 0) { + gpd->runtime.sbuffer_used++; } return GP_STROKEADD_NORMAL; @@ -930,17 +923,17 @@ static void gp_stroke_newfrombuffer(tGPsdata *p) * - drawing straight-lines only requires the endpoints */ if (p->paintmode == GP_PAINTMODE_DRAW_STRAIGHT) { - totelem = (gpd->runtime.sbuffer_size >= 2) ? 2 : gpd->runtime.sbuffer_size; + totelem = (gpd->runtime.sbuffer_used >= 2) ? 2 : gpd->runtime.sbuffer_used; } else { - totelem = gpd->runtime.sbuffer_size; + totelem = gpd->runtime.sbuffer_used; } /* exit with error if no valid points from this stroke */ if (totelem == 0) { if (G.debug & G_DEBUG) { printf("Error: No valid points in stroke buffer to convert (tot=%d)\n", - gpd->runtime.sbuffer_size); + gpd->runtime.sbuffer_used); } return; } @@ -1024,7 +1017,7 @@ static void gp_stroke_newfrombuffer(tGPsdata *p) if (totelem == 2) { /* last point if applicable */ - ptc = ((tGPspoint *)gpd->runtime.sbuffer) + (gpd->runtime.sbuffer_size - 1); + ptc = ((tGPspoint *)gpd->runtime.sbuffer) + (gpd->runtime.sbuffer_used - 1); /* convert screen-coordinates to appropriate coordinates (and store them) */ gp_stroke_convertcoords(p, &ptc->x, &pt->x, NULL); @@ -1105,9 +1098,9 @@ static void gp_stroke_newfrombuffer(tGPsdata *p) int interp_depth = 0; int found_depth = 0; - depth_arr = MEM_mallocN(sizeof(float) * gpd->runtime.sbuffer_size, "depth_points"); + depth_arr = MEM_mallocN(sizeof(float) * gpd->runtime.sbuffer_used, "depth_points"); - for (i = 0, ptc = gpd->runtime.sbuffer; i < gpd->runtime.sbuffer_size; i++, ptc++, pt++) { + for (i = 0, ptc = gpd->runtime.sbuffer; i < gpd->runtime.sbuffer_used; i++, ptc++, pt++) { round_v2i_v2fl(mval_i, &ptc->x); @@ -1125,7 +1118,7 @@ static void gp_stroke_newfrombuffer(tGPsdata *p) if (found_depth == false) { /* eeh... not much we can do.. :/, ignore depth in this case, use the 3D cursor */ - for (i = gpd->runtime.sbuffer_size - 1; i >= 0; i--) { + for (i = gpd->runtime.sbuffer_used - 1; i >= 0; i--) { depth_arr[i] = 0.9999f; } } @@ -1137,7 +1130,7 @@ static void gp_stroke_newfrombuffer(tGPsdata *p) int last_valid = 0; /* find first valid contact point */ - for (i = 0; i < gpd->runtime.sbuffer_size; i++) { + for (i = 0; i < gpd->runtime.sbuffer_used; i++) { if (depth_arr[i] != FLT_MAX) { break; } @@ -1149,7 +1142,7 @@ static void gp_stroke_newfrombuffer(tGPsdata *p) last_valid = first_valid; } else { - for (i = gpd->runtime.sbuffer_size - 1; i >= 0; i--) { + for (i = gpd->runtime.sbuffer_used - 1; i >= 0; i--) { if (depth_arr[i] != FLT_MAX) { break; } @@ -1158,7 +1151,7 @@ static void gp_stroke_newfrombuffer(tGPsdata *p) } /* invalidate any other point, to interpolate between * first and last contact in an imaginary line between them */ - for (i = 0; i < gpd->runtime.sbuffer_size; i++) { + for (i = 0; i < gpd->runtime.sbuffer_used; i++) { if ((i != first_valid) && (i != last_valid)) { depth_arr[i] = FLT_MAX; } @@ -1167,7 +1160,7 @@ static void gp_stroke_newfrombuffer(tGPsdata *p) } if (interp_depth) { - interp_sparse_array(depth_arr, gpd->runtime.sbuffer_size, FLT_MAX); + interp_sparse_array(depth_arr, gpd->runtime.sbuffer_used, FLT_MAX); } } } @@ -1176,7 +1169,7 @@ static void gp_stroke_newfrombuffer(tGPsdata *p) dvert = gps->dvert; /* convert all points (normal behavior) */ - for (i = 0, ptc = gpd->runtime.sbuffer; i < gpd->runtime.sbuffer_size && ptc; + for (i = 0, ptc = gpd->runtime.sbuffer; i < gpd->runtime.sbuffer_used && ptc; i++, ptc++, pt++) { /* convert screen-coordinates to appropriate coordinates (and store them) */ gp_stroke_convertcoords(p, &ptc->x, &pt->x, depth_arr ? depth_arr + i : NULL); @@ -1725,18 +1718,8 @@ static void gp_session_validatebuffer(tGPsdata *p) Brush *brush = p->brush; /* clear memory of buffer (or allocate it if starting a new session) */ - if (gpd->runtime.sbuffer) { - /* printf("\t\tGP - reset sbuffer\n"); */ - memset(gpd->runtime.sbuffer, 0, sizeof(tGPspoint) * GP_STROKE_BUFFER_MAX); - } - else { - /* printf("\t\tGP - allocate sbuffer\n"); */ - gpd->runtime.sbuffer = MEM_callocN(sizeof(tGPspoint) * GP_STROKE_BUFFER_MAX, - "gp_session_strokebuffer"); - } - - /* reset indices */ - gpd->runtime.sbuffer_size = 0; + gpd->runtime.sbuffer = ED_gpencil_sbuffer_ensure( + gpd->runtime.sbuffer, &gpd->runtime.sbuffer_size, &gpd->runtime.sbuffer_used, true); /* reset flags */ gpd->runtime.sbuffer_sflag = 0; @@ -1911,7 +1894,7 @@ static bool gp_session_initdata(bContext *C, wmOperator *op, tGPsdata *p) p->C = C; p->bmain = CTX_data_main(C); p->scene = CTX_data_scene(C); - p->depsgraph = CTX_data_depsgraph(C); + p->depsgraph = CTX_data_ensure_evaluated_depsgraph(C); p->win = CTX_wm_window(C); p->disable_fill = RNA_boolean_get(op->ptr, "disable_fill"); @@ -2070,6 +2053,7 @@ static void gp_session_cleanup(tGPsdata *p) } /* clear flags */ + gpd->runtime.sbuffer_used = 0; gpd->runtime.sbuffer_size = 0; gpd->runtime.sbuffer_sflag = 0; p->inittime = 0.0; @@ -2089,7 +2073,6 @@ static void gp_paint_initstroke(tGPsdata *p, eGPencil_PaintModes paintmode, Deps { Scene *scene = p->scene; ToolSettings *ts = scene->toolsettings; - int cfra_eval = (int)DEG_get_ctime(p->depsgraph); /* get active layer (or add a new one if non-existent) */ p->gpl = BKE_gpencil_layer_getactive(p->gpd); @@ -2131,7 +2114,7 @@ static void gp_paint_initstroke(tGPsdata *p, eGPencil_PaintModes paintmode, Deps * -> If there are no strokes in that frame, don't add a new empty frame */ if (gpl->actframe && gpl->actframe->strokes.first) { - gpl->actframe = BKE_gpencil_layer_getframe(gpl, cfra_eval, GP_GETFRAME_ADD_COPY); + gpl->actframe = BKE_gpencil_layer_getframe(gpl, CFRA, GP_GETFRAME_ADD_COPY); has_layer_to_erase = true; } @@ -2169,7 +2152,7 @@ static void gp_paint_initstroke(tGPsdata *p, eGPencil_PaintModes paintmode, Deps add_frame_mode = GP_GETFRAME_ADD_NEW; } - p->gpf = BKE_gpencil_layer_getframe(p->gpl, cfra_eval, add_frame_mode); + p->gpf = BKE_gpencil_layer_getframe(p->gpl, CFRA, add_frame_mode); if (p->gpf == NULL) { p->status = GP_STATUS_ERROR; @@ -2448,7 +2431,7 @@ static int gpencil_draw_init(bContext *C, wmOperator *op, const wmEvent *event) } /* init painting data */ - gp_paint_initstroke(p, paintmode, CTX_data_depsgraph(C)); + gp_paint_initstroke(p, paintmode, CTX_data_ensure_evaluated_depsgraph(C)); if (p->status == GP_STATUS_ERROR) { gpencil_draw_exit(C, op); return 0; @@ -2624,14 +2607,14 @@ static void gpencil_draw_apply(bContext *C, wmOperator *op, tGPsdata *p, Depsgra p->opressure = p->pressure; p->ocurtime = p->curtime; - pt = (tGPspoint *)gpd->runtime.sbuffer + gpd->runtime.sbuffer_size - 1; + pt = (tGPspoint *)gpd->runtime.sbuffer + gpd->runtime.sbuffer_used - 1; if (p->paintmode != GP_PAINTMODE_ERASER) { ED_gpencil_toggle_brush_cursor(C, true, &pt->x); } } else if ((p->brush->gpencil_settings->flag & GP_BRUSH_STABILIZE_MOUSE_TEMP) && - (gpd->runtime.sbuffer_size > 0)) { - pt = (tGPspoint *)gpd->runtime.sbuffer + gpd->runtime.sbuffer_size - 1; + (gpd->runtime.sbuffer_used > 0)) { + pt = (tGPspoint *)gpd->runtime.sbuffer + gpd->runtime.sbuffer_used - 1; if (p->paintmode != GP_PAINTMODE_ERASER) { ED_gpencil_toggle_brush_cursor(C, true, &pt->x); } @@ -2842,10 +2825,10 @@ static void gpencil_draw_apply_event( float pt[2]; copy_v2_v2(tmp, p->mval); sub_v2_v2v2(pt, p->mval, p->mvali); - gpencil_draw_apply_event(C, op, event, CTX_data_depsgraph(C), pt[0], pt[1]); + gpencil_draw_apply_event(C, op, event, depsgraph, pt[0], pt[1]); if (len_v2v2(p->mval, p->mvalo)) { sub_v2_v2v2(pt, p->mval, p->mvalo); - gpencil_draw_apply_event(C, op, event, CTX_data_depsgraph(C), pt[0], pt[1]); + gpencil_draw_apply_event(C, op, event, depsgraph, pt[0], pt[1]); } copy_v2_v2(p->mval, tmp); } @@ -2965,7 +2948,7 @@ static void gpencil_draw_apply_event( static int gpencil_draw_exec(bContext *C, wmOperator *op) { tGPsdata *p = NULL; - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); /* printf("GPencil - Starting Re-Drawing\n"); */ @@ -3213,7 +3196,7 @@ static int gpencil_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event p->status = GP_STATUS_PAINTING; /* handle the initial drawing - i.e. for just doing a simple dot */ - gpencil_draw_apply_event(C, op, event, CTX_data_depsgraph(C), 0.0f, 0.0f); + gpencil_draw_apply_event(C, op, event, CTX_data_ensure_evaluated_depsgraph(C), 0.0f, 0.0f); op->flag |= OP_IS_MODAL_CURSOR_REGION; } else { @@ -3277,7 +3260,7 @@ static tGPsdata *gpencil_stroke_begin(bContext *C, wmOperator *op) * it'd be nice to allow changing paint-mode when in sketching-sessions */ if (gp_session_initdata(C, op, p)) { - gp_paint_initstroke(p, p->paintmode, CTX_data_depsgraph(C)); + gp_paint_initstroke(p, p->paintmode, CTX_data_depsgraph_pointer(C)); } if (p->status != GP_STATUS_ERROR) { @@ -3338,6 +3321,7 @@ static void gpencil_add_missing_events(bContext *C, { Brush *brush = p->brush; GP_Sculpt_Guide *guide = &p->scene->toolsettings->gp_sculpt.guide; + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); int input_samples = brush->gpencil_settings->input_samples; /* ensure sampling when using circular guide */ @@ -3396,7 +3380,7 @@ static void gpencil_add_missing_events(bContext *C, interp_v2_v2v2(pt, a, b, 0.5f); sub_v2_v2v2(pt, b, pt); /* create fake event */ - gpencil_draw_apply_event(C, op, event, CTX_data_depsgraph(C), pt[0], pt[1]); + gpencil_draw_apply_event(C, op, event, depsgraph, pt[0], pt[1]); } else if (dist >= factor) { int slices = 2 + (int)((dist - 1.0) / factor); @@ -3405,7 +3389,7 @@ static void gpencil_add_missing_events(bContext *C, interp_v2_v2v2(pt, a, b, n * i); sub_v2_v2v2(pt, b, pt); /* create fake event */ - gpencil_draw_apply_event(C, op, event, CTX_data_depsgraph(C), pt[0], pt[1]); + gpencil_draw_apply_event(C, op, event, depsgraph, pt[0], pt[1]); } } } @@ -3712,7 +3696,7 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event) gpencil_add_missing_events(C, op, event, p); } - gpencil_draw_apply_event(C, op, event, CTX_data_depsgraph(C), 0.0f, 0.0f); + gpencil_draw_apply_event(C, op, event, CTX_data_depsgraph_pointer(C), 0.0f, 0.0f); /* finish painting operation if anything went wrong just now */ if (p->status == GP_STATUS_ERROR) { diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c index cca94925e6e..bdc65e7172a 100644 --- a/source/blender/editors/gpencil/gpencil_primitive.c +++ b/source/blender/editors/gpencil/gpencil_primitive.c @@ -114,16 +114,8 @@ static void gp_session_validatebuffer(tGPDprimitive *p) bGPdata *gpd = p->gpd; /* clear memory of buffer (or allocate it if starting a new session) */ - if (gpd->runtime.sbuffer) { - memset(gpd->runtime.sbuffer, 0, sizeof(tGPspoint) * GP_STROKE_BUFFER_MAX); - } - else { - gpd->runtime.sbuffer = MEM_callocN(sizeof(tGPspoint) * GP_STROKE_BUFFER_MAX, - "gp_session_strokebuffer"); - } - - /* reset indices */ - gpd->runtime.sbuffer_size = 0; + gpd->runtime.sbuffer = ED_gpencil_sbuffer_ensure( + gpd->runtime.sbuffer, &gpd->runtime.sbuffer_size, &gpd->runtime.sbuffer_used, true); /* reset flags */ gpd->runtime.sbuffer_sflag = 0; @@ -305,8 +297,8 @@ static void gpencil_primitive_allocate_memory(tGPDprimitive *tgpi) /* Helper: Create internal strokes primitives data */ static void gp_primitive_set_initdata(bContext *C, tGPDprimitive *tgpi) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); - int cfra_eval = (int)DEG_get_ctime(depsgraph); + Scene *scene = CTX_data_scene(C); + int cfra = CFRA; bGPDlayer *gpl = CTX_data_active_gpencil_layer(C); @@ -318,7 +310,7 @@ static void gp_primitive_set_initdata(bContext *C, tGPDprimitive *tgpi) /* create a new temporary frame */ tgpi->gpf = MEM_callocN(sizeof(bGPDframe), "Temp bGPDframe"); - tgpi->gpf->framenum = tgpi->cframe = cfra_eval; + tgpi->gpf->framenum = tgpi->cframe = cfra; /* create new temp stroke */ bGPDstroke *gps = MEM_callocN(sizeof(bGPDstroke), "Temp bGPDstroke"); @@ -828,7 +820,7 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi) } /* Copy points to buffer */ - tGPspoint *tpt = ((tGPspoint *)(gpd->runtime.sbuffer) + gpd->runtime.sbuffer_size); + tGPspoint *tpt = ((tGPspoint *)(gpd->runtime.sbuffer) + gpd->runtime.sbuffer_used); /* Store original points */ float tmp_xyp[2]; @@ -927,10 +919,10 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi) tpt->time = p2d->time; /* point uv */ - if (gpd->runtime.sbuffer_size > 0) { + if (gpd->runtime.sbuffer_used > 0) { MaterialGPencilStyle *gp_style = tgpi->mat->gp_style; const float pixsize = gp_style->texture_pixsize / 1000000.0f; - tGPspoint *tptb = (tGPspoint *)gpd->runtime.sbuffer + gpd->runtime.sbuffer_size - 1; + tGPspoint *tptb = (tGPspoint *)gpd->runtime.sbuffer + gpd->runtime.sbuffer_used - 1; bGPDspoint spt, spt2; /* get origin to reproject point */ @@ -958,7 +950,11 @@ static void gp_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi) tpt->uv_rot = p2d->uv_rot; - gpd->runtime.sbuffer_size++; + gpd->runtime.sbuffer_used++; + + /* check if still room in buffer or add more */ + gpd->runtime.sbuffer = ED_gpencil_sbuffer_ensure( + gpd->runtime.sbuffer, &gpd->runtime.sbuffer_size, &gpd->runtime.sbuffer_used, false); /* add small offset to keep stroke over the surface */ if ((depth_arr) && (gpd->zdepth_offset > 0.0f)) { @@ -1078,6 +1074,7 @@ static void gpencil_primitive_exit(bContext *C, wmOperator *op) gpd->runtime.sbuffer = NULL; /* clear flags */ + gpd->runtime.sbuffer_used = 0; gpd->runtime.sbuffer_size = 0; gpd->runtime.sbuffer_sflag = 0; } @@ -1096,11 +1093,8 @@ static void gpencil_primitive_init(bContext *C, wmOperator *op) bGPdata *gpd = CTX_data_gpencil_data(C); Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); Paint *paint = &ts->gp_paint->paint; - int cfra_eval = (int)DEG_get_ctime(depsgraph); - /* create temporary operator data */ tGPDprimitive *tgpi = MEM_callocN(sizeof(tGPDprimitive), "GPencil Primitive Data"); op->customdata = tgpi; @@ -1115,14 +1109,14 @@ static void gpencil_primitive_init(bContext *C, wmOperator *op) tgpi->ar = CTX_wm_region(C); tgpi->rv3d = tgpi->ar->regiondata; tgpi->v3d = tgpi->sa->spacedata.first; - tgpi->depsgraph = CTX_data_depsgraph(C); + tgpi->depsgraph = CTX_data_ensure_evaluated_depsgraph(C); tgpi->win = CTX_wm_window(C); /* save original type */ tgpi->orign_type = RNA_enum_get(op->ptr, "type"); /* set current frame number */ - tgpi->cframe = cfra_eval; + tgpi->cframe = CFRA; /* set GP datablock */ tgpi->gpd = gpd; diff --git a/source/blender/editors/gpencil/gpencil_select.c b/source/blender/editors/gpencil/gpencil_select.c index ba806022d3e..5a962809954 100644 --- a/source/blender/editors/gpencil/gpencil_select.c +++ b/source/blender/editors/gpencil/gpencil_select.c @@ -302,11 +302,10 @@ typedef enum eGP_SelectGrouped { /* On each visible layer, check for selected strokes - if found, select all others */ static void gp_select_same_layer(bContext *C) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); - int cfra_eval = (int)DEG_get_ctime(depsgraph); + Scene *scene = CTX_data_scene(C); CTX_DATA_BEGIN (C, bGPDlayer *, gpl, editable_gpencil_layers) { - bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, cfra_eval, GP_GETFRAME_USE_PREV); + bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, CFRA, GP_GETFRAME_USE_PREV); bGPDstroke *gps; bool found = false; @@ -990,7 +989,7 @@ void GPENCIL_OT_select_circle(wmOperatorType *ot) ot->cancel = WM_gesture_circle_cancel; /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ WM_operator_properties_gesture_circle(ot); @@ -1181,7 +1180,7 @@ void GPENCIL_OT_select_box(wmOperatorType *ot) ot->poll = gpencil_select_poll; /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ WM_operator_properties_gesture_box(ot); @@ -1249,7 +1248,7 @@ void GPENCIL_OT_select_lasso(wmOperatorType *ot) ot->cancel = WM_gesture_lasso_cancel; /* flags */ - ot->flag = OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA; + ot->flag = OPTYPE_UNDO; /* properties */ WM_operator_properties_select_operation(ot); @@ -1469,7 +1468,7 @@ void GPENCIL_OT_select(wmOperatorType *ot) ot->poll = gpencil_select_poll; /* flag */ - ot->flag = OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA; + ot->flag = OPTYPE_UNDO; /* properties */ WM_operator_properties_mouse_select(ot); diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c index 065c133bf97..a475e43755c 100644 --- a/source/blender/editors/gpencil/gpencil_utils.c +++ b/source/blender/editors/gpencil/gpencil_utils.c @@ -259,7 +259,7 @@ bGPdata *ED_gpencil_data_get_active_evaluated(const bContext *C) ID *screen_id = (ID *)CTX_wm_screen(C); ScrArea *sa = CTX_wm_area(C); - const Depsgraph *depsgraph = CTX_data_depsgraph(C); + const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); Object *ob = CTX_data_active_object(C); Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); @@ -548,7 +548,7 @@ void gp_point_conversion_init(bContext *C, GP_SpaceConversion *r_gsc) if (sa->spacetype == SPACE_VIEW3D) { wmWindow *win = CTX_wm_window(C); Scene *scene = CTX_data_scene(C); - struct Depsgraph *depsgraph = CTX_data_depsgraph(C); + struct Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); View3D *v3d = (View3D *)CTX_wm_space_data(C); RegionView3D *rv3d = ar->regiondata; @@ -560,8 +560,7 @@ void gp_point_conversion_init(bContext *C, GP_SpaceConversion *r_gsc) /* for camera view set the subrect */ if (rv3d->persp == RV3D_CAMOB) { - ED_view3d_calc_camera_border( - scene, CTX_data_depsgraph(C), ar, v3d, rv3d, &r_gsc->subrect_data, true); + ED_view3d_calc_camera_border(scene, depsgraph, ar, v3d, rv3d, &r_gsc->subrect_data, true); r_gsc->subrect = &r_gsc->subrect_data; } } @@ -929,7 +928,7 @@ void ED_gp_get_drawing_reference( void ED_gpencil_project_stroke_to_view(bContext *C, bGPDlayer *gpl, bGPDstroke *gps) { Scene *scene = CTX_data_scene(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Object *ob = CTX_data_active_object(C); bGPdata *gpd = (bGPdata *)ob->data; GP_SpaceConversion gsc = {NULL}; @@ -1094,7 +1093,7 @@ void ED_gp_project_point_to_plane(const Scene *scene, /* get a vector from the point with the current view direction of the viewport */ ED_view3d_global_to_vector(rv3d, &pt->x, vn); - /* calculate line extrem point to create a ray that cross the plane */ + /* calculate line extreme point to create a ray that cross the plane */ mul_v3_fl(vn, -50.0f); add_v3_v3v3(ray, &pt->x, vn); @@ -1740,7 +1739,7 @@ static void gp_brush_cursor_draw(bContext *C, int x, int y, void *customdata) } /* while drawing hide */ - if ((gpd->runtime.sbuffer_size > 0) && + if ((gpd->runtime.sbuffer_used > 0) && ((brush->gpencil_settings->flag & GP_BRUSH_STABILIZE_MOUSE) == 0) && ((brush->gpencil_settings->flag & GP_BRUSH_STABILIZE_MOUSE_TEMP) == 0)) { return; @@ -2525,3 +2524,37 @@ void ED_gpencil_select_toggle_all(bContext *C, int action) CTX_DATA_END; } } + +/* Ensure the SBuffer (while drawing stroke) size is enough to save all points of the stroke */ +tGPspoint *ED_gpencil_sbuffer_ensure(tGPspoint *buffer_array, + short *buffer_size, + short *buffer_used, + const bool clear) +{ + tGPspoint *p = NULL; + + /* By default a buffer is created with one block with a predefined number of free points, + * if the size is not enough, the cache is reallocated adding a new block of free points. + * This is done in order to keep cache small and improve speed. */ + if (*buffer_used + 1 > *buffer_size) { + if ((*buffer_size == 0) || (buffer_array == NULL)) { + p = MEM_callocN(sizeof(struct tGPspoint) * GP_STROKE_BUFFER_CHUNK, "GPencil Sbuffer"); + *buffer_size = GP_STROKE_BUFFER_CHUNK; + } + else { + *buffer_size += GP_STROKE_BUFFER_CHUNK; + p = MEM_recallocN(buffer_array, sizeof(struct tGPspoint) * *buffer_size); + } + buffer_array = p; + } + + /* clear old data */ + if (clear) { + *buffer_used = 0; + if (buffer_array != NULL) { + memset(buffer_array, 0, sizeof(tGPspoint) * *buffer_size); + } + } + + return buffer_array; +} diff --git a/source/blender/editors/include/ED_anim_api.h b/source/blender/editors/include/ED_anim_api.h index 230d62d400c..a232e1376d3 100644 --- a/source/blender/editors/include/ED_anim_api.h +++ b/source/blender/editors/include/ED_anim_api.h @@ -27,6 +27,7 @@ struct AnimData; struct ID; struct ListBase; +struct Depsgraph; struct ARegion; struct Main; @@ -84,8 +85,6 @@ typedef struct bAnimContext { /** dopesheet data for editor (or which is being used) */ struct bDopeSheet *ads; - /** active dependency graph */ - struct Depsgraph *depsgraph; /** Current Main */ struct Main *bmain; /** active scene */ diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h index 0e3204b30c7..6410e6630a7 100644 --- a/source/blender/editors/include/ED_gpencil.h +++ b/source/blender/editors/include/ED_gpencil.h @@ -35,6 +35,7 @@ struct bGPDlayer; struct bGPDspoint; struct bGPDstroke; struct bGPdata; +struct tGPspoint; struct ARegion; struct Depsgraph; @@ -287,4 +288,9 @@ int ED_gpencil_select_stroke_segment(struct bGPDlayer *gpl, void ED_gpencil_select_toggle_all(struct bContext *C, int action); +/* Ensure stroke sbuffer size is enough */ +struct tGPspoint *ED_gpencil_sbuffer_ensure(struct tGPspoint *buffer_array, + short *buffer_size, + short *buffer_used, + const bool clear); #endif /* __ED_GPENCIL_H__ */ diff --git a/source/blender/editors/include/ED_keyframes_draw.h b/source/blender/editors/include/ED_keyframes_draw.h index 9fa8996c384..05f641abe91 100644 --- a/source/blender/editors/include/ED_keyframes_draw.h +++ b/source/blender/editors/include/ED_keyframes_draw.h @@ -127,7 +127,7 @@ typedef enum eKeyframeExtremeDrawOpts { KEYFRAME_EXTREME_MAX = (1 << 1), /* Grouped keys have different states. */ KEYFRAME_EXTREME_MIXED = (1 << 2), - /* Both neigbors are equal to this key. */ + /* Both neighbors are equal to this key. */ KEYFRAME_EXTREME_FLAT = (1 << 3), } eKeyframeExtremeDrawOpts; diff --git a/source/blender/editors/include/ED_keyframing.h b/source/blender/editors/include/ED_keyframing.h index a893f03bd88..8f197fa9afe 100644 --- a/source/blender/editors/include/ED_keyframing.h +++ b/source/blender/editors/include/ED_keyframing.h @@ -113,8 +113,7 @@ int insert_vert_fcurve( * Use this to insert a keyframe using the current value being keyframed, in the * nominated F-Curve (no creation of animation data performed). Returns success. */ -bool insert_keyframe_direct(struct Depsgraph *depsgraph, - struct ReportList *reports, +bool insert_keyframe_direct(struct ReportList *reports, struct PointerRNA ptr, struct PropertyRNA *prop, struct FCurve *fcu, @@ -130,7 +129,6 @@ bool insert_keyframe_direct(struct Depsgraph *depsgraph, * using the current value being keyframed, in the relevant place. Returns success. */ short insert_keyframe(struct Main *bmain, - struct Depsgraph *depsgraph, struct ReportList *reports, struct ID *id, struct bAction *act, diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h index d2613facd83..5ebba4e5d25 100644 --- a/source/blender/editors/include/ED_mesh.h +++ b/source/blender/editors/include/ED_mesh.h @@ -254,7 +254,10 @@ void ED_operatormacros_mesh(void); void ED_keymap_mesh(struct wmKeyConfig *keyconf); /* editmesh_tools.c (could be moved) */ -void EDBM_project_snap_verts(struct bContext *C, struct ARegion *ar, struct BMEditMesh *em); +void EDBM_project_snap_verts(struct bContext *C, + struct Depsgraph *depsgraph, + struct ARegion *ar, + struct BMEditMesh *em); /* editface.c */ void paintface_flush_flags(struct bContext *C, struct Object *ob, short flag); diff --git a/source/blender/editors/include/ED_object.h b/source/blender/editors/include/ED_object.h index 038f1bf52a6..5f9534a1f1c 100644 --- a/source/blender/editors/include/ED_object.h +++ b/source/blender/editors/include/ED_object.h @@ -166,13 +166,11 @@ void ED_object_vpaintmode_enter_ex(struct Main *bmain, struct wmWindowManager *wm, struct Scene *scene, struct Object *ob); -void ED_object_vpaintmode_enter(struct bContext *C); void ED_object_wpaintmode_enter_ex(struct Main *bmain, struct Depsgraph *depsgraph, struct wmWindowManager *wm, struct Scene *scene, struct Object *ob); -void ED_object_wpaintmode_enter(struct bContext *C); void ED_object_vpaintmode_exit_ex(struct Object *ob); void ED_object_vpaintmode_exit(struct bContext *C); @@ -185,12 +183,10 @@ void ED_object_sculptmode_enter_ex(struct Main *bmain, struct Object *ob, const bool force_dyntopo, struct ReportList *reports); -void ED_object_sculptmode_enter(struct bContext *C, struct ReportList *reports); void ED_object_sculptmode_exit_ex(struct Main *bmain, struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob); -void ED_object_sculptmode_exit(struct bContext *C); void ED_object_location_from_view(struct bContext *C, float loc[3]); void ED_object_rotation_from_quat(float rot[3], const float quat[4], const char align_axis); @@ -271,7 +267,6 @@ bool ED_object_mode_compat_set(struct bContext *C, struct ReportList *reports); void ED_object_mode_toggle(struct bContext *C, eObjectMode mode); void ED_object_mode_set(struct bContext *C, eObjectMode mode); -void ED_object_mode_exit(struct bContext *C); bool ED_object_mode_generic_enter(struct bContext *C, eObjectMode object_mode); void ED_object_mode_generic_exit(struct Main *bmain, diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index 93268456277..081bcbf4746 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -76,6 +76,10 @@ enum eGPUFXFlags; typedef struct ViewContext { struct bContext *C; struct Main *bmain; + /* Dependency graph is uses for depth drawing, viewport camera matrix access, and also some areas + * are re-using this to access evaluated entities. + * + * Moral of the story: assign to a fully evaluated state. */ struct Depsgraph *depsgraph; struct Scene *scene; struct ViewLayer *view_layer; @@ -512,26 +516,6 @@ int view3d_opengl_select(struct ViewContext *vc, eV3DSelectObjectFilter select_filter); /* view3d_select.c */ -struct EDSelectID_Context; -struct EDSelectID_Context *ED_view3d_select_id_context_create(struct ViewContext *vc, - struct Base **bases, - const uint bases_len, - short select_mode); - -void ED_view3d_select_id_context_destroy(struct EDSelectID_Context *sel_id_ctx); -void ED_view3d_select_id_validate_view_matrices(struct EDSelectID_Context *sel_id_ctx, - struct ViewContext *vc); - -uint ED_view3d_select_id_context_offset_for_object_elem( - const struct EDSelectID_Context *sel_id_ctx, int base_index, char elem_type); - -uint ED_view3d_select_id_context_elem_len(const struct EDSelectID_Context *sel_id_ctx); -bool ED_view3d_select_id_elem_get(struct EDSelectID_Context *sel_id_ctx, - const uint sel_id, - uint *r_elem, - uint *r_base_index, - char *r_elem_type); - float ED_view3d_select_dist_px(void); void ED_view3d_viewcontext_init(struct bContext *C, struct ViewContext *vc); void ED_view3d_viewcontext_init_object(struct ViewContext *vc, struct Object *obact); @@ -584,7 +568,7 @@ void ED_view3d_draw_offscreen(struct Depsgraph *depsgraph, bool do_sky, bool is_persp, const char *viewname, - const bool do_color_managment, + const bool do_color_management, struct GPUOffScreen *ofs, struct GPUViewport *viewport); void ED_view3d_draw_setup_view(struct wmWindow *win, diff --git a/source/blender/editors/include/UI_icons.h b/source/blender/editors/include/UI_icons.h index 47cf827ed66..03a49943ed3 100644 --- a/source/blender/editors/include/UI_icons.h +++ b/source/blender/editors/include/UI_icons.h @@ -90,8 +90,8 @@ DEF_ICON(COPY_ID) DEF_ICON(EYEDROPPER) DEF_ICON_BLANK(92) DEF_ICON(AUTO) -DEF_ICON(CHECKBOX_DEHLT) /* de-Hilight - Checkbox OFF */ -DEF_ICON(CHECKBOX_HLT) /* Hilight - Checkbox ON */ +DEF_ICON(CHECKBOX_DEHLT) /* de-Highlight - Checkbox OFF */ +DEF_ICON(CHECKBOX_HLT) /* Highlight - Checkbox ON */ DEF_ICON(UNLOCKED) DEF_ICON(LOCKED) DEF_ICON(UNPINNED) diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 3b2a80c1e05..5ef3e5d8987 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -562,7 +562,8 @@ int UI_popover_panel_invoke(struct bContext *C, bool keep_open, struct ReportList *reports); -uiPopover *UI_popover_begin(struct bContext *C, int menu_width) ATTR_NONNULL(1); +uiPopover *UI_popover_begin(struct bContext *C, int menu_width, bool from_active_button) + ATTR_NONNULL(1); void UI_popover_end(struct bContext *C, struct uiPopover *head, struct wmKeyMap *keymap); struct uiLayout *UI_popover_layout(uiPopover *head); void UI_popover_once_clear(uiPopover *pup); diff --git a/source/blender/editors/interface/interface_anim.c b/source/blender/editors/interface/interface_anim.c index 5ff200fa7e4..4d87cc22ef2 100644 --- a/source/blender/editors/interface/interface_anim.c +++ b/source/blender/editors/interface/interface_anim.c @@ -286,12 +286,11 @@ void ui_but_anim_autokey(bContext *C, uiBut *but, Scene *scene, float cfra) if (special) { /* NLA Strip property */ if (IS_AUTOKEY_ON(scene)) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); ReportList *reports = CTX_wm_reports(C); ToolSettings *ts = scene->toolsettings; insert_keyframe_direct( - depsgraph, reports, but->rnapoin, but->rnaprop, fcu, cfra, ts->keyframe_type, NULL, 0); + reports, but->rnapoin, but->rnaprop, fcu, cfra, ts->keyframe_type, NULL, 0); WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL); } } @@ -300,12 +299,10 @@ void ui_but_anim_autokey(bContext *C, uiBut *but, Scene *scene, float cfra) * making it easier to set up corrective drivers */ if (IS_AUTOKEY_ON(scene)) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); ReportList *reports = CTX_wm_reports(C); ToolSettings *ts = scene->toolsettings; - insert_keyframe_direct(depsgraph, - reports, + insert_keyframe_direct(reports, but->rnapoin, but->rnaprop, fcu, @@ -321,7 +318,6 @@ void ui_but_anim_autokey(bContext *C, uiBut *but, Scene *scene, float cfra) /* TODO: this should probably respect the keyingset only option for anim */ if (autokeyframe_cfra_can_key(scene, id)) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); ReportList *reports = CTX_wm_reports(C); ToolSettings *ts = scene->toolsettings; short flag = ANIM_get_keyframing_flags(scene, 1); @@ -333,7 +329,6 @@ void ui_but_anim_autokey(bContext *C, uiBut *but, Scene *scene, float cfra) * E.g., color wheels (see T42567). */ BLI_assert((fcu->array_index == but->rnaindex) || (but->rnaindex == -1)); insert_keyframe(bmain, - depsgraph, reports, id, action, diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c index 7afdbe9d266..6a36bf364a3 100644 --- a/source/blender/editors/interface/interface_draw.c +++ b/source/blender/editors/interface/interface_draw.c @@ -1606,6 +1606,11 @@ void ui_draw_but_COLORBAND(uiBut *but, const uiWidgetColors *UNUSED(wcol), const float sizey_solid = sizey * 0.25f; float y1 = rect->ymin; + /* exit early if too narrow */ + if (sizex <= 0) { + return; + } + GPUVertFormat *format = immVertexFormat(); pos_id = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); immBindBuiltinProgram(GPU_SHADER_2D_CHECKER); diff --git a/source/blender/editors/interface/interface_eyedropper_depth.c b/source/blender/editors/interface/interface_eyedropper_depth.c index fc60fc06ac0..2e51701e01d 100644 --- a/source/blender/editors/interface/interface_eyedropper_depth.c +++ b/source/blender/editors/interface/interface_eyedropper_depth.c @@ -168,7 +168,7 @@ static void depthdropper_depth_sample_pt( if (sa->spacetype == SPACE_VIEW3D) { ARegion *ar = BKE_area_find_region_xy(sa, RGN_TYPE_WINDOW, mx, my); if (ar) { - struct Depsgraph *depsgraph = CTX_data_depsgraph(C); + struct Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); View3D *v3d = sa->spacedata.first; RegionView3D *rv3d = ar->regiondata; /* weak, we could pass in some reference point */ diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index a7fc0cfec25..245277c8d22 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -10113,31 +10113,18 @@ static int ui_handler_region_menu(bContext *C, const wmEvent *event, void *UNUSE if (but) { bScreen *screen = CTX_wm_screen(C); - ARegion *ar_temp; uiBut *but_other; uiHandleButtonData *data; - bool is_inside_menu = false; - - /* look for a popup menu containing the mouse */ - for (ar_temp = screen->regionbase.first; ar_temp; ar_temp = ar_temp->next) { - rcti winrct; - - ui_region_winrct_get_no_margin(ar_temp, &winrct); - - if (BLI_rcti_isect_pt_v(&winrct, &event->x)) { - BLI_assert(ar_temp->type->regionid == RGN_TYPE_TEMPORARY); - - is_inside_menu = true; - break; - } - } /* handle activated button events */ data = but->active; if ((data->state == BUTTON_STATE_MENU_OPEN) && + /* Make sure this popup isn't dragging a button. + * can happen with popovers (see T67882). */ + (ui_region_find_active_but(data->menu->region) == NULL) && /* make sure mouse isn't inside another menu (see T43247) */ - (is_inside_menu == false) && + (ui_screen_region_find_mouse_over(screen, event) == NULL) && (ELEM(but->type, UI_BTYPE_PULLDOWN, UI_BTYPE_POPOVER, UI_BTYPE_MENU)) && (but_other = ui_but_find_mouse_over(ar, event)) && (but != but_other) && (ELEM(but_other->type, UI_BTYPE_PULLDOWN, UI_BTYPE_POPOVER, UI_BTYPE_MENU))) { diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c index ea5ef94d90d..7584a43a790 100644 --- a/source/blender/editors/interface/interface_icons.c +++ b/source/blender/editors/interface/interface_icons.c @@ -464,7 +464,7 @@ DEF_ICON_VECTOR_COLORSET_DRAW_NTH(20, 19) # undef DEF_ICON_VECTOR_COLORSET_DRAW_NTH /* Dynamically render icon instead of rendering a plain color to a texture/buffer - * This is mot strictly a "vicon", as it needs access to icon->obj to get the color info, + * This is not strictly a "vicon", as it needs access to icon->obj to get the color info, * but it works in a very similar way. */ static void vicon_gplayer_color_draw(Icon *icon, int x, int y, int w, int h) diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h index fc65129ebf7..a5d9d35e2fe 100644 --- a/source/blender/editors/interface/interface_intern.h +++ b/source/blender/editors/interface/interface_intern.h @@ -938,6 +938,9 @@ uiBut *ui_region_find_active_but(struct ARegion *ar) ATTR_WARN_UNUSED_RESULT; bool ui_region_contains_point_px(const struct ARegion *ar, int x, int y) ATTR_WARN_UNUSED_RESULT; bool ui_region_contains_rect_px(const struct ARegion *ar, const rcti *rect_px); +ARegion *ui_screen_region_find_mouse_over_ex(bScreen *screen, int x, int y); +ARegion *ui_screen_region_find_mouse_over(bScreen *screen, const struct wmEvent *event); + /* interface_context_menu.c */ bool ui_popup_context_menu_for_button(struct bContext *C, uiBut *but); void ui_popup_context_menu_for_panel(struct bContext *C, struct ARegion *ar, struct Panel *pa); diff --git a/source/blender/editors/interface/interface_query.c b/source/blender/editors/interface/interface_query.c index 462183b4245..d0efb3714bc 100644 --- a/source/blender/editors/interface/interface_query.c +++ b/source/blender/editors/interface/interface_query.c @@ -570,3 +570,29 @@ bool ui_region_contains_rect_px(const ARegion *ar, const rcti *rect_px) } /** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Screen (#bScreen) Spatial + * \{ */ + +/** Check if the cursor is over any popups. */ +ARegion *ui_screen_region_find_mouse_over_ex(bScreen *screen, int x, int y) +{ + for (ARegion *ar = screen->regionbase.first; ar; ar = ar->next) { + rcti winrct; + + ui_region_winrct_get_no_margin(ar, &winrct); + + if (BLI_rcti_isect_pt(&winrct, x, y)) { + return ar; + } + } + return NULL; +} + +ARegion *ui_screen_region_find_mouse_over(bScreen *screen, const wmEvent *event) +{ + return ui_screen_region_find_mouse_over_ex(screen, event->x, event->y); +} + +/** \} */ diff --git a/source/blender/editors/interface/interface_region_hud.c b/source/blender/editors/interface/interface_region_hud.c index 43afdc534ad..54bdbe0ec6e 100644 --- a/source/blender/editors/interface/interface_region_hud.c +++ b/source/blender/editors/interface/interface_region_hud.c @@ -57,16 +57,32 @@ /* -------------------------------------------------------------------- */ /** \name Utilities * \{ */ +struct HudRegionData { + short regionid; +}; -static bool last_redo_poll(const bContext *C) +static bool last_redo_poll(const bContext *C, short region_type) { wmOperator *op = WM_operator_last_redo(C); if (op == NULL) { return false; } + bool success = false; - if (WM_operator_repeat_check(C, op) && WM_operator_check_ui_empty(op->type) == false) { - success = WM_operator_poll((bContext *)C, op->type); + { + /* Make sure that we are using the same region type as the original + * operator call. Otherwise we would be polling the operator with the + * wrong context. + */ + ScrArea *sa = CTX_wm_area(C); + ARegion *ar_op = (region_type != -1) ? BKE_area_find_region_type(sa, region_type) : NULL; + ARegion *ar_prev = CTX_wm_region(C); + CTX_wm_region_set((bContext *)C, ar_op); + + if (WM_operator_repeat_check(C, op) && WM_operator_check_ui_empty(op->type) == false) { + success = WM_operator_poll((bContext *)C, op->type); + } + CTX_wm_region_set((bContext *)C, ar_prev); } return success; } @@ -87,7 +103,15 @@ static void hud_region_hide(ARegion *ar) static bool hud_panel_operator_redo_poll(const bContext *C, PanelType *UNUSED(pt)) { - return last_redo_poll(C); + ScrArea *sa = CTX_wm_area(C); + ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_HUD); + if (ar != NULL) { + struct HudRegionData *hrd = ar->regiondata; + if (hrd != NULL) { + return last_redo_poll(C, hrd->regionid); + } + } + return false; } static void hud_panel_operator_redo_draw_header(const bContext *C, Panel *pa) @@ -132,10 +156,6 @@ static void hud_panels_register(ARegionType *art, int space_type, int region_typ /** \name Callbacks for Floating Region * \{ */ -struct HudRegionData { - short regionid; -}; - static void hud_region_init(wmWindowManager *wm, ARegion *ar) { ED_region_panels_init(wm, ar); @@ -150,21 +170,8 @@ static void hud_region_free(ARegion *ar) static void hud_region_layout(const bContext *C, ARegion *ar) { - bool ok = false; - - { - struct HudRegionData *hrd = ar->regiondata; - if (hrd != NULL) { - ScrArea *sa = CTX_wm_area(C); - ARegion *ar_op = (hrd->regionid != -1) ? BKE_area_find_region_type(sa, hrd->regionid) : NULL; - ARegion *ar_prev = CTX_wm_region(C); - CTX_wm_region_set((bContext *)C, ar_op); - ok = last_redo_poll(C); - CTX_wm_region_set((bContext *)C, ar_prev); - } - } - - if (!ok) { + struct HudRegionData *hrd = ar->regiondata; + if (hrd == NULL || !last_redo_poll(C, hrd->regionid)) { ED_region_tag_redraw(ar); hud_region_hide(ar); return; @@ -301,7 +308,9 @@ void ED_area_type_hud_ensure(bContext *C, ScrArea *sa) bool init = false; bool was_hidden = ar == NULL || ar->visible == false; - if (!last_redo_poll(C)) { + ARegion *ar_op = CTX_wm_region(C); + BLI_assert((ar_op == NULL) || (ar_op->regiontype != RGN_TYPE_HUD)); + if (!last_redo_poll(C, ar_op ? ar_op->regiontype : -1)) { if (ar) { ED_region_tag_redraw(ar); hud_region_hide(ar); @@ -328,8 +337,6 @@ void ED_area_type_hud_ensure(bContext *C, ScrArea *sa) } { - ARegion *ar_op = CTX_wm_region(C); - BLI_assert((ar_op == NULL) || (ar_op->regiontype != RGN_TYPE_HUD)); struct HudRegionData *hrd = ar->regiondata; if (hrd == NULL) { hrd = MEM_callocN(sizeof(*hrd), __func__); diff --git a/source/blender/editors/interface/interface_region_popover.c b/source/blender/editors/interface/interface_region_popover.c index 53c96fb72a7..028d99ac052 100644 --- a/source/blender/editors/interface/interface_region_popover.c +++ b/source/blender/editors/interface/interface_region_popover.c @@ -72,6 +72,7 @@ struct uiPopover { uiBlock *block; uiLayout *layout; uiBut *but; + ARegion *butregion; /* Needed for keymap removal. */ wmWindow *window; @@ -325,7 +326,7 @@ int UI_popover_panel_invoke(bContext *C, const char *idname, bool keep_open, Rep block = pup->block; } else { - uiPopover *pup = UI_popover_begin(C, U.widget_unit * pt->ui_units_x); + uiPopover *pup = UI_popover_begin(C, U.widget_unit * pt->ui_units_x, false); layout = UI_popover_layout(pup); UI_paneltype_draw(C, pt, layout); UI_popover_end(C, pup, NULL); @@ -346,8 +347,11 @@ int UI_popover_panel_invoke(bContext *C, const char *idname, bool keep_open, Rep /** * Only return handler, and set optional title. + * + * \param from_active_button: Use the active button for positioning, + * use when the popover is activated from an operator instead of directly from the button. */ -uiPopover *UI_popover_begin(bContext *C, int ui_size_x) +uiPopover *UI_popover_begin(bContext *C, int ui_size_x, bool from_active_button) { uiPopover *pup = MEM_callocN(sizeof(uiPopover), "popover menu"); if (ui_size_x == 0) { @@ -355,6 +359,20 @@ uiPopover *UI_popover_begin(bContext *C, int ui_size_x) } pup->ui_size_x = ui_size_x; + ARegion *butregion = NULL; + uiBut *but = NULL; + + if (from_active_button) { + butregion = CTX_wm_region(C); + but = UI_region_active_but_get(butregion); + if (but == NULL) { + butregion = NULL; + } + } + + pup->but = but; + pup->butregion = butregion; + /* Operator context default same as menus, change if needed. */ ui_popover_create_block(C, pup, WM_OP_EXEC_REGION_WIN); @@ -387,7 +405,7 @@ void UI_popover_end(bContext *C, uiPopover *pup, wmKeyMap *keymap) } handle = ui_popup_block_create( - C, NULL, NULL, NULL, ui_block_func_POPOVER, pup, ui_block_free_func_POPOVER); + C, pup->butregion, pup->but, NULL, ui_block_func_POPOVER, pup, ui_block_free_func_POPOVER); /* Add handlers. */ UI_popup_handlers_add(C, &window->modalhandlers, handle, 0); diff --git a/source/blender/editors/interface/view2d_ops.c b/source/blender/editors/interface/view2d_ops.c index 7d9b722fcc0..b57d100127e 100644 --- a/source/blender/editors/interface/view2d_ops.c +++ b/source/blender/editors/interface/view2d_ops.c @@ -31,6 +31,7 @@ #include "BLI_blenlib.h" #include "BLI_utildefines.h" #include "BLI_math_base.h" +#include "BLI_math_vector.h" #include "BKE_context.h" @@ -1146,33 +1147,49 @@ static int view_zoomdrag_modal(bContext *C, wmOperator *op, const wmEvent *event } else if (event->type == MOUSEMOVE) { float dx, dy; + float zoomfac = 0.01f; + + /* some view2d's (graph) don't have min/max zoom, or extreme ones */ + if (v2d->maxzoom > 0.0f) { + zoomfac = clamp_f(0.001f * v2d->maxzoom, 0.001f, 0.01f); + } /* calculate new delta transform, based on zooming mode */ if (U.viewzoom == USER_ZOOM_SCALE) { /* 'scale' zooming */ float dist; + float len_old[2]; + float len_new[2]; /* x-axis transform */ dist = BLI_rcti_size_x(&v2d->mask) / 2.0f; - dx = 1.0f - (fabsf(vzd->lastx - vzd->ar->winrct.xmin - dist) + 2.0f) / - (fabsf(event->mval[0] - dist) + 2.0f); - dx *= 0.5f * BLI_rctf_size_x(&v2d->cur); + len_old[0] = fabsf(vzd->lastx - vzd->ar->winrct.xmin - dist); + len_new[0] = fabsf(event->x - vzd->ar->winrct.xmin - dist); + + len_old[0] *= zoomfac * BLI_rctf_size_x(&v2d->cur); + len_new[0] *= zoomfac * BLI_rctf_size_x(&v2d->cur); /* y-axis transform */ dist = BLI_rcti_size_y(&v2d->mask) / 2.0f; - dy = 1.0f - (fabsf(vzd->lasty - vzd->ar->winrct.ymin - dist) + 2.0f) / - (fabsf(event->mval[1] - dist) + 2.0f); - dy *= 0.5f * BLI_rctf_size_y(&v2d->cur); + len_old[1] = fabsf(vzd->lasty - vzd->ar->winrct.ymin - dist); + len_new[1] = fabsf(event->y - vzd->ar->winrct.ymin - dist); + + len_old[1] *= zoomfac * BLI_rctf_size_y(&v2d->cur); + len_new[1] *= zoomfac * BLI_rctf_size_y(&v2d->cur); + + /* Calculate distance */ + if (v2d->keepzoom & V2D_KEEPASPECT) { + dist = len_v2(len_new) - len_v2(len_old); + dx = dy = dist; + } + else { + dx = len_new[0] - len_old[0]; + dy = len_new[1] - len_old[1]; + } } else { /* 'continuous' or 'dolly' */ - float fac, zoomfac = 0.01f; - - /* some view2d's (graph) don't have min/max zoom, or extreme ones */ - if (v2d->maxzoom > 0.0f) { - zoomfac = clamp_f(0.001f * v2d->maxzoom, 0.001f, 0.01f); - } - + float fac; /* x-axis transform */ fac = zoomfac * (event->x - vzd->lastx); dx = fac * BLI_rctf_size_x(&v2d->cur); @@ -1180,6 +1197,18 @@ static int view_zoomdrag_modal(bContext *C, wmOperator *op, const wmEvent *event /* y-axis transform */ fac = zoomfac * (event->y - vzd->lasty); dy = fac * BLI_rctf_size_y(&v2d->cur); + + /* Only respect user setting zoom axis if the view does not have any zoom restrictions + * any will be scaled uniformly */ + if ((v2d->keepzoom & V2D_LOCKZOOM_X) == 0 && (v2d->keepzoom & V2D_LOCKZOOM_Y) == 0 && + (v2d->keepzoom & V2D_KEEPASPECT)) { + if (U.uiflag & USER_ZOOM_HORIZ) { + dy = 0; + } + else { + dx = 0; + } + } } /* support zoom to always zoom entirely - the v2d code uses portrait or diff --git a/source/blender/editors/io/io_cache.c b/source/blender/editors/io/io_cache.c index 9fdcec71cfd..ff2bc72c2f7 100644 --- a/source/blender/editors/io/io_cache.c +++ b/source/blender/editors/io/io_cache.c @@ -147,7 +147,7 @@ static int cachefile_reload_exec(bContext *C, wmOperator *UNUSED(op)) return OPERATOR_CANCELLED; } - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); BKE_cachefile_reload(depsgraph, cache_file); return OPERATOR_FINISHED; diff --git a/source/blender/editors/mask/mask_add.c b/source/blender/editors/mask/mask_add.c index 883dfe9ad7c..683e6d8a2b0 100644 --- a/source/blender/editors/mask/mask_add.c +++ b/source/blender/editors/mask/mask_add.c @@ -72,7 +72,7 @@ bool ED_mask_find_nearest_diff_point(const bContext *C, float u = 0.0f; float scalex, scaley; - Depsgraph *depsgraph = CTX_data_evaluated_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Mask *mask_eval = (Mask *)DEG_get_evaluated_id(depsgraph, &mask_orig->id); ED_mask_get_size(sa, &width, &height); diff --git a/source/blender/editors/mask/mask_ops.c b/source/blender/editors/mask/mask_ops.c index 8e4efddd8a7..c91f431ad20 100644 --- a/source/blender/editors/mask/mask_ops.c +++ b/source/blender/editors/mask/mask_ops.c @@ -86,7 +86,7 @@ MaskSplinePoint *ED_mask_point_find_nearest(const bContext *C, eMaskWhichHandle which_handle = MASK_WHICH_HANDLE_NONE; int width, height; - Depsgraph *depsgraph = CTX_data_evaluated_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Mask *mask_eval = (Mask *)DEG_get_evaluated_id(depsgraph, &mask_orig->id); ED_mask_get_size(sa, &width, &height); @@ -241,7 +241,7 @@ bool ED_mask_feather_find_nearest(const bContext *C, float scalex, scaley; int width, height; - Depsgraph *depsgraph = CTX_data_evaluated_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Mask *mask_eval = (Mask *)DEG_get_evaluated_id(depsgraph, &mask_orig->id); ED_mask_get_size(sa, &width, &height); diff --git a/source/blender/editors/mesh/CMakeLists.txt b/source/blender/editors/mesh/CMakeLists.txt index 57bf67e825e..9a779db4812 100644 --- a/source/blender/editors/mesh/CMakeLists.txt +++ b/source/blender/editors/mesh/CMakeLists.txt @@ -23,6 +23,7 @@ set(INC ../../blentranslation ../../bmesh ../../depsgraph + ../../draw ../../gpu ../../imbuf ../../makesdna diff --git a/source/blender/editors/mesh/editface.c b/source/blender/editors/mesh/editface.c index d61c340f7a2..9a70b0a8d36 100644 --- a/source/blender/editors/mesh/editface.c +++ b/source/blender/editors/mesh/editface.c @@ -77,7 +77,7 @@ void paintface_flush_flags(struct bContext *C, Object *ob, short flag) BKE_mesh_flush_select_from_polys(me); } - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); if (ob_eval == NULL) { diff --git a/source/blender/editors/mesh/editmesh_extrude.c b/source/blender/editors/mesh/editmesh_extrude.c index 0da4d20c6b5..5b16cfd00f5 100644 --- a/source/blender/editors/mesh/editmesh_extrude.c +++ b/source/blender/editors/mesh/editmesh_extrude.c @@ -658,6 +658,7 @@ void MESH_OT_extrude_faces_indiv(wmOperatorType *ot) static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, const wmEvent *event) { + struct Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); ViewContext vc; BMVert *v1; BMIter iter; @@ -819,7 +820,7 @@ static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, const w /* also project the source, for retopo workflow */ if (use_proj) { - EDBM_project_snap_verts(C, vc.ar, vc.em); + EDBM_project_snap_verts(C, depsgraph, vc.ar, vc.em); } } @@ -852,7 +853,7 @@ static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, const w } if (use_proj) { - EDBM_project_snap_verts(C, vc.ar, vc.em); + EDBM_project_snap_verts(C, depsgraph, vc.ar, vc.em); } /* This normally happens when pushing undo but modal operators diff --git a/source/blender/editors/mesh/editmesh_knife_project.c b/source/blender/editors/mesh/editmesh_knife_project.c index 13bcb1334a9..3d34a4ad3b5 100644 --- a/source/blender/editors/mesh/editmesh_knife_project.c +++ b/source/blender/editors/mesh/editmesh_knife_project.c @@ -57,7 +57,7 @@ static LinkNode *knifeproject_poly_from_object(const bContext *C, Object *ob, LinkNode *polys) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); ARegion *ar = CTX_wm_region(C); struct Mesh *me_eval; bool me_eval_needs_free; @@ -173,7 +173,7 @@ void MESH_OT_knife_project(wmOperatorType *ot) ot->poll = ED_operator_editmesh_region_view3d; /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING | OPTYPE_USE_EVAL_DATA; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING; /* parameters */ RNA_def_boolean(ot->srna, diff --git a/source/blender/editors/mesh/editmesh_loopcut.c b/source/blender/editors/mesh/editmesh_loopcut.c index c7606758b63..2ddd654f824 100644 --- a/source/blender/editors/mesh/editmesh_loopcut.c +++ b/source/blender/editors/mesh/editmesh_loopcut.c @@ -272,7 +272,7 @@ static int ringsel_init(bContext *C, wmOperator *op, bool do_cut) em_setup_viewcontext(C, &lcd->vc); - lcd->depsgraph = CTX_data_depsgraph(C); + lcd->depsgraph = CTX_data_ensure_evaluated_depsgraph(C); /* assign the drawing handle for drawing preview line... */ lcd->ar = CTX_wm_region(C); diff --git a/source/blender/editors/mesh/editmesh_select.c b/source/blender/editors/mesh/editmesh_select.c index 7b770f055b4..12b5a36c510 100644 --- a/source/blender/editors/mesh/editmesh_select.c +++ b/source/blender/editors/mesh/editmesh_select.c @@ -68,6 +68,8 @@ #include "DEG_depsgraph.h" #include "DEG_depsgraph_query.h" +#include "DRW_engine.h" + #include "mesh_intern.h" /* own include */ /* use bmesh operator flags for a few operators */ @@ -197,15 +199,11 @@ void EDBM_automerge(Scene *scene, Object *obedit, bool update, const char hflag) /** \name Back-Buffer OpenGL Selection * \{ */ -static BMElem *EDBM_select_id_bm_elem_get(struct EDSelectID_Context *sel_id_ctx, - Base **bases, - const uint sel_id, - uint *r_base_index) +static BMElem *edbm_select_id_bm_elem_get(Base **bases, const uint sel_id, uint *r_base_index) { uint elem_id; char elem_type = 0; - bool success = ED_view3d_select_id_elem_get( - sel_id_ctx, sel_id, &elem_id, r_base_index, &elem_type); + bool success = DRW_select_elem_get(sel_id, &elem_id, r_base_index, &elem_type); if (success) { Object *obedit = bases[*r_base_index]->object; @@ -335,20 +333,17 @@ BMVert *EDBM_vert_find_nearest_ex(ViewContext *vc, { FAKE_SELECT_MODE_BEGIN(vc, fake_select_mode, select_mode, SCE_SELECT_VERTEX); - struct EDSelectID_Context *sel_id_ctx = ED_view3d_select_id_context_create( - vc, bases, bases_len, select_mode); + DRW_draw_select_id(vc->depsgraph, vc->ar, vc->v3d, bases, bases_len, select_mode); index = ED_select_buffer_find_nearest_to_point(vc->mval, 1, UINT_MAX, &dist_px); if (index) { - eve = (BMVert *)EDBM_select_id_bm_elem_get(sel_id_ctx, bases, index, &base_index); + eve = (BMVert *)edbm_select_id_bm_elem_get(bases, index, &base_index); } else { eve = NULL; } - ED_view3d_select_id_context_destroy(sel_id_ctx); - FAKE_SELECT_MODE_END(vc, fake_select_mode); } @@ -564,20 +559,17 @@ BMEdge *EDBM_edge_find_nearest_ex(ViewContext *vc, { FAKE_SELECT_MODE_BEGIN(vc, fake_select_mode, select_mode, SCE_SELECT_EDGE); - struct EDSelectID_Context *sel_id_ctx = ED_view3d_select_id_context_create( - vc, bases, bases_len, select_mode); + DRW_draw_select_id(vc->depsgraph, vc->ar, vc->v3d, bases, bases_len, select_mode); index = ED_select_buffer_find_nearest_to_point(vc->mval, 1, UINT_MAX, &dist_px); if (index) { - eed = (BMEdge *)EDBM_select_id_bm_elem_get(sel_id_ctx, bases, index, &base_index); + eed = (BMEdge *)edbm_select_id_bm_elem_get(bases, index, &base_index); } else { eed = NULL; } - ED_view3d_select_id_context_destroy(sel_id_ctx); - FAKE_SELECT_MODE_END(vc, fake_select_mode); } @@ -777,20 +769,17 @@ BMFace *EDBM_face_find_nearest_ex(ViewContext *vc, { FAKE_SELECT_MODE_BEGIN(vc, fake_select_mode, select_mode, SCE_SELECT_FACE); - struct EDSelectID_Context *sel_id_ctx = ED_view3d_select_id_context_create( - vc, bases, bases_len, select_mode); + DRW_draw_select_id(vc->depsgraph, vc->ar, vc->v3d, bases, bases_len, select_mode); index = ED_select_buffer_sample_point(vc->mval); if (index) { - efa = (BMFace *)EDBM_select_id_bm_elem_get(sel_id_ctx, bases, index, &base_index); + efa = (BMFace *)edbm_select_id_bm_elem_get(bases, index, &base_index); } else { efa = NULL; } - ED_view3d_select_id_context_destroy(sel_id_ctx); - FAKE_SELECT_MODE_END(vc, fake_select_mode); } diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c index 919de4cdb20..ecdf103e6eb 100644 --- a/source/blender/editors/mesh/editmesh_tools.c +++ b/source/blender/editors/mesh/editmesh_tools.c @@ -411,7 +411,7 @@ void MESH_OT_unsubdivide(wmOperatorType *ot) ot->srna, "iterations", 2, 1, 1000, "Iterations", "Number of times to unsubdivide", 1, 100); } -void EDBM_project_snap_verts(bContext *C, ARegion *ar, BMEditMesh *em) +void EDBM_project_snap_verts(bContext *C, Depsgraph *depsgraph, ARegion *ar, BMEditMesh *em) { Main *bmain = CTX_data_main(C); Object *obedit = em->ob; @@ -421,7 +421,7 @@ void EDBM_project_snap_verts(bContext *C, ARegion *ar, BMEditMesh *em) ED_view3d_init_mats_rv3d(obedit, ar->regiondata); struct SnapObjectContext *snap_context = ED_transform_snap_object_context_create_view3d( - bmain, CTX_data_scene(C), CTX_data_depsgraph(C), 0, ar, CTX_wm_view3d(C)); + bmain, CTX_data_scene(C), depsgraph, 0, ar, CTX_wm_view3d(C)); BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) { @@ -4593,7 +4593,8 @@ static int edbm_fill_grid_exec(bContext *C, wmOperator *op) /* Only reuse on redo because these settings need to match the current selection. * We never want to use them on other geometry, repeat last for eg, see: T60777. */ - if ((op->flag & OP_IS_REPEAT_LAST) == 0 && RNA_property_is_set(op->ptr, prop_span)) { + if (((op->flag & OP_IS_INVOKE) || (op->flag & OP_IS_REPEAT_LAST) == 0) && + RNA_property_is_set(op->ptr, prop_span)) { span = RNA_property_int_get(op->ptr, prop_span); span = min_ii(span, (clamp / 2) - 1); calc_span = false; @@ -8615,7 +8616,7 @@ static int edbm_normals_tools_exec(bContext *C, wmOperator *op) switch (mode) { case EDBM_CLNOR_TOOLS_COPY: - if (bm->totfacesel == 0 || bm->totvertsel == 0) { + if (bm->totfacesel == 0 && bm->totvertsel == 0) { BM_loop_normal_editdata_array_free(lnors_ed_arr); continue; } diff --git a/source/blender/editors/mesh/editmesh_undo.c b/source/blender/editors/mesh/editmesh_undo.c index e823fb46140..7071258d8cf 100644 --- a/source/blender/editors/mesh/editmesh_undo.c +++ b/source/blender/editors/mesh/editmesh_undo.c @@ -699,7 +699,6 @@ typedef struct MeshUndoStep_Elem { typedef struct MeshUndoStep { UndoStep step; - struct UndoIDPtrMap *id_map; MeshUndoStep_Elem *elems; uint elems_len; } MeshUndoStep; @@ -788,10 +787,6 @@ static void mesh_undosys_step_free(UndoStep *us_p) undomesh_free_data(&elem->data); } MEM_freeN(us->elems); - - if (us->id_map != NULL) { - BKE_undosys_ID_map_destroy(us->id_map); - } } static void mesh_undosys_foreach_ID_ref(UndoStep *us_p, @@ -804,10 +799,6 @@ static void mesh_undosys_foreach_ID_ref(UndoStep *us_p, MeshUndoStep_Elem *elem = &us->elems[i]; foreach_ID_ref_fn(user_data, ((UndoRefID *)&elem->obedit_ref)); } - - if (us->id_map != NULL) { - BKE_undosys_ID_map_foreach_ID_ref(us->id_map, foreach_ID_ref_fn, user_data); - } } /* Export for ED_undo_sys. */ diff --git a/source/blender/editors/mesh/mesh_mirror.c b/source/blender/editors/mesh/mesh_mirror.c index d76801a2500..e086eda9b33 100644 --- a/source/blender/editors/mesh/mesh_mirror.c +++ b/source/blender/editors/mesh/mesh_mirror.c @@ -278,7 +278,7 @@ void ED_mesh_mirrtopo_init(Mesh *me, } if ((tot_unique <= tot_unique_prev) && (tot_unique_edges <= tot_unique_edges_prev)) { - /* Finish searching for unique values when 1 loop dosn't give a + /* Finish searching for unique values when 1 loop doesn't give a * higher number of unique values compared to the previous loop. */ break; } diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c index 41736fb9a14..b082af352b2 100644 --- a/source/blender/editors/mesh/meshtools.c +++ b/source/blender/editors/mesh/meshtools.c @@ -311,7 +311,7 @@ int join_mesh_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); /* count & check */ CTX_DATA_BEGIN (C, Object *, ob_iter, selected_editable_objects) { @@ -674,7 +674,7 @@ int join_mesh_shapes_exec(bContext *C, wmOperator *op) Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); Object *ob_active = CTX_data_active_object(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Mesh *me = (Mesh *)ob_active->data; Mesh *selme = NULL; Mesh *me_deformed = NULL; @@ -1165,7 +1165,7 @@ static void ed_mesh_pick_face_vert__mpoly_find( bool ED_mesh_pick_face_vert( bContext *C, Object *ob, const int mval[2], uint dist_px, uint *r_index) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); unsigned int poly_index; Mesh *me = ob->data; diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c index f8cf55933aa..137af917f9a 100644 --- a/source/blender/editors/object/object_add.c +++ b/source/blender/editors/object/object_add.c @@ -236,7 +236,7 @@ void ED_object_base_init_transform(bContext *C, Base *base, const float loc[3], { Object *ob = base->object; Scene *scene = CTX_data_scene(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); if (!scene) { return; @@ -250,7 +250,11 @@ void ED_object_base_init_transform(bContext *C, Base *base, const float loc[3], copy_v3_v3(ob->rot, rot); } - BKE_object_where_is_calc(depsgraph, scene, ob); + Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); + Object *object_eval = DEG_get_evaluated_object(depsgraph, ob); + BKE_object_transform_copy(object_eval, ob); + BKE_object_where_is_calc(depsgraph, scene_eval, object_eval); + BKE_object_transform_copy(ob, object_eval); } /* Uses context to figure out transform for primitive. @@ -1758,12 +1762,15 @@ static bool dupliobject_instancer_cmp(const void *a_, const void *b_) return false; } -static void make_object_duplilist_real( - bContext *C, Scene *scene, Base *base, const bool use_base_parent, const bool use_hierarchy) +static void make_object_duplilist_real(bContext *C, + Depsgraph *depsgraph, + Scene *scene, + Base *base, + const bool use_base_parent, + const bool use_hierarchy) { Main *bmain = CTX_data_main(C); ViewLayer *view_layer = CTX_data_view_layer(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); ListBase *lb_duplis; DupliObject *dob; GHash *dupli_gh, *parent_gh = NULL, *instancer_gh = NULL; @@ -1955,6 +1962,7 @@ static void make_object_duplilist_real( static int object_duplicates_make_real_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene = CTX_data_scene(C); const bool use_base_parent = RNA_boolean_get(op->ptr, "use_base_parent"); @@ -1963,7 +1971,7 @@ static int object_duplicates_make_real_exec(bContext *C, wmOperator *op) BKE_main_id_clear_newpoins(bmain); CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases) { - make_object_duplilist_real(C, scene, base, use_base_parent, use_hierarchy); + make_object_duplilist_real(C, depsgraph, scene, base, use_base_parent, use_hierarchy); /* dependencies were changed */ WM_event_add_notifier(C, NC_OBJECT | ND_PARENT, base->object); @@ -1990,7 +1998,7 @@ void OBJECT_OT_duplicates_make_real(wmOperatorType *ot) ot->poll = ED_operator_objectmode; /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; RNA_def_boolean(ot->srna, "use_base_parent", @@ -2131,7 +2139,7 @@ static Base *duplibase_for_convert( static int convert_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); - Depsgraph *depsgraph = CTX_data_evaluated_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); Base *basen = NULL, *basact = NULL; diff --git a/source/blender/editors/object/object_constraint.c b/source/blender/editors/object/object_constraint.c index 5ef133e87de..7343dba420f 100644 --- a/source/blender/editors/object/object_constraint.c +++ b/source/blender/editors/object/object_constraint.c @@ -864,13 +864,12 @@ void CONSTRAINT_OT_limitdistance_reset(wmOperatorType *ot) /* ------------- Child-Of Constraint ------------------ */ static void child_get_inverse_matrix_owner_bone( - const bContext *C, wmOperator *op, Scene *scene, Object *ob, float invmat[4][4]) + Depsgraph *depsgraph, wmOperator *op, Scene *scene, Object *ob, float invmat[4][4]) { /* For bone owner we want to do this in evaluated domain. * BKE_pose_where_is / BKE_pose_where_is_bone relies on (re)evaluating parts of the scene * and copying new evaluated stuff back to original. */ - Depsgraph *depsgraph = CTX_data_depsgraph(C); Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); bConstraint *con_eval = edit_constraint_property_get(op, ob_eval, CONSTRAINT_TYPE_CHILDOF); @@ -947,9 +946,8 @@ static void child_get_inverse_matrix_owner_bone( } static void child_get_inverse_matrix_owner_object( - const bContext *C, Scene *scene, Object *ob, bConstraint *con, float invmat[4][4]) + Depsgraph *depsgraph, Scene *scene, Object *ob, bConstraint *con, float invmat[4][4]) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); /* nullify inverse matrix first */ unit_m4(invmat); @@ -971,6 +969,7 @@ static void child_get_inverse_matrix_owner_object( static int childof_set_inverse_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene = CTX_data_scene(C); Object *ob = ED_object_active_context(C); bConstraint *con = edit_constraint_property_get(op, ob, CONSTRAINT_TYPE_CHILDOF); @@ -985,10 +984,10 @@ static int childof_set_inverse_exec(bContext *C, wmOperator *op) } if (owner == EDIT_CONSTRAINT_OWNER_OBJECT) { - child_get_inverse_matrix_owner_object(C, scene, ob, con, data->invmat); + child_get_inverse_matrix_owner_object(depsgraph, scene, ob, con, data->invmat); } else if (owner == EDIT_CONSTRAINT_OWNER_BONE) { - child_get_inverse_matrix_owner_bone(C, op, scene, ob, data->invmat); + child_get_inverse_matrix_owner_bone(depsgraph, op, scene, ob, data->invmat); } ED_object_constraint_update(bmain, ob); @@ -1224,6 +1223,7 @@ void CONSTRAINT_OT_followpath_path_animate(wmOperatorType *ot) static int objectsolver_set_inverse_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene = CTX_data_scene(C); Object *ob = ED_object_active_context(C); bConstraint *con = edit_constraint_property_get(op, ob, CONSTRAINT_TYPE_OBJECTSOLVER); @@ -1238,10 +1238,10 @@ static int objectsolver_set_inverse_exec(bContext *C, wmOperator *op) } if (owner == EDIT_CONSTRAINT_OWNER_OBJECT) { - child_get_inverse_matrix_owner_object(C, scene, ob, con, data->invmat); + child_get_inverse_matrix_owner_object(depsgraph, scene, ob, con, data->invmat); } else if (owner == EDIT_CONSTRAINT_OWNER_BONE) { - child_get_inverse_matrix_owner_bone(C, op, scene, ob, data->invmat); + child_get_inverse_matrix_owner_bone(depsgraph, op, scene, ob, data->invmat); } ED_object_constraint_update(bmain, ob); diff --git a/source/blender/editors/object/object_data_transfer.c b/source/blender/editors/object/object_data_transfer.c index 690bc270605..79aafc6978f 100644 --- a/source/blender/editors/object/object_data_transfer.c +++ b/source/blender/editors/object/object_data_transfer.c @@ -111,8 +111,6 @@ static const EnumPropertyItem *dt_layers_select_src_itemf(bContext *C, int totitem = 0; const int data_type = RNA_enum_get(ptr, "data_type"); - Depsgraph *depsgraph = CTX_data_depsgraph(C); - PropertyRNA *prop = RNA_struct_find_property(ptr, "use_reverse_transfer"); const bool reverse_transfer = prop != NULL && RNA_property_boolean_get(ptr, prop); const int layers_select_dst = reverse_transfer ? RNA_enum_get(ptr, "layers_select_src") : @@ -158,6 +156,7 @@ static const EnumPropertyItem *dt_layers_select_src_itemf(bContext *C, Mesh *me_eval; int num_data, i; + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); Object *ob_src_eval = DEG_get_evaluated_object(depsgraph, ob_src); @@ -183,6 +182,7 @@ static const EnumPropertyItem *dt_layers_select_src_itemf(bContext *C, Mesh *me_eval; int num_data, i; + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); Object *ob_src_eval = DEG_get_evaluated_object(depsgraph, ob_src); @@ -397,7 +397,7 @@ static bool data_transfer_exec_is_object_valid(wmOperator *op, static int data_transfer_exec(bContext *C, wmOperator *op) { Object *ob_src = ED_object_active_context(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); ListBase ctx_objects; @@ -613,7 +613,7 @@ void OBJECT_OT_data_transfer(wmOperatorType *ot) ot->check = data_transfer_check; /* Flags.*/ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* Properties.*/ prop = RNA_def_boolean(ot->srna, @@ -760,14 +760,14 @@ void OBJECT_OT_data_transfer(wmOperatorType *ot) static bool datalayout_transfer_poll(bContext *C) { - return (edit_modifier_poll_generic(C, &RNA_DataTransferModifier, (1 << OB_MESH)) || + return (edit_modifier_poll_generic(C, &RNA_DataTransferModifier, (1 << OB_MESH), true) || data_transfer_poll(C)); } static int datalayout_transfer_exec(bContext *C, wmOperator *op) { Object *ob_act = ED_object_active_context(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); DataTransferModifierData *dtmd; @@ -873,7 +873,7 @@ void OBJECT_OT_datalayout_transfer(wmOperatorType *ot) ot->check = data_transfer_check; /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* Properties.*/ edit_modifier_properties(ot); diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c index a390cf67cf5..ed40a4eb948 100644 --- a/source/blender/editors/object/object_edit.c +++ b/source/blender/editors/object/object_edit.c @@ -906,7 +906,9 @@ void ED_objects_recalculate_paths(bContext *C, Scene *scene, bool current_frame_ } Main *bmain = CTX_data_main(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + /* NOTE: Dependency graph will be evaluated at all the frames, but we first need to access some + * nested pointers, like animation data. */ + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); ListBase targets = {NULL, NULL}; /* loop over objects in scene */ @@ -1056,7 +1058,7 @@ void OBJECT_OT_paths_update(wmOperatorType *ot) ot->idname = "OBJECT_OT_paths_update"; ot->description = "Recalculate paths for selected objects"; - /* api callbakcs */ + /* api callbacks */ ot->exec = object_update_paths_exec; ot->poll = object_update_paths_poll; diff --git a/source/blender/editors/object/object_gpencil_modifier.c b/source/blender/editors/object/object_gpencil_modifier.c index 5c4fa5aeee6..075cd5acad6 100644 --- a/source/blender/editors/object/object_gpencil_modifier.c +++ b/source/blender/editors/object/object_gpencil_modifier.c @@ -596,7 +596,7 @@ void OBJECT_OT_gpencil_modifier_move_down(wmOperatorType *ot) static int gpencil_modifier_apply_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Object *ob = ED_object_active_context(C); GpencilModifierData *md = gpencil_edit_modifier_property_get(op, ob, 0); int apply_as = RNA_enum_get(op->ptr, "apply_as"); diff --git a/source/blender/editors/object/object_hook.c b/source/blender/editors/object/object_hook.c index c939cb0a61d..15c5ea40991 100644 --- a/source/blender/editors/object/object_hook.c +++ b/source/blender/editors/object/object_hook.c @@ -52,6 +52,7 @@ #include "DEG_depsgraph.h" #include "DEG_depsgraph_build.h" +#include "DEG_depsgraph_query.h" #include "RNA_define.h" #include "RNA_access.h" @@ -527,6 +528,7 @@ static int add_hook_object(const bContext *C, int mode, ReportList *reports) { + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); ModifierData *md = NULL; HookModifierData *hmd = NULL; float cent[3]; @@ -601,11 +603,14 @@ static int add_hook_object(const bContext *C, /* matrix calculus */ /* vert x (obmat x hook->imat) x hook->obmat x ob->imat */ /* (parentinv ) */ - BKE_object_where_is_calc(CTX_data_depsgraph(C), scene, ob); + Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); + Object *object_eval = DEG_get_evaluated_object(depsgraph, ob); + BKE_object_transform_copy(object_eval, ob); + BKE_object_where_is_calc(depsgraph, scene_eval, object_eval); - invert_m4_m4(ob->imat, ob->obmat); + invert_m4_m4(object_eval->imat, object_eval->obmat); /* apparently this call goes from right to left... */ - mul_m4_series(hmd->parentinv, pose_mat, ob->imat, obedit->obmat); + mul_m4_series(hmd->parentinv, pose_mat, object_eval->imat, obedit->obmat); DEG_relations_tag_update(bmain); diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h index b9350052093..e697c25b37f 100644 --- a/source/blender/editors/object/object_intern.h +++ b/source/blender/editors/object/object_intern.h @@ -137,7 +137,10 @@ void COLLECTION_OT_objects_add_active(struct wmOperatorType *ot); void COLLECTION_OT_objects_remove_active(struct wmOperatorType *ot); /* object_modifier.c */ -bool edit_modifier_poll_generic(struct bContext *C, struct StructRNA *rna_type, int obtype_flag); +bool edit_modifier_poll_generic(struct bContext *C, + struct StructRNA *rna_type, + int obtype_flag, + const bool is_editmode_allowed); bool edit_modifier_poll(struct bContext *C); void edit_modifier_properties(struct wmOperatorType *ot); int edit_modifier_invoke_properties(struct bContext *C, struct wmOperator *op); diff --git a/source/blender/editors/object/object_modes.c b/source/blender/editors/object/object_modes.c index 0ec98e089a2..271d8effd30 100644 --- a/source/blender/editors/object/object_modes.c +++ b/source/blender/editors/object/object_modes.c @@ -171,14 +171,6 @@ void ED_object_mode_toggle(bContext *C, eObjectMode mode) if (opstring) { wmOperatorType *ot = WM_operatortype_find(opstring, false); - if (ot->flag & OPTYPE_USE_EVAL_DATA) { - /* We need to force refresh of depsgraph after undo step, - * redoing the operator *may* rely on some valid evaluated data. */ - struct Main *bmain = CTX_data_main(C); - Scene *scene = CTX_data_scene(C); - ViewLayer *view_layer = CTX_data_view_layer(C); - BKE_scene_view_layer_graph_evaluated_ensure(bmain, scene, view_layer); - } WM_operator_name_call_ptr(C, ot, WM_OP_EXEC_REGION_WIN, NULL); } } @@ -194,20 +186,6 @@ void ED_object_mode_set(bContext *C, eObjectMode mode) wm->op_undo_depth--; } -void ED_object_mode_exit(bContext *C) -{ - Depsgraph *depsgraph = CTX_data_depsgraph(C); - struct Main *bmain = CTX_data_main(C); - Scene *scene = CTX_data_scene(C); - ViewLayer *view_layer = CTX_data_view_layer(C); - FOREACH_OBJECT_BEGIN (view_layer, ob) { - if (ob->mode & OB_MODE_ALL_MODE_DATA) { - ED_object_mode_generic_exit(bmain, depsgraph, scene, ob); - } - } - FOREACH_OBJECT_END; -} - /** \} */ /* -------------------------------------------------------------------- */ diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c index 08012842c37..8818fd71190 100644 --- a/source/blender/editors/object/object_modifier.c +++ b/source/blender/editors/object/object_modifier.c @@ -99,7 +99,7 @@ static void object_force_modifier_update_for_bind(Depsgraph *depsgraph, Object * BKE_object_eval_reset(ob_eval); if (ob->type == OB_MESH) { Mesh *me_eval = mesh_create_eval_final_view(depsgraph, scene_eval, ob_eval, &CD_MASK_BAREMESH); - BKE_id_free(NULL, me_eval); + BKE_mesh_eval_delete(me_eval); } else if (ob->type == OB_LATTICE) { BKE_lattice_modifiers_calc(depsgraph, scene_eval, ob_eval); @@ -912,7 +912,10 @@ void OBJECT_OT_modifier_add(wmOperatorType *ot) /********** generic functions for operators using mod names and data context *********************/ -bool edit_modifier_poll_generic(bContext *C, StructRNA *rna_type, int obtype_flag) +bool edit_modifier_poll_generic(bContext *C, + StructRNA *rna_type, + int obtype_flag, + const bool is_editmode_allowed) { PointerRNA ptr = CTX_data_pointer_get_type(C, "modifier", rna_type); Object *ob = (ptr.id.data) ? ptr.id.data : ED_object_active_context(C); @@ -932,12 +935,17 @@ bool edit_modifier_poll_generic(bContext *C, StructRNA *rna_type, int obtype_fla return (((ModifierData *)ptr.data)->flag & eModifierFlag_OverrideLibrary_Local) != 0; } + if (!is_editmode_allowed && CTX_data_edit_object(C) != NULL) { + CTX_wm_operator_poll_msg_set(C, "This modifier operation is not allowed from Edit mode"); + return 0; + } + return 1; } bool edit_modifier_poll(bContext *C) { - return edit_modifier_poll_generic(C, &RNA_Modifier, 0); + return edit_modifier_poll_generic(C, &RNA_Modifier, 0, true); } void edit_modifier_properties(wmOperatorType *ot) @@ -1122,7 +1130,7 @@ void OBJECT_OT_modifier_move_down(wmOperatorType *ot) static int modifier_apply_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene = CTX_data_scene(C); Object *ob = ED_object_active_context(C); ModifierData *md = edit_modifier_property_get(op, ob, 0); @@ -1186,7 +1194,7 @@ void OBJECT_OT_modifier_apply(wmOperatorType *ot) static int modifier_convert_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); Object *ob = ED_object_active_context(C); @@ -1274,7 +1282,7 @@ void OBJECT_OT_modifier_copy(wmOperatorType *ot) static bool multires_poll(bContext *C) { - return edit_modifier_poll_generic(C, &RNA_MultiresModifier, (1 << OB_MESH)); + return edit_modifier_poll_generic(C, &RNA_MultiresModifier, (1 << OB_MESH), true); } static int multires_higher_levels_delete_exec(bContext *C, wmOperator *op) @@ -1383,7 +1391,7 @@ void OBJECT_OT_multires_subdivide(wmOperatorType *ot) static int multires_reshape_exec(bContext *C, wmOperator *op) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Object *ob = ED_object_active_context(C), *secondob = NULL; MultiresModifierData *mmd = (MultiresModifierData *)edit_modifier_property_get( op, ob, eModifierType_Multires); @@ -1627,14 +1635,13 @@ static void modifier_skin_customdata_delete(Object *ob) static bool skin_poll(bContext *C) { - return (!CTX_data_edit_object(C) && - edit_modifier_poll_generic(C, &RNA_SkinModifier, (1 << OB_MESH))); + return (edit_modifier_poll_generic(C, &RNA_SkinModifier, (1 << OB_MESH), false)); } static bool skin_edit_poll(bContext *C) { return (CTX_data_edit_object(C) && - edit_modifier_poll_generic(C, &RNA_SkinModifier, (1 << OB_MESH))); + edit_modifier_poll_generic(C, &RNA_SkinModifier, (1 << OB_MESH), true)); } static void skin_root_clear(BMVert *bm_vert, GSet *visited, const int cd_vert_skin_offset) @@ -1927,7 +1934,7 @@ static Object *modifier_skin_armature_create(Depsgraph *depsgraph, static int skin_armature_create_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C), *arm_ob; Mesh *me = ob->data; @@ -1987,12 +1994,12 @@ void OBJECT_OT_skin_armature_create(wmOperatorType *ot) static bool correctivesmooth_poll(bContext *C) { - return edit_modifier_poll_generic(C, &RNA_CorrectiveSmoothModifier, 0); + return edit_modifier_poll_generic(C, &RNA_CorrectiveSmoothModifier, 0, true); } static int correctivesmooth_bind_exec(bContext *C, wmOperator *op) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene = CTX_data_scene(C); Object *ob = ED_object_active_context(C); CorrectiveSmoothModifierData *csmd = (CorrectiveSmoothModifierData *)edit_modifier_property_get( @@ -2065,12 +2072,12 @@ void OBJECT_OT_correctivesmooth_bind(wmOperatorType *ot) static bool meshdeform_poll(bContext *C) { - return edit_modifier_poll_generic(C, &RNA_MeshDeformModifier, 0); + return edit_modifier_poll_generic(C, &RNA_MeshDeformModifier, 0, true); } static int meshdeform_bind_exec(bContext *C, wmOperator *op) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Object *ob = ED_object_active_context(C); MeshDeformModifierData *mmd = (MeshDeformModifierData *)edit_modifier_property_get( op, ob, eModifierType_MeshDeform); @@ -2138,7 +2145,7 @@ void OBJECT_OT_meshdeform_bind(wmOperatorType *ot) static bool explode_poll(bContext *C) { - return edit_modifier_poll_generic(C, &RNA_ExplodeModifier, 0); + return edit_modifier_poll_generic(C, &RNA_ExplodeModifier, 0, true); } static int explode_refresh_exec(bContext *C, wmOperator *op) @@ -2188,7 +2195,7 @@ void OBJECT_OT_explode_refresh(wmOperatorType *ot) static bool ocean_bake_poll(bContext *C) { - return edit_modifier_poll_generic(C, &RNA_OceanModifier, 0); + return edit_modifier_poll_generic(C, &RNA_OceanModifier, 0, true); } typedef struct OceanBakeJob { @@ -2309,8 +2316,9 @@ static int ocean_bake_exec(bContext *C, wmOperator *op) for (f = omd->bakestart; f <= omd->bakeend; f++) { /* For now only simple animation of time value is supported, nothing else. * No drivers or other modifier parameters. */ - BKE_animsys_evaluate_animdata( - CTX_data_depsgraph(C), scene, (ID *)ob, ob->adt, f, ADT_RECALC_ANIM); + /* TODO(sergey): This operates on an original data, so no flush is needed. However, baking + * usually should happen on an evaluated objects, so this seems to be deeper issue here. */ + BKE_animsys_evaluate_animdata(scene, (ID *)ob, ob->adt, f, ADT_RECALC_ANIM, false); och->time[i] = omd->time; i++; @@ -2389,13 +2397,13 @@ void OBJECT_OT_ocean_bake(wmOperatorType *ot) static bool laplaciandeform_poll(bContext *C) { - return edit_modifier_poll_generic(C, &RNA_LaplacianDeformModifier, 0); + return edit_modifier_poll_generic(C, &RNA_LaplacianDeformModifier, 0, false); } static int laplaciandeform_bind_exec(bContext *C, wmOperator *op) { Object *ob = ED_object_active_context(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); LaplacianDeformModifierData *lmd = (LaplacianDeformModifierData *)edit_modifier_property_get( op, ob, eModifierType_LaplacianDeform); @@ -2464,13 +2472,13 @@ void OBJECT_OT_laplaciandeform_bind(wmOperatorType *ot) static bool surfacedeform_bind_poll(bContext *C) { - return edit_modifier_poll_generic(C, &RNA_SurfaceDeformModifier, 0); + return edit_modifier_poll_generic(C, &RNA_SurfaceDeformModifier, 0, true); } static int surfacedeform_bind_exec(bContext *C, wmOperator *op) { Object *ob = ED_object_active_context(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); SurfaceDeformModifierData *smd = (SurfaceDeformModifierData *)edit_modifier_property_get( op, ob, eModifierType_SurfaceDeform); diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c index e6637265fbc..a69f4872e72 100644 --- a/source/blender/editors/object/object_relations.c +++ b/source/blender/editors/object/object_relations.c @@ -124,7 +124,7 @@ static int vertex_parent_set_exec(bContext *C, wmOperator *op) Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); View3D *v3d = CTX_wm_view3d(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); ViewLayer *view_layer = CTX_data_view_layer(C); Object *obedit = CTX_data_edit_object(C); BMVert *eve; @@ -677,7 +677,7 @@ bool ED_object_parent_set(ReportList *reports, const int vert_par[3]) { Main *bmain = CTX_data_main(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); bPoseChannel *pchan = NULL; bPoseChannel *pchan_eval = NULL; const bool pararm = ELEM( @@ -1582,6 +1582,7 @@ static int make_links_data_exec(bContext *C, wmOperator *op) id_us_plus(&ob_dst->instance_collection->id); ob_dst->transflag |= OB_DUPLICOLLECTION; } + DEG_id_tag_update(&ob_dst->id, ID_RECALC_COPY_ON_WRITE); break; case MAKE_LINKS_MODIFIERS: BKE_object_link_modifiers(scene, ob_dst, ob_src); @@ -1726,7 +1727,7 @@ static Collection *single_object_users_collection(Main *bmain, const bool is_master_collection) { /* Generate new copies for objects in given collection and all its children, - * and optionnaly also copy collections themselves. */ + * and optionally also copy collections themselves. */ if (copy_collections && !is_master_collection) { collection = ID_NEW_SET(collection, BKE_collection_copy(bmain, NULL, collection)); } diff --git a/source/blender/editors/object/object_transform.c b/source/blender/editors/object/object_transform.c index 9c98fdc2a2e..5934eab62bb 100644 --- a/source/blender/editors/object/object_transform.c +++ b/source/blender/editors/object/object_transform.c @@ -547,7 +547,7 @@ static int apply_objects_internal(bContext *C, { Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); - Depsgraph *depsgraph = CTX_data_evaluated_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); float rsmat[3][3], obmat[3][3], iobmat[3][3], mat[4][4], scale; bool changed = true; @@ -856,6 +856,7 @@ static int apply_objects_internal(bContext *C, BKE_object_where_is_calc(depsgraph, scene, ob_eval); if (ob->type == OB_ARMATURE) { /* needed for bone parents */ + BKE_armature_copy_bone_transforms(ob_eval->data, ob->data); BKE_pose_where_is(depsgraph, scene, ob_eval); } @@ -880,7 +881,7 @@ static int apply_objects_internal(bContext *C, static int visual_transform_apply_exec(bContext *C, wmOperator *UNUSED(op)) { Scene *scene = CTX_data_scene(C); - Depsgraph *depsgraph = CTX_data_evaluated_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); bool changed = false; CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects) { @@ -975,7 +976,7 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) Scene *scene = CTX_data_scene(C); Object *obact = CTX_data_active_object(C); Object *obedit = CTX_data_edit_object(C); - Depsgraph *depsgraph = CTX_data_evaluated_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Object *tob; float cent[3], cent_neg[3], centn[3]; const float *cursor = scene->cursor.location; @@ -1229,6 +1230,7 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); BKE_object_transform_copy(ob_eval, ob); + BKE_armature_copy_bone_transforms(ob_eval->data, ob->data); BKE_object_where_is_calc(depsgraph, scene, ob_eval); BKE_pose_where_is(depsgraph, scene, ob_eval); /* needed for bone parents */ @@ -1370,6 +1372,7 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) BKE_object_where_is_calc(depsgraph, scene, ob_eval); if (ob->type == OB_ARMATURE) { /* needed for bone parents */ + BKE_armature_copy_bone_transforms(ob_eval->data, ob->data); BKE_pose_where_is(depsgraph, scene, ob_eval); } @@ -1398,6 +1401,7 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) BKE_object_where_is_calc(depsgraph, scene, ob_other_eval); if (ob_other->type == OB_ARMATURE) { /* needed for bone parents */ + BKE_armature_copy_bone_transforms(ob_eval->data, ob->data); BKE_pose_where_is(depsgraph, scene, ob_other_eval); } ignore_parent_tx(bmain, depsgraph, scene, ob_other); diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 4f61443ac54..a43ac59c9b8 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -1514,7 +1514,7 @@ static void moveCloserToDistanceFromPlane(Depsgraph *depsgraph, static void vgroup_fix( const bContext *C, Scene *UNUSED(scene), Object *ob, float distToBe, float strength, float cp) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); Object *object_eval = DEG_get_evaluated_object(depsgraph, ob); int i; diff --git a/source/blender/editors/physics/dynamicpaint_ops.c b/source/blender/editors/physics/dynamicpaint_ops.c index 40b7a245f69..c06c21b9057 100644 --- a/source/blender/editors/physics/dynamicpaint_ops.c +++ b/source/blender/editors/physics/dynamicpaint_ops.c @@ -473,7 +473,7 @@ static void dpaint_bake_startjob(void *customdata, short *stop, short *do_update */ static int dynamicpaint_bake_exec(struct bContext *C, struct wmOperator *op) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Object *ob_ = ED_object_context(C); Object *object_eval = DEG_get_evaluated_object(depsgraph, ob_); Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); @@ -505,7 +505,7 @@ static int dynamicpaint_bake_exec(struct bContext *C, struct wmOperator *op) DynamicPaintBakeJob *job = MEM_mallocN(sizeof(DynamicPaintBakeJob), "DynamicPaintBakeJob"); job->bmain = CTX_data_main(C); job->scene = scene_eval; - job->depsgraph = CTX_data_depsgraph(C); + job->depsgraph = depsgraph; job->ob = object_eval; job->canvas = canvas; job->surface = surface; diff --git a/source/blender/editors/physics/particle_edit.c b/source/blender/editors/physics/particle_edit.c index 4e6022cf18c..e6870cda19d 100644 --- a/source/blender/editors/physics/particle_edit.c +++ b/source/blender/editors/physics/particle_edit.c @@ -252,7 +252,7 @@ static void pe_update_hair_particle_edit_pointers(PTCacheEdit *edit) /* always gets at least the first particlesystem even if PSYS_CURRENT flag is not set * - * note: this function runs on poll, therefor it can runs many times a second + * note: this function runs on poll, therefore it can runs many times a second * keep it fast! */ static PTCacheEdit *pe_get_current(Depsgraph *depsgraph, Scene *scene, Object *ob, int create) { @@ -465,7 +465,7 @@ static void PE_set_data(bContext *C, PEData *data) data->scene = CTX_data_scene(C); data->view_layer = CTX_data_view_layer(C); data->ob = CTX_data_active_object(C); - data->depsgraph = CTX_data_depsgraph(C); + data->depsgraph = CTX_data_ensure_evaluated_depsgraph(C); data->edit = PE_get_current(data->scene, data->ob); } @@ -785,7 +785,7 @@ typedef struct KeyIterData { static void foreach_mouse_hit_key_iter(void *__restrict iter_data_v, const int iter, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { KeyIterData *iter_data = (KeyIterData *)iter_data_v; PEData *data = iter_data->data; @@ -855,7 +855,7 @@ static void foreach_mouse_hit_key(PEData *data, ForHitKeyMatFunc func, int selec iter_data.selected = selected; iter_data.func = func; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.scheduling_mode = TASK_SCHEDULING_DYNAMIC; BLI_task_parallel_range(0, edit->totpoint, &iter_data, foreach_mouse_hit_key_iter, &settings); @@ -1152,7 +1152,7 @@ typedef struct DeflectEmitterIter { static void deflect_emitter_iter(void *__restrict iter_data_v, const int iter, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { DeflectEmitterIter *iter_data = (DeflectEmitterIter *)iter_data_v; PTCacheEdit *edit = iter_data->edit; @@ -1246,7 +1246,7 @@ static void pe_deflect_emitter(Scene *scene, Object *ob, PTCacheEdit *edit) iter_data.dist = dist; iter_data.emitterdist = pset->emitterdist; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.scheduling_mode = TASK_SCHEDULING_DYNAMIC; BLI_task_parallel_range(0, edit->totpoint, &iter_data, deflect_emitter_iter, &settings); @@ -1258,7 +1258,7 @@ typedef struct ApplyLengthsIterData { static void apply_lengths_iter(void *__restrict iter_data_v, const int iter, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { ApplyLengthsIterData *iter_data = (ApplyLengthsIterData *)iter_data_v; PTCacheEdit *edit = iter_data->edit; @@ -1296,7 +1296,7 @@ static void PE_apply_lengths(Scene *scene, PTCacheEdit *edit) ApplyLengthsIterData iter_data; iter_data.edit = edit; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.scheduling_mode = TASK_SCHEDULING_DYNAMIC; BLI_task_parallel_range(0, edit->totpoint, &iter_data, apply_lengths_iter, &settings); @@ -1309,7 +1309,7 @@ typedef struct IterateLengthsIterData { static void iterate_lengths_iter(void *__restrict iter_data_v, const int iter, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { IterateLengthsIterData *iter_data = (IterateLengthsIterData *)iter_data_v; PTCacheEdit *edit = iter_data->edit; @@ -1371,7 +1371,7 @@ static void pe_iterate_lengths(Scene *scene, PTCacheEdit *edit) iter_data.edit = edit; iter_data.pset = pset; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.scheduling_mode = TASK_SCHEDULING_DYNAMIC; BLI_task_parallel_range(0, edit->totpoint, &iter_data, iterate_lengths_iter, &settings); @@ -1499,7 +1499,7 @@ static void PE_update_selection(Depsgraph *depsgraph, Scene *scene, Object *ob, DEG_id_tag_update(&ob->id, ID_RECALC_SELECT); } -void update_world_cos(Depsgraph *UNUSED(depsgraph), Object *ob, PTCacheEdit *edit) +void update_world_cos(Object *ob, PTCacheEdit *edit) { ParticleSystem *psys = edit->psys; ParticleSystemModifierData *psmd_eval = edit->psmd_eval; @@ -1619,7 +1619,7 @@ void PE_update_object(Depsgraph *depsgraph, Scene *scene, Object *ob, int usefla PE_apply_mirror(ob, edit->psys); } if (edit->psys) { - update_world_cos(depsgraph, ob, edit); + update_world_cos(ob, edit); } if (pset->flag & PE_AUTO_VELOCITY) { update_velocities(edit); @@ -1778,7 +1778,7 @@ static bool select_action_apply(PTCacheEditPoint *point, PTCacheEditKey *key, in static int pe_select_all_exec(bContext *C, wmOperator *op) { Scene *scene = CTX_data_scene(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Object *ob = CTX_data_active_object(C); PTCacheEdit *edit = PE_get_current(scene, ob); POINT_P; @@ -2348,7 +2348,7 @@ static int hide_exec(bContext *C, wmOperator *op) { Object *ob = CTX_data_active_object(C); Scene *scene = CTX_data_scene(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); PTCacheEdit *edit = PE_get_current(scene, ob); POINT_P; @@ -2409,7 +2409,7 @@ static int reveal_exec(bContext *C, wmOperator *op) { Object *ob = CTX_data_active_object(C); Scene *scene = CTX_data_scene(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); PTCacheEdit *edit = PE_get_current(scene, ob); const bool select = RNA_boolean_get(op->ptr, "select"); POINT_P; @@ -2709,7 +2709,7 @@ static void rekey_particle_to_time( psys = edit->psys; - sim.depsgraph = CTX_data_depsgraph(C); + sim.depsgraph = CTX_data_depsgraph_pointer(C); sim.scene = scene; sim.ob = ob; sim.psys = psys; @@ -3519,7 +3519,7 @@ static int mirror_exec(bContext *C, wmOperator *UNUSED(op)) PE_mirror_x(scene, ob, 0); - update_world_cos(CTX_data_depsgraph(C), ob, edit); + update_world_cos(ob, edit); WM_event_add_notifier(C, NC_OBJECT | ND_PARTICLE | NA_EDITED, ob); DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); @@ -4116,7 +4116,7 @@ typedef struct BrushAddCountIterTLSData { static void brush_add_count_iter(void *__restrict iter_data_v, const int iter, - const ParallelRangeTLS *__restrict tls_v) + const TaskParallelTLS *__restrict tls_v) { BrushAddCountIterData *iter_data = (BrushAddCountIterData *)iter_data_v; Depsgraph *depsgraph = iter_data->depsgraph; @@ -4211,7 +4211,7 @@ static void brush_add_count_iter_finalize(void *__restrict userdata_v, static int brush_add(const bContext *C, PEData *data, short number) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); Scene *scene = data->scene; Object *ob = data->ob; Mesh *mesh; @@ -4272,7 +4272,7 @@ static int brush_add(const bContext *C, PEData *data, short number) BrushAddCountIterTLSData tls = {NULL}; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.scheduling_mode = TASK_SCHEDULING_DYNAMIC; settings.userdata_chunk = &tls; @@ -4542,7 +4542,7 @@ static int brush_edit_init(bContext *C, wmOperator *op) static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr) { BrushEdit *bedit = op->customdata; - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); Scene *scene = bedit->scene; Object *ob = bedit->ob; PTCacheEdit *edit = bedit->edit; @@ -4747,7 +4747,7 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr) PE_mirror_x(scene, ob, 1); } - update_world_cos(depsgraph, ob, edit); + update_world_cos(ob, edit); psys_free_path_cache(NULL, edit); DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); } @@ -4993,7 +4993,6 @@ static void shape_cut(PEData *data, int pa_index) static int shape_cut_exec(bContext *C, wmOperator *UNUSED(op)) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); ParticleEditSettings *pset = PE_settings(scene); @@ -5032,7 +5031,7 @@ static int shape_cut_exec(bContext *C, wmOperator *UNUSED(op)) recalc_lengths(edit); if (removed) { - update_world_cos(depsgraph, ob, edit); + update_world_cos(ob, edit); psys_free_path_cache(NULL, edit); DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); } @@ -5203,7 +5202,7 @@ void PE_create_particle_edit( } pa++; } - update_world_cos(depsgraph, ob, edit); + update_world_cos(ob, edit); } else { PTCacheMem *pm; @@ -5295,7 +5294,7 @@ static void free_all_psys_edit(Object *object) static int particle_edit_toggle_exec(bContext *C, wmOperator *op) { struct wmMsgBus *mbus = CTX_wm_message_bus(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); const int mode_flag = OB_MODE_PARTICLE_EDIT; @@ -5496,7 +5495,7 @@ static int unify_length_exec(bContext *C, wmOperator *UNUSED(op)) { Object *ob = CTX_data_active_object(C); Scene *scene = CTX_data_scene(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); PTCacheEdit *edit = PE_get_current(scene, ob); float average_length = calculate_average_length(edit); diff --git a/source/blender/editors/physics/particle_object.c b/source/blender/editors/physics/particle_object.c index b03ec56c7e4..0999d1f3588 100644 --- a/source/blender/editors/physics/particle_object.c +++ b/source/blender/editors/physics/particle_object.c @@ -652,7 +652,7 @@ static void disconnect_hair(Depsgraph *depsgraph, Scene *scene, Object *ob, Part static int disconnect_hair_exec(bContext *C, wmOperator *op) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene = CTX_data_scene(C); Object *ob = ED_object_context(C); ParticleSystem *psys = NULL; @@ -934,7 +934,7 @@ static bool connect_hair(Depsgraph *depsgraph, Scene *scene, Object *ob, Particl static int connect_hair_exec(bContext *C, wmOperator *op) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene = CTX_data_scene(C); Object *ob = ED_object_context(C); ParticleSystem *psys = NULL; @@ -1037,7 +1037,7 @@ static void copy_particle_edit(Depsgraph *depsgraph, pa++; } - update_world_cos(depsgraph, ob, edit); + update_world_cos(ob, edit); UI_GetThemeColor3ubv(TH_EDGE_SELECT, edit->sel_col); UI_GetThemeColor3ubv(TH_WIRE, edit->nosel_col); @@ -1086,11 +1086,10 @@ static bool copy_particle_systems_to_object(const bContext *C, bool duplicate_settings) { Main *bmain = CTX_data_main(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); ModifierData *md; ParticleSystem *psys_start = NULL, *psys, *psys_from; ParticleSystem **tmp_psys; - Mesh *final_mesh; CustomData_MeshMasks cdmask = {0}; int i, totpsys; @@ -1132,9 +1131,6 @@ static bool copy_particle_systems_to_object(const bContext *C, */ psys_start = totpsys > 0 ? tmp_psys[0] : NULL; - /* Get the evaluated mesh (psys and their modifiers have not been appended yet) */ - final_mesh = mesh_get_eval_final(depsgraph, scene, ob_to, &cdmask); - /* now append psys to the object and make modifiers */ for (i = 0, psys_from = PSYS_FROM_FIRST; i < totpsys; ++i, psys_from = PSYS_FROM_NEXT(psys_from)) { @@ -1155,10 +1151,6 @@ static bool copy_particle_systems_to_object(const bContext *C, modifier_unique_name(&ob_to->modifiers, (ModifierData *)psmd); psmd->psys = psys; - BKE_id_copy_ex(NULL, &final_mesh->id, (ID **)&psmd->mesh_final, LIB_ID_COPY_LOCALIZE); - - BKE_mesh_calc_normals(psmd->mesh_final); - BKE_mesh_tessface_ensure(psmd->mesh_final); if (psys_from->edit) { copy_particle_edit(depsgraph, scene, ob_to, psys, psys_from); diff --git a/source/blender/editors/physics/physics_fluid.c b/source/blender/editors/physics/physics_fluid.c index dc3673c972f..44858e36fab 100644 --- a/source/blender/editors/physics/physics_fluid.c +++ b/source/blender/editors/physics/physics_fluid.c @@ -334,6 +334,7 @@ static void free_all_fluidobject_channels(ListBase *fobjects) } static void fluid_init_all_channels(bContext *C, + Depsgraph *depsgraph, Object *UNUSED(fsDomain), FluidsimSettings *domainSettings, FluidAnimChannels *channels, @@ -341,7 +342,6 @@ static void fluid_init_all_channels(bContext *C, { Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); Base *base; int i; int length = channels->length; @@ -514,9 +514,11 @@ static void fluid_init_all_channels(bContext *C, } } -static void export_fluid_objects(const bContext *C, ListBase *fobjects, Scene *scene, int length) +static void export_fluid_objects(Depsgraph *depsgraph, + ListBase *fobjects, + Scene *scene, + int length) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); FluidObject *fobj; for (fobj = fobjects->first; fobj; fobj = fobj->next) { @@ -714,7 +716,7 @@ static bool fluid_init_filepaths(Main *bmain, /* .tmp: don't overwrite/delete original file */ BLI_join_dirfile(targetFile, FILE_MAX, targetDir, suffixConfigTmp); - /* Ensure whole path exists and is wirtable. */ + /* Ensure whole path exists and is writeable. */ const bool dir_exists = BLI_dir_create_recursive(targetDir); const bool is_writable = BLI_file_is_writable(targetFile); @@ -747,7 +749,7 @@ static bool fluid_init_filepaths(Main *bmain, /* .tmp: don't overwrite/delete original file */ BLI_join_dirfile(targetFile, FILE_MAX, targetDir, suffixConfigTmp); - /* Ensure whole path exists and is wirtable. */ + /* Ensure whole path exists and is writeable. */ if (!BLI_dir_create_recursive(targetDir) || !BLI_file_is_writable(targetFile)) { BKE_reportf(reports, RPT_ERROR, @@ -922,7 +924,7 @@ static int fluidsimBake(bContext *C, ReportList *reports, Object *fsDomain, shor Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); int i; FluidsimSettings *domainSettings; @@ -1051,11 +1053,11 @@ static int fluidsimBake(bContext *C, ReportList *reports, Object *fsDomain, shor (double)noFrames; /* ******** initialize and allocate animation channels ******** */ - fluid_init_all_channels(C, fsDomain, domainSettings, channels, fobjects); + fluid_init_all_channels(C, depsgraph, fsDomain, domainSettings, channels, fobjects); /* reset to original current frame */ scene->r.cfra = origFrame; - ED_update_for_newframe(CTX_data_main(C), depsgraph); + ED_update_for_newframe(CTX_data_main(C), CTX_data_depsgraph_pointer(C)); /* ******** init domain object's matrix ******** */ copy_m4_m4(domainMat, fsDomain->obmat); @@ -1153,7 +1155,7 @@ static int fluidsimBake(bContext *C, ReportList *reports, Object *fsDomain, shor elbeemAddDomain(fsset); /* ******** export all fluid objects to elbeem ******** */ - export_fluid_objects(C, fobjects, scene, channels->length); + export_fluid_objects(depsgraph, fobjects, scene, channels->length); /* custom data for fluid bake job */ fb->settings = fsset; diff --git a/source/blender/editors/physics/physics_intern.h b/source/blender/editors/physics/physics_intern.h index bb7cfe9b1a3..9ebbba07fdf 100644 --- a/source/blender/editors/physics/physics_intern.h +++ b/source/blender/editors/physics/physics_intern.h @@ -70,7 +70,7 @@ void recalc_lengths(struct PTCacheEdit *edit); void recalc_emitter_field(struct Depsgraph *depsgraph, struct Object *ob, struct ParticleSystem *psys); -void update_world_cos(struct Depsgraph *depsgraph, struct Object *ob, struct PTCacheEdit *edit); +void update_world_cos(struct Object *ob, struct PTCacheEdit *edit); /* particle_object.c */ void OBJECT_OT_particle_system_add(struct wmOperatorType *ot); diff --git a/source/blender/editors/physics/physics_pointcache.c b/source/blender/editors/physics/physics_pointcache.c index e9e89a31f94..bc2f1d6cef6 100644 --- a/source/blender/editors/physics/physics_pointcache.c +++ b/source/blender/editors/physics/physics_pointcache.c @@ -156,7 +156,8 @@ static PTCacheBaker *ptcache_baker_create(bContext *C, wmOperator *op, bool all) baker->bmain = CTX_data_main(C); baker->scene = CTX_data_scene(C); baker->view_layer = CTX_data_view_layer(C); - baker->depsgraph = CTX_data_depsgraph(C); + /* Depsgraph is used to sweep the frame range and evaluate scene at different times. */ + baker->depsgraph = CTX_data_depsgraph_pointer(C); baker->bake = RNA_boolean_get(op->ptr, "bake"); baker->render = 0; baker->anim_init = 0; diff --git a/source/blender/editors/physics/rigidbody_object.c b/source/blender/editors/physics/rigidbody_object.c index aa323dc53eb..70142b790c0 100644 --- a/source/blender/editors/physics/rigidbody_object.c +++ b/source/blender/editors/physics/rigidbody_object.c @@ -464,7 +464,7 @@ static const EnumPropertyItem *rigidbody_materials_itemf(bContext *UNUSED(C), static int rigidbody_objects_calc_mass_exec(bContext *C, wmOperator *op) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); int material = RNA_enum_get(op->ptr, "material"); float density; bool changed = false; @@ -537,7 +537,7 @@ void RIGIDBODY_OT_mass_calculate(wmOperatorType *ot) ot->poll = ED_operator_scene_editable; /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ ot->prop = prop = RNA_def_enum( diff --git a/source/blender/editors/render/render_intern.h b/source/blender/editors/render/render_intern.h index 1e03d986e3e..50f0b53c037 100644 --- a/source/blender/editors/render/render_intern.h +++ b/source/blender/editors/render/render_intern.h @@ -37,6 +37,7 @@ void OBJECT_OT_material_slot_select(struct wmOperatorType *ot); void OBJECT_OT_material_slot_deselect(struct wmOperatorType *ot); void OBJECT_OT_material_slot_copy(struct wmOperatorType *ot); void OBJECT_OT_material_slot_move(struct wmOperatorType *ot); +void OBJECT_OT_material_slot_remove_unused(struct wmOperatorType *ot); void MATERIAL_OT_new(struct wmOperatorType *ot); void TEXTURE_OT_new(struct wmOperatorType *ot); diff --git a/source/blender/editors/render/render_internal.c b/source/blender/editors/render/render_internal.c index 9ac93f07300..acd7126e56a 100644 --- a/source/blender/editors/render/render_internal.c +++ b/source/blender/editors/render/render_internal.c @@ -368,7 +368,7 @@ static int screen_render_exec(bContext *C, wmOperator *op) RE_SetReports(re, NULL); // no redraw needed, we leave state as we entered it - ED_update_for_newframe(mainp, CTX_data_depsgraph(C)); + ED_update_for_newframe(mainp, CTX_data_depsgraph_pointer(C)); WM_event_add_notifier(C, NC_SCENE | ND_RENDER_RESULT, scene); @@ -978,8 +978,11 @@ static int screen_render_invoke(bContext *C, wmOperator *op, const wmEvent *even rj->scene = scene; rj->current_scene = rj->scene; rj->single_layer = single_layer; - /* TODO(sergey): Render engine should be using own depsgraph. */ - rj->depsgraph = CTX_data_depsgraph(C); + /* TODO(sergey): Render engine should be using own depsgraph. + * + * NOTE: Currently is only used by ED_update_for_newframe() at the end of the render, so no + * need to ensure evaluation here. */ + rj->depsgraph = CTX_data_depsgraph_pointer(C); rj->camera_override = camera_override; rj->anim = is_animation; rj->write_still = is_write_still && !is_animation; diff --git a/source/blender/editors/render/render_opengl.c b/source/blender/editors/render/render_opengl.c index 72e6c6fdf03..f419d30a17e 100644 --- a/source/blender/editors/render/render_opengl.c +++ b/source/blender/editors/render/render_opengl.c @@ -273,7 +273,7 @@ static void screen_opengl_views_setup(OGLRender *oglrender) static void screen_opengl_render_doit(const bContext *C, OGLRender *oglrender, RenderResult *rr) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene = oglrender->scene; ARegion *ar = oglrender->ar; View3D *v3d = oglrender->v3d; @@ -592,7 +592,9 @@ static bool screen_opengl_render_init(bContext *C, wmOperator *op) oglrender->scene = scene; oglrender->workspace = workspace; oglrender->view_layer = CTX_data_view_layer(C); - oglrender->depsgraph = CTX_data_depsgraph(C); + /* NOTE: The depsgraph is not only used to update scene for a new frames, but also to initialize + * output video handles, which does need evaluated scene. */ + oglrender->depsgraph = CTX_data_ensure_evaluated_depsgraph(C); oglrender->cfrao = scene->r.cfra; oglrender->ofs_samples = samples; diff --git a/source/blender/editors/render/render_ops.c b/source/blender/editors/render/render_ops.c index b77f5c2bbad..8156f48343f 100644 --- a/source/blender/editors/render/render_ops.c +++ b/source/blender/editors/render/render_ops.c @@ -42,6 +42,7 @@ void ED_operatortypes_render(void) WM_operatortype_append(OBJECT_OT_material_slot_deselect); WM_operatortype_append(OBJECT_OT_material_slot_copy); WM_operatortype_append(OBJECT_OT_material_slot_move); + WM_operatortype_append(OBJECT_OT_material_slot_remove_unused); WM_operatortype_append(MATERIAL_OT_new); WM_operatortype_append(TEXTURE_OT_new); diff --git a/source/blender/editors/render/render_preview.c b/source/blender/editors/render/render_preview.c index fbabdc2f3c1..9b380ad5db1 100644 --- a/source/blender/editors/render/render_preview.c +++ b/source/blender/editors/render/render_preview.c @@ -153,7 +153,6 @@ typedef struct ShaderPreview { short *stop, *do_update; Scene *scene; - Depsgraph *depsgraph; ID *id, *id_copy; ID *parent; MTex *slot; @@ -185,7 +184,6 @@ typedef struct IconPreviewSize { typedef struct IconPreview { Main *bmain; Scene *scene; - Depsgraph *depsgraph; void *owner; ID *id, *id_copy; ListBase sizes; @@ -292,7 +290,7 @@ static void set_preview_visibility(Scene *scene, char pr_type, int pr_method) { - /* Set appropriate layer as visibile. */ + /* Set appropriate layer as visible. */ LayerCollection *lc = view_layer->layer_collections.first; const char *collection_name = preview_collection_name(pr_type); @@ -1229,7 +1227,6 @@ static void icon_preview_startjob_all_sizes(void *customdata, /* construct shader preview from image size and previewcustomdata */ sp->scene = ip->scene; - sp->depsgraph = ip->depsgraph; sp->owner = ip->owner; sp->sizex = cur_size->sizex; sp->sizey = cur_size->sizey; @@ -1372,7 +1369,6 @@ void ED_preview_icon_job(const bContext *C, /* customdata for preview thread */ ip->bmain = CTX_data_main(C); ip->scene = CTX_data_scene(C); - ip->depsgraph = CTX_data_depsgraph(C); ip->owner = owner; ip->id = id; ip->id_copy = duplicate_ids(id); @@ -1439,7 +1435,6 @@ void ED_preview_shader_job(const bContext *C, /* customdata for preview thread */ sp->scene = scene; - sp->depsgraph = CTX_data_depsgraph(C); sp->owner = owner; sp->sizex = sizex; sp->sizey = sizey; diff --git a/source/blender/editors/render/render_shading.c b/source/blender/editors/render/render_shading.c index f7a1d7187f1..01740c13c9d 100644 --- a/source/blender/editors/render/render_shading.c +++ b/source/blender/editors/render/render_shading.c @@ -310,7 +310,7 @@ static int material_slot_de_select(bContext *C, bool select) } else { /* Find the first matching material. - * Note: there may be multiple but thats not a common use case. */ + * Note: there may be multiple but that's not a common use case. */ for (short i = 0; i < ob->totcol; i++) { const Material *mat = give_current_material(ob, i + 1); if (mat_active == mat) { @@ -549,6 +549,73 @@ void OBJECT_OT_material_slot_move(wmOperatorType *ot) "Direction to move the active material towards"); } +static int material_slot_remove_unused_exec(bContext *C, wmOperator *op) +{ + Object *ob = CTX_data_active_object(C); + + if (!ob) { + return OPERATOR_CANCELLED; + } + + /* Removing material slots in edit mode screws things up, see bug #21822.*/ + if (ob == CTX_data_edit_object(C)) { + BKE_report(op->reports, RPT_ERROR, "Unable to remove material slot in edit mode"); + return OPERATOR_CANCELLED; + } + + int actcol = ob->actcol; + + int removed = 0; + for (int slot = 1; slot <= ob->totcol; slot++) { + while (slot <= ob->totcol && !BKE_object_material_slot_used(ob->data, slot)) { + ob->actcol = slot; + BKE_object_material_slot_remove(CTX_data_main(C), ob); + + if (actcol >= slot) { + actcol--; + } + + removed++; + } + } + + ob->actcol = actcol; + + if (!removed) { + return OPERATOR_CANCELLED; + } + + BKE_reportf(op->reports, RPT_INFO, "Removed %d slots", removed); + + if (ob->mode & OB_MODE_TEXTURE_PAINT) { + Scene *scene = CTX_data_scene(C); + BKE_paint_proj_mesh_data_check(scene, ob, NULL, NULL, NULL, NULL); + WM_event_add_notifier(C, NC_SCENE | ND_TOOLSETTINGS, NULL); + } + + DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); + WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob); + WM_event_add_notifier(C, NC_OBJECT | ND_OB_SHADING, ob); + WM_event_add_notifier(C, NC_MATERIAL | ND_SHADING_PREVIEW, ob); + + return OPERATOR_FINISHED; +} + +void OBJECT_OT_material_slot_remove_unused(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Remove Unused Slots"; + ot->idname = "OBJECT_OT_material_slot_remove_unused"; + ot->description = "Remove unused material slots"; + + /* api callbacks */ + ot->exec = material_slot_remove_unused_exec; + ot->poll = ED_operator_object_active_editable; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; +} + /********************** new material operator *********************/ static int new_material_exec(bContext *C, wmOperator *UNUSED(op)) @@ -859,7 +926,7 @@ static int light_cache_bake_exec(bContext *C, wmOperator *op) EEVEE_lightbake_job_data_free(rj); // no redraw needed, we leave state as we entered it - ED_update_for_newframe(bmain, CTX_data_depsgraph(C)); + ED_update_for_newframe(bmain, CTX_data_depsgraph_pointer(C)); WM_event_add_notifier(C, NC_SCENE | NA_EDITED, scene); diff --git a/source/blender/editors/render/render_update.c b/source/blender/editors/render/render_update.c index 64869b71746..82e4d577777 100644 --- a/source/blender/editors/render/render_update.c +++ b/source/blender/editors/render/render_update.c @@ -135,7 +135,7 @@ void ED_render_scene_update(const DEGEditorUpdateContext *update_ctx, int update /* NOTE: Important to pass non-updated depsgraph, This is because this function is called * from inside dependency graph evaluation. Additionally, if we pass fully evaluated one * we will loose updates stored in the graph. */ - engine->type->view_update(engine, C, CTX_data_depsgraph(C)); + engine->type->view_update(engine, C, CTX_data_depsgraph_pointer(C)); } else { RenderEngineType *engine_type = ED_view3d_engine_type(scene, v3d->shading.type); diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c index e5bbeafd89d..5099c370a85 100644 --- a/source/blender/editors/screen/area.c +++ b/source/blender/editors/screen/area.c @@ -2696,7 +2696,7 @@ void ED_region_header_init(ARegion *ar) int ED_area_headersize(void) { - /* Accomodate widget and padding. */ + /* Accommodate widget and padding. */ return U.widget_unit + (int)(UI_DPI_FAC * HEADER_PADDING_Y); } diff --git a/source/blender/editors/screen/screen_edit.c b/source/blender/editors/screen/screen_edit.c index e59477fbe6e..dddc33e3ad0 100644 --- a/source/blender/editors/screen/screen_edit.c +++ b/source/blender/editors/screen/screen_edit.c @@ -1457,6 +1457,8 @@ void ED_update_for_newframe(Main *bmain, Depsgraph *depsgraph) { Scene *scene = DEG_get_input_scene(depsgraph); + DEG_id_tag_update_ex(bmain, &scene->id, ID_RECALC_TIME); + #ifdef DURIAN_CAMERA_SWITCH void *camera = BKE_scene_camera_switch_find(scene); if (camera && scene->camera != camera) { diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index c9a45728bc2..eccd85ab276 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -1059,7 +1059,7 @@ static int actionzone_modal(bContext *C, wmOperator *op, const wmEvent *event) is_gesture = (delta_max > split_threshold); } else { - /* Different area, so posible join. */ + /* Different area, so possible join. */ if (sad->gesture_dir == 'n') { WM_cursor_set(win, BC_N_ARROWCURSOR); } @@ -4465,7 +4465,7 @@ int ED_screen_animation_play(bContext *C, int sync, int mode) { bScreen *screen = CTX_wm_screen(C); Scene *scene = CTX_data_scene(C); - Scene *scene_eval = DEG_get_evaluated_scene(CTX_data_depsgraph(C)); + Scene *scene_eval = DEG_get_evaluated_scene(CTX_data_ensure_evaluated_depsgraph(C)); if (ED_screen_animation_playing(CTX_wm_manager(C))) { /* stop playback now */ diff --git a/source/blender/editors/sculpt_paint/CMakeLists.txt b/source/blender/editors/sculpt_paint/CMakeLists.txt index 23617e687ea..2a8ff9d4f78 100644 --- a/source/blender/editors/sculpt_paint/CMakeLists.txt +++ b/source/blender/editors/sculpt_paint/CMakeLists.txt @@ -29,6 +29,7 @@ set(INC ../../makesrna ../../render/extern/include ../../windowmanager + ../../../../intern/atomic ../../../../intern/glew-mx ../../../../intern/guardedalloc ) diff --git a/source/blender/editors/sculpt_paint/paint_cursor.c b/source/blender/editors/sculpt_paint/paint_cursor.c index ac74afce79e..576baf5794b 100644 --- a/source/blender/editors/sculpt_paint/paint_cursor.c +++ b/source/blender/editors/sculpt_paint/paint_cursor.c @@ -148,7 +148,7 @@ typedef struct LoadTexData { static void load_tex_task_cb_ex(void *__restrict userdata, const int j, - const ParallelRangeTLS *__restrict tls) + const TaskParallelTLS *__restrict tls) { LoadTexData *data = userdata; Brush *br = data->br; @@ -328,7 +328,7 @@ static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col, bool prima .radius = radius, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); BLI_task_parallel_range(0, size, &data, load_tex_task_cb_ex, &settings); @@ -385,7 +385,7 @@ static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col, bool prima static void load_tex_cursor_task_cb(void *__restrict userdata, const int j, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { LoadTexData *data = userdata; Brush *br = data->br; @@ -468,7 +468,7 @@ static int load_tex_cursor(Brush *br, ViewContext *vc, float zoom) .size = size, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); BLI_task_parallel_range(0, size, &data, load_tex_cursor_task_cb, &settings); diff --git a/source/blender/editors/sculpt_paint/paint_hide.c b/source/blender/editors/sculpt_paint/paint_hide.c index d7e1b47d973..5852012891d 100644 --- a/source/blender/editors/sculpt_paint/paint_hide.c +++ b/source/blender/editors/sculpt_paint/paint_hide.c @@ -339,7 +339,7 @@ static int hide_show_exec(bContext *C, wmOperator *op) { ARegion *ar = CTX_wm_region(C); Object *ob = CTX_data_active_object(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Mesh *me = ob->data; PartialVisAction action; PartialVisArea area; diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index 41dfd6f68c3..f3a6cfa0d5c 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -1238,7 +1238,7 @@ void PAINT_OT_texture_paint_toggle(wmOperatorType *ot) ot->poll = texture_paint_toggle_poll; /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } static int brush_colors_flip_exec(bContext *C, wmOperator *UNUSED(op)) @@ -1246,8 +1246,7 @@ static int brush_colors_flip_exec(bContext *C, wmOperator *UNUSED(op)) Scene *scene = CTX_data_scene(C); UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings; - ViewLayer *view_layer = CTX_data_view_layer(C); - Paint *paint = BKE_paint_get_active(scene, view_layer); + Paint *paint = BKE_paint_get_active_from_context(C); Brush *br = BKE_paint_brush(paint); if (ups->flag & UNIFIED_PAINT_COLOR) { @@ -1256,6 +1255,10 @@ static int brush_colors_flip_exec(bContext *C, wmOperator *UNUSED(op)) else if (br) { swap_v3_v3(br->rgb, br->secondary_rgb); } + else { + return OPERATOR_CANCELLED; + } + WM_event_add_notifier(C, NC_BRUSH | NA_EDITED, br); return OPERATOR_FINISHED; diff --git a/source/blender/editors/sculpt_paint/paint_image_2d.c b/source/blender/editors/sculpt_paint/paint_image_2d.c index 474d3a8ceba..8f1156295a3 100644 --- a/source/blender/editors/sculpt_paint/paint_image_2d.c +++ b/source/blender/editors/sculpt_paint/paint_image_2d.c @@ -1251,7 +1251,7 @@ typedef struct Paint2DForeachData { static void paint_2d_op_foreach_do(void *__restrict data_v, const int iter, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { Paint2DForeachData *data = (Paint2DForeachData *)data_v; paint_2d_do_making_brush(data->s, @@ -1360,7 +1360,7 @@ static int paint_2d_op(void *state, data.tilex = tilex; data.tilew = tilew; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); BLI_task_parallel_range(tiley, tileh + 1, &data, paint_2d_op_foreach_do, &settings); } diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c index 22de22e8e59..e5527e7210d 100644 --- a/source/blender/editors/sculpt_paint/paint_image_proj.c +++ b/source/blender/editors/sculpt_paint/paint_image_proj.c @@ -44,6 +44,8 @@ #include "BLI_threads.h" #include "BLI_utildefines.h" +#include "atomic_ops.h" + #include "BLT_translation.h" #include "IMB_imbuf.h" @@ -366,7 +368,7 @@ typedef struct ProjPaintState { int bucketMin[2]; int bucketMax[2]; /** must lock threads while accessing these. */ - int context_bucket_x, context_bucket_y; + int context_bucket_index; struct CurveMapping *cavity_curve; BlurKernel *blurkernel; @@ -1769,7 +1771,7 @@ static float project_paint_uvpixel_mask(const ProjPaintState *ps, } else if (angle_cos < ps->normal_angle_inner__cos) { mask *= (ps->normal_angle - acosf(angle_cos)) / ps->normal_angle_range; - } /* otherwise no mask normal is needed, were within the limit */ + } /* otherwise no mask normal is needed, we're within the limit */ } /* This only works when the opacity doesn't change while painting, stylus pressure messes with @@ -3157,7 +3159,7 @@ static void project_paint_face_init(const ProjPaintState *ps, //#endif } -#if 0 /* TODO - investigate why this dosnt work sometimes! it should! */ +#if 0 /* TODO - investigate why this doesn't work sometimes! it should! */ /* no intersection for this entire row, * after some intersection above means we can quit now */ if (has_x_isect == 0 && has_isect) { @@ -3213,7 +3215,7 @@ static void project_paint_face_init(const ProjPaintState *ps, * clipped by the bucket's screen aligned rectangle. */ float bucket_clip_edges[2][2]; float edge_verts_inset_clip[2][3]; - /* face edge pairs - loop throuh these: + /* face edge pairs - loop through these: * ((0,1), (1,2), (2,3), (3,0)) or ((0,1), (1,2), (2,0)) for a tri */ int fidx1, fidx2; @@ -3393,12 +3395,12 @@ static void project_paint_face_init(const ProjPaintState *ps, } else if (has_x_isect) { /* assuming the face is not a bow-tie - we know - * we cant intersect again on the X */ + * we can't intersect again on the X */ break; } } -# if 0 /* TODO - investigate why this dosnt work sometimes! it should! */ +# if 0 /* TODO - investigate why this doesn't work sometimes! it should! */ /* no intersection for this entire row, * after some intersection above means we can quit now */ if (has_x_isect == 0 && has_isect) { @@ -4010,7 +4012,7 @@ static void project_paint_bleed_add_face_user(const ProjPaintState *ps, /* Return true if evaluated mesh can be painted on, false otherwise */ static bool proj_paint_state_mesh_eval_init(const bContext *C, ProjPaintState *ps) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Object *ob = ps->ob; Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); @@ -4386,7 +4388,7 @@ static void project_paint_prepare_all_faces(ProjPaintState *ps, image_index = BLI_linklist_index(image_LinkList.list, tpage); if (image_index == -1 && BKE_image_has_ibuf(tpage, NULL)) { - /* MemArena dosnt have an append func */ + /* MemArena doesn't have an append func */ BLI_linklist_append(&image_LinkList, tpage); image_index = ps->image_tot; ps->image_tot++; @@ -4712,11 +4714,8 @@ static bool project_bucket_iter_init(ProjPaintState *ps, const float mval_f[2]) /* mouse outside the model areas? */ if (ps->bucketMin[0] == ps->bucketMax[0] || ps->bucketMin[1] == ps->bucketMax[1]) { - return 0; + return false; } - - ps->context_bucket_x = ps->bucketMin[0]; - ps->context_bucket_y = ps->bucketMin[1]; } else { /* reproject: PROJ_SRC_* */ ps->bucketMin[0] = 0; @@ -4724,11 +4723,10 @@ static bool project_bucket_iter_init(ProjPaintState *ps, const float mval_f[2]) ps->bucketMax[0] = ps->buckets_x; ps->bucketMax[1] = ps->buckets_y; - - ps->context_bucket_x = 0; - ps->context_bucket_y = 0; } - return 1; + + ps->context_bucket_index = ps->bucketMin[0] + ps->bucketMin[1] * ps->buckets_x; + return true; } static bool project_bucket_iter_next(ProjPaintState *ps, @@ -4738,37 +4736,28 @@ static bool project_bucket_iter_next(ProjPaintState *ps, { const int diameter = 2 * ps->brush_size; - if (ps->thread_tot > 1) { - BLI_thread_lock(LOCK_CUSTOM1); - } - - // printf("%d %d\n", ps->context_bucket_x, ps->context_bucket_y); + const int max_bucket_idx = ps->bucketMax[0] + (ps->bucketMax[1] - 1) * ps->buckets_x; - for (; ps->context_bucket_y < ps->bucketMax[1]; ps->context_bucket_y++) { - for (; ps->context_bucket_x < ps->bucketMax[0]; ps->context_bucket_x++) { + for (int bidx = atomic_fetch_and_add_int32(&ps->context_bucket_index, 1); bidx < max_bucket_idx; + bidx = atomic_fetch_and_add_int32(&ps->context_bucket_index, 1)) { + const int bucket_y = bidx / ps->buckets_x; + const int bucket_x = bidx - (bucket_y * ps->buckets_x); + BLI_assert(bucket_y >= ps->bucketMin[1] && bucket_y < ps->bucketMax[1]); + if (bucket_x >= ps->bucketMin[0] && bucket_x < ps->bucketMax[0]) { /* use bucket_bounds for project_bucket_isect_circle and project_bucket_init*/ - project_bucket_bounds(ps, ps->context_bucket_x, ps->context_bucket_y, bucket_bounds); + project_bucket_bounds(ps, bucket_x, bucket_y, bucket_bounds); if ((ps->source != PROJ_SRC_VIEW) || project_bucket_isect_circle(mval, (float)(diameter * diameter), bucket_bounds)) { - *bucket_index = ps->context_bucket_x + (ps->context_bucket_y * ps->buckets_x); - ps->context_bucket_x++; - - if (ps->thread_tot > 1) { - BLI_thread_unlock(LOCK_CUSTOM1); - } + *bucket_index = bidx; - return 1; + return true; } } - ps->context_bucket_x = ps->bucketMin[0]; } - if (ps->thread_tot > 1) { - BLI_thread_unlock(LOCK_CUSTOM1); - } - return 0; + return false; } /* Each thread gets one of these, also used as an argument to pass to project_paint_op */ @@ -5721,7 +5710,7 @@ void paint_proj_stroke(const bContext *C, /* clone gets special treatment here to avoid going through image initialization */ if (ps_handle->is_clone_cursor_pick) { Scene *scene = ps_handle->scene; - struct Depsgraph *depsgraph = CTX_data_depsgraph(C); + struct Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); View3D *v3d = CTX_wm_view3d(C); ARegion *ar = CTX_wm_region(C); float *cursor = scene->cursor.location; @@ -5733,6 +5722,7 @@ void paint_proj_stroke(const bContext *C, return; } + DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE); ED_region_tag_redraw(ar); return; @@ -5789,7 +5779,7 @@ static void project_state_init(bContext *C, Object *ob, ProjPaintState *ps, int ps->rv3d = CTX_wm_region_view3d(C); ps->ar = CTX_wm_region(C); - ps->depsgraph = CTX_data_depsgraph(C); + ps->depsgraph = CTX_data_ensure_evaluated_depsgraph(C); ps->scene = scene; /* allow override of active object */ ps->ob = ob; @@ -6153,7 +6143,7 @@ static int texture_paint_image_from_view_exec(bContext *C, wmOperator *op) char filename[FILE_MAX]; Main *bmain = CTX_data_main(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene = CTX_data_scene(C); ToolSettings *settings = scene->toolsettings; int w = settings->imapaint.screen_grab_size[0]; @@ -6244,8 +6234,7 @@ static int texture_paint_image_from_view_exec(bContext *C, wmOperator *op) array += sizeof(rv3d->winmat) / sizeof(float); memcpy(array, rv3d->viewmat, sizeof(rv3d->viewmat)); array += sizeof(rv3d->viewmat) / sizeof(float); - is_ortho = ED_view3d_clip_range_get( - CTX_data_depsgraph(C), v3d, rv3d, &array[0], &array[1], true); + is_ortho = ED_view3d_clip_range_get(depsgraph, v3d, rv3d, &array[0], &array[1], true); /* using float for a bool is dodgy but since its an extra member in the array... * easier then adding a single bool prop */ array[2] = is_ortho ? 1.0f : 0.0f; diff --git a/source/blender/editors/sculpt_paint/paint_image_undo.c b/source/blender/editors/sculpt_paint/paint_image_undo.c index e7f100ebacb..2a1158ec804 100644 --- a/source/blender/editors/sculpt_paint/paint_image_undo.c +++ b/source/blender/editors/sculpt_paint/paint_image_undo.c @@ -69,7 +69,10 @@ typedef struct UndoImageTile { int x, y; - Image *ima; + /* TODO(campbell): avoid storing the ID per tile, + * adds unnecessary overhead restoring undo steps when most tiles share the same image. */ + UndoRefID_Image image_ref; + short source, use_float; char gen_type; bool valid; @@ -245,7 +248,7 @@ void *image_undo_push_tile(ListBase *undo_tiles, tile->source = ima->source; tile->use_float = use_float; tile->valid = true; - tile->ima = ima; + tile->image_ref.ptr = ima; if (valid) { *valid = &tile->valid; @@ -284,7 +287,7 @@ static void image_undo_restore_runtime(ListBase *lb) tmpibuf = IMB_allocImBuf(IMAPAINT_TILE_SIZE, IMAPAINT_TILE_SIZE, 32, IB_rectfloat | IB_rect); for (tile = lb->first; tile; tile = tile->next) { - Image *ima = tile->ima; + Image *ima = tile->image_ref.ptr; ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL); undo_copy_tile(tile, tmpibuf, ibuf, RESTORE); @@ -304,19 +307,15 @@ static void image_undo_restore_runtime(ListBase *lb) IMB_freeImBuf(tmpibuf); } -static void image_undo_restore_list(ListBase *lb, struct UndoIDPtrMap *id_map) +static void image_undo_restore_list(ListBase *lb) { ImBuf *tmpibuf = IMB_allocImBuf( IMAPAINT_TILE_SIZE, IMAPAINT_TILE_SIZE, 32, IB_rectfloat | IB_rect); - /* Store last found image. */ - ID *image_prev[2] = {NULL}; - for (UndoImageTile *tile = lb->first; tile; tile = tile->next) { short use_float; - Image *ima = (Image *)BKE_undosys_ID_map_lookup_with_prev(id_map, &tile->ima->id, image_prev); - + Image *ima = tile->image_ref.ptr; ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL); if (ima && ibuf && !STREQ(tile->ibufname, ibuf->name)) { @@ -398,33 +397,8 @@ typedef struct ImageUndoStep { ListBase tiles; bool is_encode_init; ePaintMode paint_mode; - - /* Use for all ID lookups (can be NULL). */ - struct UndoIDPtrMap *id_map; } ImageUndoStep; -static void image_undosys_step_encode_store_ids(ImageUndoStep *us) -{ - us->id_map = BKE_undosys_ID_map_create(); - - ID *image_prev = NULL; - for (UndoImageTile *tile = us->tiles.first; tile; tile = tile->next) { - BKE_undosys_ID_map_add_with_prev(us->id_map, &tile->ima->id, &image_prev); - } -} - -/* Restore at runtime. */ -#if 0 -static void paint_undosys_step_decode_restore_ids(ImageUndoStep *us) -{ - ID *image_prev[2] = {NULL}; - for (UndoImageTile *tile = us->tiles.first; tile; tile = tile->next) { - tile->ima = (Image *)BKE_undosys_ID_map_lookup_with_prev( - us->id_map, &tile->ima->id, image_prev); - } -} -#endif - static bool image_undosys_poll(bContext *C) { Object *obact = CTX_data_active_object(C); @@ -486,8 +460,6 @@ static bool image_undosys_step_encode(struct bContext *C, us->paint_mode = paint_mode; } - image_undosys_step_encode_store_ids(us); - us_p->is_applied = true; return true; @@ -496,18 +468,18 @@ static bool image_undosys_step_encode(struct bContext *C, static void image_undosys_step_decode_undo_impl(ImageUndoStep *us) { BLI_assert(us->step.is_applied == true); - image_undo_restore_list(&us->tiles, us->id_map); + image_undo_restore_list(&us->tiles); us->step.is_applied = false; } static void image_undosys_step_decode_redo_impl(ImageUndoStep *us) { BLI_assert(us->step.is_applied == false); - image_undo_restore_list(&us->tiles, us->id_map); + image_undo_restore_list(&us->tiles); us->step.is_applied = true; } -static void image_undosys_step_decode_undo(ImageUndoStep *us) +static void image_undosys_step_decode_undo(ImageUndoStep *us, bool is_final) { ImageUndoStep *us_iter = us; while (us_iter->step.next && (us_iter->step.next->type == us_iter->step.type)) { @@ -516,8 +488,11 @@ static void image_undosys_step_decode_undo(ImageUndoStep *us) } us_iter = (ImageUndoStep *)us_iter->step.next; } - while (us_iter != us) { + while (us_iter != us || (!is_final && us_iter == us)) { image_undosys_step_decode_undo_impl(us_iter); + if (us_iter == us) { + break; + } us_iter = (ImageUndoStep *)us_iter->step.prev; } } @@ -541,15 +516,11 @@ static void image_undosys_step_decode_redo(ImageUndoStep *us) } static void image_undosys_step_decode( - struct bContext *C, struct Main *bmain, UndoStep *us_p, int dir, bool UNUSED(is_final)) + struct bContext *C, struct Main *bmain, UndoStep *us_p, int dir, bool is_final) { ImageUndoStep *us = (ImageUndoStep *)us_p; -#if 0 - paint_undosys_step_decode_restore_ids(us); -#endif - if (dir < 0) { - image_undosys_step_decode_undo(us); + image_undosys_step_decode_undo(us, is_final); } else { image_undosys_step_decode_redo(us); @@ -567,7 +538,6 @@ static void image_undosys_step_free(UndoStep *us_p) { ImageUndoStep *us = (ImageUndoStep *)us_p; image_undo_free_list(&us->tiles); - BKE_undosys_ID_map_destroy(us->id_map); } static void image_undosys_foreach_ID_ref(UndoStep *us_p, @@ -575,8 +545,8 @@ static void image_undosys_foreach_ID_ref(UndoStep *us_p, void *user_data) { ImageUndoStep *us = (ImageUndoStep *)us_p; - if (us->id_map != NULL) { - BKE_undosys_ID_map_foreach_ID_ref(us->id_map, foreach_ID_ref_fn, user_data); + for (UndoImageTile *tile = us->tiles.first; tile; tile = tile->next) { + foreach_ID_ref_fn(user_data, ((UndoRefID *)&tile->image_ref)); } } diff --git a/source/blender/editors/sculpt_paint/paint_mask.c b/source/blender/editors/sculpt_paint/paint_mask.c index f60ea8410ef..74212058fc7 100644 --- a/source/blender/editors/sculpt_paint/paint_mask.c +++ b/source/blender/editors/sculpt_paint/paint_mask.c @@ -101,7 +101,7 @@ typedef struct MaskTaskData { static void mask_flood_fill_task_cb(void *__restrict userdata, const int i, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { MaskTaskData *data = userdata; @@ -130,7 +130,7 @@ static int mask_flood_fill_exec(bContext *C, wmOperator *op) { ARegion *ar = CTX_wm_region(C); Object *ob = CTX_data_active_object(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); PaintMaskFloodMode mode; float value; PBVH *pbvh; @@ -159,7 +159,7 @@ static int mask_flood_fill_exec(bContext *C, wmOperator *op) .value = value, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range( @@ -243,7 +243,7 @@ static void flip_plane(float out[4], const float in[4], const char symm) static void mask_box_select_task_cb(void *__restrict userdata, const int i, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { MaskTaskData *data = userdata; @@ -277,7 +277,7 @@ static void mask_box_select_task_cb(void *__restrict userdata, bool ED_sculpt_mask_box_select(struct bContext *C, ViewContext *vc, const rcti *rect, bool select) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Sculpt *sd = vc->scene->toolsettings->sculpt; BoundBox bb; float clip_planes[4][4]; @@ -328,7 +328,7 @@ bool ED_sculpt_mask_box_select(struct bContext *C, ViewContext *vc, const rcti * .clip_planes_final = clip_planes_final, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); @@ -405,7 +405,7 @@ static void mask_lasso_px_cb(int x, int x_end, int y, void *user_data) static void mask_gesture_lasso_task_cb(void *__restrict userdata, const int i, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { LassoMaskData *lasso_data = userdata; MaskTaskData *data = &lasso_data->task_data; @@ -444,7 +444,7 @@ static int paint_mask_gesture_lasso_exec(bContext *C, wmOperator *op) const int(*mcords)[2] = WM_gesture_lasso_path_to_array(C, op, &mcords_tot); if (mcords) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); float clip_planes[4][4], clip_planes_final[4][4]; BoundBox bb; Object *ob; @@ -515,7 +515,7 @@ static int paint_mask_gesture_lasso_exec(bContext *C, wmOperator *op) data.task_data.mode = mode; data.task_data.value = value; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && (totnode > SCULPT_THREADED_LIMIT)); diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c index 12891484e73..f073877ebcf 100644 --- a/source/blender/editors/sculpt_paint/paint_stroke.c +++ b/source/blender/editors/sculpt_paint/paint_stroke.c @@ -1329,7 +1329,7 @@ int paint_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event) redraw = true; } - /* do updates for redraw. if event is inbetween mousemove there are more + /* do updates for redraw. if event is in between mouse-move there are more * coming, so postpone potentially slow redraw updates until all are done */ if (event->type != INBETWEEN_MOUSEMOVE) { wmWindow *window = CTX_wm_window(C); diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c index c8ad1b5781d..0f37968f599 100644 --- a/source/blender/editors/sculpt_paint/paint_utils.c +++ b/source/blender/editors/sculpt_paint/paint_utils.c @@ -463,7 +463,7 @@ void paint_sample_color( bContext *C, ARegion *ar, int x, int y, bool texpaint_proj, bool use_palette) { Scene *scene = CTX_data_scene(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Paint *paint = BKE_paint_get_active_from_context(C); Palette *palette = BKE_paint_palette(paint); PaletteColor *color = NULL; diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 980b043bf8b..9215a90c446 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -1171,30 +1171,11 @@ void ED_object_vpaintmode_enter_ex( { ed_vwpaintmode_enter_generic(bmain, depsgraph, wm, scene, ob, OB_MODE_VERTEX_PAINT); } -void ED_object_vpaintmode_enter(struct bContext *C) -{ - Main *bmain = CTX_data_main(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); - wmWindowManager *wm = CTX_wm_manager(C); - Scene *scene = CTX_data_scene(C); - Object *ob = CTX_data_active_object(C); - ED_object_vpaintmode_enter_ex(bmain, depsgraph, wm, scene, ob); -} - void ED_object_wpaintmode_enter_ex( Main *bmain, Depsgraph *depsgraph, wmWindowManager *wm, Scene *scene, Object *ob) { ed_vwpaintmode_enter_generic(bmain, depsgraph, wm, scene, ob, OB_MODE_WEIGHT_PAINT); } -void ED_object_wpaintmode_enter(struct bContext *C) -{ - Main *bmain = CTX_data_main(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); - wmWindowManager *wm = CTX_wm_manager(C); - Scene *scene = CTX_data_scene(C); - Object *ob = CTX_data_active_object(C); - ED_object_wpaintmode_enter_ex(bmain, depsgraph, wm, scene, ob); -} /** \} */ @@ -1396,7 +1377,7 @@ void PAINT_OT_weight_paint_toggle(wmOperatorType *ot) ot->poll = paint_poll_test; /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /** \} */ @@ -1556,7 +1537,7 @@ static bool wpaint_stroke_test_start(bContext *C, wmOperator *op, const float mo bool *defbase_sel; SculptSession *ss = ob->sculpt; VPaint *vp = CTX_data_tool_settings(C)->wpaint; - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); if (ED_wpaint_ensure_data(C, op->reports, WPAINT_ENSURE_MIRROR, &vgroup_index) == false) { return false; @@ -1713,7 +1694,7 @@ static float wpaint_get_active_weight(const MDeformVert *dv, const WeightPaintIn static void do_wpaint_precompute_weight_cb_ex(void *__restrict userdata, const int n, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { SculptThreadedTaskData *data = userdata; const MDeformVert *dv = &data->me->dvert[n]; @@ -1737,7 +1718,7 @@ static void precompute_weight_values( .me = me, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); BLI_task_parallel_range(0, me->totvert, &data, do_wpaint_precompute_weight_cb_ex, &settings); @@ -1746,7 +1727,7 @@ static void precompute_weight_values( static void do_wpaint_brush_blur_task_cb_ex(void *__restrict userdata, const int n, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; @@ -1838,7 +1819,7 @@ static void do_wpaint_brush_blur_task_cb_ex(void *__restrict userdata, static void do_wpaint_brush_smear_task_cb_ex(void *__restrict userdata, const int n, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; @@ -1949,7 +1930,7 @@ static void do_wpaint_brush_smear_task_cb_ex(void *__restrict userdata, static void do_wpaint_brush_draw_task_cb_ex(void *__restrict userdata, const int n, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; @@ -2022,7 +2003,7 @@ static void do_wpaint_brush_draw_task_cb_ex(void *__restrict userdata, } static void do_wpaint_brush_calc_average_weight_cb_ex( - void *__restrict userdata, const int n, const ParallelRangeTLS *__restrict UNUSED(tls)) + void *__restrict userdata, const int n, const TaskParallelTLS *__restrict UNUSED(tls)) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; @@ -2078,7 +2059,7 @@ static void calculate_average_weight(SculptThreadedTaskData *data, struct WPaintAverageAccum *accum = MEM_mallocN(sizeof(*accum) * totnode, __func__); data->custom_data = accum; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((data->sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); @@ -2127,7 +2108,7 @@ static void wpaint_paint_leaves(bContext *C, /* Use this so average can modify its weight without touching the brush. */ data.strength = BKE_brush_weight_get(scene, brush); - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); /* NOTE: current mirroring code cannot be run in parallel */ settings.use_threading = !(me->editflag & ME_EDIT_MIRROR_X); @@ -2569,7 +2550,7 @@ void PAINT_OT_vertex_paint_toggle(wmOperatorType *ot) ot->poll = paint_poll_test; /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /** \} */ @@ -2638,7 +2619,7 @@ static bool vpaint_stroke_test_start(bContext *C, struct wmOperator *op, const f Object *ob = CTX_data_active_object(C); Mesh *me; SculptSession *ss = ob->sculpt; - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); /* context checks could be a poll() */ me = BKE_mesh_from_object(ob); @@ -2705,8 +2686,9 @@ static bool vpaint_stroke_test_start(bContext *C, struct wmOperator *op, const f return 1; } -static void do_vpaint_brush_calc_average_color_cb_ex( - void *__restrict userdata, const int n, const ParallelRangeTLS *__restrict UNUSED(tls)) +static void do_vpaint_brush_calc_average_color_cb_ex(void *__restrict userdata, + const int n, + const TaskParallelTLS *__restrict UNUSED(tls)) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; @@ -2772,7 +2754,7 @@ static float tex_color_alpha_ubyte(SculptThreadedTaskData *data, static void do_vpaint_brush_draw_task_cb_ex(void *__restrict userdata, const int n, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; @@ -2871,7 +2853,7 @@ static void do_vpaint_brush_draw_task_cb_ex(void *__restrict userdata, static void do_vpaint_brush_blur_task_cb_ex(void *__restrict userdata, const int n, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; @@ -2989,7 +2971,7 @@ static void do_vpaint_brush_blur_task_cb_ex(void *__restrict userdata, static void do_vpaint_brush_smear_task_cb_ex(void *__restrict userdata, const int n, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; @@ -3139,7 +3121,7 @@ static void calculate_average_color(SculptThreadedTaskData *data, struct VPaintAverageAccum *accum = MEM_mallocN(sizeof(*accum) * totnode, __func__); data->custom_data = accum; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); BLI_task_parallel_range(0, totnode, data, do_vpaint_brush_calc_average_color_cb_ex, &settings); @@ -3185,7 +3167,7 @@ static void vpaint_paint_leaves(bContext *C, .lcol = (uint *)me->mloopcol, .me = me, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); switch ((eBrushVertexPaintTool)brush->vertexpaint_tool) { case VPAINT_TOOL_AVERAGE: diff --git a/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c b/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c index b6a6c897606..1dc28328244 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c +++ b/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c @@ -119,7 +119,7 @@ static bool weight_from_bones_poll(bContext *C) static int weight_from_bones_exec(bContext *C, wmOperator *op) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); Object *armob = modifiers_isDeformedByArmature(ob); @@ -161,7 +161,7 @@ void PAINT_OT_weight_from_bones(wmOperatorType *ot) ot->poll = weight_from_bones_poll; /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ ot->prop = RNA_def_enum( @@ -746,7 +746,7 @@ static int paint_weight_gradient_exec(bContext *C, wmOperator *op) float sco_end[2] = {x_end, y_end}; const bool is_interactive = (gesture != NULL); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); WPGradient_userData data = {NULL}; @@ -880,7 +880,7 @@ void PAINT_OT_weight_gradient(wmOperatorType *ot) ot->cancel = WM_gesture_straightline_cancel; /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; prop = RNA_def_enum(ot->srna, "type", gradient_types, 0, "Type", ""); RNA_def_property_flag(prop, PROP_SKIP_SAVE); diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 173d6ed5085..c8709d40f96 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -368,7 +368,7 @@ static bool sculpt_stroke_is_dynamic_topology(const SculptSession *ss, const Bru static void paint_mesh_restore_co_task_cb(void *__restrict userdata, const int n, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; @@ -438,7 +438,7 @@ static void paint_mesh_restore_co(Sculpt *sd, Object *ob) .nodes = nodes, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && !ss->bm && totnode > SCULPT_THREADED_LIMIT); @@ -801,7 +801,7 @@ static float calc_symmetry_feather(Sculpt *sd, StrokeCache *cache) static void calc_area_normal_and_center_task_cb(void *__restrict userdata, const int n, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; @@ -961,7 +961,7 @@ static void calc_area_center( }; BLI_mutex_init(&data.mutex); - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, calc_area_normal_and_center_task_cb, &settings); @@ -1018,7 +1018,7 @@ void sculpt_pbvh_calc_area_normal(const Brush *brush, }; BLI_mutex_init(&data.mutex); - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = use_threading; BLI_task_parallel_range(0, totnode, &data, calc_area_normal_and_center_task_cb, &settings); @@ -1063,7 +1063,7 @@ static void calc_area_normal_and_center( }; BLI_mutex_init(&data.mutex); - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, calc_area_normal_and_center_task_cb, &settings); @@ -1262,7 +1262,6 @@ float tex_strength(SculptSession *ss, /* Falloff curve */ avg *= BKE_brush_curve_strength(br, len, cache->radius); - avg *= frontface(br, cache->view_normal, vno, fno); /* Paint mask */ @@ -1758,7 +1757,7 @@ typedef struct { static void do_smooth_brush_mesh_task_cb_ex(void *__restrict userdata, const int n, - const ParallelRangeTLS *__restrict tls) + const TaskParallelTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; @@ -1813,7 +1812,7 @@ static void do_smooth_brush_mesh_task_cb_ex(void *__restrict userdata, static void do_smooth_brush_bmesh_task_cb_ex(void *__restrict userdata, const int n, - const ParallelRangeTLS *__restrict tls) + const TaskParallelTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; @@ -1868,7 +1867,7 @@ static void do_smooth_brush_bmesh_task_cb_ex(void *__restrict userdata, static void do_topology_rake_bmesh_task_cb_ex(void *__restrict userdata, const int n, - const ParallelRangeTLS *__restrict tls) + const TaskParallelTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; @@ -1925,7 +1924,7 @@ static void do_topology_rake_bmesh_task_cb_ex(void *__restrict userdata, static void do_smooth_brush_multires_task_cb_ex(void *__restrict userdata, const int n, - const ParallelRangeTLS *__restrict tls) + const TaskParallelTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptDoBrushSmoothGridDataChunk *data_chunk = tls->userdata_chunk; @@ -2115,7 +2114,7 @@ static void smooth(Sculpt *sd, .strength = strength, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); @@ -2175,7 +2174,7 @@ static void bmesh_topology_rake( .nodes = nodes, .strength = factor, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); @@ -2191,7 +2190,7 @@ static void do_smooth_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnod static void do_mask_brush_draw_task_cb_ex(void *__restrict userdata, const int n, - const ParallelRangeTLS *__restrict tls) + const TaskParallelTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; @@ -2233,7 +2232,7 @@ static void do_mask_brush_draw(Sculpt *sd, Object *ob, PBVHNode **nodes, int tot .nodes = nodes, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, do_mask_brush_draw_task_cb_ex, &settings); @@ -2256,7 +2255,7 @@ static void do_mask_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) static void do_draw_brush_task_cb_ex(void *__restrict userdata, const int n, - const ParallelRangeTLS *__restrict tls) + const TaskParallelTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; @@ -2320,7 +2319,7 @@ static void do_draw_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) .offset = offset, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, do_draw_brush_task_cb_ex, &settings); @@ -2331,7 +2330,7 @@ static void do_draw_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) */ static void do_crease_brush_task_cb_ex(void *__restrict userdata, const int n, - const ParallelRangeTLS *__restrict tls) + const TaskParallelTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; @@ -2436,7 +2435,7 @@ static void do_crease_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnod .flippedbstrength = flippedbstrength, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, do_crease_brush_task_cb_ex, &settings); @@ -2444,7 +2443,7 @@ static void do_crease_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnod static void do_pinch_brush_task_cb_ex(void *__restrict userdata, const int n, - const ParallelRangeTLS *__restrict tls) + const TaskParallelTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; @@ -2498,7 +2497,7 @@ static void do_pinch_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode .nodes = nodes, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, do_pinch_brush_task_cb_ex, &settings); @@ -2506,7 +2505,7 @@ static void do_pinch_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode static void do_grab_brush_task_cb_ex(void *__restrict userdata, const int n, - const ParallelRangeTLS *__restrict tls) + const TaskParallelTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; @@ -2570,7 +2569,7 @@ static void do_grab_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) .grab_delta = grab_delta, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, do_grab_brush_task_cb_ex, &settings); @@ -2578,7 +2577,7 @@ static void do_grab_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) static void do_nudge_brush_task_cb_ex(void *__restrict userdata, const int n, - const ParallelRangeTLS *__restrict tls) + const TaskParallelTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; @@ -2637,7 +2636,7 @@ static void do_nudge_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode .cono = cono, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, do_nudge_brush_task_cb_ex, &settings); @@ -2645,7 +2644,7 @@ static void do_nudge_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode static void do_snake_hook_brush_task_cb_ex(void *__restrict userdata, const int n, - const ParallelRangeTLS *__restrict tls) + const TaskParallelTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; @@ -2758,7 +2757,7 @@ static void do_snake_hook_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int to .grab_delta = grab_delta, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, do_snake_hook_brush_task_cb_ex, &settings); @@ -2766,7 +2765,7 @@ static void do_snake_hook_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int to static void do_thumb_brush_task_cb_ex(void *__restrict userdata, const int n, - const ParallelRangeTLS *__restrict tls) + const TaskParallelTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; @@ -2830,7 +2829,7 @@ static void do_thumb_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode .cono = cono, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, do_thumb_brush_task_cb_ex, &settings); @@ -2838,7 +2837,7 @@ static void do_thumb_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode static void do_rotate_brush_task_cb_ex(void *__restrict userdata, const int n, - const ParallelRangeTLS *__restrict tls) + const TaskParallelTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; @@ -2903,7 +2902,7 @@ static void do_rotate_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnod .angle = angle, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, do_rotate_brush_task_cb_ex, &settings); @@ -2911,7 +2910,7 @@ static void do_rotate_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnod static void do_layer_brush_task_cb_ex(void *__restrict userdata, const int n, - const ParallelRangeTLS *__restrict tls) + const TaskParallelTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; @@ -3000,7 +2999,7 @@ static void do_layer_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode }; BLI_mutex_init(&data.mutex); - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, do_layer_brush_task_cb_ex, &settings); @@ -3010,7 +3009,7 @@ static void do_layer_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode static void do_inflate_brush_task_cb_ex(void *__restrict userdata, const int n, - const ParallelRangeTLS *__restrict tls) + const TaskParallelTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; @@ -3068,7 +3067,7 @@ static void do_inflate_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totno .nodes = nodes, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, do_inflate_brush_task_cb_ex, &settings); @@ -3184,7 +3183,7 @@ static float get_offset(Sculpt *sd, SculptSession *ss) static void do_flatten_brush_task_cb_ex(void *__restrict userdata, const int n, - const ParallelRangeTLS *__restrict tls) + const TaskParallelTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; @@ -3266,7 +3265,7 @@ static void do_flatten_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totno .area_co = area_co, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, do_flatten_brush_task_cb_ex, &settings); @@ -3274,7 +3273,7 @@ static void do_flatten_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totno static void do_clay_brush_task_cb_ex(void *__restrict userdata, const int n, - const ParallelRangeTLS *__restrict tls) + const TaskParallelTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; @@ -3364,7 +3363,7 @@ static void do_clay_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) .area_co = area_co, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, do_clay_brush_task_cb_ex, &settings); @@ -3372,7 +3371,7 @@ static void do_clay_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) static void do_clay_strips_brush_task_cb_ex(void *__restrict userdata, const int n, - const ParallelRangeTLS *__restrict tls) + const TaskParallelTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; @@ -3494,7 +3493,7 @@ static void do_clay_strips_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int t .mat = mat, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, do_clay_strips_brush_task_cb_ex, &settings); @@ -3502,7 +3501,7 @@ static void do_clay_strips_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int t static void do_fill_brush_task_cb_ex(void *__restrict userdata, const int n, - const ParallelRangeTLS *__restrict tls) + const TaskParallelTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; @@ -3587,7 +3586,7 @@ static void do_fill_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) .area_co = area_co, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, do_fill_brush_task_cb_ex, &settings); @@ -3595,7 +3594,7 @@ static void do_fill_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode) static void do_scrape_brush_task_cb_ex(void *__restrict userdata, const int n, - const ParallelRangeTLS *__restrict tls) + const TaskParallelTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; @@ -3679,7 +3678,7 @@ static void do_scrape_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnod .area_co = area_co, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, do_scrape_brush_task_cb_ex, &settings); @@ -3687,7 +3686,7 @@ static void do_scrape_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnod static void do_gravity_task_cb_ex(void *__restrict userdata, const int n, - const ParallelRangeTLS *__restrict tls) + const TaskParallelTLS *__restrict tls) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; @@ -3748,7 +3747,7 @@ static void do_gravity(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode, fl .offset = offset, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, do_gravity_task_cb_ex, &settings); @@ -3862,7 +3861,7 @@ static void sculpt_topology_update(Sculpt *sd, static void do_brush_action_task_cb(void *__restrict userdata, const int n, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { SculptThreadedTaskData *data = userdata; @@ -3896,7 +3895,7 @@ static void do_brush_action(Sculpt *sd, Object *ob, Brush *brush, UnifiedPaintSe .nodes = nodes, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &task_data, do_brush_action_task_cb, &settings); @@ -4021,7 +4020,7 @@ static void sculpt_flush_pbvhvert_deform(Object *ob, PBVHVertexIter *vd) static void sculpt_combine_proxies_task_cb(void *__restrict userdata, const int n, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; @@ -4093,7 +4092,7 @@ static void sculpt_combine_proxies(Sculpt *sd, Object *ob) .nodes = nodes, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, sculpt_combine_proxies_task_cb, &settings); @@ -4130,7 +4129,7 @@ static void sculpt_update_keyblock(Object *ob) static void sculpt_flush_stroke_deform_task_cb(void *__restrict userdata, const int n, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; @@ -4186,7 +4185,7 @@ static void sculpt_flush_stroke_deform(Sculpt *sd, Object *ob) .vertCos = vertCos, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range(0, totnode, &data, sculpt_flush_stroke_deform_task_cb, &settings); @@ -4923,7 +4922,7 @@ static void sculpt_stroke_modifiers_check(const bContext *C, Object *ob, const B SculptSession *ss = ob->sculpt; if (ss->kb || ss->modifiers_active) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); bool need_pmap = sculpt_any_smooth_mode(brush, ss->cache, 0); BKE_sculpt_update_object_for_edit(depsgraph, ob, need_pmap, false); } @@ -5136,7 +5135,7 @@ static void sculpt_brush_init_tex(const Scene *scene, Sculpt *sd, SculptSession static void sculpt_brush_stroke_init(bContext *C, wmOperator *op) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); Sculpt *sd = CTX_data_tool_settings(C)->sculpt; @@ -5184,7 +5183,7 @@ void sculpt_update_object_bounding_box(Object *ob) static void sculpt_flush_update_step(bContext *C) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); Object *ob = CTX_data_active_object(C); SculptSession *ss = ob->sculpt; ARegion *ar = CTX_wm_region(C); @@ -5753,7 +5752,7 @@ static void sculpt_dynamic_topology_disable_ex( void sculpt_dynamic_topology_disable(bContext *C, SculptUndoNode *unode) { Main *bmain = CTX_data_main(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); sculpt_dynamic_topology_disable_ex(bmain, depsgraph, scene, ob, unode); @@ -5790,7 +5789,7 @@ static void sculpt_dynamic_topology_enable_with_undo(Main *bmain, static int sculpt_dynamic_topology_toggle_exec(bContext *C, wmOperator *UNUSED(op)) { Main *bmain = CTX_data_main(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); SculptSession *ss = ob->sculpt; @@ -6153,16 +6152,6 @@ void ED_object_sculptmode_enter_ex(Main *bmain, DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE); } -void ED_object_sculptmode_enter(struct bContext *C, ReportList *reports) -{ - Main *bmain = CTX_data_main(C); - Scene *scene = CTX_data_scene(C); - ViewLayer *view_layer = CTX_data_view_layer(C); - Object *ob = OBACT(view_layer); - Depsgraph *depsgraph = CTX_data_depsgraph(C); - ED_object_sculptmode_enter_ex(bmain, depsgraph, scene, ob, false, reports); -} - void ED_object_sculptmode_exit_ex(Main *bmain, Depsgraph *depsgraph, Scene *scene, Object *ob) { const int mode_flag = OB_MODE_SCULPT; @@ -6209,16 +6198,6 @@ void ED_object_sculptmode_exit_ex(Main *bmain, Depsgraph *depsgraph, Scene *scen DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE); } -void ED_object_sculptmode_exit(bContext *C) -{ - Main *bmain = CTX_data_main(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); - Scene *scene = CTX_data_scene(C); - ViewLayer *view_layer = CTX_data_view_layer(C); - Object *ob = OBACT(view_layer); - ED_object_sculptmode_exit_ex(bmain, depsgraph, scene, ob); -} - static int sculpt_mode_toggle_exec(bContext *C, wmOperator *op) { struct wmMsgBus *mbus = CTX_wm_message_bus(C); @@ -6265,7 +6244,7 @@ static void SCULPT_OT_sculptmode_toggle(wmOperatorType *ot) ot->exec = sculpt_mode_toggle_exec; ot->poll = ED_operator_object_active_editable_mesh; - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } static bool sculpt_and_constant_or_manual_detail_poll(bContext *C) diff --git a/source/blender/editors/sculpt_paint/sculpt_undo.c b/source/blender/editors/sculpt_paint/sculpt_undo.c index 81bb9c35817..dde1e51e764 100644 --- a/source/blender/editors/sculpt_paint/sculpt_undo.c +++ b/source/blender/editors/sculpt_paint/sculpt_undo.c @@ -127,11 +127,10 @@ static bool sculpt_undo_restore_deformed( } } -static bool sculpt_undo_restore_coords(bContext *C, SculptUndoNode *unode) +static bool sculpt_undo_restore_coords(bContext *C, Depsgraph *depsgraph, SculptUndoNode *unode) { ViewLayer *view_layer = CTX_data_view_layer(C); Object *ob = OBACT(view_layer); - Depsgraph *depsgraph = CTX_data_depsgraph(C); SculptSession *ss = ob->sculpt; SubdivCCG *subdiv_ccg = ss->subdiv_ccg; MVert *mvert; @@ -323,7 +322,7 @@ static bool sculpt_undo_restore_mask(bContext *C, SculptUndoNode *unode) } static void sculpt_undo_bmesh_restore_generic_task_cb( - void *__restrict userdata, const int n, const ParallelRangeTLS *__restrict UNUSED(tls)) + void *__restrict userdata, const int n, const TaskParallelTLS *__restrict UNUSED(tls)) { PBVHNode **nodes = userdata; @@ -351,7 +350,7 @@ static void sculpt_undo_bmesh_restore_generic(bContext *C, BKE_pbvh_search_gather(ss->pbvh, NULL, NULL, &nodes, &totnode); - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = ((sd->flags & SCULPT_USE_OPENMP) && totnode > SCULPT_THREADED_LIMIT); BLI_task_parallel_range( @@ -455,13 +454,12 @@ static int sculpt_undo_bmesh_restore(bContext *C, return false; } -static void sculpt_undo_restore_list(bContext *C, ListBase *lb) +static void sculpt_undo_restore_list(bContext *C, Depsgraph *depsgraph, ListBase *lb) { Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); View3D *v3d = CTX_wm_view3d(C); Object *ob = OBACT(view_layer); - Depsgraph *depsgraph = CTX_data_depsgraph(C); SculptSession *ss = ob->sculpt; SubdivCCG *subdiv_ccg = ss->subdiv_ccg; SculptUndoNode *unode; @@ -512,7 +510,7 @@ static void sculpt_undo_restore_list(bContext *C, ListBase *lb) switch (unode->type) { case SCULPT_UNDO_COORDS: - if (sculpt_undo_restore_coords(C, unode)) { + if (sculpt_undo_restore_coords(C, depsgraph, unode)) { update = true; } break; @@ -1062,21 +1060,27 @@ static bool sculpt_undosys_step_encode(struct bContext *UNUSED(C), return true; } -static void sculpt_undosys_step_decode_undo_impl(struct bContext *C, SculptUndoStep *us) +static void sculpt_undosys_step_decode_undo_impl(struct bContext *C, + Depsgraph *depsgraph, + SculptUndoStep *us) { BLI_assert(us->step.is_applied == true); - sculpt_undo_restore_list(C, &us->data.nodes); + sculpt_undo_restore_list(C, depsgraph, &us->data.nodes); us->step.is_applied = false; } -static void sculpt_undosys_step_decode_redo_impl(struct bContext *C, SculptUndoStep *us) +static void sculpt_undosys_step_decode_redo_impl(struct bContext *C, + Depsgraph *depsgraph, + SculptUndoStep *us) { BLI_assert(us->step.is_applied == false); - sculpt_undo_restore_list(C, &us->data.nodes); + sculpt_undo_restore_list(C, depsgraph, &us->data.nodes); us->step.is_applied = true; } -static void sculpt_undosys_step_decode_undo(struct bContext *C, SculptUndoStep *us) +static void sculpt_undosys_step_decode_undo(struct bContext *C, + Depsgraph *depsgraph, + SculptUndoStep *us) { SculptUndoStep *us_iter = us; while (us_iter->step.next && (us_iter->step.next->type == us_iter->step.type)) { @@ -1086,12 +1090,14 @@ static void sculpt_undosys_step_decode_undo(struct bContext *C, SculptUndoStep * us_iter = (SculptUndoStep *)us_iter->step.next; } while (us_iter != us) { - sculpt_undosys_step_decode_undo_impl(C, us_iter); + sculpt_undosys_step_decode_undo_impl(C, depsgraph, us_iter); us_iter = (SculptUndoStep *)us_iter->step.prev; } } -static void sculpt_undosys_step_decode_redo(struct bContext *C, SculptUndoStep *us) +static void sculpt_undosys_step_decode_redo(struct bContext *C, + Depsgraph *depsgraph, + SculptUndoStep *us) { SculptUndoStep *us_iter = us; while (us_iter->step.prev && (us_iter->step.prev->type == us_iter->step.type)) { @@ -1101,7 +1107,7 @@ static void sculpt_undosys_step_decode_redo(struct bContext *C, SculptUndoStep * us_iter = (SculptUndoStep *)us_iter->step.prev; } while (us_iter && (us_iter->step.is_applied == false)) { - sculpt_undosys_step_decode_redo_impl(C, us_iter); + sculpt_undosys_step_decode_redo_impl(C, depsgraph, us_iter); if (us_iter == us) { break; } @@ -1112,6 +1118,8 @@ static void sculpt_undosys_step_decode_redo(struct bContext *C, SculptUndoStep * static void sculpt_undosys_step_decode( struct bContext *C, struct Main *bmain, UndoStep *us_p, int dir, bool UNUSED(is_final)) { + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); + /* Ensure sculpt mode. */ { Scene *scene = CTX_data_scene(C); @@ -1120,7 +1128,6 @@ static void sculpt_undosys_step_decode( BKE_scene_view_layer_graph_evaluated_ensure(bmain, scene, view_layer); Object *ob = OBACT(view_layer); if (ob && (ob->type == OB_MESH)) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); if (ob->mode & OB_MODE_SCULPT) { /* pass */ } @@ -1142,10 +1149,10 @@ static void sculpt_undosys_step_decode( SculptUndoStep *us = (SculptUndoStep *)us_p; if (dir < 0) { - sculpt_undosys_step_decode_undo(C, us); + sculpt_undosys_step_decode_undo(C, depsgraph, us); } else { - sculpt_undosys_step_decode_redo(C, us); + sculpt_undosys_step_decode_redo(C, depsgraph, us); } } diff --git a/source/blender/editors/sound/sound_ops.c b/source/blender/editors/sound/sound_ops.c index 0241a2fbe88..10d38055085 100644 --- a/source/blender/editors/sound/sound_ops.c +++ b/source/blender/editors/sound/sound_ops.c @@ -305,7 +305,9 @@ static int sound_bake_animation_exec(bContext *C, wmOperator *UNUSED(op)) { Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); - struct Depsgraph *depsgraph = CTX_data_depsgraph(C); + /* NOTE: We will be forefully evaluating dependency graph at every frame, so no need to ensure + * current scene state is evaluated as it will be lost anyway. */ + struct Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); int oldfra = scene->r.cfra; int cfra; @@ -343,7 +345,7 @@ static int sound_mixdown_exec(bContext *C, wmOperator *op) #ifdef WITH_AUDASPACE char path[FILE_MAX]; char filename[FILE_MAX]; - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); Main *bmain = CTX_data_main(C); int split; diff --git a/source/blender/editors/space_action/action_edit.c b/source/blender/editors/space_action/action_edit.c index 7fc84db3f75..944a0c74f4c 100644 --- a/source/blender/editors/space_action/action_edit.c +++ b/source/blender/editors/space_action/action_edit.c @@ -704,7 +704,6 @@ static void insert_action_keys(bAnimContext *ac, short mode) bAnimListElem *ale; int filter; - struct Depsgraph *depsgraph = ac->depsgraph; ReportList *reports = ac->reports; Scene *scene = ac->scene; ToolSettings *ts = scene->toolsettings; @@ -741,7 +740,6 @@ static void insert_action_keys(bAnimContext *ac, short mode) */ if (ale->id && !ale->owner) { insert_keyframe(ac->bmain, - depsgraph, reports, ale->id, NULL, diff --git a/source/blender/editors/space_action/action_select.c b/source/blender/editors/space_action/action_select.c index 7cc222ea529..9e2634b183a 100644 --- a/source/blender/editors/space_action/action_select.c +++ b/source/blender/editors/space_action/action_select.c @@ -1199,9 +1199,14 @@ static void select_moreless_action_keys(bAnimContext *ac, short mode) ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype); for (ale = anim_data.first; ale; ale = ale->next) { - FCurve *fcu = (FCurve *)ale->key_data; + + /* TODO: other types. */ + if (ale->datatype != ALE_FCURVE) { + continue; + } /* only continue if F-Curve has keyframes */ + FCurve *fcu = (FCurve *)ale->key_data; if (fcu->bezt == NULL) { continue; } diff --git a/source/blender/editors/space_clip/clip_graph_draw.c b/source/blender/editors/space_clip/clip_graph_draw.c index ef5de1acee3..3f705aad89a 100644 --- a/source/blender/editors/space_clip/clip_graph_draw.c +++ b/source/blender/editors/space_clip/clip_graph_draw.c @@ -48,6 +48,7 @@ #include "clip_intern.h" // own include typedef struct TrackMotionCurveUserData { + SpaceClip *sc; MovieTrackingTrack *act_track; bool sel; float xscale, yscale, hsize; @@ -57,24 +58,43 @@ typedef struct TrackMotionCurveUserData { static void tracking_segment_point_cb(void *userdata, MovieTrackingTrack *UNUSED(track), MovieTrackingMarker *UNUSED(marker), - int UNUSED(coord), + eClipCurveValueSource value_source, int scene_framenr, float val) { TrackMotionCurveUserData *data = (TrackMotionCurveUserData *)userdata; + if (!clip_graph_value_visible(data->sc, value_source)) { + return; + } + immVertex2f(data->pos, scene_framenr, val); } static void tracking_segment_start_cb(void *userdata, MovieTrackingTrack *track, - int coord, + eClipCurveValueSource value_source, bool is_point) { TrackMotionCurveUserData *data = (TrackMotionCurveUserData *)userdata; + SpaceClip *sc = data->sc; float col[4] = {0.0f, 0.0f, 0.0f, 0.0f}; - col[coord] = 1.0f; + if (!clip_graph_value_visible(sc, value_source)) { + return; + } + + switch (value_source) { + case CLIP_VALUE_SOURCE_SPEED_X: + col[0] = 1.0f; + break; + case CLIP_VALUE_SOURCE_SPEED_Y: + col[1] = 1.0f; + break; + case CLIP_VALUE_SOURCE_REPROJECTION_ERROR: + col[2] = 1.0f; + break; + } if (track == data->act_track) { col[3] = 1.0f; @@ -96,15 +116,20 @@ static void tracking_segment_start_cb(void *userdata, } } -static void tracking_segment_end_cb(void *UNUSED(userdata), int UNUSED(coord)) +static void tracking_segment_end_cb(void *userdata, eClipCurveValueSource value_source) { + TrackMotionCurveUserData *data = (TrackMotionCurveUserData *)userdata; + SpaceClip *sc = data->sc; + if (!clip_graph_value_visible(sc, value_source)) { + return; + } immEnd(); } static void tracking_segment_knot_cb(void *userdata, MovieTrackingTrack *track, MovieTrackingMarker *marker, - int coord, + eClipCurveValueSource value_source, int scene_framenr, float val) { @@ -114,8 +139,11 @@ static void tracking_segment_knot_cb(void *userdata, if (track != data->act_track) { return; } + if (!ELEM(value_source, CLIP_VALUE_SOURCE_SPEED_X, CLIP_VALUE_SOURCE_SPEED_Y)) { + return; + } - sel_flag = coord == 0 ? MARKER_GRAPH_SEL_X : MARKER_GRAPH_SEL_Y; + sel_flag = value_source == CLIP_VALUE_SOURCE_SPEED_X ? MARKER_GRAPH_SEL_X : MARKER_GRAPH_SEL_Y; sel = (marker->flag & sel_flag) ? 1 : 0; if (sel == data->sel) { @@ -131,34 +159,39 @@ static void tracking_segment_knot_cb(void *userdata, } } -static void draw_tracks_motion_curves(View2D *v2d, SpaceClip *sc, unsigned int pos) +static void draw_tracks_motion_and_error_curves(View2D *v2d, SpaceClip *sc, unsigned int pos) { MovieClip *clip = ED_space_clip_get_clip(sc); MovieTracking *tracking = &clip->tracking; MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking); - int width, height; - TrackMotionCurveUserData userdata; + const bool draw_knots = (sc->flag & SC_SHOW_GRAPH_TRACKS_MOTION) != 0; + int width, height; BKE_movieclip_get_size(clip, &sc->user, &width, &height); - if (!width || !height) { return; } - /* non-selected knot handles */ + TrackMotionCurveUserData userdata; + userdata.sc = sc; userdata.hsize = UI_GetThemeValuef(TH_HANDLE_VERTEX_SIZE); userdata.sel = false; userdata.act_track = act_track; userdata.pos = pos; - UI_view2d_scale_get(v2d, &userdata.xscale, &userdata.yscale); - clip_graph_tracking_values_iterate(sc, - (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0, - (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0, - &userdata, - tracking_segment_knot_cb, - NULL, - NULL); - /* draw graph lines */ + + /* Non-selected knot handles. */ + if (draw_knots) { + UI_view2d_scale_get(v2d, &userdata.xscale, &userdata.yscale); + clip_graph_tracking_values_iterate(sc, + (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0, + (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0, + &userdata, + tracking_segment_knot_cb, + NULL, + NULL); + } + + /* Draw graph lines. */ GPU_blend(true); clip_graph_tracking_values_iterate(sc, (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0, @@ -169,138 +202,19 @@ static void draw_tracks_motion_curves(View2D *v2d, SpaceClip *sc, unsigned int p tracking_segment_end_cb); GPU_blend(false); - /* selected knot handles on top of curves */ - userdata.sel = true; - clip_graph_tracking_values_iterate(sc, - (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0, - (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0, - &userdata, - tracking_segment_knot_cb, - NULL, - NULL); -} - -typedef struct TrackErrorCurveUserData { - MovieClip *clip; - MovieTracking *tracking; - MovieTrackingObject *tracking_object; - MovieTrackingTrack *active_track; - bool matrix_initialized; - int matrix_frame; - float projection_matrix[4][4]; - int width, height; - float aspy; - unsigned int pos; -} TrackErrorCurveUserData; - -static void tracking_error_segment_point_cb(void *userdata, - MovieTrackingTrack *track, - MovieTrackingMarker *marker, - int coord, - int scene_framenr, - float UNUSED(value)) -{ - if (coord == 1) { - TrackErrorCurveUserData *data = (TrackErrorCurveUserData *)userdata; - float reprojected_position[4], bundle_position[4], marker_position[2], delta[2]; - float reprojection_error; - float weight = BKE_tracking_track_get_weight_for_marker(data->clip, track, marker); - - if (!data->matrix_initialized || data->matrix_frame != scene_framenr) { - BKE_tracking_get_projection_matrix(data->tracking, - data->tracking_object, - scene_framenr, - data->width, - data->height, - data->projection_matrix); - } - - copy_v3_v3(bundle_position, track->bundle_pos); - bundle_position[3] = 1; - - mul_v4_m4v4(reprojected_position, data->projection_matrix, bundle_position); - reprojected_position[0] = (reprojected_position[0] / (reprojected_position[3] * 2.0f) + 0.5f) * - data->width; - reprojected_position[1] = (reprojected_position[1] / (reprojected_position[3] * 2.0f) + 0.5f) * - data->height * data->aspy; - - BKE_tracking_distort_v2(data->tracking, reprojected_position, reprojected_position); - - marker_position[0] = (marker->pos[0] + track->offset[0]) * data->width; - marker_position[1] = (marker->pos[1] + track->offset[1]) * data->height * data->aspy; - - sub_v2_v2v2(delta, reprojected_position, marker_position); - reprojection_error = len_v2(delta) * weight; - - immVertex2f(data->pos, scene_framenr, reprojection_error); - } -} - -static void tracking_error_segment_start_cb(void *userdata, - MovieTrackingTrack *track, - int coord, - bool is_point) -{ - if (coord == 1) { - TrackErrorCurveUserData *data = (TrackErrorCurveUserData *)userdata; - float col[4] = {0.0f, 0.0f, 1.0f, 1.0f}; - - if (track == data->active_track) { - col[3] = 1.0f; - GPU_line_width(2.0f); - } - else { - col[3] = 0.5f; - GPU_line_width(1.0f); - } - - immUniformColor4fv(col); - - if (is_point) { /* This probably never happens here, but just in case... */ - immBeginAtMost(GPU_PRIM_POINTS, 1); - } - else { - /* Graph can be composed of smaller segments, if any marker is disabled */ - immBeginAtMost(GPU_PRIM_LINE_STRIP, track->markersnr); - } - } -} - -static void tracking_error_segment_end_cb(void *UNUSED(userdata), int coord) -{ - if (coord == 1) { - immEnd(); + /* Selected knot handles on top of curves. */ + if (draw_knots) { + userdata.sel = true; + clip_graph_tracking_values_iterate(sc, + (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0, + (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0, + &userdata, + tracking_segment_knot_cb, + NULL, + NULL); } } -static void draw_tracks_error_curves(SpaceClip *sc, unsigned int pos) -{ - MovieClip *clip = ED_space_clip_get_clip(sc); - MovieTracking *tracking = &clip->tracking; - TrackErrorCurveUserData data; - - data.clip = clip; - data.tracking = tracking; - data.tracking_object = BKE_tracking_object_get_active(tracking); - data.active_track = BKE_tracking_track_get_active(tracking); - data.matrix_initialized = false; - data.pos = pos; - BKE_movieclip_get_size(clip, &sc->user, &data.width, &data.height); - data.aspy = 1.0f / tracking->camera.pixel_aspect; - - if (!data.width || !data.height) { - return; - } - - clip_graph_tracking_values_iterate(sc, - (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0, - (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0, - &data, - tracking_error_segment_point_cb, - tracking_error_segment_start_cb, - tracking_error_segment_end_cb); -} - static void draw_frame_curves(SpaceClip *sc, unsigned int pos) { MovieClip *clip = ED_space_clip_get_clip(sc); @@ -350,12 +264,8 @@ void clip_draw_graph(SpaceClip *sc, ARegion *ar, Scene *scene) GPU_point_size(3.0f); - if (sc->flag & SC_SHOW_GRAPH_TRACKS_MOTION) { - draw_tracks_motion_curves(v2d, sc, pos); - } - - if (sc->flag & SC_SHOW_GRAPH_TRACKS_ERROR) { - draw_tracks_error_curves(sc, pos); + if (sc->flag & (SC_SHOW_GRAPH_TRACKS_MOTION | SC_SHOW_GRAPH_TRACKS_ERROR)) { + draw_tracks_motion_and_error_curves(v2d, sc, pos); } if (sc->flag & SC_SHOW_GRAPH_FRAMES) { diff --git a/source/blender/editors/space_clip/clip_graph_ops.c b/source/blender/editors/space_clip/clip_graph_ops.c index a3722433e33..58a00d2e6b9 100644 --- a/source/blender/editors/space_clip/clip_graph_ops.c +++ b/source/blender/editors/space_clip/clip_graph_ops.c @@ -64,7 +64,7 @@ static bool clip_graph_knots_poll(bContext *C) if (ED_space_clip_graph_poll(C)) { SpaceClip *sc = CTX_wm_space_clip(C); - return (sc->flag & SC_SHOW_GRAPH_TRACKS_MOTION) != 0; + return (sc->flag & (SC_SHOW_GRAPH_TRACKS_MOTION | SC_SHOW_GRAPH_TRACKS_ERROR)) != 0; } return false; } @@ -93,13 +93,14 @@ static void toggle_selection_cb(void *userdata, MovieTrackingMarker *marker) /******************** mouse select operator ********************/ typedef struct { - int coord; /* coordinate index of found entuty (0 = X-axis, 1 = Y-axis) */ + SpaceClip *sc; + eClipCurveValueSource value_source; bool has_prev; /* if there's valid coordinate of previous point of curve segment */ - float min_dist_sq, /* minimal distance between mouse and currently found entity */ - mouse_co[2], /* mouse coordinate */ - prev_co[2], /* coordinate of previeous point of segment */ - min_co[2]; /* coordinate of entity with minimal distance */ + float min_dist_sq; /* minimal distance between mouse and currently found entity */ + float mouse_co[2]; /* mouse coordinate */ + float prev_co[2]; /* coordinate of previous point of segment */ + float min_co[2]; /* coordinate of entity with minimal distance */ MovieTrackingTrack *track; /* nearest found track */ MovieTrackingMarker *marker; /* nearest found marker */ @@ -108,20 +109,24 @@ typedef struct { static void find_nearest_tracking_segment_cb(void *userdata, MovieTrackingTrack *track, MovieTrackingMarker *UNUSED(marker), - int coord, + eClipCurveValueSource value_source, int scene_framenr, float val) { MouseSelectUserData *data = userdata; float co[2] = {scene_framenr, val}; + if (!clip_graph_value_visible(data->sc, value_source)) { + return; + } + if (data->has_prev) { float dist_sq = dist_squared_to_line_segment_v2(data->mouse_co, data->prev_co, co); if (data->track == NULL || dist_sq < data->min_dist_sq) { data->track = track; data->min_dist_sq = dist_sq; - data->coord = coord; + data->value_source = value_source; copy_v2_v2(data->min_co, co); } } @@ -130,7 +135,8 @@ static void find_nearest_tracking_segment_cb(void *userdata, copy_v2_v2(data->prev_co, co); } -static void find_nearest_tracking_segment_end_cb(void *userdata, int UNUSED(coord)) +static void find_nearest_tracking_segment_end_cb(void *userdata, + eClipCurveValueSource UNUSED(source_value)) { MouseSelectUserData *data = userdata; @@ -140,7 +146,7 @@ static void find_nearest_tracking_segment_end_cb(void *userdata, int UNUSED(coor static void find_nearest_tracking_knot_cb(void *userdata, MovieTrackingTrack *track, MovieTrackingMarker *marker, - int coord, + eClipCurveValueSource value_source, int scene_framenr, float val) { @@ -148,20 +154,26 @@ static void find_nearest_tracking_knot_cb(void *userdata, float mdiff[2] = {scene_framenr - data->mouse_co[0], val - data->mouse_co[1]}; float dist_sq = len_squared_v2(mdiff); + if (!clip_graph_value_visible(data->sc, value_source)) { + return; + } + if (data->marker == NULL || dist_sq < data->min_dist_sq) { float co[2] = {scene_framenr, val}; data->track = track; data->marker = marker; data->min_dist_sq = dist_sq; - data->coord = coord; + data->value_source = value_source; copy_v2_v2(data->min_co, co); } } -static void mouse_select_init_data(MouseSelectUserData *userdata, const float co[2]) +static void mouse_select_init_data(bContext *C, MouseSelectUserData *userdata, const float co[2]) { + SpaceClip *sc = CTX_wm_space_clip(C); memset(userdata, 0, sizeof(MouseSelectUserData)); + userdata->sc = sc; userdata->min_dist_sq = FLT_MAX; copy_v2_v2(userdata->mouse_co, co); } @@ -179,7 +191,7 @@ static bool mouse_select_knot(bContext *C, float co[2], bool extend) if (act_track) { MouseSelectUserData userdata; - mouse_select_init_data(&userdata, co); + mouse_select_init_data(C, &userdata, co); clip_graph_tracking_values_iterate_track( sc, act_track, &userdata, find_nearest_tracking_knot_cb, NULL, NULL); @@ -199,7 +211,7 @@ static bool mouse_select_knot(bContext *C, float co[2], bool extend) toggle_selection_cb); } - if (userdata.coord == 0) { + if (userdata.value_source == CLIP_VALUE_SOURCE_SPEED_X) { if (extend && (userdata.marker->flag & MARKER_GRAPH_SEL_X) != 0) { userdata.marker->flag &= ~MARKER_GRAPH_SEL_X; } @@ -207,7 +219,7 @@ static bool mouse_select_knot(bContext *C, float co[2], bool extend) userdata.marker->flag |= MARKER_GRAPH_SEL_X; } } - else { + else if (userdata.value_source == CLIP_VALUE_SOURCE_SPEED_Y) { if (extend && (userdata.marker->flag & MARKER_GRAPH_SEL_Y) != 0) { userdata.marker->flag &= ~MARKER_GRAPH_SEL_Y; } @@ -232,7 +244,7 @@ static bool mouse_select_curve(bContext *C, float co[2], bool extend) MovieTrackingTrack *act_track = BKE_tracking_track_get_active(tracking); MouseSelectUserData userdata; - mouse_select_init_data(&userdata, co); + mouse_select_init_data(C, &userdata, co); clip_graph_tracking_values_iterate(sc, (sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0, (sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0, @@ -281,7 +293,7 @@ static int mouse_select(bContext *C, float co[2], bool extend) sel = mouse_select_knot(C, co, extend); if (!sel) { - /* if there's no close enough knot to mouse osition, select nearest curve */ + /* if there's no close enough knot to mouse position, select nearest curve */ sel = mouse_select_curve(C, co, extend); } @@ -356,16 +368,19 @@ typedef struct BoxSelectuserData { static void box_select_cb(void *userdata, MovieTrackingTrack *UNUSED(track), MovieTrackingMarker *marker, - int coord, + eClipCurveValueSource value_source, int scene_framenr, float val) { BoxSelectuserData *data = (BoxSelectuserData *)userdata; + if (!ELEM(value_source, CLIP_VALUE_SOURCE_SPEED_X, CLIP_VALUE_SOURCE_SPEED_Y)) { + return; + } if (BLI_rctf_isect_pt(&data->rect, scene_framenr, val)) { int flag = 0; - if (coord == 0) { + if (value_source == CLIP_VALUE_SOURCE_SPEED_X) { flag = MARKER_GRAPH_SEL_X; } else { @@ -591,7 +606,7 @@ typedef struct { static void view_all_cb(void *userdata, MovieTrackingTrack *UNUSED(track), MovieTrackingMarker *UNUSED(marker), - int UNUSED(coord), + eClipCurveValueSource UNUSED(value_source), int UNUSED(scene_framenr), float val) { diff --git a/source/blender/editors/space_clip/clip_intern.h b/source/blender/editors/space_clip/clip_intern.h index 7683823a79f..8599de9f16f 100644 --- a/source/blender/editors/space_clip/clip_intern.h +++ b/source/blender/editors/space_clip/clip_intern.h @@ -112,35 +112,44 @@ void CLIP_OT_cursor_set(struct wmOperatorType *ot); struct ARegion *ED_clip_has_properties_region(struct ScrArea *sa); /* clip_utils.c */ -void clip_graph_tracking_values_iterate_track( - struct SpaceClip *sc, - struct MovieTrackingTrack *track, - void *userdata, - void (*func)(void *userdata, - struct MovieTrackingTrack *track, - struct MovieTrackingMarker *marker, - int coord, - int scene_framenr, - float val), - void (*segment_start)( - void *userdata, struct MovieTrackingTrack *track, int coord, bool is_point), - void (*segment_end)(void *userdata, int coord)); + +typedef enum { + CLIP_VALUE_SOURCE_SPEED_X, + CLIP_VALUE_SOURCE_SPEED_Y, + CLIP_VALUE_SOURCE_REPROJECTION_ERROR, +} eClipCurveValueSource; + +typedef void (*ClipTrackValueCallback)(void *userdata, + struct MovieTrackingTrack *track, + struct MovieTrackingMarker *marker, + eClipCurveValueSource value_source, + int scene_framenr, + float val); + +typedef void (*ClipTrackValueSegmentStartCallback)(void *userdata, + struct MovieTrackingTrack *track, + eClipCurveValueSource value_source, + bool is_point); + +typedef void (*ClipTrackValueSegmentEndCallback)(void *userdata, + eClipCurveValueSource value_source); + +bool clip_graph_value_visible(struct SpaceClip *sc, eClipCurveValueSource value_source); + +void clip_graph_tracking_values_iterate_track(struct SpaceClip *sc, + struct MovieTrackingTrack *track, + void *userdata, + ClipTrackValueCallback func, + ClipTrackValueSegmentStartCallback segment_start, + ClipTrackValueSegmentEndCallback segment_end); void clip_graph_tracking_values_iterate(struct SpaceClip *sc, bool selected_only, bool include_hidden, void *userdata, - void (*func)(void *userdata, - struct MovieTrackingTrack *track, - struct MovieTrackingMarker *marker, - int coord, - int scene_framenr, - float val), - void (*segment_start)(void *userdata, - struct MovieTrackingTrack *track, - int coord, - bool is_point), - void (*segment_end)(void *userdata, int coord)); + ClipTrackValueCallback func, + ClipTrackValueSegmentStartCallback segment_start, + ClipTrackValueSegmentEndCallback segment_end); void clip_graph_tracking_iterate(struct SpaceClip *sc, bool selected_only, diff --git a/source/blender/editors/space_clip/clip_ops.c b/source/blender/editors/space_clip/clip_ops.c index 45479c4253d..5f04d0863a7 100644 --- a/source/blender/editors/space_clip/clip_ops.c +++ b/source/blender/editors/space_clip/clip_ops.c @@ -626,36 +626,35 @@ static void view_zoom_apply( bContext *C, ViewZoomData *vpd, wmOperator *op, const wmEvent *event, const bool zoom_to_pos) { float factor; + float delta; - if (U.viewzoom == USER_ZOOM_CONT) { - SpaceClip *sclip = CTX_wm_space_clip(C); - double time = PIL_check_seconds_timer(); - float time_step = (float)(time - vpd->timer_lastdraw); - float fac; - float zfac; - + if (U.viewzoom != USER_ZOOM_SCALE) { if (U.uiflag & USER_ZOOM_HORIZ) { - fac = (float)(event->x - vpd->x); + delta = (float)(event->x - vpd->x); } else { - fac = (float)(event->y - vpd->y); + delta = (float)(event->y - vpd->y); } + } + else { + delta = event->x - vpd->x + event->y - vpd->y; + } - if (U.uiflag & USER_ZOOM_INVERT) { - fac = -fac; - } + if (U.uiflag & USER_ZOOM_INVERT) { + delta = -delta; + } - zfac = 1.0f + ((fac / 20.0f) * time_step); + if (U.viewzoom == USER_ZOOM_CONT) { + SpaceClip *sclip = CTX_wm_space_clip(C); + double time = PIL_check_seconds_timer(); + float time_step = (float)(time - vpd->timer_lastdraw); + float zfac; + + zfac = 1.0f + ((delta / 20.0f) * time_step); vpd->timer_lastdraw = time; factor = (sclip->zoom * zfac) / vpd->zoom; } else { - float delta = event->x - vpd->x + event->y - vpd->y; - - if (U.uiflag & USER_ZOOM_INVERT) { - delta *= -1; - } - factor = 1.0f + delta / 300.0f; } @@ -1434,7 +1433,7 @@ static void proxy_endjob(void *pjv) if (pj->clip->source == MCLIP_SRC_MOVIE) { /* Timecode might have changed, so do a full reload to deal with this. */ - BKE_movieclip_reload(pj->main, pj->clip); + DEG_id_tag_update(&pj->clip->id, ID_RECALC_SOURCE); } else { /* For image sequences we'll preserve original cache. */ diff --git a/source/blender/editors/space_clip/clip_utils.c b/source/blender/editors/space_clip/clip_utils.c index 3dfe529f8e8..48f788e2e3a 100644 --- a/source/blender/editors/space_clip/clip_utils.c +++ b/source/blender/editors/space_clip/clip_utils.c @@ -27,6 +27,7 @@ #include "BLI_utildefines.h" #include "BLI_listbase.h" +#include "BLI_math.h" #include "BKE_animsys.h" #include "BKE_context.h" @@ -52,18 +53,28 @@ #include "clip_intern.h" // own include -void clip_graph_tracking_values_iterate_track( +bool clip_graph_value_visible(SpaceClip *sc, eClipCurveValueSource value_source) +{ + if (ELEM(value_source, CLIP_VALUE_SOURCE_SPEED_X, CLIP_VALUE_SOURCE_SPEED_Y)) { + if ((sc->flag & SC_SHOW_GRAPH_TRACKS_MOTION) == 0) { + return false; + } + } + else if (value_source == CLIP_VALUE_SOURCE_REPROJECTION_ERROR) { + if ((sc->flag & SC_SHOW_GRAPH_TRACKS_ERROR) == 0) { + return false; + } + } + return true; +} + +static void clip_graph_tracking_values_iterate_track_speed_values( SpaceClip *sc, MovieTrackingTrack *track, void *userdata, - void (*func)(void *userdata, - MovieTrackingTrack *track, - MovieTrackingMarker *marker, - int coord, - int scene_framenr, - float val), - void (*segment_start)(void *userdata, MovieTrackingTrack *track, int coord, bool is_point), - void (*segment_end)(void *userdata, int coord)) + ClipTrackValueCallback func, + ClipTrackValueSegmentStartCallback segment_start, + ClipTrackValueSegmentEndCallback segment_end) { MovieClip *clip = ED_space_clip_get_clip(sc); int width, height, coord; @@ -71,6 +82,8 @@ void clip_graph_tracking_values_iterate_track( BKE_movieclip_get_size(clip, &sc->user, &width, &height); for (coord = 0; coord < 2; coord++) { + eClipCurveValueSource value_source = (coord == 0) ? CLIP_VALUE_SOURCE_SPEED_X : + CLIP_VALUE_SOURCE_SPEED_Y; int i, prevfra = track->markers[0].framenr; bool open = false; float prevval = 0.0f; @@ -82,7 +95,7 @@ void clip_graph_tracking_values_iterate_track( if (marker->flag & MARKER_DISABLED) { if (open) { if (segment_end) { - segment_end(userdata, coord); + segment_end(userdata, value_source); } open = false; @@ -94,10 +107,11 @@ void clip_graph_tracking_values_iterate_track( if (!open) { if (segment_start) { if ((i + 1) == track->markersnr) { - segment_start(userdata, track, coord, true); + segment_start(userdata, track, value_source, true); } else { - segment_start(userdata, track, coord, (track->markers[i + 1].flag & MARKER_DISABLED)); + segment_start( + userdata, track, value_source, (track->markers[i + 1].flag & MARKER_DISABLED)); } } @@ -112,7 +126,7 @@ void clip_graph_tracking_values_iterate_track( if (func) { int scene_framenr = BKE_movieclip_remap_clip_to_scene_frame(clip, marker->framenr); - func(userdata, track, marker, coord, scene_framenr, val); + func(userdata, track, marker, value_source, scene_framenr, val); } prevval = marker->pos[coord]; @@ -121,25 +135,139 @@ void clip_graph_tracking_values_iterate_track( if (open) { if (segment_end) { - segment_end(userdata, coord); + segment_end(userdata, value_source); } } } } -void clip_graph_tracking_values_iterate( +static float calculate_reprojection_error_at_marker(MovieClip *clip, + MovieTracking *tracking, + MovieTrackingObject *tracking_object, + MovieTrackingTrack *track, + MovieTrackingMarker *marker, + const int clip_width, + const int clip_height, + const int scene_framenr) +{ + float reprojected_position[4], bundle_position[4], marker_position[2], delta[2]; + float weight = BKE_tracking_track_get_weight_for_marker(clip, track, marker); + const float aspy = 1.0f / tracking->camera.pixel_aspect; + + float projection_matrix[4][4]; + BKE_tracking_get_projection_matrix( + tracking, tracking_object, scene_framenr, clip_width, clip_height, projection_matrix); + + copy_v3_v3(bundle_position, track->bundle_pos); + bundle_position[3] = 1; + + mul_v4_m4v4(reprojected_position, projection_matrix, bundle_position); + reprojected_position[0] = (reprojected_position[0] / (reprojected_position[3] * 2.0f) + 0.5f) * + clip_width; + reprojected_position[1] = (reprojected_position[1] / (reprojected_position[3] * 2.0f) + 0.5f) * + clip_height * aspy; + + BKE_tracking_distort_v2(tracking, reprojected_position, reprojected_position); + + marker_position[0] = (marker->pos[0] + track->offset[0]) * clip_width; + marker_position[1] = (marker->pos[1] + track->offset[1]) * clip_height * aspy; + + sub_v2_v2v2(delta, reprojected_position, marker_position); + return len_v2(delta) * weight; +} + +static void clip_graph_tracking_values_iterate_track_reprojection_error_values( SpaceClip *sc, - bool selected_only, - bool include_hidden, + MovieTrackingTrack *track, void *userdata, - void (*func)(void *userdata, - MovieTrackingTrack *track, - MovieTrackingMarker *marker, - int coord, - int scene_framenr, - float val), - void (*segment_start)(void *userdata, MovieTrackingTrack *track, int coord, bool is_point), - void (*segment_end)(void *userdata, int coord)) + ClipTrackValueCallback func, + ClipTrackValueSegmentStartCallback segment_start, + ClipTrackValueSegmentEndCallback segment_end) +{ + /* Tracks without bundle can not have any reprojection error curve. */ + if ((track->flag & TRACK_HAS_BUNDLE) == 0) { + return; + } + + MovieClip *clip = ED_space_clip_get_clip(sc); + MovieTracking *tracking = &clip->tracking; + MovieTrackingObject *tracking_object = BKE_tracking_object_get_active(tracking); + + int clip_width, clip_height; + BKE_movieclip_get_size(clip, &sc->user, &clip_width, &clip_height); + + /* Iterate over segments. */ + bool is_segment_open = false; + for (int marker_index = 0; marker_index < track->markersnr; marker_index++) { + MovieTrackingMarker *marker = &track->markers[marker_index]; + + /* End of tracked segment, no reprojection error can be calculated here since the ground truth + * 2D position is not known. */ + if (marker->flag & MARKER_DISABLED) { + if (is_segment_open) { + if (segment_end != NULL) { + segment_end(userdata, CLIP_VALUE_SOURCE_REPROJECTION_ERROR); + } + is_segment_open = false; + } + continue; + } + + /* Begin new segment if it is not open yet. */ + if (!is_segment_open) { + if (segment_start != NULL) { + if ((marker_index + 1) == track->markersnr) { + segment_start(userdata, track, CLIP_VALUE_SOURCE_REPROJECTION_ERROR, true); + } + else { + segment_start(userdata, + track, + CLIP_VALUE_SOURCE_REPROJECTION_ERROR, + (track->markers[marker_index + 1].flag & MARKER_DISABLED)); + } + } + is_segment_open = true; + } + + if (func != NULL) { + const int scene_framenr = BKE_movieclip_remap_clip_to_scene_frame(clip, marker->framenr); + const float reprojection_error = calculate_reprojection_error_at_marker( + clip, tracking, tracking_object, track, marker, clip_width, clip_height, scene_framenr); + func(userdata, + track, + marker, + CLIP_VALUE_SOURCE_REPROJECTION_ERROR, + scene_framenr, + reprojection_error); + } + } + + if (is_segment_open && segment_end != NULL) { + segment_end(userdata, CLIP_VALUE_SOURCE_REPROJECTION_ERROR); + } +} + +void clip_graph_tracking_values_iterate_track(SpaceClip *sc, + MovieTrackingTrack *track, + void *userdata, + ClipTrackValueCallback func, + ClipTrackValueSegmentStartCallback segment_start, + ClipTrackValueSegmentEndCallback segment_end) +{ + clip_graph_tracking_values_iterate_track_speed_values( + sc, track, userdata, func, segment_start, segment_end); + + clip_graph_tracking_values_iterate_track_reprojection_error_values( + sc, track, userdata, func, segment_start, segment_end); +} + +void clip_graph_tracking_values_iterate(SpaceClip *sc, + bool selected_only, + bool include_hidden, + void *userdata, + ClipTrackValueCallback func, + ClipTrackValueSegmentStartCallback segment_start, + ClipTrackValueSegmentEndCallback segment_end) { MovieClip *clip = ED_space_clip_get_clip(sc); MovieTracking *tracking = &clip->tracking; diff --git a/source/blender/editors/space_clip/space_clip.c b/source/blender/editors/space_clip/space_clip.c index 7e19ac255f0..c1cb975447f 100644 --- a/source/blender/editors/space_clip/space_clip.c +++ b/source/blender/editors/space_clip/space_clip.c @@ -556,17 +556,17 @@ static void clip_operatortypes(void) static void clip_keymap(struct wmKeyConfig *keyconf) { - /* ******** Global hotkeys avalaible for all regions ******** */ + /* ******** Global hotkeys available for all regions ******** */ WM_keymap_ensure(keyconf, "Clip", SPACE_CLIP, 0); - /* ******** Hotkeys avalaible for main region only ******** */ + /* ******** Hotkeys available for main region only ******** */ WM_keymap_ensure(keyconf, "Clip Editor", SPACE_CLIP, 0); // keymap->poll = ED_space_clip_tracking_poll; - /* ******** Hotkeys avalaible for preview region only ******** */ + /* ******** Hotkeys available for preview region only ******** */ WM_keymap_ensure(keyconf, "Clip Graph Editor", SPACE_CLIP, 0); - /* ******** Hotkeys avalaible for channels region only ******** */ + /* ******** Hotkeys available for channels region only ******** */ WM_keymap_ensure(keyconf, "Clip Dopesheet Editor", SPACE_CLIP, 0); } @@ -947,7 +947,7 @@ static void clip_main_region_draw(const bContext *C, ARegion *ar) ScrArea *sa = CTX_wm_area(C); int mask_width, mask_height; ED_mask_get_size(sa, &mask_width, &mask_height); - ED_mask_draw_region(CTX_data_depsgraph(C), + ED_mask_draw_region(CTX_data_expect_evaluated_depsgraph(C), mask, ar, sc->mask_info.draw_flag, @@ -1224,7 +1224,7 @@ static void clip_header_region_listener(wmWindow *UNUSED(win), switch (wmn->data) { /* for proportional editmode only */ case ND_TOOLSETTINGS: - /* TODO - should do this when in mask mode only but no datas available */ + /* TODO - should do this when in mask mode only but no data available */ // if (sc->mode == SC_MODE_MASKEDIT) { ED_region_tag_redraw(ar); diff --git a/source/blender/editors/space_clip/tracking_ops.c b/source/blender/editors/space_clip/tracking_ops.c index d8d50ba72b5..1375b99bdaa 100644 --- a/source/blender/editors/space_clip/tracking_ops.c +++ b/source/blender/editors/space_clip/tracking_ops.c @@ -1894,6 +1894,7 @@ static int tracking_object_new_exec(bContext *C, wmOperator *UNUSED(op)) BKE_tracking_object_add(tracking, "Object"); + DEG_id_tag_update(&clip->id, ID_RECALC_COPY_ON_WRITE); WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip); return OPERATOR_FINISHED; @@ -1932,6 +1933,7 @@ static int tracking_object_remove_exec(bContext *C, wmOperator *op) BKE_tracking_object_delete(tracking, object); + DEG_id_tag_update(&clip->id, ID_RECALC_COPY_ON_WRITE); WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip); return OPERATOR_FINISHED; diff --git a/source/blender/editors/space_clip/tracking_ops_orient.c b/source/blender/editors/space_clip/tracking_ops_orient.c index 61991993b10..de0025a53d2 100644 --- a/source/blender/editors/space_clip/tracking_ops_orient.c +++ b/source/blender/editors/space_clip/tracking_ops_orient.c @@ -39,6 +39,7 @@ #include "BKE_report.h" #include "DEG_depsgraph.h" +#include "DEG_depsgraph_query.h" #include "WM_api.h" #include "WM_types.h" @@ -395,7 +396,6 @@ static int set_plane_exec(bContext *C, wmOperator *op) ListBase *tracksbase; Object *object; Object *camera = get_camera_with_movieclip(scene, clip); - Depsgraph *depsgraph = CTX_data_depsgraph(C); int tot = 0; float vec[3][3], mat[4][4], obmat[4][4], newmat[4][4], orig[3] = {0.0f, 0.0f, 0.0f}; int plane = RNA_enum_get(op->ptr, "plane"); @@ -484,7 +484,13 @@ static int set_plane_exec(bContext *C, wmOperator *op) BKE_object_apply_mat4(object, mat, 0, 0); } - BKE_object_where_is_calc(depsgraph, scene, object); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); + Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); + Object *object_eval = DEG_get_evaluated_object(depsgraph, object); + BKE_object_transform_copy(object_eval, object); + BKE_object_where_is_calc(depsgraph, scene_eval, object_eval); + BKE_object_transform_copy(object, object_eval); + set_axis(scene, object, clip, tracking_object, axis_track, 'X'); DEG_id_tag_update(&clip->id, 0); diff --git a/source/blender/editors/space_clip/tracking_ops_solve.c b/source/blender/editors/space_clip/tracking_ops_solve.c index 4490655393e..806df4dbaff 100644 --- a/source/blender/editors/space_clip/tracking_ops_solve.c +++ b/source/blender/editors/space_clip/tracking_ops_solve.c @@ -122,8 +122,14 @@ static void solve_camera_freejob(void *scv) solved = BKE_tracking_reconstruction_finish(scj->context, tracking); if (!solved) { - BKE_report( - scj->reports, RPT_WARNING, "Some data failed to reconstruct (see console for details)"); + const char *error_message = BKE_tracking_reconstruction_error_message_get(scj->context); + if (error_message[0]) { + BKE_report(scj->reports, RPT_ERROR, error_message); + } + else { + BKE_report( + scj->reports, RPT_WARNING, "Some data failed to reconstruct (see console for details)"); + } } else { BKE_reportf(scj->reports, @@ -146,6 +152,7 @@ static void solve_camera_freejob(void *scv) int width, height; BKE_movieclip_get_size(clip, &scj->user, &width, &height); BKE_tracking_camera_to_blender(tracking, scene, camera, width, height); + DEG_id_tag_update(&camera->id, ID_RECALC_COPY_ON_WRITE); WM_main_add_notifier(NC_OBJECT, camera); } diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c index 9bdea13276b..3a6d59c1dbf 100644 --- a/source/blender/editors/space_file/file_draw.c +++ b/source/blender/editors/space_file/file_draw.c @@ -536,7 +536,7 @@ static void renamebutton_cb(bContext *C, void *UNUSED(arg1), char *oldname) WM_report_banner_show(); } else { - /* If rename is sucessfull, scroll to newly renamed entry. */ + /* If rename is successful, scroll to newly renamed entry. */ BLI_strncpy(sfile->params->renamefile, filename, sizeof(sfile->params->renamefile)); sfile->params->rename_flag = FILE_PARAMS_RENAME_POSTSCROLL_PENDING; diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index 4e50413513a..eb5f02b6e13 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -1757,7 +1757,7 @@ static int file_smoothscroll_invoke(bContext *C, wmOperator *UNUSED(op), const w (middle_offset - min_middle_offset < items_block_size)); /* OR edited item must be towards the end, and we are scrolled fully to the end. * This one is crucial (unlike the one for the beginning), because without it we won't scroll - * fully to the end, and last column or row wil end up only partially drawn. */ + * fully to the end, and last column or row will end up only partially drawn. */ const bool is_full_end = ((sfile->scroll_offset > max_middle_offset) && (max_tot_scroll - max_curr_scroll < 1.0f) && (max_middle_offset - middle_offset < items_block_size)); diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c index 9004eaa7bf6..e06ee620ea7 100644 --- a/source/blender/editors/space_file/filelist.c +++ b/source/blender/editors/space_file/filelist.c @@ -1317,6 +1317,9 @@ static void filelist_cache_init(FileListEntryCache *cache, size_t cache_size) cache->size = cache_size; cache->flags = FLC_IS_INIT; + + /* We cannot translate from non-main thread, so init translated strings once from here. */ + IMB_thumb_ensure_translations(); } static void filelist_cache_free(FileListEntryCache *cache) diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c index faaecd975a3..db42d007b8e 100644 --- a/source/blender/editors/space_file/filesel.c +++ b/source/blender/editors/space_file/filesel.c @@ -28,7 +28,7 @@ #include <sys/stat.h> #include <sys/types.h> -/* path/file handeling stuff */ +/* path/file handling stuff */ #ifdef WIN32 # include <io.h> # include <direct.h> diff --git a/source/blender/editors/space_graph/graph_draw.c b/source/blender/editors/space_graph/graph_draw.c index b16374e0d66..e7ba498fc11 100644 --- a/source/blender/editors/space_graph/graph_draw.c +++ b/source/blender/editors/space_graph/graph_draw.c @@ -721,7 +721,7 @@ static void draw_fcurve_curve_bezts( v1[1] = prevbezt->vec[1][1]; } else if (prevbezt->ipo == BEZT_IPO_LIN) { - /* extrapolate linear dosnt use the handle, use the next points center instead */ + /* extrapolate linear doesn't use the handle, use the next points center instead */ fac = (prevbezt->vec[1][0] - bezt->vec[1][0]) / (prevbezt->vec[1][0] - v1[0]); if (fac) { fac = 1.0f / fac; @@ -840,7 +840,7 @@ static void draw_fcurve_curve_bezts( v1[1] = prevbezt->vec[1][1]; } else if (prevbezt->ipo == BEZT_IPO_LIN) { - /* extrapolate linear dosnt use the handle, use the previous points center instead */ + /* extrapolate linear doesn't use the handle, use the previous points center instead */ bezt = prevbezt - 1; fac = (prevbezt->vec[1][0] - bezt->vec[1][0]) / (prevbezt->vec[1][0] - v1[0]); if (fac) { diff --git a/source/blender/editors/space_graph/graph_edit.c b/source/blender/editors/space_graph/graph_edit.c index dc5837e3fd1..b624e21937f 100644 --- a/source/blender/editors/space_graph/graph_edit.c +++ b/source/blender/editors/space_graph/graph_edit.c @@ -604,7 +604,6 @@ static void insert_graph_keys(bAnimContext *ac, eGraphKeys_InsertKey_Types mode) ReportList *reports = ac->reports; SpaceGraph *sipo = (SpaceGraph *)ac->sl; - struct Depsgraph *depsgraph = ac->depsgraph; Scene *scene = ac->scene; ToolSettings *ts = scene->toolsettings; short flag = 0; @@ -696,7 +695,6 @@ static void insert_graph_keys(bAnimContext *ac, eGraphKeys_InsertKey_Types mode) */ if (ale->id && !ale->owner && !fcu->driver) { insert_keyframe(ac->bmain, - depsgraph, reports, ale->id, NULL, diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c index b79ed1c83c4..374a58d1808 100644 --- a/source/blender/editors/space_image/image_ops.c +++ b/source/blender/editors/space_image/image_ops.c @@ -556,39 +556,36 @@ static void image_zoom_apply(ViewZoomData *vpd, const bool zoom_to_pos) { float factor; + float delta; - if (viewzoom == USER_ZOOM_CONT) { - double time = PIL_check_seconds_timer(); - float time_step = (float)(time - vpd->timer_lastdraw); - float fac; - float zfac; - + if (viewzoom != USER_ZOOM_SCALE) { if (U.uiflag & USER_ZOOM_HORIZ) { - fac = (float)(x - vpd->origx); + delta = (float)(x - vpd->origx); } else { - fac = (float)(y - vpd->origy); + delta = (float)(y - vpd->origy); } + } + else { + delta = x - vpd->origx + y - vpd->origy; + } - if (zoom_invert) { - fac = -fac; - } + if (zoom_invert) { + delta = -delta; + } + + if (viewzoom == USER_ZOOM_CONT) { + double time = PIL_check_seconds_timer(); + float time_step = (float)(time - vpd->timer_lastdraw); + float zfac; /* oldstyle zoom */ - zfac = 1.0f + ((fac / 20.0f) * time_step); + zfac = 1.0f + ((delta / 20.0f) * time_step); vpd->timer_lastdraw = time; /* this is the final zoom, but instead make it into a factor */ - // zoom = vpd->sima->zoom * zfac; factor = (vpd->sima->zoom * zfac) / vpd->zoom; } else { - /* for now do the same things for scale and dolly */ - float delta = x - vpd->origx + y - vpd->origy; - - if (zoom_invert) { - delta *= -1.0f; - } - factor = 1.0f + delta / 300.0f; } diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c index e8116193c1f..7ff075bf819 100644 --- a/source/blender/editors/space_image/space_image.c +++ b/source/blender/editors/space_image/space_image.c @@ -576,7 +576,7 @@ static void image_main_region_draw(const bContext *C, ARegion *ar) SpaceImage *sima = CTX_wm_space_image(C); Object *obact = CTX_data_active_object(C); Object *obedit = CTX_data_edit_object(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_expect_evaluated_depsgraph(C); Mask *mask = NULL; bool show_uvedit = false; bool show_curve = false; diff --git a/source/blender/editors/space_info/info_stats.c b/source/blender/editors/space_info/info_stats.c index 1c9a7d3584c..946274de882 100644 --- a/source/blender/editors/space_info/info_stats.c +++ b/source/blender/editors/space_info/info_stats.c @@ -158,7 +158,7 @@ static void stats_object(Object *ob, SceneStats *stats, GSet *objects_gset) if (stats_mesheval(me_eval, is_selected, stats)) { break; } - ATTR_FALLTHROUGH; /* Falltrough to displist. */ + ATTR_FALLTHROUGH; /* Fallthrough to displist. */ } case OB_MBALL: { int totv = 0, totf = 0, tottri = 0; diff --git a/source/blender/editors/space_node/node_ops.c b/source/blender/editors/space_node/node_ops.c index 0836617ab44..11933ef0811 100644 --- a/source/blender/editors/space_node/node_ops.c +++ b/source/blender/editors/space_node/node_ops.c @@ -143,7 +143,6 @@ void ED_operatormacros_node(void) "Move nodes and attach to frame", OPTYPE_UNDO | OPTYPE_REGISTER); mot = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); - RNA_boolean_set(mot->ptr, "release_confirm", true); WM_operatortype_macro_define(ot, "NODE_OT_attach"); WM_operatortype_macro_define(ot, "NODE_OT_insert_offset"); @@ -153,7 +152,6 @@ void ED_operatormacros_node(void) "Move nodes and attach to frame", OPTYPE_UNDO | OPTYPE_REGISTER); mot = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); - RNA_boolean_set(mot->ptr, "release_confirm", true); RNA_boolean_set(mot->ptr, "remove_on_cancel", true); WM_operatortype_macro_define(ot, "NODE_OT_attach"); WM_operatortype_macro_define(ot, "NODE_OT_insert_offset"); @@ -168,7 +166,6 @@ void ED_operatormacros_node(void) OPTYPE_UNDO | OPTYPE_REGISTER); WM_operatortype_macro_define(ot, "NODE_OT_detach"); mot = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate"); - RNA_boolean_set(mot->ptr, "release_confirm", true); WM_operatortype_macro_define(ot, "NODE_OT_attach"); ot = WM_operatortype_append_macro("NODE_OT_duplicate_move", diff --git a/source/blender/editors/space_outliner/outliner_select.c b/source/blender/editors/space_outliner/outliner_select.c index bee615108f9..c932766ab93 100644 --- a/source/blender/editors/space_outliner/outliner_select.c +++ b/source/blender/editors/space_outliner/outliner_select.c @@ -113,7 +113,7 @@ static void do_outliner_activate_obdata( bContext *C, Scene *scene, ViewLayer *view_layer, Base *base, const bool extend) { Main *bmain = CTX_data_main(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Object *obact = OBACT(view_layer); Object *ob = base->object; bool use_all = false; @@ -161,7 +161,7 @@ static void do_outliner_activate_pose( bContext *C, Scene *scene, ViewLayer *view_layer, Base *base, const bool extend) { Main *bmain = CTX_data_main(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Object *obact = OBACT(view_layer); Object *ob = base->object; bool use_all = false; @@ -341,7 +341,7 @@ static eOLDrawState tree_element_set_active_object(bContext *C, if (base && !BKE_object_is_mode_compat(base->object, object_mode)) { if (object_mode == OB_MODE_OBJECT) { struct Main *bmain = CTX_data_main(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); ED_object_mode_generic_exit(bmain, depsgraph, scene, base->object); } if (!BKE_object_is_mode_compat(base->object, object_mode)) { diff --git a/source/blender/editors/space_outliner/outliner_tools.c b/source/blender/editors/space_outliner/outliner_tools.c index 89eb3b9d953..f9905cc4fcd 100644 --- a/source/blender/editors/space_outliner/outliner_tools.c +++ b/source/blender/editors/space_outliner/outliner_tools.c @@ -747,6 +747,7 @@ static void clear_animdata_cb(int UNUSED(event), void *UNUSED(arg)) { BKE_animdata_free(tselem->id, true); + DEG_id_tag_update(tselem->id, ID_RECALC_ANIMATION); } static void unlinkact_animdata_cb(int UNUSED(event), @@ -756,6 +757,7 @@ static void unlinkact_animdata_cb(int UNUSED(event), { /* just set action to NULL */ BKE_animdata_set_action(NULL, tselem->id, NULL); + DEG_id_tag_update(tselem->id, ID_RECALC_ANIMATION); } static void cleardrivers_animdata_cb(int UNUSED(event), @@ -767,6 +769,7 @@ static void cleardrivers_animdata_cb(int UNUSED(event), /* just free drivers - stored as a list of F-Curves */ free_fcurves(&iat->adt->drivers); + DEG_id_tag_update(tselem->id, ID_RECALC_ANIMATION); } static void refreshdrivers_animdata_cb(int UNUSED(event), @@ -1899,7 +1902,6 @@ static int outliner_animdata_operation_exec(bContext *C, wmOperator *op) SpaceOutliner *soops = CTX_wm_space_outliner(C); int scenelevel = 0, objectlevel = 0, idlevel = 0, datalevel = 0; eOutliner_AnimDataOps event; - short updateDeps = 0; /* check for invalid states */ if (soops == NULL) { @@ -1943,7 +1945,6 @@ static int outliner_animdata_operation_exec(bContext *C, wmOperator *op) WM_event_add_notifier(C, NC_ANIMATION | ND_ANIMCHAN, NULL); // ED_undo_push(C, "Refresh Drivers"); /* no undo needed - shouldn't have any impact? */ - updateDeps = 1; break; case OUTLINER_ANIMOP_CLEAR_DRV: @@ -1952,7 +1953,6 @@ static int outliner_animdata_operation_exec(bContext *C, wmOperator *op) WM_event_add_notifier(C, NC_ANIMATION | ND_ANIMCHAN, NULL); ED_undo_push(C, "Clear Drivers"); - updateDeps = 1; break; default: // invalid @@ -1960,10 +1960,7 @@ static int outliner_animdata_operation_exec(bContext *C, wmOperator *op) } /* update dependencies */ - if (updateDeps) { - /* rebuild depsgraph for the new deps */ - DEG_relations_tag_update(CTX_data_main(C)); - } + DEG_relations_tag_update(CTX_data_main(C)); return OPERATOR_FINISHED; } diff --git a/source/blender/editors/space_sequencer/sequencer_buttons.c b/source/blender/editors/space_sequencer/sequencer_buttons.c index a6458ee5d31..6740c2baad2 100644 --- a/source/blender/editors/space_sequencer/sequencer_buttons.c +++ b/source/blender/editors/space_sequencer/sequencer_buttons.c @@ -76,7 +76,7 @@ static void metadata_panel_context_draw(const bContext *C, Panel *panel) return; } struct Main *bmain = CTX_data_main(C); - struct Depsgraph *depsgraph = CTX_data_depsgraph(C); + struct Depsgraph *depsgraph = CTX_data_expect_evaluated_depsgraph(C); struct Scene *scene = CTX_data_scene(C); SpaceSeq *space_sequencer = CTX_wm_space_seq(C); /* NOTE: We can only reliably show metadata for the original (current) diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c index 76c198b3d6b..ea815bd5456 100644 --- a/source/blender/editors/space_sequencer/sequencer_draw.c +++ b/source/blender/editors/space_sequencer/sequencer_draw.c @@ -1546,7 +1546,7 @@ void sequencer_draw_preview(const bContext *C, bool draw_backdrop) { struct Main *bmain = CTX_data_main(C); - struct Depsgraph *depsgraph = CTX_data_depsgraph(C); + struct Depsgraph *depsgraph = CTX_data_expect_evaluated_depsgraph(C); struct View2D *v2d = &ar->v2d; struct ImBuf *ibuf = NULL; struct ImBuf *scope = NULL; diff --git a/source/blender/editors/space_sequencer/sequencer_edit.c b/source/blender/editors/space_sequencer/sequencer_edit.c index ff0ab9285db..2cdadfbd2ab 100644 --- a/source/blender/editors/space_sequencer/sequencer_edit.c +++ b/source/blender/editors/space_sequencer/sequencer_edit.c @@ -181,7 +181,7 @@ static void seq_proxy_build_job(const bContext *C) { wmJob *wm_job; ProxyJob *pj; - struct Depsgraph *depsgraph = CTX_data_depsgraph(C); + struct Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); Scene *scene = CTX_data_scene(C); Editing *ed = BKE_sequencer_editing_get(scene, false); ScrArea *sa = CTX_wm_area(C); @@ -1135,6 +1135,7 @@ static int sequencer_gap_remove_exec(bContext *C, wmOperator *op) } WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene); + DEG_id_tag_update(&scene->id, ID_RECALC_SEQUENCER_STRIPS); return OPERATOR_FINISHED; } @@ -2886,7 +2887,7 @@ static int sequencer_view_all_preview_exec(bContext *C, wmOperator *UNUSED(op)) imgwidth = (scene->r.size * scene->r.xsch) / 100; imgheight = (scene->r.size * scene->r.ysch) / 100; - /* Apply aspect, dosnt need to be that accurate */ + /* Apply aspect, doesn't need to be that accurate */ imgwidth = (int)(imgwidth * (scene->r.xasp / scene->r.yasp)); if (((imgwidth >= width) || (imgheight >= height)) && ((width > 0) && (height > 0))) { @@ -3612,7 +3613,7 @@ static int sequencer_rebuild_proxy_invoke(bContext *C, static int sequencer_rebuild_proxy_exec(bContext *C, wmOperator *UNUSED(op)) { Main *bmain = CTX_data_main(C); - struct Depsgraph *depsgraph = CTX_data_depsgraph(C); + struct Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene = CTX_data_scene(C); Editing *ed = BKE_sequencer_editing_get(scene, false); Sequence *seq; diff --git a/source/blender/editors/space_sequencer/sequencer_scopes.c b/source/blender/editors/space_sequencer/sequencer_scopes.c index 2aebc6c97fb..c55d77800ff 100644 --- a/source/blender/editors/space_sequencer/sequencer_scopes.c +++ b/source/blender/editors/space_sequencer/sequencer_scopes.c @@ -452,7 +452,7 @@ typedef struct MakeHistogramViewData { static void make_histogram_view_from_ibuf_byte_cb_ex(void *__restrict userdata, const int y, - const ParallelRangeTLS *__restrict tls) + const TaskParallelTLS *__restrict tls) { MakeHistogramViewData *data = userdata; const ImBuf *ibuf = data->ibuf; @@ -498,7 +498,7 @@ static ImBuf *make_histogram_view_from_ibuf_byte(ImBuf *ibuf) .ibuf = ibuf, .bins = bins, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (ibuf->y >= 256); settings.userdata_chunk = bins; @@ -553,7 +553,7 @@ BLI_INLINE int get_bin_float(float f) static void make_histogram_view_from_ibuf_float_cb_ex(void *__restrict userdata, const int y, - const ParallelRangeTLS *__restrict tls) + const TaskParallelTLS *__restrict tls) { const MakeHistogramViewData *data = userdata; const ImBuf *ibuf = data->ibuf; @@ -584,7 +584,7 @@ static ImBuf *make_histogram_view_from_ibuf_float(ImBuf *ibuf) .ibuf = ibuf, .bins = bins, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (ibuf->y >= 256); settings.userdata_chunk = bins; diff --git a/source/blender/editors/space_sequencer/sequencer_view.c b/source/blender/editors/space_sequencer/sequencer_view.c index 593dd86477a..534d02c7bf3 100644 --- a/source/blender/editors/space_sequencer/sequencer_view.c +++ b/source/blender/editors/space_sequencer/sequencer_view.c @@ -92,7 +92,7 @@ static void sample_draw(const bContext *C, ARegion *ar, void *arg_info) static void sample_apply(bContext *C, wmOperator *op, const wmEvent *event) { Main *bmain = CTX_data_main(C); - struct Depsgraph *depsgraph = CTX_data_depsgraph(C); + struct Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene = CTX_data_scene(C); SpaceSeq *sseq = (SpaceSeq *)CTX_wm_space_data(C); ARegion *ar = CTX_wm_region(C); diff --git a/source/blender/editors/space_text/space_text.c b/source/blender/editors/space_text/space_text.c index 24f282ff920..7d8424a5996 100644 --- a/source/blender/editors/space_text/space_text.c +++ b/source/blender/editors/space_text/space_text.c @@ -199,6 +199,7 @@ static void text_operatortypes(void) WM_operatortype_append(TEXT_OT_convert_whitespace); WM_operatortype_append(TEXT_OT_uncomment); WM_operatortype_append(TEXT_OT_comment); + WM_operatortype_append(TEXT_OT_toggle_comment); WM_operatortype_append(TEXT_OT_unindent); WM_operatortype_append(TEXT_OT_indent); @@ -254,7 +255,9 @@ static int text_context(const bContext *C, const char *member, bContextDataResul return 1; } else if (CTX_data_equals(member, "edit_text")) { - CTX_data_id_pointer_set(result, &st->text->id); + if (st->text != NULL) { + CTX_data_id_pointer_set(result, &st->text->id); + } return 1; } diff --git a/source/blender/editors/space_text/text_intern.h b/source/blender/editors/space_text/text_intern.h index aab5069f919..400405155f8 100644 --- a/source/blender/editors/space_text/text_intern.h +++ b/source/blender/editors/space_text/text_intern.h @@ -121,6 +121,7 @@ void TEXT_OT_duplicate_line(struct wmOperatorType *ot); void TEXT_OT_convert_whitespace(struct wmOperatorType *ot); void TEXT_OT_uncomment(struct wmOperatorType *ot); void TEXT_OT_comment(struct wmOperatorType *ot); +void TEXT_OT_toggle_comment(struct wmOperatorType *ot); void TEXT_OT_unindent(struct wmOperatorType *ot); void TEXT_OT_indent(struct wmOperatorType *ot); diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index 8f7bd83cbf4..95e7d906b11 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -61,7 +61,9 @@ static void txt_screen_clamp(SpaceText *st, ARegion *ar); -/************************ util ***************************/ +/* -------------------------------------------------------------------- */ +/** \name Util + * \{ */ /** * Tests if the given character represents a start of a new line or the @@ -138,14 +140,18 @@ static char *buf_tabs_to_spaces(const char *in_buf, const int tab_size) return out_buf; } -/************************ poll ***************************/ - BLI_INLINE int text_pixel_x_to_column(SpaceText *st, const int x) { /* add half the char width so mouse cursor selection is inbetween letters */ return (x + (st->cwidth / 2)) / st->cwidth; } +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Operator Poll + * \{ */ + static bool text_new_poll(bContext *UNUSED(C)) { return 1; @@ -206,7 +212,11 @@ static bool text_region_edit_poll(bContext *C) return 1; } -/********************** updates *********************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Updates + * \{ */ void text_update_line_edited(TextLine *line) { @@ -230,7 +240,11 @@ void text_update_edited(Text *text) } } -/******************* new operator *********************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name New Operator + * \{ */ static int text_new_exec(bContext *C, wmOperator *UNUSED(op)) { @@ -281,7 +295,11 @@ void TEXT_OT_new(wmOperatorType *ot) ot->flag = OPTYPE_UNDO; } -/******************* open operator *********************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Open Operator + * \{ */ static void text_open_init(bContext *C, wmOperator *op) { @@ -392,7 +410,11 @@ void TEXT_OT_open(wmOperatorType *ot) ot->srna, "internal", 0, "Make internal", "Make text file internal after loading"); } -/******************* reload operator *********************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Reload Operator + * \{ */ static int text_reload_exec(bContext *C, wmOperator *op) { @@ -443,7 +465,11 @@ void TEXT_OT_reload(wmOperatorType *ot) ot->poll = text_edit_poll; } -/******************* delete operator *********************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Delete Operator + * \{ */ static bool text_unlink_poll(bContext *C) { @@ -495,7 +521,11 @@ void TEXT_OT_unlink(wmOperatorType *ot) ot->flag = OPTYPE_UNDO; } -/******************* make internal operator *********************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Make Internal Operator + * \{ */ static int text_make_internal_exec(bContext *C, wmOperator *UNUSED(op)) { @@ -529,7 +559,11 @@ void TEXT_OT_make_internal(wmOperatorType *ot) ot->flag = OPTYPE_UNDO; } -/******************* save operator *********************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Save Operator + * \{ */ static bool text_save_poll(bContext *C) { @@ -614,7 +648,11 @@ void TEXT_OT_save(wmOperatorType *ot) ot->poll = text_save_poll; } -/******************* save as operator *********************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Save As Operator + * \{ */ static int text_save_as_exec(bContext *C, wmOperator *op) { @@ -690,7 +728,11 @@ void TEXT_OT_save_as(wmOperatorType *ot) FILE_SORT_ALPHA); // XXX TODO, relative_path } -/******************* run script operator *********************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Run Script Operator + * \{ */ static bool text_run_script_poll(bContext *C) { @@ -765,7 +807,11 @@ void TEXT_OT_run_script(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } -/******************* refresh pyconstraints operator *********************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Refresh Pyconstraints Operator + * \{ */ static int text_refresh_pyconstraints_exec(bContext *UNUSED(C), wmOperator *UNUSED(op)) { @@ -825,7 +871,11 @@ void TEXT_OT_refresh_pyconstraints(wmOperatorType *ot) ot->poll = text_edit_poll; } -/******************* paste operator *********************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Paste Operator + * \{ */ static int text_paste_exec(bContext *C, wmOperator *op) { @@ -889,7 +939,11 @@ void TEXT_OT_paste(wmOperatorType *ot) "Paste text selected elsewhere rather than copied (X11 only)"); } -/**************** duplicate operator *******************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Duplicate Operator + * \{ */ static int text_duplicate_line_exec(bContext *C, wmOperator *UNUSED(op)) { @@ -924,7 +978,11 @@ void TEXT_OT_duplicate_line(wmOperatorType *ot) ot->flag = OPTYPE_UNDO; } -/******************* copy operator *********************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Copy Operator + * \{ */ static void txt_copy_clipboard(Text *text) { @@ -963,7 +1021,11 @@ void TEXT_OT_copy(wmOperatorType *ot) ot->poll = text_edit_poll; } -/******************* cut operator *********************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Cut Operator + * \{ */ static int text_cut_exec(bContext *C, wmOperator *UNUSED(op)) { @@ -1002,7 +1064,11 @@ void TEXT_OT_cut(wmOperatorType *ot) ot->flag = OPTYPE_UNDO; } -/******************* indent operator *********************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Indent Operator + * \{ */ static int text_indent_exec(bContext *C, wmOperator *UNUSED(op)) { @@ -1043,7 +1109,11 @@ void TEXT_OT_indent(wmOperatorType *ot) ot->flag = OPTYPE_UNDO; } -/******************* unindent operator *********************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Unindent Operator + * \{ */ static int text_unindent_exec(bContext *C, wmOperator *UNUSED(op)) { @@ -1079,7 +1149,11 @@ void TEXT_OT_unindent(wmOperatorType *ot) ot->flag = OPTYPE_UNDO; } -/******************* line break operator *********************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Line Break Operator + * \{ */ static int text_line_break_exec(bContext *C, wmOperator *UNUSED(op)) { @@ -1132,7 +1206,11 @@ void TEXT_OT_line_break(wmOperatorType *ot) ot->flag = OPTYPE_UNDO; } -/******************* comment operator *********************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Comment Operator + * \{ */ static int text_comment_exec(bContext *C, wmOperator *UNUSED(op)) { @@ -1170,7 +1248,11 @@ void TEXT_OT_comment(wmOperatorType *ot) ot->flag = OPTYPE_UNDO; } -/******************* uncomment operator *********************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Uncomment Operator + * \{ */ static int text_uncomment_exec(bContext *C, wmOperator *UNUSED(op)) { @@ -1209,7 +1291,55 @@ void TEXT_OT_uncomment(wmOperatorType *ot) ot->flag = OPTYPE_UNDO; } -/******************* convert whitespace operator *********************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Toggle-Comment Operator + * \{ */ + +static int text_toggle_comment_exec(bContext *C, wmOperator *UNUSED(op)) +{ + Text *text = CTX_data_edit_text(C); + + if (txt_has_sel(text)) { + text_drawcache_tag_update(CTX_wm_space_text(C), 0); + + ED_text_undo_push_init(C); + + txt_order_cursors(text, false); + if (txt_uncomment(text) == false) { + txt_comment(text); + } + text_update_edited(text); + + text_update_cursor_moved(C); + WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text); + + return OPERATOR_FINISHED; + } + + return OPERATOR_CANCELLED; +} + +void TEXT_OT_toggle_comment(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Toggle Comment"; + ot->idname = "TEXT_OT_toggle_comment"; + + /* api callbacks */ + ot->exec = text_toggle_comment_exec; + ot->poll = text_edit_poll; + + /* flags */ + ot->flag = OPTYPE_UNDO; +} + +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Convert Whitespace Operator + * \{ */ enum { TO_SPACES, TO_TABS }; static const EnumPropertyItem whitespace_type_items[] = { @@ -1360,7 +1490,11 @@ void TEXT_OT_convert_whitespace(wmOperatorType *ot) "Type of whitespace to convert to"); } -/******************* select all operator *********************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Select All Operator + * \{ */ static int text_select_all_exec(bContext *C, wmOperator *UNUSED(op)) { @@ -1386,7 +1520,11 @@ void TEXT_OT_select_all(wmOperatorType *ot) ot->poll = text_edit_poll; } -/******************* select line operator *********************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Select Line Operator + * \{ */ static int text_select_line_exec(bContext *C, wmOperator *UNUSED(op)) { @@ -1412,7 +1550,11 @@ void TEXT_OT_select_line(wmOperatorType *ot) ot->poll = text_edit_poll; } -/******************* select word operator *********************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Select Word Operator + * \{ */ static int text_select_word_exec(bContext *C, wmOperator *UNUSED(op)) { @@ -1441,7 +1583,11 @@ void TEXT_OT_select_word(wmOperatorType *ot) ot->poll = text_edit_poll; } -/********************* move lines operators ***********************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Move Lines Operators + * \{ */ static int move_lines_exec(bContext *C, wmOperator *op) { @@ -1487,7 +1633,11 @@ void TEXT_OT_move_lines(wmOperatorType *ot) RNA_def_enum(ot->srna, "direction", direction_items, 1, "Direction", ""); } -/************************ move operator ************************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Move Operator + * \{ */ static const EnumPropertyItem move_type_items[] = { {LINE_BEGIN, "LINE_BEGIN", 0, "Line Begin", ""}, @@ -2126,7 +2276,11 @@ void TEXT_OT_move(wmOperatorType *ot) RNA_def_enum(ot->srna, "type", move_type_items, LINE_BEGIN, "Type", "Where to move cursor to"); } -/******************* move select operator ********************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Move Select Operator + * \{ */ static int text_move_select_exec(bContext *C, wmOperator *op) { @@ -2155,7 +2309,11 @@ void TEXT_OT_move_select(wmOperatorType *ot) "Where to move cursor to, to make a selection"); } -/******************* jump operator *********************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Jump Operator + * \{ */ static int text_jump_exec(bContext *C, wmOperator *op) { @@ -2203,7 +2361,11 @@ void TEXT_OT_jump(wmOperatorType *ot) RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_TEXT); } -/******************* delete operator **********************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Delete Operator + * \{ */ static const EnumPropertyItem delete_type_items[] = { {DEL_NEXT_CHAR, "NEXT_CHARACTER", 0, "Next Character", ""}, @@ -2317,7 +2479,11 @@ void TEXT_OT_delete(wmOperatorType *ot) RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE); } -/******************* toggle overwrite operator **********************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Toggle Overwrite Operator + * \{ */ static int text_toggle_overwrite_exec(bContext *C, wmOperator *UNUSED(op)) { @@ -2342,7 +2508,11 @@ void TEXT_OT_overwrite_toggle(wmOperatorType *ot) ot->poll = text_space_edit_poll; } -/******************* scroll operator **********************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Scroll Operator + * \{ */ static void txt_screen_clamp(SpaceText *st, ARegion *ar) { @@ -2571,7 +2741,11 @@ void TEXT_OT_scroll(wmOperatorType *ot) ot->srna, "lines", 1, INT_MIN, INT_MAX, "Lines", "Number of lines to scroll", -100, 100); } -/******************** scroll bar operator *******************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Scroll Bar Operator + * \{ */ static bool text_region_scroll_poll(bContext *C) { @@ -3073,7 +3247,11 @@ void TEXT_OT_selection_set(wmOperatorType *ot) RNA_def_boolean(ot->srna, "select", 0, "Select", "Set selection end rather than cursor"); } -/******************* set cursor operator **********************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Set Cursor Operator + * \{ */ static int text_cursor_set_exec(bContext *C, wmOperator *op) { @@ -3121,7 +3299,11 @@ void TEXT_OT_cursor_set(wmOperatorType *ot) RNA_def_int(ot->srna, "y", 0, INT_MIN, INT_MAX, "Y", "", INT_MIN, INT_MAX); } -/******************* line number operator **********************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Line Number Operator + * \{ */ static int text_line_number_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event) { @@ -3177,7 +3359,11 @@ void TEXT_OT_line_number(wmOperatorType *ot) ot->poll = text_region_edit_poll; } -/******************* insert operator **********************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Insert Operator + * \{ */ static int text_insert_exec(bContext *C, wmOperator *op) { @@ -3284,7 +3470,11 @@ void TEXT_OT_insert(wmOperatorType *ot) RNA_def_property_flag(prop, PROP_SKIP_SAVE); } -/******************* find operator *********************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Find Operator + * \{ */ /* mode */ #define TEXT_FIND 0 @@ -3378,7 +3568,11 @@ void TEXT_OT_find(wmOperatorType *ot) ot->poll = text_space_edit_poll; } -/******************* replace operator *********************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Replace Operator + * \{ */ static int text_replace_exec(bContext *C, wmOperator *op) { @@ -3400,7 +3594,11 @@ void TEXT_OT_replace(wmOperatorType *ot) ot->flag = OPTYPE_UNDO; } -/******************* find set selected *********************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Find Set Selected + * \{ */ static int text_find_set_selected_exec(bContext *C, wmOperator *op) { @@ -3431,7 +3629,11 @@ void TEXT_OT_find_set_selected(wmOperatorType *ot) ot->poll = text_space_edit_poll; } -/******************* replace set selected *********************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Replace Set Selected + * \{ */ static int text_replace_set_selected_exec(bContext *C, wmOperator *UNUSED(op)) { @@ -3461,7 +3663,11 @@ void TEXT_OT_replace_set_selected(wmOperatorType *ot) ot->flag = OPTYPE_UNDO; } -/****************** resolve conflict operator ******************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Resolve Conflict Operator + * \{ */ enum { RESOLVE_IGNORE, RESOLVE_RELOAD, RESOLVE_SAVE, RESOLVE_MAKE_INTERNAL }; static const EnumPropertyItem resolution_items[] = { @@ -3574,7 +3780,11 @@ void TEXT_OT_resolve_conflict(wmOperatorType *ot) "How to solve conflict due to differences in internal and external text"); } -/********************** to 3d object operator *****************/ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name To 3D Object Operator + * \{ */ static int text_to_3d_object_exec(bContext *C, wmOperator *op) { @@ -3604,3 +3814,5 @@ void TEXT_OT_to_3d_object(wmOperatorType *ot) RNA_def_boolean( ot->srna, "split_lines", 0, "Split Lines", "Create one object per line in the text"); } + +/** \} */ diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c index 57b98ffeda3..d1ea01146bc 100644 --- a/source/blender/editors/space_view3d/space_view3d.c +++ b/source/blender/editors/space_view3d/space_view3d.c @@ -1140,7 +1140,7 @@ static void view3d_header_region_listener(wmWindow *UNUSED(win), } /* From topbar, which ones are needed? split per header? */ - /* Disable for now, re-enable if neede, or remove - campbell. */ + /* Disable for now, re-enable if needed, or remove - campbell. */ #if 0 /* context changes */ switch (wmn->category) { diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index eef36dae86a..8844428b1bf 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -803,13 +803,19 @@ void ED_view3d_draw_depth(Depsgraph *depsgraph, ARegion *ar, View3D *v3d, bool a GPU_depth_test(true); + /* Needed in cases the view-port isn't already setup. */ + WM_draw_region_viewport_ensure(ar, SPACE_VIEW3D); + WM_draw_region_viewport_bind(ar); + GPUViewport *viewport = WM_draw_region_get_viewport(ar, 0); /* When Blender is starting, a click event can trigger a depth test while the viewport is not * yet available. */ if (viewport != NULL) { - DRW_draw_depth_loop(depsgraph, ar, v3d, viewport); + DRW_draw_depth_loop(depsgraph, ar, v3d, viewport, false); } + WM_draw_region_viewport_unbind(ar); + if (rv3d->rflag & RV3D_CLIPPING) { ED_view3d_clipping_disable(); } @@ -1076,7 +1082,7 @@ static void draw_rotation_guide(const RegionView3D *rv3d) static void view3d_draw_border(const bContext *C, ARegion *ar) { Scene *scene = CTX_data_scene(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_expect_evaluated_depsgraph(C); RegionView3D *rv3d = ar->regiondata; View3D *v3d = CTX_wm_view3d(C); @@ -1447,7 +1453,7 @@ void view3d_draw_region_info(const bContext *C, ARegion *ar) static void view3d_draw_view(const bContext *C, ARegion *ar) { ED_view3d_draw_setup_view(CTX_wm_window(C), - CTX_data_depsgraph(C), + CTX_data_expect_evaluated_depsgraph(C), CTX_data_scene(C), ar, CTX_wm_view3d(C), diff --git a/source/blender/editors/space_view3d/view3d_draw_legacy.c b/source/blender/editors/space_view3d/view3d_draw_legacy.c index 386c3164843..4c03995307a 100644 --- a/source/blender/editors/space_view3d/view3d_draw_legacy.c +++ b/source/blender/editors/space_view3d/view3d_draw_legacy.c @@ -155,11 +155,13 @@ void ED_view3d_clipping_enable(void) /** * \note Only use in object mode. */ -static void validate_object_select_id( - struct Depsgraph *depsgraph, Scene *scene, ARegion *ar, View3D *v3d, Object *obact) +static void validate_object_select_id(struct Depsgraph *depsgraph, + Scene *scene, + ViewLayer *view_layer, + ARegion *ar, + View3D *v3d, + Object *obact) { - RegionView3D *rv3d = ar->regiondata; - Scene *scene_eval = (Scene *)DEG_get_evaluated_id(depsgraph, &scene->id); Object *obact_eval = DEG_get_evaluated_object(depsgraph, obact); BLI_assert(ar->regiontype == RGN_TYPE_WINDOW); @@ -186,19 +188,8 @@ static void validate_object_select_id( } if (obact_eval && ((obact_eval->base_flag & BASE_VISIBLE) != 0)) { - uint dummy_vert_ofs, dummy_edge_ofs, dummy_face_ofs; - DRW_framebuffer_select_id_setup(ar, true); - DRW_draw_select_id_object(scene_eval, - rv3d, - obact_eval, - scene->toolsettings->selectmode, - false, - 1, - &dummy_vert_ofs, - &dummy_edge_ofs, - &dummy_face_ofs); - - DRW_framebuffer_select_id_release(ar); + DRW_draw_select_id_object( + depsgraph, view_layer, ar, v3d, obact, scene->toolsettings->selectmode); } /* TODO: Create a flag in `DRW_manager` because the drawing is no longer @@ -233,7 +224,8 @@ void ED_view3d_select_id_validate(ViewContext *vc) /* TODO: Create a flag in `DRW_manager` because the drawing is no longer * made on the backbuffer in this case. */ if (vc->v3d->flag & V3D_INVALID_BACKBUF) { - validate_object_select_id(vc->depsgraph, vc->scene, vc->ar, vc->v3d, vc->obact); + validate_object_select_id( + vc->depsgraph, vc->scene, vc->view_layer, vc->ar, vc->v3d, vc->obact); } } diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 7c4b35507b9..826eddc63d1 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -219,7 +219,7 @@ static void viewops_data_alloc(bContext *C, wmOperator *op) /* store data */ op->customdata = vod; vod->bmain = CTX_data_main(C); - vod->depsgraph = CTX_data_depsgraph(C); + vod->depsgraph = CTX_data_ensure_evaluated_depsgraph(C); vod->scene = CTX_data_scene(C); vod->sa = CTX_wm_area(C); vod->ar = CTX_wm_region(C); @@ -249,7 +249,7 @@ static bool view3d_orbit_calc_center(bContext *C, float r_dyn_ofs[3]) static float lastofs[3] = {0, 0, 0}; bool is_set = false; - const Depsgraph *depsgraph = CTX_data_depsgraph(C); + const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene = CTX_data_scene(C); ViewLayer *view_layer_eval = DEG_get_evaluated_view_layer(depsgraph); View3D *v3d = CTX_wm_view3d(C); @@ -373,7 +373,7 @@ static void viewops_data_create(bContext *C, const wmEvent *event, enum eViewOpsFlag viewops_flag) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); ViewOpsData *vod = op->customdata; RegionView3D *rv3d = vod->rv3d; @@ -1317,7 +1317,7 @@ static int ndof_orbit_invoke(bContext *C, wmOperator *op, const wmEvent *event) return OPERATOR_CANCELLED; } - const Depsgraph *depsgraph = CTX_data_depsgraph(C); + const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); ViewOpsData *vod; View3D *v3d; RegionView3D *rv3d; @@ -1397,7 +1397,7 @@ static int ndof_orbit_zoom_invoke(bContext *C, wmOperator *op, const wmEvent *ev return OPERATOR_CANCELLED; } - const Depsgraph *depsgraph = CTX_data_depsgraph(C); + const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); ViewOpsData *vod; View3D *v3d; RegionView3D *rv3d; @@ -1511,7 +1511,7 @@ static int ndof_pan_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *e return OPERATOR_CANCELLED; } - const Depsgraph *depsgraph = CTX_data_depsgraph(C); + const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); View3D *v3d = CTX_wm_view3d(C); RegionView3D *rv3d = CTX_wm_region_view3d(C); const wmNDOFMotionData *ndof = event->customdata; @@ -2188,7 +2188,7 @@ static int viewzoom_modal(bContext *C, wmOperator *op, const wmEvent *event) static int viewzoom_exec(bContext *C, wmOperator *op) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene = CTX_data_scene(C); View3D *v3d; RegionView3D *rv3d; @@ -2553,7 +2553,7 @@ static int viewdolly_exec(bContext *C, wmOperator *op) ED_view3d_depth_tag_update(rv3d); - ED_view3d_camera_lock_sync(CTX_data_depsgraph(C), v3d, rv3d); + ED_view3d_camera_lock_sync(CTX_data_ensure_evaluated_depsgraph(C), v3d, rv3d); ED_region_tag_redraw(ar); @@ -2588,7 +2588,7 @@ static int viewdolly_invoke(bContext *C, wmOperator *op, const wmEvent *event) if (vod->rv3d->persp != RV3D_PERSP) { if (vod->rv3d->persp == RV3D_CAMOB) { /* ignore rv3d->lpersp because dolly only makes sense in perspective mode */ - const Depsgraph *depsgraph = CTX_data_depsgraph(C); + const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); ED_view3d_persp_switch_from_camera(depsgraph, vod->v3d, vod->rv3d, RV3D_PERSP); } else { @@ -2749,8 +2749,9 @@ static void view3d_from_minmax(bContext *C, } if (ok_dist) { + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); new_dist = ED_view3d_radius_to_dist( - v3d, ar, CTX_data_depsgraph(C), persp, true, (size / 2) * VIEW3D_MARGIN); + v3d, ar, depsgraph, persp, true, (size / 2) * VIEW3D_MARGIN); if (rv3d->is_persp) { /* don't zoom closer than the near clipping plane */ new_dist = max_ff(new_dist, v3d->clip_start * 1.5f); @@ -2817,7 +2818,7 @@ static int view3d_all_exec(bContext *C, wmOperator *op) View3D *v3d = CTX_wm_view3d(C); RegionView3D *rv3d = CTX_wm_region_view3d(C); Scene *scene = CTX_data_scene(C); - const Depsgraph *depsgraph = CTX_data_depsgraph(C); + const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); ViewLayer *view_layer_eval = DEG_get_evaluated_view_layer(depsgraph); Base *base_eval; const bool use_all_regions = RNA_boolean_get(op->ptr, "use_all_regions"); @@ -2922,14 +2923,14 @@ static int viewselected_exec(bContext *C, wmOperator *op) View3D *v3d = CTX_wm_view3d(C); RegionView3D *rv3d = CTX_wm_region_view3d(C); Scene *scene = CTX_data_scene(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); ViewLayer *view_layer_eval = DEG_get_evaluated_view_layer(depsgraph); - bGPdata *gpd = CTX_data_gpencil_data(C); - const bool is_gp_edit = GPENCIL_ANY_MODE(gpd); - const bool is_face_map = ((is_gp_edit == false) && ar->gizmo_map && - WM_gizmomap_is_any_selected(ar->gizmo_map)); Object *ob_eval = OBACT(view_layer_eval); Object *obedit = CTX_data_edit_object(C); + const bGPdata *gpd_eval = ob_eval && (ob_eval->type == OB_GPENCIL) ? ob_eval->data : NULL; + const bool is_gp_edit = gpd_eval ? GPENCIL_ANY_MODE(gpd_eval) : false; + const bool is_face_map = ((is_gp_edit == false) && ar->gizmo_map && + WM_gizmomap_is_any_selected(ar->gizmo_map)); float min[3], max[3]; bool ok = false, ok_dist = true; const bool use_all_regions = RNA_boolean_get(op->ptr, "use_all_regions"); @@ -3120,7 +3121,8 @@ static int view_lock_to_active_exec(bContext *C, wmOperator *UNUSED(op)) if (obact && obact->type == OB_ARMATURE) { if (obact->mode & OB_MODE_POSE) { - Object *obact_eval = DEG_get_evaluated_object(CTX_data_depsgraph(C), obact); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); + Object *obact_eval = DEG_get_evaluated_object(depsgraph, obact); bPoseChannel *pcham_act = BKE_pose_channel_active(obact_eval); if (pcham_act) { BLI_strncpy(v3d->ob_centre_bone, pcham_act->name, sizeof(v3d->ob_centre_bone)); @@ -3216,7 +3218,7 @@ static int viewcenter_pick_invoke(bContext *C, wmOperator *op, const wmEvent *ev ARegion *ar = CTX_wm_region(C); if (rv3d) { - struct Depsgraph *depsgraph = CTX_data_depsgraph(C); + struct Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); float new_ofs[3]; const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); @@ -3262,7 +3264,7 @@ void VIEW3D_OT_view_center_pick(wmOperatorType *ot) static int view3d_center_camera_exec(bContext *C, wmOperator *UNUSED(op)) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene = CTX_data_scene(C); float xfac, yfac; float size[2]; @@ -3361,7 +3363,7 @@ static int render_border_exec(bContext *C, wmOperator *op) /* calculate range */ if (rv3d->persp == RV3D_CAMOB) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); ED_view3d_calc_camera_border(scene, depsgraph, ar, v3d, rv3d, &vb, false); } else { @@ -3530,7 +3532,7 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op) ED_view3d_dist_range_get(v3d, dist_range); /* Get Z Depths, needed for perspective, nice for ortho */ - ED_view3d_draw_depth(CTX_data_depsgraph(C), ar, v3d, true); + ED_view3d_draw_depth(CTX_data_ensure_evaluated_depsgraph(C), ar, v3d, true); { /* avoid allocating the whole depth buffer */ @@ -3585,7 +3587,7 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op) float mval_f[2]; float zfac; - /* We cant use the depth, fallback to the old way that dosnt set the center depth */ + /* We can't use the depth, fallback to the old way that doesn't set the center depth */ copy_v3_v3(new_ofs, rv3d->ofs); { @@ -3619,7 +3621,7 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op) /* TODO(campbell): 'is_camera_lock' not currently working well. */ const bool is_camera_lock = ED_view3d_camera_lock_check(v3d, rv3d); if ((rv3d->persp == RV3D_CAMOB) && (is_camera_lock == false)) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); ED_view3d_persp_switch_from_camera(depsgraph, v3d, rv3d, RV3D_PERSP); } @@ -3686,7 +3688,7 @@ static void view3d_set_1_to_1_viewborder(Scene *scene, static int view3d_zoom_1_to_1_camera_exec(bContext *C, wmOperator *UNUSED(op)) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene = CTX_data_scene(C); View3D *v3d; @@ -3794,7 +3796,8 @@ static void axis_set_view(bContext *C, dist = rv3d->dist; /* so we animate _from_ the camera location */ - Object *camera_eval = DEG_get_evaluated_object(CTX_data_depsgraph(C), v3d->camera); + Object *camera_eval = DEG_get_evaluated_object(CTX_data_ensure_evaluated_depsgraph(C), + v3d->camera); ED_view3d_from_object(camera_eval, rv3d->ofs, NULL, &rv3d->dist, NULL); ED_view3d_smooth_view(C, @@ -4124,7 +4127,7 @@ static int vieworbit_exec(bContext *C, wmOperator *op) float quat_new[4]; if (view_opposite == RV3D_VIEW_USER) { - const Depsgraph *depsgraph = CTX_data_depsgraph(C); + const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); ED_view3d_persp_ensure(depsgraph, v3d, ar); } @@ -4874,7 +4877,7 @@ void ED_view3d_cursor3d_position(bContext *C, } if (use_depth) { /* maybe this should be accessed some other way */ - struct Depsgraph *depsgraph = CTX_data_depsgraph(C); + struct Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); view3d_operator_needs_opengl(C); if (ED_view3d_autodist(depsgraph, ar, v3d, mval, cursor_co, true, NULL)) { @@ -4930,7 +4933,7 @@ void ED_view3d_cursor3d_position_rotation(bContext *C, float ray_co[3]; struct SnapObjectContext *snap_context = ED_transform_snap_object_context_create_view3d( - bmain, scene, CTX_data_depsgraph(C), 0, ar, v3d); + bmain, scene, CTX_data_ensure_evaluated_depsgraph(C), 0, ar, v3d); float obmat[4][4]; Object *ob_dummy = NULL; diff --git a/source/blender/editors/space_view3d/view3d_fly.c b/source/blender/editors/space_view3d/view3d_fly.c index 3fa0c2c59b7..961ac4c26fb 100644 --- a/source/blender/editors/space_view3d/view3d_fly.c +++ b/source/blender/editors/space_view3d/view3d_fly.c @@ -270,7 +270,7 @@ static bool initFlyInfo(bContext *C, FlyInfo *fly, wmOperator *op, const wmEvent fly->rv3d = CTX_wm_region_view3d(C); fly->v3d = CTX_wm_view3d(C); fly->ar = CTX_wm_region(C); - fly->depsgraph = CTX_data_depsgraph(C); + fly->depsgraph = CTX_data_expect_evaluated_depsgraph(C); fly->scene = CTX_data_scene(C); #ifdef NDOF_FLY_DEBUG @@ -337,12 +337,8 @@ static bool initFlyInfo(bContext *C, FlyInfo *fly, wmOperator *op, const wmEvent fly->zlock = FLY_AXISLOCK_STATE_IDLE; } - fly->v3d_camera_control = ED_view3d_cameracontrol_acquire(CTX_data_depsgraph(C), - fly->scene, - fly->v3d, - fly->rv3d, - (U.uiflag & USER_CAM_LOCK_NO_PARENT) == - 0); + fly->v3d_camera_control = ED_view3d_cameracontrol_acquire( + fly->depsgraph, fly->scene, fly->v3d, fly->rv3d, (U.uiflag & USER_CAM_LOCK_NO_PARENT) == 0); /* calculate center */ if (ED_view3d_cameracontrol_object_get(fly->v3d_camera_control)) { diff --git a/source/blender/editors/space_view3d/view3d_gizmo_camera.c b/source/blender/editors/space_view3d/view3d_gizmo_camera.c index 002a7e12515..1bb10697936 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_camera.c +++ b/source/blender/editors/space_view3d/view3d_gizmo_camera.c @@ -437,7 +437,8 @@ static void WIDGETGROUP_camera_view_draw_prepare(const bContext *C, wmGizmoGroup struct CameraViewWidgetGroup *viewgroup = gzgroup->customdata; ARegion *ar = CTX_wm_region(C); - struct Depsgraph *depsgraph = CTX_data_depsgraph(C); + /* Drawing code should happen with fully evaluated graph. */ + struct Depsgraph *depsgraph = CTX_data_expect_evaluated_depsgraph(C); RegionView3D *rv3d = ar->regiondata; if (rv3d->persp == RV3D_CAMOB) { Scene *scene = CTX_data_scene(C); diff --git a/source/blender/editors/space_view3d/view3d_gizmo_preselect_type.c b/source/blender/editors/space_view3d/view3d_gizmo_preselect_type.c index 64697a59019..a984e339305 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_preselect_type.c +++ b/source/blender/editors/space_view3d/view3d_gizmo_preselect_type.c @@ -176,7 +176,7 @@ static int gizmo_preselect_elem_test_select(bContext *C, wmGizmo *gz, const int const float(*coords)[3] = NULL; { Object *ob = gz_ele->bases[gz_ele->base_index]->object; - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Mesh *me_eval = (Mesh *)DEG_get_evaluated_id(depsgraph, ob->data); if (me_eval->runtime.edit_data) { coords = me_eval->runtime.edit_data->vertexCos; @@ -334,7 +334,7 @@ static int gizmo_preselect_edgering_test_select(bContext *C, wmGizmo *gz, const const float(*coords)[3] = NULL; { Object *ob = gz_ring->bases[gz_ring->base_index]->object; - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Mesh *me_eval = (Mesh *)DEG_get_evaluated_id(depsgraph, ob->data); if (me_eval->runtime.edit_data) { coords = me_eval->runtime.edit_data->vertexCos; diff --git a/source/blender/editors/space_view3d/view3d_gizmo_ruler.c b/source/blender/editors/space_view3d/view3d_gizmo_ruler.c index e781e129540..97a12c7100e 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_ruler.c +++ b/source/blender/editors/space_view3d/view3d_gizmo_ruler.c @@ -289,7 +289,12 @@ static void ruler_state_set(bContext *C, RulerInfo *ruler_info, int state) else if (state == RULER_STATE_DRAG) { memset(&ruler_info->drag_state_prev, 0x0, sizeof(ruler_info->drag_state_prev)); ruler_info->snap_context = ED_transform_snap_object_context_create_view3d( - bmain, CTX_data_scene(C), CTX_data_depsgraph(C), 0, ruler_info->ar, CTX_wm_view3d(C)); + bmain, + CTX_data_scene(C), + CTX_data_ensure_evaluated_depsgraph(C), + 0, + ruler_info->ar, + CTX_wm_view3d(C)); } else { BLI_assert(0); diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c index 61de61c8e31..36eb07e9a2f 100644 --- a/source/blender/editors/space_view3d/view3d_select.c +++ b/source/blender/editors/space_view3d/view3d_select.c @@ -111,192 +111,6 @@ // #include "PIL_time_utildefines.h" /* -------------------------------------------------------------------- */ -/** \name Selection Utilities - * \{ */ - -struct EDBaseOffset { - /* For convenience only. */ - union { - uint offset; - uint face_start; - }; - union { - uint face; - uint edge_start; - }; - union { - uint edge; - uint vert_start; - }; - uint vert; -}; - -struct EDSelectID_Context { - struct EDBaseOffset *base_array_index_offsets; - /** Borrow from caller (not freed). */ - struct Base **bases; - uint bases_len; - /** Total number of items `base_array_index_offsets[bases_len - 1].vert`. */ - uint base_array_index_len; - /** Used to check for changes. (Use depsgraph instead?). */ - float persmat[4][4]; - short select_mode; -}; - -static bool check_ob_drawface_dot(short select_mode, const View3D *v3d, char dt) -{ - if (select_mode & SCE_SELECT_FACE) { - if ((dt < OB_SOLID) || XRAY_FLAG_ENABLED(v3d)) { - return true; - } - if (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_FACE_DOT) { - return true; - } - if ((v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_EDGES) == 0) { - /* Since we can't deduce face selection when edges aren't visible - show dots. */ - return true; - } - } - return false; -} - -static void ed_select_id_draw_bases(struct EDSelectID_Context *sel_id_ctx, - ViewContext *vc, - short select_mode) -{ - Scene *scene_eval = (Scene *)DEG_get_evaluated_id(vc->depsgraph, &vc->scene->id); - DRW_framebuffer_select_id_setup(vc->ar, true); - - uint offset = 1; - for (uint base_index = 0; base_index < sel_id_ctx->bases_len; base_index++) { - Object *ob_eval = DEG_get_evaluated_object(vc->depsgraph, - sel_id_ctx->bases[base_index]->object); - - struct EDBaseOffset *base_ofs = &sel_id_ctx->base_array_index_offsets[base_index]; - bool draw_facedot = check_ob_drawface_dot(select_mode, vc->v3d, ob_eval->dt); - - DRW_draw_select_id_object(scene_eval, - vc->rv3d, - ob_eval, - select_mode, - draw_facedot, - offset, - &base_ofs->vert, - &base_ofs->edge, - &base_ofs->face); - - base_ofs->offset = offset; - offset = base_ofs->vert; - } - - sel_id_ctx->base_array_index_len = offset; - - DRW_framebuffer_select_id_release(vc->ar); -} - -void ED_view3d_select_id_validate_view_matrices(struct EDSelectID_Context *sel_id_ctx, - ViewContext *vc) -{ - if (!compare_m4m4(sel_id_ctx->persmat, vc->rv3d->persmat, FLT_EPSILON)) { - ed_select_id_draw_bases(sel_id_ctx, vc, sel_id_ctx->select_mode); - } -} - -uint ED_view3d_select_id_context_offset_for_object_elem( - const struct EDSelectID_Context *sel_id_ctx, int base_index, char elem_type) -{ - struct EDBaseOffset *base_ofs = &sel_id_ctx->base_array_index_offsets[base_index]; - if (elem_type == SCE_SELECT_VERTEX) { - return base_ofs->vert_start - 1; - } - if (elem_type == SCE_SELECT_EDGE) { - return base_ofs->edge_start - 1; - } - if (elem_type == SCE_SELECT_FACE) { - return base_ofs->face_start - 1; - } - BLI_assert(0); - return 0; -} - -uint ED_view3d_select_id_context_elem_len(const struct EDSelectID_Context *sel_id_ctx) -{ - return sel_id_ctx->base_array_index_len; -} - -struct EDSelectID_Context *ED_view3d_select_id_context_create(ViewContext *vc, - Base **bases, - const uint bases_len, - short select_mode) -{ - struct EDSelectID_Context *sel_id_ctx = MEM_mallocN(sizeof(*sel_id_ctx), __func__); - sel_id_ctx->base_array_index_offsets = MEM_mallocN(sizeof(struct EDBaseOffset) * bases_len, - __func__); - sel_id_ctx->bases = bases; - sel_id_ctx->bases_len = bases_len; - copy_m4_m4(sel_id_ctx->persmat, vc->rv3d->persmat); - sel_id_ctx->select_mode = select_mode; - ed_select_id_draw_bases(sel_id_ctx, vc, select_mode); - - return sel_id_ctx; -} - -void ED_view3d_select_id_context_destroy(struct EDSelectID_Context *sel_id_ctx) -{ - MEM_freeN(sel_id_ctx->base_array_index_offsets); - MEM_freeN(sel_id_ctx); -} - -bool ED_view3d_select_id_elem_get(struct EDSelectID_Context *sel_id_ctx, - const uint sel_id, - uint *r_elem, - uint *r_base_index, - char *r_elem_type) -{ - char elem_type = 0; - uint elem_id; - uint base_index = 0; - - while (true) { - struct EDBaseOffset *base_ofs = &sel_id_ctx->base_array_index_offsets[base_index]; - if (base_ofs->face > sel_id) { - elem_id = sel_id - base_ofs->face_start; - elem_type = SCE_SELECT_FACE; - break; - } - if (base_ofs->edge > sel_id) { - elem_id = sel_id - base_ofs->edge_start; - elem_type = SCE_SELECT_EDGE; - break; - } - if (base_ofs->vert > sel_id) { - elem_id = sel_id - base_ofs->vert_start; - elem_type = SCE_SELECT_VERTEX; - break; - } - - base_index++; - if (base_index >= sel_id_ctx->bases_len) { - return false; - } - } - - *r_elem = elem_id; - - if (r_base_index) { - *r_base_index = base_index; - } - - if (r_elem_type) { - *r_elem_type = elem_type; - } - - return true; -} - -/** \} */ - -/* -------------------------------------------------------------------- */ /** \name Public Utilities * \{ */ @@ -312,7 +126,7 @@ void ED_view3d_viewcontext_init(bContext *C, ViewContext *vc) vc->C = C; vc->ar = CTX_wm_region(C); vc->bmain = CTX_data_main(C); - vc->depsgraph = CTX_data_depsgraph(C); + vc->depsgraph = CTX_data_ensure_evaluated_depsgraph(C); vc->scene = CTX_data_scene(C); vc->view_layer = CTX_data_view_layer(C); vc->v3d = CTX_wm_view3d(C); @@ -385,7 +199,6 @@ static bool object_deselect_all_except(ViewLayer *view_layer, Base *b) struct EditSelectBuf_Cache { Base **bases; uint bases_len; - struct EDSelectID_Context *sel_id_ctx; BLI_bitmap *select_bitmap; }; @@ -407,8 +220,12 @@ static void editselect_buf_cache_init(struct EditSelectBuf_Cache *esel, ViewCont esel->bases_len = 0; } } - esel->sel_id_ctx = ED_view3d_select_id_context_create( - vc, esel->bases, esel->bases_len, vc->scene->toolsettings->selectmode); + DRW_draw_select_id(vc->depsgraph, + vc->ar, + vc->v3d, + esel->bases, + esel->bases_len, + vc->scene->toolsettings->selectmode); for (int i = 0; i < esel->bases_len; i++) { esel->bases[i]->object->runtime.select_id = i; } @@ -416,9 +233,6 @@ static void editselect_buf_cache_init(struct EditSelectBuf_Cache *esel, ViewCont static void editselect_buf_cache_free(struct EditSelectBuf_Cache *esel) { - if (esel->sel_id_ctx) { - ED_view3d_select_id_context_destroy(esel->sel_id_ctx); - } MEM_SAFE_FREE(esel->select_bitmap); MEM_SAFE_FREE(esel->bases); } @@ -455,8 +269,7 @@ static bool edbm_backbuf_check_and_select_verts(struct EditSelectBuf_Cache *esel bool changed = false; const BLI_bitmap *select_bitmap = esel->select_bitmap; - uint index = ED_view3d_select_id_context_offset_for_object_elem( - esel->sel_id_ctx, ob->runtime.select_id, SCE_SELECT_VERTEX); + uint index = DRW_select_context_offset_for_object_elem(ob->runtime.select_id, SCE_SELECT_VERTEX); BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) { if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) { @@ -483,8 +296,7 @@ static bool edbm_backbuf_check_and_select_edges(struct EditSelectBuf_Cache *esel bool changed = false; const BLI_bitmap *select_bitmap = esel->select_bitmap; - uint index = ED_view3d_select_id_context_offset_for_object_elem( - esel->sel_id_ctx, ob->runtime.select_id, SCE_SELECT_EDGE); + uint index = DRW_select_context_offset_for_object_elem(ob->runtime.select_id, SCE_SELECT_EDGE); BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) { if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) { @@ -511,8 +323,7 @@ static bool edbm_backbuf_check_and_select_faces(struct EditSelectBuf_Cache *esel bool changed = false; const BLI_bitmap *select_bitmap = esel->select_bitmap; - uint index = ED_view3d_select_id_context_offset_for_object_elem( - esel->sel_id_ctx, ob->runtime.select_id, SCE_SELECT_FACE); + uint index = DRW_select_context_offset_for_object_elem(ob->runtime.select_id, SCE_SELECT_FACE); BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) { @@ -1017,7 +828,7 @@ static bool do_lasso_select_mesh(ViewContext *vc, if (wm_userdata->data == NULL) { editselect_buf_cache_init_with_generic_userdata(wm_userdata, vc); esel = wm_userdata->data; - const uint buffer_len = ED_view3d_select_id_context_elem_len(esel->sel_id_ctx); + const uint buffer_len = DRW_select_context_elem_len(); esel->select_bitmap = ED_select_buffer_bitmap_from_poly(buffer_len, mcords, moves, &rect); } } @@ -1036,10 +847,8 @@ static bool do_lasso_select_mesh(ViewContext *vc, struct LassoSelectUserData_ForMeshEdge data_for_edge = { .data = &data, .esel = use_zbuf ? esel : NULL, - .backbuf_offset = use_zbuf ? ED_view3d_select_id_context_offset_for_object_elem( - esel->sel_id_ctx, - vc->obedit->runtime.select_id, - SCE_SELECT_EDGE) : + .backbuf_offset = use_zbuf ? DRW_select_context_offset_for_object_elem( + vc->obedit->runtime.select_id, SCE_SELECT_EDGE) : 0, }; mesh_foreachScreenEdge( @@ -1327,7 +1136,7 @@ static bool do_lasso_select_paintvert(ViewContext *vc, if (wm_userdata->data == NULL) { editselect_buf_cache_init_with_generic_userdata(wm_userdata, vc); esel = wm_userdata->data; - const uint buffer_len = ED_view3d_select_id_context_elem_len(esel->sel_id_ctx); + const uint buffer_len = DRW_select_context_elem_len(); esel->select_bitmap = ED_select_buffer_bitmap_from_poly(buffer_len, mcords, moves, &rect); } } @@ -1386,7 +1195,7 @@ static bool do_lasso_select_paintface(ViewContext *vc, if (esel == NULL) { editselect_buf_cache_init_with_generic_userdata(wm_userdata, vc); esel = wm_userdata->data; - const uint buffer_len = ED_view3d_select_id_context_elem_len(esel->sel_id_ctx); + const uint buffer_len = DRW_select_context_elem_len(); esel->select_bitmap = ED_select_buffer_bitmap_from_poly(buffer_len, mcords, moves, &rect); } @@ -2742,7 +2551,7 @@ static bool do_paintvert_box_select(ViewContext *vc, if (wm_userdata->data == NULL) { editselect_buf_cache_init_with_generic_userdata(wm_userdata, vc); esel = wm_userdata->data; - const uint buffer_len = ED_view3d_select_id_context_elem_len(esel->sel_id_ctx); + const uint buffer_len = DRW_select_context_elem_len(); esel->select_bitmap = ED_select_buffer_bitmap_from_rect(buffer_len, rect); } if (esel->select_bitmap != NULL) { @@ -2797,7 +2606,7 @@ static bool do_paintface_box_select(ViewContext *vc, if (wm_userdata->data == NULL) { editselect_buf_cache_init_with_generic_userdata(wm_userdata, vc); esel = wm_userdata->data; - const uint buffer_len = ED_view3d_select_id_context_elem_len(esel->sel_id_ctx); + const uint buffer_len = DRW_select_context_elem_len(); esel->select_bitmap = ED_select_buffer_bitmap_from_rect(buffer_len, rect); } if (esel->select_bitmap != NULL) { @@ -2995,7 +2804,7 @@ static bool do_mesh_box_select(ViewContext *vc, if (wm_userdata->data == NULL) { editselect_buf_cache_init_with_generic_userdata(wm_userdata, vc); esel = wm_userdata->data; - const uint buffer_len = ED_view3d_select_id_context_elem_len(esel->sel_id_ctx); + const uint buffer_len = DRW_select_context_elem_len(); esel->select_bitmap = ED_select_buffer_bitmap_from_rect(buffer_len, rect); } } @@ -3014,10 +2823,8 @@ static bool do_mesh_box_select(ViewContext *vc, struct BoxSelectUserData_ForMeshEdge cb_data = { .data = &data, .esel = use_zbuf ? esel : NULL, - .backbuf_offset = use_zbuf ? ED_view3d_select_id_context_offset_for_object_elem( - esel->sel_id_ctx, - vc->obedit->runtime.select_id, - SCE_SELECT_EDGE) : + .backbuf_offset = use_zbuf ? DRW_select_context_offset_for_object_elem( + vc->obedit->runtime.select_id, SCE_SELECT_EDGE) : 0, }; mesh_foreachScreenEdge( @@ -3582,8 +3389,7 @@ static bool mesh_circle_select(ViewContext *vc, struct EditSelectBuf_Cache *esel = wm_userdata->data; if (use_zbuf) { - ED_view3d_select_id_validate_view_matrices(esel->sel_id_ctx, vc); - const uint buffer_len = ED_view3d_select_id_context_elem_len(esel->sel_id_ctx); + const uint buffer_len = DRW_select_context_elem_len(); esel->select_bitmap = ED_select_buffer_bitmap_from_circle(buffer_len, mval, (int)(rad + 1.0f)); } @@ -3660,7 +3466,7 @@ static bool paint_facesel_circle_select(ViewContext *vc, { struct EditSelectBuf_Cache *esel = wm_userdata->data; - const uint buffer_len = ED_view3d_select_id_context_elem_len(esel->sel_id_ctx); + const uint buffer_len = DRW_select_context_elem_len(); esel->select_bitmap = ED_select_buffer_bitmap_from_circle(buffer_len, mval, (int)(rad + 1.0f)); if (esel->select_bitmap != NULL) { changed |= edbm_backbuf_check_and_select_faces_obmode(me, esel, sel_op); @@ -3715,7 +3521,7 @@ static bool paint_vertsel_circle_select(ViewContext *vc, if (use_zbuf) { struct EditSelectBuf_Cache *esel = wm_userdata->data; - const uint buffer_len = ED_view3d_select_id_context_elem_len(esel->sel_id_ctx); + const uint buffer_len = DRW_select_context_elem_len(); esel->select_bitmap = ED_select_buffer_bitmap_from_circle(buffer_len, mval, (int)(rad + 1.0f)); if (esel->select_bitmap != NULL) { changed |= edbm_backbuf_check_and_select_verts_obmode(me, esel, sel_op); @@ -4150,7 +3956,7 @@ static int view3d_circle_select_exec(bContext *C, wmOperator *op) const int radius = RNA_int_get(op->ptr, "radius"); const int mval[2] = {RNA_int_get(op->ptr, "x"), RNA_int_get(op->ptr, "y")}; - /* Allow each selection type to allocate their own data thats used between executions. */ + /* Allow each selection type to allocate their own data that's used between executions. */ wmGesture *gesture = op->customdata; /* NULL when non-modal. */ wmGenericUserData wm_userdata_buf = {0}; wmGenericUserData *wm_userdata = gesture ? &gesture->user_data : &wm_userdata_buf; diff --git a/source/blender/editors/space_view3d/view3d_snap.c b/source/blender/editors/space_view3d/view3d_snap.c index 0103fd0df53..9a2f4062631 100644 --- a/source/blender/editors/space_view3d/view3d_snap.c +++ b/source/blender/editors/space_view3d/view3d_snap.c @@ -66,7 +66,7 @@ static bool snap_calc_active_center(bContext *C, const bool select_only, float r /** Snaps every individual object center to its nearest point on the grid. */ static int snap_sel_to_grid_exec(bContext *C, wmOperator *UNUSED(op)) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); ViewLayer *view_layer_eval = DEG_get_evaluated_view_layer(depsgraph); Object *obedit = CTX_data_edit_object(C); Scene *scene = CTX_data_scene(C); @@ -226,7 +226,7 @@ void VIEW3D_OT_snap_selected_to_grid(wmOperatorType *ot) ot->poll = ED_operator_region_view3d_active; /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /* *************************************************** */ @@ -243,7 +243,6 @@ static int snap_selected_to_location(bContext *C, const float snap_target_global[3], const bool use_offset) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *scene = CTX_data_scene(C); Object *obedit = CTX_data_edit_object(C); Object *obact = CTX_data_active_object(C); @@ -431,6 +430,7 @@ static int snap_selected_to_location(bContext *C, float originmat[3][3], parentmat[4][4]; /* Use the evaluated object here because sometimes * `ob->parent->runtime.curve_cache` is required. */ + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); BKE_object_get_parent_matrix(ob_eval, ob_eval->parent, parentmat); @@ -486,7 +486,7 @@ void VIEW3D_OT_snap_selected_to_cursor(wmOperatorType *ot) ot->poll = ED_operator_view3d_active; /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* rna */ RNA_def_boolean(ot->srna, @@ -523,7 +523,7 @@ void VIEW3D_OT_snap_selected_to_active(wmOperatorType *ot) ot->poll = ED_operator_view3d_active; /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /* *************************************************** */ @@ -626,7 +626,7 @@ static void bundle_midpoint(Scene *scene, Object *ob, float r_vec[3]) /** Snaps the 3D cursor location to the median point of the selection. */ static bool snap_curs_to_sel_ex(bContext *C, float cursor[3]) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); ViewLayer *view_layer_eval = DEG_get_evaluated_view_layer(depsgraph); Object *obedit = CTX_data_edit_object(C); Scene *scene = CTX_data_scene(C); @@ -757,7 +757,7 @@ void VIEW3D_OT_snap_cursor_to_selected(wmOperatorType *ot) ot->poll = ED_operator_view3d_active; /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /* ********************************************** */ @@ -804,7 +804,7 @@ void VIEW3D_OT_snap_cursor_to_active(wmOperatorType *ot) ot->poll = ED_operator_view3d_active; /* flags */ - ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_USE_EVAL_DATA; + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; } /* **************************************************** */ diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index c0902cd1cd5..2515ee6e482 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -304,7 +304,7 @@ void ED_view3d_smooth_view(bContext *C, const int smooth_viewtx, const struct V3D_SmoothParams *sview) { - const Depsgraph *depsgraph = CTX_data_depsgraph(C); + const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); wmWindowManager *wm = CTX_wm_manager(C); wmWindow *win = CTX_wm_window(C); ScrArea *sa = CTX_wm_area(C); @@ -315,7 +315,6 @@ void ED_view3d_smooth_view(bContext *C, /* only meant for timer usage */ static void view3d_smoothview_apply(bContext *C, View3D *v3d, ARegion *ar, bool sync_boxview) { - const Depsgraph *depsgraph = CTX_data_depsgraph(C); RegionView3D *rv3d = ar->regiondata; struct SmoothView3DStore *sms = rv3d->sms; float step, step_inv; @@ -336,6 +335,8 @@ static void view3d_smoothview_apply(bContext *C, View3D *v3d, ARegion *ar, bool view3d_smooth_view_state_restore(&sms->org, v3d, rv3d); } else { + const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); + view3d_smooth_view_state_restore(&sms->dst, v3d, rv3d); ED_view3d_camera_lock_sync(depsgraph, v3d, rv3d); @@ -372,6 +373,7 @@ static void view3d_smoothview_apply(bContext *C, View3D *v3d, ARegion *ar, bool rv3d->dist = sms->dst.dist * step + sms->src.dist * step_inv; v3d->lens = sms->dst.lens * step + sms->src.lens * step_inv; + const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); ED_view3d_camera_lock_sync(depsgraph, v3d, rv3d); if (ED_screen_animation_playing(CTX_wm_manager(C))) { ED_view3d_camera_lock_autokey(v3d, rv3d, C, true, true); @@ -428,7 +430,7 @@ void ED_view3d_smooth_view_force_finish(bContext *C, View3D *v3d, ARegion *ar) /* force update of view matrix so tools that run immediately after * can use them without redrawing first */ - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene = CTX_data_scene(C); ED_view3d_update_viewmat(depsgraph, scene, v3d, ar, NULL, NULL, NULL, false); } @@ -457,7 +459,7 @@ void VIEW3D_OT_smoothview(wmOperatorType *ot) static int view3d_camera_to_view_exec(bContext *C, wmOperator *UNUSED(op)) { - const Depsgraph *depsgraph = CTX_data_depsgraph(C); + const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); View3D *v3d; ARegion *ar; RegionView3D *rv3d; @@ -527,7 +529,7 @@ void VIEW3D_OT_camera_to_view(wmOperatorType *ot) * meant to take into account vertex/bone selection for eg. */ static int view3d_camera_to_view_selected_exec(bContext *C, wmOperator *op) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene = CTX_data_scene(C); View3D *v3d = CTX_wm_view3d(C); /* can be NULL */ Object *camera_ob = v3d ? v3d->camera : scene->camera; @@ -1413,7 +1415,7 @@ static void view3d_localview_exit(const Depsgraph *depsgraph, static int localview_exec(bContext *C, wmOperator *op) { - const Depsgraph *depsgraph = CTX_data_depsgraph(C); + const Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); wmWindowManager *wm = CTX_wm_manager(C); wmWindow *win = CTX_wm_window(C); diff --git a/source/blender/editors/space_view3d/view3d_walk.c b/source/blender/editors/space_view3d/view3d_walk.c index 853955a4078..c5585857b55 100644 --- a/source/blender/editors/space_view3d/view3d_walk.c +++ b/source/blender/editors/space_view3d/view3d_walk.c @@ -426,7 +426,7 @@ static bool initWalkInfo(bContext *C, WalkInfo *walk, wmOperator *op) walk->rv3d = CTX_wm_region_view3d(C); walk->v3d = CTX_wm_view3d(C); walk->ar = CTX_wm_region(C); - walk->depsgraph = CTX_data_depsgraph(C); + walk->depsgraph = CTX_data_ensure_evaluated_depsgraph(C); walk->scene = CTX_data_scene(C); #ifdef NDOF_WALK_DEBUG @@ -520,7 +520,7 @@ static bool initWalkInfo(bContext *C, WalkInfo *walk, wmOperator *op) walk->rv3d->rflag |= RV3D_NAVIGATING; walk->snap_context = ED_transform_snap_object_context_create_view3d( - bmain, walk->scene, CTX_data_depsgraph(C), 0, walk->ar, walk->v3d); + bmain, walk->scene, CTX_data_ensure_evaluated_depsgraph(C), 0, walk->ar, walk->v3d); walk->v3d_camera_control = ED_view3d_cameracontrol_acquire( walk->depsgraph, diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index a316567fc63..5ef86c71d2d 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -1595,11 +1595,8 @@ int transformEvent(TransInfo *t, const wmEvent *event) } /* confirm transform if launch key is released after mouse move */ - if (t->flag & T_RELEASE_CONFIRM) { - /* XXX Keyrepeat bug in Xorg messes this up, will test when fixed */ - if ((event->type == t->launch_event) && ISMOUSE(t->launch_event)) { - t->state = TRANS_CONFIRM; - } + if ((t->flag & T_RELEASE_CONFIRM) && event->type == t->launch_event) { + t->state = TRANS_CONFIRM; } } @@ -2157,16 +2154,6 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op) } } - /* do we check for parameter? */ - if (transformModeUseSnap(t)) { - if (t->modifiers & MOD_SNAP) { - ts->snap_flag |= SCE_SNAP; - } - else { - ts->snap_flag &= ~SCE_SNAP; - } - } - if (t->spacetype == SPACE_VIEW3D) { if ((prop = RNA_struct_find_property(op->ptr, "orient_type")) && !RNA_property_is_set(op->ptr, prop) && @@ -2180,6 +2167,18 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op) } } + if (t->flag & T_MODAL) { + /* do we check for parameter? */ + if (transformModeUseSnap(t)) { + if (t->modifiers & MOD_SNAP) { + ts->snap_flag |= SCE_SNAP; + } + else { + ts->snap_flag &= ~SCE_SNAP; + } + } + } + if ((prop = RNA_struct_find_property(op->ptr, "use_proportional_edit"))) { RNA_property_boolean_set(op->ptr, prop, proportional & PROP_EDIT_USE); RNA_boolean_set(op->ptr, "use_proportional_connected", proportional & PROP_EDIT_CONNECTED); @@ -4581,17 +4580,42 @@ static void ElementRotation( ElementRotation_ex(t, tc, td, mat, center); } -static void applyRotationValue(TransInfo *t, float angle, float axis[3]) +static float large_rotation_limit(float angle) +{ + /* Limit rotation to 1001 turns max + * (otherwise iterative handling of 'large' rotations would become too slow). */ + const float angle_max = (float)(M_PI * 2000.0); + if (fabsf(angle) > angle_max) { + const float angle_sign = angle < 0.0f ? -1.0f : 1.0f; + angle = angle_sign * (fmodf(fabsf(angle), (float)(M_PI * 2.0)) + angle_max); + } + return angle; +} + +static void applyRotationValue(TransInfo *t, + float angle, + float axis[3], + const bool is_large_rotation) { float mat[3][3]; int i; + const float angle_sign = angle < 0.0f ? -1.0f : 1.0f; + /* We cannot use something too close to 180°, or 'continuous' rotation may fail + * due to computing error... */ + const float angle_step = angle_sign * (float)(0.9 * M_PI); + + if (is_large_rotation) { + /* Just in case, calling code should have already done that in practice + * (for UI feedback reasons). */ + angle = large_rotation_limit(angle); + } + axis_angle_normalized_to_mat3(mat, axis, angle); FOREACH_TRANS_DATA_CONTAINER (t, tc) { TransData *td = tc->data; for (i = 0; i < tc->data_len; i++, td++) { - if (td->flag & TD_NOACTION) { break; } @@ -4600,14 +4624,37 @@ static void applyRotationValue(TransInfo *t, float angle, float axis[3]) continue; } + float angle_final = angle; if (t->con.applyRot) { t->con.applyRot(t, tc, td, axis, NULL); - axis_angle_normalized_to_mat3(mat, axis, angle * td->factor); + angle_final = angle * td->factor; } else if (t->flag & T_PROP_EDIT) { - axis_angle_normalized_to_mat3(mat, axis, angle * td->factor); + angle_final = angle * td->factor; + } + + /* Rotation is very likely to be above 180°, we need to do rotation by steps. + * Note that this is only needed when doing 'absolute' rotation + * (i.e. from initial rotation again, typically when using numinput). + * regular incremental rotation (from mouse/widget/...) will be called often enough, + * hence steps are small enough to be properly handled without that complicated trick. + * Note that we can only do that kind of stepped rotation if we have initial rotation values + * (and access to some actual rotation value storage). + * Otherwise, just assume it's useless (e.g. in case of mesh/UV/etc. editing). + * Also need to be in Euler rotation mode, the others never allow more than one turn anyway. + */ + if (is_large_rotation && td->ext != NULL && td->ext->rotOrder == ROT_MODE_EUL) { + copy_v3_v3(td->ext->rot, td->ext->irot); + for (float angle_progress = angle_step; fabsf(angle_progress) < fabsf(angle_final); + angle_progress += angle_step) { + axis_angle_normalized_to_mat3(mat, axis, angle_progress); + ElementRotation(t, tc, td, mat, t->around); + } + axis_angle_normalized_to_mat3(mat, axis, angle_final); + } + else if (angle_final != angle) { + axis_angle_normalized_to_mat3(mat, axis, angle_final); } - ElementRotation(t, tc, td, mat, t->around); } } @@ -4632,15 +4679,18 @@ static void applyRotation(TransInfo *t, const int UNUSED(mval[2])) applySnapping(t, &final); - /* Used to clamp final result in [-PI, PI[ range, no idea why, - * inheritance from 2.4x area, see T48998. */ - applyNumInput(&t->num, &final); + if (applyNumInput(&t->num, &final)) { + /* We have to limit the amount of turns to a reasonable number here, + * to avoid things getting *very* slow, see how applyRotationValue() handles those... */ + final = large_rotation_limit(final); + } t->values[0] = final; headerRotation(t, str, final); - applyRotationValue(t, final, axis_final); + const bool is_large_rotation = hasNumInput(&t->num); + applyRotationValue(t, final, axis_final, is_large_rotation); recalcData(t); diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h index b0f720bfdf7..833792379ae 100644 --- a/source/blender/editors/transform/transform.h +++ b/source/blender/editors/transform/transform.h @@ -102,7 +102,7 @@ typedef struct TransSnap { * Get the transform distance between two points (used by Closest snap) * * \note Return value can be anything, - * where the smallest absolute value defines whats closest. + * where the smallest absolute value defines what's closest. */ float (*distance)(struct TransInfo *t, const float p1[3], const float p2[3]); diff --git a/source/blender/editors/transform/transform_constraints.c b/source/blender/editors/transform/transform_constraints.c index 208242d53b3..3a204d0d157 100644 --- a/source/blender/editors/transform/transform_constraints.c +++ b/source/blender/editors/transform/transform_constraints.c @@ -263,9 +263,8 @@ static void axisProjection(const TransInfo *t, /* Use ray-ray intersection instead of line-line because this gave * precision issues adding small values to large numbers. */ float mul; - if (isect_ray_ray_v3(v, norm, t_con_center, axis, &mul, NULL)) { - madd_v3_v3v3fl(out, t_con_center, axis, mul); - sub_v3_v3(out, t_con_center); + if (isect_ray_ray_v3(t_con_center, axis, v, norm, &mul, NULL)) { + mul_v3_v3fl(out, axis, mul); } else { /* In practice this should never fail. */ diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c index d13c0f8e8f1..4eccf4c5071 100644 --- a/source/blender/editors/transform/transform_conversions.c +++ b/source/blender/editors/transform/transform_conversions.c @@ -6133,6 +6133,8 @@ static void freeSeqData(TransInfo *t, TransDataContainer *tc, TransCustomData *c MEM_freeN(custom_data->data); custom_data->data = NULL; } + + DEG_id_tag_update(&t->scene->id, ID_RECALC_SEQUENCER_STRIPS); } static void createTransSeqData(bContext *C, TransInfo *t) @@ -6629,7 +6631,6 @@ void autokeyframe_object(bContext *C, Scene *scene, ViewLayer *view_layer, Objec // TODO: this should probably be done per channel instead... if (autokeyframe_cfra_can_key(scene, id)) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); ReportList *reports = CTX_wm_reports(C); ToolSettings *ts = scene->toolsettings; KeyingSet *active_ks = ANIM_scene_get_active_keyingset(scene); @@ -6656,11 +6657,9 @@ void autokeyframe_object(bContext *C, Scene *scene, ViewLayer *view_layer, Objec /* only key on available channels */ if (adt && adt->action) { ListBase nla_cache = {NULL, NULL}; - for (fcu = adt->action->curves.first; fcu; fcu = fcu->next) { fcu->flag &= ~FCURVE_SELECTED; insert_keyframe(bmain, - depsgraph, reports, id, adt->action, @@ -6775,7 +6774,6 @@ void autokeyframe_pose(bContext *C, Scene *scene, Object *ob, int tmode, short t // TODO: this should probably be done per channel instead... if (autokeyframe_cfra_can_key(scene, id)) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); ReportList *reports = CTX_wm_reports(C); ToolSettings *ts = scene->toolsettings; KeyingSet *active_ks = ANIM_scene_get_active_keyingset(scene); @@ -6823,7 +6821,6 @@ void autokeyframe_pose(bContext *C, Scene *scene, Object *ob, int tmode, short t */ if (pchanName && STREQ(pchanName, pchan->name)) { insert_keyframe(bmain, - depsgraph, reports, id, act, @@ -9018,7 +9015,7 @@ static void createTransGPencil_center_get(bGPDstroke *gps, float r_center[3]) static void createTransGPencil(bContext *C, TransInfo *t) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); bGPdata *gpd = ED_gpencil_data_get_active(C); ToolSettings *ts = CTX_data_tool_settings(C); diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c index 4a9584ed9be..969e2558abb 100644 --- a/source/blender/editors/transform/transform_generics.c +++ b/source/blender/editors/transform/transform_generics.c @@ -1391,7 +1391,6 @@ void initTransDataContainers_FromObjectData(TransInfo *t, */ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *event) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); Scene *sce = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); const eObjectMode object_mode = OBACT(view_layer) ? OBACT(view_layer)->mode : OB_MODE_OBJECT; @@ -1403,7 +1402,7 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve bGPdata *gpd = CTX_data_gpencil_data(C); PropertyRNA *prop; - t->depsgraph = depsgraph; + t->depsgraph = CTX_data_depsgraph_pointer(C); t->scene = sce; t->view_layer = view_layer; t->sa = sa; @@ -1692,7 +1691,8 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve } } else { - if (U.flag & USER_RELEASECONFIRM) { + if (ISMOUSE(t->launch_event) && (U.flag & USER_RELEASECONFIRM)) { + /* Global "release confirm" on mouse bindings */ t->flag |= T_RELEASE_CONFIRM; } } diff --git a/source/blender/editors/transform/transform_gizmo_3d.c b/source/blender/editors/transform/transform_gizmo_3d.c index a883b5b6ba5..fbfeb4f53de 100644 --- a/source/blender/editors/transform/transform_gizmo_3d.c +++ b/source/blender/editors/transform/transform_gizmo_3d.c @@ -731,7 +731,9 @@ int ED_transform_calc_gizmo_stats(const bContext *C, ScrArea *sa = CTX_wm_area(C); ARegion *ar = CTX_wm_region(C); Scene *scene = CTX_data_scene(C); - Depsgraph *depsgraph = CTX_data_depsgraph(C); + /* TODO(sergey): This function is used from operator's modal() and from gizmo's refresh(). + * Is it fine to possibly evaluate dependency graph here? */ + Depsgraph *depsgraph = CTX_data_expect_evaluated_depsgraph(C); ViewLayer *view_layer = CTX_data_view_layer(C); View3D *v3d = sa->spacedata.first; Object *obedit = CTX_data_edit_object(C); diff --git a/source/blender/editors/undo/ed_undo.c b/source/blender/editors/undo/ed_undo.c index 183e140169d..c84d7539cce 100644 --- a/source/blender/editors/undo/ed_undo.c +++ b/source/blender/editors/undo/ed_undo.c @@ -568,15 +568,6 @@ int ED_undo_operator_repeat(bContext *C, wmOperator *op) } } - if (op->type->flag & OPTYPE_USE_EVAL_DATA) { - /* We need to force refresh of depsgraph after undo step, - * redoing the operator *may* rely on some valid evaluated data. */ - Main *bmain = CTX_data_main(C); - scene = CTX_data_scene(C); - ViewLayer *view_layer = CTX_data_view_layer(C); - BKE_scene_view_layer_graph_evaluated_ensure(bmain, scene, view_layer); - } - retval = WM_operator_repeat(C, op); if ((retval & OPERATOR_FINISHED) == 0) { if (G.debug & G_DEBUG) { @@ -748,7 +739,7 @@ void ED_undo_object_editmode_restore_helper(struct bContext *C, Main *bmain = CTX_data_main(C); ViewLayer *view_layer = CTX_data_view_layer(C); uint bases_len = 0; - /* Don't request unique data because we wan't to de-select objects when exiting edit-mode + /* Don't request unique data because we want to de-select objects when exiting edit-mode * for that to be done on all objects we can't skip ones that share data. */ Base **bases = BKE_view_layer_array_from_bases_in_edit_mode(view_layer, NULL, &bases_len); for (uint i = 0; i < bases_len; i++) { diff --git a/source/blender/editors/util/ed_util.c b/source/blender/editors/util/ed_util.c index c1b6a7b42b2..c2566d111cf 100644 --- a/source/blender/editors/util/ed_util.c +++ b/source/blender/editors/util/ed_util.c @@ -99,7 +99,7 @@ void ED_editors_init_for_undo(Main *bmain) void ED_editors_init(bContext *C) { - struct Depsgraph *depsgraph = CTX_data_depsgraph(C); + struct Depsgraph *depsgraph = CTX_data_expect_evaluated_depsgraph(C); Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); wmWindowManager *wm = CTX_wm_manager(C); diff --git a/source/blender/editors/util/select_buffer_utils.c b/source/blender/editors/util/select_buffer_utils.c index 79f0f48830e..2201ee5cec2 100644 --- a/source/blender/editors/util/select_buffer_utils.c +++ b/source/blender/editors/util/select_buffer_utils.c @@ -216,7 +216,7 @@ uint ED_select_buffer_sample_point(const int center[2]) /** * Find the selection id closest to \a center. * \param dist[in,out]: Use to initialize the distance, - * when found, this value is set to the distance of the selection thats returned. + * when found, this value is set to the distance of the selection that's returned. */ uint ED_select_buffer_find_nearest_to_point(const int center[2], const uint id_min, diff --git a/source/blender/editors/uvedit/uvedit_buttons.c b/source/blender/editors/uvedit/uvedit_buttons.c index 1482fea456d..2abbe67237e 100644 --- a/source/blender/editors/uvedit/uvedit_buttons.c +++ b/source/blender/editors/uvedit/uvedit_buttons.c @@ -40,8 +40,9 @@ #include "BKE_context.h" #include "BKE_customdata.h" -#include "BKE_screen.h" #include "BKE_editmesh.h" +#include "BKE_layer.h" +#include "BKE_screen.h" #include "DEG_depsgraph.h" @@ -57,7 +58,8 @@ /* UV Utilities */ -static int uvedit_center(Scene *scene, Object *obedit, BMEditMesh *em, Image *ima, float center[2]) +static int uvedit_center( + Scene *scene, Object **objects, uint objects_len, Image *ima, float center[2]) { BMFace *f; BMLoop *l; @@ -65,19 +67,24 @@ static int uvedit_center(Scene *scene, Object *obedit, BMEditMesh *em, Image *im MLoopUV *luv; int tot = 0; - const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); - zero_v2(center); - BM_ITER_MESH (f, &iter, em->bm, BM_FACES_OF_MESH) { - if (!uvedit_face_visible_test(scene, obedit, ima, f)) { - continue; - } - BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) { - if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { - luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); - add_v2_v2(center, luv->uv); - tot++; + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; + BMEditMesh *em = BKE_editmesh_from_object(obedit); + const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); + + BM_ITER_MESH (f, &iter, em->bm, BM_FACES_OF_MESH) { + if (!uvedit_face_visible_test(scene, obedit, ima, f)) { + continue; + } + + BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) { + if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { + luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); + add_v2_v2(center, luv->uv); + tot++; + } } } } @@ -91,24 +98,29 @@ static int uvedit_center(Scene *scene, Object *obedit, BMEditMesh *em, Image *im } static void uvedit_translate( - Scene *scene, Object *obedit, BMEditMesh *em, Image *ima, float delta[2]) + Scene *scene, Object **objects, uint objects_len, Image *ima, float delta[2]) { BMFace *f; BMLoop *l; BMIter iter, liter; MLoopUV *luv; - const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; + BMEditMesh *em = BKE_editmesh_from_object(obedit); - BM_ITER_MESH (f, &iter, em->bm, BM_FACES_OF_MESH) { - if (!uvedit_face_visible_test(scene, obedit, ima, f)) { - continue; - } + const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV); - BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) { - if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { - luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); - add_v2_v2(luv->uv, delta); + BM_ITER_MESH (f, &iter, em->bm, BM_FACES_OF_MESH) { + if (!uvedit_face_visible_test(scene, obedit, ima, f)) { + continue; + } + + BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) { + if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) { + luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); + add_v2_v2(luv->uv, delta); + } } } } @@ -122,18 +134,17 @@ static void uvedit_vertex_buttons(const bContext *C, uiBlock *block) { SpaceImage *sima = CTX_wm_space_image(C); Scene *scene = CTX_data_scene(C); - Object *obedit = CTX_data_edit_object(C); Image *ima = sima->image; - BMEditMesh *em; float center[2]; int imx, imy, step, digits; float width = 8 * UI_UNIT_X; + uint objects_len = 0; + Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs( + CTX_data_view_layer(C), CTX_wm_view3d(C), &objects_len); ED_space_image_get_size(sima, &imx, &imy); - em = BKE_editmesh_from_object(obedit); - - if (uvedit_center(scene, obedit, em, ima, center)) { + if (uvedit_center(scene, objects, objects_len, ima, center)) { float range_xy[2][2] = { {-10.0f, 10.0f}, {-10.0f, 10.0f}, @@ -193,15 +204,15 @@ static void uvedit_vertex_buttons(const bContext *C, uiBlock *block) ""); UI_block_align_end(block); } + + MEM_freeN(objects); } static void do_uvedit_vertex(bContext *C, void *UNUSED(arg), int event) { SpaceImage *sima = CTX_wm_space_image(C); Scene *scene = CTX_data_scene(C); - Object *obedit = CTX_data_edit_object(C); Image *ima = sima->image; - BMEditMesh *em; float center[2], delta[2]; int imx, imy; @@ -209,10 +220,12 @@ static void do_uvedit_vertex(bContext *C, void *UNUSED(arg), int event) return; } - em = BKE_editmesh_from_object(obedit); + uint objects_len = 0; + Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs( + CTX_data_view_layer(C), CTX_wm_view3d(C), &objects_len); ED_space_image_get_size(sima, &imx, &imy); - uvedit_center(scene, obedit, em, ima, center); + uvedit_center(scene, objects, objects_len, ima, center); if (sima->flag & SI_COORDFLOATS) { delta[0] = uvedit_old_center[0] - center[0]; @@ -223,10 +236,15 @@ static void do_uvedit_vertex(bContext *C, void *UNUSED(arg), int event) delta[1] = uvedit_old_center[1] / imy - center[1]; } - uvedit_translate(scene, obedit, em, ima, delta); + uvedit_translate(scene, objects, objects_len, ima, delta); WM_event_add_notifier(C, NC_IMAGE, sima->image); - DEG_id_tag_update((ID *)obedit->data, ID_RECALC_GEOMETRY); + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; + DEG_id_tag_update((ID *)obedit->data, ID_RECALC_GEOMETRY); + } + + MEM_freeN(objects); } /* Panels */ diff --git a/source/blender/editors/uvedit/uvedit_ops.c b/source/blender/editors/uvedit/uvedit_ops.c index 71bf6a1946a..6a2f740ba51 100644 --- a/source/blender/editors/uvedit/uvedit_ops.c +++ b/source/blender/editors/uvedit/uvedit_ops.c @@ -2376,7 +2376,7 @@ static void uv_select_all_perform_multi( static int uv_select_all_exec(bContext *C, wmOperator *op) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene = CTX_data_scene(C); ToolSettings *ts = scene->toolsettings; Image *ima = CTX_data_edit_image(C); @@ -2456,7 +2456,7 @@ static int uv_mouse_select_multi(bContext *C, const bool deselect_all, const bool loop) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); SpaceImage *sima = CTX_wm_space_image(C); Scene *scene = CTX_data_scene(C); ToolSettings *ts = scene->toolsettings; @@ -3429,7 +3429,7 @@ static void uv_select_flush_from_tag_loop(SpaceImage *sima, static int uv_box_select_exec(bContext *C, wmOperator *op) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); SpaceImage *sima = CTX_wm_space_image(C); Scene *scene = CTX_data_scene(C); ToolSettings *ts = scene->toolsettings; @@ -3587,7 +3587,7 @@ static int uv_inside_circle(const float uv[2], const float offset[2], const floa static int uv_circle_select_exec(bContext *C, wmOperator *op) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); SpaceImage *sima = CTX_wm_space_image(C); Image *ima = CTX_data_edit_image(C); Scene *scene = CTX_data_scene(C); @@ -3727,7 +3727,7 @@ static bool do_lasso_select_mesh_uv(bContext *C, short moves, const eSelectOp sel_op) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); SpaceImage *sima = CTX_wm_space_image(C); Image *ima = CTX_data_edit_image(C); ARegion *ar = CTX_wm_region(C); @@ -4278,7 +4278,7 @@ static void UV_OT_pin(wmOperatorType *ot) static int uv_select_pinned_exec(bContext *C, wmOperator *UNUSED(op)) { - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene = CTX_data_scene(C); ToolSettings *ts = scene->toolsettings; ViewLayer *view_layer = CTX_data_view_layer(C); diff --git a/source/blender/freestyle/intern/geometry/FastGrid.h b/source/blender/freestyle/intern/geometry/FastGrid.h index a3b20661fa6..367c233d799 100644 --- a/source/blender/freestyle/intern/geometry/FastGrid.h +++ b/source/blender/freestyle/intern/geometry/FastGrid.h @@ -60,7 +60,7 @@ class FastGrid : public Grid { */ virtual void configure(const Vec3r &orig, const Vec3r &size, unsigned nb); - /*! returns the cell whose coordinates are pased as argument */ + /*! returns the cell whose coordinates are passed as argument */ Cell *getCell(const Vec3u &p); /*! Fills the case p with the cell iCell */ diff --git a/source/blender/freestyle/intern/geometry/GeomCleaner.h b/source/blender/freestyle/intern/geometry/GeomCleaner.h index 253d3553010..1c193e7252e 100644 --- a/source/blender/freestyle/intern/geometry/GeomCleaner.h +++ b/source/blender/freestyle/intern/geometry/GeomCleaner.h @@ -72,7 +72,7 @@ class GeomCleaner { unsigned **oIndices); /*! Compress a SORTED indexed vertex array by eliminating multiple - * appearing occurences of a single vertex. + * appearing occurrences of a single vertex. * iVertices * The SORTED vertex array to compress. * It is organized as a float series of vertex coordinates: XYZXYZXYZ... diff --git a/source/blender/freestyle/intern/geometry/GeomUtils.cpp b/source/blender/freestyle/intern/geometry/GeomUtils.cpp index e6b1c947476..4c4f12faaba 100644 --- a/source/blender/freestyle/intern/geometry/GeomUtils.cpp +++ b/source/blender/freestyle/intern/geometry/GeomUtils.cpp @@ -488,7 +488,7 @@ bool intersectRayTriangle(const Vec3r &orig, } } else { - return false; // ray is parallell to the plane of the triangle + return false; // ray is parallel to the plane of the triangle } u *= inv_det; diff --git a/source/blender/freestyle/intern/geometry/Grid.cpp b/source/blender/freestyle/intern/geometry/Grid.cpp index 4076bfe03df..e3e25796de1 100644 --- a/source/blender/freestyle/intern/geometry/Grid.cpp +++ b/source/blender/freestyle/intern/geometry/Grid.cpp @@ -165,7 +165,7 @@ void Grid::insertOccluder(Polygon3r *occluder) Vec3r min, max; occluder->getBBox(min, max); - // Retrieve the cell x, y, z cordinates associated with these min and max + // Retrieve the cell x, y, z coordinates associated with these min and max Vec3u imax, imin; getCellCoordinates(max, imax); getCellCoordinates(min, imin); @@ -245,7 +245,7 @@ bool Grid::nextRayCell(Vec3u ¤t_cell, Vec3u &next_cell) unsigned coord = 0; // predominant coord(0=x, 1=y, 2=z) // using a parametric equation of a line : B = A + t u, we find the tx, ty and tz respectively - // coresponding to the intersections with the plans: + // corresponding to the intersections with the plans: // x = _cell_size[0], y = _cell_size[1], z = _cell_size[2] for (i = 0; i < 3; i++) { if (_ray_dir[i] == 0) { diff --git a/source/blender/freestyle/intern/geometry/Grid.h b/source/blender/freestyle/intern/geometry/Grid.h index 6090eeb122a..0a9fa5dc85a 100644 --- a/source/blender/freestyle/intern/geometry/Grid.h +++ b/source/blender/freestyle/intern/geometry/Grid.h @@ -243,7 +243,7 @@ class Grid { /*! Fills the case corresponding to coord with the cell */ virtual void fillCell(const Vec3u &coord, Cell &cell) = 0; - /*! returns the cell whose coordinates are pased as argument */ + /*! returns the cell whose coordinates are passed as argument */ virtual Cell *getCell(const Vec3u &coord) = 0; /*! returns the cell containing the point passed as argument. diff --git a/source/blender/freestyle/intern/geometry/HashGrid.h b/source/blender/freestyle/intern/geometry/HashGrid.h index 73751d820ab..4bb92859775 100644 --- a/source/blender/freestyle/intern/geometry/HashGrid.h +++ b/source/blender/freestyle/intern/geometry/HashGrid.h @@ -81,7 +81,7 @@ class HashGrid : public Grid { */ virtual void configure(const Vec3r &orig, const Vec3r &size, unsigned nb); - /*! returns the cell whose coordinates are pased as argument */ + /*! returns the cell whose coordinates are passed as argument */ virtual Cell *getCell(const Vec3u &p) { Cell *found_cell = NULL; diff --git a/source/blender/freestyle/intern/geometry/VecMat.h b/source/blender/freestyle/intern/geometry/VecMat.h index acc593e8ac9..ee1cc42876c 100644 --- a/source/blender/freestyle/intern/geometry/VecMat.h +++ b/source/blender/freestyle/intern/geometry/VecMat.h @@ -474,7 +474,7 @@ template<class T> class HVec3 : public Vec<T, 4> { return this->_coord[3]; } - // Acces to non-homogeneous coordinates in 3D + // Access to non-homogeneous coordinates in 3D inline value_type x() const { return this->_coord[0] / this->_coord[3]; diff --git a/source/blender/freestyle/intern/image/GaussianFilter.h b/source/blender/freestyle/intern/image/GaussianFilter.h index f933e66dc94..f8e2524fa4f 100644 --- a/source/blender/freestyle/intern/image/GaussianFilter.h +++ b/source/blender/freestyle/intern/image/GaussianFilter.h @@ -39,7 +39,7 @@ namespace Freestyle { class GaussianFilter { protected: - /* The mask is a symetrical 2d array (with respect to the middle point). + /* The mask is a symmetrical 2d array (with respect to the middle point). * Thus, M(i,j) = M(-i,j) = M(i,-j) = M(-i,-j). * For this reason, to represent a NxN array (N odd), we only store a ((N+1)/2)x((N+1)/2) array. */ diff --git a/source/blender/freestyle/intern/python/BPy_Iterator.cpp b/source/blender/freestyle/intern/python/BPy_Iterator.cpp index 10417c07f33..d2575b3b5e9 100644 --- a/source/blender/freestyle/intern/python/BPy_Iterator.cpp +++ b/source/blender/freestyle/intern/python/BPy_Iterator.cpp @@ -197,7 +197,7 @@ static PyObject *Iterator_name_get(BPy_Iterator *self, void *UNUSED(closure)) } PyDoc_STRVAR(Iterator_is_begin_doc, - "True if the interator points the first element.\n" + "True if the iterator points to the first element.\n" "\n" ":type: bool"); @@ -207,7 +207,7 @@ static PyObject *Iterator_is_begin_get(BPy_Iterator *self, void *UNUSED(closure) } PyDoc_STRVAR(Iterator_is_end_doc, - "True if the interator points the last element.\n" + "True if the iterator points to the last element.\n" "\n" ":type: bool"); diff --git a/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp b/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp index 505566d3515..e3d6738058e 100644 --- a/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp +++ b/source/blender/freestyle/intern/python/BPy_StrokeAttribute.cpp @@ -241,7 +241,7 @@ PyDoc_STRVAR(StrokeAttribute_has_attribute_real_doc, "\n" " :arg name: The name of the attribute.\n" " :type name: str\n" - " :return: True if the attribute is availbale.\n" + " :return: True if the attribute is available.\n" " :rtype: bool\n"); static PyObject *StrokeAttribute_has_attribute_real(BPy_StrokeAttribute *self, @@ -265,7 +265,7 @@ PyDoc_STRVAR(StrokeAttribute_has_attribute_vec2_doc, "\n" " :arg name: The name of the attribute.\n" " :type name: str\n" - " :return: True if the attribute is availbale.\n" + " :return: True if the attribute is available.\n" " :rtype: bool\n"); static PyObject *StrokeAttribute_has_attribute_vec2(BPy_StrokeAttribute *self, @@ -289,7 +289,7 @@ PyDoc_STRVAR(StrokeAttribute_has_attribute_vec3_doc, "\n" " :arg name: The name of the attribute.\n" " :type name: str\n" - " :return: True if the attribute is availbale.\n" + " :return: True if the attribute is available.\n" " :rtype: bool\n"); static PyObject *StrokeAttribute_has_attribute_vec3(BPy_StrokeAttribute *self, diff --git a/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.cpp b/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.cpp index 8e619ec95a4..49cd98376c5 100644 --- a/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.cpp +++ b/source/blender/freestyle/intern/python/Interface0D/BPy_CurvePoint.cpp @@ -45,7 +45,7 @@ PyDoc_STRVAR(CurvePoint_doc, "\n" ".. method:: __init__()\n" "\n" - " Defult constructor.\n" + " Default constructor.\n" "\n" ".. method:: __init__(brother)\n" "\n" diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.cpp index b33ebc0f4ef..abc10b75ea1 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_CurvePointIterator.cpp @@ -35,7 +35,7 @@ PyDoc_STRVAR(CurvePointIterator_doc, "Class hierarchy: :class:`Iterator` > :class:`CurvePointIterator`\n" "\n" "Class representing an iterator on a curve. Allows an iterating\n" - "outside initial vertices. A CurvePoint is instanciated and returned\n" + "outside initial vertices. A CurvePoint is instantiated and returned\n" "through the .object attribute.\n" "\n" ".. method:: __init__()\n" diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp index 13a981920f3..8428badc0fd 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_Interface0DIterator.cpp @@ -180,7 +180,7 @@ static PyObject *Interface0DIterator_u_get(BPy_Interface0DIterator *self, void * } PyDoc_STRVAR(Interface0DIterator_at_last_doc, - "True if the interator points to the last valid element.\n" + "True if the iterator points to the last valid element.\n" "For its counterpart (pointing to the first valid element), use it.is_begin.\n" "\n" ":type: bool"); diff --git a/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp b/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp index 70de25aaf84..4269dfb3cdd 100644 --- a/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp +++ b/source/blender/freestyle/intern/python/Iterator/BPy_StrokeVertexIterator.cpp @@ -254,7 +254,7 @@ static PyObject *StrokeVertexIterator_u_get(BPy_StrokeVertexIterator *self, void } PyDoc_STRVAR(StrokeVertexIterator_at_last_doc, - "True if the interator points to the last valid element.\n" + "True if the iterator points to the last valid element.\n" "For its counterpart (pointing to the first valid element), use it.is_begin.\n" "\n" ":type: bool"); diff --git a/source/blender/freestyle/intern/python/StrokeShader/BPy_CalligraphicShader.cpp b/source/blender/freestyle/intern/python/StrokeShader/BPy_CalligraphicShader.cpp index 98b50f2112c..27af7207b97 100644 --- a/source/blender/freestyle/intern/python/StrokeShader/BPy_CalligraphicShader.cpp +++ b/source/blender/freestyle/intern/python/StrokeShader/BPy_CalligraphicShader.cpp @@ -57,8 +57,8 @@ static char CalligraphicShader___doc__[] = "\n" " Assigns thicknesses to the stroke vertices so that the stroke looks\n" " like made with a calligraphic tool, i.e. the stroke will be the\n" - " thickest in a main direction, and the thinest in the direction\n" - " perpendicular to this one, and an interpolation inbetween.\n" + " thickest in a main direction, and the thinnest in the direction\n" + " perpendicular to this one, and an interpolation in between.\n" "\n" " :arg stroke: A Stroke object.\n" " :type stroke: :class:`freestyle.types.Stroke`\n"; diff --git a/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.h b/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.h index 5163a0af07e..d70794d9b78 100644 --- a/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.h +++ b/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.h @@ -42,7 +42,7 @@ class IndexedFaceSet : public Rep { }; /*! User-specified face and edge marks for feature edge detection */ - /* XXX Why in hel not use an enum here too? */ + /* XXX Why in hell not use an enum here too? */ typedef unsigned char FaceEdgeMark; static const FaceEdgeMark FACE_MARK = 1 << 0; static const FaceEdgeMark EDGE_MARK_V1V2 = 1 << 1; @@ -55,12 +55,12 @@ class IndexedFaceSet : public Rep { /*! Builds an indexed face set * iVertices * The array of object vertices 3D coordinates (for all faces). - * If iCopy != 0, the array is copied; you must desallocate iVertices. Else you must not. + * If iCopy != 0, the array is copied; you must deallocate iVertices. Else you must not. * iVSize * The size of iVertices (must be a multiple of 3) * iNormals * The array of object normals 3D coordinates. - * If iCopy != 0, the array is copied; you must desallocate iNormals. Else you must not. + * If iCopy != 0, the array is copied; you must deallocate iNormals. Else you must not. * iNSize * The size of iNormals * iMaterials @@ -81,17 +81,17 @@ class IndexedFaceSet : public Rep { * - TRIANGLE_STRIP: the face indices describe a triangle strip * - TRIANGLE_FAN : the face indices describe a triangle fan * - TRIANGLES : the face indices describe single triangles - * If iCopy != 0, the array is copied; you must desallocate iFaceStyle. Else you must not. + * If iCopy != 0, the array is copied; you must deallocate iFaceStyle. Else you must not. * iVIndices, * Array of vertices indices. * The integers contained in this array must be multiple of 3. - * If iCopy != 0, the array is copied; you must desallocate iVIndices. Else you must not. + * If iCopy != 0, the array is copied; you must deallocate iVIndices. Else you must not. * iVISize * The size of iVIndices. * iNIndices * Array of normals indices. * The integers contained in this array must be multiple of 3. - * If iCopy != 0, the array is copied; you must desallocate iNIndices. Else you must not. + * If iCopy != 0, the array is copied; you must deallocate iNIndices. Else you must not. * iNISize * The size of iNIndices * iMIndices @@ -167,8 +167,8 @@ class IndexedFaceSet : public Rep { return *this; } - /*! Desctructor - * desallocates all the resources + /*! Destructor + * deallocates all the resources */ virtual ~IndexedFaceSet(); diff --git a/source/blender/freestyle/intern/scene_graph/NodeGroup.h b/source/blender/freestyle/intern/scene_graph/NodeGroup.h index f40deb13a3e..5ef16255e46 100644 --- a/source/blender/freestyle/intern/scene_graph/NodeGroup.h +++ b/source/blender/freestyle/intern/scene_graph/NodeGroup.h @@ -54,7 +54,7 @@ class NodeGroup : public Node { /*! Detaches all the children */ virtual void DetachChildren(); - /*! Detached the sepcified child */ + /*! Detached the specified child */ virtual void DetachChild(Node *iChild); /*! Retrieve children */ diff --git a/source/blender/freestyle/intern/stroke/AdvancedStrokeShaders.h b/source/blender/freestyle/intern/stroke/AdvancedStrokeShaders.h index 5209839a8e1..641e133b019 100644 --- a/source/blender/freestyle/intern/stroke/AdvancedStrokeShaders.h +++ b/source/blender/freestyle/intern/stroke/AdvancedStrokeShaders.h @@ -28,8 +28,8 @@ namespace Freestyle { /*! [ Thickness Shader ]. * Assigns thicknesses to the stroke vertices so that the stroke looks like made with a - * calligraphic tool. i.e. The stroke will be the thickest in a main direction, the thinest in the - * direction perpendicular to this one, and an interpolation inbetween. + * calligraphic tool. i.e. The stroke will be the thickest in a main direction, the thinnest in the + * direction perpendicular to this one, and an interpolation in between. */ class CalligraphicShader : public StrokeShader { public: diff --git a/source/blender/freestyle/intern/stroke/BasicStrokeShaders.cpp b/source/blender/freestyle/intern/stroke/BasicStrokeShaders.cpp index 843395c136c..2c014c86d36 100644 --- a/source/blender/freestyle/intern/stroke/BasicStrokeShaders.cpp +++ b/source/blender/freestyle/intern/stroke/BasicStrokeShaders.cpp @@ -57,7 +57,7 @@ int ConstantThicknessShader::shade(Stroke &stroke) const int i = 0; int size = stroke.strokeVerticesSize(); for (v = stroke.strokeVerticesBegin(), vend = stroke.strokeVerticesEnd(); v != vend; ++v) { - // XXX What's the use of i here? And is not the thickness always overriden by the last line of + // XXX What's the use of i here? And is not the thickness always overridden by the last line of // the loop? if ((1 == i) || (size - 2 == i)) { v->attribute().setThickness(_thickness / 4.0, _thickness / 4.0); @@ -77,7 +77,7 @@ int ConstantExternThicknessShader::shade(Stroke &stroke) const int i = 0; int size = stroke.strokeVerticesSize(); for (v = stroke.strokeVerticesBegin(), vend = stroke.strokeVerticesEnd(); v != vend; ++v) { - // XXX What's the use of i here? And is not the thickness always overriden by the last line of + // XXX What's the use of i here? And is not the thickness always overridden by the last line of // the loop? if ((1 == i) || (size - 2 == i)) { v->attribute().setThickness(_thickness / 2.0, 0); @@ -156,7 +156,7 @@ int LengthDependingThicknessShader::shade(Stroke &stroke) const int i = 0; int size = stroke.strokeVerticesSize(); for (v = stroke.strokeVerticesBegin(), vend = stroke.strokeVerticesEnd(); v != vend; ++v) { - // XXX What's the use of i here? And is not the thickness always overriden by the last line of + // XXX What's the use of i here? And is not the thickness always overridden by the last line of // the loop? if ((1 == i) || (size - 2 == i)) { v->attribute().setThickness(thickness / 4.0, thickness / 4.0); @@ -427,7 +427,7 @@ int BezierCurveShader::shade(Stroke &stroke) const int newsize = stroke.strokeVerticesSize(); int nExtraVertex = 0; if (newsize < originalSize) { - cerr << "Warning: unsufficient resampling" << endl; + cerr << "Warning: insufficient resampling" << endl; } else { nExtraVertex = newsize - originalSize; diff --git a/source/blender/freestyle/intern/stroke/BasicStrokeShaders.h b/source/blender/freestyle/intern/stroke/BasicStrokeShaders.h index db5738449e6..e4a54106c38 100644 --- a/source/blender/freestyle/intern/stroke/BasicStrokeShaders.h +++ b/source/blender/freestyle/intern/stroke/BasicStrokeShaders.h @@ -187,7 +187,7 @@ class ConstrainedIncreasingThicknessShader : public StrokeShader { }; /* [ Thickness Shader ]. - * Modifys the thickness in a relative way depending on its length. + * Modifies the thickness in a relative way depending on its length. */ class LengthDependingThicknessShader : public StrokeShader { private: diff --git a/source/blender/freestyle/intern/stroke/Chain.h b/source/blender/freestyle/intern/stroke/Chain.h index 2c19748771e..7cd0c64cc16 100644 --- a/source/blender/freestyle/intern/stroke/Chain.h +++ b/source/blender/freestyle/intern/stroke/Chain.h @@ -39,7 +39,7 @@ class Chain : public Curve { _fedgeB; // the last FEdge of the ViewEdge passed to the last call for push_viewedge_back(). public: - /*! Defult constructor. */ + /*! Default constructor. */ Chain() : Curve() { _splittingId = 0; diff --git a/source/blender/freestyle/intern/stroke/Curve.h b/source/blender/freestyle/intern/stroke/Curve.h index 3e079256161..7eadfa830ce 100644 --- a/source/blender/freestyle/intern/stroke/Curve.h +++ b/source/blender/freestyle/intern/stroke/Curve.h @@ -205,7 +205,7 @@ class CurvePoint : public Interface0D { Vec3r _Point3d; public: - /*! Defult Constructor. */ + /*! Default Constructor. */ CurvePoint(); /*! Builds a CurvePoint from two SVertex and an interpolation parameter. diff --git a/source/blender/freestyle/intern/stroke/CurveAdvancedIterators.h b/source/blender/freestyle/intern/stroke/CurveAdvancedIterators.h index 9999950e240..662222524f1 100644 --- a/source/blender/freestyle/intern/stroke/CurveAdvancedIterators.h +++ b/source/blender/freestyle/intern/stroke/CurveAdvancedIterators.h @@ -50,8 +50,8 @@ class CurvePoint_nonconst_traits : public Nonconst_traits<CurvePoint *> { /* */ /**********************************/ -/*! iterator on a curve. Allows an iterating outside initial vertices. A CurvePoint is - * instanciated an returned when the iterator is dereferenced. +/*! iterator on a curve. Allows an iterating outside initial vertices. A CurvePoint is + * instantiated and returned when the iterator is dereferenced. */ template<class Traits> class __point_iterator : public IteratorBase<Traits, BidirectionalIteratorTag_Traits> { diff --git a/source/blender/freestyle/intern/stroke/CurveIterators.h b/source/blender/freestyle/intern/stroke/CurveIterators.h index 0ebbd0509ca..3ac7ede0954 100644 --- a/source/blender/freestyle/intern/stroke/CurveIterators.h +++ b/source/blender/freestyle/intern/stroke/CurveIterators.h @@ -30,7 +30,7 @@ namespace Freestyle { namespace CurveInternal { /*! iterator on a curve. Allows an iterating outside - * initial vertices. A CurvePoint is instanciated an returned + * initial vertices. A CurvePoint is instantiated an returned * when the iterator is dereferenced. */ diff --git a/source/blender/freestyle/intern/stroke/Stroke.h b/source/blender/freestyle/intern/stroke/Stroke.h index ec722516d2a..f4fd2b132e8 100644 --- a/source/blender/freestyle/intern/stroke/Stroke.h +++ b/source/blender/freestyle/intern/stroke/Stroke.h @@ -194,13 +194,13 @@ class StrokeAttribute { */ Vec3f getAttributeVec3f(const char *iName) const; - /*! Checks whether the attribute iName is availbale */ + /*! Checks whether the attribute iName is available */ bool isAttributeAvailableReal(const char *iName) const; - /*! Checks whether the attribute iName is availbale */ + /*! Checks whether the attribute iName is available */ bool isAttributeAvailableVec2f(const char *iName) const; - /*! Checks whether the attribute iName is availbale */ + /*! Checks whether the attribute iName is available */ bool isAttributeAvailableVec3f(const char *iName) const; /* modifiers */ @@ -653,7 +653,7 @@ class Stroke : public Interface1D { return _textureId; } - /*! Returns the spacing of texture coordinates along the stroke lenght */ + /*! Returns the spacing of texture coordinates along the stroke length */ inline float getTextureStep() { return _textureStep; @@ -766,7 +766,7 @@ class Stroke : public Interface1D { _textureId = id; } - /*! sets the spacing of texture coordinates along the stroke lenght. */ + /*! sets the spacing of texture coordinates along the stroke length. */ inline void setTextureStep(float step) { _textureStep = step; diff --git a/source/blender/freestyle/intern/system/BaseIterator.h b/source/blender/freestyle/intern/system/BaseIterator.h index 3826a129a1c..651f2bf4387 100644 --- a/source/blender/freestyle/intern/system/BaseIterator.h +++ b/source/blender/freestyle/intern/system/BaseIterator.h @@ -30,7 +30,7 @@ namespace Freestyle { -// use for iterators defintions +// use for iterators definitions template<class Element> class Nonconst_traits; template<class Element> class Const_traits { diff --git a/source/blender/freestyle/intern/view_map/CulledOccluderSource.cpp b/source/blender/freestyle/intern/view_map/CulledOccluderSource.cpp index 8e10d06d623..2df5ecd0867 100644 --- a/source/blender/freestyle/intern/view_map/CulledOccluderSource.cpp +++ b/source/blender/freestyle/intern/view_map/CulledOccluderSource.cpp @@ -131,7 +131,7 @@ void CulledOccluderSource::cullViewEdges(ViewMap &viewMap, bool extensiveFEdgeSe GridHelpers::getDefaultViewProscenium(occluderProscenium); // XXX Freestyle is inconsistent in its use of ViewMap::viewedges_container and - // vector<ViewEdge*>::iterator. Probably all occurences of vector<ViewEdge*>::iterator should be + // vector<ViewEdge*>::iterator. Probably all occurrences of vector<ViewEdge*>::iterator should be // replaced ViewMap::viewedges_container throughout the code. For each view edge ViewMap::viewedges_container::iterator ve, veend; @@ -144,7 +144,7 @@ void CulledOccluderSource::cullViewEdges(ViewMap &viewMap, bool extensiveFEdgeSe // If none exists, find the feature edge with center point closest to viewport origin. // Expand occluder proscenium to enclose center point. - // For each feature edge, while bestOccluderTarget not found and view edge not visibile + // For each feature edge, while bestOccluderTarget not found and view edge not visible bool bestOccluderTargetFound = false; FEdge *bestOccluderTarget = NULL; real bestOccluderDistance = 0.0; diff --git a/source/blender/freestyle/intern/view_map/FEdgeXDetector.cpp b/source/blender/freestyle/intern/view_map/FEdgeXDetector.cpp index 5c3ba1c3db3..3788b5e3545 100644 --- a/source/blender/freestyle/intern/view_map/FEdgeXDetector.cpp +++ b/source/blender/freestyle/intern/view_map/FEdgeXDetector.cpp @@ -132,7 +132,7 @@ void FEdgeXDetector::preProcessShape(WXShape *iWShape) vector<WFace *> &wfaces = iWShape->GetFaceList(); vector<WFace *>::iterator f, fend; - // view dependant stuff + // view dependent stuff for (f = wfaces.begin(), fend = wfaces.end(); f != fend; ++f) { preProcessFace((WXFace *)(*f)); } @@ -226,7 +226,7 @@ void FEdgeXDetector::computeCurvatures(WXVertex *vertex) _minK1 = absK1; } } - // view dependant + // view dependent C = vertex->curvatures(); if (C == 0) { return; diff --git a/source/blender/freestyle/intern/view_map/Silhouette.h b/source/blender/freestyle/intern/view_map/Silhouette.h index 5e9edd234ef..648eb4e453d 100644 --- a/source/blender/freestyle/intern/view_map/Silhouette.h +++ b/source/blender/freestyle/intern/view_map/Silhouette.h @@ -168,7 +168,7 @@ class SVertex : public Interface0D { public: /*! A field that can be used by the user to store any data. - * This field must be reseted afterwards using ResetUserData(). + * This field must be reset afterwards using ResetUserData(). */ void *userdata; @@ -535,7 +535,7 @@ class FEdge : public Interface1D { public: /*! A field that can be used by the user to store any data. - * This field must be reseted afterwards using ResetUserData(). + * This field must be reset afterwards using ResetUserData(). */ void *userdata; @@ -620,7 +620,7 @@ class FEdge : public Interface1D { return _VertexB; } - /*! Returns the first SVertex if i=0, the seccond SVertex if i=1. */ + /*! Returns the first SVertex if i=0, the second SVertex if i=1. */ inline SVertex *operator[](const unsigned short int &i) const { return (i % 2 == 0) ? _VertexA : _VertexB; @@ -1433,7 +1433,7 @@ class SShape { public: /*! A field that can be used by the user to store any data. - * This field must be reseted afterwards using ResetUserData(). + * This field must be reset afterwards using ResetUserData(). */ void *userdata; // added by E.T. diff --git a/source/blender/freestyle/intern/view_map/ViewEdgeXBuilder.cpp b/source/blender/freestyle/intern/view_map/ViewEdgeXBuilder.cpp index fde4ee7e476..d024c360e3f 100644 --- a/source/blender/freestyle/intern/view_map/ViewEdgeXBuilder.cpp +++ b/source/blender/freestyle/intern/view_map/ViewEdgeXBuilder.cpp @@ -37,7 +37,7 @@ void ViewEdgeXBuilder::Init(ViewShape *oVShape) return; } - // for design conveniance, we store the current SShape. + // for design convenience, we store the current SShape. _pCurrentSShape = oVShape->sshape(); if (0 == _pCurrentSShape) { return; @@ -627,12 +627,12 @@ OWXEdge ViewEdgeXBuilder::FindNextWEdge(const OWXEdge &iEdge) } if (wxe->GetaVertex() == v) { - // That means that the face necesarily lies on the edge left. + // That means that the face necessarily lies on the edge left. // So the vertex order is OK. return OWXEdge(wxe, true); } else { - // That means that the face necesarily lies on the edge left. + // That means that the face necessarily lies on the edge left. // So the vertex order is OK. return OWXEdge(wxe, false); } diff --git a/source/blender/freestyle/intern/view_map/ViewEdgeXBuilder.h b/source/blender/freestyle/intern/view_map/ViewEdgeXBuilder.h index 26f114497c0..b1934d08376 100644 --- a/source/blender/freestyle/intern/view_map/ViewEdgeXBuilder.h +++ b/source/blender/freestyle/intern/view_map/ViewEdgeXBuilder.h @@ -272,11 +272,11 @@ class ViewEdgeXBuilder { FEdge *BuildSharpFEdge(FEdge *feprevious, const OWXEdge &iwe); // GENERAL // - /*! Instanciate a SVertex */ + /*! Instantiate a SVertex */ SVertex *MakeSVertex(Vec3r &iPoint); - /*! Instanciate a SVertex if it hasn't been already created */ + /*! Instantiate a SVertex if it hasn't been already created */ SVertex *MakeSVertex(Vec3r &iPoint, bool shared); - /*! instanciate a ViewVertex from a SVertex, if it doesn't exist yet */ + /*! instantiate a ViewVertex from a SVertex, if it doesn't exist yet */ ViewVertex *MakeViewVertex(SVertex *iSVertex); // oldtmp values diff --git a/source/blender/freestyle/intern/view_map/ViewMap.h b/source/blender/freestyle/intern/view_map/ViewMap.h index a6ca4e3c072..83c45be8c61 100644 --- a/source/blender/freestyle/intern/view_map/ViewMap.h +++ b/source/blender/freestyle/intern/view_map/ViewMap.h @@ -81,7 +81,7 @@ class ViewMap { public: /*! A field that can be used by the user to store any data. - * This field must be reseted afterwards using ResetUserData(). + * This field must be reset afterwards using ResetUserData(). */ void *userdata; @@ -292,7 +292,7 @@ class ViewVertex : public Interface0D { public: /*! A field that can be used by the user to store any data. - * This field must be reseted afterwards using ResetUserData(). + * This field must be reset afterwards using ResetUserData(). */ void *userdata; @@ -962,7 +962,7 @@ class ViewEdge : public Interface1D { public: /*! A field that can be used by the user to store any data. - * This field must be reseted afterwards using ResetUserData(). + * This field must be reset afterwards using ResetUserData(). */ void *userdata; @@ -1414,7 +1414,7 @@ class ViewShape { public: /*! A field that can be used by the user to store any data. - * This field must be reseted afterwards using ResetUserData(). + * This field must be reset afterwards using ResetUserData(). */ void *userdata; diff --git a/source/blender/freestyle/intern/view_map/ViewMapBuilder.cpp b/source/blender/freestyle/intern/view_map/ViewMapBuilder.cpp index aaab3936fa6..c67be4f97b3 100644 --- a/source/blender/freestyle/intern/view_map/ViewMapBuilder.cpp +++ b/source/blender/freestyle/intern/view_map/ViewMapBuilder.cpp @@ -1123,7 +1123,7 @@ void ViewMapBuilder::CullViewEdges(ViewMap *ioViewMap, GridHelpers::getDefaultViewProscenium(occluderProscenium); // N.B. Freestyle is inconsistent in its use of ViewMap::viewedges_container and - // vector<ViewEdge*>::iterator. Probably all occurences of vector<ViewEdge*>::iterator should be + // vector<ViewEdge*>::iterator. Probably all occurrences of vector<ViewEdge*>::iterator should be // replaced ViewMap::viewedges_container throughout the code. For each view edge ViewMap::viewedges_container::iterator ve, veend; @@ -1137,7 +1137,7 @@ void ViewMapBuilder::CullViewEdges(ViewMap *ioViewMap, // If none exists, find the feature edge with center point closest to viewport origin. // Expand occluder proscenium to enclose center point. - // For each feature edge, while bestOccluderTarget not found and view edge not visibile + // For each feature edge, while bestOccluderTarget not found and view edge not visible bool bestOccluderTargetFound = false; FEdge *bestOccluderTarget = NULL; real bestOccluderDistance = 0.0; diff --git a/source/blender/freestyle/intern/winged_edge/Curvature.cpp b/source/blender/freestyle/intern/winged_edge/Curvature.cpp index a293d2da62b..591d6518741 100644 --- a/source/blender/freestyle/intern/winged_edge/Curvature.cpp +++ b/source/blender/freestyle/intern/winged_edge/Curvature.cpp @@ -546,7 +546,7 @@ void gts_vertex_principal_directions(WVertex *v, Vec3r Kh, real Kg, Vec3r &e1, V e1[2] = eig[0] * basis1[2] + eig[1] * basis2[2]; e1.normalize(); - /* make N,e1,e2 a right handed coordinate sytem */ + /* make N,e1,e2 a right handed coordinate system */ e2 = N ^ e1; e2.normalize(); } diff --git a/source/blender/freestyle/intern/winged_edge/WXEdge.h b/source/blender/freestyle/intern/winged_edge/WXEdge.h index 20c0bd172ad..21418c44614 100644 --- a/source/blender/freestyle/intern/winged_edge/WXEdge.h +++ b/source/blender/freestyle/intern/winged_edge/WXEdge.h @@ -108,7 +108,7 @@ class WXEdge : public WEdge { private: // flag to indicate whether the edge is a silhouette edge or not WXNature _nature; - // 0: the order doesn't matter. 1: the order is the orginal one. -1: the order is not good + // 0: the order doesn't matter. 1: the order is the original one. -1: the order is not good short _order; // A front facing edge is an edge for which the bording face which is the nearest from the // viewpoint is front. A back facing edge is the opposite. diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencilnoise.c b/source/blender/gpencil_modifiers/intern/MOD_gpencilnoise.c index 54218da9eb5..e0139eac6b2 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpencilnoise.c +++ b/source/blender/gpencil_modifiers/intern/MOD_gpencilnoise.c @@ -85,6 +85,21 @@ static bool dependsOnTime(GpencilModifierData *md) return (mmd->flag & GP_NOISE_USE_RANDOM) != 0; } +/* Get the lower number of frame for all layers. */ +static int get_lower_frame(bGPdata *gpd) +{ + int init = 99999; + for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) { + if (gpl->frames.first) { + bGPDframe *gpf = gpl->frames.first; + if (gpf->framenum < init) { + init = gpf->framenum; + } + } + } + return init; +} + /* aply noise effect based on stroke direction */ static void deformStroke( GpencilModifierData *md, Depsgraph *depsgraph, Object *ob, bGPDlayer *gpl, bGPDstroke *gps) @@ -103,6 +118,7 @@ static void deformStroke( Object *object_eval = DEG_get_evaluated_object(depsgraph, ob); GpencilModifierData *md_eval = BKE_gpencil_modifiers_findByName(object_eval, md->name); NoiseGpencilModifierData *mmd_eval = (NoiseGpencilModifierData *)md_eval; + bGPdata *gpd = (bGPdata *)ob->data; /* Random generator, only init once. (it uses eval to get same value in render) */ if (mmd_eval->rng == NULL) { @@ -110,6 +126,9 @@ static void deformStroke( rng_seed ^= POINTER_AS_UINT(mmd); mmd_eval->rng = BLI_rng_new(rng_seed); mmd->rng = mmd_eval->rng; + /* Get lower frame number */ + mmd_eval->scene_frame = get_lower_frame(gpd); + mmd->scene_frame = mmd_eval->scene_frame; } if (!is_stroke_affected_by_modifier(ob, @@ -176,19 +195,17 @@ static void deformStroke( sub_v3_v3v3(vec1, &pt1->x, &pt0->x); } vran = len_v3(vec1); - /* vector orthogonal to normal */ + /* Vector orthogonal to normal. */ cross_v3_v3v3(vec2, vec1, normal); normalize_v3(vec2); - /* use random noise */ + /* Use random noise */ if (mmd->flag & GP_NOISE_USE_RANDOM) { - sc_diff = abs(mmd->scene_frame - sc_frame); - /* only recalc if the gp frame change or the number of scene frames is bigger than step */ - if ((!gpl->actframe) || (mmd->gp_frame != gpl->actframe->framenum) || - (sc_diff >= mmd->step)) { + sc_diff = abs(sc_frame - mmd->scene_frame) % mmd->step; + /* Only recalc if the gp frame change or is a step. */ + if ((mmd->gp_frame != sc_frame) && (sc_diff == 0)) { vran = mmd->vrand1 = BLI_rng_get_float(mmd->rng); vdir = mmd->vrand2 = BLI_rng_get_float(mmd->rng); - mmd->gp_frame = gpl->actframe->framenum; - mmd->scene_frame = sc_frame; + mmd->gp_frame = sc_frame; } else { vran = mmd->vrand1; diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt index f30eff1484b..c620644a5f8 100644 --- a/source/blender/gpu/CMakeLists.txt +++ b/source/blender/gpu/CMakeLists.txt @@ -221,9 +221,6 @@ data_to_c_simple(shaders/gpu_shader_2D_edituvs_edges_vert.glsl SRC) data_to_c_simple(shaders/gpu_shader_2D_edituvs_faces_vert.glsl SRC) data_to_c_simple(shaders/gpu_shader_2D_edituvs_stretch_vert.glsl SRC) -data_to_c_simple(shaders/gpu_shader_3D_selection_id_vert.glsl SRC) -data_to_c_simple(shaders/gpu_shader_selection_id_frag.glsl SRC) - data_to_c_simple(shaders/gpu_shader_text_simple_vert.glsl SRC) data_to_c_simple(shaders/gpu_shader_text_simple_geom.glsl SRC) data_to_c_simple(shaders/gpu_shader_text_vert.glsl SRC) diff --git a/source/blender/gpu/GPU_extensions.h b/source/blender/gpu/GPU_extensions.h index d0abf671fcd..023cbb804d9 100644 --- a/source/blender/gpu/GPU_extensions.h +++ b/source/blender/gpu/GPU_extensions.h @@ -43,6 +43,7 @@ int GPU_max_ubo_binds(void); int GPU_max_ubo_size(void); float GPU_max_line_width(void); void GPU_get_dfdy_factors(float fac[2]); +bool GPU_arb_base_instance_is_supported(void); bool GPU_mip_render_workaround(void); bool GPU_depth_blitting_workaround(void); bool GPU_unused_fb_slot_workaround(void); diff --git a/source/blender/gpu/GPU_framebuffer.h b/source/blender/gpu/GPU_framebuffer.h index b919a3dd8f3..7d0f8b0bcbf 100644 --- a/source/blender/gpu/GPU_framebuffer.h +++ b/source/blender/gpu/GPU_framebuffer.h @@ -71,7 +71,7 @@ GPUFrameBuffer *GPU_framebuffer_active_get(void); } \ } while (0) -/* Framebuffer setup : You need to call GPU_framebuffer_bind for theses +/* Framebuffer setup : You need to call GPU_framebuffer_bind for these * to be effective. */ void GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, struct GPUTexture *tex, int slot, int mip); diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h index cae2392e503..124f1f1ff8a 100644 --- a/source/blender/gpu/GPU_shader.h +++ b/source/blender/gpu/GPU_shader.h @@ -355,11 +355,8 @@ typedef enum eGPUBuiltinShader { GPU_SHADER_2D_UV_FACES, GPU_SHADER_2D_UV_FACES_STRETCH_AREA, GPU_SHADER_2D_UV_FACES_STRETCH_ANGLE, - /* Selection */ - GPU_SHADER_3D_FLAT_SELECT_ID, - GPU_SHADER_3D_UNIFORM_SELECT_ID, } eGPUBuiltinShader; -#define GPU_SHADER_BUILTIN_LEN (GPU_SHADER_3D_UNIFORM_SELECT_ID + 1) +#define GPU_SHADER_BUILTIN_LEN (GPU_SHADER_2D_UV_FACES_STRETCH_ANGLE + 1) /** Support multiple configurations. */ typedef enum eGPUShaderConfig { diff --git a/source/blender/gpu/intern/gpu_batch.c b/source/blender/gpu/intern/gpu_batch.c index ba3c7f68518..11b487f7be4 100644 --- a/source/blender/gpu/intern/gpu_batch.c +++ b/source/blender/gpu/intern/gpu_batch.c @@ -28,6 +28,7 @@ #include "GPU_batch.h" #include "GPU_batch_presets.h" +#include "GPU_extensions.h" #include "GPU_matrix.h" #include "GPU_shader.h" @@ -599,7 +600,7 @@ void GPU_batch_draw_advanced(GPUBatch *batch, int v_first, int v_count, int i_fi i_count = (batch->inst) ? batch->inst->vertex_len : 1; } - if (!GLEW_ARB_base_instance) { + if (!GPU_arb_base_instance_is_supported()) { if (i_first > 0 && i_count > 0) { /* If using offset drawing with instancing, we must * use the default VAO and redo bindings. */ @@ -624,7 +625,7 @@ void GPU_batch_draw_advanced(GPUBatch *batch, int v_first, int v_count, int i_fi #endif void *v_first_ofs = elem_offset(el, v_first); - if (GLEW_ARB_base_instance) { + if (GPU_arb_base_instance_is_supported()) { glDrawElementsInstancedBaseVertexBaseInstance( batch->gl_prim_type, v_count, index_type, v_first_ofs, i_count, base_index, i_first); } @@ -637,7 +638,7 @@ void GPU_batch_draw_advanced(GPUBatch *batch, int v_first, int v_count, int i_fi #ifdef __APPLE__ glDisable(GL_PRIMITIVE_RESTART); #endif - if (GLEW_ARB_base_instance) { + if (GPU_arb_base_instance_is_supported()) { glDrawArraysInstancedBaseInstance(batch->gl_prim_type, v_first, v_count, i_count, i_first); } else { diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c index 0c751808489..51b73c93c86 100644 --- a/source/blender/gpu/intern/gpu_codegen.c +++ b/source/blender/gpu/intern/gpu_codegen.c @@ -2138,7 +2138,7 @@ static bool gpu_pass_shader_validate(GPUPass *pass, GPUShader *shader) bool GPU_pass_compile(GPUPass *pass, const char *shname) { - bool sucess = true; + bool success = true; if (!pass->compiled) { GPUShader *shader = GPU_shader_create( pass->vertexcode, pass->fragmentcode, pass->geometrycode, NULL, pass->defines, shname); @@ -2146,7 +2146,7 @@ bool GPU_pass_compile(GPUPass *pass, const char *shname) /* NOTE: Some drivers / gpu allows more active samplers than the opengl limit. * We need to make sure to count active samplers to avoid undefined behavior. */ if (!gpu_pass_shader_validate(pass, shader)) { - sucess = false; + success = false; if (shader != NULL) { fprintf(stderr, "GPUShader: error: too many samplers in shader.\n"); GPU_shader_free(shader); @@ -2169,7 +2169,7 @@ bool GPU_pass_compile(GPUPass *pass, const char *shname) MEM_SAFE_FREE(pass->binary.content); } - return sucess; + return success; } void GPU_pass_release(GPUPass *pass) diff --git a/source/blender/gpu/intern/gpu_extensions.c b/source/blender/gpu/intern/gpu_extensions.c index ba5cf214a42..61f7ba6da7c 100644 --- a/source/blender/gpu/intern/gpu_extensions.c +++ b/source/blender/gpu/intern/gpu_extensions.c @@ -77,6 +77,9 @@ static struct GPUGlobal { * number is factor on screen and second is off-screen */ float dfdyfactors[2]; float max_anisotropy; + /* Some Intel drivers have limited support for `GLEW_ARB_base_instance` so in + * these cases it is best to indicate that it is not supported. See T67951 */ + bool glew_arb_base_instance_is_supported; /* Some Intel drivers have issues with using mips as framebuffer targets if * GL_TEXTURE_MAX_LEVEL is higher than the target mip. * We need a workaround in this cases. */ @@ -197,6 +200,11 @@ void GPU_get_dfdy_factors(float fac[2]) copy_v2_v2(fac, GG.dfdyfactors); } +bool GPU_arb_base_instance_is_supported(void) +{ + return GG.glew_arb_base_instance_is_supported; +} + bool GPU_mip_render_workaround(void) { return GG.mip_render_workaround; @@ -343,6 +351,7 @@ void gpu_extensions_init(void) GG.os = GPU_OS_UNIX; #endif + GG.glew_arb_base_instance_is_supported = GLEW_ARB_base_instance; gpu_detect_mip_render_workaround(); if (G.debug & G_DEBUG_GPU_FORCE_WORKAROUNDS) { @@ -383,6 +392,9 @@ void gpu_extensions_init(void) strstr(version, "Build 10.18.10.4653") || strstr(version, "Build 10.18.10.5069") || strstr(version, "Build 10.18.14.4264") || strstr(version, "Build 10.18.14.4432") || strstr(version, "Build 10.18.14.5067")) { + /* Maybe not all of these drivers have problems with `GLEW_ARB_base_instance`. + * But it's hard to test each case. */ + GG.glew_arb_base_instance_is_supported = false; GG.context_local_shaders_workaround = true; } } diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c index 6f1b8d2d0c6..20b91c0c95d 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -733,7 +733,7 @@ GPUMaterial *GPU_material_from_nodetree(Scene *scene, void GPU_material_compile(GPUMaterial *mat) { - bool sucess; + bool success; BLI_assert(mat->status == GPU_MAT_QUEUED); BLI_assert(mat->pass); @@ -741,12 +741,12 @@ void GPU_material_compile(GPUMaterial *mat) /* NOTE: The shader may have already been compiled here since we are * sharing GPUShader across GPUMaterials. In this case it's a no-op. */ #ifndef NDEBUG - sucess = GPU_pass_compile(mat->pass, mat->name); + success = GPU_pass_compile(mat->pass, mat->name); #else - sucess = GPU_pass_compile(mat->pass, __func__); + success = GPU_pass_compile(mat->pass, __func__); #endif - if (sucess) { + if (success) { GPUShader *sh = GPU_pass_shader_get(mat->pass); if (sh != NULL) { mat->status = GPU_MAT_SUCCESS; diff --git a/source/blender/gpu/intern/gpu_shader.c b/source/blender/gpu/intern/gpu_shader.c index c142d8ccba2..3e930d19696 100644 --- a/source/blender/gpu/intern/gpu_shader.c +++ b/source/blender/gpu/intern/gpu_shader.c @@ -139,9 +139,6 @@ extern char datatoc_gpu_shader_2D_edituvs_edges_vert_glsl[]; extern char datatoc_gpu_shader_2D_edituvs_faces_vert_glsl[]; extern char datatoc_gpu_shader_2D_edituvs_stretch_vert_glsl[]; -extern char datatoc_gpu_shader_3D_selection_id_vert_glsl[]; -extern char datatoc_gpu_shader_selection_id_frag_glsl[]; - extern char datatoc_gpu_shader_2D_line_dashed_uniform_color_vert_glsl[]; extern char datatoc_gpu_shader_2D_line_dashed_frag_glsl[]; extern char datatoc_gpu_shader_2D_line_dashed_geom_glsl[]; @@ -1312,18 +1309,6 @@ static const GPUShaderStages builtin_shader_stages[GPU_SHADER_BUILTIN_LEN] = { .defs = "#define STRETCH_ANGLE\n", }, - [GPU_SHADER_3D_FLAT_SELECT_ID] = - { - .vert = datatoc_gpu_shader_3D_selection_id_vert_glsl, - .frag = datatoc_gpu_shader_selection_id_frag_glsl, - }, - [GPU_SHADER_3D_UNIFORM_SELECT_ID] = - { - .vert = datatoc_gpu_shader_3D_selection_id_vert_glsl, - .frag = datatoc_gpu_shader_selection_id_frag_glsl, - .defs = "#define UNIFORM_ID\n", - }, - [GPU_SHADER_GPENCIL_STROKE] = { .vert = datatoc_gpu_shader_gpencil_stroke_vert_glsl, @@ -1370,9 +1355,7 @@ GPUShader *GPU_shader_get_builtin_shader_with_config(eGPUBuiltinShader shader, GPU_SHADER_3D_GROUNDLINE, GPU_SHADER_3D_GROUNDPOINT, GPU_SHADER_DISTANCE_LINES, - GPU_SHADER_INSTANCE_EDGES_VARIYING_COLOR, - GPU_SHADER_3D_FLAT_SELECT_ID, - GPU_SHADER_3D_UNIFORM_SELECT_ID) || + GPU_SHADER_INSTANCE_EDGES_VARIYING_COLOR) || ELEM(shader, GPU_SHADER_3D_FLAT_COLOR, GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR, diff --git a/source/blender/gpu/shaders/gpu_shader_3D_selection_id_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_selection_id_vert.glsl deleted file mode 100644 index 0d58909efd8..00000000000 --- a/source/blender/gpu/shaders/gpu_shader_3D_selection_id_vert.glsl +++ /dev/null @@ -1,26 +0,0 @@ - -uniform mat4 ModelViewProjectionMatrix; - -in vec3 pos; - -#ifndef UNIFORM_ID -uniform uint offset; -in uint color; - -flat out uint id; -#endif - -void main() -{ -#ifndef UNIFORM_ID - id = offset + color; -#endif - - vec4 pos_4d = vec4(pos, 1.0); - gl_Position = ModelViewProjectionMatrix * pos_4d; - -#ifdef USE_WORLD_CLIP_PLANES - /* Warning: ModelMatrix is typically used but select drawing is different. */ - world_clip_planes_calc_clip_distance(pos); -#endif -} diff --git a/source/blender/ikplugin/intern/itasc_plugin.cpp b/source/blender/ikplugin/intern/itasc_plugin.cpp index b1eb0978339..0401c485c2a 100644 --- a/source/blender/ikplugin/intern/itasc_plugin.cpp +++ b/source/blender/ikplugin/intern/itasc_plugin.cpp @@ -303,7 +303,7 @@ static int initialize_chain(Object *ob, bPoseChannel *pchan_tip, bConstraint *co /* create a target */ target = (PoseTarget *)MEM_callocN(sizeof(PoseTarget), "posetarget"); target->con = con; - // by contruction there can be only one tree per channel + // by construction there can be only one tree per channel // and each channel can be part of at most one tree. tree = (PoseTree *)pchan_root->iktree.first; @@ -1729,7 +1729,7 @@ static void execute_scene(struct Depsgraph *depsgraph, IK_Channel *ikchan; if (ikparam->flag & ITASC_SIMULATION) { for (i = 0, ikchan = ikscene->channels; i < ikscene->numchan; i++, ++ikchan) { - // In simulation mode we don't allow external contraint to change our bones, mark the channel + // In simulation mode we don't allow external constraint to change our bones, mark the channel // done also tell Blender that this channel is part of IK tree // (cleared on each BKE_pose_where_is() ikchan->pchan->flag |= (POSE_DONE | POSE_CHAIN); diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h index fbaa9b06d3b..791e939db7f 100644 --- a/source/blender/imbuf/IMB_imbuf.h +++ b/source/blender/imbuf/IMB_imbuf.h @@ -324,7 +324,7 @@ struct IndexBuildContext *IMB_anim_index_rebuild_context(struct anim *anim, IMB_Timecode_Type tcs_in_use, IMB_Proxy_Size proxy_sizes_in_use, int quality, - const bool overwite, + const bool overwrite, struct GSet *file_list); /* will rebuild all used indices and proxies at once */ diff --git a/source/blender/imbuf/IMB_thumbs.h b/source/blender/imbuf/IMB_thumbs.h index bac408e869b..5c7a60bbdcf 100644 --- a/source/blender/imbuf/IMB_thumbs.h +++ b/source/blender/imbuf/IMB_thumbs.h @@ -59,27 +59,34 @@ typedef enum ThumbSource { #define THUMB_DEFAULT_HASH "00000000000000000000000000000000" /* create thumbnail for file and returns new imbuf for thumbnail */ -ImBuf *IMB_thumb_create(const char *path, ThumbSize size, ThumbSource source, ImBuf *ibuf); +struct ImBuf *IMB_thumb_create(const char *path, + ThumbSize size, + ThumbSource source, + struct ImBuf *ibuf); /* read thumbnail for file and returns new imbuf for thumbnail */ -ImBuf *IMB_thumb_read(const char *path, ThumbSize size); +struct ImBuf *IMB_thumb_read(const char *path, ThumbSize size); /* delete all thumbs for the file */ void IMB_thumb_delete(const char *path, ThumbSize size); /* return the state of the thumb, needed to determine how to manage the thumb */ -ImBuf *IMB_thumb_manage(const char *path, ThumbSize size, ThumbSource source); +struct ImBuf *IMB_thumb_manage(const char *path, ThumbSize size, ThumbSource source); /* create the necessary dirs to store the thumbnails */ void IMB_thumb_makedirs(void); /* special function for loading a thumbnail embedded into a blend file */ -ImBuf *IMB_thumb_load_blend(const char *blen_path, const char *blen_group, const char *blen_id); +struct ImBuf *IMB_thumb_load_blend(const char *blen_path, + const char *blen_group, + const char *blen_id); void IMB_thumb_overlay_blend(unsigned int *thumb, int width, int height, float aspect); /* special function for previewing fonts */ -ImBuf *IMB_thumb_load_font(const char *filename, unsigned int x, unsigned int y); +struct ImBuf *IMB_thumb_load_font(const char *filename, unsigned int x, unsigned int y); bool IMB_thumb_load_font_get_hash(char *r_hash); +void IMB_thumb_clear_translations(void); +void IMB_thumb_ensure_translations(void); /* Threading */ void IMB_thumb_locks_acquire(void); diff --git a/source/blender/imbuf/intern/dds/ColorBlock.cpp b/source/blender/imbuf/intern/dds/ColorBlock.cpp index 1ca584e9b0e..cbc85962a36 100644 --- a/source/blender/imbuf/intern/dds/ColorBlock.cpp +++ b/source/blender/imbuf/intern/dds/ColorBlock.cpp @@ -84,7 +84,7 @@ void ColorBlock::init(uint w, uint h, const uint *data, uint x, uint y) const uint bh = MIN(h - y, 4U); // Blocks that are smaller than 4x4 are handled by repeating the pixels. - // @@ Thats only correct when block size is 1, 2 or 4, but not with 3. :( + // @@ That's only correct when block size is 1, 2 or 4, but not with 3. :( // @@ Ideally we should zero the weights of the pixels out of range. for (uint i = 0; i < 4; i++) { @@ -105,7 +105,7 @@ void ColorBlock::init(uint w, uint h, const float *data, uint x, uint y) const uint bh = MIN(h - y, 4U); // Blocks that are smaller than 4x4 are handled by repeating the pixels. - // @@ Thats only correct when block size is 1, 2 or 4, but not with 3. :( + // @@ That's only correct when block size is 1, 2 or 4, but not with 3. :( // @@ Ideally we should zero the weights of the pixels out of range. uint srcPlane = w * h; diff --git a/source/blender/imbuf/intern/dds/Stream.h b/source/blender/imbuf/intern/dds/Stream.h index 35662e8f24e..43cd6b56fb9 100644 --- a/source/blender/imbuf/intern/dds/Stream.h +++ b/source/blender/imbuf/intern/dds/Stream.h @@ -27,7 +27,7 @@ struct Stream { unsigned char *mem; // location in memory unsigned int size; // size unsigned int pos; // current position - bool failed; // error occured when seeking + bool failed; // error occurred when seeking Stream(unsigned char *m, unsigned int s) : mem(m), size(s), pos(0), failed(false) { } diff --git a/source/blender/imbuf/intern/jp2.c b/source/blender/imbuf/intern/jp2.c index 49437e77d8e..3bf97cb851f 100644 --- a/source/blender/imbuf/intern/jp2.c +++ b/source/blender/imbuf/intern/jp2.c @@ -450,7 +450,7 @@ static ImBuf *imb_load_jp2_stream(opj_stream_t *stream, signed_offsets[i] = 1 << (image->comps[i].prec - 1); } - /* only needed for float images but dosnt hurt to calc this */ + /* only needed for float images but doesn't hurt to calc this */ float_divs[i] = (1 << image->comps[i].prec) - 1; } diff --git a/source/blender/imbuf/intern/thumbs_font.c b/source/blender/imbuf/intern/thumbs_font.c index 1213927d329..ddb1eb62006 100644 --- a/source/blender/imbuf/intern/thumbs_font.c +++ b/source/blender/imbuf/intern/thumbs_font.c @@ -32,14 +32,28 @@ #include "../../blenfont/BLF_api.h" #include "../../blentranslation/BLT_translation.h" -static const char *thumb_str[] = { - N_("AaBbCc"), +#define THUMB_TXT_ITEMS \ + N_("AaBbCc"), N_("The quick"), N_("brown fox"), N_("jumps over"), N_("the lazy dog"), - N_("The quick"), - N_("brown fox"), - N_("jumps over"), - N_("the lazy dog"), -}; +static const char *thumb_str[] = {THUMB_TXT_ITEMS}; + +static const char *i18n_thumb_str[] = {THUMB_TXT_ITEMS}; + +#undef THUMB_TXT_ITEMS + +void IMB_thumb_clear_translations(void) +{ + for (int i = ARRAY_SIZE(thumb_str); i-- > 0;) { + i18n_thumb_str[i] = NULL; + } +} + +void IMB_thumb_ensure_translations(void) +{ + for (int i = ARRAY_SIZE(thumb_str); i-- > 0;) { + i18n_thumb_str[i] = BLT_translate_do(BLT_I18NCONTEXT_DEFAULT, thumb_str[i]); + } +} struct ImBuf *IMB_thumb_load_font(const char *filename, unsigned int x, unsigned int y) { @@ -62,6 +76,7 @@ struct ImBuf *IMB_thumb_load_font(const char *filename, unsigned int x, unsigned BLF_thumb_preview(filename, thumb_str, + i18n_thumb_str, ARRAY_SIZE(thumb_str), font_color, font_size, @@ -87,8 +102,9 @@ bool IMB_thumb_load_font_get_hash(char *r_hash) len += BLI_strncpy_rlen(str + len, THUMB_DEFAULT_HASH, sizeof(buf) - len); for (i = 0; (i < draw_str_lines) && (len < sizeof(buf)); i++) { - len += BLI_strncpy_rlen( - str + len, BLT_translate_do(BLT_I18NCONTEXT_DEFAULT, thumb_str[i]), sizeof(buf) - len); + len += BLI_strncpy_rlen(str + len, + i18n_thumb_str[i] != NULL ? i18n_thumb_str[i] : thumb_str[i], + sizeof(buf) - len); } BLI_hash_md5_buffer(str, len, digest); diff --git a/source/blender/imbuf/readme.txt b/source/blender/imbuf/readme.txt index 855f6229420..c192515371b 100644 --- a/source/blender/imbuf/readme.txt +++ b/source/blender/imbuf/readme.txt @@ -8,7 +8,7 @@ creating an openexr read/writer use openexr.c It should contain functions to match the following prototypes: struct ImBuf *imb_loadopenexr(unsigned char *mem,int size,int flags); -/* Use one of the following depending on whats easyer for your file format */ +/* Use one of the following depending on what's easier for your file format */ short imb_saveopenexr(struct ImBuf *ibuf, FILE myfile, int flags); short imb_saveopenexr(struct ImBuf *ibuf, char *myfile, int flags); diff --git a/source/blender/makesdna/DNA_ID.h b/source/blender/makesdna/DNA_ID.h index cad1af8eb50..ef9069acb78 100644 --- a/source/blender/makesdna/DNA_ID.h +++ b/source/blender/makesdna/DNA_ID.h @@ -616,6 +616,15 @@ typedef enum IDRecalcFlag { ID_RECALC_PARAMETERS = (1 << 21), + /* Makes it so everything what depends on time. + * Basically, the same what changing frame in a timeline will do. */ + ID_RECALC_TIME = (1 << 22), + + /* Input has changed and datablock is to be reload from disk. + * Applies to movie clips to inform that copy-on-written version is to be refreshed for the new + * input file or for color space changes. */ + ID_RECALC_SOURCE = (1 << 23), + /*************************************************************************** * Pseudonyms, to have more semantic meaning in the actual code without * using too much low-level and implementation specific tags. */ diff --git a/source/blender/makesdna/DNA_brush_types.h b/source/blender/makesdna/DNA_brush_types.h index 6f775e48d58..93ce3d9769b 100644 --- a/source/blender/makesdna/DNA_brush_types.h +++ b/source/blender/makesdna/DNA_brush_types.h @@ -186,6 +186,18 @@ typedef enum eGP_BrushIcons { GP_BRUSH_ICON_ERASE_STROKE = 10, } eGP_BrushIcons; +typedef enum eBrushCurvePreset { + BRUSH_CURVE_CUSTOM = 0, + BRUSH_CURVE_SMOOTH = 1, + BRUSH_CURVE_SPHERE = 2, + BRUSH_CURVE_ROOT = 3, + BRUSH_CURVE_SHARP = 4, + BRUSH_CURVE_LIN = 5, + BRUSH_CURVE_POW4 = 6, + BRUSH_CURVE_INVSQUARE = 7, + BRUSH_CURVE_CONSTANT = 8, +} eBrushCurvePreset; + typedef struct Brush { ID id; @@ -289,6 +301,9 @@ typedef struct Brush { float texture_sample_bias; + int curve_preset; + char _pad1[4]; + /* overlay */ int texture_overlay_alpha; int mask_overlay_alpha; diff --git a/source/blender/makesdna/DNA_collection_types.h b/source/blender/makesdna/DNA_collection_types.h index c7f3ef4156d..af543864536 100644 --- a/source/blender/makesdna/DNA_collection_types.h +++ b/source/blender/makesdna/DNA_collection_types.h @@ -57,7 +57,9 @@ typedef struct Collection { float instance_offset[3]; short flag; - char _pad[6]; + /* Runtime-only, always cleared on file load. */ + short tag; + char _pad[4]; /* Runtime. Cache of objects in this collection and all its * children. This is created on demand when e.g. some physics @@ -84,4 +86,12 @@ enum { COLLECTION_IS_MASTER = (1 << 5), /* Is master collection embedded in the scene. */ }; +/* Collection->tag */ +enum { + /* That code (BKE_main_collections_parent_relations_rebuild and the like) + * is called from very low-level places, like e.g ID remapping... + * Using a generic tag like LIB_TAG_DOIT for this is just impossible, we need our very own. */ + COLLECTION_TAG_RELATION_REBUILD = (1 << 0), +}; + #endif /* __DNA_COLLECTION_TYPES_H__ */ diff --git a/source/blender/makesdna/DNA_constraint_types.h b/source/blender/makesdna/DNA_constraint_types.h index b613c661f29..eda52fdf14a 100644 --- a/source/blender/makesdna/DNA_constraint_types.h +++ b/source/blender/makesdna/DNA_constraint_types.h @@ -149,7 +149,7 @@ typedef struct bPythonConstraint { */ struct Object *tar; /** - * Subtarger from previous implementation + * Subtarget from previous implementation * (version-patch sets this to "" on file-load), MAX_ID_NAME-2. */ char subtarget[64]; diff --git a/source/blender/makesdna/DNA_customdata_types.h b/source/blender/makesdna/DNA_customdata_types.h index 75a417150c8..14a078d8386 100644 --- a/source/blender/makesdna/DNA_customdata_types.h +++ b/source/blender/makesdna/DNA_customdata_types.h @@ -42,13 +42,13 @@ typedef struct CustomDataLayer { int flag; /** Number of the active layer of this type. */ int active; - /** Number of the layer to rende.r*/ + /** Number of the layer to render. */ int active_rnd; - /** Number of the layer to rende.r*/ + /** Number of the layer to render. */ int active_clone; - /** Number of the layer to rende.r*/ + /** Number of the layer to render. */ int active_mask; - /** Shape keyblock unique id referenc.e*/ + /** Shape keyblock unique id reference. */ int uid; /** Layer name, MAX_CUSTOMDATA_LAYER_NAME. */ char name[64]; diff --git a/source/blender/makesdna/DNA_gpencil_modifier_types.h b/source/blender/makesdna/DNA_gpencil_modifier_types.h index 8b756ff2937..c2a9d3cf296 100644 --- a/source/blender/makesdna/DNA_gpencil_modifier_types.h +++ b/source/blender/makesdna/DNA_gpencil_modifier_types.h @@ -92,7 +92,7 @@ typedef struct NoiseGpencilModifierData { int step; /** Last gp frame used. */ int gp_frame; - /** Last scene frame used. */ + /** First scene frame used. */ int scene_frame; /** Random values. */ float vrand1, vrand2; diff --git a/source/blender/makesdna/DNA_gpencil_types.h b/source/blender/makesdna/DNA_gpencil_types.h index 307a6f2fe16..bf72ce5e598 100644 --- a/source/blender/makesdna/DNA_gpencil_types.h +++ b/source/blender/makesdna/DNA_gpencil_types.h @@ -148,8 +148,7 @@ typedef struct bGPDpalette { /* bGPDpalette->flag */ typedef enum eGPDpalette_Flag { /* palette is active */ - A, - PL_PALETTE_ACTIVE = (1 << 0) + PL_PALETTE_ACTIVE = (1 << 0), } eGPDpalette_Flag; /* ***************************************** */ @@ -412,7 +411,7 @@ typedef enum eGPLayerBlendModes { typedef struct bGPdata_Runtime { /** Last region where drawing was originated. */ struct ARegion *ar; - /** Stroke buffer (can hold GP_STROKE_BUFFER_MAX). */ + /** Stroke buffer. */ void *sbuffer; /* GP Object drawing */ @@ -431,11 +430,13 @@ typedef struct bGPdata_Runtime { * - buffer must be initialized before use, but freed after * whole paint operation is over */ - /** Number of elements currently in cache. */ - short sbuffer_size; + /** Number of elements currently used in cache. */ + short sbuffer_used; /** Flags for stroke that cache represents. */ short sbuffer_sflag; - char _pad[6]; + /** Number of total elements available in cache. */ + short sbuffer_size; + char _pad[4]; /** Number of control-points for stroke. */ int tot_cp_points; diff --git a/source/blender/makesdna/DNA_lightprobe_types.h b/source/blender/makesdna/DNA_lightprobe_types.h index 5cae3c0b1e9..6ffdd60a094 100644 --- a/source/blender/makesdna/DNA_lightprobe_types.h +++ b/source/blender/makesdna/DNA_lightprobe_types.h @@ -142,7 +142,7 @@ typedef struct LightGridCache { float visibility_bias, visibility_bleed, visibility_range, _pad5; } LightGridCache; -/* Theses are used as ubo data. They need to be aligned to size of vec4. */ +/* These are used as ubo data. They need to be aligned to size of vec4. */ BLI_STATIC_ASSERT_ALIGN(LightProbeCache, 16) BLI_STATIC_ASSERT_ALIGN(LightGridCache, 16) diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h index 672dbaebae1..75c0721f72a 100644 --- a/source/blender/makesdna/DNA_node_types.h +++ b/source/blender/makesdna/DNA_node_types.h @@ -387,12 +387,12 @@ typedef struct bNodeLink { #define NTREE_QUALITY_LOW 2 /* tree->chunksize */ -#define NTREE_CHUNCKSIZE_32 32 -#define NTREE_CHUNCKSIZE_64 64 -#define NTREE_CHUNCKSIZE_128 128 -#define NTREE_CHUNCKSIZE_256 256 -#define NTREE_CHUNCKSIZE_512 512 -#define NTREE_CHUNCKSIZE_1024 1024 +#define NTREE_CHUNKSIZE_32 32 +#define NTREE_CHUNKSIZE_64 64 +#define NTREE_CHUNKSIZE_128 128 +#define NTREE_CHUNKSIZE_256 256 +#define NTREE_CHUNKSIZE_512 512 +#define NTREE_CHUNKSIZE_1024 1024 /* the basis for a Node tree, all links and nodes reside internal here */ /* only re-usable node trees are in the library though, diff --git a/source/blender/makesdna/DNA_object_types.h b/source/blender/makesdna/DNA_object_types.h index 13b7a0a7600..d9487f4338f 100644 --- a/source/blender/makesdna/DNA_object_types.h +++ b/source/blender/makesdna/DNA_object_types.h @@ -177,7 +177,7 @@ typedef struct Object_Runtime { /** Runtime grease pencil drawing data */ struct GpencilBatchCache *gpencil_cache; - void *_pad2; /* Padding is here for win32s unconventional stuct alignment rules. */ + void *_pad2; /* Padding is here for win32s unconventional struct alignment rules. */ } Object_Runtime; typedef struct Object { diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index 0973405ce7b..f0ca4e30cdf 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -1116,7 +1116,7 @@ typedef struct GP_Sculpt_Settings { char _pad[4]; /** Multiframe edit falloff effect by frame. */ struct CurveMapping *cur_falloff; - /** Curve used for primitve tools. */ + /** Curve used for primitive tools. */ struct CurveMapping *cur_primitive; /** Guides used for paint tools */ struct GP_Sculpt_Guide guide; @@ -1138,7 +1138,7 @@ typedef enum eGP_Sculpt_SettingsFlag { GP_SCULPT_SETT_FLAG_FRAME_FALLOFF = (1 << 5), /* apply brush to uv data */ GP_SCULPT_SETT_FLAG_APPLY_UV = (1 << 6), - /* apply primitve curve */ + /* apply primitive curve */ GP_SCULPT_SETT_FLAG_PRIMITIVE_CURVE = (1 << 7), } eGP_Sculpt_SettingsFlag; diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h index 894dbc05c54..2d3d091c65d 100644 --- a/source/blender/makesdna/DNA_userdef_types.h +++ b/source/blender/makesdna/DNA_userdef_types.h @@ -756,8 +756,9 @@ typedef struct UserDef { char font_path_ui[1024]; char font_path_ui_mono[1024]; + /** Legacy, for backwards compatibility only. */ int compute_device_type; - int compute_device_id; + char _pad6[4]; /** Opacity of inactive F-Curves in F-Curve Editor. */ float fcu_inactive_alpha; diff --git a/source/blender/makesdna/intern/dna_genfile.c b/source/blender/makesdna/intern/dna_genfile.c index 3cc005535b6..5252c8f3350 100644 --- a/source/blender/makesdna/intern/dna_genfile.c +++ b/source/blender/makesdna/intern/dna_genfile.c @@ -899,7 +899,7 @@ static void cast_elem( * as lookup keys to identify data blocks in the saved .blend file, not * as actual in-memory pointers. * - * \param curlen: Pointer length to conver to + * \param curlen: Pointer length to convert to * \param oldlen: Length of pointers in olddata * \param name_array_len: Result of #DNA_elem_array_size for this element. * \param curdata: Where to put converted data diff --git a/source/blender/makesrna/intern/rna_brush.c b/source/blender/makesrna/intern/rna_brush.c index fb60f092d16..eeba7161309 100644 --- a/source/blender/makesrna/intern/rna_brush.c +++ b/source/blender/makesrna/intern/rna_brush.c @@ -1565,6 +1565,19 @@ static void rna_def_brush(BlenderRNA *brna) {0, NULL, 0, NULL, NULL}, }; + static const EnumPropertyItem brush_curve_preset_items[] = { + {BRUSH_CURVE_CUSTOM, "CUSTOM", ICON_RNDCURVE, "Custom", ""}, + {BRUSH_CURVE_SMOOTH, "SMOOTH", ICON_SMOOTHCURVE, "Smooth", ""}, + {BRUSH_CURVE_SPHERE, "SPHERE", ICON_SPHERECURVE, "Sphere", ""}, + {BRUSH_CURVE_ROOT, "ROOT", ICON_ROOTCURVE, "Root", ""}, + {BRUSH_CURVE_SHARP, "SHARP", ICON_SHARPCURVE, "Sharp", ""}, + {BRUSH_CURVE_LIN, "LIN", ICON_LINCURVE, "Linear", ""}, + {BRUSH_CURVE_POW4, "POW4", ICON_SHARPCURVE, "Sharper", ""}, + {BRUSH_CURVE_INVSQUARE, "INVSQUARE", ICON_INVERSESQUARECURVE, "Inverse square", ""}, + {BRUSH_CURVE_CONSTANT, "CONSTANT", ICON_NOCURVE, "Constant", ""}, + {0, NULL, 0, NULL, NULL}, + }; + srna = RNA_def_struct(brna, "Brush", "ID"); RNA_def_struct_ui_text( srna, "Brush", "Brush data-block for storing brush settings for painting and sculpting"); @@ -1640,6 +1653,11 @@ static void rna_def_brush(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Mask Tool", ""); RNA_def_property_update(prop, 0, "rna_Brush_update"); + prop = RNA_def_property(srna, "curve_preset", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_items(prop, brush_curve_preset_items); + RNA_def_property_ui_text(prop, "Curve Preset", ""); + RNA_def_property_update(prop, 0, "rna_Brush_update"); + /* number values */ prop = RNA_def_property(srna, "size", PROP_INT, PROP_PIXEL); RNA_def_property_int_funcs(prop, NULL, "rna_Brush_set_size", NULL); diff --git a/source/blender/makesrna/intern/rna_color.c b/source/blender/makesrna/intern/rna_color.c index 43df1d8e1aa..d221b7005f6 100644 --- a/source/blender/makesrna/intern/rna_color.c +++ b/source/blender/makesrna/intern/rna_color.c @@ -597,7 +597,7 @@ static void rna_ColorManagedColorspaceSettings_reload_update(Main *bmain, else if (GS(id->name) == ID_MC) { MovieClip *clip = (MovieClip *)id; - BKE_movieclip_reload(bmain, clip); + DEG_id_tag_update(&clip->id, ID_RECALC_SOURCE); BKE_sequence_invalidate_movieclip_strips(bmain, clip); WM_main_add_notifier(NC_MOVIECLIP | ND_DISPLAY, &clip->id); diff --git a/source/blender/makesrna/intern/rna_context.c b/source/blender/makesrna/intern/rna_context.c index 9986b4c1674..735cd1fd923 100644 --- a/source/blender/makesrna/intern/rna_context.c +++ b/source/blender/makesrna/intern/rna_context.c @@ -211,7 +211,7 @@ static struct Depsgraph *rna_Context_evaluated_depsgraph_get(bContext *C) BPy_BEGIN_ALLOW_THREADS; # endif - depsgraph = CTX_data_evaluated_depsgraph(C); + depsgraph = CTX_data_ensure_evaluated_depsgraph(C); # ifdef WITH_PYTHON BPy_END_ALLOW_THREADS; diff --git a/source/blender/makesrna/intern/rna_depsgraph.c b/source/blender/makesrna/intern/rna_depsgraph.c index df1727ff87c..ebd9bd8e925 100644 --- a/source/blender/makesrna/intern/rna_depsgraph.c +++ b/source/blender/makesrna/intern/rna_depsgraph.c @@ -346,7 +346,7 @@ static void rna_Depsgraph_object_instances_next(CollectionPropertyIterator *iter RNA_Depsgraph_Instances_Iterator *di_it = (RNA_Depsgraph_Instances_Iterator *) iter->internal.custom; - /* We need to copy current iterator status to next one beeing worked on. */ + /* We need to copy current iterator status to next one being worked on. */ di_it->iterators[(di_it->counter + 1) % 2] = di_it->iterators[di_it->counter % 2]; di_it->deg_data[(di_it->counter + 1) % 2] = di_it->deg_data[di_it->counter % 2]; di_it->counter++; diff --git a/source/blender/makesrna/intern/rna_image.c b/source/blender/makesrna/intern/rna_image.c index d6f4d82c298..75867b2fe13 100644 --- a/source/blender/makesrna/intern/rna_image.c +++ b/source/blender/makesrna/intern/rna_image.c @@ -700,7 +700,7 @@ static void rna_def_image(BlenderRNA *brna) "PREMUL", 0, "Premultiplied", - "Store RGB channels with alpha multipled in, also known as associated alpha. The natural " + "Store RGB channels with alpha multiplied in, also known as associated alpha. The natural " "format for renders and used by file formats like OpenEXR"}, {IMA_ALPHA_CHANNEL_PACKED, "CHANNEL_PACKED", diff --git a/source/blender/makesrna/intern/rna_layer.c b/source/blender/makesrna/intern/rna_layer.c index 1c0ced060d5..c9b51707759 100644 --- a/source/blender/makesrna/intern/rna_layer.c +++ b/source/blender/makesrna/intern/rna_layer.c @@ -178,8 +178,8 @@ static void rna_ViewLayer_update_tagged(ID *id_ptr, ViewLayer *view_layer, Main Scene *scene = (Scene *)id_ptr; Depsgraph *depsgraph = BKE_scene_get_depsgraph(scene, view_layer, true); - /* NOTE: This is similar to CTX_data_depsgraph(). Ideally such access would be de-duplicated - * across all possible cases, but for now this is safest and easiest way to go. + /* NOTE: This is similar to CTX_data_depsgraph_pointer(). Ideally such access would be + * de-duplicated across all possible cases, but for now this is safest and easiest way to go. * * The reason for this is that it's possible to have Python operator which asks view layer to * be updated. After re-do of such operator view layer's dependency graph will not be marked diff --git a/source/blender/makesrna/intern/rna_material.c b/source/blender/makesrna/intern/rna_material.c index 28989d1dd5f..162ba6be834 100644 --- a/source/blender/makesrna/intern/rna_material.c +++ b/source/blender/makesrna/intern/rna_material.c @@ -147,16 +147,8 @@ static void rna_Material_active_paint_texture_index_update(Main *bmain, Material *ma = ptr->id.data; if (ma->use_nodes && ma->nodetree) { - struct bNode *node; - int index = 0; - for (node = ma->nodetree->nodes.first; node; node = node->next) { - if (node->typeinfo->nclass == NODE_CLASS_TEXTURE && - node->typeinfo->type == SH_NODE_TEX_IMAGE && node->id) { - if (index++ == ma->paint_active_slot) { - break; - } - } - } + struct bNode *node = BKE_texpaint_slot_material_find_node(ma, ma->paint_active_slot); + if (node) { nodeSetActive(ma->nodetree, node); } diff --git a/source/blender/makesrna/intern/rna_mesh_api.c b/source/blender/makesrna/intern/rna_mesh_api.c index d647c647136..283590fc529 100644 --- a/source/blender/makesrna/intern/rna_mesh_api.c +++ b/source/blender/makesrna/intern/rna_mesh_api.c @@ -202,6 +202,14 @@ static void rna_Mesh_count_selected_items(Mesh *mesh, int r_count[3]) BKE_mesh_count_selected_items(mesh, r_count); } +static void rna_Mesh_clear_geometry(Mesh *mesh) +{ + BKE_mesh_clear_geometry(mesh); + + DEG_id_tag_update(&mesh->id, ID_RECALC_GEOMETRY); + WM_main_add_notifier(NC_GEOM | ND_DATA, mesh); +} + #else void RNA_api_mesh(StructRNA *srna) @@ -319,6 +327,11 @@ void RNA_api_mesh(StructRNA *srna) func, "result", "nothing", 64, "Return value", "String description of result of comparison"); RNA_def_function_return(func, parm); + func = RNA_def_function(srna, "clear_geometry", "rna_Mesh_clear_geometry"); + RNA_def_function_ui_description( + func, + "Remove all geometry from the mesh. Note that this does not free shape keys or materials"); + func = RNA_def_function(srna, "validate", "BKE_mesh_validate"); RNA_def_function_ui_description(func, "Validate geometry, return True when the mesh has had " diff --git a/source/blender/makesrna/intern/rna_meta.c b/source/blender/makesrna/intern/rna_meta.c index 92a32ec8ab5..743bac2b709 100644 --- a/source/blender/makesrna/intern/rna_meta.c +++ b/source/blender/makesrna/intern/rna_meta.c @@ -332,6 +332,7 @@ static void rna_def_metaball(BlenderRNA *brna) /* number values */ prop = RNA_def_property(srna, "resolution", PROP_FLOAT, PROP_DISTANCE); RNA_def_property_float_sdna(prop, NULL, "wiresize"); + RNA_def_property_float_default(prop, 0.4f); RNA_def_property_range(prop, 0.005f, 10000.0f); RNA_def_property_ui_range(prop, 0.05f, 1000.0f, 2.5f, 3); RNA_def_property_ui_text(prop, "Wire Size", "Polygonization resolution in the 3D viewport"); @@ -339,6 +340,7 @@ static void rna_def_metaball(BlenderRNA *brna) prop = RNA_def_property(srna, "render_resolution", PROP_FLOAT, PROP_DISTANCE); RNA_def_property_float_sdna(prop, NULL, "rendersize"); + RNA_def_property_float_default(prop, 0.2f); RNA_def_property_range(prop, 0.005f, 10000.0f); RNA_def_property_ui_range(prop, 0.025f, 1000.0f, 2.5f, 3); RNA_def_property_ui_text(prop, "Render Size", "Polygonization resolution in rendering"); diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index 6cd4be81a56..7e1ff01a7c3 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -1114,8 +1114,6 @@ static const EnumPropertyItem *rna_DataTransferModifier_layers_select_src_itemf( return rna_enum_dt_layers_select_src_items; } - Depsgraph *depsgraph = CTX_data_depsgraph(C); - /* No active here! */ RNA_enum_items_add_value( &item, &totitem, rna_enum_dt_layers_select_src_items, DT_LAYERS_ALL_SRC); @@ -1155,6 +1153,7 @@ static const EnumPropertyItem *rna_DataTransferModifier_layers_select_src_itemf( Mesh *me_eval; int num_data, i; + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); Object *ob_src_eval = DEG_get_evaluated_object(depsgraph, ob_src); @@ -1180,6 +1179,7 @@ static const EnumPropertyItem *rna_DataTransferModifier_layers_select_src_itemf( Mesh *me_eval; int num_data, i; + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); Object *ob_src_eval = DEG_get_evaluated_object(depsgraph, ob_src); @@ -5668,7 +5668,8 @@ static void rna_def_modifier_datatransfer(BlenderRNA *brna) 0.0f, 1.0f, "Mix Factor", - "Factor to use when applying data to destination (exact behavior depends on mix mode)", + "Factor to use when applying data to destination (exact behavior depends on mix mode, " + "multiplied with weights from vertex group when defined)", 0.0f, 1.0f); RNA_def_property_update(prop, 0, "rna_Modifier_update"); diff --git a/source/blender/makesrna/intern/rna_movieclip.c b/source/blender/makesrna/intern/rna_movieclip.c index 247c4c69019..10e19b92dda 100644 --- a/source/blender/makesrna/intern/rna_movieclip.c +++ b/source/blender/makesrna/intern/rna_movieclip.c @@ -51,12 +51,11 @@ # include "DNA_screen_types.h" # include "DNA_space_types.h" -static void rna_MovieClip_reload_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr) +static void rna_MovieClip_reload_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr) { MovieClip *clip = (MovieClip *)ptr->id.data; - BKE_movieclip_reload(bmain, clip); - DEG_id_tag_update(&clip->id, 0); + DEG_id_tag_update(&clip->id, ID_RECALC_SOURCE); } static void rna_MovieClip_size_get(PointerRNA *ptr, int *values) diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index eec280a5f3e..b28403bf28c 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -89,12 +89,12 @@ static const EnumPropertyItem node_quality_items[] = { }; static const EnumPropertyItem node_chunksize_items[] = { - {NTREE_CHUNCKSIZE_32, "32", 0, "32x32", "Chunksize of 32x32"}, - {NTREE_CHUNCKSIZE_64, "64", 0, "64x64", "Chunksize of 64x64"}, - {NTREE_CHUNCKSIZE_128, "128", 0, "128x128", "Chunksize of 128x128"}, - {NTREE_CHUNCKSIZE_256, "256", 0, "256x256", "Chunksize of 256x256"}, - {NTREE_CHUNCKSIZE_512, "512", 0, "512x512", "Chunksize of 512x512"}, - {NTREE_CHUNCKSIZE_1024, "1024", 0, "1024x1024", "Chunksize of 1024x1024"}, + {NTREE_CHUNKSIZE_32, "32", 0, "32x32", "Chunksize of 32x32"}, + {NTREE_CHUNKSIZE_64, "64", 0, "64x64", "Chunksize of 64x64"}, + {NTREE_CHUNKSIZE_128, "128", 0, "128x128", "Chunksize of 128x128"}, + {NTREE_CHUNKSIZE_256, "256", 0, "256x256", "Chunksize of 256x256"}, + {NTREE_CHUNKSIZE_512, "512", 0, "512x512", "Chunksize of 512x512"}, + {NTREE_CHUNKSIZE_1024, "1024", 0, "1024x1024", "Chunksize of 1024x1024"}, {0, NULL, 0, NULL, NULL}, }; #endif diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c index d3b532dd11d..6069e78d874 100644 --- a/source/blender/makesrna/intern/rna_object.c +++ b/source/blender/makesrna/intern/rna_object.c @@ -441,7 +441,7 @@ static void rna_Object_data_set(PointerRNA *ptr, PointerRNA value, struct Report return; } - if ((id->tag & LIB_TAG_NO_MAIN) != (ob->id.tag & LIB_TAG_NO_MAIN)) { + if (id && ((id->tag & LIB_TAG_NO_MAIN) != (ob->id.tag & LIB_TAG_NO_MAIN))) { BKE_report(reports, RPT_ERROR, "Can only assign evaluated data to evaluated object, or original data to " @@ -2537,7 +2537,7 @@ static void rna_def_object(BlenderRNA *brna) prop = RNA_def_property(srna, "dimensions", PROP_FLOAT, PROP_XYZ_LENGTH); RNA_def_property_array(prop, 3); - /* Only as convinient helper for py API, and conflicts with animating scale. */ + /* Only as convenient helper for py API, and conflicts with animating scale. */ RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_float_funcs( prop, "rna_Object_dimensions_get", "rna_Object_dimensions_set", NULL); @@ -2546,7 +2546,7 @@ static void rna_def_object(BlenderRNA *brna) prop, "Dimensions", "Absolute bounding box dimensions of the object (WARNING: assigning to it or " - "its members mutiple consecutive times will not work correctly, " + "its members multiple consecutive times will not work correctly, " "as this needs up-to-date evaluated data)"); RNA_def_property_update(prop, NC_OBJECT | ND_TRANSFORM, "rna_Object_internal_update"); diff --git a/source/blender/makesrna/intern/rna_object_api.c b/source/blender/makesrna/intern/rna_object_api.c index c91481931a2..9a76885a19d 100644 --- a/source/blender/makesrna/intern/rna_object_api.c +++ b/source/blender/makesrna/intern/rna_object_api.c @@ -465,6 +465,8 @@ static int mesh_looptri_to_poly_index(Mesh *me_eval, const MLoopTri *lt) return index_mp_to_orig ? index_mp_to_orig[lt->poly] : lt->poly; } +/* TOOD(sergey): Make the Python API more clear that evaluation might happen, or requite passing + * fully evaluated depsgraph. */ static Object *eval_object_ensure(Object *ob, bContext *C, ReportList *reports, @@ -474,7 +476,7 @@ static Object *eval_object_ensure(Object *ob, Object *ob_orig = ob; Depsgraph *depsgraph = rnaptr_depsgraph != NULL ? rnaptr_depsgraph->data : NULL; if (depsgraph == NULL) { - depsgraph = CTX_data_depsgraph(C); + depsgraph = CTX_data_ensure_evaluated_depsgraph(C); } if (depsgraph != NULL) { ob = DEG_get_evaluated_object(depsgraph, ob); @@ -502,6 +504,8 @@ static void rna_Object_ray_cast(Object *ob, { bool success = false; + /* TODO(sergey): This isn't very reliable check. It is possible to have non-NULL pointer but + * which is out of date, and possibly dangling one. */ if (ob->runtime.mesh_eval == NULL && (ob = eval_object_ensure(ob, C, reports, rnaptr_depsgraph)) == NULL) { return; @@ -972,7 +976,7 @@ void RNA_api_object(StructRNA *srna) RNA_def_parameter_flags(parm, 0, PARM_RNAPTR); /* return location and normal */ - parm = RNA_def_boolean(func, "result", 0, "", "Wheter the ray successfully hit the geometry"); + parm = RNA_def_boolean(func, "result", 0, "", "Whether the ray successfully hit the geometry"); RNA_def_function_output(func, parm); parm = RNA_def_float_vector(func, "location", @@ -1035,7 +1039,7 @@ void RNA_api_object(StructRNA *srna) RNA_def_parameter_flags(parm, 0, PARM_RNAPTR); /* return location and normal */ - parm = RNA_def_boolean(func, "result", 0, "", "Wheter closest point on geometry was found"); + parm = RNA_def_boolean(func, "result", 0, "", "Whether closest point on geometry was found"); RNA_def_function_output(func, parm); parm = RNA_def_float_vector(func, "location", @@ -1109,7 +1113,7 @@ void RNA_api_object(StructRNA *srna) "(only needed if current Context's depsgraph is not suitable)"); RNA_def_parameter_flags(parm, 0, PARM_RNAPTR); /* weak!, no way to return dynamic string type */ - parm = RNA_def_string(func, "result", NULL, 16384, "", "Requested informations"); + parm = RNA_def_string(func, "result", NULL, 16384, "", "Requested information"); RNA_def_parameter_flags(parm, PROP_THICK_WRAP, 0); /* needed for string return value */ RNA_def_function_output(func, parm); # endif /* NDEBUG */ diff --git a/source/blender/makesrna/intern/rna_rna.c b/source/blender/makesrna/intern/rna_rna.c index 9834520f952..3ca4792f9b4 100644 --- a/source/blender/makesrna/intern/rna_rna.c +++ b/source/blender/makesrna/intern/rna_rna.c @@ -3077,7 +3077,7 @@ void RNA_def_rna(BlenderRNA *brna) /* FloatProperty */ srna = RNA_def_struct(brna, "FloatProperty", "Property"); RNA_def_struct_ui_text( - srna, "Float Definition", "RNA floating pointer number property definition"); + srna, "Float Definition", "RNA floating point number (single precision) property definition"); rna_def_number_property(srna, PROP_FLOAT); /* StringProperty */ diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index dcbbdd67d7b..fd8791cf193 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -5171,6 +5171,7 @@ static void rna_def_scene_ffmpeg_settings(BlenderRNA *brna) {FFMPEG_OGG, "OGG", 0, "Ogg", ""}, {FFMPEG_MKV, "MKV", 0, "Matroska", ""}, {FFMPEG_FLV, "FLASH", 0, "Flash", ""}, + {FFMPEG_WEBM, "WEBM", 0, "WebM", ""}, {0, NULL, 0, NULL, NULL}, }; @@ -5229,6 +5230,7 @@ static void rna_def_scene_ffmpeg_settings(BlenderRNA *brna) {AV_CODEC_ID_FLAC, "FLAC", 0, "FLAC", ""}, {AV_CODEC_ID_MP2, "MP2", 0, "MP2", ""}, {AV_CODEC_ID_MP3, "MP3", 0, "MP3", ""}, + {AV_CODEC_ID_OPUS, "OPUS", 0, "Opus", ""}, {AV_CODEC_ID_PCM_S16LE, "PCM", 0, "PCM", ""}, {AV_CODEC_ID_VORBIS, "VORBIS", 0, "Vorbis", ""}, {0, NULL, 0, NULL, NULL}, diff --git a/source/blender/makesrna/intern/rna_sequencer.c b/source/blender/makesrna/intern/rna_sequencer.c index 241764ff9a6..b54fdf5aadb 100644 --- a/source/blender/makesrna/intern/rna_sequencer.c +++ b/source/blender/makesrna/intern/rna_sequencer.c @@ -161,7 +161,7 @@ static void rna_Sequence_use_sequence(Main *bmain, Scene *scene, PointerRNA *ptr { /* General update callback. */ rna_Sequence_invalidate_raw_update(bmain, scene, ptr); - /* Chaning recursion changes set of IDs which needs to be remapped by the copy-on-write. + /* Changing recursion changes set of IDs which needs to be remapped by the copy-on-write. * the only way for this currently is to tag the ID for ID_RECALC_COPY_ON_WRITE. */ Editing *ed = BKE_sequencer_editing_get(scene, false); if (ed) { diff --git a/source/blender/makesrna/intern/rna_tracking.c b/source/blender/makesrna/intern/rna_tracking.c index 83e4766c57d..84bde91e654 100644 --- a/source/blender/makesrna/intern/rna_tracking.c +++ b/source/blender/makesrna/intern/rna_tracking.c @@ -1066,7 +1066,7 @@ static void rna_def_trackingSettings(BlenderRNA *brna) prop, "Normalize", "Normalize light intensities while tracking (slower)"); RNA_def_property_update(prop, NC_MOVIECLIP | ND_DISPLAY, NULL); - /* default minmal correlation */ + /* default minimal correlation */ prop = RNA_def_property(srna, "default_correlation_min", PROP_FLOAT, PROP_NONE); RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c index 8a9b8a14563..7b7d9e71cd2 100644 --- a/source/blender/makesrna/intern/rna_userdef.c +++ b/source/blender/makesrna/intern/rna_userdef.c @@ -5112,13 +5112,18 @@ static void rna_def_userdef_input(BlenderRNA *brna) "CONTINUE", 0, "Continue", - "Old style zoom, continues while moving mouse up or down"}, - {USER_ZOOM_DOLLY, "DOLLY", 0, "Dolly", "Zoom in and out based on vertical mouse movement"}, + "Continuous zooming. The zoom direction and speed depends on how far along the set Zoom " + "Axis the mouse has moved"}, + {USER_ZOOM_DOLLY, + "DOLLY", + 0, + "Dolly", + "Zoom in and out based on mouse movement along the set Zoom Axis"}, {USER_ZOOM_SCALE, "SCALE", 0, "Scale", - "Zoom in and out like scaling the view, mouse movements relative to center"}, + "Zoom in and out as if you are scaling the view, mouse movements relative to center"}, {0, NULL, 0, NULL, NULL}, }; diff --git a/source/blender/makesrna/intern/rna_wm_api.c b/source/blender/makesrna/intern/rna_wm_api.c index 1fea87df10c..d9306ba7a65 100644 --- a/source/blender/makesrna/intern/rna_wm_api.c +++ b/source/blender/makesrna/intern/rna_wm_api.c @@ -471,12 +471,12 @@ static void rna_PopMenuEnd(bContext *C, PointerRNA *handle) } /* popover wrapper */ -static PointerRNA rna_PopoverBegin(bContext *C, int ui_units_x) +static PointerRNA rna_PopoverBegin(bContext *C, int ui_units_x, bool from_active_button) { PointerRNA r_ptr; void *data; - data = (void *)UI_popover_begin(C, U.widget_unit * ui_units_x); + data = (void *)UI_popover_begin(C, U.widget_unit * ui_units_x, from_active_button); RNA_pointer_create(NULL, &RNA_UIPopover, data, &r_ptr); @@ -821,6 +821,8 @@ void RNA_api_wm(StructRNA *srna) parm = RNA_def_pointer(func, "menu", "UIPopover", "", ""); RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_RNAPTR); RNA_def_function_return(func, parm); + RNA_def_boolean( + func, "from_active_button", 0, "Use Button", "Use the active button for positioning"); /* wrap UI_popover_end */ func = RNA_def_function(srna, "popover_end__internal", "rna_PopoverEnd"); diff --git a/source/blender/modifiers/intern/MOD_correctivesmooth.c b/source/blender/modifiers/intern/MOD_correctivesmooth.c index 705ffb266c5..3df66855376 100644 --- a/source/blender/modifiers/intern/MOD_correctivesmooth.c +++ b/source/blender/modifiers/intern/MOD_correctivesmooth.c @@ -523,7 +523,7 @@ static void calc_deltas(CorrectiveSmoothModifierData *csmd, MEM_SAFE_FREE(csmd->delta_cache); } - /* allocate deltas if they have not yet been allocated, otheriwse we will just write over them */ + /* allocate deltas if they have not yet been allocated, otherwise we will just write over them */ if (!csmd->delta_cache) { csmd->delta_cache_num = numVerts; csmd->delta_cache = MEM_malloc_arrayN(numVerts, sizeof(float[3]), __func__); diff --git a/source/blender/modifiers/intern/MOD_datatransfer.c b/source/blender/modifiers/intern/MOD_datatransfer.c index 3235d64cbbb..c994a680fb0 100644 --- a/source/blender/modifiers/intern/MOD_datatransfer.c +++ b/source/blender/modifiers/intern/MOD_datatransfer.c @@ -158,7 +158,7 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes Mesh *result = me_mod; ReportList reports; - /* Only used to check wehther we are operating on org data or not... */ + /* Only used to check whether we are operating on org data or not... */ Mesh *me = ctx->object->data; Object *ob_source = dtmd->ob_source; diff --git a/source/blender/modifiers/intern/MOD_displace.c b/source/blender/modifiers/intern/MOD_displace.c index 50447ae0376..ac0d72214c8 100644 --- a/source/blender/modifiers/intern/MOD_displace.c +++ b/source/blender/modifiers/intern/MOD_displace.c @@ -169,7 +169,7 @@ typedef struct DisplaceUserdata { static void displaceModifier_do_task(void *__restrict userdata, const int iter, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { DisplaceUserdata *data = (DisplaceUserdata *)userdata; DisplaceModifierData *dmd = data->dmd; @@ -348,7 +348,7 @@ static void displaceModifier_do(DisplaceModifierData *dmd, data.pool = BKE_image_pool_new(); BKE_texture_fetch_images_for_pool(tex_target, data.pool); } - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (numVerts > 512); BLI_task_parallel_range(0, numVerts, &data, displaceModifier_do_task, &settings); diff --git a/source/blender/modifiers/intern/MOD_laplaciandeform.c b/source/blender/modifiers/intern/MOD_laplaciandeform.c index e27d2786751..abb4c5cae32 100644 --- a/source/blender/modifiers/intern/MOD_laplaciandeform.c +++ b/source/blender/modifiers/intern/MOD_laplaciandeform.c @@ -671,8 +671,9 @@ static void LaplacianDeformModifier_do( &lmd->modifier, "Edges changed from %d to %d", sys->total_edges, mesh->totedge); } else if (sysdif == LAPDEFORM_SYSTEM_CHANGE_NOT_VALID_GROUP) { - modifier_setError( - &lmd->modifier, "Vertex group '%s' is not valid", sys->anchor_grp_name); + modifier_setError(&lmd->modifier, + "Vertex group '%s' is not valid, or maybe empty", + sys->anchor_grp_name); } } } @@ -683,7 +684,8 @@ static void LaplacianDeformModifier_do( } else { if (!isValidVertexGroup(lmd, ob, mesh)) { - modifier_setError(&lmd->modifier, "Vertex group '%s' is not valid", lmd->anchor_grp_name); + modifier_setError( + &lmd->modifier, "Vertex group '%s' is not valid, or maybe empty", lmd->anchor_grp_name); lmd->flag &= ~MOD_LAPLACIANDEFORM_BIND; } else if (lmd->total_verts > 0 && lmd->total_verts == numVerts) { diff --git a/source/blender/modifiers/intern/MOD_meshdeform.c b/source/blender/modifiers/intern/MOD_meshdeform.c index d89a47f4cf3..da261b4f835 100644 --- a/source/blender/modifiers/intern/MOD_meshdeform.c +++ b/source/blender/modifiers/intern/MOD_meshdeform.c @@ -259,7 +259,7 @@ typedef struct MeshdeformUserdata { static void meshdeform_vert_task(void *__restrict userdata, const int iter, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { MeshdeformUserdata *data = userdata; /*const*/ MeshDeformModifierData *mmd = data->mmd; @@ -435,7 +435,7 @@ static void meshdeformModifier_do(ModifierData *md, data.icagemat = icagemat; /* Do deformation. */ - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.min_iter_per_thread = 16; BLI_task_parallel_range(0, totvert, &data, meshdeform_vert_task, &settings); diff --git a/source/blender/modifiers/intern/MOD_ocean.c b/source/blender/modifiers/intern/MOD_ocean.c index 5cded96efe2..aff5b8b071b 100644 --- a/source/blender/modifiers/intern/MOD_ocean.c +++ b/source/blender/modifiers/intern/MOD_ocean.c @@ -196,7 +196,7 @@ typedef struct GenerateOceanGeometryData { static void generate_ocean_geometry_vertices(void *__restrict userdata, const int y, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { GenerateOceanGeometryData *gogd = userdata; int x; @@ -212,7 +212,7 @@ static void generate_ocean_geometry_vertices(void *__restrict userdata, static void generate_ocean_geometry_polygons(void *__restrict userdata, const int y, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { GenerateOceanGeometryData *gogd = userdata; int x; @@ -241,7 +241,7 @@ static void generate_ocean_geometry_polygons(void *__restrict userdata, static void generate_ocean_geometry_uvs(void *__restrict userdata, const int y, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { GenerateOceanGeometryData *gogd = userdata; int x; @@ -301,7 +301,7 @@ static Mesh *generate_ocean_geometry(OceanModifierData *omd) gogd.mpolys = result->mpoly; gogd.mloops = result->mloop; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = use_threading; diff --git a/source/blender/modifiers/intern/MOD_skin.c b/source/blender/modifiers/intern/MOD_skin.c index b6ab3f5b4fe..1a541f9fc5a 100644 --- a/source/blender/modifiers/intern/MOD_skin.c +++ b/source/blender/modifiers/intern/MOD_skin.c @@ -864,7 +864,7 @@ static Mesh *subdivide_base(Mesh *orig) } /* Per edge, store how many subdivisions are needed */ - edge_subd = MEM_calloc_arrayN(totorigedge, sizeof(int), "edge_subd"); + edge_subd = MEM_calloc_arrayN((uint)totorigedge, sizeof(int), "edge_subd"); for (i = 0, totsubd = 0; i < totorigedge; i++) { edge_subd[i] += calc_edge_subdivisions(origvert, orignode, &origedge[i], degree); BLI_assert(edge_subd[i] >= 0); diff --git a/source/blender/modifiers/intern/MOD_surfacedeform.c b/source/blender/modifiers/intern/MOD_surfacedeform.c index 47c0114f02f..c428325e42b 100644 --- a/source/blender/modifiers/intern/MOD_surfacedeform.c +++ b/source/blender/modifiers/intern/MOD_surfacedeform.c @@ -796,7 +796,7 @@ BLI_INLINE float computeNormalDisplacement(const float point_co[3], static void bindVert(void *__restrict userdata, const int index, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { SDefBindCalcData *const data = (SDefBindCalcData *)userdata; float point_co[3]; @@ -1076,7 +1076,7 @@ static bool surfacedeformBind(SurfaceDeformModifierData *smd, mul_v3_m4v3(data.targetCos[i], smd->mat, mvert[i].co); } - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (numverts > 10000); BLI_task_parallel_range(0, numverts, &data, bindVert, &settings); @@ -1116,7 +1116,7 @@ static bool surfacedeformBind(SurfaceDeformModifierData *smd, static void deformVert(void *__restrict userdata, const int index, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { const SDefDeformData *const data = (SDefDeformData *)userdata; const SDefBind *sdbind = data->bind_verts[index].binds; @@ -1247,7 +1247,7 @@ static void surfacedeformModifier_do(ModifierData *md, mul_v3_m4v3(data.targetCos[i], smd->mat, mvert[i].co); } - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (numverts > 10000); BLI_task_parallel_range(0, numverts, &data, deformVert, &settings); diff --git a/source/blender/modifiers/intern/MOD_uvwarp.c b/source/blender/modifiers/intern/MOD_uvwarp.c index 995f3d06fcb..2c5f4b66c23 100644 --- a/source/blender/modifiers/intern/MOD_uvwarp.c +++ b/source/blender/modifiers/intern/MOD_uvwarp.c @@ -98,7 +98,7 @@ typedef struct UVWarpData { static void uv_warp_compute(void *__restrict userdata, const int i, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { const UVWarpData *data = userdata; @@ -202,7 +202,7 @@ static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mes .axis_u = axis_u, .axis_v = axis_v, }; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (numPolys > 1000); BLI_task_parallel_range(0, numPolys, &data, uv_warp_compute, &settings); diff --git a/source/blender/modifiers/intern/MOD_weightvgproximity.c b/source/blender/modifiers/intern/MOD_weightvgproximity.c index 37f25fd7c89..86d1b310d0c 100644 --- a/source/blender/modifiers/intern/MOD_weightvgproximity.c +++ b/source/blender/modifiers/intern/MOD_weightvgproximity.c @@ -92,7 +92,7 @@ typedef struct Vert2GeomDataChunk { */ static void vert2geom_task_cb_ex(void *__restrict userdata, const int iter, - const ParallelRangeTLS *__restrict tls) + const TaskParallelTLS *__restrict tls) { Vert2GeomData *data = userdata; Vert2GeomDataChunk *data_chunk = tls->userdata_chunk; @@ -188,7 +188,7 @@ static void get_vert2geom_distance(int numVerts, data.dist[1] = dist_e; data.dist[2] = dist_f; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (numVerts > 10000); settings.userdata_chunk = &data_chunk; diff --git a/source/blender/nodes/composite/nodes/node_composite_colorSpill.c b/source/blender/nodes/composite/nodes/node_composite_colorSpill.c index d47cf72f086..e4fa7fbc757 100644 --- a/source/blender/nodes/composite/nodes/node_composite_colorSpill.c +++ b/source/blender/nodes/composite/nodes/node_composite_colorSpill.c @@ -23,7 +23,7 @@ #include "node_composite_util.h" -/* ******************* Color Spill Supression ********************************* */ +/* ******************* Color Spill Suppression ********************************* */ static bNodeSocketTemplate cmp_node_color_spill_in[] = { {SOCK_RGBA, 1, N_("Image"), 1.0f, 1.0f, 1.0f, 1.0f}, {SOCK_FLOAT, 1, N_("Fac"), 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_FACTOR}, diff --git a/source/blender/nodes/composite/nodes/node_composite_common.c b/source/blender/nodes/composite/nodes/node_composite_common.c index a22835ba85b..0736496a24f 100644 --- a/source/blender/nodes/composite/nodes/node_composite_common.c +++ b/source/blender/nodes/composite/nodes/node_composite_common.c @@ -60,7 +60,7 @@ void register_node_type_cmp_group(void) void register_node_type_cmp_custom_group(bNodeType *ntype) { - /* These methods can be overriden but need a default implementation otherwise. */ + /* These methods can be overridden but need a default implementation otherwise. */ if (ntype->poll == NULL) { ntype->poll = cmp_node_poll_default; } diff --git a/source/blender/nodes/composite/nodes/node_composite_cryptomatte.c b/source/blender/nodes/composite/nodes/node_composite_cryptomatte.c index 8d05c18621f..dcd8589cfdd 100644 --- a/source/blender/nodes/composite/nodes/node_composite_cryptomatte.c +++ b/source/blender/nodes/composite/nodes/node_composite_cryptomatte.c @@ -63,7 +63,7 @@ static void cryptomatte_add(NodeCryptomatte *n, float f) ++start; } - /* Find the next seprator. */ + /* Find the next separator. */ char *token_end = strchr(n->matte_id + start, ','); if (token_end == NULL || token_end == n->matte_id + start) { token_end = n->matte_id + end; @@ -142,7 +142,7 @@ static void cryptomatte_remove(NodeCryptomatte *n, float f) ++start; } - /* Find the next seprator. */ + /* Find the next separator. */ char *token_end = strchr(n->matte_id + start + 1, ','); if (token_end == NULL || token_end == n->matte_id + start) { token_end = n->matte_id + end; diff --git a/source/blender/nodes/composite/nodes/node_composite_vecBlur.c b/source/blender/nodes/composite/nodes/node_composite_vecBlur.c index f1f44d07084..497c2555d86 100644 --- a/source/blender/nodes/composite/nodes/node_composite_vecBlur.c +++ b/source/blender/nodes/composite/nodes/node_composite_vecBlur.c @@ -39,7 +39,7 @@ static void node_composit_init_vecblur(bNodeTree *UNUSED(ntree), bNode *node) nbd->fac = 1.0f; } -/* custom1: itterations, custom2: maxspeed (0 = nolimit) */ +/* custom1: iterations, custom2: maxspeed (0 = nolimit) */ void register_node_type_cmp_vecblur(void) { static bNodeType ntype; diff --git a/source/blender/nodes/shader/node_shader_tree.c b/source/blender/nodes/shader/node_shader_tree.c index 92b24d40b0d..4891fb323ad 100644 --- a/source/blender/nodes/shader/node_shader_tree.c +++ b/source/blender/nodes/shader/node_shader_tree.c @@ -782,7 +782,7 @@ static void ntree_shader_relink_displacement(bNodeTree *ntree, bNode *output_nod return; } - /* Copy the whole displacement branch to avoid cyclic dependancy + /* Copy the whole displacement branch to avoid cyclic dependency * and issue when bypassing bump nodes. */ ntree_shader_copy_branch_displacement( ntree, displacement_node, displacement_socket, displacement_link); diff --git a/source/blender/nodes/shader/nodes/node_shader_attribute.c b/source/blender/nodes/shader/nodes/node_shader_attribute.c index ec1bb988c1c..c92ae28f2e6 100644 --- a/source/blender/nodes/shader/nodes/node_shader_attribute.c +++ b/source/blender/nodes/shader/nodes/node_shader_attribute.c @@ -42,7 +42,7 @@ static int node_shader_gpu_attribute(GPUMaterial *mat, { NodeShaderAttribute *attr = node->storage; - /* FIXME : if an attribute layer (like vertex color) has one of theses name, + /* FIXME : if an attribute layer (like vertex color) has one of these names, * it will not work as expected. */ if (strcmp(attr->name, "density") == 0) { return GPU_stack_link( diff --git a/source/blender/nodes/shader/nodes/node_shader_common.c b/source/blender/nodes/shader/nodes/node_shader_common.c index cee4d2505b2..10f6aadbc5f 100644 --- a/source/blender/nodes/shader/nodes/node_shader_common.c +++ b/source/blender/nodes/shader/nodes/node_shader_common.c @@ -254,7 +254,7 @@ void register_node_type_sh_group(void) void register_node_type_sh_custom_group(bNodeType *ntype) { - /* These methods can be overriden but need a default implementation otherwise. */ + /* These methods can be overridden but need a default implementation otherwise. */ if (ntype->poll == NULL) { ntype->poll = sh_node_poll_default; } diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp index bc404110008..95c16c2f033 100644 --- a/source/blender/physics/intern/BPH_mass_spring.cpp +++ b/source/blender/physics/intern/BPH_mass_spring.cpp @@ -393,7 +393,7 @@ BLI_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s) if (s->type & CLOTH_SPRING_TYPE_SEWING) { /* TODO: verify, half verified (couldn't see error) * sewing springs usually have a large distance at first so clamp the force so we don't get - * tunnelling through colission objects */ + * tunnelling through collision objects. */ BPH_mass_spring_force_spring_linear(data, s->ij, s->kl, diff --git a/source/blender/python/gpu/gpu_py_batch.c b/source/blender/python/gpu/gpu_py_batch.c index a9e65413767..f147b7de01d 100644 --- a/source/blender/python/gpu/gpu_py_batch.c +++ b/source/blender/python/gpu/gpu_py_batch.c @@ -214,7 +214,7 @@ PyDoc_STRVAR(bpygpu_Batch_draw_doc, " Run the drawing program with the parameters assigned to the batch.\n" "\n" " :param program: Program that performs the drawing operations.\n" - " If ``None`` is passed, the last program setted to this batch will run.\n" + " If ``None`` is passed, the last program set to this batch will run.\n" " :type program: :class:`gpu.types.GPUShader`\n"); static PyObject *bpygpu_Batch_draw(BPyGPUBatch *self, PyObject *args) { diff --git a/source/blender/python/gpu/gpu_py_vertex_format.c b/source/blender/python/gpu/gpu_py_vertex_format.c index 34df4cb1a4b..d8266be7e2c 100644 --- a/source/blender/python/gpu/gpu_py_vertex_format.c +++ b/source/blender/python/gpu/gpu_py_vertex_format.c @@ -114,7 +114,7 @@ static int bpygpu_ParseVertCompType(PyObject *o, void *p) int comp_type = bpygpu_parse_component_type(str, length); if (comp_type == -1) { - PyErr_Format(PyExc_ValueError, "unkown component type: '%s", str); + PyErr_Format(PyExc_ValueError, "unknown component type: '%s", str); return 0; } @@ -188,7 +188,7 @@ static PyObject *bpygpu_VertFormat_attr_add(BPyGPUVertFormat *self, PyObject *ar } params; if (self->fmt.attr_len == GPU_VERT_ATTR_MAX_LEN) { - PyErr_SetString(PyExc_ValueError, "Maxumum attr reached " STRINGIFY(GPU_VERT_ATTR_MAX_LEN)); + PyErr_SetString(PyExc_ValueError, "Maximum attr reached " STRINGIFY(GPU_VERT_ATTR_MAX_LEN)); return NULL; } diff --git a/source/blender/python/intern/bpy.c b/source/blender/python/intern/bpy.c index b8a83d0588d..8c34699b598 100644 --- a/source/blender/python/intern/bpy.c +++ b/source/blender/python/intern/bpy.c @@ -386,7 +386,7 @@ void BPy_init_modules(void) Py_DECREF(py_modpath); } else { - printf("bpy: couldnt find 'scripts/modules', blender probably wont start.\n"); + printf("bpy: couldn't find 'scripts/modules', blender probably wont start.\n"); } /* stand alone utility modules not related to blender directly */ IDProp_Init_Types(); /* not actually a submodule, just types */ diff --git a/source/blender/python/intern/bpy_interface_atexit.c b/source/blender/python/intern/bpy_interface_atexit.c index 1c48dc1baae..4a43d4e6853 100644 --- a/source/blender/python/intern/bpy_interface_atexit.c +++ b/source/blender/python/intern/bpy_interface_atexit.c @@ -36,7 +36,7 @@ static PyObject *bpy_atexit(PyObject *UNUSED(self), PyObject *UNUSED(args), PyOb /* close down enough of blender at least not to crash */ struct bContext *C = BPy_GetContext(); - WM_exit_ext(C, 0); + WM_exit_ex(C, false); Py_RETURN_NONE; } diff --git a/source/blender/python/intern/bpy_props.c b/source/blender/python/intern/bpy_props.c index ad7d5137ebc..50c61dd0061 100644 --- a/source/blender/python/intern/bpy_props.c +++ b/source/blender/python/intern/bpy_props.c @@ -2566,8 +2566,8 @@ PyDoc_STRVAR(BPy_FloatProperty_doc, ".. function:: FloatProperty(name=\"\", " "description=\"\", " "default=0.0, " - "min=sys.float_info.min, max=sys.float_info.max, " - "soft_min=sys.float_info.min, soft_max=sys.float_info.max, " + "min=-3.402823e+38, max=3.402823e+38, " + "soft_min=-3.402823e+38, soft_max=3.402823e+38, " "step=3, " "precision=2, " "options={'ANIMATABLE'}, " @@ -2578,7 +2578,7 @@ PyDoc_STRVAR(BPy_FloatProperty_doc, "get=None, " "set=None)\n" "\n" - " Returns a new float property definition.\n" + " Returns a new float (single precision) property definition.\n" "\n" BPY_PROPDEF_NAME_DOC BPY_PROPDEF_DESC_DOC BPY_PROPDEF_NUM_MIN_DOC " :type min: float\n" BPY_PROPDEF_NUM_MAX_DOC " :type max: float\n" BPY_PROPDEF_NUM_SOFTMIN_DOC @@ -2968,7 +2968,7 @@ PyDoc_STRVAR( " The first three elements of the tuples are mandatory.\n" "\n" " :identifier: The identifier is used for Python access.\n" - " :name: Name for the interace.\n" + " :name: Name for the interface.\n" " :description: Used for documentation and tooltips.\n" " :icon: An icon string identifier or integer icon value\n" " (e.g. returned by :class:`bpy.types.UILayout.icon`)\n" diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 734e929fdf4..9a8d8c5ec21 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -1857,7 +1857,7 @@ static int pyrna_py_to_prop( else { /* Same as bytes. */ /* XXX, this is suspect, but needed for function calls, - * need to see if theres a better way. */ + * need to see if there's a better way. */ if (data) { *((char **)data) = (char *)param; } diff --git a/source/blender/python/intern/bpy_rna_anim.c b/source/blender/python/intern/bpy_rna_anim.c index 710ae0433e0..fb9454bf108 100644 --- a/source/blender/python/intern/bpy_rna_anim.c +++ b/source/blender/python/intern/bpy_rna_anim.c @@ -301,7 +301,7 @@ char pyrna_struct_keyframe_insert_doc[] = " - ``INSERTKEY_VISUAL`` Insert keyframes based on 'visual transforms'.\n" " - ``INSERTKEY_XYZ_TO_RGB`` Color for newly added transformation F-Curves (Location, " "Rotation, Scale) is based on the transform axis.\n" - " - ``INSERTKEY_REPLACE`` Only replace already exising keyframes.\n" + " - ``INSERTKEY_REPLACE`` Only replace already existing keyframes.\n" " - ``INSERTKEY_AVAILABLE`` Only insert into already existing F-Curves.\n" " - ``INSERTKEY_CYCLE_AWARE`` Take cyclic extrapolation into account " "(Cycle-Aware Keying option).\n" @@ -337,7 +337,6 @@ PyObject *pyrna_struct_keyframe_insert(BPy_StructRNA *self, PyObject *args, PyOb * strips themselves. These are stored separately or else the properties will * not have any effect. */ - struct Depsgraph *depsgraph = CTX_data_depsgraph(BPy_GetContext()); ReportList reports; short result = 0; @@ -357,8 +356,7 @@ PyObject *pyrna_struct_keyframe_insert(BPy_StructRNA *self, PyObject *args, PyOb NlaStrip *strip = (NlaStrip *)ptr.data; FCurve *fcu = list_find_fcurve(&strip->fcurves, RNA_property_identifier(prop), index); - result = insert_keyframe_direct( - depsgraph, &reports, ptr, prop, fcu, cfra, keytype, NULL, options); + result = insert_keyframe_direct(&reports, ptr, prop, fcu, cfra, keytype, NULL, options); } else { BKE_reportf(&reports, RPT_ERROR, "Could not resolve path (%s)", path_full); @@ -373,25 +371,14 @@ PyObject *pyrna_struct_keyframe_insert(BPy_StructRNA *self, PyObject *args, PyOb } else { ID *id = self->ptr.id.data; - struct Depsgraph *depsgraph = CTX_data_depsgraph(BPy_GetContext()); ReportList reports; short result; BKE_reports_init(&reports, RPT_STORE); BLI_assert(BKE_id_is_in_global_main(id)); - result = insert_keyframe(G_MAIN, - depsgraph, - &reports, - id, - NULL, - group_name, - path_full, - index, - cfra, - keytype, - NULL, - options); + result = insert_keyframe( + G_MAIN, &reports, id, NULL, group_name, path_full, index, cfra, keytype, NULL, options); MEM_freeN((void *)path_full); if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) { diff --git a/source/blender/python/intern/bpy_traceback.c b/source/blender/python/intern/bpy_traceback.c index c9c9e4adafb..06d8b645ac7 100644 --- a/source/blender/python/intern/bpy_traceback.c +++ b/source/blender/python/intern/bpy_traceback.c @@ -143,7 +143,6 @@ void python_script_error_jump(const char *filepath, int *lineno, int *offset) /* no traceback available when SyntaxError. * python has no api's to this. reference parse_syntax_error() from pythonrun.c */ PyErr_NormalizeException(&exception, &value, (PyObject **)&tb); - PyErr_Restore(exception, value, (PyObject *)tb); /* takes away reference! */ if (value) { /* should always be true */ PyObject *message; @@ -165,6 +164,7 @@ void python_script_error_jump(const char *filepath, int *lineno, int *offset) *lineno = -1; } } + PyErr_Restore(exception, value, (PyObject *)tb); /* takes away reference! */ } else { PyErr_NormalizeException(&exception, &value, (PyObject **)&tb); diff --git a/source/blender/python/mathutils/mathutils_Vector.c b/source/blender/python/mathutils/mathutils_Vector.c index 2c9a25d24bc..1f17d1eebf2 100644 --- a/source/blender/python/mathutils/mathutils_Vector.c +++ b/source/blender/python/mathutils/mathutils_Vector.c @@ -47,7 +47,7 @@ static PyObject *Vector_copy(VectorObject *self); static PyObject *Vector_deepcopy(VectorObject *self, PyObject *args); -static PyObject *Vector_to_tuple_ext(VectorObject *self, int ndigits); +static PyObject *Vector_to_tuple_ex(VectorObject *self, int ndigits); static int row_vector_multiplication(float rvec[MAX_DIMENSIONS], VectorObject *vec, MatrixObject *mat); @@ -630,7 +630,7 @@ PyDoc_STRVAR(Vector_to_tuple_doc, " :return: the values of the vector rounded by *precision*\n" " :rtype: tuple\n"); /* note: BaseMath_ReadCallback must be called beforehand */ -static PyObject *Vector_to_tuple_ext(VectorObject *self, int ndigits) +static PyObject *Vector_to_tuple_ex(VectorObject *self, int ndigits) { PyObject *ret; int i; @@ -674,7 +674,7 @@ static PyObject *Vector_to_tuple(VectorObject *self, PyObject *args) return NULL; } - return Vector_to_tuple_ext(self, ndigits); + return Vector_to_tuple_ex(self, ndigits); } PyDoc_STRVAR(Vector_to_track_quat_doc, @@ -1338,7 +1338,7 @@ static PyObject *Vector_repr(VectorObject *self) return NULL; } - tuple = Vector_to_tuple_ext(self, -1); + tuple = Vector_to_tuple_ex(self, -1); ret = PyUnicode_FromFormat("Vector(%R)", tuple); Py_DECREF(tuple); return ret; diff --git a/source/blender/render/intern/source/pipeline.c b/source/blender/render/intern/source/pipeline.c index ee39ba4c92f..8764671ae04 100644 --- a/source/blender/render/intern/source/pipeline.c +++ b/source/blender/render/intern/source/pipeline.c @@ -2566,7 +2566,7 @@ void RE_RenderAnim(Render *re, for (nfra = sfra, scene->r.cfra = sfra; scene->r.cfra <= efra; scene->r.cfra++) { char name[FILE_MAX]; - /* Here is a feedback loop exists -- render initialization requires updated + /* A feedback loop exists here -- render initialization requires updated * render layers settings which could be animated, but scene evaluation for * the frame happens later because it depends on what layers are visible to * render engine. @@ -2580,12 +2580,7 @@ void RE_RenderAnim(Render *re, { float ctime = BKE_scene_frame_get(scene); AnimData *adt = BKE_animdata_from_id(&scene->id); - /* TODO(sergey): Currently depsgraph is only used to check whether it is an active - * edit window or not to deal with unkeyed changes. We don't have depsgraph here yet, - * but we also dont' deal with unkeyed changes. But still nice to get proper depsgraph - * within tjhe render pipeline, somehow. - */ - BKE_animsys_evaluate_animdata(NULL, scene, &scene->id, adt, ctime, ADT_RECALC_ALL); + BKE_animsys_evaluate_animdata(scene, &scene->id, adt, ctime, ADT_RECALC_ALL, false); } render_update_depsgraph(re); diff --git a/source/blender/render/intern/source/pointdensity.c b/source/blender/render/intern/source/pointdensity.c index ab8146c6626..75ddf7e0b22 100644 --- a/source/blender/render/intern/source/pointdensity.c +++ b/source/blender/render/intern/source/pointdensity.c @@ -792,7 +792,7 @@ static void particle_system_minmax(Depsgraph *depsgraph, INIT_MINMAX(min, max); if (part->type == PART_HAIR) { - /* TOOD(sergey): Not supported currently. */ + /* TODO(sergey): Not supported currently. */ return; } @@ -895,7 +895,7 @@ typedef struct SampleCallbackData { static void point_density_sample_func(void *__restrict data_v, const int iter, - const ParallelRangeTLS *__restrict UNUSED(tls)) + const TaskParallelTLS *__restrict UNUSED(tls)) { SampleCallbackData *data = (SampleCallbackData *)data_v; @@ -966,7 +966,7 @@ void RE_point_density_sample(Depsgraph *depsgraph, data.min = min; data.dim = dim; data.values = values; - ParallelRangeSettings settings; + TaskParallelSettings settings; BLI_parallel_range_settings_defaults(&settings); settings.use_threading = (resolution > 32); BLI_task_parallel_range(0, resolution, &data, point_density_sample_func, &settings); diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 04e3f7e88dc..5d6e405dd5d 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -93,7 +93,7 @@ void WM_init_native_pixels(bool do_it); void WM_init_tablet_api(void); void WM_init(struct bContext *C, int argc, const char **argv); -void WM_exit_ext(struct bContext *C, const bool do_python); +void WM_exit_ex(struct bContext *C, const bool do_python); void WM_exit(struct bContext *C) ATTR_NORETURN; @@ -565,8 +565,8 @@ bool WM_menutype_poll(struct bContext *C, struct MenuType *mt); void WM_paneltype_init(void); void WM_paneltype_clear(void); struct PanelType *WM_paneltype_find(const char *idname, bool quiet); -bool WM_paneltype_add(struct PanelType *mt); -void WM_paneltype_remove(struct PanelType *mt); +bool WM_paneltype_add(struct PanelType *pt); +void WM_paneltype_remove(struct PanelType *pt); /* wm_gesture_ops.c */ int WM_gesture_box_invoke(struct bContext *C, struct wmOperator *op, const struct wmEvent *event); @@ -741,6 +741,10 @@ void *WM_draw_cb_activate(struct wmWindow *win, void WM_draw_cb_exit(struct wmWindow *win, void *handle); void WM_redraw_windows(struct bContext *C); +void WM_draw_region_viewport_ensure(struct ARegion *ar, short space_type); +void WM_draw_region_viewport_bind(struct ARegion *ar); +void WM_draw_region_viewport_unbind(struct ARegion *ar); + /* Region drawing */ void WM_draw_region_free(struct ARegion *ar); struct GPUViewport *WM_draw_region_get_viewport(struct ARegion *ar, int view); diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h index a0c7e8ef752..195822efd7e 100644 --- a/source/blender/windowmanager/WM_types.h +++ b/source/blender/windowmanager/WM_types.h @@ -180,8 +180,6 @@ enum { OPTYPE_LOCK_BYPASS = (1 << 9), /** Special type of undo which doesn't store itself multiple times. */ OPTYPE_UNDO_GROUPED = (1 << 10), - /** Need evaluated data (i.e. a valid, up-to-date depsgraph for current context). */ - OPTYPE_USE_EVAL_DATA = (1 << 11), }; /** For #WM_cursor_grab_enable wrap axis. */ diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c b/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c index 534474a6221..ef4d8174718 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c @@ -540,6 +540,7 @@ static int gizmo_find_intersected_3d_intern(wmGizmo **visible_gizmos, ScrArea *sa = CTX_wm_area(C); ARegion *ar = CTX_wm_region(C); View3D *v3d = sa->spacedata.first; + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); rcti rect; /* Almost certainly overkill, but allow for many custom gizmos. */ GLuint buffer[MAXPICKBUF]; @@ -548,7 +549,7 @@ static int gizmo_find_intersected_3d_intern(wmGizmo **visible_gizmos, BLI_rcti_init_pt_radius(&rect, co, hotspot); ED_view3d_draw_setup_view( - CTX_wm_window(C), CTX_data_depsgraph(C), CTX_data_scene(C), ar, v3d, NULL, NULL, &rect); + CTX_wm_window(C), depsgraph, CTX_data_scene(C), ar, v3d, NULL, NULL, &rect); bool use_select_bias = false; @@ -568,7 +569,7 @@ static int gizmo_find_intersected_3d_intern(wmGizmo **visible_gizmos, } ED_view3d_draw_setup_view( - CTX_wm_window(C), CTX_data_depsgraph(C), CTX_data_scene(C), ar, v3d, NULL, NULL, NULL); + CTX_wm_window(C), depsgraph, CTX_data_scene(C), ar, v3d, NULL, NULL, NULL); if (use_select_bias && (hits > 1)) { float co_direction[3]; @@ -973,7 +974,8 @@ bool WM_gizmomap_cursor_set(const wmGizmoMap *gzmap, wmWindow *win) bool wm_gizmomap_highlight_set(wmGizmoMap *gzmap, const bContext *C, wmGizmo *gz, int part) { if ((gz != gzmap->gzmap_context.highlight) || (gz && part != gz->highlight_part)) { - const bool init_last_cursor = (gzmap->gzmap_context.highlight == NULL); + const bool init_last_cursor = !(gzmap->gzmap_context.highlight && + gzmap->gzmap_context.last_cursor != -1); if (gzmap->gzmap_context.highlight) { gzmap->gzmap_context.highlight->state &= ~WM_GIZMO_STATE_HIGHLIGHT; gzmap->gzmap_context.highlight->highlight_part = -1; diff --git a/source/blender/windowmanager/intern/wm_draw.c b/source/blender/windowmanager/intern/wm_draw.c index fc669c9543e..3bcb955c2b2 100644 --- a/source/blender/windowmanager/intern/wm_draw.c +++ b/source/blender/windowmanager/intern/wm_draw.c @@ -239,9 +239,14 @@ static void wm_region_test_render_do_draw(const Scene *scene, } } +static bool wm_region_use_viewport_by_type(short space_type, short region_type) +{ + return (ELEM(space_type, SPACE_VIEW3D, SPACE_IMAGE) && region_type == RGN_TYPE_WINDOW); +} + static bool wm_region_use_viewport(ScrArea *sa, ARegion *ar) { - return (ELEM(sa->spacetype, SPACE_VIEW3D, SPACE_IMAGE) && ar->regiontype == RGN_TYPE_WINDOW); + return wm_region_use_viewport_by_type(sa->spacetype, ar->regiontype); } /********************** draw all **************************/ @@ -976,3 +981,31 @@ void WM_redraw_windows(bContext *C) CTX_wm_area_set(C, area_prev); CTX_wm_region_set(C, ar_prev); } + +/* -------------------------------------------------------------------- */ +/** \name Region Viewport Drawing + * + * This is needed for viewport drawing for operator use + * (where the viewport may not have drawn yet). + * + * Otherwise avoid using these sine they're exposing low level logic externally. + * + * \{ */ + +void WM_draw_region_viewport_ensure(ARegion *ar, short space_type) +{ + bool use_viewport = wm_region_use_viewport_by_type(space_type, ar->regiontype); + wm_draw_region_buffer_create(ar, false, use_viewport); +} + +void WM_draw_region_viewport_bind(ARegion *ar) +{ + wm_draw_region_bind(ar, 0); +} + +void WM_draw_region_viewport_unbind(ARegion *ar) +{ + wm_draw_region_unbind(ar, 0); +} + +/** \} */ diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 76cb78b1e04..cea2f127b3e 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -495,7 +495,7 @@ void wm_event_do_notifiers(bContext *C) * twice which can depgraph update the same object at once */ if (G.is_rendering == false) { /* depsgraph gets called, might send more notifiers */ - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); ED_update_for_newframe(CTX_data_main(C), depsgraph); } } diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index 48b09b0d329..10773cf58e1 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -353,7 +353,7 @@ static void wm_window_match_do(bContext *C, } /* in case UserDef was read, we re-initialize all, and do versioning */ -static void wm_init_userdef(Main *bmain, const bool read_userdef_from_memory) +static void wm_init_userdef(Main *bmain) { /* versioning is here */ UI_init_userdef(bmain); @@ -367,11 +367,6 @@ static void wm_init_userdef(Main *bmain, const bool read_userdef_from_memory) SET_FLAG_FROM_TEST(G.f, (U.flag & USER_SCRIPT_AUTOEXEC_DISABLE) == 0, G_FLAG_SCRIPT_AUTOEXEC); } - /* avoid re-saving for every small change to our prefs, allow overrides */ - if (read_userdef_from_memory) { - BLO_update_defaults_userpref_blend(); - } - MEM_CacheLimiter_set_maximum(((size_t)U.memcachelimit) * 1024 * 1024); BKE_sound_init(bmain); @@ -605,7 +600,6 @@ bool WM_file_read(bContext *C, const char *filepath, ReportList *reports) /* assume automated tasks with background, don't write recent file list */ const bool do_history = (G.background == false) && (CTX_wm_manager(C)->op_undo_depth == 0); bool success = false; - int retval; /* so we can get the error message */ errno = 0; @@ -619,7 +613,7 @@ bool WM_file_read(bContext *C, const char *filepath, ReportList *reports) /* first try to append data from exotic file formats... */ /* it throws error box when file doesn't exist and returns -1 */ /* note; it should set some error message somewhere... (ton) */ - retval = wm_read_exotic(filepath); + const int retval = wm_read_exotic(filepath); /* we didn't succeed, now try to read Blender file */ if (retval == BKE_READ_EXOTIC_OK_BLEND) { @@ -632,7 +626,7 @@ bool WM_file_read(bContext *C, const char *filepath, ReportList *reports) /* confusing this global... */ G.relbase_valid = 1; - retval = BKE_blendfile_read( + success = BKE_blendfile_read( C, filepath, /* Loading preferences when the user intended to load a regular file is a security risk, @@ -668,7 +662,7 @@ bool WM_file_read(bContext *C, const char *filepath, ReportList *reports) wm_window_match_do(C, &wmbase, &bmain->wm, &bmain->wm); WM_check(C); /* opens window(s), checks keymaps */ - if (retval != BKE_BLENDFILE_READ_FAIL) { + if (success) { if (do_history) { wm_history_file_update(); } @@ -677,8 +671,6 @@ bool WM_file_read(bContext *C, const char *filepath, ReportList *reports) const bool use_data = true; const bool use_userdef = false; wm_file_read_post(C, false, false, use_data, use_userdef, false); - - success = true; } #if 0 else if (retval == BKE_READ_EXOTIC_OK_OTHER) { @@ -790,16 +782,6 @@ void wm_homefile_read(bContext *C, * '{BLENDER_SYSTEM_SCRIPTS}/startup/bl_app_templates_system/{app_template}' */ char app_template_config[FILE_MAX]; - /* Indicates whether user preferences were really load from memory. - * - * This is used for versioning code, and for this we can not rely on use_factory_settings - * passed via argument. This is because there might be configuration folder - * exists but it might not have userpref.blend and in this case we fallback to - * reading home file from memory. - * - * And in this case versioning code is to be run. - */ - bool read_userdef_from_memory = false; eBLOReadSkip skip_flags = 0; if (use_data == false) { @@ -939,9 +921,9 @@ void wm_homefile_read(bContext *C, filepath_startup, &(const struct BlendFileReadParams){ .is_startup = true, - .skip_flags = skip_flags, + .skip_flags = skip_flags | BLO_READ_SKIP_USERDEF, }, - NULL) != BKE_BLENDFILE_READ_FAIL; + NULL); } if (BLI_listbase_is_empty(&U.themes)) { if (G.debug & G_DEBUG) { @@ -966,6 +948,14 @@ void wm_homefile_read(bContext *C, } if (success == false) { + if (use_userdef) { + if ((skip_flags & BLO_READ_SKIP_USERDEF) == 0) { + UserDef *userdef_default = BKE_blendfile_userdef_from_defaults(); + BKE_blender_userdef_data_set_and_free(userdef_default); + skip_flags |= BLO_READ_SKIP_USERDEF; + } + } + success = BKE_blendfile_read_from_memory(C, datatoc_startup_blend, datatoc_startup_blend_size, @@ -975,13 +965,7 @@ void wm_homefile_read(bContext *C, .skip_flags = skip_flags, }, NULL); - if (success) { - if (use_userdef) { - if ((skip_flags & BLO_READ_SKIP_USERDEF) == 0) { - read_userdef_from_memory = true; - } - } - } + if (use_data && BLI_listbase_is_empty(&wmbase)) { wm_clear_default_size(C); } @@ -1018,9 +1002,7 @@ void wm_homefile_read(bContext *C, } if (userdef_template == NULL) { /* we need to have preferences load to overwrite preferences from previous template */ - userdef_template = BKE_blendfile_userdef_read_from_memory( - datatoc_startup_blend, datatoc_startup_blend_size, NULL); - read_userdef_from_memory = true; + userdef_template = BKE_blendfile_userdef_from_defaults(); } if (userdef_template) { BKE_blender_userdef_app_template_data_set_and_free(userdef_template); @@ -1044,7 +1026,7 @@ void wm_homefile_read(bContext *C, if (use_userdef) { /* check userdef before open window, keymaps etc */ - wm_init_userdef(bmain, read_userdef_from_memory); + wm_init_userdef(bmain); reset_app_template = true; } @@ -1053,7 +1035,7 @@ void wm_homefile_read(bContext *C, wm_window_match_do(C, &wmbase, &bmain->wm, &bmain->wm); } - if (use_factory_settings) { + if (use_userdef) { /* Clear keymaps because the current default keymap may have been initialized * from user preferences, which have been reset. */ for (wmWindowManager *wm = bmain->wm.first; wm; wm = wm->id.next) { @@ -1247,7 +1229,7 @@ static ImBuf *blend_file_thumb(const bContext *C, } /* gets scaled to BLEN_THUMB_SIZE */ - Depsgraph *depsgraph = CTX_data_depsgraph(C); + Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); if (scene->camera) { ibuf = ED_view3d_draw_offscreen_imbuf_simple(depsgraph, @@ -1653,7 +1635,7 @@ static int wm_homefile_write_exec(bContext *C, wmOperator *op) /* force save as regular blend file */ fileflags = G.fileflags & ~(G_FILE_COMPRESS | G_FILE_HISTORY); - if (BLO_write_file(bmain, filepath, fileflags | G_FILE_USERPREFS, op->reports, NULL) == 0) { + if (BLO_write_file(bmain, filepath, fileflags, op->reports, NULL) == 0) { printf("fail\n"); return OPERATOR_CANCELLED; } @@ -1737,7 +1719,7 @@ void WM_OT_save_userpref(wmOperatorType *ot) { ot->name = "Save Preferences"; ot->idname = "WM_OT_save_userpref"; - ot->description = "Save preferences separately, overrides startup file preferences"; + ot->description = "Make the current preferences default"; ot->invoke = WM_operator_confirm; ot->exec = wm_userpref_write_exec; @@ -2956,7 +2938,8 @@ static void wm_block_file_close_save(bContext *C, void *arg_block, void *arg_dat wmWindow *win = CTX_wm_window(C); UI_popup_block_close(C, win, arg_block); - if (save_images_when_file_is_closed) { + int modified_images_count = ED_image_save_all_modified_info(C, NULL); + if (modified_images_count > 0 && save_images_when_file_is_closed) { if (ED_image_should_save_modified(C)) { ReportList *reports = CTX_wm_reports(C); ED_image_save_all_modified(C, reports); diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c index f3c94162786..29cb02888ac 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.c +++ b/source/blender/windowmanager/intern/wm_init_exit.c @@ -80,6 +80,8 @@ #include "RE_engine.h" #include "RE_pipeline.h" /* RE_ free stuff */ +#include "IMB_thumbs.h" + #ifdef WITH_PYTHON # include "BPY_extern.h" #endif @@ -299,6 +301,9 @@ void WM_init(bContext *C, int argc, const char **argv) /* Call again to set from userpreferences... */ BLT_lang_set(NULL); + /* That one is generated on demand, we need to be sure it's clear on init. */ + IMB_thumb_clear_translations(); + if (!G.background) { #ifdef WITH_INPUT_NDOF @@ -462,7 +467,7 @@ void wm_exit_schedule_delayed(const bContext *C) /** * \note doesn't run exit() call #WM_exit() for that. */ -void WM_exit_ext(bContext *C, const bool do_python) +void WM_exit_ex(bContext *C, const bool do_python) { wmWindowManager *wm = C ? CTX_wm_manager(C) : NULL; @@ -661,7 +666,7 @@ void WM_exit_ext(bContext *C, const bool do_python) */ void WM_exit(bContext *C) { - WM_exit_ext(C, 1); + WM_exit_ex(C, true); printf("\nBlender quit\n"); diff --git a/source/blender/windowmanager/intern/wm_keymap.c b/source/blender/windowmanager/intern/wm_keymap.c index d8ad0582bd8..4e7a7bf96f1 100644 --- a/source/blender/windowmanager/intern/wm_keymap.c +++ b/source/blender/windowmanager/intern/wm_keymap.c @@ -463,7 +463,7 @@ bool WM_keymap_poll(bContext *C, wmKeyMap *keymap) if (UNLIKELY(BLI_listbase_is_empty(&keymap->items))) { /* Empty key-maps may be missing more there may be a typo in the name. - * Warn early to avoid loosing time investigating each case. */ + * Warn early to avoid losing time investigating each case. */ CLOG_WARN(WM_LOG_KEYMAPS, "empty keymap '%s'", keymap->idname); } diff --git a/source/blender/windowmanager/intern/wm_operator_props.c b/source/blender/windowmanager/intern/wm_operator_props.c index c471cb6f922..f22b5d07686 100644 --- a/source/blender/windowmanager/intern/wm_operator_props.c +++ b/source/blender/windowmanager/intern/wm_operator_props.c @@ -340,8 +340,11 @@ void WM_operator_properties_gesture_box_ex(wmOperatorType *ot, bool deselect, bo */ void WM_operator_properties_use_cursor_init(wmOperatorType *ot) { - PropertyRNA *prop = RNA_def_boolean( - ot->srna, "use_cursor_init", true, "Cursor Init", "Use initial cursor position"); + PropertyRNA *prop = RNA_def_boolean(ot->srna, + "use_cursor_init", + true, + "Use Mouse Position", + "Allow the initial mouse position to be used"); RNA_def_property_flag(prop, PROP_SKIP_SAVE | PROP_HIDDEN); } diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 367a5a81098..ea1aa8ea4ea 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -3157,7 +3157,10 @@ static int redraw_timer_exec(bContext *C, wmOperator *op) const int cfra = scene->r.cfra; int a, iter_steps = 0; const char *infostr = ""; - struct Depsgraph *depsgraph = CTX_data_depsgraph(C); + + /* NOTE: Depsgraph is used to update scene for a new state, so no need to ensure evaluation here. + */ + struct Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); WM_cursor_wait(1); diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt index 77877ff3cca..e911a591881 100644 --- a/source/creator/CMakeLists.txt +++ b/source/creator/CMakeLists.txt @@ -1050,6 +1050,12 @@ unset(LIB) setup_liblinks(blender) +# vcpkg substitutes our libs with theirs, which will cause issues when you +# you run these builds on other systems due to missing dlls. So we opt out +# the use of vcpkg +if (WIN32) + set_target_properties(blender PROPERTIES VS_GLOBAL_VcpkgEnabled "false") +endif() # ----------------------------------------------------------------------------- # Setup launcher diff --git a/source/creator/creator.c b/source/creator/creator.c index b257564519a..d6e1d7e7f5f 100644 --- a/source/creator/creator.c +++ b/source/creator/creator.c @@ -25,9 +25,6 @@ #include <string.h> #ifdef WIN32 -# if defined(_MSC_VER) && defined(_M_X64) -# include <math.h> /* needed for _set_FMA3_enable */ -# endif # include <windows.h> # include "utfconv.h" #endif @@ -237,12 +234,6 @@ int main(int argc, _putenv_s("OMP_WAIT_POLICY", "PASSIVE"); # endif - /* FMA3 support in the 2013 CRT is broken on Vista and Windows 7 RTM - * (fixed in SP1). Just disable it. */ -# if defined(_MSC_VER) && defined(_M_X64) - _set_FMA3_enable(0); -# endif - /* Win32 Unicode Args */ /* NOTE: cannot use guardedalloc malloc here, as it's not yet initialized * (it depends on the args passed in, which is what we're getting here!) @@ -505,7 +496,7 @@ int main(int argc, #ifdef WITH_PYTHON_MODULE void main_python_exit(void) { - WM_exit_ext((bContext *)evil_C, true); + WM_exit_ex((bContext *)evil_C, true); evil_C = NULL; } #endif diff --git a/source/creator/creator_signals.c b/source/creator/creator_signals.c index 5dae5c5d808..5a5bc74d2d3 100644 --- a/source/creator/creator_signals.c +++ b/source/creator/creator_signals.c @@ -31,9 +31,6 @@ # endif # ifdef WIN32 -# if defined(_MSC_VER) && defined(_M_X64) -# include <math.h> /* needed for _set_FMA3_enable */ -# endif # include <windows.h> # include <float.h> # endif @@ -311,7 +308,7 @@ void main_signal_setup(void) void main_signal_setup_background(void) { - /* for all platforms, even windos has it! */ + /* for all platforms, even windows has it! */ BLI_assert(G.background); # if !defined(WITH_HEADLESS) |