Render API: add update_progress() function to update progress bar progress from
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Sat, 22 Oct 2011 17:01:54 +0000 (17:01 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Sat, 22 Oct 2011 17:01:54 +0000 (17:01 +0000)
external render engines.

Also refactoring to move some render engine registration stuff out of RNA and
into render module.

source/blender/makesrna/intern/rna_render.c
source/blender/render/CMakeLists.txt
source/blender/render/SConscript
source/blender/render/extern/include/RE_engine.h
source/blender/render/intern/source/external_engine.c
source/blenderplayer/bad_level_call_stubs/stubs.c

index aeff9240b274c43f2ae6e9934011e8ac51873363..f9b110912ad728c1da278ee07195326c42490039 100644 (file)
 
 /* RenderEngine */
 
-static RenderEngineType internal_render_type = {
-       NULL, NULL, "BLENDER_RENDER", "Blender Render", RE_INTERNAL, NULL, {NULL, NULL, NULL, NULL}};
-#ifdef WITH_GAMEENGINE
-static RenderEngineType internal_game_type = {
-       NULL, NULL, "BLENDER_GAME", "Blender Game", RE_INTERNAL|RE_GAME, NULL, {NULL, NULL, NULL, NULL}};
-#endif
-
-ListBase R_engines = {NULL, NULL};
-
-void RE_engines_init(void)
-{
-       BLI_addtail(&R_engines, &internal_render_type);
-#ifdef WITH_GAMEENGINE
-       BLI_addtail(&R_engines, &internal_game_type);
-#endif
-}
-
-void RE_engines_exit(void)
-{
-       RenderEngineType *type, *next;
-
-       for(type=R_engines.first; type; type=next) {
-               next= type->next;
-
-               BLI_remlink(&R_engines, type);
-
-               if(!(type->flag & RE_INTERNAL)) {
-                       if(type->ext.free)
-                               type->ext.free(type->ext.data);
-
-                       MEM_freeN(type);
-               }
-       }
-}
-
 static void engine_render(RenderEngine *engine, struct Scene *scene)
 {
        extern FunctionRNA rna_RenderEngine_render_func;
@@ -96,7 +61,7 @@ static void engine_render(RenderEngine *engine, struct Scene *scene)
        FunctionRNA *func;
 
        RNA_pointer_create(NULL, engine->type->ext.srna, engine, &ptr);
-       func= &rna_RenderEngine_render_func; /* RNA_struct_find_function(&ptr, "render"); */
+       func= &rna_RenderEngine_render_func;
 
        RNA_parameter_list_create(&list, &ptr, func);
        RNA_parameter_set_lookup(&list, "scene", &scene);
@@ -105,6 +70,8 @@ static void engine_render(RenderEngine *engine, struct Scene *scene)
        RNA_parameter_list_free(&list);
 }
 
+/* RenderEngine registration */
+
 static void rna_RenderEngine_unregister(Main *UNUSED(bmain), StructRNA *type)
 {
        RenderEngineType *et= RNA_struct_blender_type_get(type);
@@ -148,7 +115,7 @@ static StructRNA *rna_RenderEngine_register(Main *bmain, ReportList *reports, vo
        }
        
        /* create a new engine type */
-       et= MEM_callocN(sizeof(RenderEngineType), "python buttons engine");
+       et= MEM_callocN(sizeof(RenderEngineType), "python render engine");
        memcpy(et, &dummyet, sizeof(dummyet));
 
        et->ext.srna= RNA_def_struct(&BLENDER_RNA, et->idname, "RenderEngine"); 
@@ -276,6 +243,10 @@ static void rna_def_render_engine(BlenderRNA *brna)
        prop= RNA_def_string(func, "info", "", 0, "Info", "");
        RNA_def_property_flag(prop, PROP_REQUIRED);
 
+       func= RNA_def_function(srna, "update_progress", "RE_engine_update_progress");
+       prop= RNA_def_float(func, "progress", 0, 0.0f, 1.0f, "", "Percentage of render that's done", 0.0f, 1.0f);
+       RNA_def_property_flag(prop, PROP_REQUIRED);
+
        func= RNA_def_function(srna, "report", "RE_engine_report");
        prop= RNA_def_enum_flag(func, "type", wm_report_items, 0, "Type", "");
        RNA_def_property_flag(prop, PROP_REQUIRED);
@@ -294,11 +265,11 @@ static void rna_def_render_engine(BlenderRNA *brna)
        RNA_def_property_flag(prop, PROP_REGISTER);
 
        prop= RNA_def_property(srna, "bl_use_preview", PROP_BOOLEAN, PROP_NONE);
-       RNA_def_property_boolean_sdna(prop, NULL, "type->flag", RE_DO_PREVIEW);
+       RNA_def_property_boolean_sdna(prop, NULL, "type->flag", RE_USE_PREVIEW);
        RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
 
        prop= RNA_def_property(srna, "bl_use_postprocess", PROP_BOOLEAN, PROP_NONE);
-       RNA_def_property_boolean_negative_sdna(prop, NULL, "type->flag", RE_DO_ALL);
+       RNA_def_property_boolean_negative_sdna(prop, NULL, "type->flag", RE_USE_POSTPROCESS);
        RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
 
        RNA_define_verify_sdna(1);
index e2222cad2ea1e38eb58b17fc87c9e6b77597d343..d5b3bd5e3114fc30b6b4915f14ed06cec0820bb6 100644 (file)
@@ -118,6 +118,17 @@ set(SRC
        intern/raytrace/vbvh.h
 )
 
+if(WITH_PYTHON)
+       add_definitions(-DWITH_PYTHON)
+       list(APPEND INC
+               ../python
+       )
+
+       list(APPEND INC_SYS
+               ${PYTHON_INCLUDE_DIRS}
+       )
+endif()
+
 if(WITH_IMAGE_OPENEXR)
        add_definitions(-DWITH_OPENEXR)
 endif()
@@ -136,6 +147,10 @@ if(WITH_CODEC_QUICKTIME)
        add_definitions(-DWITH_QUICKTIME)
 endif()
 
+if(WITH_GAMEENGINE)
+       add_definitions(-DWITH_GAMEENGINE)
+endif()
+
 if(APPLE)
        if(CMAKE_OSX_ARCHITECTURES MATCHES "i386" OR CMAKE_OSX_ARCHITECTURES MATCHES "x86_64")
                set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -mfpmath=sse")
index 4ec1ce3de6bc4d1f40b4725eccd3e4c9e87897bc..9c724187c27cfcfb8c9546fd45b6783a71f9129b 100644 (file)
@@ -16,6 +16,13 @@ defs_raytrace = []
 
 defs.append('WITH_SMOKE')  # TODO, make optional
 
+if env['WITH_BF_PYTHON']:
+    incs += ' ../python'
+    incs += ' ' + env['BF_PYTHON_INC']
+    defs.append('WITH_PYTHON')
+    if env['BF_DEBUG']:
+        defs.append('DEBUG')
+
 if env['OURPLATFORM'] in ('win32-vc', 'win64-vc'):
     if env['WITH_BF_RAYOPTIMIZATION']:
         cflags_raytrace = env['CCFLAGS'] + env['BF_RAYOPTIMIZATION_SSE_FLAGS']
@@ -49,6 +56,9 @@ if env['WITH_BF_QUICKTIME']:
 if env['WITH_BF_OPENEXR']:
     defs.append('WITH_OPENEXR')
 
+if env['WITH_BF_GAMEENGINE']:
+    defs.append('WITH_GAMEENGINE')
+
 if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc'):
     incs += ' ' + env['BF_PTHREADS_INC']
 
index 23b67854a83e6cb133e94283f4fe8391852bbfda..8300582c1735e7b14daac36be552c35600a10696 100644 (file)
@@ -48,10 +48,10 @@ struct Scene;
 
 /* External Engine */
 
-#define RE_INTERNAL                    1
-#define RE_GAME                                2
-#define RE_DO_PREVIEW          4
-#define RE_DO_ALL                      8
+#define RE_INTERNAL                            1
+#define RE_GAME                                        2
+#define RE_USE_PREVIEW                 4
+#define RE_USE_POSTPROCESS             8
 
 extern ListBase R_engines;
 
@@ -71,10 +71,14 @@ typedef struct RenderEngineType {
 
 typedef struct RenderEngine {
        RenderEngineType *type;
+
        struct Render *re;
        ListBase fullresult;
 } RenderEngine;
 
+RenderEngine *RE_engine_create(RenderEngineType *type);
+void RE_engine_free(RenderEngine *engine);
+
 void RE_layer_load_from_file(struct RenderLayer *layer, struct ReportList *reports, const char *filename, int x, int y);
 void RE_result_load_from_file(struct RenderResult *result, struct ReportList *reports, const char *filename);
 
@@ -84,6 +88,7 @@ void RE_engine_end_result(RenderEngine *engine, struct RenderResult *result);
 
 int RE_engine_test_break(RenderEngine *engine);
 void RE_engine_update_stats(RenderEngine *engine, const char *stats, const char *info);
+void RE_engine_update_progress(RenderEngine *engine, float progress);
 void RE_engine_report(RenderEngine *engine, int type, const char *msg);
 
 int RE_engine_render(struct Render *re, int do_all);
@@ -93,5 +98,7 @@ int RE_engine_render(struct Render *re, int do_all);
 void RE_engines_init(void);
 void RE_engines_exit(void);
 
+RenderEngineType *RE_engines_find(const char *idname);
+
 #endif /* RE_ENGINE_H */
 
index b76a3e16513353535c9024c7b5b3a0592b9d6f1f..9470101d455917c38f7183bfe38d13e29d67c0da 100644 (file)
 #include "IMB_imbuf.h"
 #include "IMB_imbuf_types.h"
 
+#ifdef WITH_PYTHON
+#include "BPY_extern.h"
+#endif
+
 #include "RE_engine.h"
 #include "RE_pipeline.h"
 
 #include "render_types.h"
 #include "renderpipeline.h"
 
-/************************** External Engines ***************************/
+/* Render Engine Types */
+
+static RenderEngineType internal_render_type = {
+       NULL, NULL,
+       "BLENDER_RENDER", "Blender Render", RE_INTERNAL,
+       NULL,
+       {NULL, NULL, NULL}};
+
+#ifdef WITH_GAMEENGINE
+
+static RenderEngineType internal_game_type = {
+       NULL, NULL,
+       "BLENDER_GAME", "Blender Game", RE_INTERNAL|RE_GAME,
+       NULL,
+       {NULL, NULL, NULL}};
+
+#endif
+
+ListBase R_engines = {NULL, NULL};
+
+void RE_engines_init(void)
+{
+       BLI_addtail(&R_engines, &internal_render_type);
+#ifdef WITH_GAMEENGINE
+       BLI_addtail(&R_engines, &internal_game_type);
+#endif
+}
+
+void RE_engines_exit(void)
+{
+       RenderEngineType *type, *next;
+
+       for(type=R_engines.first; type; type=next) {
+               next= type->next;
+
+               BLI_remlink(&R_engines, type);
+
+               if(!(type->flag & RE_INTERNAL)) {
+                       if(type->ext.free)
+                               type->ext.free(type->ext.data);
+
+                       MEM_freeN(type);
+               }
+       }
+}
+
+RenderEngineType *RE_engines_find(const char *idname)
+{
+       RenderEngineType *type;
+       
+       type= BLI_findstring(&R_engines, idname, offsetof(RenderEngineType, idname));
+       if(!type)
+               type= &internal_render_type;
+
+       return type;
+}
+
+/* Create, Free */
+
+RenderEngine *RE_engine_create(RenderEngineType *type)
+{
+       RenderEngine *engine = MEM_callocN(sizeof(RenderEngine), "RenderEngine");
+       engine->type= type;
+
+       return engine;
+}
+
+void RE_engine_free(RenderEngine *engine)
+{
+       MEM_freeN(engine);
+}
+
+/* Render Results */
 
 RenderResult *RE_engine_begin_result(RenderEngine *engine, int x, int y, int w, int h)
 {
@@ -133,11 +209,24 @@ void RE_engine_update_stats(RenderEngine *engine, const char *stats, const char
 {
        Render *re= engine->re;
 
-       re->i.statstr= stats;
-       re->i.infostr= info;
-       re->stats_draw(re->sdh, &re->i);
-       re->i.infostr= NULL;
-       re->i.statstr= NULL;
+       /* stats draw callback */
+       if(re) {
+               re->i.statstr= stats;
+               re->i.infostr= info;
+               re->stats_draw(re->sdh, &re->i);
+               re->i.infostr= NULL;
+               re->i.statstr= NULL;
+       }
+}
+
+void RE_engine_update_progress(RenderEngine *engine, float progress)
+{
+       Render *re= engine->re;
+
+       if(re) {
+               CLAMP(progress, 0.0f, 1.0f);
+               re->progress(re->prh, progress);
+       }
 }
 
 void RE_engine_report(RenderEngine *engine, int type, const char *msg)
@@ -149,16 +238,17 @@ void RE_engine_report(RenderEngine *engine, int type, const char *msg)
 
 int RE_engine_render(Render *re, int do_all)
 {
-       RenderEngineType *type= BLI_findstring(&R_engines, re->r.engine, offsetof(RenderEngineType, idname));
-       RenderEngine engine;
+       RenderEngineType *type= RE_engines_find(re->r.engine);
+       RenderEngine *engine;
 
-       if(!(type && type->render))
+       /* verify if we can render */
+       if(!type->render)
                return 0;
-       if((re->r.scemode & R_PREVIEWBUTS) && !(type->flag & RE_DO_PREVIEW))
+       if((re->r.scemode & R_PREVIEWBUTS) && !(type->flag & RE_USE_PREVIEW))
                return 0;
-       if(do_all && !(type->flag & RE_DO_ALL))
+       if(do_all && !(type->flag & RE_USE_POSTPROCESS))
                return 0;
-       if(!do_all && (type->flag & RE_DO_ALL))
+       if(!do_all && (type->flag & RE_USE_POSTPROCESS))
                return 0;
 
        /* create render result */
@@ -172,14 +262,19 @@ int RE_engine_render(Render *re, int do_all)
        if(re->result==NULL)
                return 1;
 
-       /* external */
-       memset(&engine, 0, sizeof(engine));
-       engine.type= type;
-       engine.re= re;
+       /* render */
+       engine = RE_engine_create(type);
+       engine->re= re;
+
+       if((re->r.scemode & (R_NO_FRAME_UPDATE|R_PREVIEWBUTS))==0)
+               scene_update_for_newframe(re->main, re->scene, re->lay);
+
+       type->render(engine, re->scene);
+
 
-       type->render(&engine, re->scene);
+       free_render_result(&engine->fullresult, engine->fullresult.first);
 
-       free_render_result(&engine.fullresult, engine.fullresult.first);
+       RE_engine_free(engine);
 
        return 1;
 }
index 788b4e40eb230ba77f7f8885f48284d97b82d9b1..8b9ef3835d23437fa6be44672ef49e1d95ad5dbf 100644 (file)
@@ -375,6 +375,7 @@ struct RenderResult *RE_AcquireResultRead(struct Render *re){return (struct Rend
 struct RenderResult *RE_AcquireResultWrite(struct Render *re){return (struct RenderResult *) NULL;}
 struct RenderStats *RE_GetStats(struct Render *re){return (struct RenderStats *) NULL;}
 void RE_engine_update_result(struct RenderEngine *engine, struct RenderResult *result){}
+void RE_engine_update_progress(struct RenderEngine *engine, float progress) {}
 void RE_engine_end_result(struct RenderEngine *engine, struct RenderResult *result){}
 void RE_engine_update_stats(struct RenderEngine *engine, char *stats, char *info){}
 void RE_layer_load_from_file(struct RenderLayer *layer, struct ReportList *reports, char *filename){}
@@ -383,7 +384,11 @@ void RE_AcquireResultImage(struct Render *re, struct RenderResult *rr){}
 void RE_ReleaseResult(struct Render *re){}
 void RE_ReleaseResultImage(struct Render *re){}
 int RE_engine_test_break(struct RenderEngine *engine){return 0;}
+void RE_engines_init() {}
+void RE_engines_exit() {}
 void RE_engine_report(struct RenderEngine *engine, int type, const char *msg) {}
+ListBase R_engines = {NULL, NULL};
+void RE_engine_free(struct RenderEngine *engine) {}
 
 /* python */
 struct wmOperatorType *WM_operatortype_find(const char *idname, int quiet){return (struct wmOperatorType *) NULL;}