External render engines can now render previews as well, disabled by
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Sun, 28 Mar 2010 13:48:11 +0000 (13:48 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Sun, 28 Mar 2010 13:48:11 +0000 (13:48 +0000)
default, set RenderEngine property bl_preview = True to enable it.

source/blender/editors/render/render_preview.c
source/blender/makesrna/intern/rna_render.c
source/blender/render/extern/include/RE_pipeline.h
source/blender/render/intern/source/envmap.c
source/blender/render/intern/source/pipeline.c
source/blender/render/intern/source/sss.c

index 13f8b07c405e03836e333f824d38c3e6ef878625..1a9e70518bc7d68e7a272ce8f3823c6cedf07b89 100644 (file)
@@ -299,6 +299,7 @@ static Scene *preview_prepare_scene(Scene *scene, ID *id, int id_type, ShaderPre
                        sce->r.alphamode= R_ADDSKY;
 
                sce->r.cfra= scene->r.cfra;
+               strcpy(sce->r.engine, scene->r.engine);
                
                if(id_type==ID_MA) {
                        Material *mat= (Material *)id;
@@ -780,7 +781,7 @@ void BIF_view3d_previewrender(Scene *scene, ScrArea *sa)
                /* OK, can we enter render code? */
                if(ri->status==(PR_DISPRECT|PR_DBASE|PR_PROJECTED|PR_ROTATED)) {
                        //printf("curtile %d tottile %d\n", ri->curtile, ri->tottile);
-                       RE_TileProcessor(ri->re, ri->curtile, 0);
+                       RE_TileProcessor(ri->re); //, ri->curtile, 0);
        
                        if(ri->rect==NULL)
                                ri->rect= MEM_mallocN(sizeof(int)*ri->pr_rectx*ri->pr_recty, "preview view3d rect");
@@ -915,7 +916,9 @@ static void shader_preview_render(ShaderPreview *sp, ID *id, int split, int firs
        else sizex= sp->sizex;
 
        /* allocates or re-uses render result */
-       RE_InitState(re, NULL, &sce->r, NULL, sizex, sp->sizey, NULL);
+       sce->r.xsch= sizex;
+       sce->r.ysch= sp->sizey;
+       sce->r.size= 100;
 
        /* callbacs are cleared on GetRender() */
        if(sp->pr_method==PR_BUTS_RENDER) {
@@ -928,10 +931,7 @@ static void shader_preview_render(ShaderPreview *sp, ID *id, int split, int firs
                ((Camera *)sce->camera->data)->lens *= (float)sp->sizey/(float)sizex;
 
        /* entire cycle for render engine */
-       RE_SetCamera(re, sce->camera);
-       RE_Database_FromScene(re, sce, sce->lay, 1);
-       RE_TileProcessor(re, 0, 1);     // actual render engine
-       RE_Database_Free(re);
+       RE_PreviewRender(re, sce);
 
        ((Camera *)sce->camera->data)->lens= oldlens;
 
index 710a22ba17a4c430861e8dfc87757b932f70e573..28d309c2d375817a9655faff9638be09d9da6305 100644 (file)
@@ -279,6 +279,10 @@ static void rna_def_render_engine(BlenderRNA *brna)
        RNA_def_property_string_sdna(prop, NULL, "type->name");
        RNA_def_property_flag(prop, PROP_REGISTER);
 
+       prop= RNA_def_property(srna, "bl_preview", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "type->flag", RE_DO_PREVIEW);
+       RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
+
        RNA_define_verify_sdna(1);
 }
 
index 2a653724051744a43d90b30a406b27190ad1d0c9..9373b3e20c91e7b9bb16677034f5595064a4deba 100644 (file)
@@ -202,12 +202,15 @@ void RE_set_max_threads(int threads);
 void RE_init_threadcount(Render *re);
 
 /* the main processor, assumes all was set OK! */
-void RE_TileProcessor(struct Render *re, int firsttile, int threaded);
+void RE_TileProcessor(struct Render *re);
 
 /* only RE_NewRender() needed, main Blender render calls */
 void RE_BlenderFrame(struct Render *re, struct Scene *scene, struct SceneRenderLayer *srl, unsigned int lay, int frame);
 void RE_BlenderAnim(struct Render *re, struct Scene *scene, unsigned int lay, int sfra, int efra, int tfra, struct ReportList *reports);
 
+/* main preview render call */
+void RE_PreviewRender(struct Render *re, struct Scene *scene);
+
 void RE_ReadRenderResult(struct Scene *scene, struct Scene *scenode);
 void RE_WriteRenderResult(RenderResult *rr, char *filename, int compress);
 struct RenderResult *RE_MultilayerConvert(void *exrhandle, int rectx, int recty);
@@ -252,6 +255,7 @@ struct Scene *RE_GetScene(struct Render *re);
 
 #define RE_INTERNAL            1
 #define RE_GAME                        2
+#define RE_DO_PREVIEW  4
 
 extern ListBase R_engines;
 
index a3d6eddb192322f01273c8e40ec3187a5bbef6cb..1a34868b9fdb29d799a370199bb3aa6557fd5951 100644 (file)
@@ -447,7 +447,7 @@ static void render_envmap(Render *re, EnvMap *env)
                env_set_imats(envre);
                                
                if(re->test_break(re->tbh)==0) {
-                       RE_TileProcessor(envre, 0, 0);
+                       RE_TileProcessor(envre);
                }
                
                /* rotate back */
index e814a6b1b4559f95d156ef822285512d1fb30270..f2b58c5dc0feda711f20d24738197bd9b1ddba2b 100644 (file)
@@ -1456,61 +1456,6 @@ static void *do_part_thread(void *pa_v)
        return NULL;
 }
 
-/* returns with render result filled, not threaded, used for preview now only */
-static void render_tile_processor(Render *re, int firsttile)
-{
-       RenderPart *pa;
-       
-       if(re->test_break(re->tbh))
-               return;
-
-       BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
-
-       /* hrmf... exception, this is used for preview render, re-entrant, so render result has to be re-used */
-       if(re->result==NULL || re->result->layers.first==NULL) {
-               if(re->result) RE_FreeRenderResult(re->result);
-               re->result= new_render_result(re, &re->disprect, 0, RR_USEMEM);
-       }
-
-       BLI_rw_mutex_unlock(&re->resultmutex);
-       
-       re->stats_draw(re->sdh, &re->i);
-       if(re->result==NULL)
-               return;
-       
-       initparts(re);
-
-       /* assuming no new data gets added to dbase... */
-       R= *re;
-       
-       for(pa= re->parts.first; pa; pa= pa->next) {
-               if(firsttile) {
-                       re->i.partsdone++;      /* was reset in initparts */
-                       firsttile--;
-               }
-               else {
-                       do_part_thread(pa);
-                       
-                       if(pa->result) {
-                               if(!re->test_break(re->tbh)) {
-                                       if(render_display_draw_enabled(re))
-                                               re->display_draw(re->ddh, pa->result, NULL);
-                                       
-                                       re->i.partsdone++;
-                                       re->stats_draw(re->sdh, &re->i);
-                               }
-                               RE_FreeRenderResult(pa->result);
-                               pa->result= NULL;
-                       }               
-                       if(re->test_break(re->tbh))
-                               break;
-               }
-       }
-
-       freeparts(re);
-}
-
 /* calculus for how much 1 pixel rendered should rotate the 3d geometry */
 /* is not that simple, needs to be corrected for errors of larger viewplane sizes */
 /* called in initrender.c, initparts() and convertblender.c, for speedvectors */
@@ -1784,43 +1729,20 @@ static void threaded_tile_processor(Render *re)
 }
 
 /* currently only called by preview renders and envmap */
-void RE_TileProcessor(Render *re, int firsttile, int threaded)
+void RE_TileProcessor(Render *re)
 {
-       /* the partsdone variable has to be reset to firsttile, to survive esc before it was set to zero */
-       
-       re->i.partsdone= firsttile;
-
-       if(!re->sss_points)
-               re->i.starttime= PIL_check_seconds_timer();
-
-       if(threaded)
-               threaded_tile_processor(re);
-       else
-               render_tile_processor(re, firsttile);
-               
-       if(!re->sss_points)
-               re->i.lastframetime= PIL_check_seconds_timer()- re->i.starttime;
-       re->stats_draw(re->sdh, &re->i);
+       threaded_tile_processor(re);
 }
 
-
 /* ************  This part uses API, for rendering Blender scenes ********** */
 
-static void external_render_3d(Render *re, RenderEngineType *type);
+static int external_render_3d(Render *re);
 
 static void do_render_3d(Render *re)
 {
-       RenderEngineType *type;
-
        /* try external */
-       for(type=R_engines.first; type; type=type->next)
-               if(strcmp(type->idname, re->r.engine) == 0)
-                       break;
-
-       if(type && type->render) {
-               external_render_3d(re, type);
+       if(external_render_3d(re))
                return;
-       }
 
        /* internal */
        
@@ -2988,6 +2910,23 @@ void RE_BlenderAnim(Render *re, Scene *scene, unsigned int lay, int sfra, int ef
        G.rendering= 0;
 }
 
+void RE_PreviewRender(Render *re, Scene *sce)
+{
+       int winx, winy;
+
+       winx= (sce->r.size*sce->r.xsch)/100;
+       winy= (sce->r.size*sce->r.ysch)/100;
+
+       RE_InitState(re, NULL, &sce->r, NULL, winx, winy, NULL);
+
+       re->scene = sce;
+       re->lay = sce->lay;
+
+       RE_SetCamera(re, sce->camera);
+
+       do_render_3d(re);
+}
+
 /* note; repeated win/disprect calc... solve that nicer, also in compo */
 
 /* only the temp file! */
@@ -3193,10 +3132,20 @@ void RE_result_load_from_file(RenderResult *result, ReportList *reports, char *f
        }
 }
 
-static void external_render_3d(Render *re, RenderEngineType *type)
+static int external_render_3d(Render *re)
 {
+       RenderEngineType *type;
        RenderEngine engine;
 
+       for(type=R_engines.first; type; type=type->next)
+               if(strcmp(type->idname, re->r.engine) == 0)
+                       break;
+
+       if(!(type && type->render))
+               return 0;
+       if((re->r.scemode & R_PREVIEWBUTS) && !(type->flag & RE_DO_PREVIEW))
+               return 0;
+
        BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
        if(re->result==NULL || !(re->r.scemode & R_PREVIEWBUTS)) {
                RE_FreeRenderResult(re->result);
@@ -3209,7 +3158,7 @@ static void external_render_3d(Render *re, RenderEngineType *type)
        BLI_rw_mutex_unlock(&re->resultmutex);
        
        if(re->result==NULL)
-               return;
+               return 1;
 
        /* external */
        memset(&engine, 0, sizeof(engine));
@@ -3237,5 +3186,7 @@ static void external_render_3d(Render *re, RenderEngineType *type)
                read_render_result(re, 0);
        }
        BLI_rw_mutex_unlock(&re->resultmutex);
+
+       return 1;
 }
 
index 6bc1153f8b3bfd6f54bdf6c37d84a0278ff731d1..836a60ef4f9fe02fb681fa854c0597c964440c74 100644 (file)
@@ -878,7 +878,7 @@ static void sss_create_tree_mat(Render *re, Material *mat)
                re->result= NULL;
        BLI_rw_mutex_unlock(&re->resultmutex);
 
-       RE_TileProcessor(re, 0, 1);
+       RE_TileProcessor(re);
        
        BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
        if(!(re->r.scemode & R_PREVIEWBUTS)) {