diff options
Diffstat (limited to 'source/blender/blenkernel/intern/subsurf_ccg.c')
-rw-r--r-- | source/blender/blenkernel/intern/subsurf_ccg.c | 79 |
1 files changed, 63 insertions, 16 deletions
diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index e38d62cd9bc..867065b060d 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -2622,24 +2622,72 @@ static void ccgDM_drawFacesSolid(DerivedMesh *dm, float (*partial_redraw_planes) #ifdef WITH_OPENSUBDIV if (ccgdm->useGpuBackend) { CCGSubSurf *ss = ccgdm->ss; - DMFlagMat *faceFlags = ccgdm->faceFlags; - int new_matnr; - bool draw_smooth; + const DMFlagMat *faceFlags = ccgdm->faceFlags; + const int level = ccgSubSurf_getSubdivisionLevels(ss); + const int face_side = 1 << level; + const int grid_side = 1 << (level - 1); + const int face_patches = face_side * face_side; + const int grid_patches = grid_side * grid_side; + const int num_base_faces = ccgSubSurf_getNumGLMeshBaseFaces(ss); + int i, current_patch = 0; + int mat_nr = -1; + bool draw_smooth = false; + int start_draw_patch = -1, num_draw_patches = 0; if (UNLIKELY(ccgSubSurf_prepareGLMesh(ss, setMaterial != NULL) == false)) { return; } - /* TODO(sergey): Single matierial currently. */ - if (faceFlags) { - draw_smooth = (faceFlags[0].flag & ME_SMOOTH); - new_matnr = (faceFlags[0].mat_nr + 1); - } - else { - draw_smooth = true; - new_matnr = 1; + if (setMaterial == NULL) { + ccgSubSurf_drawGLMesh(ss, + true, + -1, + -1); + return; } - if (setMaterial && setMaterial(new_matnr, NULL)) { - glShadeModel(draw_smooth ? GL_SMOOTH : GL_FLAT); - ccgSubSurf_drawGLMesh(ss, true, -1, -1); + for (i = 0; i < num_base_faces; ++i) { + const int num_face_verts = ccgSubSurf_getNumGLMeshBaseFaceVerts(ss, i); + const int num_patches = (num_face_verts == 4) ? face_patches + : num_face_verts * grid_patches; + int new_matnr; + bool new_draw_smooth; + if (faceFlags) { + new_draw_smooth = (faceFlags[i].flag & ME_SMOOTH); + new_matnr = (faceFlags[i].mat_nr + 1); + } + else { + new_draw_smooth = true; + new_matnr = 1; + } + if (new_draw_smooth != draw_smooth || new_matnr != mat_nr) { + if (num_draw_patches != 0) { + bool do_draw = setMaterial == NULL || + setMaterial(mat_nr, NULL); + if (do_draw) { + glShadeModel(draw_smooth ? GL_SMOOTH : GL_FLAT); + ccgSubSurf_drawGLMesh(ss, + true, + start_draw_patch, + num_draw_patches); + } + } + start_draw_patch = current_patch; + num_draw_patches = num_patches; + mat_nr = new_matnr; + draw_smooth = new_draw_smooth; + } + else { + num_draw_patches += num_patches; + } + current_patch += num_patches; + } + if (num_draw_patches != 0) { + bool do_draw = setMaterial(mat_nr, NULL); + if (do_draw) { + glShadeModel(draw_smooth ? GL_SMOOTH : GL_FLAT); + ccgSubSurf_drawGLMesh(ss, + true, + start_draw_patch, + num_draw_patches); + } } return; } @@ -4528,8 +4576,7 @@ static void set_ccgdm_gpu_geometry(CCGDerivedMesh *ccgdm, DerivedMesh *dm) for (index = 0; index < totface; index++) { faceFlags->flag = mpoly ? mpoly[index].flag : 0; - /* faceFlags->mat_nr = mpoly ? mpoly[index].mat_nr : 0; */ - faceFlags->mat_nr = 0; + faceFlags->mat_nr = mpoly ? mpoly[index].mat_nr : 0; faceFlags++; } |