diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2015-11-22 07:15:56 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2015-11-23 00:49:43 +0300 |
commit | d28431a6481a7698105ad45fc68a410e3cd71939 (patch) | |
tree | c3d25742b6bbd85c56fc23091ee3d726524384fe /source/blender/bmesh | |
parent | 47ce2d7bef32a7f5de34ac3e0cfb8300a4e63cd9 (diff) |
OpenNL: make the API thread safe by always passing context.
Previously two laplacian smooth or deform modifiers executing
simultaneously could crash.
Diffstat (limited to 'source/blender/bmesh')
-rw-r--r-- | source/blender/bmesh/operators/bmo_smooth_laplacian.c | 83 |
1 files changed, 41 insertions, 42 deletions
diff --git a/source/blender/bmesh/operators/bmo_smooth_laplacian.c b/source/blender/bmesh/operators/bmo_smooth_laplacian.c index 661b1c21892..624fbd93818 100644 --- a/source/blender/bmesh/operators/bmo_smooth_laplacian.c +++ b/source/blender/bmesh/operators/bmo_smooth_laplacian.c @@ -333,9 +333,9 @@ static void fill_laplacian_matrix(LaplacianSystem *sys) w4 = w4 / 4.0f; if (!vert_is_boundary(vf[j]) && sys->zerola[idv1] == 0) { - nlMatrixAdd(idv1, idv2, w2 * sys->vweights[idv1]); - nlMatrixAdd(idv1, idv3, w3 * sys->vweights[idv1]); - nlMatrixAdd(idv1, idv4, w4 * sys->vweights[idv1]); + nlMatrixAdd(sys->context, idv1, idv2, w2 * sys->vweights[idv1]); + nlMatrixAdd(sys->context, idv1, idv3, w3 * sys->vweights[idv1]); + nlMatrixAdd(sys->context, idv1, idv4, w4 * sys->vweights[idv1]); } } } @@ -346,16 +346,16 @@ static void fill_laplacian_matrix(LaplacianSystem *sys) /* Is ring if number of faces == number of edges around vertice*/ i = BM_elem_index_get(f); if (!vert_is_boundary(vf[0]) && sys->zerola[idv1] == 0) { - nlMatrixAdd(idv1, idv2, sys->fweights[i][2] * sys->vweights[idv1]); - nlMatrixAdd(idv1, idv3, sys->fweights[i][1] * sys->vweights[idv1]); + nlMatrixAdd(sys->context, idv1, idv2, sys->fweights[i][2] * sys->vweights[idv1]); + nlMatrixAdd(sys->context, idv1, idv3, sys->fweights[i][1] * sys->vweights[idv1]); } if (!vert_is_boundary(vf[1]) && sys->zerola[idv2] == 0) { - nlMatrixAdd(idv2, idv1, sys->fweights[i][2] * sys->vweights[idv2]); - nlMatrixAdd(idv2, idv3, sys->fweights[i][0] * sys->vweights[idv2]); + nlMatrixAdd(sys->context, idv2, idv1, sys->fweights[i][2] * sys->vweights[idv2]); + nlMatrixAdd(sys->context, idv2, idv3, sys->fweights[i][0] * sys->vweights[idv2]); } if (!vert_is_boundary(vf[2]) && sys->zerola[idv3] == 0) { - nlMatrixAdd(idv3, idv1, sys->fweights[i][1] * sys->vweights[idv3]); - nlMatrixAdd(idv3, idv2, sys->fweights[i][0] * sys->vweights[idv3]); + nlMatrixAdd(sys->context, idv3, idv1, sys->fweights[i][1] * sys->vweights[idv3]); + nlMatrixAdd(sys->context, idv3, idv2, sys->fweights[i][0] * sys->vweights[idv3]); } } } @@ -368,8 +368,8 @@ static void fill_laplacian_matrix(LaplacianSystem *sys) idv2 = BM_elem_index_get(e->v2); if (sys->zerola[idv1] == 0 && sys->zerola[idv2] == 0) { i = BM_elem_index_get(e); - nlMatrixAdd(idv1, idv2, sys->eweights[i] * sys->vlengths[idv1]); - nlMatrixAdd(idv2, idv1, sys->eweights[i] * sys->vlengths[idv2]); + nlMatrixAdd(sys->context, idv1, idv2, sys->eweights[i] * sys->vlengths[idv1]); + nlMatrixAdd(sys->context, idv2, idv1, sys->eweights[i] * sys->vlengths[idv2]); } } } @@ -434,12 +434,12 @@ static void validate_solution(LaplacianSystem *sys, int usex, int usey, int usez idv2 = BM_elem_index_get(e->v2); vi1 = e->v1->co; vi2 = e->v2->co; - ve1[0] = nlGetVariable(0, idv1); - ve1[1] = nlGetVariable(1, idv1); - ve1[2] = nlGetVariable(2, idv1); - ve2[0] = nlGetVariable(0, idv2); - ve2[1] = nlGetVariable(1, idv2); - ve2[2] = nlGetVariable(2, idv2); + ve1[0] = nlGetVariable(sys->context, 0, idv1); + ve1[1] = nlGetVariable(sys->context, 1, idv1); + ve1[2] = nlGetVariable(sys->context, 2, idv1); + ve2[0] = nlGetVariable(sys->context, 0, idv2); + ve2[1] = nlGetVariable(sys->context, 1, idv2); + ve2[2] = nlGetVariable(sys->context, 2, idv2); leni = len_v3v3(vi1, vi2); lene = len_v3v3(ve1, ve2); if (lene > leni * SMOOTH_LAPLACIAN_MAX_EDGE_PERCENTAGE || lene < leni * SMOOTH_LAPLACIAN_MIN_EDGE_PERCENTAGE) { @@ -455,13 +455,13 @@ static void validate_solution(LaplacianSystem *sys, int usex, int usey, int usez m_vertex_id = BM_elem_index_get(v); if (sys->zerola[m_vertex_id] == 0) { if (usex) { - v->co[0] = nlGetVariable(0, m_vertex_id); + v->co[0] = nlGetVariable(sys->context, 0, m_vertex_id); } if (usey) { - v->co[1] = nlGetVariable(1, m_vertex_id); + v->co[1] = nlGetVariable(sys->context, 1, m_vertex_id); } if (usez) { - v->co[2] = nlGetVariable(2, m_vertex_id); + v->co[2] = nlGetVariable(sys->context, 2, m_vertex_id); } } } @@ -501,33 +501,32 @@ void bmo_smooth_laplacian_vert_exec(BMesh *bm, BMOperator *op) preserve_volume = BMO_slot_bool_get(op->slots_in, "preserve_volume"); - nlNewContext(); - sys->context = nlGetCurrent(); + sys->context = nlNewContext(); - nlSolverParameteri(NL_NB_VARIABLES, bm->totvert); - nlSolverParameteri(NL_LEAST_SQUARES, NL_TRUE); - nlSolverParameteri(NL_NB_ROWS, bm->totvert); - nlSolverParameteri(NL_NB_RIGHT_HAND_SIDES, 3); + nlSolverParameteri(sys->context, NL_NB_VARIABLES, bm->totvert); + nlSolverParameteri(sys->context, NL_LEAST_SQUARES, NL_TRUE); + nlSolverParameteri(sys->context, NL_NB_ROWS, bm->totvert); + nlSolverParameteri(sys->context, NL_NB_RIGHT_HAND_SIDES, 3); - nlBegin(NL_SYSTEM); + nlBegin(sys->context, NL_SYSTEM); for (i = 0; i < bm->totvert; i++) { - nlLockVariable(i); + nlLockVariable(sys->context, i); } BMO_ITER (v, &siter, op->slots_in, "verts", BM_VERT) { m_vertex_id = BM_elem_index_get(v); - nlUnlockVariable(m_vertex_id); - nlSetVariable(0, m_vertex_id, v->co[0]); - nlSetVariable(1, m_vertex_id, v->co[1]); - nlSetVariable(2, m_vertex_id, v->co[2]); + nlUnlockVariable(sys->context, m_vertex_id); + nlSetVariable(sys->context, 0, m_vertex_id, v->co[0]); + nlSetVariable(sys->context, 1, m_vertex_id, v->co[1]); + nlSetVariable(sys->context, 2, m_vertex_id, v->co[2]); } - nlBegin(NL_MATRIX); + nlBegin(sys->context, NL_MATRIX); init_laplacian_matrix(sys); BMO_ITER (v, &siter, op->slots_in, "verts", BM_VERT) { m_vertex_id = BM_elem_index_get(v); - nlRightHandSideAdd(0, m_vertex_id, v->co[0]); - nlRightHandSideAdd(1, m_vertex_id, v->co[1]); - nlRightHandSideAdd(2, m_vertex_id, v->co[2]); + nlRightHandSideAdd(sys->context, 0, m_vertex_id, v->co[0]); + nlRightHandSideAdd(sys->context, 1, m_vertex_id, v->co[1]); + nlRightHandSideAdd(sys->context, 2, m_vertex_id, v->co[2]); i = m_vertex_id; if (sys->zerola[i] == 0) { w = sys->vweights[i] * sys->ring_areas[i]; @@ -536,22 +535,22 @@ void bmo_smooth_laplacian_vert_exec(BMesh *bm, BMOperator *op) sys->vlengths[i] = (w == 0.0f) ? 0.0f : -lambda_border * 2.0f / w; if (!vert_is_boundary(v)) { - nlMatrixAdd(i, i, 1.0f + lambda_factor / (4.0f * sys->ring_areas[i])); + nlMatrixAdd(sys->context, i, i, 1.0f + lambda_factor / (4.0f * sys->ring_areas[i])); } else { - nlMatrixAdd(i, i, 1.0f + lambda_border * 2.0f); + nlMatrixAdd(sys->context, i, i, 1.0f + lambda_border * 2.0f); } } else { - nlMatrixAdd(i, i, 1.0f); + nlMatrixAdd(sys->context, i, i, 1.0f); } } fill_laplacian_matrix(sys); - nlEnd(NL_MATRIX); - nlEnd(NL_SYSTEM); + nlEnd(sys->context, NL_MATRIX); + nlEnd(sys->context, NL_SYSTEM); - if (nlSolve(NL_TRUE) ) { + if (nlSolve(sys->context, NL_TRUE) ) { validate_solution(sys, usex, usey, usez, preserve_volume); } |