diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-01-18 17:40:06 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-01-18 17:40:06 +0300 |
commit | 9ae90efc8e87bf646e356f0f0d0e40b536798207 (patch) | |
tree | b6488b0719f2798c9297c40968d931c218e3f46e /source/blender/editors/screen | |
parent | dc589a33ddbe5effed136750b37c18441d490f64 (diff) |
- opengl render anim exec function so python can render opengl animations without and have it block until its done.
- timeline rna camera access.
- new textblocks have tabs as spaces enabled by default since this is blenders default.
Diffstat (limited to 'source/blender/editors/screen')
-rw-r--r-- | source/blender/editors/screen/screen_ops.c | 155 |
1 files changed, 108 insertions, 47 deletions
diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index 4461549aa28..f837409ca4a 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -3260,7 +3260,7 @@ typedef struct OGLRender { bMovieHandle *mh; int cfrao, nfra; - wmTimer *timer; + wmTimer *timer; /* use to check if running modal or not (invoke'd or exec'd)*/ } OGLRender; static void screen_opengl_render_apply(OGLRender *oglrender) @@ -3378,8 +3378,8 @@ static void screen_opengl_render_end(bContext *C, OGLRender *oglrender) if(BKE_imtype_is_movie(scene->r.imtype)) oglrender->mh->end_movie(); } - - if(oglrender->timer) { + + if(oglrender->timer) { /* exec will not have a timer */ scene->r.cfra= oglrender->cfrao; scene_update_for_newframe(scene, scene->lay); @@ -3401,7 +3401,32 @@ static int screen_opengl_render_cancel(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } -static int screen_opengl_render_modal(bContext *C, wmOperator *op, wmEvent *event) +/* share between invoke and exec */ +static int screen_opengl_render_anim_initialize(bContext *C, wmOperator *op) +{ + /* initialize animation */ + OGLRender *oglrender; + Scene *scene; + + oglrender= op->customdata; + scene= oglrender->scene; + + oglrender->reports= op->reports; + oglrender->mh= BKE_get_movie_handle(scene->r.imtype); + if(BKE_imtype_is_movie(scene->r.imtype)) { + if(!oglrender->mh->start_movie(scene, &scene->r, oglrender->sizex, oglrender->sizey, oglrender->reports)) { + screen_opengl_render_end(C, oglrender); + return 0; + } + } + + oglrender->cfrao= scene->r.cfra; + oglrender->nfra= SFRA; + scene->r.cfra= SFRA; + + return 1; +} +static int screen_opengl_render_anim_step(bContext *C, wmOperator *op) { OGLRender *oglrender= op->customdata; Scene *scene= oglrender->scene; @@ -3410,32 +3435,18 @@ static int screen_opengl_render_modal(bContext *C, wmOperator *op, wmEvent *even char name[FILE_MAXDIR+FILE_MAXFILE]; unsigned int lay; int ok= 0; - - switch(event->type) { - case ESCKEY: - /* cancel */ - screen_opengl_render_end(C, op->customdata); - return OPERATOR_FINISHED; - case TIMER: - /* render frame? */ - if(oglrender->timer == event->customdata) - break; - default: - /* nothing to do */ - return OPERATOR_RUNNING_MODAL; - } - + /* go to next frame */ while(CFRA<oglrender->nfra) { if(scene->lay & 0xFF000000) lay= scene->lay & 0xFF000000; else lay= scene->lay; - + scene_update_for_newframe(scene, lay); CFRA++; } - + scene_update_for_newframe(scene, scene->lay); if(oglrender->rv3d->persp==RV3D_CAMOB && oglrender->v3d->camera && oglrender->v3d->scenelock) { @@ -3446,7 +3457,7 @@ static int screen_opengl_render_modal(bContext *C, wmOperator *op, wmEvent *even if(camera) oglrender->v3d->camera= scene->camera= camera; } - + /* render into offscreen buffer */ screen_opengl_render_apply(oglrender); @@ -3477,11 +3488,42 @@ static int screen_opengl_render_modal(bContext *C, wmOperator *op, wmEvent *even oglrender->nfra += scene->r.frame_step; scene->r.cfra++; - WM_event_add_notifier(C, NC_SCENE|ND_RENDER_RESULT, oglrender->scene); - /* stop at the end or on error */ if(scene->r.cfra > EFRA || !ok) { screen_opengl_render_end(C, op->customdata); + return 0; + } + + return 1; +} + + +static int screen_opengl_render_modal(bContext *C, wmOperator *op, wmEvent *event) +{ + OGLRender *oglrender= op->customdata; + + int ret; + + switch(event->type) { + case ESCKEY: + /* cancel */ + screen_opengl_render_end(C, op->customdata); + return OPERATOR_FINISHED; + case TIMER: + /* render frame? */ + if(oglrender->timer == event->customdata) + break; + default: + /* nothing to do */ + return OPERATOR_RUNNING_MODAL; + } + + ret= screen_opengl_render_anim_step(C, op); + + WM_event_add_notifier(C, NC_SCENE|ND_RENDER_RESULT, oglrender->scene); + + /* stop at the end or on error */ + if(ret == 0) { return OPERATOR_FINISHED; } @@ -3504,35 +3546,53 @@ static int screen_opengl_render_invoke(bContext *C, wmOperator *op, wmEvent *eve return OPERATOR_FINISHED; } else { - /* initialize animation */ - OGLRender *oglrender; - Scene *scene; - - oglrender= op->customdata; - scene= oglrender->scene; - - oglrender->reports= op->reports; - oglrender->mh= BKE_get_movie_handle(scene->r.imtype); - if(BKE_imtype_is_movie(scene->r.imtype)) { - if(!oglrender->mh->start_movie(scene, &scene->r, oglrender->sizex, oglrender->sizey, oglrender->reports)) { - screen_opengl_render_end(C, oglrender); - return OPERATOR_CANCELLED; - } - } - - oglrender->cfrao= scene->r.cfra; - oglrender->nfra= SFRA; - scene->r.cfra= SFRA; - + OGLRender *oglrender= op->customdata; + + if(!screen_opengl_render_anim_initialize(C, op)) + return OPERATOR_CANCELLED; + + screen_set_image_output(C, event->x, event->y); + WM_event_add_modal_handler(C, op); oglrender->timer= WM_event_add_timer(CTX_wm_manager(C), CTX_wm_window(C), TIMER, 0.01f); - - screen_set_image_output(C, event->x, event->y); - + return OPERATOR_RUNNING_MODAL; } } +/* executes blocking render */ +static int screen_opengl_render_exec(bContext *C, wmOperator *op) +{ + int anim= RNA_boolean_get(op->ptr, "animation"); + + if(!screen_opengl_render_init(C, op)) + return OPERATOR_CANCELLED; + + if(!anim) { /* same as invoke */ + /* render image */ + screen_opengl_render_apply(op->customdata); + screen_opengl_render_end(C, op->customdata); + + return OPERATOR_FINISHED; + } + else { + int ret= 1; + + if(!screen_opengl_render_anim_initialize(C, op)) + return OPERATOR_CANCELLED; + + while(ret) { + ret= screen_opengl_render_anim_step(C, op); + } + } + + // no redraw needed, we leave state as we entered it +// ED_update_for_newframe(C, 1); + WM_event_add_notifier(C, NC_SCENE|ND_RENDER_RESULT, CTX_data_scene(C)); + + return OPERATOR_FINISHED; +} + static void SCREEN_OT_opengl_render(wmOperatorType *ot) { /* identifiers */ @@ -3542,6 +3602,7 @@ static void SCREEN_OT_opengl_render(wmOperatorType *ot) /* api callbacks */ ot->invoke= screen_opengl_render_invoke; + ot->exec= screen_opengl_render_exec; /* blocking */ ot->modal= screen_opengl_render_modal; ot->cancel= screen_opengl_render_cancel; |