Cycles: RenderEngine api code tweaks, also ensuring it's backwards compatible.
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 2 Nov 2011 15:15:45 +0000 (15:15 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 2 Nov 2011 15:15:45 +0000 (15:15 +0000)
intern/cycles/blender/addon/__init__.py
source/blender/editors/render/render_update.c
source/blender/makesrna/intern/rna_render.c
source/blender/render/extern/include/RE_engine.h
source/blender/render/intern/include/render_types.h
source/blender/render/intern/source/external_engine.c
source/blender/render/intern/source/pipeline.c
source/blender/windowmanager/intern/wm_draw.c

index 4a5b78300bf1f7d84135955d3284621453bd0f86..979e3e872d71c2b047f44a0cf4eeccfce436beb8 100644 (file)
@@ -54,7 +54,7 @@ class CyclesRender(bpy.types.RenderEngine):
         engine.create(self, data, scene)
         engine.update(self, data, scene)
 
-    def render(self):
+    def render(self, scene):
         engine.render(self)
 
     # preview render
index b6cf5be41e6951209b84e3e5ca0f774b65b088a1..72ea79fae7e41f60f9ef56a219fed403af085459 100644 (file)
@@ -88,12 +88,12 @@ void ED_render_engine_update_tagged(bContext *C, Main *bmain)
                                rv3d= ar->regiondata;
                                engine= rv3d->render_engine;
 
-                               if(engine && engine->do_update) {
+                               if(engine && (engine->flag & RE_ENGINE_DO_UPDATE)) {
                                        CTX_wm_screen_set(C, sc);
                                        CTX_wm_area_set(C, sa);
                                        CTX_wm_region_set(C, ar);
 
-                                       engine->do_update= 0;
+                                       engine->flag &= ~RE_ENGINE_DO_UPDATE;
                                        engine->type->view_update(engine, C);
                                }
                        }
@@ -134,7 +134,7 @@ void ED_render_engine_changed(Main *bmain)
        }
 }
 
-void tag_render_engines(Main *bmain)
+static void tag_render_engines(Main *bmain)
 {
        /* tag running render engines for update later on */
        bScreen *sc;
@@ -154,7 +154,7 @@ void tag_render_engines(Main *bmain)
                                
                                rv3d= ar->regiondata;
                                if(rv3d->render_engine)
-                                       rv3d->render_engine->do_update= 1;
+                                       rv3d->render_engine->flag |= RE_ENGINE_DO_UPDATE;
                        }
                }
        }
index da6cd02cfbc7196e304582805b4e51fc5048f0a0..ef9bf6a9e029f297c714eed1454f7592ada837c2 100644 (file)
 #include "BKE_context.h"
 #include "BKE_report.h"
 
+/* RenderEngine Callbacks */
+
 void engine_tag_redraw(RenderEngine *engine)
 {
-       engine->do_draw = 1;
+       engine->flag |= RE_ENGINE_DO_DRAW;
 }
 
 void engine_tag_update(RenderEngine *engine)
 {
-       engine->do_update = 1;
+       engine->flag |= RE_ENGINE_DO_UPDATE;
 }
 
-/* RenderEngine Callbacks */
-
 static void engine_update(RenderEngine *engine, Main *bmain, Scene *scene)
 {
        extern FunctionRNA rna_RenderEngine_update_func;
@@ -78,7 +78,7 @@ static void engine_update(RenderEngine *engine, Main *bmain, Scene *scene)
        RNA_parameter_list_free(&list);
 }
 
-static void engine_render(RenderEngine *engine)
+static void engine_render(RenderEngine *engine, struct Scene *scene)
 {
        extern FunctionRNA rna_RenderEngine_render_func;
        PointerRNA ptr;
@@ -89,6 +89,7 @@ static void engine_render(RenderEngine *engine)
        func= &rna_RenderEngine_render_func;
 
        RNA_parameter_list_create(&list, &ptr, func);
+       RNA_parameter_set_lookup(&list, "scene", &scene);
        engine->type->ext.call(NULL, &ptr, func, &list);
 
        RNA_parameter_list_free(&list);
@@ -314,41 +315,44 @@ static void rna_def_render_engine(BlenderRNA *brna)
        /* final render callbacks */
        func= RNA_def_function(srna, "update", NULL);
        RNA_def_function_ui_description(func, "Export scene data for render");
-       RNA_def_function_flag(func, FUNC_REGISTER);
+       RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
        RNA_def_pointer(func, "data", "BlendData", "", "");
        RNA_def_pointer(func, "scene", "Scene", "", "");
 
        func= RNA_def_function(srna, "render", NULL);
-       RNA_def_function_ui_description(func, "Execute render");
-       RNA_def_function_flag(func, FUNC_REGISTER);
+       RNA_def_function_ui_description(func, "Render scene into an image");
+       RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
+       RNA_def_pointer(func, "scene", "Scene", "", "");
 
        /* preview render callbacks */
        func= RNA_def_function(srna, "preview_update", NULL);
        RNA_def_function_ui_description(func, "Export scene data for preview render of the given datablock");
-       RNA_def_function_flag(func, FUNC_REGISTER);
+       RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
        RNA_def_pointer(func, "context", "Context", "", "");
        RNA_def_pointer(func, "id", "ID", "", "");
 
        func= RNA_def_function(srna, "preview_render", NULL);
        RNA_def_function_ui_description(func, "Execute preview render");
-       RNA_def_function_flag(func, FUNC_REGISTER);
+       RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
 
        /* viewport render callbacks */
        func= RNA_def_function(srna, "view_update", NULL);
        RNA_def_function_ui_description(func, "Update on data changes for viewport render");
-       RNA_def_function_flag(func, FUNC_REGISTER);
+       RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
        RNA_def_pointer(func, "context", "Context", "", "");
 
        func= RNA_def_function(srna, "view_draw", NULL);
        RNA_def_function_ui_description(func, "Draw viewport render");
-       RNA_def_function_flag(func, FUNC_REGISTER);
+       RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
        RNA_def_pointer(func, "context", "Context", "", "");
 
        /* tag for redraw */
        RNA_def_function(srna, "tag_redraw", "engine_tag_redraw");
+       RNA_def_function_ui_description(func, "Request redraw for viewport rendering");
 
        /* tag for update */
        RNA_def_function(srna, "tag_update", "engine_tag_update");
+       RNA_def_function_ui_description(func, "Request update call for viewport rendering");
 
        func= RNA_def_function(srna, "begin_result", "RE_engine_begin_result");
        prop= RNA_def_int(func, "x", 0, 0, INT_MAX, "X", "", 0, INT_MAX);
@@ -390,9 +394,16 @@ static void rna_def_render_engine(BlenderRNA *brna)
        prop= RNA_def_string(func, "message", "", 0, "Report Message", "");
        RNA_def_property_flag(prop, PROP_REQUIRED);
 
-       /* registration */
        RNA_define_verify_sdna(0);
 
+       prop= RNA_def_property(srna, "is_animation", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "flag", RE_ENGINE_ANIMATION);
+
+       prop= RNA_def_property(srna, "is_preview", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "flag", RE_ENGINE_PREVIEW);
+
+       /* registration */
+
        prop= RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE);
        RNA_def_property_string_sdna(prop, NULL, "type->idname");
        RNA_def_property_flag(prop, PROP_REGISTER|PROP_NEVER_CLAMP);
index bd93f1e63aeac40897c9cda5ba8afc0c967433d6..d8c78ef82a2f2f82fea7766474b4ffc4a0a1485e 100644 (file)
@@ -46,12 +46,19 @@ struct Scene;
 
 /* External Engine */
 
+/* RenderEngineType.flag */
 #define RE_INTERNAL                            1
 #define RE_GAME                                        2
 #define RE_USE_PREVIEW                 4
 #define RE_USE_POSTPROCESS             8
 #define RE_USE_SHADING_NODES   16
 
+/* RenderEngine.flag */
+#define RE_ENGINE_ANIMATION            1
+#define RE_ENGINE_PREVIEW              2
+#define RE_ENGINE_DO_DRAW              4
+#define RE_ENGINE_DO_UPDATE            8
+
 extern ListBase R_engines;
 
 typedef struct RenderEngineType {
@@ -63,7 +70,7 @@ typedef struct RenderEngineType {
        int flag;
 
        void (*update)(struct RenderEngine *engine, struct Main *bmain, struct Scene *scene);
-       void (*render)(struct RenderEngine *engine);
+       void (*render)(struct RenderEngine *engine, struct Scene *scene);
 
        void (*preview_update)(struct RenderEngine *engine, const struct bContext *context, struct ID *id);
        void (*preview_render)(struct RenderEngine *engine);
@@ -79,12 +86,11 @@ typedef struct RenderEngine {
        RenderEngineType *type;
        void *py_instance;
 
+       int flag;
+
        struct Render *re;
        ListBase fullresult;
        char *text;
-
-       int do_draw;
-       int do_update;
 } RenderEngine;
 
 RenderEngine *RE_engine_create(RenderEngineType *type);
index aa2dd29814e1ef43404ee967d965f6f350f384e3..ae4e55b9b883fbb8020eb046eec117b6175c5e69 100644 (file)
@@ -601,6 +601,7 @@ typedef struct LampRen {
 #define R_NEED_TANGENT 16
 #define R_BAKE_TRACE   32
 #define R_BAKING               64
+#define R_ANIMATION            128
 
 /* vlakren->flag (vlak = face in dutch) char!!! */
 #define R_SMOOTH               1
index f622405093b55e077b1d96db8bc4ebc0398c02c6..93e6983970828038f49ed6d0212baff2e78c0f96 100644 (file)
@@ -265,7 +265,8 @@ int RE_engine_render(Render *re, int do_all)
        /* verify if we can render */
        if(!type->render)
                return 0;
-       if((re->r.scemode & R_PREVIEWBUTS) && !(type->flag & RE_USE_PREVIEW))
+       if((re->r.scemode & R_PREVIEWBUTS) && !((type->flag & RE_USE_PREVIEW) ||
+               (type->preview_update && type->preview_render)))
                return 0;
        if(do_all && !(type->flag & RE_USE_POSTPROCESS))
                return 0;
@@ -287,16 +288,23 @@ int RE_engine_render(Render *re, int do_all)
        engine = RE_engine_create(type);
        engine->re= re;
 
+       if(re->flag & R_ANIMATION)
+               engine->flag |= RE_ENGINE_ANIMATION;
+       if(re->r.scemode & R_PREVIEWBUTS)
+               engine->flag |= RE_ENGINE_PREVIEW;
+
        if((re->r.scemode & (R_NO_FRAME_UPDATE|R_PREVIEWBUTS))==0)
                scene_update_for_newframe(re->main, re->scene, re->lay);
 
-       if(re->r.scemode & R_PREVIEWBUTS) {
+       if(type->preview_update && type->preview_render) {
                //type->preview_update(engine, scene, id);
                type->preview_render(engine);
        }
        else {
-               type->update(engine, re->main, re->scene);
-               type->render(engine);
+               if(type->update)
+                       type->update(engine, re->main, re->scene);
+               if(type->render)
+                       type->render(engine, re->scene);
        }
 
        free_render_result(&engine->fullresult, engine->fullresult.first);
index 6e61c930fd096f2911c750d819768672b836729b..8d72be1684cee4dd16627614400ab9f8d668b32b 100644 (file)
@@ -405,7 +405,7 @@ static const char *get_pass_name(int passtype, int channel)
        return "Unknown";
 }
 
-static int passtype_from_name(char *str)
+static int passtype_from_name(const char *str)
 {
        
        if(strcmp(str, "Combined")==0)
@@ -889,39 +889,18 @@ static void *ml_addlayer_cb(void *base, char *str)
 {
        RenderResult *rr= base;
        RenderLayer *rl;
-
-       /* don't add if layer already exists */
-       for(rl=rr->layers.first; rl; rl=rl->next)
-               if(strcmp(rl->name, str) == 0)
-                       return rl;
        
-       /* add render layer */
        rl= MEM_callocN(sizeof(RenderLayer), "new render layer");
        BLI_addtail(&rr->layers, rl);
        
        BLI_strncpy(rl->name, str, EXR_LAY_MAXNAME);
-       rl->rectx = rr->rectx;
-       rl->recty = rr->recty;
-
        return rl;
 }
-static void ml_addpass_cb(void *base, void *lay, char *str, float *rect, int totchan, char *chan_id)
+static void ml_addpass_cb(void *UNUSED(base), void *lay, char *str, float *rect, int totchan, char *chan_id)
 {
-       RenderResult *rr= base;
        RenderLayer *rl= lay;   
-       RenderPass *rpass;
+       RenderPass *rpass= MEM_callocN(sizeof(RenderPass), "loaded pass");
        int a;
-
-       /* don't add if pass already exists */
-       for(rpass=rl->passes.first; rpass; rpass=rpass->next) {
-               if(strcmp(rpass->name, str) == 0) {
-                       MEM_freeN(rect);
-                       return;
-               }
-       }
-       
-       /* add render pass */
-       rpass = MEM_callocN(sizeof(RenderPass), "loaded pass");
        
        BLI_addtail(&rl->passes, rpass);
        rpass->channels= totchan;
@@ -935,8 +914,6 @@ static void ml_addpass_cb(void *base, void *lay, char *str, float *rect, int tot
        for(a=0; a<totchan; a++)
                rpass->chan_id[a]= chan_id[a];
        
-       rpass->rectx = rr->rectx;
-       rpass->recty = rr->recty;
        rpass->rect= rect;
 }
 
@@ -944,12 +921,24 @@ static void ml_addpass_cb(void *base, void *lay, char *str, float *rect, int tot
 RenderResult *RE_MultilayerConvert(void *exrhandle, int rectx, int recty)
 {
        RenderResult *rr= MEM_callocN(sizeof(RenderResult), "loaded render result");
+       RenderLayer *rl;
+       RenderPass *rpass;
        
        rr->rectx= rectx;
        rr->recty= recty;
        
        IMB_exr_multilayer_convert(exrhandle, rr, ml_addlayer_cb, ml_addpass_cb);
 
+       for(rl=rr->layers.first; rl; rl=rl->next) {
+               rl->rectx= rectx;
+               rl->recty= recty;
+
+               for(rpass=rl->passes.first; rpass; rpass=rpass->next) {
+                       rpass->rectx= rectx;
+                       rpass->recty= recty;
+               }
+       }
+       
        return rr;
 }
 
@@ -3096,6 +3085,8 @@ void RE_BlenderAnim(Render *re, Main *bmain, Scene *scene, Object *camera_overri
        /* is also set by caller renderwin.c */
        G.rendering= 1;
 
+       re->flag |= R_ANIMATION;
+
        if(BKE_imtype_is_movie(scene->r.imtype))
                if(!mh->start_movie(scene, &re->r, re->rectx, re->recty, re->reports))
                        G.afbreek= 1;
@@ -3204,6 +3195,8 @@ void RE_BlenderAnim(Render *re, Main *bmain, Scene *scene, Object *camera_overri
 
        scene->r.cfra= cfrao;
 
+       re->flag &= ~R_ANIMATION;
+
        /* UGLY WARNING */
        G.rendering= 0;
 }
@@ -3332,22 +3325,10 @@ void RE_layer_load_from_file(RenderLayer *layer, ReportList *reports, const char
 
 void RE_result_load_from_file(RenderResult *result, ReportList *reports, const char *filename)
 {
-       /* optionally also add layers/passes that were in the file but not setup
-          for rendering, useful for external render engines or network render */
-       void *exrhandle= IMB_exr_get_handle();
-       int rectx, recty;
-
-       if(IMB_exr_begin_read(exrhandle, filename, &rectx, &recty))
-               IMB_exr_multilayer_convert(exrhandle, result, ml_addlayer_cb, ml_addpass_cb);
-
-       IMB_exr_close(exrhandle);
-       
-#if 0
-       if(!read_render_result_from_file(filename, result, 1)) {
+       if(!read_render_result_from_file(filename, result)) {
                BKE_reportf(reports, RPT_ERROR, "RE_result_rect_from_file: failed to load '%s'\n", filename);
                return;
        }
-#endif
 }
 
 const float default_envmap_layout[] = { 0,0, 1,0, 2,0, 0,1, 1,1, 2,1 };
index a491f8a6010029771be539db95f89be052a32c73..389049d9e598fe384eacd2b371004ea609a3d757 100644 (file)
@@ -121,9 +121,9 @@ static void wm_region_test_render_do_draw(ScrArea *sa, ARegion *ar)
                RegionView3D *rv3d = ar->regiondata;
                RenderEngine *engine = (rv3d)? rv3d->render_engine: NULL;
 
-               if(engine && engine->do_draw) {
+               if(engine && (engine->flag & RE_ENGINE_DO_DRAW)) {
                        ar->do_draw = 1;
-                       engine->do_draw = 0;
+                       engine->flag &= ~RE_ENGINE_DO_DRAW;
                }
        }
 }