~ubuntu-branches/ubuntu/trusty/blender/trusty-proposed

« back to all changes in this revision

Viewing changes to source/blender/editors/render/render_preview.c

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2013-08-14 10:43:49 UTC
  • mfrom: (14.2.19 sid)
  • Revision ID: package-import@ubuntu.com-20130814104349-t1d5mtwkphp12dyj
Tags: 2.68a-3
* Upload to unstable
* debian/: python3.3 Depends simplified
  - debian/control: python3.3 Depends dropped
    for blender-data package
  - 0001-blender_thumbnailer.patch refreshed
* debian/control: libavcodec b-dep versioning dropped

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
#endif   
44
44
#include "MEM_guardedalloc.h"
45
45
 
46
 
#include "BLO_readfile.h" 
47
 
 
48
46
#include "BLI_math.h"
49
47
#include "BLI_blenlib.h"
50
48
#include "BLI_threads.h"
51
49
#include "BLI_utildefines.h"
52
50
 
 
51
#include "BLO_readfile.h"
 
52
 
53
53
#include "DNA_world_types.h"
54
54
#include "DNA_camera_types.h"
55
55
#include "DNA_material_types.h"
93
93
 
94
94
#include "RE_pipeline.h"
95
95
 
96
 
 
97
96
#include "WM_api.h"
98
97
#include "WM_types.h"
99
98
 
110
109
        static const int flags = IB_rect | IB_multilayer | IB_metadata;
111
110
 
112
111
        char path[FILE_MAX];
113
 
        char *folder;
 
112
        const char *folder;
114
113
 
115
114
        if (!(brush->icon_imbuf)) {
116
115
                if (brush->flag & BRUSH_CUSTOM_ICON) {
188
187
 
189
188
/* *************************** Preview for buttons *********************** */
190
189
 
191
 
static Main *pr_main = NULL;
192
 
static Main *pr_main_cycles = NULL;
 
190
static Main *G_pr_main = NULL;
 
191
static Main *G_pr_main_cycles = NULL;
193
192
 
194
193
#ifndef WITH_HEADLESS
195
 
static Main *load_main_from_memory(char *blend, int blend_size)
 
194
static Main *load_main_from_memory(const void *blend, int blend_size)
196
195
{
197
196
        const int fileflags = G.fileflags;
198
197
        Main *bmain = NULL;
214
213
void ED_preview_init_dbase(void)
215
214
{
216
215
#ifndef WITH_HEADLESS
217
 
        pr_main = load_main_from_memory(datatoc_preview_blend, datatoc_preview_blend_size);
218
 
        pr_main_cycles = load_main_from_memory(datatoc_preview_cycles_blend, datatoc_preview_cycles_blend_size);
 
216
        G_pr_main = load_main_from_memory(datatoc_preview_blend, datatoc_preview_blend_size);
 
217
        G_pr_main_cycles = load_main_from_memory(datatoc_preview_cycles_blend, datatoc_preview_cycles_blend_size);
219
218
#endif
220
219
}
221
220
 
222
221
void ED_preview_free_dbase(void)
223
222
{
224
 
        if (pr_main)
225
 
                free_main(pr_main);
 
223
        if (G_pr_main)
 
224
                free_main(G_pr_main);
226
225
 
227
 
        if (pr_main_cycles)
228
 
                free_main(pr_main_cycles);
 
226
        if (G_pr_main_cycles)
 
227
                free_main(G_pr_main_cycles);
229
228
}
230
229
 
231
230
static int preview_mat_has_sss(Material *mat, bNodeTree *ntree)
274
273
        if (sce) {
275
274
                
276
275
                /* this flag tells render to not execute depsgraph or ipos etc */
277
 
                sce->r.scemode |= R_PREVIEWBUTS;
 
276
                sce->r.scemode |= R_BUTS_PREVIEW;
278
277
                /* set world always back, is used now */
279
278
                sce->world = pr_main->world.first;
280
279
                /* now: exposure copy */
304
303
                        sce->r.alphamode = R_ADDSKY;
305
304
 
306
305
                sce->r.cfra = scene->r.cfra;
307
 
                BLI_strncpy(sce->r.engine, scene->r.engine, sizeof(sce->r.engine));
 
306
 
 
307
                if (id_type == ID_TE && sp->pr_method == PR_ICON_RENDER) {
 
308
                        /* force blender internal for texture icons render,
 
309
                         * seems commonly used render engines does not support
 
310
                         * such kind of rendering
 
311
                         */
 
312
                        BLI_strncpy(sce->r.engine, "BLENDER_RENDER", sizeof(sce->r.engine));
 
313
                }
 
314
                else {
 
315
                        BLI_strncpy(sce->r.engine, scene->r.engine, sizeof(sce->r.engine));
 
316
                }
308
317
                
309
318
                if (id_type == ID_MA) {
310
319
                        Material *mat = NULL, *origmat = (Material *)id;
372
381
                                        }
373
382
                                        else {
374
383
                                                sce->lay = 1 << MA_SPHERE_A;
 
384
 
 
385
                                                /* same as above, use current scene world to light sphere */
 
386
                                                if (BKE_scene_use_new_shading_nodes(scene))
 
387
                                                        sce->world = scene->world;
375
388
                                        }
376
389
                                }
377
390
                                else {
378
391
                                        sce->lay = 1 << mat->pr_type;
379
392
                                        if (mat->nodetree && sp->pr_method == PR_NODE_RENDER) {
380
393
                                                /* two previews, they get copied by wmJob */
381
 
                                                ntreeInitPreview(mat->nodetree, sp->sizex, sp->sizey);
382
 
                                                ntreeInitPreview(origmat->nodetree, sp->sizex, sp->sizey);
 
394
                                                BKE_node_preview_init_tree(mat->nodetree, sp->sizex, sp->sizey, TRUE);
 
395
                                                BKE_node_preview_init_tree(origmat->nodetree, sp->sizex, sp->sizey, TRUE);
383
396
                                        }
384
397
                                }
385
398
                        }
431
444
 
432
445
                                                /* show alpha in this case */
433
446
                                                if (tex == NULL || (tex->flag & TEX_PRV_ALPHA)) {
434
 
                                                        if (!(tex && tex->type == TEX_IMAGE && (tex->imaflag & (TEX_USEALPHA|TEX_CALCALPHA)) == 0)) {
 
447
                                                        if (!(tex && tex->type == TEX_IMAGE && (tex->imaflag & (TEX_USEALPHA | TEX_CALCALPHA)) == 0)) {
435
448
                                                                mat->mtex[0]->mapto |= MAP_ALPHA;
436
449
                                                                mat->alpha = 0.0f;
437
450
                                                        }
442
455
 
443
456
                        if (tex && tex->nodetree && sp->pr_method == PR_NODE_RENDER) {
444
457
                                /* two previews, they get copied by wmJob */
445
 
                                ntreeInitPreview(origtex->nodetree, sp->sizex, sp->sizey);
446
 
                                ntreeInitPreview(tex->nodetree, sp->sizex, sp->sizey);
 
458
                                BKE_node_preview_init_tree(origtex->nodetree, sp->sizex, sp->sizey, TRUE);
 
459
                                BKE_node_preview_init_tree(tex->nodetree, sp->sizex, sp->sizey, TRUE);
447
460
                        }
448
461
                }
449
462
                else if (id_type == ID_LA) {
479
492
 
480
493
                        if (la && la->nodetree && sp->pr_method == PR_NODE_RENDER) {
481
494
                                /* two previews, they get copied by wmJob */
482
 
                                ntreeInitPreview(origla->nodetree, sp->sizex, sp->sizey);
483
 
                                ntreeInitPreview(la->nodetree, sp->sizex, sp->sizey);
 
495
                                BKE_node_preview_init_tree(origla->nodetree, sp->sizex, sp->sizey, TRUE);
 
496
                                BKE_node_preview_init_tree(la->nodetree, sp->sizex, sp->sizey, TRUE);
484
497
                        }
485
498
                }
486
499
                else if (id_type == ID_WO) {
497
510
 
498
511
                        if (wrld && wrld->nodetree && sp->pr_method == PR_NODE_RENDER) {
499
512
                                /* two previews, they get copied by wmJob */
500
 
                                ntreeInitPreview(wrld->nodetree, sp->sizex, sp->sizey);
501
 
                                ntreeInitPreview(origwrld->nodetree, sp->sizex, sp->sizey);
 
513
                                BKE_node_preview_init_tree(wrld->nodetree, sp->sizex, sp->sizey, TRUE);
 
514
                                BKE_node_preview_init_tree(origwrld->nodetree, sp->sizex, sp->sizey, TRUE);
502
515
                        }
503
516
                }
504
517
                
518
531
        int offx = 0;
519
532
        int newx = BLI_rcti_size_x(rect);
520
533
        int newy = BLI_rcti_size_y(rect);
 
534
        int ok = 0;
521
535
 
522
536
        if (!split || first) sprintf(name, "Preview %p", (void *)sa);
523
537
        else sprintf(name, "SecondPreview %p", (void *)sa);
536
550
        /* test if something rendered ok */
537
551
        re = RE_GetRender(name);
538
552
        RE_AcquireResultImage(re, &rres);
539
 
        RE_ReleaseResultImage(re);
540
553
 
541
554
        if (rres.rectf) {
542
555
                
550
563
                                float fx = rect->xmin + offx;
551
564
                                float fy = rect->ymin;
552
565
                                
553
 
                                RE_ResultGet32(re, (unsigned int *)rect_byte);
 
566
                                RE_AcquiredResultGet32(re, &rres, (unsigned int *)rect_byte);
554
567
                                glaDrawPixelsSafe(fx, fy, rres.rectx, rres.recty, rres.rectx, GL_RGBA, GL_UNSIGNED_BYTE, rect_byte);
555
568
                                
556
569
                                MEM_freeN(rect_byte);
557
570
                                
558
 
                                return 1;
 
571
                                ok = 1;
559
572
                        }
560
573
                }
561
574
        }
562
575
 
563
 
        return 0;
 
576
        RE_ReleaseResultImage(re);
 
577
 
 
578
        return ok;
564
579
}
565
580
 
566
581
void ED_preview_draw(const bContext *C, void *idp, void *parentp, void *slotp, rcti *rect)
567
582
{
568
583
        if (idp) {
 
584
                wmWindowManager *wm = CTX_wm_manager(C);
569
585
                ScrArea *sa = CTX_wm_area(C);
570
586
                ID *id = (ID *)idp;
571
587
                ID *parent = (ID *)parentp;
591
607
                if (ok)
592
608
                        *rect = newrect;
593
609
 
594
 
                /* check for spacetype... */
595
 
                if (sbuts->spacetype == SPACE_BUTS && sbuts->preview) {
 
610
                /* start a new preview render job if signalled through sbuts->preview,
 
611
                 * or if no render result was found and no preview render job is running */
 
612
                if ((sbuts->spacetype == SPACE_BUTS && sbuts->preview) ||
 
613
                    (!ok && !WM_jobs_test(wm, sa, WM_JOB_TYPE_RENDER_PREVIEW)))
 
614
                {
596
615
                        sbuts->preview = 0;
597
 
                        ok = 0;
598
 
                }
599
 
        
600
 
                if (ok == 0) {
601
616
                        ED_preview_shader_job(C, sa, id, parent, slot, newx, newy, PR_BUTS_RENDER);
602
617
                }
603
618
        }
671
686
                if (first) sizex = sp->sizex / 2;
672
687
                else sizex = sp->sizex - sp->sizex / 2;
673
688
        }
674
 
        else sizex = sp->sizex;
675
 
        
 
689
        else {
 
690
                sizex = sp->sizex;
 
691
        }
 
692
 
676
693
        /* we have to set preview variables first */
677
694
        sce = preview_get_scene(pr_main);
678
695
        if (sce) {
1014
1031
{
1015
1032
        IconPreview *ip = (IconPreview *)customdata;
1016
1033
        IconPreviewSize *cur_size = ip->sizes.first;
 
1034
        int use_new_shading = BKE_scene_use_new_shading_nodes(ip->scene);
1017
1035
 
1018
1036
        while (cur_size) {
1019
1037
                ShaderPreview *sp = MEM_callocN(sizeof(ShaderPreview), "Icon ShaderPreview");
1026
1044
                sp->pr_method = PR_ICON_RENDER;
1027
1045
                sp->pr_rect = cur_size->rect;
1028
1046
                sp->id = ip->id;
1029
 
                sp->pr_main = pr_main;
 
1047
 
 
1048
                if (use_new_shading) {
 
1049
                        /* texture icon rendering is hardcoded to use BI,
 
1050
                         * so don't even think of using cycle's bmain for
 
1051
                         * texture icons
 
1052
                         */
 
1053
                        if (GS(ip->id->name) != ID_TE)
 
1054
                                sp->pr_main = G_pr_main_cycles;
 
1055
                        else
 
1056
                                sp->pr_main = G_pr_main;
 
1057
                }
 
1058
                else {
 
1059
                        sp->pr_main = G_pr_main;
 
1060
                }
1030
1061
 
1031
1062
                common_preview_startjob(sp, stop, do_update, progress);
1032
1063
                shader_preview_free(sp);
1129
1160
        /* hardcoded preview .blend for cycles/internal, this should be solved
1130
1161
         * once with custom preview .blend path for external engines */
1131
1162
        if (BKE_scene_use_new_shading_nodes(scene))
1132
 
                sp->pr_main = pr_main_cycles;
 
1163
                sp->pr_main = G_pr_main_cycles;
1133
1164
        else
1134
 
                sp->pr_main = pr_main;
 
1165
                sp->pr_main = G_pr_main;
1135
1166
 
1136
1167
        if (ob && ob->totcol) copy_v4_v4(sp->col, ob->col);
1137
1168
        else sp->col[0] = sp->col[1] = sp->col[2] = sp->col[3] = 1.0f;
1149
1180
        wmWindowManager *wm = CTX_wm_manager(C);
1150
1181
        if (wm)
1151
1182
                WM_jobs_kill(wm, NULL, common_preview_startjob);
 
1183
        
 
1184
        ED_viewport_render_kill_jobs(C, false);
1152
1185
}
1153
1186