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:
authorCampbell Barton <ideasman42@gmail.com>2010-08-25 12:31:52 +0400
committerCampbell Barton <ideasman42@gmail.com>2010-08-25 12:31:52 +0400
commit81d5e4f8dfe4d4d6bffd719006da96167383a743 (patch)
tree2df47453889e6cd885319c173e1d272ce8ccec66 /source/blender/editors/gpencil
parent0066e337683c9b78ff3a62e1caed004d07fe4803 (diff)
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.
Diffstat (limited to 'source/blender/editors/gpencil')
-rw-r--r--source/blender/editors/gpencil/drawgpencil.c47
-rw-r--r--source/blender/editors/gpencil/gpencil_paint.c48
2 files changed, 73 insertions, 22 deletions
diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c
index 284dac7a0ae..4867c5233bb 100644
--- a/source/blender/editors/gpencil/drawgpencil.c
+++ b/source/blender/editors/gpencil/drawgpencil.c
@@ -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 @@ static void gp_draw_stroke_point (bGPDspoint *points, short thickness, short sfl
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 @@ static void gp_draw_stroke (bGPDspoint *points, int totpoints, short thickness,
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 @@ static void gp_draw_stroke (bGPDspoint *points, int totpoints, short thickness,
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 @@ static void gp_draw_stroke (bGPDspoint *points, int totpoints, short thickness,
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 @@ void draw_gpencil_view2d (bContext *C, short onlyv2d)
/* 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);
}
/* ************************************************** */
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index cfa7af99d2a..083a90efb25 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -68,6 +68,9 @@ typedef struct tGPsdata {
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 */
@@ -271,8 +274,14 @@ static void gp_stroke_convertcoords (tGPsdata *p, short mval[], float out[], flo
/* 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 @@ static void gp_stroke_eraser_dostroke (tGPsdata *p, int mval[], int mvalo[], sho
}
#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 @@ static void gp_stroke_eraser_dostroke (tGPsdata *p, int mval[], int mvalo[], sho
}
#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 @@ static tGPsdata *gp_session_initpaint (bContext *C)
/* 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 @@ static tGPsdata *gp_session_initpaint (bContext *C)
return p;
}
+ /* for camera view set the subrect */
+ if(rv3d->persp == RV3D_CAMOB) {
+ view3d_calc_camera_border(p->scene, p->ar, NULL, v3d, &p->subrect_data);
+ p->subrect= &p->subrect_data;
+ }
+
#if 0 // XXX will this sort of antiquated stuff be restored?
/* check that gpencil data is allowed to be drawn */
if ((v3d->flag2 & V3D_DISPGP)==0) {