diff options
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/intern/DerivedMesh.c | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/cdderivedmesh.c | 20 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/editderivedmesh.c | 12 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/particle_distribute.c | 23 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/subsurf_ccg.c | 3 |
5 files changed, 19 insertions, 40 deletions
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 0de0e4d7797..d590a35bb57 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -3881,7 +3881,6 @@ static void navmesh_drawColored(DerivedMesh *dm) /* if (GPU_buffer_legacy(dm) ) */ /* TODO - VBO draw code, not high priority - campbell */ { DEBUG_VBO("Using legacy code. drawNavMeshColored\n"); - //glShadeModel(GL_SMOOTH); glBegin(glmode = GL_QUADS); for (a = 0; a < dm->numTessFaceData; a++, mface++) { int new_glmode = mface->v4 ? GL_QUADS : GL_TRIANGLES; diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index 392a38773e7..267f7a65e00 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -464,7 +464,6 @@ static void cdDM_drawFacesSolid( BKE_pbvh_draw(cddm->pbvh, partial_redraw_planes, face_nors, setMaterial, false, false); - glShadeModel(GL_FLAT); return; } } @@ -472,7 +471,6 @@ static void cdDM_drawFacesSolid( GPU_vertex_setup(dm); GPU_normal_setup(dm); GPU_triangle_setup(dm); - glShadeModel(GL_SMOOTH); for (a = 0; a < dm->drawObject->totmaterial; a++) { if (!setMaterial || setMaterial(dm->drawObject->materials[a].mat_nr + 1, NULL)) { GPU_buffer_draw_elements( @@ -481,8 +479,6 @@ static void cdDM_drawFacesSolid( } } GPU_buffers_unbind(); - - glShadeModel(GL_FLAT); } static void cdDM_drawFacesTex_common( @@ -553,8 +549,7 @@ static void cdDM_drawFacesTex_common( if (mloopcol) { GPU_color_setup(dm, colType); } - - glShadeModel(GL_SMOOTH); + /* lastFlag = 0; */ /* UNUSED */ for (mat_index = 0; mat_index < dm->drawObject->totmaterial; mat_index++) { GPUBufferMaterial *bufmat = dm->drawObject->materials + mat_index; @@ -633,7 +628,6 @@ static void cdDM_drawFacesTex_common( } GPU_buffers_unbind(); - glShadeModel(GL_FLAT); } @@ -742,9 +736,6 @@ static void cdDM_drawMappedFaces( } } } - - - glShadeModel(GL_SMOOTH); tot_tri_elem = dm->drawObject->tot_triangle_point; @@ -841,7 +832,6 @@ static void cdDM_drawMappedFaces( } GPU_basic_shader_bind(GPU_SHADER_USE_COLOR); - glShadeModel(GL_FLAT); GPU_buffers_unbind(); @@ -929,8 +919,6 @@ static void cdDM_drawMappedFacesGLSL( matnr = -1; do_draw = false; - glShadeModel(GL_SMOOTH); - if (setDrawOptions != NULL) { DMVertexAttribs attribs; DEBUG_VBO("Using legacy code. cdDM_drawMappedFacesGLSL\n"); @@ -1153,8 +1141,6 @@ static void cdDM_drawMappedFacesGLSL( MEM_freeN(mat_orig_to_new); MEM_freeN(matconv); } - - glShadeModel(GL_FLAT); } static void cdDM_drawFacesGLSL(DerivedMesh *dm, DMSetMaterial setMaterial) @@ -1203,8 +1189,6 @@ static void cdDM_drawMappedFacesMat( matnr = -1; - glShadeModel(GL_SMOOTH); - memset(&attribs, 0, sizeof(attribs)); glBegin(GL_TRIANGLES); @@ -1260,8 +1244,6 @@ static void cdDM_drawMappedFacesMat( cddm_draw_attrib_vertex(&attribs, mvert, a, vtri[2], ltri[2], 2, ln3, smoothnormal); } glEnd(); - - glShadeModel(GL_FLAT); } static void cdDM_drawMappedEdges(DerivedMesh *dm, DMSetDrawOptions setDrawOptions, void *userData) diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c index 8df07c5f3f4..c1013342bd9 100644 --- a/source/blender/blenkernel/intern/editderivedmesh.c +++ b/source/blender/blenkernel/intern/editderivedmesh.c @@ -1185,6 +1185,10 @@ static void emDM_drawMappedFaces( if (draw_option_prev == DM_DRAW_OPTION_STIPPLE) { GPU_basic_shader_bind(GPU_SHADER_USE_COLOR); } + + if (shade_prev == GL_FLAT) { + glShadeModel(GL_SMOOTH); + } } static void bmdm_get_tri_uv(BMLoop *ltri[3], MLoopUV *luv[3], const int cd_loop_uv_offset) @@ -1240,8 +1244,6 @@ static void emDM_drawFacesTex_common( // dummylcol.r = dummylcol.g = dummylcol.b = dummylcol.a = 255; /* UNUSED */ /* always use smooth shading even for flat faces, else vertex colors wont interpolate */ - glShadeModel(GL_SMOOTH); - BM_mesh_elem_index_ensure(bm, BM_FACE); /* call again below is ok */ @@ -1388,8 +1390,6 @@ static void emDM_drawFacesTex_common( } } } - - glShadeModel(GL_FLAT); } static void emDM_drawFacesTex( @@ -1528,8 +1528,6 @@ static void emDM_drawMappedFacesGLSL( vertexNos = bmdm->vertexNos; polyNos = bmdm->polyNos; - /* always use smooth shading even for flat faces, else vertex colors wont interpolate */ - glShadeModel(GL_SMOOTH); BM_mesh_elem_index_ensure(bm, (BM_VERT | BM_FACE) | (lnors ? BM_LOOP : 0)); for (i = 0; i < em->tottri; i++) { @@ -1640,8 +1638,6 @@ static void emDM_drawMappedFacesMat( vertexNos = bmdm->vertexNos; polyNos = bmdm->polyNos; - /* always use smooth shading even for flat faces, else vertex colors wont interpolate */ - glShadeModel(GL_SMOOTH); BM_mesh_elem_index_ensure(bm, (BM_VERT | BM_FACE) | (lnors ? BM_LOOP : 0)); for (i = 0; i < em->tottri; i++) { diff --git a/source/blender/blenkernel/intern/particle_distribute.c b/source/blender/blenkernel/intern/particle_distribute.c index f6bddfa6f99..0d7fe04a1e4 100644 --- a/source/blender/blenkernel/intern/particle_distribute.c +++ b/source/blender/blenkernel/intern/particle_distribute.c @@ -392,22 +392,25 @@ static int distribute_binary_search(float *sum, int n, float value) { int mid, low = 0, high = n - 1; + if (high == low) + return low; + if (sum[low] >= value) return low; - if (sum[high] < value) + if (sum[high - 1] < value) return high; while (low < high) { mid = (low + high) / 2; - if ((sum[mid] < value) && (sum[mid + 1] >= value)) + if ((sum[mid] >= value) && (sum[mid - 1] < value)) return mid; - if (sum[mid] >= value) { + if (sum[mid] > value) { high = mid - 1; } - else if (sum[mid] < value) { + else { low = mid + 1; } } @@ -1024,7 +1027,7 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx, Parti /* Calculate cumulative weights. * We remove all null-weighted elements from element_sum, and create a new mapping * 'activ'_elem_index -> orig_elem_index. - * This simplifies greatly the filtering of zero-weighted items - and can be much mor efficient + * This simplifies greatly the filtering of zero-weighted items - and can be much more efficient * especially in random case (reducing a lot the size of binary-searched array)... */ float *element_sum = MEM_mallocN(sizeof(*element_sum) * totmapped, __func__); @@ -1047,13 +1050,13 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx, Parti /* Finally assign elements to particles */ if ((part->flag & PART_TRAND) || (part->simplify_flag & PART_SIMPLIFY_ENABLE)) { - float pos; - for (p = 0; p < totpart; p++) { - /* In theory element_sum[totelem - 1] should be 1.0, + /* In theory element_sum[totmapped - 1] should be 1.0, * but due to float errors this is not necessarily always true, so scale pos accordingly. */ - pos = BLI_frand() * element_sum[totmapped - 1]; - particle_element[p] = element_map[distribute_binary_search(element_sum, totmapped, pos)]; + const float pos = BLI_frand() * element_sum[totmapped - 1]; + const int eidx = distribute_binary_search(element_sum, totmapped, pos); + particle_element[p] = element_map[eidx]; + BLI_assert(pos <= element_sum[eidx] && pos > (eidx ? element_sum[eidx - 1] : 0.0f)); jitter_offset[particle_element[p]] = pos; } } diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index 88bc3fb9854..b0d19320230 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -2619,7 +2619,6 @@ static void ccgDM_drawFacesSolid(DerivedMesh *dm, float (*partial_redraw_planes) if (BKE_pbvh_has_faces(ccgdm->pbvh)) { BKE_pbvh_draw(ccgdm->pbvh, partial_redraw_planes, NULL, setMaterial, false, fast); - glShadeModel(GL_FLAT); } return; @@ -3164,7 +3163,7 @@ static void ccgDM_drawMappedFacesGLSL(DerivedMesh *dm, MEM_freeN(matconv); } - glShadeModel(GL_FLAT); + glShadeModel(GL_SMOOTH); } static void ccgDM_drawFacesGLSL(DerivedMesh *dm, DMSetMaterial setMaterial) |