[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31573] trunk/blender/source/blender: bugfix [#22819] Grease Pencil: OpenGL render incorrect if view mode, OK with cursor mode

Campbell Barton ideasman42 at gmail.com
Wed Aug 25 10:31:52 CEST 2010


Revision: 31573
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31573
Author:   campbellbarton
Date:     2010-08-25 10:31:52 +0200 (Wed, 25 Aug 2010)

Log Message:
-----------
bugfix [#22819] Grease Pencil: OpenGL render incorrect if view mode, OK with cursor mode
also made drawing in camera view stick to the camera border (belated durian request),
useful for animation review without worrying about screensize moving the overlay about.

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/BLI_math_vector.h
    trunk/blender/source/blender/blenlib/BLI_rect.h
    trunk/blender/source/blender/blenlib/intern/math_vector.c
    trunk/blender/source/blender/blenlib/intern/rct.c
    trunk/blender/source/blender/editors/gpencil/drawgpencil.c
    trunk/blender/source/blender/editors/gpencil/gpencil_paint.c
    trunk/blender/source/blender/editors/include/ED_gpencil.h
    trunk/blender/source/blender/editors/include/ED_view3d.h
    trunk/blender/source/blender/editors/space_view3d/view3d_draw.c
    trunk/blender/source/blender/editors/space_view3d/view3d_edit.c
    trunk/blender/source/blender/editors/space_view3d/view3d_intern.h
    trunk/blender/source/blender/editors/space_view3d/view3d_view.c

Modified: trunk/blender/source/blender/blenlib/BLI_math_vector.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_vector.h	2010-08-25 07:49:12 UTC (rev 31572)
+++ trunk/blender/source/blender/blenlib/BLI_math_vector.h	2010-08-25 08:31:52 UTC (rev 31573)
@@ -151,9 +151,9 @@
 
 /*********************************** Other ***********************************/
 
-void print_v2(char *str, float a[2]);
-void print_v3(char *str, float a[3]);
-void print_v4(char *str, float a[4]);
+void print_v2(const char *str, const float a[2]);
+void print_v3(const char *str, const float a[3]);
+void print_v4(const char *str, const float a[4]);
 
 MINLINE void normal_short_to_float_v3(float r[3], const short n[3]);
 MINLINE void normal_float_to_short_v3(short r[3], const float n[3]);

Modified: trunk/blender/source/blender/blenlib/BLI_rect.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_rect.h	2010-08-25 07:49:12 UTC (rev 31572)
+++ trunk/blender/source/blender/blenlib/BLI_rect.h	2010-08-25 08:31:52 UTC (rev 31573)
@@ -60,7 +60,10 @@
 int  BLI_isect_rcti(struct rcti *src1, struct rcti *src2, struct rcti *dest);
 void BLI_union_rctf(struct rctf *rcta, struct rctf *rctb);
 void BLI_union_rcti(struct rcti *rcti1, struct rcti *rcti2);
+void BLI_copy_rcti_rctf(struct rcti *tar, const struct rctf *src);
 
+void print_rctf(const char *str, struct rctf *rect);
+void print_rcti(const char *str, struct rcti *rect);
 
 #ifdef __cplusplus
 }

Modified: trunk/blender/source/blender/blenlib/intern/math_vector.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_vector.c	2010-08-25 07:49:12 UTC (rev 31572)
+++ trunk/blender/source/blender/blenlib/intern/math_vector.c	2010-08-25 08:31:52 UTC (rev 31573)
@@ -298,17 +298,17 @@
 
 /*********************************** Other ***********************************/
 
-void print_v2(char *str, float v[2])
+void print_v2(const char *str, const float v[2])
 {
 	printf("%s: %.3f %.3f\n", str, v[0], v[1]);
 }
 
-void print_v3(char *str, float v[3])
+void print_v3(const char *str, const float v[3])
 {
 	printf("%s: %.3f %.3f %.3f\n", str, v[0], v[1], v[2]);
 }
 
-void print_v4(char *str, float v[4])
+void print_v4(const char *str, const float v[4])
 {
 	printf("%s: %.3f %.3f %.3f %.3f\n", str, v[0], v[1], v[2], v[3]);
 }

Modified: trunk/blender/source/blender/blenlib/intern/rct.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/rct.c	2010-08-25 07:49:12 UTC (rev 31572)
+++ trunk/blender/source/blender/blenlib/intern/rct.c	2010-08-25 08:31:52 UTC (rev 31573)
@@ -36,6 +36,8 @@
  */
 
 #include "DNA_vec_types.h"
+#include <stdio.h>
+#include <math.h>
 
 int BLI_rcti_is_empty(rcti * rect)
 {
@@ -222,3 +224,21 @@
 		return 0;
 	}
 }
+
+void BLI_copy_rcti_rctf(rcti *tar, const rctf *src)
+{
+	tar->xmin= floor(src->xmin + 0.5);
+	tar->xmax= floor((src->xmax - src->xmin) + 0.5);
+	tar->ymin= floor(src->ymin + 0.5);
+	tar->ymax= floor((src->ymax - src->ymin) + 0.5);
+}
+
+void print_rctf(const char *str, rctf *rect)
+{
+	printf("%s: xmin %.3f, xmax %.3f, ymin %.3f, ymax %.3f\n", str, rect->xmin, rect->xmax, rect->ymin, rect->ymax);
+}
+
+void print_rcti(const char *str, rcti *rect)
+{
+	printf("%s: xmin %d, xmax %d, ymin %d, ymax %d\n", str, rect->xmin, rect->xmax, rect->ymin, rect->ymax);
+}

Modified: trunk/blender/source/blender/editors/gpencil/drawgpencil.c
===================================================================
--- trunk/blender/source/blender/editors/gpencil/drawgpencil.c	2010-08-25 07:49:12 UTC (rev 31572)
+++ trunk/blender/source/blender/editors/gpencil/drawgpencil.c	2010-08-25 08:31:52 UTC (rev 31573)
@@ -42,6 +42,7 @@
 #include "DNA_scene_types.h"
 #include "DNA_screen_types.h"
 #include "DNA_space_types.h"
+#include "DNA_view3d_types.h"
 
 #include "BKE_context.h"
 #include "BKE_global.h"
@@ -56,6 +57,7 @@
 
 #include "ED_gpencil.h"
 #include "ED_sequencer.h"
+#include "ED_view3d.h"
 
 
 #include "gpencil_intern.h"
@@ -164,8 +166,8 @@
 			co[1]= (points->y * winy) + offsy;
 		}
 		else {
-			co[0]= (points->x / 100 * winx);
-			co[1]= (points->y / 100 * winy);
+			co[0]= (points->x / 100 * winx) + offsx;
+			co[1]= (points->y / 100 * winy) + offsy;
 		}
 		
 		/* if thickness is less than GP_DRAWTHICKNESS_SPECIAL, simple dot looks ok
@@ -265,8 +267,8 @@
 				glVertex2f(x, y);
 			}
 			else {
-				const float x= (pt->x / 100 * winx);
-				const float y= (pt->y / 100 * winy);
+				const float x= (pt->x / 100 * winx) + offsx;
+				const float y= (pt->y / 100 * winy) + offsy;
 				
 				glVertex2f(x, y);
 			}
@@ -305,10 +307,10 @@
 				s1[1]= (pt2->y * winy) + offsy;
 			}
 			else {
-				s0[0]= (pt1->x / 100 * winx);
-				s0[1]= (pt1->y / 100 * winy);
-				s1[0]= (pt2->x / 100 * winx);
-				s1[1]= (pt2->y / 100 * winy);
+				s0[0]= (pt1->x / 100 * winx) + offsx;
+				s0[1]= (pt1->y / 100 * winy) + offsy;
+				s1[0]= (pt2->x / 100 * winx) + offsx;
+				s1[1]= (pt2->y / 100 * winy) + offsy;
 			}		
 			
 			/* calculate gradient and normal - 'angle'=(ny/nx) */
@@ -453,8 +455,8 @@
 				glVertex2f(x, y);
 			}
 			else {
-				const float x= (float)(pt->x / 100 * winx);
-				const float y= (float)(pt->y / 100 * winy);
+				const float x= (float)(pt->x / 100 * winx) + offsx;
+				const float y= (float)(pt->y / 100 * winy) + offsy;
 				
 				glVertex2f(x, y);
 			}
@@ -732,25 +734,44 @@
 /* draw grease-pencil sketches to specified 3d-view assuming that matrices are already set correctly 
  * Note: this gets called twice - first time with only3d=1 to draw 3d-strokes, second time with only3d=0 for screen-aligned strokes
  */
-void draw_gpencil_view3d_ext (Scene *scene, ARegion *ar, short only3d)
+
+void draw_gpencil_view3d_ext (Scene *scene, View3D *v3d, ARegion *ar, short only3d)
 {
 	bGPdata *gpd;
 	int dflag = 0;
+	rcti rect;
+	RegionView3D *rv3d= ar->regiondata;
 
 	/* check that we have grease-pencil stuff to draw */
 	gpd= gpencil_data_get_active_v3d(scene); // XXX
 	if(gpd == NULL) return;
 
+	/* when rendering to the offscreen buffer we dont want to
+	 * deal with the camera border, otherwise map the coords to the camera border. */
+	if(rv3d->persp == RV3D_CAMOB && !(G.f & G_RENDER_OGL)) {
+		rctf rectf;
+		view3d_calc_camera_border(scene, ar, rv3d, v3d, &rectf);
+		BLI_copy_rcti_rctf(&rect, &rectf);
+	}
+	else {
+		rect.xmin= 0;
+		rect.ymin= 0;
+		rect.xmax= ar->winx;
+		rect.ymax= ar->winy;
+	}
+	
 	/* draw it! */
 	if (only3d) dflag |= (GP_DRAWDATA_ONLY3D|GP_DRAWDATA_NOSTATUS);
-	gp_draw_data(gpd, 0, 0, ar->winx, ar->winy, CFRA, dflag);
+
+	gp_draw_data(gpd, rect.xmin, rect.ymin, rect.xmax, rect.ymax, CFRA, dflag);
 }
 
 void draw_gpencil_view3d (bContext *C, short only3d)
 {
 	ARegion *ar= CTX_wm_region(C);
+	View3D *v3d= CTX_wm_view3d(C);
 	Scene *scene= CTX_data_scene(C);
-	draw_gpencil_view3d_ext(scene, ar, only3d);
+	draw_gpencil_view3d_ext(scene, v3d, ar, only3d);
 }
 
 /* ************************************************** */

Modified: trunk/blender/source/blender/editors/gpencil/gpencil_paint.c
===================================================================
--- trunk/blender/source/blender/editors/gpencil/gpencil_paint.c	2010-08-25 07:49:12 UTC (rev 31572)
+++ trunk/blender/source/blender/editors/gpencil/gpencil_paint.c	2010-08-25 08:31:52 UTC (rev 31573)
@@ -68,7 +68,10 @@
 	ScrArea *sa;		/* area where painting originated */
 	ARegion *ar;        /* region where painting originated */
 	View2D *v2d;		/* needed for GP_STROKE_2DSPACE */
+	rctf *subrect;		/* for using the camera rect within the 3d view */
+	rctf subrect_data;
 	
+	
 #if 0 // XXX review this 2d image stuff...
 	ImBuf *ibuf;		/* needed for GP_STROKE_2DIMAGE */
 	struct IBufViewSettings {
@@ -271,8 +274,14 @@
 	
 	/* 2d - relative to screen (viewport area) */
 	else {
-		out[0] = (float)(mval[0]) / (float)(p->ar->winx) * 100;
-		out[1] = (float)(mval[1]) / (float)(p->ar->winy) * 100;
+		if(p->subrect == NULL) { /* normal 3D view */
+			out[0] = (float)(mval[0]) / (float)(p->ar->winx) * 100;
+			out[1] = (float)(mval[1]) / (float)(p->ar->winy) * 100;
+		}
+		else { /* camera view, use subrect */
+			out[0]= ((mval[0] - p->subrect->xmin) / ((p->subrect->xmax - p->subrect->xmin))) * 100;
+			out[1]= ((mval[1] - p->subrect->ymin) / ((p->subrect->ymax - p->subrect->ymin))) * 100;
+		}
 	}
 }
 
@@ -704,8 +713,14 @@
 		}
 #endif
 		else {
-			x0= (int)(gps->points->x / 100 * p->ar->winx);
-			y0= (int)(gps->points->y / 100 * p->ar->winy);
+			if(p->subrect == NULL) { /* normal 3D view */
+				x0= (int)(gps->points->x / 100 * p->ar->winx);
+				y0= (int)(gps->points->y / 100 * p->ar->winy);
+			}
+			else { /* camera view, use subrect */
+				x0= (int)((gps->points->x / 100) * (p->subrect->xmax - p->subrect->xmin)) + p->subrect->xmin;
+				y0= (int)((gps->points->y / 100) * (p->subrect->ymax - p->subrect->ymin)) + p->subrect->ymin;
+			}
 		}
 		
 		/* do boundbox check first */
@@ -761,10 +776,18 @@
 			}
 #endif
 			else {
-				x0= (int)(pt1->x / 100 * p->ar->winx);
-				y0= (int)(pt1->y / 100 * p->ar->winy);
-				x1= (int)(pt2->x / 100 * p->ar->winx);
-				y1= (int)(pt2->y / 100 * p->ar->winy);
+				if(p->subrect == NULL) { /* normal 3D view */
+					x0= (int)(pt1->x / 100 * p->ar->winx);
+					y0= (int)(pt1->y / 100 * p->ar->winy);
+					x1= (int)(pt2->x / 100 * p->ar->winx);
+					y1= (int)(pt2->y / 100 * p->ar->winy);
+				}
+				else { /* camera view, use subrect */ 
+					x0= (int)((pt1->x / 100) * (p->subrect->xmax - p->subrect->xmin)) + p->subrect->xmin;
+					y0= (int)((pt1->y / 100) * (p->subrect->ymax - p->subrect->ymin)) + p->subrect->ymin;
+					x1= (int)((pt2->x / 100) * (p->subrect->xmax - p->subrect->xmin)) + p->subrect->xmin;
+					y1= (int)((pt2->y / 100) * (p->subrect->ymax - p->subrect->ymin)) + p->subrect->ymin;
+				}
 			}
 			
 			/* check that point segment of the boundbox of the eraser stroke */
@@ -849,7 +872,8 @@
 		/* supported views first */
 		case SPACE_VIEW3D:
 		{
-			//View3D *v3d= curarea->spacedata.first;
+			View3D *v3d= curarea->spacedata.first;
+			RegionView3D *rv3d= ar->regiondata;
 			
 			/* set current area 
 			 *	- must verify that region data is 3D-view (and not something else)
@@ -864,6 +888,12 @@
 				return p;
 			}
 			
+			/* for camera view set the subrect */
+			if(rv3d->persp == RV3D_CAMOB) {

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list