diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-03-08 19:36:53 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-03-08 19:36:53 +0300 |
commit | d0e0f6dea3e8644acb63779f1653ed85c2ed4be3 (patch) | |
tree | 48c51dad8115f14817609312abd2f2d76770ce86 /source | |
parent | 59db9a406116f05c4bf16ef1f25b3ada82e51a69 (diff) |
move render operators into their own files, render_internal.c & render_opengl.c, rather then have them in the screen module.
also rename render operators SCREEN_OT_ --> RENDER_OT_
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/include/ED_screen.h | 1 | ||||
-rw-r--r-- | source/blender/editors/render/render_intern.h | 13 | ||||
-rw-r--r-- | source/blender/editors/render/render_internal.c | 791 | ||||
-rw-r--r-- | source/blender/editors/render/render_opengl.c | 470 | ||||
-rw-r--r-- | source/blender/editors/render/render_ops.c | 8 | ||||
-rw-r--r-- | source/blender/editors/screen/screen_edit.c | 178 | ||||
-rw-r--r-- | source/blender/editors/screen/screen_intern.h | 2 | ||||
-rw-r--r-- | source/blender/editors/screen/screen_ops.c | 1105 | ||||
-rw-r--r-- | source/blender/editors/space_node/drawnode.c | 4 |
9 files changed, 1379 insertions, 1193 deletions
diff --git a/source/blender/editors/include/ED_screen.h b/source/blender/editors/include/ED_screen.h index aae354b79fa..2a4f70959a3 100644 --- a/source/blender/editors/include/ED_screen.h +++ b/source/blender/editors/include/ED_screen.h @@ -102,6 +102,7 @@ void ED_screen_animation_timer_update(struct bScreen *screen, int redraws); int ED_screen_full_newspace(struct bContext *C, ScrArea *sa, int type); void ED_screen_full_prevspace(struct bContext *C, ScrArea *sa); void ED_screen_full_restore(struct bContext *C, ScrArea *sa); +struct ScrArea *ED_screen_full_toggle(struct bContext *C, struct wmWindow *win, struct ScrArea *sa); void ED_screen_new_window(struct bContext *C, struct rcti *position, int type); diff --git a/source/blender/editors/render/render_intern.h b/source/blender/editors/render/render_intern.h index 99b68c2bb74..cb72182dff9 100644 --- a/source/blender/editors/render/render_intern.h +++ b/source/blender/editors/render/render_intern.h @@ -30,6 +30,8 @@ #define RENDER_INTERN_H struct wmOperatorType; +struct RenderResult; +struct Scene; /* render_shading.c */ void OBJECT_OT_material_slot_add(struct wmOperatorType *ot); @@ -51,6 +53,17 @@ void SCENE_OT_render_layer_remove(struct wmOperatorType *ot); void TEXTURE_OT_slot_move(struct wmOperatorType *ot); +/* render_internal.c */ +void RENDER_OT_view_show(struct wmOperatorType *ot); +void RENDER_OT_render(struct wmOperatorType *ot); +void RENDER_OT_view_cancel(struct wmOperatorType *ot); + +/*render_opengl.c uses these */ +void image_buffer_rect_update(struct Scene *scene, struct RenderResult *rr, struct ImBuf *ibuf, volatile struct rcti *renrect); +void screen_set_image_output(struct bContext *C, int mx, int my); + +/* render_opengl.c */ +void RENDER_OT_opengl(struct wmOperatorType *ot); #endif /* RENDER_INTERN_H */ diff --git a/source/blender/editors/render/render_internal.c b/source/blender/editors/render/render_internal.c new file mode 100644 index 00000000000..85ec7cfcf34 --- /dev/null +++ b/source/blender/editors/render/render_internal.c @@ -0,0 +1,791 @@ +/** + * $Id: + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2008 Blender Foundation. + * All rights reserved. + * + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include <math.h> +#include <string.h> +#include <stddef.h> + +#include "MEM_guardedalloc.h" + +#include "BLI_math.h" +#include "BLI_blenlib.h" +#include "BLI_editVert.h" +#include "BLI_dlrbTree.h" + +#include "DNA_armature_types.h" +#include "DNA_image_types.h" +#include "DNA_lattice_types.h" +#include "DNA_object_types.h" +#include "DNA_mesh_types.h" +#include "DNA_curve_types.h" +#include "DNA_scene_types.h" +#include "DNA_meta_types.h" + +#include "BKE_blender.h" +#include "BKE_colortools.h" +#include "BKE_context.h" +#include "BKE_customdata.h" +#include "BKE_global.h" +#include "BKE_image.h" +#include "BKE_idprop.h" +#include "BKE_library.h" +#include "BKE_main.h" +#include "BKE_mesh.h" +#include "BKE_multires.h" +#include "BKE_report.h" +#include "BKE_scene.h" +#include "BKE_screen.h" +#include "BKE_utildefines.h" +#include "BKE_sound.h" +#include "BKE_writeavi.h" + +#include "WM_api.h" +#include "WM_types.h" + +#include "ED_util.h" +#include "ED_screen.h" +#include "ED_mesh.h" +#include "ED_object.h" +#include "ED_screen_types.h" +#include "ED_keyframes_draw.h" + +#include "RE_pipeline.h" +#include "IMB_imbuf.h" +#include "IMB_imbuf_types.h" + +#include "RNA_access.h" +#include "RNA_define.h" + +#include "UI_interface.h" +#include "UI_resources.h" + +#include "wm_window.h" + +#include "render_intern.h" + +static ScrArea *biggest_area(bContext *C); +static ScrArea *biggest_non_image_area(bContext *C); +static ScrArea *find_area_showing_r_result(bContext *C); +static ScrArea *find_area_image_empty(bContext *C); + +/* called inside thread! */ +void image_buffer_rect_update(Scene *scene, RenderResult *rr, ImBuf *ibuf, volatile rcti *renrect) +{ + float x1, y1, *rectf= NULL; + int ymin, ymax, xmin, xmax; + int rymin, rxmin; + char *rectc; + + /* if renrect argument, we only refresh scanlines */ + if(renrect) { + /* if ymax==recty, rendering of layer is ready, we should not draw, other things happen... */ + if(rr->renlay==NULL || renrect->ymax>=rr->recty) + return; + + /* xmin here is first subrect x coord, xmax defines subrect width */ + xmin = renrect->xmin + rr->crop; + xmax = renrect->xmax - xmin - rr->crop; + if (xmax<2) return; + + ymin= renrect->ymin + rr->crop; + ymax= renrect->ymax - ymin - rr->crop; + if(ymax<2) + return; + renrect->ymin= renrect->ymax; + + } + else { + xmin = ymin = rr->crop; + xmax = rr->rectx - 2*rr->crop; + ymax = rr->recty - 2*rr->crop; + } + + /* xmin ymin is in tile coords. transform to ibuf */ + rxmin= rr->tilerect.xmin + xmin; + if(rxmin >= ibuf->x) return; + rymin= rr->tilerect.ymin + ymin; + if(rymin >= ibuf->y) return; + + if(rxmin + xmax > ibuf->x) + xmax= ibuf->x - rxmin; + if(rymin + ymax > ibuf->y) + ymax= ibuf->y - rymin; + + if(xmax < 1 || ymax < 1) return; + + /* find current float rect for display, first case is after composit... still weak */ + if(rr->rectf) + rectf= rr->rectf; + else { + if(rr->rect32) + return; + else { + if(rr->renlay==NULL || rr->renlay->rectf==NULL) return; + rectf= rr->renlay->rectf; + } + } + if(rectf==NULL) return; + + if(ibuf->rect==NULL) + imb_addrectImBuf(ibuf); + + rectf+= 4*(rr->rectx*ymin + xmin); + rectc= (char *)(ibuf->rect + ibuf->x*rymin + rxmin); + + /* XXX make nice consistent functions for this */ + if (scene && (scene->r.color_mgt_flag & R_COLOR_MANAGEMENT)) { + for(y1= 0; y1<ymax; y1++) { + float *rf= rectf; + float srgb[3]; + char *rc= rectc; + + /* XXX temp. because crop offset */ + if( rectc >= (char *)(ibuf->rect)) { + for(x1= 0; x1<xmax; x1++, rf += 4, rc+=4) { + srgb[0]= linearrgb_to_srgb(rf[0]); + srgb[1]= linearrgb_to_srgb(rf[1]); + srgb[2]= linearrgb_to_srgb(rf[2]); + + rc[0]= FTOCHAR(srgb[0]); + rc[1]= FTOCHAR(srgb[1]); + rc[2]= FTOCHAR(srgb[2]); + rc[3]= FTOCHAR(rf[3]); + } + } + rectf += 4*rr->rectx; + rectc += 4*ibuf->x; + } + } else { + for(y1= 0; y1<ymax; y1++) { + float *rf= rectf; + char *rc= rectc; + + /* XXX temp. because crop offset */ + if( rectc >= (char *)(ibuf->rect)) { + for(x1= 0; x1<xmax; x1++, rf += 4, rc+=4) { + rc[0]= FTOCHAR(rf[0]); + rc[1]= FTOCHAR(rf[1]); + rc[2]= FTOCHAR(rf[2]); + rc[3]= FTOCHAR(rf[3]); + } + } + rectf += 4*rr->rectx; + rectc += 4*ibuf->x; + } + } +} + +/* new window uses x,y to set position */ +void screen_set_image_output(bContext *C, int mx, int my) +{ + wmWindow *win= CTX_wm_window(C); + Scene *scene= CTX_data_scene(C); + ScrArea *sa= NULL; + SpaceImage *sima; + int area_was_image=0; + + if(scene->r.displaymode==R_OUTPUT_WINDOW) { + rcti rect; + int sizex, sizey; + + sizex= 10 + (scene->r.xsch*scene->r.size)/100; + sizey= 40 + (scene->r.ysch*scene->r.size)/100; + + /* arbitrary... miniature image window views don't make much sense */ + if(sizex < 320) sizex= 320; + if(sizey < 256) sizey= 256; + + /* XXX some magic to calculate postition */ + rect.xmin= mx + win->posx - sizex/2; + rect.ymin= my + win->posy - sizey/2; + rect.xmax= rect.xmin + sizex; + rect.ymax= rect.ymin + sizey; + + /* changes context! */ + WM_window_open_temp(C, &rect, WM_WINDOW_RENDER); + + sa= CTX_wm_area(C); + } + else if(scene->r.displaymode==R_OUTPUT_SCREEN) { + if (CTX_wm_area(C)->spacetype == SPACE_IMAGE) + area_was_image = 1; + + /* this function returns with changed context */ + ED_screen_full_newspace(C, CTX_wm_area(C), SPACE_IMAGE); + sa= CTX_wm_area(C); + } + + if(!sa) { + sa= find_area_showing_r_result(C); + if(sa==NULL) + sa= find_area_image_empty(C); + + if(sa==NULL) { + /* find largest open non-image area */ + sa= biggest_non_image_area(C); + if(sa) { + ED_area_newspace(C, sa, SPACE_IMAGE); + sima= sa->spacedata.first; + + /* makes ESC go back to prev space */ + sima->flag |= SI_PREVSPACE; + } + else { + /* use any area of decent size */ + sa= biggest_area(C); + if(sa->spacetype!=SPACE_IMAGE) { + // XXX newspace(sa, SPACE_IMAGE); + sima= sa->spacedata.first; + + /* makes ESC go back to prev space */ + sima->flag |= SI_PREVSPACE; + } + } + } + } + sima= sa->spacedata.first; + + /* get the correct image, and scale it */ + sima->image= BKE_image_verify_viewer(IMA_TYPE_R_RESULT, "Render Result"); + + + /* if we're rendering to full screen, set appropriate hints on image editor + * so it can restore properly on pressing esc */ + if(sa->full) { + sima->flag |= SI_FULLWINDOW; + + /* Tell the image editor to revert to previous space in space list on close + * _only_ if it wasn't already an image editor when the render was invoked */ + if (area_was_image == 0) + sima->flag |= SI_PREVSPACE; + else { + /* Leave it alone so the image editor will just go back from + * full screen to the original tiled setup */ + ; + } + + } + +} + + +/* ****************************** render invoking ***************** */ + +/* set callbacks, exported to sequence render too. + Only call in foreground (UI) renders. */ + +/* returns biggest area that is not uv/image editor. Note that it uses buttons */ +/* window as the last possible alternative. */ +static ScrArea *biggest_non_image_area(bContext *C) +{ + bScreen *sc= CTX_wm_screen(C); + ScrArea *sa, *big= NULL; + int size, maxsize= 0, bwmaxsize= 0; + short foundwin= 0; + + for(sa= sc->areabase.first; sa; sa= sa->next) { + if(sa->winx > 30 && sa->winy > 30) { + size= sa->winx*sa->winy; + if(sa->spacetype == SPACE_BUTS) { + if(foundwin == 0 && size > bwmaxsize) { + bwmaxsize= size; + big= sa; + } + } + else if(sa->spacetype != SPACE_IMAGE && size > maxsize) { + maxsize= size; + big= sa; + foundwin= 1; + } + } + } + + return big; +} + +static ScrArea *biggest_area(bContext *C) +{ + bScreen *sc= CTX_wm_screen(C); + ScrArea *sa, *big= NULL; + int size, maxsize= 0; + + for(sa= sc->areabase.first; sa; sa= sa->next) { + size= sa->winx*sa->winy; + if(size > maxsize) { + maxsize= size; + big= sa; + } + } + return big; +} + + +static ScrArea *find_area_showing_r_result(bContext *C) +{ + wmWindowManager *wm= CTX_wm_manager(C); + wmWindow *win; + ScrArea *sa = NULL; + SpaceImage *sima; + + /* find an imagewindow showing render result */ + for(win=wm->windows.first; win; win=win->next) { + for(sa=win->screen->areabase.first; sa; sa= sa->next) { + if(sa->spacetype==SPACE_IMAGE) { + sima= sa->spacedata.first; + if(sima->image && sima->image->type==IMA_TYPE_R_RESULT) + break; + } + } + } + + return sa; +} + +static ScrArea *find_area_image_empty(bContext *C) +{ + bScreen *sc= CTX_wm_screen(C); + ScrArea *sa; + SpaceImage *sima; + + /* find an imagewindow showing render result */ + for(sa=sc->areabase.first; sa; sa= sa->next) { + if(sa->spacetype==SPACE_IMAGE) { + sima= sa->spacedata.first; + if(!sima->image) + break; + } + } + return sa; +} + +#if 0 // XXX not used +static ScrArea *find_empty_image_area(bContext *C) +{ + bScreen *sc= CTX_wm_screen(C); + ScrArea *sa; + SpaceImage *sima; + + /* find an imagewindow showing render result */ + for(sa=sc->areabase.first; sa; sa= sa->next) { + if(sa->spacetype==SPACE_IMAGE) { + sima= sa->spacedata.first; + if(!sima->image) + break; + } + } + return sa; +} +#endif // XXX not used + +/* executes blocking render */ +static int screen_render_exec(bContext *C, wmOperator *op) +{ + Scene *scene= CTX_data_scene(C); + Render *re= RE_GetRender(scene->id.name, RE_SLOT_VIEW); + + if(re==NULL) { + re= RE_NewRender(scene->id.name, RE_SLOT_VIEW); + } + RE_test_break_cb(re, NULL, (int (*)(void *)) blender_test_break); + + if(RNA_boolean_get(op->ptr, "animation")) + RE_BlenderAnim(re, scene, scene->r.sfra, scene->r.efra, scene->r.frame_step, op->reports); + else + RE_BlenderFrame(re, scene, NULL, scene->r.cfra); + + // 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, scene); + + return OPERATOR_FINISHED; +} + +typedef struct RenderJob { + Scene *scene; + Render *re; + wmWindow *win; + SceneRenderLayer *srl; + int anim; + Image *image; + ImageUser iuser; + short *stop; + short *do_update; + ReportList *reports; +} RenderJob; + +static void render_freejob(void *rjv) +{ + RenderJob *rj= rjv; + + MEM_freeN(rj); +} + +/* str is IMA_RW_MAXTEXT in size */ +static void make_renderinfo_string(RenderStats *rs, Scene *scene, char *str) +{ + char info_time_str[32]; // used to be extern to header_info.c + uintptr_t mem_in_use, mmap_in_use; + float megs_used_memory, mmap_used_memory; + char *spos= str; + + mem_in_use= MEM_get_memory_in_use(); + mmap_in_use= MEM_get_mapped_memory_in_use(); + + megs_used_memory= (mem_in_use-mmap_in_use)/(1024.0*1024.0); + mmap_used_memory= (mmap_in_use)/(1024.0*1024.0); + + if(scene->lay & 0xFF000000) + spos+= sprintf(spos, "Localview | "); + else if(scene->r.scemode & R_SINGLE_LAYER) + spos+= sprintf(spos, "Single Layer | "); + + if(rs->statstr) { + spos+= sprintf(spos, "%s ", rs->statstr); + } + else { + spos+= sprintf(spos, "Fra:%d Ve:%d Fa:%d ", (scene->r.cfra), rs->totvert, rs->totface); + if(rs->tothalo) spos+= sprintf(spos, "Ha:%d ", rs->tothalo); + if(rs->totstrand) spos+= sprintf(spos, "St:%d ", rs->totstrand); + spos+= sprintf(spos, "La:%d Mem:%.2fM (%.2fM) ", rs->totlamp, megs_used_memory, mmap_used_memory); + + if(rs->curfield) + spos+= sprintf(spos, "Field %d ", rs->curfield); + if(rs->curblur) + spos+= sprintf(spos, "Blur %d ", rs->curblur); + } + + BLI_timestr(rs->lastframetime, info_time_str); + spos+= sprintf(spos, "Time:%s ", info_time_str); + + if(rs->infostr && rs->infostr[0]) + spos+= sprintf(spos, "| %s ", rs->infostr); + + /* very weak... but 512 characters is quite safe */ + if(spos >= str+IMA_RW_MAXTEXT) + if (G.f & G_DEBUG) + printf("WARNING! renderwin text beyond limit \n"); + +} + +static void image_renderinfo_cb(void *rjv, RenderStats *rs) +{ + RenderJob *rj= rjv; + + /* malloc OK here, stats_draw is not in tile threads */ + if(rj->image->render_text==NULL) + rj->image->render_text= MEM_callocN(IMA_RW_MAXTEXT, "rendertext"); + + make_renderinfo_string(rs, rj->scene, rj->image->render_text); + + /* make jobs timer to send notifier */ + *(rj->do_update)= 1; + +} + +static void image_rect_update(void *rjv, RenderResult *rr, volatile rcti *renrect) +{ + RenderJob *rj= rjv; + ImBuf *ibuf; + void *lock; + + ibuf= BKE_image_acquire_ibuf(rj->image, &rj->iuser, &lock); + if(ibuf) { + image_buffer_rect_update(rj->scene, rr, ibuf, renrect); + + /* make jobs timer to send notifier */ + *(rj->do_update)= 1; + } + BKE_image_release_ibuf(rj->image, lock); +} + +static void render_startjob(void *rjv, short *stop, short *do_update) +{ + RenderJob *rj= rjv; +// Main *mainp= BKE_undo_get_main(&rj->scene); + + rj->stop= stop; + rj->do_update= do_update; + +#if defined(__APPLE__) && (PARALLEL == 1) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 2) + // Workaround for Apple gcc 4.2.1 omp vs background thread bug + pthread_setspecific (gomp_tls_key, thread_tls_data); +#endif + + if(rj->anim) + RE_BlenderAnim(rj->re, rj->scene, rj->scene->r.sfra, rj->scene->r.efra, rj->scene->r.frame_step, rj->reports); + else + RE_BlenderFrame(rj->re, rj->scene, rj->srl, rj->scene->r.cfra); + +// if(mainp) +// free_main(mainp); +} + +/* called by render, check job 'stop' value or the global */ +static int render_breakjob(void *rjv) +{ + RenderJob *rj= rjv; + + if(G.afbreek) + return 1; + if(rj->stop && *(rj->stop)) + return 1; + return 0; +} + +/* catch esc */ +static int screen_render_modal(bContext *C, wmOperator *op, wmEvent *event) +{ + /* no running blender, remove handler and pass through */ + if(0==WM_jobs_test(CTX_wm_manager(C), CTX_data_scene(C))) + return OPERATOR_FINISHED|OPERATOR_PASS_THROUGH; + + /* running render */ + switch (event->type) { + case ESCKEY: + return OPERATOR_RUNNING_MODAL; + break; + } + return OPERATOR_PASS_THROUGH; +} + +/* using context, starts job */ +static int screen_render_invoke(bContext *C, wmOperator *op, wmEvent *event) +{ + /* new render clears all callbacks */ + Scene *scene= CTX_data_scene(C); + SceneRenderLayer *srl=NULL; + Render *re; + wmJob *steve; + RenderJob *rj; + Image *ima; + + /* only one render job at a time */ + if(WM_jobs_test(CTX_wm_manager(C), scene)) + return OPERATOR_CANCELLED; + + /* stop all running jobs, currently previews frustrate Render */ + WM_jobs_stop_all(CTX_wm_manager(C)); + + /* handle UI stuff */ + WM_cursor_wait(1); + + /* flush multires changes (for sculpt) */ + multires_force_render_update(CTX_data_active_object(C)); + + /* get editmode results */ + ED_object_exit_editmode(C, EM_FREEDATA|EM_DO_UNDO); /* 0 = does not exit editmode */ + + // store spare + // get view3d layer, local layer, make this nice api call to render + // store spare + + /* ensure at least 1 area shows result */ + screen_set_image_output(C, event->x, event->y); + + /* single layer re-render */ + if(RNA_property_is_set(op->ptr, "layer")) { + SceneRenderLayer *rl; + Scene *scn; + char scene_name[19], rl_name[RE_MAXNAME]; + + RNA_string_get(op->ptr, "layer", rl_name); + RNA_string_get(op->ptr, "scene", scene_name); + + scn = (Scene *)BLI_findstring(&CTX_data_main(C)->scene, scene_name, offsetof(ID, name) + 2); + rl = (SceneRenderLayer *)BLI_findstring(&scene->r.layers, rl_name, offsetof(SceneRenderLayer, name)); + + if (scn && rl) { + scene = scn; + srl = rl; + } + } + + /* job custom data */ + rj= MEM_callocN(sizeof(RenderJob), "render job"); + rj->scene= scene; + rj->win= CTX_wm_window(C); + rj->srl = srl; + rj->anim= RNA_boolean_get(op->ptr, "animation"); + rj->iuser.scene= scene; + rj->iuser.ok= 1; + rj->reports= op->reports; + + /* setup job */ + steve= WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), scene, WM_JOB_EXCL_RENDER|WM_JOB_PRIORITY); + WM_jobs_customdata(steve, rj, render_freejob); + WM_jobs_timer(steve, 0.2, NC_SCENE|ND_RENDER_RESULT, 0); + WM_jobs_callbacks(steve, render_startjob, NULL, NULL); + +#if defined(__APPLE__) && (PARALLEL == 1) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 2) + // Workaround for Apple gcc 4.2.1 omp vs background thread bug + thread_tls_data = pthread_getspecific(gomp_tls_key); +#endif + + /* get a render result image, and make sure it is empty */ + ima= BKE_image_verify_viewer(IMA_TYPE_R_RESULT, "Render Result"); + BKE_image_signal(ima, NULL, IMA_SIGNAL_FREE); + rj->image= ima; + + /* setup new render */ + re= RE_NewRender(scene->id.name, RE_SLOT_VIEW); + RE_test_break_cb(re, rj, render_breakjob); + RE_display_draw_cb(re, rj, image_rect_update); + RE_stats_draw_cb(re, rj, image_renderinfo_cb); + + rj->re= re; + G.afbreek= 0; + + // BKE_report in render! + // RE_error_cb(re, error_cb); + + WM_jobs_start(CTX_wm_manager(C), steve); + + WM_cursor_wait(0); + WM_event_add_notifier(C, NC_SCENE|ND_RENDER_RESULT, scene); + + /* add modal handler for ESC */ + WM_event_add_modal_handler(C, op); + + return OPERATOR_RUNNING_MODAL; +} + + +/* contextual render, using current scene, view3d? */ +void RENDER_OT_render(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Render"; + ot->description= "Render active scene"; + ot->idname= "RENDER_OT_render"; + + /* api callbacks */ + ot->invoke= screen_render_invoke; + ot->modal= screen_render_modal; + ot->exec= screen_render_exec; + + ot->poll= ED_operator_screenactive; + + RNA_def_boolean(ot->srna, "animation", 0, "Animation", ""); + RNA_def_string(ot->srna, "layer", "", RE_MAXNAME, "Render Layer", "Single render layer to re-render"); + RNA_def_string(ot->srna, "scene", "", 19, "Scene", "Re-render single layer in this scene"); +} + +/* ****************************** opengl render *************************** */ + + +/* *********************** cancel render viewer *************** */ + +static int render_view_cancel_exec(bContext *C, wmOperator *unused) +{ + wmWindow *win= CTX_wm_window(C); + ScrArea *sa= CTX_wm_area(C); + SpaceImage *sima= sa->spacedata.first; + + /* test if we have a temp screen in front */ + if(CTX_wm_window(C)->screen->full==SCREENTEMP) { + wm_window_lower(CTX_wm_window(C)); + return OPERATOR_FINISHED; + } + /* determine if render already shows */ + else if(sima->flag & SI_PREVSPACE) { + sima->flag &= ~SI_PREVSPACE; + + if(sima->flag & SI_FULLWINDOW) { + sima->flag &= ~SI_FULLWINDOW; + ED_screen_full_prevspace(C, sa); + } + else + ED_area_prevspace(C, sa); + + return OPERATOR_FINISHED; + } + else if(sima->flag & SI_FULLWINDOW) { + sima->flag &= ~SI_FULLWINDOW; + ED_screen_full_toggle(C, win, sa); + return OPERATOR_FINISHED; + } + + return OPERATOR_PASS_THROUGH; +} + +void RENDER_OT_view_cancel(struct wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Cancel Render View"; + ot->description= "Cancel show render view"; + ot->idname= "RENDER_OT_view_cancel"; + + /* api callbacks */ + ot->exec= render_view_cancel_exec; + ot->poll= ED_operator_image_active; +} + +/* *********************** show render viewer *************** */ + +static int render_view_show_invoke(bContext *C, wmOperator *unused, wmEvent *event) +{ + ScrArea *sa= find_area_showing_r_result(C); + + /* test if we have a temp screen in front */ + if(CTX_wm_window(C)->screen->full==SCREENTEMP) { + wm_window_lower(CTX_wm_window(C)); + } + /* determine if render already shows */ + else if(sa) { + SpaceImage *sima= sa->spacedata.first; + + if(sima->flag & SI_PREVSPACE) { + sima->flag &= ~SI_PREVSPACE; + + if(sima->flag & SI_FULLWINDOW) { + sima->flag &= ~SI_FULLWINDOW; + ED_screen_full_prevspace(C, sa); + } + else if(sima->next) { + ED_area_newspace(C, sa, sima->next->spacetype); + ED_area_tag_redraw(sa); + } + } + } + else { + screen_set_image_output(C, event->x, event->y); + } + + return OPERATOR_FINISHED; +} + +void RENDER_OT_view_show(struct wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Show/Hide Render View"; + ot->description= "Toggle show render view"; + ot->idname= "RENDER_OT_view_show"; + + /* api callbacks */ + ot->invoke= render_view_show_invoke; + ot->poll= ED_operator_screenactive; +} diff --git a/source/blender/editors/render/render_opengl.c b/source/blender/editors/render/render_opengl.c new file mode 100644 index 00000000000..7916f29043f --- /dev/null +++ b/source/blender/editors/render/render_opengl.c @@ -0,0 +1,470 @@ +/** + * $Id: + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2008 Blender Foundation. + * All rights reserved. + * + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include <math.h> +#include <string.h> +#include <stddef.h> + +#include <GL/glew.h> + +#include "MEM_guardedalloc.h" + +#include "BLI_math.h" +#include "BLI_blenlib.h" +#include "BLI_editVert.h" +#include "BLI_dlrbTree.h" + +#include "DNA_armature_types.h" +#include "DNA_image_types.h" +#include "DNA_lattice_types.h" +#include "DNA_object_types.h" +#include "DNA_mesh_types.h" +#include "DNA_curve_types.h" +#include "DNA_scene_types.h" +#include "DNA_meta_types.h" +#include "DNA_view3d_types.h" + +#include "BKE_blender.h" +#include "BKE_colortools.h" +#include "BKE_context.h" +#include "BKE_customdata.h" +#include "BKE_global.h" +#include "BKE_image.h" +#include "BKE_idprop.h" +#include "BKE_library.h" +#include "BKE_main.h" +#include "BKE_mesh.h" +#include "BKE_multires.h" +#include "BKE_report.h" +#include "BKE_scene.h" +#include "BKE_screen.h" +#include "BKE_utildefines.h" +#include "BKE_sound.h" +#include "BKE_writeavi.h" + +#include "WM_api.h" +#include "WM_types.h" + +#include "ED_util.h" +#include "ED_screen.h" +#include "ED_mesh.h" +#include "ED_object.h" +#include "ED_screen_types.h" +#include "ED_keyframes_draw.h" +#include "ED_view3d.h" + +#include "RE_pipeline.h" +#include "IMB_imbuf.h" +#include "IMB_imbuf_types.h" + +#include "RNA_access.h" +#include "RNA_define.h" + +#include "UI_interface.h" +#include "UI_resources.h" + +#include "GPU_extensions.h" + +#include "wm_window.h" + +#include "render_intern.h" + +typedef struct OGLRender { + Render *re; + Scene *scene; + + View3D *v3d; + RegionView3D *rv3d; + ARegion *ar; + + Image *ima; + ImageUser iuser; + + GPUOffScreen *ofs; + int sizex, sizey; + + ReportList *reports; + bMovieHandle *mh; + int cfrao, nfra; + + wmTimer *timer; /* use to check if running modal or not (invoke'd or exec'd)*/ +} OGLRender; + +static void screen_opengl_render_apply(OGLRender *oglrender) +{ + Scene *scene= oglrender->scene; + ARegion *ar= oglrender->ar; + View3D *v3d= oglrender->v3d; + RegionView3D *rv3d= oglrender->rv3d; + RenderResult *rr; + ImBuf *ibuf; + void *lock; + float winmat[4][4]; + int sizex= oglrender->sizex; + int sizey= oglrender->sizey; + + /* bind */ + GPU_offscreen_bind(oglrender->ofs); + + /* render 3d view */ + if(rv3d->persp==RV3D_CAMOB && v3d->camera) { + RE_GetCameraWindow(oglrender->re, v3d->camera, scene->r.cfra, winmat); + ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, NULL, winmat); + } + else + ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, NULL, NULL); + + /* read in pixels & stamp */ + rr= RE_AcquireResultRead(oglrender->re); + glReadPixels(0, 0, sizex, sizey, GL_RGBA, GL_FLOAT, rr->rectf); + if((scene->r.stamp & R_STAMP_ALL) && (scene->r.stamp & R_STAMP_DRAW)) + BKE_stamp_buf(scene, NULL, rr->rectf, rr->rectx, rr->recty, 4); + RE_ReleaseResult(oglrender->re); + + /* 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); + BKE_image_release_ibuf(oglrender->ima, lock); + + /* unbind */ + GPU_offscreen_unbind(oglrender->ofs); +} + +static int screen_opengl_render_init(bContext *C, wmOperator *op) +{ + /* new render clears all callbacks */ + Scene *scene= CTX_data_scene(C); + RenderResult *rr; + GPUOffScreen *ofs; + OGLRender *oglrender; + int sizex, sizey; + + /* ensure we have a 3d view */ + if(!ED_view3d_context_activate(C)) + return 0; + + /* only one render job at a time */ + if(WM_jobs_test(CTX_wm_manager(C), scene)) + return 0; + + /* stop all running jobs, currently previews frustrate Render */ + WM_jobs_stop_all(CTX_wm_manager(C)); + + /* handle UI stuff */ + WM_cursor_wait(1); + + /* create offscreen buffer */ + sizex= (scene->r.size*scene->r.xsch)/100; + sizey= (scene->r.size*scene->r.ysch)/100; + + view3d_operator_needs_opengl(C); + ofs= GPU_offscreen_create(sizex, sizey); + + if(!ofs) { + BKE_report(op->reports, RPT_ERROR, "Failed to create OpenGL offscreen buffer."); + return 0; + } + + /* allocate opengl render */ + oglrender= MEM_callocN(sizeof(OGLRender), "OGLRender"); + op->customdata= oglrender; + + oglrender->ofs= ofs; + oglrender->sizex= sizex; + oglrender->sizey= sizey; + oglrender->scene= scene; + + oglrender->v3d= CTX_wm_view3d(C); + oglrender->ar= CTX_wm_region(C); + oglrender->rv3d= CTX_wm_region_view3d(C); + + /* create image and image user */ + oglrender->ima= BKE_image_verify_viewer(IMA_TYPE_R_RESULT, "Render Result"); + BKE_image_signal(oglrender->ima, NULL, IMA_SIGNAL_FREE); + + oglrender->iuser.scene= scene; + oglrender->iuser.ok= 1; + + /* create render and render result */ + oglrender->re= RE_NewRender(scene->id.name, RE_SLOT_VIEW); + RE_InitState(oglrender->re, NULL, &scene->r, NULL, sizex, sizey, NULL); + + rr= RE_AcquireResultWrite(oglrender->re); + if(rr->rectf==NULL) + rr->rectf= MEM_mallocN(sizeof(float)*4*sizex*sizey, "32 bits rects"); + RE_ReleaseResult(oglrender->re); + + return 1; +} + +static void screen_opengl_render_end(bContext *C, OGLRender *oglrender) +{ + Scene *scene= oglrender->scene; + + if(oglrender->mh) { + if(BKE_imtype_is_movie(scene->r.imtype)) + oglrender->mh->end_movie(); + } + + if(oglrender->timer) { /* exec will not have a timer */ + scene->r.cfra= oglrender->cfrao; + scene_update_for_newframe(scene, scene->lay); + + WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), oglrender->timer); + } + + WM_cursor_wait(0); + WM_event_add_notifier(C, NC_SCENE|ND_RENDER_RESULT, oglrender->scene); + + GPU_offscreen_free(oglrender->ofs); + + MEM_freeN(oglrender); +} + +static int screen_opengl_render_cancel(bContext *C, wmOperator *op) +{ + screen_opengl_render_end(C, op->customdata); + + return OPERATOR_CANCELLED; +} + +/* 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; + ImBuf *ibuf; + void *lock; + char name[FILE_MAXDIR+FILE_MAXFILE]; + unsigned int lay; + int ok= 0; + + /* 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) { + /* since scene_update_for_newframe() is used rather + * then ED_update_for_newframe() the camera needs to be set */ + Object *camera= scene_find_camera_switch(scene); + + if(camera) + oglrender->v3d->camera= scene->camera= camera; + } + + /* render into offscreen buffer */ + screen_opengl_render_apply(oglrender); + + /* save to disk */ + ibuf= BKE_image_acquire_ibuf(oglrender->ima, &oglrender->iuser, &lock); + + if(ibuf) { + if(BKE_imtype_is_movie(scene->r.imtype)) { + ok= oglrender->mh->append_movie(&scene->r, CFRA, (int*)ibuf->rect, oglrender->sizex, oglrender->sizey, oglrender->reports); + if(ok) { + printf("Append frame %d", scene->r.cfra); + BKE_reportf(op->reports, RPT_INFO, "Appended frame: %d", scene->r.cfra); + } + } + else { + BKE_makepicstring(name, scene->r.pic, scene->r.cfra, scene->r.imtype, scene->r.scemode & R_EXTENSION); + ok= BKE_write_ibuf(scene, ibuf, name, scene->r.imtype, scene->r.subimtype, scene->r.quality); + + if(ok==0) { + printf("Write error: cannot save %s\n", name); + BKE_reportf(op->reports, RPT_ERROR, "Write error: cannot save %s", name); + } + else { + printf("Saved: %s", name); + BKE_reportf(op->reports, RPT_INFO, "Saved file: %s", name); + } + } + } + + BKE_image_release_ibuf(oglrender->ima, lock); + + /* movie stats prints have no line break */ + printf("\n"); + + /* go to next frame */ + oglrender->nfra += scene->r.frame_step; + scene->r.cfra++; + + /* 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; + } + + return OPERATOR_RUNNING_MODAL; +} + +static int screen_opengl_render_invoke(bContext *C, wmOperator *op, wmEvent *event) +{ + int anim= RNA_boolean_get(op->ptr, "animation"); + + if(!screen_opengl_render_init(C, op)) + return OPERATOR_CANCELLED; + + if(!anim) { + /* render image */ + screen_opengl_render_apply(op->customdata); + screen_opengl_render_end(C, op->customdata); + screen_set_image_output(C, event->x, event->y); + + return OPERATOR_FINISHED; + } + else { + 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); + + 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; +} + +void RENDER_OT_opengl(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "OpenGL Render"; + ot->description= "OpenGL render active viewport"; + ot->idname= "RENDER_OT_opengl"; + + /* 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; + + ot->poll= ED_operator_screenactive; + + RNA_def_boolean(ot->srna, "animation", 0, "Animation", ""); +} diff --git a/source/blender/editors/render/render_ops.c b/source/blender/editors/render/render_ops.c index 62fb48c34ff..e23531d3c8f 100644 --- a/source/blender/editors/render/render_ops.c +++ b/source/blender/editors/render/render_ops.c @@ -64,5 +64,13 @@ void ED_operatortypes_render(void) #endif WM_operatortype_append(TEXTURE_OT_slot_move); + + /* render_internal.c */ + WM_operatortype_append(RENDER_OT_view_show); + WM_operatortype_append(RENDER_OT_render); + WM_operatortype_append(RENDER_OT_view_cancel); + + /* render_opengl.c */ + WM_operatortype_append(RENDER_OT_opengl); } diff --git a/source/blender/editors/screen/screen_edit.c b/source/blender/editors/screen/screen_edit.c index 7b7329aee0b..180bbb3ea58 100644 --- a/source/blender/editors/screen/screen_edit.c +++ b/source/blender/editors/screen/screen_edit.c @@ -1441,8 +1441,76 @@ void ED_screen_delete_scene(bContext *C, Scene *scene) unlink_scene(bmain, scene, newscene); } +int ED_screen_full_newspace(bContext *C, ScrArea *sa, int type) +{ + wmWindow *win= CTX_wm_window(C); + bScreen *screen= CTX_wm_screen(C); + ScrArea *newsa= NULL; + + if(!sa || sa->full==0) { + newsa= ED_screen_full_toggle(C, win, sa); + } + + if(!newsa) { + if (sa->full) { + /* if this has been called from the temporary info header generated in + * temp fullscreen layouts, find the correct fullscreen area to change + * to create a new space inside */ + for (newsa = screen->areabase.first; newsa; newsa=newsa->next) { + if (!(sa->flag & AREA_TEMP_INFO)) + break; + } + } else + newsa= sa; + } + + ED_area_newspace(C, newsa, type); + + return 1; +} + +void ED_screen_full_prevspace(bContext *C, ScrArea *sa) +{ + wmWindow *win= CTX_wm_window(C); + + ED_area_prevspace(C, sa); + + if(sa->full) + ED_screen_full_toggle(C, win, sa); +} + +/* restore a screen / area back to default operation, after temp fullscreen modes */ +void ED_screen_full_restore(bContext *C, ScrArea *sa) +{ + wmWindow *win= CTX_wm_window(C); + SpaceLink *sl = sa->spacedata.first; + + /* if fullscreen area has a secondary space (such as as file browser or fullscreen render + * overlaid on top of a existing setup) then return to the previous space */ + + if (sl->next) { + /* specific checks for space types */ + if (sl->spacetype == SPACE_IMAGE) { + SpaceImage *sima= sa->spacedata.first; + if (sima->flag & SI_PREVSPACE) + sima->flag &= ~SI_PREVSPACE; + if (sima->flag & SI_FULLWINDOW) { + sima->flag &= ~SI_FULLWINDOW; + ED_screen_full_prevspace(C, sa); + } + } else if (sl->spacetype == SPACE_FILE) { + ED_screen_full_prevspace(C, sa); + } else + ED_screen_full_toggle(C, win, sa); + } + /* otherwise just tile the area again */ + else { + ED_screen_full_toggle(C, win, sa); + } +} + /* this function toggles: if area is full then the parent will be restored */ -ScrArea *ed_screen_fullarea(bContext *C, wmWindow *win, ScrArea *sa) +ScrArea *ED_screen_full_toggle(bContext *C, wmWindow *win, ScrArea *sa) { bScreen *sc, *oldscreen; ARegion *ar; @@ -1454,45 +1522,45 @@ ScrArea *ed_screen_fullarea(bContext *C, wmWindow *win, ScrArea *sa) for(ar=sa->regionbase.first; ar; ar=ar->next) uiFreeBlocks(C, &ar->uiblocks); } - + if(sa && sa->full) { short fulltype; - + sc= sa->full; /* the old screen to restore */ oldscreen= win->screen; /* the one disappearing */ - + fulltype = sc->full; - + /* refuse to go out of SCREENAUTOPLAY as long as G_FLAGS_AUTOPLAY is set */ - + if (fulltype != SCREENAUTOPLAY || (G.flags & G_FILE_AUTOPLAY) == 0) { ScrArea *old; - + sc->full= 0; - + /* find old area */ - for(old= sc->areabase.first; old; old= old->next) + for(old= sc->areabase.first; old; old= old->next) if(old->full) break; if(old==NULL) { if (G.f & G_DEBUG) - printf("something wrong in areafullscreen\n"); + printf("something wrong in areafullscreen\n"); return NULL; } // old feature described below (ton) - // in autoplay screens the headers are disabled by + // in autoplay screens the headers are disabled by // default. So use the old headertype instead - + area_copy_data(old, sa, 1); /* 1 = swap spacelist */ if (sa->flag & AREA_TEMP_INFO) sa->flag &= ~AREA_TEMP_INFO; old->full= NULL; - + /* animtimer back */ sc->animtimer= oldscreen->animtimer; oldscreen->animtimer= NULL; - + ED_screen_set(C, sc); - + free_screen(oldscreen); free_libblock(&CTX_data_main(C)->screen, oldscreen); } @@ -1500,7 +1568,7 @@ ScrArea *ed_screen_fullarea(bContext *C, wmWindow *win, ScrArea *sa) else { ScrArea *newa; char newname[20]; - + oldscreen= win->screen; /* nothing wrong with having only 1 area, as far as I can see... @@ -1508,20 +1576,20 @@ ScrArea *ed_screen_fullarea(bContext *C, wmWindow *win, ScrArea *sa) if(oldscreen->areabase.first==oldscreen->areabase.last) return NULL; */ - + oldscreen->full = SCREENFULL; BLI_snprintf(newname, sizeof(newname), "%s-%s", oldscreen->id.name+2, "temp"); sc= ED_screen_add(win, oldscreen->scene, newname); sc->full = SCREENFULL; // XXX - + /* timer */ sc->animtimer= oldscreen->animtimer; oldscreen->animtimer= NULL; - + /* returns the top small area */ newa= area_split(win, sc, (ScrArea *)sc->areabase.first, 'h', 0.99f); ED_area_newspace(C, newa, SPACE_INFO); - + /* use random area when we have no active one, e.g. when the mouse is outside of the window and we open a file browser */ if(!sa) @@ -1535,7 +1603,7 @@ ScrArea *ed_screen_fullarea(bContext *C, wmWindow *win, ScrArea *sa) sa->full= oldscreen; newa->full= oldscreen; newa->next->full= oldscreen; // XXX - + ED_screen_set(C, sc); } @@ -1547,74 +1615,6 @@ ScrArea *ed_screen_fullarea(bContext *C, wmWindow *win, ScrArea *sa) return sc->areabase.first; } -int ED_screen_full_newspace(bContext *C, ScrArea *sa, int type) -{ - wmWindow *win= CTX_wm_window(C); - bScreen *screen= CTX_wm_screen(C); - ScrArea *newsa= NULL; - - if(!sa || sa->full==0) { - newsa= ed_screen_fullarea(C, win, sa); - } - - if(!newsa) { - if (sa->full) { - /* if this has been called from the temporary info header generated in - * temp fullscreen layouts, find the correct fullscreen area to change - * to create a new space inside */ - for (newsa = screen->areabase.first; newsa; newsa=newsa->next) { - if (!(sa->flag & AREA_TEMP_INFO)) - break; - } - } else - newsa= sa; - } - - ED_area_newspace(C, newsa, type); - - return 1; -} - -void ED_screen_full_prevspace(bContext *C, ScrArea *sa) -{ - wmWindow *win= CTX_wm_window(C); - - ED_area_prevspace(C, sa); - - if(sa->full) - ed_screen_fullarea(C, win, sa); -} - -/* restore a screen / area back to default operation, after temp fullscreen modes */ -void ED_screen_full_restore(bContext *C, ScrArea *sa) -{ - wmWindow *win= CTX_wm_window(C); - SpaceLink *sl = sa->spacedata.first; - - /* if fullscreen area has a secondary space (such as as file browser or fullscreen render - * overlaid on top of a existing setup) then return to the previous space */ - - if (sl->next) { - /* specific checks for space types */ - if (sl->spacetype == SPACE_IMAGE) { - SpaceImage *sima= sa->spacedata.first; - if (sima->flag & SI_PREVSPACE) - sima->flag &= ~SI_PREVSPACE; - if (sima->flag & SI_FULLWINDOW) { - sima->flag &= ~SI_FULLWINDOW; - ED_screen_full_prevspace(C, sa); - } - } else if (sl->spacetype == SPACE_FILE) { - ED_screen_full_prevspace(C, sa); - } else - ed_screen_fullarea(C, win, sa); - } - /* otherwise just tile the area again */ - else { - ed_screen_fullarea(C, win, sa); - } -} - /* update frame rate info for viewport drawing */ void ED_refresh_viewport_fps(bContext *C) { diff --git a/source/blender/editors/screen/screen_intern.h b/source/blender/editors/screen/screen_intern.h index 147b4bd5780..96b547eff21 100644 --- a/source/blender/editors/screen/screen_intern.h +++ b/source/blender/editors/screen/screen_intern.h @@ -51,8 +51,6 @@ ScrEdge *screen_find_active_scredge(bScreen *sc, int mx, int my); AZone *is_in_area_actionzone(ScrArea *sa, int x, int y); -ScrArea *ed_screen_fullarea(bContext *C, wmWindow *win, ScrArea *sa); - /* screen_context.c */ void ed_screen_context(const bContext *C, const char *member, bContextDataResult *result); diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index 98cbd95b867..b22728a16b3 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -26,9 +26,6 @@ #include <math.h> #include <string.h> -#include <stddef.h> - -#include <GL/glew.h> #include "MEM_guardedalloc.h" @@ -38,21 +35,18 @@ #include "BLI_dlrbTree.h" #include "DNA_armature_types.h" -#include "DNA_image_types.h" #include "DNA_lattice_types.h" #include "DNA_object_types.h" #include "DNA_mesh_types.h" #include "DNA_curve_types.h" #include "DNA_scene_types.h" #include "DNA_meta_types.h" -#include "DNA_view3d_types.h" #include "BKE_blender.h" #include "BKE_colortools.h" #include "BKE_context.h" #include "BKE_customdata.h" #include "BKE_global.h" -#include "BKE_image.h" #include "BKE_idprop.h" #include "BKE_library.h" #include "BKE_main.h" @@ -63,7 +57,6 @@ #include "BKE_screen.h" #include "BKE_utildefines.h" #include "BKE_sound.h" -#include "BKE_writeavi.h" #include "WM_api.h" #include "WM_types.h" @@ -74,11 +67,6 @@ #include "ED_object.h" #include "ED_screen_types.h" #include "ED_keyframes_draw.h" -#include "ED_view3d.h" - -#include "RE_pipeline.h" -#include "IMB_imbuf.h" -#include "IMB_imbuf_types.h" #include "RNA_access.h" #include "RNA_define.h" @@ -86,8 +74,6 @@ #include "UI_interface.h" #include "UI_resources.h" -#include "GPU_extensions.h" - #include "wm_window.h" #include "screen_intern.h" /* own module include */ @@ -1697,7 +1683,7 @@ static void SCREEN_OT_screen_set(wmOperatorType *ot) /* function to be called outside UI context, or for redo */ static int screen_full_area_exec(bContext *C, wmOperator *op) { - ed_screen_fullarea(C, CTX_wm_window(C), CTX_wm_area(C)); + ED_screen_full_toggle(C, CTX_wm_window(C), CTX_wm_area(C)); return OPERATOR_FINISHED; } @@ -2702,1081 +2688,6 @@ static void SCREEN_OT_border_select(wmOperatorType *ot) } #endif -/* ****************************** render invoking ***************** */ - -/* set callbacks, exported to sequence render too. - Only call in foreground (UI) renders. */ - -/* returns biggest area that is not uv/image editor. Note that it uses buttons */ -/* window as the last possible alternative. */ -static ScrArea *biggest_non_image_area(bContext *C) -{ - bScreen *sc= CTX_wm_screen(C); - ScrArea *sa, *big= NULL; - int size, maxsize= 0, bwmaxsize= 0; - short foundwin= 0; - - for(sa= sc->areabase.first; sa; sa= sa->next) { - if(sa->winx > 30 && sa->winy > 30) { - size= sa->winx*sa->winy; - if(sa->spacetype == SPACE_BUTS) { - if(foundwin == 0 && size > bwmaxsize) { - bwmaxsize= size; - big= sa; - } - } - else if(sa->spacetype != SPACE_IMAGE && size > maxsize) { - maxsize= size; - big= sa; - foundwin= 1; - } - } - } - - return big; -} - -static ScrArea *biggest_area(bContext *C) -{ - bScreen *sc= CTX_wm_screen(C); - ScrArea *sa, *big= NULL; - int size, maxsize= 0; - - for(sa= sc->areabase.first; sa; sa= sa->next) { - size= sa->winx*sa->winy; - if(size > maxsize) { - maxsize= size; - big= sa; - } - } - return big; -} - - -static ScrArea *find_area_showing_r_result(bContext *C) -{ - wmWindowManager *wm= CTX_wm_manager(C); - wmWindow *win; - ScrArea *sa = NULL; - SpaceImage *sima; - - /* find an imagewindow showing render result */ - for(win=wm->windows.first; win; win=win->next) { - for(sa=win->screen->areabase.first; sa; sa= sa->next) { - if(sa->spacetype==SPACE_IMAGE) { - sima= sa->spacedata.first; - if(sima->image && sima->image->type==IMA_TYPE_R_RESULT) - break; - } - } - } - - return sa; -} - -static ScrArea *find_area_image_empty(bContext *C) -{ - bScreen *sc= CTX_wm_screen(C); - ScrArea *sa; - SpaceImage *sima; - - /* find an imagewindow showing render result */ - for(sa=sc->areabase.first; sa; sa= sa->next) { - if(sa->spacetype==SPACE_IMAGE) { - sima= sa->spacedata.first; - if(!sima->image) - break; - } - } - return sa; -} - -#if 0 // XXX not used -static ScrArea *find_empty_image_area(bContext *C) -{ - bScreen *sc= CTX_wm_screen(C); - ScrArea *sa; - SpaceImage *sima; - - /* find an imagewindow showing render result */ - for(sa=sc->areabase.first; sa; sa= sa->next) { - if(sa->spacetype==SPACE_IMAGE) { - sima= sa->spacedata.first; - if(!sima->image) - break; - } - } - return sa; -} -#endif // XXX not used - -/* new window uses x,y to set position */ -static void screen_set_image_output(bContext *C, int mx, int my) -{ - wmWindow *win= CTX_wm_window(C); - Scene *scene= CTX_data_scene(C); - ScrArea *sa= NULL; - SpaceImage *sima; - int area_was_image=0; - - if(scene->r.displaymode==R_OUTPUT_WINDOW) { - rcti rect; - int sizex, sizey; - - sizex= 10 + (scene->r.xsch*scene->r.size)/100; - sizey= 40 + (scene->r.ysch*scene->r.size)/100; - - /* arbitrary... miniature image window views don't make much sense */ - if(sizex < 320) sizex= 320; - if(sizey < 256) sizey= 256; - - /* XXX some magic to calculate postition */ - rect.xmin= mx + win->posx - sizex/2; - rect.ymin= my + win->posy - sizey/2; - rect.xmax= rect.xmin + sizex; - rect.ymax= rect.ymin + sizey; - - /* changes context! */ - WM_window_open_temp(C, &rect, WM_WINDOW_RENDER); - - sa= CTX_wm_area(C); - } - else if(scene->r.displaymode==R_OUTPUT_SCREEN) { - if (CTX_wm_area(C)->spacetype == SPACE_IMAGE) - area_was_image = 1; - - /* this function returns with changed context */ - ED_screen_full_newspace(C, CTX_wm_area(C), SPACE_IMAGE); - sa= CTX_wm_area(C); - } - - if(!sa) { - sa= find_area_showing_r_result(C); - if(sa==NULL) - sa= find_area_image_empty(C); - - if(sa==NULL) { - /* find largest open non-image area */ - sa= biggest_non_image_area(C); - if(sa) { - ED_area_newspace(C, sa, SPACE_IMAGE); - sima= sa->spacedata.first; - - /* makes ESC go back to prev space */ - sima->flag |= SI_PREVSPACE; - } - else { - /* use any area of decent size */ - sa= biggest_area(C); - if(sa->spacetype!=SPACE_IMAGE) { - // XXX newspace(sa, SPACE_IMAGE); - sima= sa->spacedata.first; - - /* makes ESC go back to prev space */ - sima->flag |= SI_PREVSPACE; - } - } - } - } - sima= sa->spacedata.first; - - /* get the correct image, and scale it */ - sima->image= BKE_image_verify_viewer(IMA_TYPE_R_RESULT, "Render Result"); - - - /* if we're rendering to full screen, set appropriate hints on image editor - * so it can restore properly on pressing esc */ - if(sa->full) { - sima->flag |= SI_FULLWINDOW; - - /* Tell the image editor to revert to previous space in space list on close - * _only_ if it wasn't already an image editor when the render was invoked */ - if (area_was_image == 0) - sima->flag |= SI_PREVSPACE; - else { - /* Leave it alone so the image editor will just go back from - * full screen to the original tiled setup */ - ; - } - - } - -} - -/* executes blocking render */ -static int screen_render_exec(bContext *C, wmOperator *op) -{ - Scene *scene= CTX_data_scene(C); - Render *re= RE_GetRender(scene->id.name, RE_SLOT_VIEW); - - if(re==NULL) { - re= RE_NewRender(scene->id.name, RE_SLOT_VIEW); - } - RE_test_break_cb(re, NULL, (int (*)(void *)) blender_test_break); - - if(RNA_boolean_get(op->ptr, "animation")) - RE_BlenderAnim(re, scene, scene->r.sfra, scene->r.efra, scene->r.frame_step, op->reports); - else - RE_BlenderFrame(re, scene, NULL, scene->r.cfra); - - // 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, scene); - - return OPERATOR_FINISHED; -} - -typedef struct RenderJob { - Scene *scene; - Render *re; - wmWindow *win; - SceneRenderLayer *srl; - int anim; - Image *image; - ImageUser iuser; - short *stop; - short *do_update; - ReportList *reports; -} RenderJob; - -static void render_freejob(void *rjv) -{ - RenderJob *rj= rjv; - - MEM_freeN(rj); -} - -/* str is IMA_RW_MAXTEXT in size */ -static void make_renderinfo_string(RenderStats *rs, Scene *scene, char *str) -{ - char info_time_str[32]; // used to be extern to header_info.c - uintptr_t mem_in_use, mmap_in_use; - float megs_used_memory, mmap_used_memory; - char *spos= str; - - mem_in_use= MEM_get_memory_in_use(); - mmap_in_use= MEM_get_mapped_memory_in_use(); - - megs_used_memory= (mem_in_use-mmap_in_use)/(1024.0*1024.0); - mmap_used_memory= (mmap_in_use)/(1024.0*1024.0); - - if(scene->lay & 0xFF000000) - spos+= sprintf(spos, "Localview | "); - else if(scene->r.scemode & R_SINGLE_LAYER) - spos+= sprintf(spos, "Single Layer | "); - - if(rs->statstr) { - spos+= sprintf(spos, "%s ", rs->statstr); - } - else { - spos+= sprintf(spos, "Fra:%d Ve:%d Fa:%d ", (scene->r.cfra), rs->totvert, rs->totface); - if(rs->tothalo) spos+= sprintf(spos, "Ha:%d ", rs->tothalo); - if(rs->totstrand) spos+= sprintf(spos, "St:%d ", rs->totstrand); - spos+= sprintf(spos, "La:%d Mem:%.2fM (%.2fM) ", rs->totlamp, megs_used_memory, mmap_used_memory); - - if(rs->curfield) - spos+= sprintf(spos, "Field %d ", rs->curfield); - if(rs->curblur) - spos+= sprintf(spos, "Blur %d ", rs->curblur); - } - - BLI_timestr(rs->lastframetime, info_time_str); - spos+= sprintf(spos, "Time:%s ", info_time_str); - - if(rs->infostr && rs->infostr[0]) - spos+= sprintf(spos, "| %s ", rs->infostr); - - /* very weak... but 512 characters is quite safe */ - if(spos >= str+IMA_RW_MAXTEXT) - if (G.f & G_DEBUG) - printf("WARNING! renderwin text beyond limit \n"); - -} - -static void image_renderinfo_cb(void *rjv, RenderStats *rs) -{ - RenderJob *rj= rjv; - - /* malloc OK here, stats_draw is not in tile threads */ - if(rj->image->render_text==NULL) - rj->image->render_text= MEM_callocN(IMA_RW_MAXTEXT, "rendertext"); - - make_renderinfo_string(rs, rj->scene, rj->image->render_text); - - /* make jobs timer to send notifier */ - *(rj->do_update)= 1; - -} - -/* called inside thread! */ -static void image_buffer_rect_update(Scene *scene, RenderResult *rr, ImBuf *ibuf, volatile rcti *renrect) -{ - float x1, y1, *rectf= NULL; - int ymin, ymax, xmin, xmax; - int rymin, rxmin; - char *rectc; - - /* if renrect argument, we only refresh scanlines */ - if(renrect) { - /* if ymax==recty, rendering of layer is ready, we should not draw, other things happen... */ - if(rr->renlay==NULL || renrect->ymax>=rr->recty) - return; - - /* xmin here is first subrect x coord, xmax defines subrect width */ - xmin = renrect->xmin + rr->crop; - xmax = renrect->xmax - xmin - rr->crop; - if (xmax<2) return; - - ymin= renrect->ymin + rr->crop; - ymax= renrect->ymax - ymin - rr->crop; - if(ymax<2) - return; - renrect->ymin= renrect->ymax; - - } - else { - xmin = ymin = rr->crop; - xmax = rr->rectx - 2*rr->crop; - ymax = rr->recty - 2*rr->crop; - } - - /* xmin ymin is in tile coords. transform to ibuf */ - rxmin= rr->tilerect.xmin + xmin; - if(rxmin >= ibuf->x) return; - rymin= rr->tilerect.ymin + ymin; - if(rymin >= ibuf->y) return; - - if(rxmin + xmax > ibuf->x) - xmax= ibuf->x - rxmin; - if(rymin + ymax > ibuf->y) - ymax= ibuf->y - rymin; - - if(xmax < 1 || ymax < 1) return; - - /* find current float rect for display, first case is after composit... still weak */ - if(rr->rectf) - rectf= rr->rectf; - else { - if(rr->rect32) - return; - else { - if(rr->renlay==NULL || rr->renlay->rectf==NULL) return; - rectf= rr->renlay->rectf; - } - } - if(rectf==NULL) return; - - if(ibuf->rect==NULL) - imb_addrectImBuf(ibuf); - - rectf+= 4*(rr->rectx*ymin + xmin); - rectc= (char *)(ibuf->rect + ibuf->x*rymin + rxmin); - - /* XXX make nice consistent functions for this */ - if (scene && (scene->r.color_mgt_flag & R_COLOR_MANAGEMENT)) { - for(y1= 0; y1<ymax; y1++) { - float *rf= rectf; - float srgb[3]; - char *rc= rectc; - - /* XXX temp. because crop offset */ - if( rectc >= (char *)(ibuf->rect)) { - for(x1= 0; x1<xmax; x1++, rf += 4, rc+=4) { - srgb[0]= linearrgb_to_srgb(rf[0]); - srgb[1]= linearrgb_to_srgb(rf[1]); - srgb[2]= linearrgb_to_srgb(rf[2]); - - rc[0]= FTOCHAR(srgb[0]); - rc[1]= FTOCHAR(srgb[1]); - rc[2]= FTOCHAR(srgb[2]); - rc[3]= FTOCHAR(rf[3]); - } - } - rectf += 4*rr->rectx; - rectc += 4*ibuf->x; - } - } else { - for(y1= 0; y1<ymax; y1++) { - float *rf= rectf; - char *rc= rectc; - - /* XXX temp. because crop offset */ - if( rectc >= (char *)(ibuf->rect)) { - for(x1= 0; x1<xmax; x1++, rf += 4, rc+=4) { - rc[0]= FTOCHAR(rf[0]); - rc[1]= FTOCHAR(rf[1]); - rc[2]= FTOCHAR(rf[2]); - rc[3]= FTOCHAR(rf[3]); - } - } - rectf += 4*rr->rectx; - rectc += 4*ibuf->x; - } - } - -} - -static void image_rect_update(void *rjv, RenderResult *rr, volatile rcti *renrect) -{ - RenderJob *rj= rjv; - ImBuf *ibuf; - void *lock; - - ibuf= BKE_image_acquire_ibuf(rj->image, &rj->iuser, &lock); - if(ibuf) { - image_buffer_rect_update(rj->scene, rr, ibuf, renrect); - - /* make jobs timer to send notifier */ - *(rj->do_update)= 1; - } - BKE_image_release_ibuf(rj->image, lock); -} - -static void render_startjob(void *rjv, short *stop, short *do_update) -{ - RenderJob *rj= rjv; -// Main *mainp= BKE_undo_get_main(&rj->scene); - - rj->stop= stop; - rj->do_update= do_update; - -#if defined(__APPLE__) && (PARALLEL == 1) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 2) - // Workaround for Apple gcc 4.2.1 omp vs background thread bug - pthread_setspecific (gomp_tls_key, thread_tls_data); -#endif - - if(rj->anim) - RE_BlenderAnim(rj->re, rj->scene, rj->scene->r.sfra, rj->scene->r.efra, rj->scene->r.frame_step, rj->reports); - else - RE_BlenderFrame(rj->re, rj->scene, rj->srl, rj->scene->r.cfra); - -// if(mainp) -// free_main(mainp); -} - -/* called by render, check job 'stop' value or the global */ -static int render_breakjob(void *rjv) -{ - RenderJob *rj= rjv; - - if(G.afbreek) - return 1; - if(rj->stop && *(rj->stop)) - return 1; - return 0; -} - -/* catch esc */ -static int screen_render_modal(bContext *C, wmOperator *op, wmEvent *event) -{ - /* no running blender, remove handler and pass through */ - if(0==WM_jobs_test(CTX_wm_manager(C), CTX_data_scene(C))) - return OPERATOR_FINISHED|OPERATOR_PASS_THROUGH; - - /* running render */ - switch (event->type) { - case ESCKEY: - return OPERATOR_RUNNING_MODAL; - break; - } - return OPERATOR_PASS_THROUGH; -} - -/* using context, starts job */ -static int screen_render_invoke(bContext *C, wmOperator *op, wmEvent *event) -{ - /* new render clears all callbacks */ - Scene *scene= CTX_data_scene(C); - SceneRenderLayer *srl=NULL; - Render *re; - wmJob *steve; - RenderJob *rj; - Image *ima; - - /* only one render job at a time */ - if(WM_jobs_test(CTX_wm_manager(C), scene)) - return OPERATOR_CANCELLED; - - /* stop all running jobs, currently previews frustrate Render */ - WM_jobs_stop_all(CTX_wm_manager(C)); - - /* handle UI stuff */ - WM_cursor_wait(1); - - /* flush multires changes (for sculpt) */ - multires_force_render_update(CTX_data_active_object(C)); - - /* get editmode results */ - ED_object_exit_editmode(C, EM_FREEDATA|EM_DO_UNDO); /* 0 = does not exit editmode */ - - // store spare - // get view3d layer, local layer, make this nice api call to render - // store spare - - /* ensure at least 1 area shows result */ - screen_set_image_output(C, event->x, event->y); - - /* single layer re-render */ - if(RNA_property_is_set(op->ptr, "layer")) { - SceneRenderLayer *rl; - Scene *scn; - char scene_name[19], rl_name[RE_MAXNAME]; - - RNA_string_get(op->ptr, "layer", rl_name); - RNA_string_get(op->ptr, "scene", scene_name); - - scn = (Scene *)BLI_findstring(&CTX_data_main(C)->scene, scene_name, offsetof(ID, name) + 2); - rl = (SceneRenderLayer *)BLI_findstring(&scene->r.layers, rl_name, offsetof(SceneRenderLayer, name)); - - if (scn && rl) { - scene = scn; - srl = rl; - } - } - - /* job custom data */ - rj= MEM_callocN(sizeof(RenderJob), "render job"); - rj->scene= scene; - rj->win= CTX_wm_window(C); - rj->srl = srl; - rj->anim= RNA_boolean_get(op->ptr, "animation"); - rj->iuser.scene= scene; - rj->iuser.ok= 1; - rj->reports= op->reports; - - /* setup job */ - steve= WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), scene, WM_JOB_EXCL_RENDER|WM_JOB_PRIORITY); - WM_jobs_customdata(steve, rj, render_freejob); - WM_jobs_timer(steve, 0.2, NC_SCENE|ND_RENDER_RESULT, 0); - WM_jobs_callbacks(steve, render_startjob, NULL, NULL); - -#if defined(__APPLE__) && (PARALLEL == 1) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 2) - // Workaround for Apple gcc 4.2.1 omp vs background thread bug - thread_tls_data = pthread_getspecific(gomp_tls_key); -#endif - - /* get a render result image, and make sure it is empty */ - ima= BKE_image_verify_viewer(IMA_TYPE_R_RESULT, "Render Result"); - BKE_image_signal(ima, NULL, IMA_SIGNAL_FREE); - rj->image= ima; - - /* setup new render */ - re= RE_NewRender(scene->id.name, RE_SLOT_VIEW); - RE_test_break_cb(re, rj, render_breakjob); - RE_display_draw_cb(re, rj, image_rect_update); - RE_stats_draw_cb(re, rj, image_renderinfo_cb); - - rj->re= re; - G.afbreek= 0; - - // BKE_report in render! - // RE_error_cb(re, error_cb); - - WM_jobs_start(CTX_wm_manager(C), steve); - - WM_cursor_wait(0); - WM_event_add_notifier(C, NC_SCENE|ND_RENDER_RESULT, scene); - - /* add modal handler for ESC */ - WM_event_add_modal_handler(C, op); - - return OPERATOR_RUNNING_MODAL; -} - - -/* contextual render, using current scene, view3d? */ -static void SCREEN_OT_render(wmOperatorType *ot) -{ - /* identifiers */ - ot->name= "Render"; - ot->description= "Render active scene"; - ot->idname= "SCREEN_OT_render"; - - /* api callbacks */ - ot->invoke= screen_render_invoke; - ot->modal= screen_render_modal; - ot->exec= screen_render_exec; - - ot->poll= ED_operator_screenactive; - - RNA_def_boolean(ot->srna, "animation", 0, "Animation", ""); - RNA_def_string(ot->srna, "layer", "", RE_MAXNAME, "Render Layer", "Single render layer to re-render"); - RNA_def_string(ot->srna, "scene", "", 19, "Scene", "Re-render single layer in this scene"); -} - -/* ****************************** opengl render *************************** */ - -typedef struct OGLRender { - Render *re; - Scene *scene; - - View3D *v3d; - RegionView3D *rv3d; - ARegion *ar; - - Image *ima; - ImageUser iuser; - - GPUOffScreen *ofs; - int sizex, sizey; - - ReportList *reports; - bMovieHandle *mh; - int cfrao, nfra; - - wmTimer *timer; /* use to check if running modal or not (invoke'd or exec'd)*/ -} OGLRender; - -static void screen_opengl_render_apply(OGLRender *oglrender) -{ - Scene *scene= oglrender->scene; - ARegion *ar= oglrender->ar; - View3D *v3d= oglrender->v3d; - RegionView3D *rv3d= oglrender->rv3d; - RenderResult *rr; - ImBuf *ibuf; - void *lock; - float winmat[4][4]; - int sizex= oglrender->sizex; - int sizey= oglrender->sizey; - - /* bind */ - GPU_offscreen_bind(oglrender->ofs); - - /* render 3d view */ - if(rv3d->persp==RV3D_CAMOB && v3d->camera) { - RE_GetCameraWindow(oglrender->re, v3d->camera, scene->r.cfra, winmat); - ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, NULL, winmat); - } - else - ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, NULL, NULL); - - /* read in pixels & stamp */ - rr= RE_AcquireResultRead(oglrender->re); - glReadPixels(0, 0, sizex, sizey, GL_RGBA, GL_FLOAT, rr->rectf); - if((scene->r.stamp & R_STAMP_ALL) && (scene->r.stamp & R_STAMP_DRAW)) - BKE_stamp_buf(scene, NULL, rr->rectf, rr->rectx, rr->recty, 4); - RE_ReleaseResult(oglrender->re); - - /* 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); - BKE_image_release_ibuf(oglrender->ima, lock); - - /* unbind */ - GPU_offscreen_unbind(oglrender->ofs); -} - -static int screen_opengl_render_init(bContext *C, wmOperator *op) -{ - /* new render clears all callbacks */ - Scene *scene= CTX_data_scene(C); - RenderResult *rr; - GPUOffScreen *ofs; - OGLRender *oglrender; - int sizex, sizey; - - /* ensure we have a 3d view */ - if(!ED_view3d_context_activate(C)) - return 0; - - /* only one render job at a time */ - if(WM_jobs_test(CTX_wm_manager(C), scene)) - return 0; - - /* stop all running jobs, currently previews frustrate Render */ - WM_jobs_stop_all(CTX_wm_manager(C)); - - /* handle UI stuff */ - WM_cursor_wait(1); - - /* create offscreen buffer */ - sizex= (scene->r.size*scene->r.xsch)/100; - sizey= (scene->r.size*scene->r.ysch)/100; - - view3d_operator_needs_opengl(C); - ofs= GPU_offscreen_create(sizex, sizey); - - if(!ofs) { - BKE_report(op->reports, RPT_ERROR, "Failed to create OpenGL offscreen buffer."); - return 0; - } - - /* allocate opengl render */ - oglrender= MEM_callocN(sizeof(OGLRender), "OGLRender"); - op->customdata= oglrender; - - oglrender->ofs= ofs; - oglrender->sizex= sizex; - oglrender->sizey= sizey; - oglrender->scene= scene; - - oglrender->v3d= CTX_wm_view3d(C); - oglrender->ar= CTX_wm_region(C); - oglrender->rv3d= CTX_wm_region_view3d(C); - - /* create image and image user */ - oglrender->ima= BKE_image_verify_viewer(IMA_TYPE_R_RESULT, "Render Result"); - BKE_image_signal(oglrender->ima, NULL, IMA_SIGNAL_FREE); - - oglrender->iuser.scene= scene; - oglrender->iuser.ok= 1; - - /* create render and render result */ - oglrender->re= RE_NewRender(scene->id.name, RE_SLOT_VIEW); - RE_InitState(oglrender->re, NULL, &scene->r, NULL, sizex, sizey, NULL); - - rr= RE_AcquireResultWrite(oglrender->re); - if(rr->rectf==NULL) - rr->rectf= MEM_mallocN(sizeof(float)*4*sizex*sizey, "32 bits rects"); - RE_ReleaseResult(oglrender->re); - - return 1; -} - -static void screen_opengl_render_end(bContext *C, OGLRender *oglrender) -{ - Scene *scene= oglrender->scene; - - if(oglrender->mh) { - if(BKE_imtype_is_movie(scene->r.imtype)) - oglrender->mh->end_movie(); - } - - if(oglrender->timer) { /* exec will not have a timer */ - scene->r.cfra= oglrender->cfrao; - scene_update_for_newframe(scene, scene->lay); - - WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), oglrender->timer); - } - - WM_cursor_wait(0); - WM_event_add_notifier(C, NC_SCENE|ND_RENDER_RESULT, oglrender->scene); - - GPU_offscreen_free(oglrender->ofs); - - MEM_freeN(oglrender); -} - -static int screen_opengl_render_cancel(bContext *C, wmOperator *op) -{ - screen_opengl_render_end(C, op->customdata); - - return OPERATOR_CANCELLED; -} - -/* 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; - ImBuf *ibuf; - void *lock; - char name[FILE_MAXDIR+FILE_MAXFILE]; - unsigned int lay; - int ok= 0; - - /* 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) { - /* since scene_update_for_newframe() is used rather - * then ED_update_for_newframe() the camera needs to be set */ - Object *camera= scene_find_camera_switch(scene); - - if(camera) - oglrender->v3d->camera= scene->camera= camera; - } - - /* render into offscreen buffer */ - screen_opengl_render_apply(oglrender); - - /* save to disk */ - ibuf= BKE_image_acquire_ibuf(oglrender->ima, &oglrender->iuser, &lock); - - if(ibuf) { - if(BKE_imtype_is_movie(scene->r.imtype)) { - ok= oglrender->mh->append_movie(&scene->r, CFRA, (int*)ibuf->rect, oglrender->sizex, oglrender->sizey, oglrender->reports); - if(ok) { - printf("Append frame %d", scene->r.cfra); - BKE_reportf(op->reports, RPT_INFO, "Appended frame: %d", scene->r.cfra); - } - } - else { - BKE_makepicstring(name, scene->r.pic, scene->r.cfra, scene->r.imtype, scene->r.scemode & R_EXTENSION); - ok= BKE_write_ibuf(scene, ibuf, name, scene->r.imtype, scene->r.subimtype, scene->r.quality); - - if(ok==0) { - printf("Write error: cannot save %s\n", name); - BKE_reportf(op->reports, RPT_ERROR, "Write error: cannot save %s", name); - } - else { - printf("Saved: %s", name); - BKE_reportf(op->reports, RPT_INFO, "Saved file: %s", name); - } - } - } - - BKE_image_release_ibuf(oglrender->ima, lock); - - /* movie stats prints have no line break */ - printf("\n"); - - /* go to next frame */ - oglrender->nfra += scene->r.frame_step; - scene->r.cfra++; - - /* 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; - } - - return OPERATOR_RUNNING_MODAL; -} - -static int screen_opengl_render_invoke(bContext *C, wmOperator *op, wmEvent *event) -{ - int anim= RNA_boolean_get(op->ptr, "animation"); - - if(!screen_opengl_render_init(C, op)) - return OPERATOR_CANCELLED; - - if(!anim) { - /* render image */ - screen_opengl_render_apply(op->customdata); - screen_opengl_render_end(C, op->customdata); - screen_set_image_output(C, event->x, event->y); - - return OPERATOR_FINISHED; - } - else { - 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); - - 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 */ - ot->name= "OpenGL Render"; - ot->description= "OpenGL render active viewport"; - ot->idname= "SCREEN_OT_opengl_render"; - - /* 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; - - ot->poll= ED_operator_screenactive; - - RNA_def_boolean(ot->srna, "animation", 0, "Animation", ""); -} - -/* *********************** cancel render viewer *************** */ - -static int render_view_cancel_exec(bContext *C, wmOperator *unused) -{ - wmWindow *win= CTX_wm_window(C); - ScrArea *sa= CTX_wm_area(C); - SpaceImage *sima= sa->spacedata.first; - - /* test if we have a temp screen in front */ - if(CTX_wm_window(C)->screen->full==SCREENTEMP) { - wm_window_lower(CTX_wm_window(C)); - return OPERATOR_FINISHED; - } - /* determine if render already shows */ - else if(sima->flag & SI_PREVSPACE) { - sima->flag &= ~SI_PREVSPACE; - - if(sima->flag & SI_FULLWINDOW) { - sima->flag &= ~SI_FULLWINDOW; - ED_screen_full_prevspace(C, sa); - } - else - ED_area_prevspace(C, sa); - - return OPERATOR_FINISHED; - } - else if(sima->flag & SI_FULLWINDOW) { - sima->flag &= ~SI_FULLWINDOW; - ed_screen_fullarea(C, win, sa); - return OPERATOR_FINISHED; - } - - return OPERATOR_PASS_THROUGH; -} - -static void SCREEN_OT_render_view_cancel(struct wmOperatorType *ot) -{ - /* identifiers */ - ot->name= "Cancel Render View"; - ot->description= "Cancel show render view"; - ot->idname= "SCREEN_OT_render_view_cancel"; - - /* api callbacks */ - ot->exec= render_view_cancel_exec; - ot->poll= ED_operator_image_active; -} - -/* *********************** show render viewer *************** */ - -static int render_view_show_invoke(bContext *C, wmOperator *unused, wmEvent *event) -{ - ScrArea *sa= find_area_showing_r_result(C); - - /* test if we have a temp screen in front */ - if(CTX_wm_window(C)->screen->full==SCREENTEMP) { - wm_window_lower(CTX_wm_window(C)); - } - /* determine if render already shows */ - else if(sa) { - SpaceImage *sima= sa->spacedata.first; - - if(sima->flag & SI_PREVSPACE) { - sima->flag &= ~SI_PREVSPACE; - - if(sima->flag & SI_FULLWINDOW) { - sima->flag &= ~SI_FULLWINDOW; - ED_screen_full_prevspace(C, sa); - } - else if(sima->next) { - ED_area_newspace(C, sa, sima->next->spacetype); - ED_area_tag_redraw(sa); - } - } - } - else { - screen_set_image_output(C, event->x, event->y); - } - - return OPERATOR_FINISHED; -} - -static void SCREEN_OT_render_view_show(struct wmOperatorType *ot) -{ - /* identifiers */ - ot->name= "Show/Hide Render View"; - ot->description= "Toggle show render view"; - ot->idname= "SCREEN_OT_render_view_show"; - - /* api callbacks */ - ot->invoke= render_view_show_invoke; - ot->poll= ED_operator_screenactive; -} - /* *********************** generic fullscreen 'back' button *************** */ @@ -4011,12 +2922,6 @@ void ED_operatortypes_screen(void) WM_operatortype_append(SCREEN_OT_animation_play); WM_operatortype_append(SCREEN_OT_animation_cancel); - /* render */ - WM_operatortype_append(SCREEN_OT_render); - WM_operatortype_append(SCREEN_OT_render_view_cancel); - WM_operatortype_append(SCREEN_OT_render_view_show); - WM_operatortype_append(SCREEN_OT_opengl_render); - /* new/delete */ WM_operatortype_append(SCREEN_OT_new); WM_operatortype_append(SCREEN_OT_delete); @@ -4118,10 +3023,10 @@ void ED_keymap_screen(wmKeyConfig *keyconf) /* render */ - WM_keymap_add_item(keymap, "SCREEN_OT_render", F12KEY, KM_PRESS, 0, 0); - RNA_boolean_set(WM_keymap_add_item(keymap, "SCREEN_OT_render", F12KEY, KM_PRESS, KM_CTRL, 0)->ptr, "animation", 1); - WM_keymap_add_item(keymap, "SCREEN_OT_render_view_cancel", ESCKEY, KM_PRESS, 0, 0); - WM_keymap_add_item(keymap, "SCREEN_OT_render_view_show", F11KEY, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "RENDER_OT_render", F12KEY, KM_PRESS, 0, 0); + RNA_boolean_set(WM_keymap_add_item(keymap, "RENDER_OT_render", F12KEY, KM_PRESS, KM_CTRL, 0)->ptr, "animation", 1); + WM_keymap_add_item(keymap, "RENDER_OT_view_cancel", ESCKEY, KM_PRESS, 0, 0); + WM_keymap_add_item(keymap, "RENDER_OT_view_show", F11KEY, KM_PRESS, 0, 0); WM_keymap_add_item(keymap, "SCREEN_OT_play_rendered_anim", F11KEY, KM_PRESS, KM_CTRL, 0); /* user prefs */ diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c index 9f02702372f..a110e7a5c4b 100644 --- a/source/blender/editors/space_node/drawnode.c +++ b/source/blender/editors/space_node/drawnode.c @@ -527,10 +527,10 @@ static void node_composit_buts_renderlayers(uiLayout *layout, bContext *C, Point scn_ptr = RNA_pointer_get(ptr, "scene"); RNA_string_get(&scn_ptr, "name", scene_name); - WM_operator_properties_create(&op_ptr, "SCREEN_OT_render"); + WM_operator_properties_create(&op_ptr, "RENDER_OT_render"); RNA_string_set(&op_ptr, "layer", layer_name); RNA_string_set(&op_ptr, "scene", scene_name); - uiItemFullO(row, "", ICON_RENDER_STILL, "SCREEN_OT_render", op_ptr.data, WM_OP_INVOKE_DEFAULT, 0); + uiItemFullO(row, "", ICON_RENDER_STILL, "RENDER_OT_render", op_ptr.data, WM_OP_INVOKE_DEFAULT, 0); } |