[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30367] branches/soc-2010-jwilkins/source/ blender: * Bug Fix: overlay is now on all the time

Jason Wilkins Jason.A.Wilkins at gmail.com
Thu Jul 15 09:44:05 CEST 2010


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

Log Message:
-----------
* Bug Fix: overlay is now on all the time
* Known Problem: generating the overlay is slow but optimizing it will be moderately complicated.  There will have to be a complex function written to draw the overlay so that it corresponds to all of Blender's texture mapping options.

Right now it samples the texture into the overlay from blender, which guarantees that the result is one-to-one what blender will generate but is a little slow.

Modified Paths:
--------------
    branches/soc-2010-jwilkins/source/blender/editors/include/ED_sculpt.h
    branches/soc-2010-jwilkins/source/blender/editors/include/ED_view3d.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
    branches/soc-2010-jwilkins/source/blender/editors/space_view3d/view3d_select.c
    branches/soc-2010-jwilkins/source/blender/makesrna/intern/rna_brush.c
    branches/soc-2010-jwilkins/source/blender/makesrna/intern/rna_texture.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 05:53:11 UTC (rev 30366)
+++ branches/soc-2010-jwilkins/source/blender/editors/include/ED_sculpt.h	2010-07-15 07:44:04 UTC (rev 30367)
@@ -52,4 +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);
+
 #endif

Modified: branches/soc-2010-jwilkins/source/blender/editors/include/ED_view3d.h
===================================================================
--- branches/soc-2010-jwilkins/source/blender/editors/include/ED_view3d.h	2010-07-15 05:53:11 UTC (rev 30366)
+++ branches/soc-2010-jwilkins/source/blender/editors/include/ED_view3d.h	2010-07-15 07:44:04 UTC (rev 30367)
@@ -138,7 +138,7 @@
 #define MAXPICKBUF      10000
 short view3d_opengl_select(struct ViewContext *vc, unsigned int *buffer, unsigned int bufsize, rcti *input);
 
-void view3d_set_viewcontext(struct bContext *C, struct ViewContext *vc);
+void view3d_set_viewcontext(const struct bContext *C, struct ViewContext *vc);
 void view3d_operator_needs_opengl(const struct bContext *C);
 void view3d_get_view_aligned_coordinate(struct ViewContext *vc, float *fp, short mval[2]);
 void view3d_get_transformation(struct ARegion *ar, struct RegionView3D *rv3d, struct Object *ob, struct bglMats *mats);

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 05:53:11 UTC (rev 30366)
+++ branches/soc-2010-jwilkins/source/blender/editors/sculpt_paint/paint_stroke.c	2010-07-15 07:44:04 UTC (rev 30367)
@@ -253,7 +253,7 @@
 	snap->winy = vc->ar->winy;
 }
 
-int load_tex(Sculpt *sd, Brush* br, ViewContext* vc)
+int ED_paint_load_overlay_tex(Sculpt *sd, Brush* br, ViewContext* vc)
 {
 	static GLuint overlay_texture = 0;
 	static int init = 0;
@@ -317,7 +317,7 @@
 			old_size = size;
 		}
 
-		buffer = MEM_mallocN(sizeof(GLubyte)*size*size, "load_tex");
+		buffer = MEM_mallocN(sizeof(GLubyte)*size*size, "ED_paint_load_overlay_tex");
 
 		#pragma omp parallel for schedule(static) if (sd->flags & SCULPT_USE_OPENMP)
 		for (j= 0; j < size; j++) {
@@ -597,7 +597,7 @@
 
 		alpha = (paint->flags & PAINT_SHOW_BRUSH_ON_SURFACE) ? min_alpha + (visual_strength*(max_alpha-min_alpha)) : 0.50f;
 
-		if (ELEM(brush->mtex.brush_map_mode, MTEX_MAP_MODE_FIXED, MTEX_MAP_MODE_TILED) && brush->flag & BRUSH_TEXTURE_OVERLAY) {
+		if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_FIXED && (brush->flag & BRUSH_TEXTURE_OVERLAY)) {
 			glPushAttrib(
 				GL_COLOR_BUFFER_BIT|
 				GL_CURRENT_BIT|
@@ -610,7 +610,7 @@
 				GL_VIEWPORT_BIT|
 				GL_TEXTURE_BIT);
 
-			if (load_tex(sd, brush, &vc)) {
+			if (ED_paint_load_overlay_tex(sd, brush, &vc)) {
 				glEnable(GL_BLEND);
 
 				glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
@@ -647,46 +647,31 @@
 					brush->texture_overlay_alpha / 100.0f);
 
 				glBegin(GL_QUADS);
-				if (brush->mtex.brush_map_mode == MTEX_MAP_MODE_FIXED) {
-					if (sd->draw_anchored) {
-						glTexCoord2f(0, 0);
-						glVertex2f(sd->anchored_initial_mouse[0]-sd->anchored_size - vc.ar->winrct.xmin, sd->anchored_initial_mouse[1]-sd->anchored_size - vc.ar->winrct.ymin);
+				if (sd->draw_anchored) {
+					glTexCoord2f(0, 0);
+					glVertex2f(sd->anchored_initial_mouse[0]-sd->anchored_size - vc.ar->winrct.xmin, sd->anchored_initial_mouse[1]-sd->anchored_size - vc.ar->winrct.ymin);
 
-						glTexCoord2f(1, 0);
-						glVertex2f(sd->anchored_initial_mouse[0]+sd->anchored_size - vc.ar->winrct.xmin, sd->anchored_initial_mouse[1]-sd->anchored_size - vc.ar->winrct.ymin);
+					glTexCoord2f(1, 0);
+					glVertex2f(sd->anchored_initial_mouse[0]+sd->anchored_size - vc.ar->winrct.xmin, sd->anchored_initial_mouse[1]-sd->anchored_size - vc.ar->winrct.ymin);
 
-						glTexCoord2f(1, 1);
-						glVertex2f(sd->anchored_initial_mouse[0]+sd->anchored_size - vc.ar->winrct.xmin, sd->anchored_initial_mouse[1]+sd->anchored_size - vc.ar->winrct.ymin);
+					glTexCoord2f(1, 1);
+					glVertex2f(sd->anchored_initial_mouse[0]+sd->anchored_size - vc.ar->winrct.xmin, sd->anchored_initial_mouse[1]+sd->anchored_size - vc.ar->winrct.ymin);
 
-						glTexCoord2f(0, 1);
-						glVertex2f(sd->anchored_initial_mouse[0]-sd->anchored_size - vc.ar->winrct.xmin, sd->anchored_initial_mouse[1]+sd->anchored_size - vc.ar->winrct.ymin);
-					}
-					else {
-						glTexCoord2f(0, 0);
-						glVertex2f((float)x-sculpt_get_brush_size(brush), (float)y-sculpt_get_brush_size(brush));
-
-						glTexCoord2f(1, 0);
-						glVertex2f((float)x+sculpt_get_brush_size(brush), (float)y-sculpt_get_brush_size(brush));
-
-						glTexCoord2f(1, 1);
-						glVertex2f((float)x+sculpt_get_brush_size(brush), (float)y+sculpt_get_brush_size(brush));
-
-						glTexCoord2f(0, 1);
-						glVertex2f((float)x-sculpt_get_brush_size(brush), (float)y+sculpt_get_brush_size(brush));
-					}
+					glTexCoord2f(0, 1);
+					glVertex2f(sd->anchored_initial_mouse[0]-sd->anchored_size - vc.ar->winrct.xmin, sd->anchored_initial_mouse[1]+sd->anchored_size - vc.ar->winrct.ymin);
 				}
 				else {
 					glTexCoord2f(0, 0);
-					glVertex2f(0, 0);
+					glVertex2f((float)x-sculpt_get_brush_size(brush), (float)y-sculpt_get_brush_size(brush));
 
 					glTexCoord2f(1, 0);
-					glVertex2f(viewport[2], 0);
+					glVertex2f((float)x+sculpt_get_brush_size(brush), (float)y-sculpt_get_brush_size(brush));
 
 					glTexCoord2f(1, 1);
-					glVertex2f(viewport[2], viewport[3]);
+					glVertex2f((float)x+sculpt_get_brush_size(brush), (float)y+sculpt_get_brush_size(brush));
 
 					glTexCoord2f(0, 1);
-					glVertex2f(0, viewport[3]);
+					glVertex2f((float)x-sculpt_get_brush_size(brush), (float)y+sculpt_get_brush_size(brush));
 				}
 				glEnd();
 

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 05:53:11 UTC (rev 30366)
+++ branches/soc-2010-jwilkins/source/blender/editors/space_view3d/view3d_draw.c	2010-07-15 07:44:04 UTC (rev 30367)
@@ -78,6 +78,7 @@
 #include "ED_screen_types.h"
 #include "ED_transform.h"
 #include "ED_gpencil.h"
+#include "ED_sculpt.h"
 
 #include "UI_interface.h"
 #include "UI_interface_icons.h"
@@ -2395,7 +2396,73 @@
 		draw_selected_name(scene, ob, v3d);
 
 	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];
+
+		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;

Modified: branches/soc-2010-jwilkins/source/blender/editors/space_view3d/view3d_select.c
===================================================================
--- branches/soc-2010-jwilkins/source/blender/editors/space_view3d/view3d_select.c	2010-07-15 05:53:11 UTC (rev 30366)
+++ branches/soc-2010-jwilkins/source/blender/editors/space_view3d/view3d_select.c	2010-07-15 07:44:04 UTC (rev 30367)
@@ -80,7 +80,7 @@
 #include "view3d_intern.h"	// own include
 
 // TODO: should return whether there is valid context to continue
-void view3d_set_viewcontext(bContext *C, ViewContext *vc)
+void view3d_set_viewcontext(const bContext *C, ViewContext *vc)
 {
 	memset(vc, 0, sizeof(ViewContext));
 	vc->ar= CTX_wm_region(C);

Modified: branches/soc-2010-jwilkins/source/blender/makesrna/intern/rna_brush.c
===================================================================
--- branches/soc-2010-jwilkins/source/blender/makesrna/intern/rna_brush.c	2010-07-15 05:53:11 UTC (rev 30366)
+++ branches/soc-2010-jwilkins/source/blender/makesrna/intern/rna_brush.c	2010-07-15 07:44:04 UTC (rev 30367)
@@ -50,6 +50,7 @@
 {
 	Brush *br= (Brush*)ptr->data;
 	WM_main_add_notifier(NC_BRUSH|NA_EDITED, br);
+	WM_main_add_notifier(NC_SPACE|ND_SPACE_VIEW3D, NULL);
 }
 
 static int rna_Brush_is_sculpt_brush(Brush *me, bContext *C)

Modified: branches/soc-2010-jwilkins/source/blender/makesrna/intern/rna_texture.c
===================================================================
--- branches/soc-2010-jwilkins/source/blender/makesrna/intern/rna_texture.c	2010-07-15 05:53:11 UTC (rev 30366)
+++ branches/soc-2010-jwilkins/source/blender/makesrna/intern/rna_texture.c	2010-07-15 07:44:04 UTC (rev 30367)
@@ -182,6 +182,7 @@
 			break;
 		case ID_BR: 
 			WM_main_add_notifier(NC_BRUSH, id);
+			WM_main_add_notifier(NC_SPACE|ND_SPACE_VIEW3D, NULL);
 			break;
 	}
 }





More information about the Bf-blender-cvs mailing list