Revision: 44711
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=44711
Author:   nazgul
Date:     2012-03-07 17:45:40 +0000 (Wed, 07 Mar 2012)
Log Message:
-----------
Mango request: use active scene clip as background for sequencer scene strip 
renderer
and opengl renerer when rendering from camera view.

Other usages of offscreen drawing shouldn't be affected by this change.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/include/ED_view3d.h
    trunk/blender/source/blender/editors/render/render_opengl.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_image.c
    trunk/blender/source/blender/editors/space_view3d/view3d_draw.c
    trunk/blender/source/blender/windowmanager/intern/wm_files.c

Modified: trunk/blender/source/blender/editors/include/ED_view3d.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_view3d.h    2012-03-07 
17:36:38 UTC (rev 44710)
+++ trunk/blender/source/blender/editors/include/ED_view3d.h    2012-03-07 
17:45:40 UTC (rev 44711)
@@ -284,10 +284,10 @@
 
 int ED_view3d_context_activate(struct bContext *C);
 void ED_view3d_draw_offscreen(struct Scene *scene, struct View3D *v3d, struct 
ARegion *ar,
-       int winx, int winy, float viewmat[][4], float winmat[][4]);
+       int winx, int winy, float viewmat[][4], float winmat[][4], int 
draw_background);
 
-struct ImBuf *ED_view3d_draw_offscreen_imbuf(struct Scene *scene, struct 
View3D *v3d, struct ARegion *ar, int sizex, int sizey, unsigned int flag, char 
err_out[256]);
-struct ImBuf *ED_view3d_draw_offscreen_imbuf_simple(struct Scene *scene, 
struct Object *camera, int width, int height, unsigned int flag, int drawtype, 
char err_out[256]);
+struct ImBuf *ED_view3d_draw_offscreen_imbuf(struct Scene *scene, struct 
View3D *v3d, struct ARegion *ar, int sizex, int sizey, unsigned int flag, int 
draw_background, char err_out[256]);
+struct ImBuf *ED_view3d_draw_offscreen_imbuf_simple(struct Scene *scene, 
struct Object *camera, int width, int height, unsigned int flag, int drawtype, 
int draw_background, char err_out[256]);
 
 
 struct Base *ED_view3d_give_base_under_cursor(struct bContext *C, const int 
mval[2]);

Modified: trunk/blender/source/blender/editors/render/render_opengl.c
===================================================================
--- trunk/blender/source/blender/editors/render/render_opengl.c 2012-03-07 
17:36:38 UTC (rev 44710)
+++ trunk/blender/source/blender/editors/render/render_opengl.c 2012-03-07 
17:45:40 UTC (rev 44711)
@@ -149,7 +149,7 @@
                }
 
                if((scene->r.mode & R_OSA) == 0) { 
-                       ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, 
NULL, winmat);
+                       ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, 
NULL, winmat, TRUE);
                        GPU_offscreen_read_pixels(oglrender->ofs, GL_FLOAT, 
rr->rectf);
                }
                else {
@@ -163,7 +163,7 @@
                        BLI_initjit(jit_ofs[0], scene->r.osa);
 
                        /* first sample buffer, also initializes 
'rv3d->persmat' */
-                       ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, 
NULL, winmat);
+                       ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, 
NULL, winmat, TRUE);
                        GPU_offscreen_read_pixels(oglrender->ofs, GL_FLOAT, 
accum_buffer);
 
                        /* skip the first sample */
@@ -173,7 +173,7 @@
                                                    (jit_ofs[j][0] * 2.0f) / 
sizex,
                                                    (jit_ofs[j][1] * 2.0f) / 
sizey);
 
-                               ED_view3d_draw_offscreen(scene, v3d, ar, sizex, 
sizey, NULL, winmat_jitter);
+                               ED_view3d_draw_offscreen(scene, v3d, ar, sizex, 
sizey, NULL, winmat_jitter, TRUE);
                                GPU_offscreen_read_pixels(oglrender->ofs, 
GL_FLOAT, accum_tmp);
                                add_vn_vn(accum_buffer, accum_tmp, 
sizex*sizey*sizeof(float));
                        }
@@ -189,7 +189,7 @@
        else {
                /* shouldnt suddenly give errors mid-render but possible */
                char err_out[256]= "unknown";
-               ImBuf *ibuf_view= ED_view3d_draw_offscreen_imbuf_simple(scene, 
scene->camera, oglrender->sizex, oglrender->sizey, IB_rectfloat, OB_SOLID, 
err_out);
+               ImBuf *ibuf_view= ED_view3d_draw_offscreen_imbuf_simple(scene, 
scene->camera, oglrender->sizex, oglrender->sizey, IB_rectfloat, OB_SOLID, 
TRUE, err_out);
                camera= scene->camera;
 
                if(ibuf_view) {

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_image.c     
2012-03-07 17:36:38 UTC (rev 44710)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_image.c     
2012-03-07 17:45:40 UTC (rev 44711)
@@ -5739,7 +5739,7 @@
        if(w > maxsize) w= maxsize;
        if(h > maxsize) h= maxsize;
 
-       ibuf= ED_view3d_draw_offscreen_imbuf(CTX_data_scene(C), 
CTX_wm_view3d(C), CTX_wm_region(C), w, h, IB_rect, err_out);
+       ibuf= ED_view3d_draw_offscreen_imbuf(CTX_data_scene(C), 
CTX_wm_view3d(C), CTX_wm_region(C), w, h, IB_rect, FALSE, err_out);
        if(!ibuf) {
                /* Mostly happens when OpenGL offscreen buffer was failed to 
create, */
                /* but could be other reasons. Should be handled in the future. 
nazgul */

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_draw.c     
2012-03-07 17:36:38 UTC (rev 44710)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_draw.c     
2012-03-07 17:45:40 UTC (rev 44711)
@@ -2252,7 +2252,7 @@
                mult_m4_m4m4(rv3d.persmat, rv3d.winmat, rv3d.viewmat);
                invert_m4_m4(rv3d.persinv, rv3d.viewinv);
 
-               ED_view3d_draw_offscreen(scene, v3d, &ar, winsize, winsize, 
viewmat, winmat);
+               ED_view3d_draw_offscreen(scene, v3d, &ar, winsize, winsize, 
viewmat, winmat, FALSE);
                GPU_lamp_shadow_buffer_unbind(shadow->lamp);
                
                v3d->drawtype= drawtype;
@@ -2387,13 +2387,15 @@
 }
 
 void ED_view3d_draw_offscreen(Scene *scene, View3D *v3d, ARegion *ar,
-                              int winx, int winy, float viewmat[][4], float 
winmat[][4])
+                              int winx, int winy, float viewmat[][4], float 
winmat[][4],
+                              int draw_background)
 {
        RegionView3D *rv3d= ar->regiondata;
        Base *base;
        float backcol[3];
        int bwinx, bwiny;
        rcti brect;
+       ImBuf *bg_ibuf = NULL;
 
        glPushMatrix();
 
@@ -2421,20 +2423,67 @@
        if (draw_glsl_material(scene, NULL, v3d, v3d->drawtype))
                gpu_update_lamps_shadows(scene, v3d);
 
-       /* set background color, fallback on the view background color */
-       if (scene->world) {
-               if (scene->r.color_mgt_flag & R_COLOR_MANAGEMENT)
-                       linearrgb_to_srgb_v3_v3(backcol, &scene->world->horr);
-               else
-                       copy_v3_v3(backcol, &scene->world->horr);
-               glClearColor(backcol[0], backcol[1], backcol[2], 0.0);
+       /* if scene has got active clip, use it for render backdrop */
+       if (draw_background && scene->clip && rv3d->persp==RV3D_CAMOB && 
v3d->camera) {
+               MovieClipUser user = {0};
+
+               BKE_movieclip_user_set_frame(&user, CFRA);
+               bg_ibuf = BKE_movieclip_get_ibuf(scene->clip, &user);
        }
-       else {
-               UI_ThemeClearColor(TH_BACK);    
+
+       if (!bg_ibuf) {
+               /* set background color, fallback on the view background color
+                * (if active clip is set but frame is failed to load fallback 
to horizon color as background) */
+               if (scene->world) {
+                       if (scene->r.color_mgt_flag & R_COLOR_MANAGEMENT)
+                               linearrgb_to_srgb_v3_v3(backcol, 
&scene->world->horr);
+                       else
+                               copy_v3_v3(backcol, &scene->world->horr);
+                       glClearColor(backcol[0], backcol[1], backcol[2], 0.0);
+               }
+               else {
+                       UI_ThemeClearColor(TH_BACK);
+               }
        }
 
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
 
+       if (bg_ibuf) {
+               unsigned char *pixels, *cp, *dst_cp;
+               int i;
+
+               if (bg_ibuf->rect_float && !bg_ibuf->rect)
+                       IMB_rect_from_float(bg_ibuf);
+
+               dst_cp = pixels = MEM_callocN(4*sizeof(unsigned 
char)*bg_ibuf->x*bg_ibuf->y, "draw offscreen clip pixels");
+               cp = bg_ibuf->rect;
+               for (i = 0; i < bg_ibuf->x*bg_ibuf->y; i++, cp += 4, dst_cp += 
4) {
+                       dst_cp[0] = cp[0];
+                       dst_cp[1] = cp[1];
+                       dst_cp[2] = cp[2];
+                       dst_cp[3] = 255;
+               }
+
+               glMatrixMode(GL_PROJECTION);
+               glPushMatrix();
+               glMatrixMode(GL_MODELVIEW);
+               glPushMatrix();
+               ED_region_pixelspace(ar);
+
+               glPixelZoom((float)winx / bg_ibuf->x, (float)winy / bg_ibuf->y);
+               glaDrawPixelsTex(0, 0, bg_ibuf->x, bg_ibuf->y, 
GL_UNSIGNED_BYTE, pixels);
+
+               glPixelZoom(1.0, 1.0);
+
+               glMatrixMode(GL_PROJECTION);
+               glPopMatrix();
+               glMatrixMode(GL_MODELVIEW);
+               glPopMatrix();
+
+               IMB_freeImBuf(bg_ibuf);
+               MEM_freeN(pixels);
+       }
+
        /* setup view matrices */
        view3d_main_area_setup_view(scene, v3d, ar, viewmat, winmat);
 
@@ -2520,7 +2569,7 @@
 
 /* utility func for ED_view3d_draw_offscreen */
 ImBuf *ED_view3d_draw_offscreen_imbuf(Scene *scene, View3D *v3d, ARegion *ar,
-                                      int sizex, int sizey, unsigned int flag, 
char err_out[256])
+                                      int sizex, int sizey, unsigned int flag, 
int draw_background, char err_out[256])
 {
        RegionView3D *rv3d= ar->regiondata;
        ImBuf *ibuf;
@@ -2545,10 +2594,10 @@
                camera_params_compute_viewplane(&params, sizex, sizey, 
scene->r.xasp, scene->r.yasp);
                camera_params_compute_matrix(&params);
 
-               ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, NULL, 
params.winmat);
+               ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, NULL, 
params.winmat, draw_background);
        }
        else {
-               ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, NULL, 
NULL);
+               ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, NULL, 
NULL, draw_background);
        }
 
        /* read in pixels & stamp */
@@ -2576,7 +2625,7 @@
 
 /* creates own 3d views, used by the sequencer */
 ImBuf *ED_view3d_draw_offscreen_imbuf_simple(Scene *scene, Object *camera, int 
width, int height,
-                                             unsigned int flag, int drawtype, 
char err_out[256])
+                                             unsigned int flag, int drawtype, 
int draw_background, char err_out[256])
 {
        View3D v3d= {NULL};
        ARegion ar= {NULL};
@@ -2615,7 +2664,7 @@
        mult_m4_m4m4(rv3d.persmat, rv3d.winmat, rv3d.viewmat);
        invert_m4_m4(rv3d.persinv, rv3d.viewinv);
 
-       return ED_view3d_draw_offscreen_imbuf(scene, &v3d, &ar, width, height, 
flag, err_out);
+       return ED_view3d_draw_offscreen_imbuf(scene, &v3d, &ar, width, height, 
flag, draw_background, err_out);
 
        // seq_view3d_cb(scene, cfra, render_size, seqrectx, seqrecty);
 }

Modified: trunk/blender/source/blender/windowmanager/intern/wm_files.c
===================================================================
--- trunk/blender/source/blender/windowmanager/intern/wm_files.c        
2012-03-07 17:36:38 UTC (rev 44710)
+++ trunk/blender/source/blender/windowmanager/intern/wm_files.c        
2012-03-07 17:45:40 UTC (rev 44711)
@@ -676,7 +676,7 @@
        /* gets scaled to BLEN_THUMB_SIZE */
        ibuf= ED_view3d_draw_offscreen_imbuf_simple(scene, scene->camera,
                                                    BLEN_THUMB_SIZE * 2, 
BLEN_THUMB_SIZE * 2,
-                                                   IB_rect, OB_SOLID, err_out);
+                                                   IB_rect, OB_SOLID, FALSE, 
err_out);
 
        if(ibuf) {              
                float aspect= (scene->r.xsch*scene->r.xasp) / 
(scene->r.ysch*scene->r.yasp);

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to