fix relating to r56260, when in vertex paint mode the mesh would have tessfaces alloc...
authorCampbell Barton <ideasman42@gmail.com>
Wed, 24 Apr 2013 13:53:09 +0000 (13:53 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 24 Apr 2013 13:53:09 +0000 (13:53 +0000)
baking now clears tessfaces.

source/blender/editors/object/object_bake.c
source/blender/render/intern/source/bake.c

index 00af771e45d4255aba83b8fcccdb7fda4d459342..426f543c045af54971a89e21b41805c1deb9471e 100644 (file)
@@ -61,6 +61,8 @@
 #include "BKE_modifier.h"
 #include "BKE_DerivedMesh.h"
 #include "BKE_subsurf.h"
+#include "BKE_depsgraph.h"
+#include "BKE_mesh.h"
 
 #include "RE_pipeline.h"
 #include "RE_shader_ext.h"
@@ -607,40 +609,58 @@ static void finish_bake_internal(BakeRender *bkr)
                        bkr->scene->r.mode &= ~R_RAYTRACE;
 
        /* force OpenGL reload and mipmap recalc */
-       for (ima = G.main->image.first; ima; ima = ima->id.next) {
-               ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL);
+       if ((bkr->scene->r.bake_flag & R_BAKE_VCOL) == 0) {
+               for (ima = G.main->image.first; ima; ima = ima->id.next) {
+                       ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL);
 
-               /* some of the images could have been changed during bake,
-                * so recreate mipmaps regardless bake result status
-                */
-               if (ima->ok == IMA_OK_LOADED) {
-                       if (ibuf) {
-                               if (ibuf->userflags & IB_BITMAPDIRTY) {
-                                       GPU_free_image(ima);
-                                       imb_freemipmapImBuf(ibuf);
+                       /* some of the images could have been changed during bake,
+                        * so recreate mipmaps regardless bake result status
+                        */
+                       if (ima->ok == IMA_OK_LOADED) {
+                               if (ibuf) {
+                                       if (ibuf->userflags & IB_BITMAPDIRTY) {
+                                               GPU_free_image(ima);
+                                               imb_freemipmapImBuf(ibuf);
+                                       }
+
+                                       /* invalidate display buffers for changed images */
+                                       if (ibuf->userflags & IB_BITMAPDIRTY)
+                                               ibuf->userflags |= IB_DISPLAY_BUFFER_INVALID;
                                }
+                       }
 
-                               /* invalidate display buffers for changed images */
-                               if (ibuf->userflags & IB_BITMAPDIRTY)
-                                       ibuf->userflags |= IB_DISPLAY_BUFFER_INVALID;
+                       /* freed when baking is done, but if its canceled we need to free here */
+                       if (ibuf) {
+                               if (ibuf->userdata) {
+                                       BakeImBufuserData *userdata = (BakeImBufuserData *) ibuf->userdata;
+                                       if (userdata->mask_buffer)
+                                               MEM_freeN(userdata->mask_buffer);
+                                       if (userdata->displacement_buffer)
+                                               MEM_freeN(userdata->displacement_buffer);
+                                       MEM_freeN(userdata);
+                                       ibuf->userdata = NULL;
+                               }
                        }
+
+                       BKE_image_release_ibuf(ima, ibuf, NULL);
                }
+       }
 
-               /* freed when baking is done, but if its canceled we need to free here */
-               if (ibuf) {
-                       if (ibuf->userdata) {
-                               BakeImBufuserData *userdata = (BakeImBufuserData *) ibuf->userdata;
-                               if (userdata->mask_buffer)
-                                       MEM_freeN(userdata->mask_buffer);
-                               if (userdata->displacement_buffer)
-                                       MEM_freeN(userdata->displacement_buffer);
-                               MEM_freeN(userdata);
-                               ibuf->userdata = NULL;
+       if (bkr->scene->r.bake_flag & R_BAKE_VCOL) {
+               /* update all tagged meshes */
+               Object *ob;
+               BLI_assert(BLI_thread_is_main());
+               for (ob = G.main->object.first; ob; ob = ob->id.next) {
+                       if (ob->type == OB_MESH) {
+                               Mesh *me = ob->data;
+                               if (me->id.flag & LIB_DOIT) {
+                                       DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA);
+                                       BKE_mesh_tessface_clear(me);
+                               }
                        }
                }
-
-               BKE_image_release_ibuf(ima, ibuf, NULL);
        }
+
 }
 
 static void *do_bake_render(void *bake_v)
index d99bac1f7b44661cc82dec827254a96dc648ef4f..c17db52673177a9d738930d7010dc6fb0cf95bc4 100644 (file)
@@ -47,7 +47,6 @@
 #include "DNA_meshdata_types.h"
 
 #include "BKE_customdata.h"
-#include "BKE_depsgraph.h"
 #include "BKE_global.h"
 #include "BKE_image.h"
 #include "BKE_main.h"
@@ -1105,19 +1104,6 @@ int RE_bake_shade_all_selected(Render *re, int type, Object *actob, short *do_up
                }
        }
 
-       if (R.r.bake_flag & R_BAKE_VCOL) {
-               /* update all tagged meshes */
-               Object *ob;
-               for (ob = G.main->object.first; ob; ob = ob->id.next) {
-                       if (ob->type == OB_MESH) {
-                               Mesh *me = ob->data;
-                               if (me->id.flag & LIB_DOIT) {
-                                       DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA);
-                               }
-                       }
-               }
-       }
-
        MEM_freeN(handles);
        
        BLI_end_threads(&threads);