[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59645] branches/soc-2013-paint/source/ blender: Speedup for new texture selection system: Cache the texture paint image
Antony Riakiotakis
kalast at gmail.com
Fri Aug 30 00:10:26 CEST 2013
Revision: 59645
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59645
Author: psy-fi
Date: 2013-08-29 22:10:25 +0000 (Thu, 29 Aug 2013)
Log Message:
-----------
Speedup for new texture selection system: Cache the texture paint image
on the material. This makes it possible to avoid looping through all
material slots. Since there are quite a few lookups per face for this
image, better only calculate the result once.
Modified Paths:
--------------
branches/soc-2013-paint/source/blender/blenkernel/BKE_material.h
branches/soc-2013-paint/source/blender/blenkernel/intern/material.c
branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_proj.c
branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_utils.c
branches/soc-2013-paint/source/blender/editors/space_view3d/drawmesh.c
branches/soc-2013-paint/source/blender/makesdna/DNA_material_types.h
Modified: branches/soc-2013-paint/source/blender/blenkernel/BKE_material.h
===================================================================
--- branches/soc-2013-paint/source/blender/blenkernel/BKE_material.h 2013-08-29 20:53:29 UTC (rev 59644)
+++ branches/soc-2013-paint/source/blender/blenkernel/BKE_material.h 2013-08-29 22:10:25 UTC (rev 59645)
@@ -89,7 +89,9 @@
int object_remove_material_slot(struct Object *ob);
bool get_mtex_slot_valid_texpaint(struct MTex *);
-struct Image *give_current_texpaint_image(struct Material *ma);
+void refresh_texpaint_image_cache(struct Material *ma);
+struct MTex *give_current_texpaint_slot(struct Material *ma);
+void refresh_object_texpaint_images(struct Object*);
/* rna api */
void BKE_material_resize_id(struct ID *id, short totcol, bool do_id_user);
Modified: branches/soc-2013-paint/source/blender/blenkernel/intern/material.c
===================================================================
--- branches/soc-2013-paint/source/blender/blenkernel/intern/material.c 2013-08-29 20:53:29 UTC (rev 59644)
+++ branches/soc-2013-paint/source/blender/blenkernel/intern/material.c 2013-08-29 22:10:25 UTC (rev 59645)
@@ -1306,16 +1306,59 @@
mtex->tex->ima;
}
-struct Image *give_current_texpaint_image(Material *ma)
+void refresh_texpaint_image_cache(Material *ma)
{
MTex **mtex, *validmtex = NULL;
short index = 0, i = 0;
+ if (!ma)
+ return;
+
for(mtex = ma->mtex; i < MAX_MTEX; i++, mtex++) {
if (get_mtex_slot_valid_texpaint(*mtex)) {
+ if (index++ == ma->texactpaint) {
+ ma->texpaintima = (*mtex)->tex->ima;
+ return;
+ }
+
+ validmtex = *mtex;
+ }
+ }
+
+ /* possible to not have selected anything as active texture. Just set to a valid index */
+ if (index > 0) {
+ ma->texactpaint = index;
+ ma->texpaintima = validmtex->tex->ima;
+ }
+
+ return;
+}
+
+void refresh_object_texpaint_images(struct Object *ob)
+{
+ int i;
+
+ if (!ob)
+ return;
+
+ for (i = 1; i < ob->totcol + 1; i++) {
+ Material *ma = give_current_material(ob, i);
+ refresh_texpaint_image_cache(ma);
+ }
+}
+
+/* no caching - slow, but not as useful as image */
+struct MTex *give_current_texpaint_slot(Material *ma)
+{
+ MTex **mtex, *validmtex = NULL;
+
+ short index = 0, i = 0;
+
+ for(mtex = ma->mtex; i < MAX_MTEX; i++, mtex++) {
+ if (get_mtex_slot_valid_texpaint(*mtex)) {
if (index++ == ma->texactpaint)
- return (*mtex)->tex->ima;
+ return (*mtex);
validmtex = *mtex;
}
@@ -1324,10 +1367,9 @@
/* possible to not have selected anything as active texture. Just set to a valid index */
if (index > 0) {
ma->texactpaint = index;
- return validmtex->tex->ima;
}
- return NULL;
+ return validmtex;
}
/* r_col = current value, col = new value, (fac == 0) is no change */
Modified: branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_proj.c
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_proj.c 2013-08-29 20:53:29 UTC (rev 59644)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_image_proj.c 2013-08-29 22:10:25 UTC (rev 59645)
@@ -348,7 +348,7 @@
else {
MFace *mf = ps->dm_mface + face_index;
Material *ma = give_current_material(ps->ob, mf->mat_nr + 1);
- ima = give_current_texpaint_image(ma);
+ ima = ma->texpaintima;
}
return ima;
@@ -4496,6 +4496,7 @@
void *paint_proj_new_stroke(bContext *C, Object *ob, const float mouse[2], int mode)
{
ProjPaintState *ps = MEM_callocN(sizeof(ProjPaintState), "ProjectionPaintState");
+ refresh_object_texpaint_images(ob);
project_state_init(C, ob, ps, mode);
if (ps->tool == PAINT_TOOL_CLONE && mode == BRUSH_STROKE_INVERT) {
Modified: branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_utils.c
===================================================================
--- branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_utils.c 2013-08-29 20:53:29 UTC (rev 59644)
+++ branches/soc-2013-paint/source/blender/editors/sculpt_paint/paint_utils.c 2013-08-29 22:10:25 UTC (rev 59645)
@@ -364,7 +364,7 @@
else {
MFace *mf = dm_mface + face_index;
Material *ma = give_current_material(ob, mf->mat_nr + 1);
- ima = give_current_texpaint_image(ma);
+ ima = ma->texpaintima;
}
return ima;
@@ -402,6 +402,8 @@
unsigned int totface = dm->getNumTessFaces(dm);
MTFace *dm_mtface = dm->getTessFaceDataArray(dm, CD_MTFACE);
+ refresh_object_texpaint_images(ob);
+
if (dm_mtface) {
view3d_set_viewcontext(C, &vc);
Modified: branches/soc-2013-paint/source/blender/editors/space_view3d/drawmesh.c
===================================================================
--- branches/soc-2013-paint/source/blender/editors/space_view3d/drawmesh.c 2013-08-29 20:53:29 UTC (rev 59644)
+++ branches/soc-2013-paint/source/blender/editors/space_view3d/drawmesh.c 2013-08-29 22:10:25 UTC (rev 59645)
@@ -268,8 +268,8 @@
if (!ma && BKE_image_has_alpha(texface->tpage))
alphablend = GPU_BLEND_ALPHA;
}
- else if (texpaint) {
- ima = ma ? give_current_texpaint_image(ma) : NULL;
+ else if (texpaint && ma) {
+ ima = ma->texpaintima;
}
else
textured = 0;
@@ -364,6 +364,9 @@
solidtex = false;
Gtexdraw.is_lit = GPU_scene_object_lights(scene, ob, v3d->lay, rv3d->viewmat, !rv3d->is_persp);
}
+
+ if (ob->mode & OB_MODE_TEXTURE_PAINT)
+ refresh_object_texpaint_images(ob);
rgba_float_to_uchar(obcol, ob->col);
Modified: branches/soc-2013-paint/source/blender/makesdna/DNA_material_types.h
===================================================================
--- branches/soc-2013-paint/source/blender/makesdna/DNA_material_types.h 2013-08-29 20:53:29 UTC (rev 59644)
+++ branches/soc-2013-paint/source/blender/makesdna/DNA_material_types.h 2013-08-29 22:10:25 UTC (rev 59645)
@@ -137,6 +137,8 @@
/* texture painting */
char texactpaint;
+ struct Image *texpaintima; /* cached image for painting. Make sure to recalculate before use
+ * with refresh_texpaint_image_cache */
/* shaders */
short diff_shader, spec_shader;
More information about the Bf-blender-cvs
mailing list