[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30369] branches/soc-2010-jwilkins/source/ blender/editors: * re-factored the new overlay drawing code

Jason Wilkins Jason.A.Wilkins at gmail.com
Thu Jul 15 13:40:31 CEST 2010


Revision: 30369
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30369
Author:   jwilkins
Date:     2010-07-15 13:40:31 +0200 (Thu, 15 Jul 2010)

Log Message:
-----------
* re-factored the new overlay drawing code

Modified Paths:
--------------
    branches/soc-2010-jwilkins/source/blender/editors/include/ED_sculpt.h
    branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/paint_stroke.c
    branches/soc-2010-jwilkins/source/blender/editors/space_view3d/view3d_draw.c

Modified: branches/soc-2010-jwilkins/source/blender/editors/include/ED_sculpt.h
===================================================================
--- branches/soc-2010-jwilkins/source/blender/editors/include/ED_sculpt.h	2010-07-15 10:51:05 UTC (rev 30368)
+++ branches/soc-2010-jwilkins/source/blender/editors/include/ED_sculpt.h	2010-07-15 11:40:31 UTC (rev 30369)
@@ -52,6 +52,6 @@
 void ED_undo_paint_step(struct bContext *C, int type, int step);
 void ED_undo_paint_free(void);
 
-int ED_paint_load_overlay_tex(struct Sculpt *sd, struct Brush* br, struct ViewContext* vc);
+void ED_paint_draw_overlay(const struct bContext *C, struct ARegion *ar);
 
 #endif

Modified: branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/paint_stroke.c
===================================================================
--- branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/paint_stroke.c	2010-07-15 10:51:05 UTC (rev 30368)
+++ branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/paint_stroke.c	2010-07-15 11:40:31 UTC (rev 30369)
@@ -214,7 +214,7 @@
 	int curve_changed_timestamp;
 } Snapshot;
 
-static int same_snap(Snapshot* snap, Brush* brush, ViewContext* vc)
+static int same_snap(Snapshot* snap, Brush* brush, ARegion *ar)
 {
 	MTex* mtex = &brush->mtex;
 
@@ -229,11 +229,11 @@
 		    mtex->rot == snap->rot) &&
 		((mtex->brush_map_mode == MTEX_MAP_MODE_FIXED && sculpt_get_brush_size(brush) <= snap->brush_size) || (sculpt_get_brush_size(brush) == snap->brush_size)) && // make brush smaller shouldn't cause a resample
 		mtex->brush_map_mode == snap->brush_map_mode &&
-		vc->ar->winx == snap->winx &&
-		vc->ar->winy == snap->winy;
+		ar->winx == snap->winx &&
+		ar->winy == snap->winy;
 }
 
-static void make_snap(Snapshot* snap, Brush* brush, ViewContext* vc)
+static void make_snap(Snapshot* snap, Brush* brush, ARegion *ar)
 {
 	if (brush->mtex.tex) {
 		snap->brush_map_mode = brush->mtex.brush_map_mode;
@@ -249,11 +249,11 @@
 	}
 
 	snap->brush_size = sculpt_get_brush_size(brush);
-	snap->winx = vc->ar->winx;
-	snap->winy = vc->ar->winy;
+	snap->winx = ar->winx;
+	snap->winy = ar->winy;
 }
 
-int ED_paint_load_overlay_tex(Sculpt *sd, Brush* br, ViewContext* vc)
+static int paint_load_overlay_tex(Sculpt *sd, Brush* br, ARegion *ar)
 {
 	static GLuint overlay_texture = 0;
 	static int init = 0;
@@ -277,7 +277,7 @@
 		      br->mtex.tex->preview->changed_timestamp[0] != tex_changed_timestamp)) ||
 		!br->curve ||
 		br->curve->changed_timestamp != curve_changed_timestamp ||
-		!same_snap(&snap, br, vc);
+		!same_snap(&snap, br, ar);
 
 	if (refresh) {
 		if (br->mtex.tex && br->mtex.tex->preview)
@@ -286,7 +286,7 @@
 		if (br->curve)
 			curve_changed_timestamp = br->curve->changed_timestamp;
 
-		make_snap(&snap, br, vc);
+		make_snap(&snap, br, ar);
 
 		if (br->mtex.brush_map_mode == MTEX_MAP_MODE_FIXED) {
 			int s = sculpt_get_brush_size(br);
@@ -317,7 +317,7 @@
 			old_size = size;
 		}
 
-		buffer = MEM_mallocN(sizeof(GLubyte)*size*size, "ED_paint_load_overlay_tex");
+		buffer = MEM_mallocN(sizeof(GLubyte)*size*size, "paint_load_overlay_tex");
 
 		#pragma omp parallel for schedule(static) if (sd->flags & SCULPT_USE_OPENMP)
 		for (j= 0; j < size; j++) {
@@ -342,8 +342,8 @@
 				y -= 0.5f;
 
 				if (br->mtex.brush_map_mode == MTEX_MAP_MODE_TILED) {
-					x *= vc->ar->winx / diameter;
-					y *= vc->ar->winy / diameter;
+					x *= ar->winx / diameter;
+					y *= ar->winy / diameter;
 				}
 				else {
 					x *= 2;
@@ -420,6 +420,65 @@
 	return 1;
 }
 
+void ED_paint_draw_overlay(const bContext* C, ARegion *ar)
+{
+	Paint  *paint = paint_get_active(CTX_data_scene(C));
+	Brush  *brush = paint_brush(paint);
+	Sculpt *sd    = CTX_data_tool_settings(C)->sculpt;
+
+	if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_TILED && (brush->flag & BRUSH_TEXTURE_OVERLAY)) {
+		glPushAttrib(
+			GL_COLOR_BUFFER_BIT|
+			GL_CURRENT_BIT|
+			GL_DEPTH_BUFFER_BIT|
+			GL_ENABLE_BIT|
+			GL_LINE_BIT|
+			GL_POLYGON_BIT|
+			GL_STENCIL_BUFFER_BIT|
+			GL_TRANSFORM_BIT|
+			GL_VIEWPORT_BIT|
+			GL_TEXTURE_BIT);
+
+		if (paint_load_overlay_tex(sd, brush, ar)) {
+			glEnable(GL_BLEND);
+
+			glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+			glDepthMask(GL_FALSE);
+			glDepthFunc(GL_ALWAYS);
+
+			glMatrixMode(GL_TEXTURE);
+			glPushMatrix();
+			glLoadIdentity();
+
+			glColor4f(
+				U.sculpt_paint_overlay_col[0],
+				U.sculpt_paint_overlay_col[1],
+				U.sculpt_paint_overlay_col[2],
+				brush->texture_overlay_alpha / 100.0f);
+
+			glBegin(GL_QUADS);
+				glTexCoord2f(0, 0);
+				glVertex2f(0, 0);
+
+				glTexCoord2f(1, 0);
+				glVertex2f(ar->winx, 0);
+
+				glTexCoord2f(1, 1);
+				glVertex2f(ar->winx, ar->winy);
+
+				glTexCoord2f(0, 1);
+				glVertex2f(0, ar->winy);
+			glEnd();
+
+			glPopMatrix();
+
+			glMatrixMode(GL_MODELVIEW);
+		}
+
+		glPopAttrib();
+	}
+}
+
 /* Convert a point in model coordinates to 2D screen coordinates. */
 // XXX duplicated from sculpt.c, deal with this later.
 static void projectf(bglMats *mats, const float v[3], float p[2])
@@ -610,7 +669,7 @@
 				GL_VIEWPORT_BIT|
 				GL_TEXTURE_BIT);
 
-			if (ED_paint_load_overlay_tex(sd, brush, &vc)) {
+			if (paint_load_overlay_tex(sd, brush, vc.ar)) {
 				glEnable(GL_BLEND);
 
 				glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);

Modified: branches/soc-2010-jwilkins/source/blender/editors/space_view3d/view3d_draw.c
===================================================================
--- branches/soc-2010-jwilkins/source/blender/editors/space_view3d/view3d_draw.c	2010-07-15 10:51:05 UTC (rev 30368)
+++ branches/soc-2010-jwilkins/source/blender/editors/space_view3d/view3d_draw.c	2010-07-15 11:40:31 UTC (rev 30369)
@@ -2397,72 +2397,8 @@
 
 	ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_PIXEL);
 
-	/* Sculpt/Paint Overlay */
-	{
-		ViewContext vc;
-		Paint *paint = paint_get_active(CTX_data_scene(C));
-		Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
-		Brush *brush = paint_brush(paint);
-		float viewport[4];
+	ED_paint_draw_overlay(C, ar);
 
-		view3d_set_viewcontext(C, &vc);
-
-		viewport[0] = vc.ar->winrct.xmin;
-		viewport[1] = vc.ar->winrct.ymin;
-		viewport[2] = vc.ar->winx;
-		viewport[3] = vc.ar->winy;
-
-		if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_TILED && (brush->flag & BRUSH_TEXTURE_OVERLAY)) {
-			glPushAttrib(
-				GL_COLOR_BUFFER_BIT|
-				GL_CURRENT_BIT|
-				GL_DEPTH_BUFFER_BIT|
-				GL_ENABLE_BIT|
-				GL_LINE_BIT|
-				GL_POLYGON_BIT|
-				GL_STENCIL_BUFFER_BIT|
-				GL_TRANSFORM_BIT|
-				GL_VIEWPORT_BIT|
-				GL_TEXTURE_BIT);
-
-			if (ED_paint_load_overlay_tex(sd, brush, &vc)) {
-				glEnable(GL_BLEND);
-
-				glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
-				glDepthMask(GL_FALSE);
-				glDepthFunc(GL_ALWAYS);
-
-				glMatrixMode(GL_TEXTURE);
-				glPushMatrix();
-				glLoadIdentity();
-
-				glColor4f(
-					U.sculpt_paint_overlay_col[0],
-					U.sculpt_paint_overlay_col[1],
-					U.sculpt_paint_overlay_col[2],
-					brush->texture_overlay_alpha / 100.0f);
-
-				glBegin(GL_QUADS);
-				glTexCoord2f(0, 0);
-				glVertex2f(0, 0);
-
-				glTexCoord2f(1, 0);
-				glVertex2f(viewport[2], 0);
-
-				glTexCoord2f(1, 1);
-				glVertex2f(viewport[2], viewport[3]);
-
-				glTexCoord2f(0, 1);
-				glVertex2f(0, viewport[3]);
-				glEnd();
-
-				glPopMatrix();
-			}
-
-			glPopAttrib();
-		}
-	}
-
 	/* XXX here was the blockhandlers for floating panels */
 
 	v3d->flag |= V3D_INVALID_BACKBUF;





More information about the Bf-blender-cvs mailing list