diff --git a/source/blender/editors/render/render_internal.c b/source/blender/editors/render/render_internal.c index 1c8c111437d..94057aa5087 100644 --- a/source/blender/editors/render/render_internal.c +++ b/source/blender/editors/render/render_internal.c @@ -718,7 +718,7 @@ static int screen_render_invoke(bContext *C, wmOperator *op, wmEvent *event) rj->srl = srl; rj->lay = (v3d)? v3d->lay: scene->lay; rj->anim= is_animation; - rj->write_still= is_write_still; + rj->write_still= is_write_still && !is_animation; rj->iuser.scene= scene; rj->iuser.ok= 1; rj->reports= op->reports; diff --git a/source/blender/editors/render/render_opengl.c b/source/blender/editors/render/render_opengl.c index 71354ad6d07..6b067a94003 100644 --- a/source/blender/editors/render/render_opengl.c +++ b/source/blender/editors/render/render_opengl.c @@ -81,6 +81,7 @@ typedef struct OGLRender { GPUOffScreen *ofs; int sizex, sizey; + int write_still; ReportList *reports; bMovieHandle *mh; @@ -112,7 +113,7 @@ static void screen_opengl_render_apply(OGLRender *oglrender) float winmat[4][4]; int sizex= oglrender->sizex; int sizey= oglrender->sizey; - int view_context = (v3d != NULL); + const short view_context= (v3d != NULL); rr= RE_AcquireResultRead(oglrender->re); @@ -196,7 +197,20 @@ static void screen_opengl_render_apply(OGLRender *oglrender) /* update byte from float buffer */ ibuf= BKE_image_acquire_ibuf(oglrender->ima, &oglrender->iuser, &lock); - if(ibuf) image_buffer_rect_update(NULL, rr, ibuf, NULL); + + if(ibuf) { + image_buffer_rect_update(NULL, rr, ibuf, NULL); + + if(oglrender->write_still) { + char name[FILE_MAX]; + int ok; + BKE_makepicstring(name, scene->r.pic, scene->r.cfra, scene->r.imtype, scene->r.scemode & R_EXTENSION, FALSE); + ok= BKE_write_ibuf(scene, ibuf, name, scene->r.imtype, scene->r.subimtype, scene->r.quality); + if(ok) printf("OpenGL Render written to '%s'\n", name); + else printf("OpenGL Render failed to write '%s'\n", name); + } + } + BKE_image_release_ibuf(oglrender->ima, lock); } @@ -208,24 +222,31 @@ static int screen_opengl_render_init(bContext *C, wmOperator *op) GPUOffScreen *ofs; OGLRender *oglrender; int sizex, sizey; - int view_context= RNA_boolean_get(op->ptr, "view_context"); + short is_view_context= RNA_boolean_get(op->ptr, "view_context"); + const short is_animation= RNA_boolean_get(op->ptr, "animation"); + const short is_write_still= RNA_boolean_get(op->ptr, "view_context"); /* ensure we have a 3d view */ - + if(!ED_view3d_context_activate(C)) { RNA_boolean_set(op->ptr, "view_context", 0); - view_context = 0; + is_view_context= 0; } /* only one render job at a time */ if(WM_jobs_test(CTX_wm_manager(C), scene)) return 0; - if(!view_context && scene->camera==NULL) { + if(!is_view_context && scene->camera==NULL) { BKE_report(op->reports, RPT_ERROR, "Scene has no camera."); return 0; } + if(!is_animation && is_write_still && BKE_imtype_is_movie(scene->r.imtype)) { + BKE_report(op->reports, RPT_ERROR, "Can't write a single file with an animation format selected."); + return 0; + } + /* stop all running jobs, currently previews frustrate Render */ WM_jobs_stop_all(CTX_wm_manager(C)); @@ -252,7 +273,9 @@ static int screen_opengl_render_init(bContext *C, wmOperator *op) oglrender->sizey= sizey; oglrender->scene= scene; - if(view_context) { + oglrender->write_still= is_write_still && !is_animation; + + if(is_view_context) { oglrender->v3d= CTX_wm_view3d(C); oglrender->ar= CTX_wm_region(C); oglrender->rv3d= CTX_wm_region_view3d(C); @@ -343,7 +366,7 @@ static int screen_opengl_render_anim_step(bContext *C, wmOperator *op) void *lock; char name[FILE_MAXDIR+FILE_MAXFILE]; int ok= 0; - int view_context = (oglrender->v3d != NULL); + const short view_context= (oglrender->v3d != NULL); /* update animated image textures for gpu, etc, * call before scene_update_for_newframe so modifiers with textuers dont lag 1 frame */ @@ -488,12 +511,12 @@ static int screen_opengl_render_invoke(bContext *C, wmOperator *op, wmEvent *eve /* executes blocking render */ static int screen_opengl_render_exec(bContext *C, wmOperator *op) { - int anim= RNA_boolean_get(op->ptr, "animation"); + const short is_animation= RNA_boolean_get(op->ptr, "animation"); if(!screen_opengl_render_init(C, op)) return OPERATOR_CANCELLED; - if(!anim) { /* same as invoke */ + if(!is_animation) { /* same as invoke */ /* render image */ screen_opengl_render_apply(op->customdata); screen_opengl_render_end(C, op->customdata); @@ -533,7 +556,8 @@ void RENDER_OT_opengl(wmOperatorType *ot) ot->poll= ED_operator_screenactive; - RNA_def_boolean(ot->srna, "animation", 0, "Animation", ""); + RNA_def_boolean(ot->srna, "animation", 0, "Animation", "Render files from the animation range of this scene"); + RNA_def_boolean(ot->srna, "write_still", 0, "Write Image", "Save rendered the image to the output path (used only when animation is disabled)"); RNA_def_boolean(ot->srna, "view_context", 1, "View Context", "Use the current 3D view for rendering, else use scene settings."); }