Fix overdrawing and errors with textured and mapped drawing
authorAntony Riakiotakis <kalast@gmail.com>
Tue, 14 Jul 2015 21:48:38 +0000 (23:48 +0200)
committerAntony Riakiotakis <kalast@gmail.com>
Tue, 14 Jul 2015 21:49:03 +0000 (23:49 +0200)
source/blender/blenkernel/intern/cdderivedmesh.c
source/blender/blenkernel/intern/subsurf_ccg.c
source/blender/gpu/intern/gpu_draw.c

index 475233206f8593ab83f663645abca7ef779d8b5d..0df2c40f248ca380d18f01ed880f64ea9a37fd46 100644 (file)
@@ -474,7 +474,7 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm,
        MTexPoly *mtexpoly = DM_get_poly_data_layer(dm, CD_MTEXPOLY);
        MCol *mcol;
        int i, orig;
-       int colType, start_element;
+       int colType, start_element, tot_drawn;
        bool use_tface = (uvflag & DM_DRAW_USE_ACTIVE_UV) != 0;
        int totpoly;
        int next_actualFace;
@@ -536,7 +536,8 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm,
                totpoly = bufmat->totpolys;
 
                tot_element = 0;
-               start_element = bufmat->start;
+               tot_drawn = 0;
+               start_element = 0;
 
                for (i = 0; i < totpoly; i++) {
                        int actualFace = bufmat->polys[i];
@@ -584,23 +585,25 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm,
                                flush |= compareDrawOptions(userData, actualFace, next_actualFace) == 0;
                        }
 
+                       tot_element += mf[actualFace].v4 ? 6 : 3;
+
                        if (flush) {
                                if (draw_option != DM_DRAW_OPTION_SKIP)
-                                       tot_element += mf[actualFace].v4 ? 6 : 3;
+                                       tot_drawn += mf[actualFace].v4 ? 6 : 3;
 
-                               if (tot_element) {
+                               if (tot_drawn) {
                                        if (mcol && draw_option != DM_DRAW_OPTION_NO_MCOL)
                                                GPU_color_switch(1);
                                        else
                                                GPU_color_switch(0);
 
-                                       GPU_buffer_draw_elements(dm->drawObject->triangles, GL_TRIANGLES, start_element, tot_element);
+                                       GPU_buffer_draw_elements(dm->drawObject->triangles, GL_TRIANGLES, bufmat->start + start_element, tot_drawn);
+                                       tot_drawn = 0;
                                }
-
                                start_element = tot_element;
                        }
                        else {
-                               tot_element += mf[actualFace].v4 ? 6 : 3;
+                               tot_drawn += mf[actualFace].v4 ? 6 : 3;
                        }
                }
        }
@@ -757,7 +760,7 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm,
                }
        }
        else { /* use OpenGL VBOs or Vertex Arrays instead for better, faster rendering */
-               int start_element = 0, tot_element;
+               int start_element = 0, tot_element, tot_drawn;
                int totpoly;
                int tottri;
                int mat_index;
@@ -770,14 +773,14 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm,
                }
                glShadeModel(GL_SMOOTH);
                
-               tottri = dm->drawObject->tot_triangle_point / 3;
+               tottri = dm->drawObject->tot_triangle_point;
 
                if (tottri == 0) {
                        /* avoid buffer problems in following code */
                }
                else if (setDrawOptions == NULL) {
                        /* just draw the entire face array */
-                       GPU_buffer_draw_elements(dm->drawObject->triangles, GL_TRIANGLES, 0, 3 * tottri);
+                       GPU_buffer_draw_elements(dm->drawObject->triangles, GL_TRIANGLES, 0, tottri);
                }
                else {                  
                        for (mat_index = 0; mat_index < dm->drawObject->totmaterial; mat_index++) {
@@ -787,7 +790,8 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm,
                                totpoly = bufmat->totpolys;
 
                                tot_element = 0;
-                               start_element = bufmat->start;
+                               tot_drawn = 0;
+                               start_element = 0;
 
                                if (setMaterial)
                                        draw_option = setMaterial(bufmat->mat_nr + 1, NULL);
@@ -813,8 +817,8 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm,
                                                }
 
                                                /* Goal is to draw as long of a contiguous triangle
-                                        * array as possible, so draw when we hit either an
-                                        * invisible triangle or at the end of the array */
+                                                * array as possible, so draw when we hit either an
+                                                * invisible triangle or at the end of the array */
 
                                                /* flush buffer if current triangle isn't drawable or it's last triangle... */
                                                flush = (ELEM(draw_option, DM_DRAW_OPTION_SKIP, DM_DRAW_OPTION_STIPPLE)) || (i == totpoly - 1);
@@ -823,12 +827,16 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm,
                                                        flush |= compareDrawOptions(userData, actualFace, next_actualFace) == 0;
                                                }
 
+                                               tot_element += mf[actualFace].v4 ? 6 : 3;
+
                                                if (flush) {
                                                        if (!ELEM(draw_option, DM_DRAW_OPTION_SKIP, DM_DRAW_OPTION_STIPPLE))
-                                                               tot_element += mf[actualFace].v4 ? 6 : 3;
+                                                               tot_drawn += mf[actualFace].v4 ? 6 : 3;
 
-                                                       if (tot_element)
-                                                               GPU_buffer_draw_elements(dm->drawObject->triangles, GL_TRIANGLES, start_element, tot_element);
+                                                       if (tot_drawn) {
+                                                               GPU_buffer_draw_elements(dm->drawObject->triangles, GL_TRIANGLES, bufmat->start + start_element, tot_drawn);
+                                                               tot_drawn = 0;
+                                                       }
 
                                                        start_element = tot_element;
 
@@ -836,7 +844,7 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm,
                                                                glDisable(GL_POLYGON_STIPPLE);
                                                }
                                                else {
-                                                       tot_element += mf[actualFace].v4 ? 6 : 3;
+                                                       tot_drawn += mf[actualFace].v4 ? 6 : 3;
                                                }
                                        }
 
index 733cb15ea865c2f30755b5f4d613a3e4a49c3f5e..7cb6f35b8c11f6909f03385368359f7119739802 100644 (file)
@@ -2622,7 +2622,7 @@ static void ccgDM_drawFacesTex_common(DerivedMesh *dm,
        unsigned int next_actualFace;
        unsigned int gridFaces = ccgSubSurf_getGridSize(ss) - 1;
        int mat_index;
-       int tot_element, start_element;
+       int tot_element, start_element, tot_drawn;
 
        CCG_key_top_level(&key, ss);
        ccgdm_pbvh_update(ccgdm);
@@ -2657,7 +2657,8 @@ static void ccgDM_drawFacesTex_common(DerivedMesh *dm,
                totpoly = bufmat->totpolys;
 
                tot_element = 0;
-               start_element = bufmat->start;
+               tot_drawn = 0;
+               start_element = 0;
 
                for (i = 0; i < totpoly; i++) {
                        int polyindex = bufmat->polys[i];
@@ -2703,23 +2704,26 @@ static void ccgDM_drawFacesTex_common(DerivedMesh *dm,
                                flush |= compareDrawOptions(userData, actualFace, next_actualFace) == 0;
                        }
 
+                       tot_element += facequads * 6;
+
                        if (flush) {
                                if (draw_option != DM_DRAW_OPTION_SKIP)
-                                       tot_element += facequads * 6;
+                                       tot_drawn += facequads * 6;
 
-                               if (tot_element) {
+                               if (tot_drawn) {
                                        if (mcol && draw_option != DM_DRAW_OPTION_NO_MCOL)
                                                GPU_color_switch(1);
                                        else
                                                GPU_color_switch(0);
 
-                                       GPU_buffer_draw_elements(dm->drawObject->triangles, GL_TRIANGLES, start_element, tot_element);
+                                       GPU_buffer_draw_elements(dm->drawObject->triangles, GL_TRIANGLES, bufmat->start + start_element, tot_drawn);
+                                       tot_drawn = 0;
                                }
 
                                start_element = tot_element;
                        }
                        else {
-                               tot_element += facequads * 6;
+                               tot_drawn += facequads * 6;
                        }
                }
        }
index a925d44ecf8b2d13009eff02b67be4076f3fcd5b..4e2af56e1e55b23c32b7c669bbf9ad4e634506b5 100644 (file)
@@ -1634,13 +1634,13 @@ void GPU_begin_object_materials(View3D *v3d, RegionView3D *rv3d, Scene *scene, O
        GPU_disable_material();
 }
 
-int GPU_get_particle_info(GPUParticleInfo *pi)
+static int GPU_get_particle_info(GPUParticleInfo *pi)
 {
        ParticleData *p;
        DupliObject *dob = GMS.dob;
        int ind;
-       if(dob->particle_system) {
-               if(dob->persistent_id[0] < dob->particle_system->totpart)
+       if (dob->particle_system) {
+               if (dob->persistent_id[0] < dob->particle_system->totpart)
                        ind = dob->persistent_id[0];
                else {
                        ind = dob->particle_system->child[dob->persistent_id[0] - dob->particle_system->totpart].parent;