Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Bishop <nicholasbishop@gmail.com>2015-02-10 20:29:28 +0300
committerNicholas Bishop <nicholasbishop@gmail.com>2015-02-10 20:29:28 +0300
commit27b23c326e7dce6750cd45f79966ce5a200da3a5 (patch)
treefdf6851b7e9f237881d0a8e5b58095155fc7be98
parentac09b3b36a77090c69e9c9d626103686a110648a (diff)
Avoid creating new images on Ptex resolution change
-rw-r--r--source/blender/blenkernel/intern/bke_ptex.c79
-rw-r--r--source/blender/editors/mesh/mesh_data.c11
2 files changed, 49 insertions, 41 deletions
diff --git a/source/blender/blenkernel/intern/bke_ptex.c b/source/blender/blenkernel/intern/bke_ptex.c
index 88b84897604..a6647c46412 100644
--- a/source/blender/blenkernel/intern/bke_ptex.c
+++ b/source/blender/blenkernel/intern/bke_ptex.c
@@ -580,10 +580,13 @@ static BPXImageBuf *bpx_image_buf_wrap_loop_ptex(MLoopPtex *loop_ptex)
}
/* TODO(nicholasbishop): sync up with code in imb_ptex.c */
-static bool ptex_pack_loops(Image **image, Mesh *me, MLoopPtex *loop_ptex,
+/* TODO(nicholasbishop): should function apart, Image stuff really is
+ * separate from the packing stuff */
+static bool ptex_pack_loops(Image **image_r, Mesh *me, MLoopPtex *loop_ptex,
const char *layer_name)
{
BPXImageBuf *bpx_dst;
+ Image *image;
const int num_loops = me->totloop;
struct BPXPackedLayout *layout = NULL;
struct ImBuf *ibuf;
@@ -591,7 +594,7 @@ static bool ptex_pack_loops(Image **image, Mesh *me, MLoopPtex *loop_ptex,
BPXTypeDesc type_desc;
int i;
- if (!image) {
+ if (!image_r) {
return false;
}
@@ -654,52 +657,56 @@ static bool ptex_pack_loops(Image **image, Mesh *me, MLoopPtex *loop_ptex,
// TODO
IMB_float_from_rect(ibuf);
- (*image) = BKE_image_add_from_imbuf(ibuf);
-
- /* Image now owns the ImBuf */
- IMB_freeImBuf(ibuf);
-
- if (*image) {
- ID *id = &(*image)->id;
- rename_id(id, layer_name);
- id_us_min(id);
- return true;
+ image = *image_r;
+ if (image) {
+ BKE_image_free_buffers(image);
+ BKE_image_assign_ibuf(image, ibuf);
}
else {
- return false;
+ image = BKE_image_add_from_imbuf(ibuf);
+
+ rename_id(&image->id, layer_name);
+ id_us_min(&image->id);
+
+ (*image_r) = image;
}
+
+ /* Image now owns the ImBuf */
+ IMB_freeImBuf(ibuf);
+
+ return image != NULL;
}
Image *BKE_ptex_mesh_image_get(struct Object *ob,
const char layer_name[MAX_CUSTOMDATA_LAYER_NAME])
{
Mesh *me = BKE_mesh_from_object(ob);
- if (me) {
- MLoopPtex *loop_ptex = CustomData_get_layer_named(&me->ldata,
- CD_LOOP_PTEX,
- layer_name);
- if (loop_ptex) {
- // TODO
- if (!loop_ptex->image) {
- // TODO
- const bool r = ptex_pack_loops(&loop_ptex->image, me,
- loop_ptex, layer_name);
- BLI_assert(r);
- }
- else if (loop_ptex->image->tpageflag & IMA_TPAGE_REFRESH) {
- //mesh_ptex_pack_textures_free(loop_ptex->pack);
- loop_ptex->image->tpageflag &= ~IMA_TPAGE_REFRESH;
- }
- // TODO
+ MLoopPtex *loop_ptex;
+ if (!me) {
+ return NULL;
+ }
- /* if (!loop_ptex->pack->mapping_texture) { */
- /* mesh_ptex_pack_update_textures(loop_ptex->pack); */
- /* } */
+ loop_ptex = CustomData_get_layer_named(&me->ldata, CD_LOOP_PTEX,
+ layer_name);
+ if (!loop_ptex) {
+ return NULL;
+ }
- return loop_ptex->image;
- }
+ if (!loop_ptex->image ||
+ !BKE_image_has_ibuf(loop_ptex->image, NULL))
+ {
+ // TODO
+ const bool r = ptex_pack_loops(&loop_ptex->image, me,
+ loop_ptex, layer_name);
+ BLI_assert(r);
}
- return NULL;
+ // TODO
+ else if (loop_ptex->image->tpageflag & IMA_TPAGE_REFRESH) {
+ //mesh_ptex_pack_textures_free(loop_ptex->pack);
+ loop_ptex->image->tpageflag &= ~IMA_TPAGE_REFRESH;
+ }
+
+ return loop_ptex->image;
}
MPtexDataType BKE_ptex_texel_data_type(const MPtexTexelInfo texel_info)
diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c
index 90dcff731c8..424b30c7bb2 100644
--- a/source/blender/editors/mesh/mesh_data.c
+++ b/source/blender/editors/mesh/mesh_data.c
@@ -876,10 +876,12 @@ static int mesh_ptex_res_change_exec(bContext *C, wmOperator *op)
{
Object *ob = ED_object_context(C);
Mesh *me = ob->data;
- int i;
-
- MLoopPtex *loop_ptex = CustomData_get_layer(&me->ldata, CD_LOOP_PTEX);
+ const int layer_offset = CustomData_get_active_layer(&me->ldata,
+ CD_LOOP_PTEX);
+ MLoopPtex *loop_ptex = CustomData_get_layer_n(&me->ldata, CD_LOOP_PTEX,
+ layer_offset);
const PtexResChangeMode mode = RNA_enum_get(op->ptr, "mode");
+ int i;
for (i = 0; i < me->totpoly; i++) {
const MPoly *poly = &me->mpoly[i];
@@ -901,8 +903,7 @@ static int mesh_ptex_res_change_exec(bContext *C, wmOperator *op)
}
}
- /* TODO, not sure how this will look yet */
- loop_ptex[0].image = NULL;
+ BKE_ptex_image_mark_for_update(me, layer_offset);
DAG_id_tag_update(&me->id, 0);
WM_main_add_notifier(NC_GEOM | ND_DATA, me);