For the OpenGL render option in the 3d view, if a camera is active,
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Sat, 1 Dec 2007 19:29:50 +0000 (19:29 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Sat, 1 Dec 2007 19:29:50 +0000 (19:29 +0000)
it now sets the viewport exactly the same as if rendering.

source/blender/include/BSE_drawview.h
source/blender/render/extern/include/RE_pipeline.h
source/blender/render/intern/source/initrender.c
source/blender/src/drawview.c
source/blender/src/renderwin.c

index 9c577746da9a0935561280666a3f7886a4a5fa37..c425cbc62ea6823e2365c73304b5def473903967 100644 (file)
@@ -58,7 +58,7 @@ struct ImBuf *read_backbuf(short xmin, short ymin, short xmax, short ymax);
 unsigned int sample_backbuf_rect(short mval[2], int size, unsigned int min, unsigned int max, int *dist, short strict, unsigned int (*indextest)(unsigned int index));
 
 void drawview3dspace(struct ScrArea *sa, void *spacedata);
-void drawview3d_render(struct View3D *v3d, int winx, int winy);
+void drawview3d_render(struct View3D *v3d, int winx, int winy, float winmat[][4]);
 
 int update_time(void);
 void calc_viewborder(struct View3D *v3d, struct rctf *viewborder_r);
index a8abf85a28504abb00f50dacef4b69fdd5eb6776..2d9583af649d08ff730f0c9c33ca737d4a8471fb 100644 (file)
@@ -213,6 +213,7 @@ void RE_zbuf_accumulate_vecblur(struct NodeBlurData *nbd, int xsize, int ysize,
 void RE_Database_Baking(struct Render *re, struct Scene *scene, int type, struct Object *actob);
 
 void RE_DataBase_GetView(struct Render *re, float mat[][4]);
+void RE_GetCameraWindow(struct Render *re, struct Object *camera, int frame, float mat[][4]);
 
 #endif /* RE_PIPELINE_H */
 
index 83c0be6283b045cf5c0908b14ada02b48bcd0875..3ea8c6edffa265c32cd0e01aaae5c7c7b3ca04fb 100644 (file)
@@ -543,7 +543,7 @@ void RE_SetCamera(Render *re, Object *camera)
        
        re->viewdx= pixsize;
        re->viewdy= re->ycor*pixsize;
-       
+
        if(re->r.mode & R_ORTHO)
                RE_SetOrtho(re, &viewplane, clipsta, clipend);
        else 
@@ -557,6 +557,13 @@ void RE_SetPixelSize(Render *re, float pixsize)
        re->viewdy= re->ycor*pixsize;
 }
 
+void RE_GetCameraWindow(struct Render *re, struct Object *camera, int frame, float mat[][4])
+{
+       re->r.cfra= frame;
+       RE_SetCamera(re, camera);
+       Mat4CpyMat4(mat, re->winmat);
+}
+
 /* ~~~~~~~~~~~~~~~~ part (tile) calculus ~~~~~~~~~~~~~~~~~~~~~~ */
 
 
index bfccd0b77ffecd5aebc5fb55fe06eb82645f3195..a02f1065b5bf034e291ab374f8ae30c07f1124e3 100644 (file)
@@ -3090,22 +3090,25 @@ void drawview3dspace(ScrArea *sa, void *spacedata)
 }
 
 
-void drawview3d_render(struct View3D *v3d, int winx, int winy)
+void drawview3d_render(struct View3D *v3d, int winx, int winy, float winmat[][4])
 {
        Base *base;
        Scene *sce;
-       float winmat[4][4];
-       
-       update_for_newframe_muted();    /* first, since camera can be animated */
-
-       setwinmatrixview3d(winx, winy, NULL);
+       float v3dwinmat[4][4];
        
        setviewmatrixview3d();
        myloadmatrix(v3d->viewmat);
+
+       /* when winmat is not NULL, it overrides the regular window matrix */
        glMatrixMode(GL_PROJECTION);
-       mygetmatrix(winmat);
+       if(winmat)
+               myloadmatrix(winmat);
+       else
+               setwinmatrixview3d(winx, winy, NULL);
+       mygetmatrix(v3dwinmat);
        glMatrixMode(GL_MODELVIEW);
-       Mat4MulMat4(v3d->persmat, v3d->viewmat, winmat);
+
+       Mat4MulMat4(v3d->persmat, v3d->viewmat, v3dwinmat);
        Mat4Invert(v3d->persinv, v3d->persmat);
        Mat4Invert(v3d->viewinv, v3d->viewmat);
 
index 4de80414d46381192b990e8a349538f666ee51c4..40306e6073fa8c7945785bbccee3c58d4d3876db 100644 (file)
@@ -1241,6 +1241,21 @@ void BIF_do_render(int anim)
        if (G.f & G_DOSCRIPTLINKS) BPY_do_all_scripts(SCRIPT_POSTRENDER);
 }
 
+void do_ogl_view3d_render(Render *re, View3D *v3d, int winx, int winy)
+{
+       float winmat[4][4];
+
+       update_for_newframe_muted();    /* here, since camera can be animated */
+
+       if(v3d->camera) {
+               /* in camera view, use actual render winmat */
+               RE_GetCameraWindow(re, v3d->camera, CFRA, winmat);
+               drawview3d_render(v3d, winx, winy, winmat);
+       }
+       else
+               drawview3d_render(v3d, winx, winy, NULL);
+}
+
 /* set up display, render the current area view in an image */
 /* the RE_Render is only used to make sure we got the picture in the result */
 void BIF_do_ogl_render(View3D *v3d, int anim)
@@ -1256,7 +1271,7 @@ void BIF_do_ogl_render(View3D *v3d, int anim)
        winy= (G.scene->r.size*G.scene->r.ysch)/100;
        
        RE_InitState(re, &G.scene->r, winx, winy, NULL);
-       
+
        /* for now, result is defaulting to floats still... */
        rr= RE_GetResult(re);
        if(rr->rect32==NULL)
@@ -1282,7 +1297,8 @@ void BIF_do_ogl_render(View3D *v3d, int anim)
                        /* user event can close window */
                        if(render_win==NULL)
                                break;
-                       drawview3d_render(v3d, winx, winy);
+
+                       do_ogl_view3d_render(re, v3d, winx, winy);
                        glReadPixels(0, 0, winx, winy, GL_RGBA, GL_UNSIGNED_BYTE, rr->rect32);
                        BKE_stamp_buf((unsigned char *)rr->rect32, rr->rectf, rr->rectx, rr->recty);
                        window_swap_buffers(render_win->win);
@@ -1322,7 +1338,7 @@ void BIF_do_ogl_render(View3D *v3d, int anim)
                CFRA= cfrao;
        }
        else {
-               drawview3d_render(v3d, winx, winy);
+               do_ogl_view3d_render(re, v3d, winx, winy);
                glReadPixels(0, 0, winx, winy, GL_RGBA, GL_UNSIGNED_BYTE, rr->rect32);
                BKE_stamp_buf((unsigned char *)rr->rect32, rr->rectf, rr->rectx, rr->recty);
                window_swap_buffers(render_win->win);