| 
									
										
										
										
											2011-02-23 10:52:22 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  |  * ***** 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 ***** | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-27 20:29:51 +00:00
										 |  |  | /** \file blender/editors/render/render_internal.c
 | 
					
						
							|  |  |  |  *  \ingroup edrend | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | #include <math.h>
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							|  |  |  | #include <stddef.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "MEM_guardedalloc.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BLI_blenlib.h"
 | 
					
						
							| 
									
										
										
										
											2010-03-28 13:45:19 +00:00
										 |  |  | #include "BLI_math.h"
 | 
					
						
							|  |  |  | #include "BLI_threads.h"
 | 
					
						
							| 
									
										
										
										
											2010-04-21 02:48:49 +00:00
										 |  |  | #include "BLI_rand.h"
 | 
					
						
							| 
									
										
										
										
											2011-01-07 18:36:47 +00:00
										 |  |  | #include "BLI_utildefines.h"
 | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "DNA_scene_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BKE_blender.h"
 | 
					
						
							|  |  |  | #include "BKE_context.h"
 | 
					
						
							|  |  |  | #include "BKE_global.h"
 | 
					
						
							|  |  |  | #include "BKE_image.h"
 | 
					
						
							| 
									
										
										
										
											2010-08-13 14:29:56 +00:00
										 |  |  | #include "BKE_library.h"
 | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | #include "BKE_main.h"
 | 
					
						
							| 
									
										
										
										
											2010-12-17 17:06:36 +00:00
										 |  |  | #include "BKE_node.h"
 | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | #include "BKE_multires.h"
 | 
					
						
							|  |  |  | #include "BKE_report.h"
 | 
					
						
							| 
									
										
										
										
											2010-08-08 16:47:58 +00:00
										 |  |  | #include "BKE_sequencer.h"
 | 
					
						
							| 
									
										
										
										
											2011-03-25 17:11:32 +00:00
										 |  |  | #include "BKE_screen.h"
 | 
					
						
							| 
									
										
										
										
											2011-04-19 06:37:29 +00:00
										 |  |  | #include "BKE_scene.h"
 | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "WM_api.h"
 | 
					
						
							|  |  |  | #include "WM_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "ED_screen.h"
 | 
					
						
							|  |  |  | #include "ED_object.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "RE_pipeline.h"
 | 
					
						
							|  |  |  | #include "IMB_imbuf.h"
 | 
					
						
							|  |  |  | #include "IMB_imbuf_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "RNA_access.h"
 | 
					
						
							|  |  |  | #include "RNA_define.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "wm_window.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "render_intern.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-19 11:34:11 +00:00
										 |  |  | /* Render Callbacks */ | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* called inside thread! */ | 
					
						
							|  |  |  | void image_buffer_rect_update(Scene *scene, RenderResult *rr, ImBuf *ibuf, volatile rcti *renrect) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	float *rectf = NULL; | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 	int ymin, ymax, xmin, xmax; | 
					
						
							| 
									
										
										
										
											2011-12-28 13:29:33 +00:00
										 |  |  | 	int rymin, rxmin, predivide, profile_from; | 
					
						
							|  |  |  | 	unsigned char *rectc; | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* if renrect argument, we only refresh scanlines */ | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (renrect) { | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 		/* if ymax==recty, rendering of layer is ready, we should not draw, other things happen... */ | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 		if (rr->renlay == NULL || renrect->ymax >= rr->recty) | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 			return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* xmin here is first subrect x coord, xmax defines subrect width */ | 
					
						
							|  |  |  | 		xmin = renrect->xmin + rr->crop; | 
					
						
							| 
									
										
										
										
											2010-04-15 10:28:32 +00:00
										 |  |  | 		xmax = renrect->xmax - xmin + rr->crop; | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 		if (xmax < 2) | 
					
						
							| 
									
										
										
										
											2011-05-19 11:34:11 +00:00
										 |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 		ymin = renrect->ymin + rr->crop; | 
					
						
							|  |  |  | 		ymax = renrect->ymax - ymin + rr->crop; | 
					
						
							|  |  |  | 		if (ymax < 2) | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2012-03-24 02:51:46 +00:00
										 |  |  | 		renrect->ymin = renrect->ymax; | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		xmin = ymin = rr->crop; | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 		xmax = rr->rectx - 2 * rr->crop; | 
					
						
							|  |  |  | 		ymax = rr->recty - 2 * rr->crop; | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* xmin ymin is in tile coords. transform to ibuf */ | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	rxmin = rr->tilerect.xmin + xmin; | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (rxmin >= ibuf->x) return; | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	rymin = rr->tilerect.ymin + ymin; | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (rymin >= ibuf->y) return; | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (rxmin + xmax > ibuf->x) | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 		xmax = ibuf->x - rxmin; | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (rymin + ymax > ibuf->y) | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 		ymax = ibuf->y - rymin; | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (xmax < 1 || ymax < 1) return; | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-01 12:20:18 +00:00
										 |  |  | 	/* find current float rect for display, first case is after composite... still weak */ | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (rr->rectf) | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 		rectf = rr->rectf; | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 		if (rr->rect32) | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 			return; | 
					
						
							|  |  |  | 		else { | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 			if (rr->renlay == NULL || rr->renlay->rectf == NULL) return; | 
					
						
							|  |  |  | 			rectf = rr->renlay->rectf; | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	if (rectf == NULL) return; | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	if (ibuf->rect == NULL) | 
					
						
							| 
									
										
										
										
											2010-04-01 12:51:24 +00:00
										 |  |  | 		imb_addrectImBuf(ibuf); | 
					
						
							| 
									
										
										
										
											2010-04-21 02:48:49 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	rectf += 4 * (rr->rectx * ymin + xmin); | 
					
						
							|  |  |  | 	rectc = (unsigned char *)(ibuf->rect + ibuf->x * rymin + rxmin); | 
					
						
							| 
									
										
										
										
											2011-05-19 11:34:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (scene && (scene->r.color_mgt_flag & R_COLOR_MANAGEMENT)) { | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 		profile_from = IB_PROFILE_LINEAR_RGB; | 
					
						
							|  |  |  | 		predivide = (scene->r.color_mgt_flag & R_COLOR_MANAGEMENT_PREDIVIDE); | 
					
						
							| 
									
										
										
										
											2011-12-30 14:17:11 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 		profile_from = IB_PROFILE_SRGB; | 
					
						
							|  |  |  | 		predivide = 0; | 
					
						
							| 
									
										
										
										
											2011-12-30 14:17:11 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-28 13:29:33 +00:00
										 |  |  | 	IMB_buffer_byte_from_float(rectc, rectf, | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	                           4, ibuf->dither, IB_PROFILE_SRGB, profile_from, predivide, | 
					
						
							|  |  |  | 	                           xmax, ymax, ibuf->x, rr->rectx); | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ****************************** render invoking ***************** */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* set callbacks, exported to sequence render too.
 | 
					
						
							| 
									
										
										
										
											2012-03-03 16:31:46 +00:00
										 |  |  |  * Only call in foreground (UI) renders. */ | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-23 17:52:20 +00:00
										 |  |  | static void screen_render_scene_layer_set(wmOperator *op, Main *mainp, Scene **scene, SceneRenderLayer **srl) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* single layer re-render */ | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (RNA_struct_property_is_set(op->ptr, "scene")) { | 
					
						
							| 
									
										
										
										
											2011-10-23 17:52:20 +00:00
										 |  |  | 		Scene *scn; | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 		char scene_name[MAX_ID_NAME - 2]; | 
					
						
							| 
									
										
										
										
											2011-10-23 17:52:20 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		RNA_string_get(op->ptr, "scene", scene_name); | 
					
						
							|  |  |  | 		scn = (Scene *)BLI_findstring(&mainp->scene, scene_name, offsetof(ID, name) + 2); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		if (scn) { | 
					
						
							|  |  |  | 			/* camera switch wont have updated */ | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 			scn->r.cfra = (*scene)->r.cfra; | 
					
						
							| 
									
										
										
										
											2012-05-05 14:33:36 +00:00
										 |  |  | 			BKE_scene_camera_switch_update(scn); | 
					
						
							| 
									
										
										
										
											2011-10-23 17:52:20 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			*scene = scn; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (RNA_struct_property_is_set(op->ptr, "layer")) { | 
					
						
							| 
									
										
										
										
											2011-10-23 17:52:20 +00:00
										 |  |  | 		SceneRenderLayer *rl; | 
					
						
							|  |  |  | 		char rl_name[RE_MAXNAME]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		RNA_string_get(op->ptr, "layer", rl_name); | 
					
						
							|  |  |  | 		rl = (SceneRenderLayer *)BLI_findstring(&(*scene)->r.layers, rl_name, offsetof(SceneRenderLayer, name)); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		if (rl) | 
					
						
							|  |  |  | 			*srl = rl; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | /* executes blocking render */ | 
					
						
							|  |  |  | static int screen_render_exec(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	Scene *scene = CTX_data_scene(C); | 
					
						
							|  |  |  | 	SceneRenderLayer *srl = NULL; | 
					
						
							| 
									
										
										
										
											2011-11-01 14:51:44 +00:00
										 |  |  | 	Render *re; | 
					
						
							| 
									
										
										
										
											2010-03-27 15:35:34 +00:00
										 |  |  | 	Image *ima; | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	View3D *v3d = CTX_wm_view3d(C); | 
					
						
							|  |  |  | 	Main *mainp = CTX_data_main(C); | 
					
						
							| 
									
										
										
										
											2011-11-01 14:51:44 +00:00
										 |  |  | 	unsigned int lay; | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	const short is_animation = RNA_boolean_get(op->ptr, "animation"); | 
					
						
							|  |  |  | 	const short is_write_still = RNA_boolean_get(op->ptr, "write_still"); | 
					
						
							|  |  |  | 	struct Object *camera_override = v3d ? V3D_CAMERA_LOCAL(v3d) : NULL; | 
					
						
							| 
									
										
										
										
											2010-11-16 14:40:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-01 14:51:44 +00:00
										 |  |  | 	/* custom scene and single layer re-render */ | 
					
						
							|  |  |  | 	screen_render_scene_layer_set(op, mainp, &scene, &srl); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (!is_animation && is_write_still && BKE_imtype_is_movie(scene->r.im_format.imtype)) { | 
					
						
							| 
									
										
										
										
											2011-09-19 12:26:20 +00:00
										 |  |  | 		BKE_report(op->reports, RPT_ERROR, "Can't write a single file with an animation format selected"); | 
					
						
							| 
									
										
										
										
											2010-11-16 14:40:46 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	re = RE_NewRender(scene->id.name); | 
					
						
							|  |  |  | 	lay = (v3d) ? v3d->lay : scene->lay; | 
					
						
							| 
									
										
										
										
											2011-11-01 14:51:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-08 18:37:06 +00:00
										 |  |  | 	G.is_break = FALSE; | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	RE_test_break_cb(re, NULL, (int (*)(void *))blender_test_break); | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	ima = BKE_image_verify_viewer(IMA_TYPE_R_RESULT, "Render Result"); | 
					
						
							| 
									
										
										
										
											2010-03-27 15:35:34 +00:00
										 |  |  | 	BKE_image_signal(ima, NULL, IMA_SIGNAL_FREE); | 
					
						
							|  |  |  | 	BKE_image_backup_render(scene, ima); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-08 16:47:58 +00:00
										 |  |  | 	/* cleanup sequencer caches before starting user triggered render.
 | 
					
						
							| 
									
										
										
										
											2012-04-22 11:54:53 +00:00
										 |  |  | 	 * otherwise, invalidated cache entries can make their way into | 
					
						
							|  |  |  | 	 * the output rendering. We can't put that into RE_BlenderFrame, | 
					
						
							|  |  |  | 	 * since sequence rendering can call that recursively... (peter) */ | 
					
						
							| 
									
										
										
										
											2012-08-08 11:56:58 +00:00
										 |  |  | 	BKE_sequencer_cache_cleanup(); | 
					
						
							| 
									
										
										
										
											2010-08-08 16:47:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-28 16:25:07 +00:00
										 |  |  | 	RE_SetReports(re, op->reports); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (is_animation) | 
					
						
							| 
									
										
										
										
											2011-06-28 16:25:07 +00:00
										 |  |  | 		RE_BlenderAnim(re, mainp, scene, camera_override, lay, scene->r.sfra, scene->r.efra, scene->r.frame_step); | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2011-10-23 17:52:20 +00:00
										 |  |  | 		RE_BlenderFrame(re, mainp, scene, srl, camera_override, lay, scene->r.cfra, is_write_still); | 
					
						
							| 
									
										
										
										
											2010-08-01 12:47:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-28 16:25:07 +00:00
										 |  |  | 	RE_SetReports(re, NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 	// no redraw needed, we leave state as we entered it
 | 
					
						
							| 
									
										
										
										
											2012-05-25 12:37:11 +00:00
										 |  |  | 	ED_update_for_newframe(mainp, scene, 1); | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	WM_event_add_notifier(C, NC_SCENE | ND_RENDER_RESULT, scene); | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return OPERATOR_FINISHED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef struct RenderJob { | 
					
						
							| 
									
										
										
										
											2010-08-13 14:29:56 +00:00
										 |  |  | 	Main *main; | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 	Scene *scene; | 
					
						
							|  |  |  | 	Render *re; | 
					
						
							|  |  |  | 	wmWindow *win; | 
					
						
							|  |  |  | 	SceneRenderLayer *srl; | 
					
						
							| 
									
										
										
										
											2011-04-30 04:29:36 +00:00
										 |  |  | 	struct Object *camera_override; | 
					
						
							| 
									
										
										
										
											2010-03-14 20:24:11 +00:00
										 |  |  | 	int lay; | 
					
						
							| 
									
										
										
										
											2010-11-16 14:40:46 +00:00
										 |  |  | 	short anim, write_still; | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 	Image *image; | 
					
						
							|  |  |  | 	ImageUser iuser; | 
					
						
							|  |  |  | 	short *stop; | 
					
						
							|  |  |  | 	short *do_update; | 
					
						
							| 
									
										
										
										
											2010-05-27 08:22:16 +00:00
										 |  |  | 	float *progress; | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 	ReportList *reports; | 
					
						
							|  |  |  | } RenderJob; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void render_freejob(void *rjv) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	RenderJob *rj = rjv; | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	MEM_freeN(rj); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-27 15:35:34 +00:00
										 |  |  | /* str is IMA_MAX_RENDER_TEXT in size */ | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | static void make_renderinfo_string(RenderStats *rs, Scene *scene, char *str) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	char info_time_str[32]; // used to be extern to header_info.c
 | 
					
						
							| 
									
										
										
										
											2010-05-04 12:31:24 +00:00
										 |  |  | 	uintptr_t mem_in_use, mmap_in_use, peak_memory; | 
					
						
							|  |  |  | 	float megs_used_memory, mmap_used_memory, megs_peak_memory; | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	char *spos = str; | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	mem_in_use = MEM_get_memory_in_use(); | 
					
						
							|  |  |  | 	mmap_in_use = MEM_get_mapped_memory_in_use(); | 
					
						
							| 
									
										
										
										
											2010-05-04 12:31:24 +00:00
										 |  |  | 	peak_memory = MEM_get_peak_memory(); | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	megs_used_memory = (mem_in_use - mmap_in_use) / (1024.0 * 1024.0); | 
					
						
							|  |  |  | 	mmap_used_memory = (mmap_in_use) / (1024.0 * 1024.0); | 
					
						
							|  |  |  | 	megs_peak_memory = (peak_memory) / (1024.0 * 1024.0); | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (scene->lay & 0xFF000000) | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 		spos += sprintf(spos, "Localview | "); | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	else if (scene->r.scemode & R_SINGLE_LAYER) | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 		spos += sprintf(spos, "Single Layer | "); | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-04 16:09:51 +00:00
										 |  |  | 	spos += sprintf(spos, "Frame:%d ", (scene->r.cfra)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (rs->statstr) { | 
					
						
							| 
									
										
										
										
											2012-06-04 16:09:51 +00:00
										 |  |  | 		spos += sprintf(spos, "| %s ", rs->statstr); | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 		if (rs->totvert) spos += sprintf(spos, "Ve:%d ", rs->totvert); | 
					
						
							|  |  |  | 		if (rs->totface) spos += sprintf(spos, "Fa:%d ", rs->totface); | 
					
						
							|  |  |  | 		if (rs->tothalo) spos += sprintf(spos, "Ha:%d ", rs->tothalo); | 
					
						
							|  |  |  | 		if (rs->totstrand) spos += sprintf(spos, "St:%d ", rs->totstrand); | 
					
						
							|  |  |  | 		if (rs->totlamp) spos += sprintf(spos, "La:%d ", rs->totlamp); | 
					
						
							|  |  |  | 		spos += sprintf(spos, "Mem:%.2fM (%.2fM, peak %.2fM) ", megs_used_memory, mmap_used_memory, megs_peak_memory); | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 		if (rs->curfield) | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 			spos += sprintf(spos, "Field %d ", rs->curfield); | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 		if (rs->curblur) | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 			spos += sprintf(spos, "Blur %d ", rs->curblur); | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BLI_timestr(rs->lastframetime, info_time_str); | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	spos += sprintf(spos, "Time:%s ", info_time_str); | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (rs->curfsa) | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 		spos += sprintf(spos, "| Full Sample %d ", rs->curfsa); | 
					
						
							| 
									
										
										
										
											2011-06-12 13:35:17 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (rs->infostr && rs->infostr[0]) | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 		spos += sprintf(spos, "| %s ", rs->infostr); | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* very weak... but 512 characters is quite safe */ | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	if (spos >= str + IMA_MAX_RENDER_TEXT) | 
					
						
							| 
									
										
										
										
											2012-03-31 00:59:17 +00:00
										 |  |  | 		if (G.debug & G_DEBUG) | 
					
						
							|  |  |  | 			printf("WARNING! renderwin text beyond limit\n"); | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void image_renderinfo_cb(void *rjv, RenderStats *rs) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	RenderJob *rj = rjv; | 
					
						
							| 
									
										
										
										
											2010-03-27 15:35:34 +00:00
										 |  |  | 	RenderResult *rr; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	rr = RE_AcquireResultRead(rj->re); | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (rr) { | 
					
						
							| 
									
										
										
										
											2010-07-05 09:31:24 +00:00
										 |  |  | 		/* malloc OK here, stats_draw is not in tile threads */ | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 		if (rr->text == NULL) | 
					
						
							|  |  |  | 			rr->text = MEM_callocN(IMA_MAX_RENDER_TEXT, "rendertext"); | 
					
						
							| 
									
										
										
										
											2010-07-05 09:31:24 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		make_renderinfo_string(rs, rj->scene, rr->text); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-27 15:35:34 +00:00
										 |  |  | 	RE_ReleaseResult(rj->re); | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* make jobs timer to send notifier */ | 
					
						
							| 
									
										
										
										
											2012-05-19 13:28:19 +00:00
										 |  |  | 	*(rj->do_update) = TRUE; | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-27 08:22:16 +00:00
										 |  |  | static void render_progress_update(void *rjv, float progress) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	RenderJob *rj = rjv; | 
					
						
							| 
									
										
										
										
											2010-05-27 08:22:16 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (rj->progress && *rj->progress != progress) { | 
					
						
							| 
									
										
										
										
											2010-05-27 08:22:16 +00:00
										 |  |  | 		*rj->progress = progress; | 
					
						
							| 
									
										
										
										
											2011-12-07 11:29:24 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		/* make jobs timer to send notifier */ | 
					
						
							| 
									
										
										
										
											2012-05-19 13:28:19 +00:00
										 |  |  | 		*(rj->do_update) = TRUE; | 
					
						
							| 
									
										
										
										
											2011-12-07 11:29:24 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-05-27 08:22:16 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | static void image_rect_update(void *rjv, RenderResult *rr, volatile rcti *renrect) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	RenderJob *rj = rjv; | 
					
						
							|  |  |  | 	Image *ima = rj->image; | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 	ImBuf *ibuf; | 
					
						
							|  |  |  | 	void *lock; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-01 12:51:24 +00:00
										 |  |  | 	/* only update if we are displaying the slot being rendered */ | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (ima->render_slot != ima->last_render_slot) | 
					
						
							| 
									
										
										
										
											2010-04-01 12:51:24 +00:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	ibuf = BKE_image_acquire_ibuf(ima, &rj->iuser, &lock); | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (ibuf) { | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 		image_buffer_rect_update(rj->scene, rr, ibuf, renrect); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* make jobs timer to send notifier */ | 
					
						
							| 
									
										
										
										
											2012-05-19 13:28:19 +00:00
										 |  |  | 		*(rj->do_update) = TRUE; | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-04-01 12:51:24 +00:00
										 |  |  | 	BKE_image_release_ibuf(ima, lock); | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-27 08:22:16 +00:00
										 |  |  | static void render_startjob(void *rjv, short *stop, short *do_update, float *progress) | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	RenderJob *rj = rjv; | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	rj->stop = stop; | 
					
						
							|  |  |  | 	rj->do_update = do_update; | 
					
						
							|  |  |  | 	rj->progress = progress; | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-28 16:25:07 +00:00
										 |  |  | 	RE_SetReports(rj->re, rj->reports); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (rj->anim) | 
					
						
							| 
									
										
										
										
											2011-06-28 16:25:07 +00:00
										 |  |  | 		RE_BlenderAnim(rj->re, rj->main, rj->scene, rj->camera_override, rj->lay, rj->scene->r.sfra, rj->scene->r.efra, rj->scene->r.frame_step); | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2011-04-30 04:29:36 +00:00
										 |  |  | 		RE_BlenderFrame(rj->re, rj->main, rj->scene, rj->srl, rj->camera_override, rj->lay, rj->scene->r.cfra, rj->write_still); | 
					
						
							| 
									
										
										
										
											2011-06-28 16:25:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	RE_SetReports(rj->re, NULL); | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-15 10:28:32 +00:00
										 |  |  | static void render_endjob(void *rjv) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	RenderJob *rj = rjv; | 
					
						
							| 
									
										
										
										
											2010-11-03 11:14:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* this render may be used again by the sequencer without the active 'Render' where the callbacks
 | 
					
						
							|  |  |  | 	 * would be re-assigned. assign dummy callbacks to avoid referencing freed renderjobs bug [#24508] */ | 
					
						
							|  |  |  | 	RE_InitRenderCB(rj->re); | 
					
						
							| 
									
										
										
										
											2010-08-13 14:29:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (rj->main != G.main) | 
					
						
							| 
									
										
										
										
											2010-08-13 14:29:56 +00:00
										 |  |  | 		free_main(rj->main); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-02 09:34:32 +00:00
										 |  |  | 	/* else the frame will not update for the original value */ | 
					
						
							| 
									
										
										
										
											2012-06-01 15:05:30 +00:00
										 |  |  | 	if (!(rj->scene->r.scemode & R_NO_FRAME_UPDATE)) { | 
					
						
							|  |  |  | 		/* possible this fails of loading new file while rendering */ | 
					
						
							|  |  |  | 		if (G.main->wm.first) { | 
					
						
							|  |  |  | 			ED_update_for_newframe(G.main, rj->scene, 1); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-11-02 09:34:32 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2011-02-07 16:41:57 +00:00
										 |  |  | 	/* XXX above function sets all tags in nodes */ | 
					
						
							| 
									
										
										
										
											2011-10-19 17:08:35 +00:00
										 |  |  | 	ntreeCompositClearTags(rj->scene->nodetree); | 
					
						
							| 
									
										
										
										
											2011-02-07 16:41:57 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2011-02-07 18:09:27 +00:00
										 |  |  | 	/* potentially set by caller */ | 
					
						
							|  |  |  | 	rj->scene->r.scemode &= ~R_NO_FRAME_UPDATE; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (rj->srl) { | 
					
						
							| 
									
										
										
										
											2011-10-19 17:08:35 +00:00
										 |  |  | 		nodeUpdateID(rj->scene->nodetree, &rj->scene->id); | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 		WM_main_add_notifier(NC_NODE | NA_EDITED, rj->scene); | 
					
						
							| 
									
										
										
										
											2010-12-17 17:06:36 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2010-04-15 10:28:32 +00:00
										 |  |  | 	/* XXX render stability hack */ | 
					
						
							| 
									
										
										
										
											2012-08-08 18:37:06 +00:00
										 |  |  | 	G.is_rendering = FALSE; | 
					
						
							| 
									
										
										
										
											2010-04-15 10:28:32 +00:00
										 |  |  | 	WM_main_add_notifier(NC_WINDOW, NULL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | /* called by render, check job 'stop' value or the global */ | 
					
						
							|  |  |  | static int render_breakjob(void *rjv) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	RenderJob *rj = rjv; | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-08 18:37:06 +00:00
										 |  |  | 	if (G.is_break) | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 		return 1; | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (rj->stop && *(rj->stop)) | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 		return 1; | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-25 17:11:32 +00:00
										 |  |  | /* runs in thread, no cursor setting here works. careful with notifiers too (malloc conflicts) */ | 
					
						
							|  |  |  | /* maybe need a way to get job send notifer? */ | 
					
						
							|  |  |  | static void render_drawlock(void *UNUSED(rjv), int lock) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	BKE_spacedata_draw_locks(lock); | 
					
						
							| 
									
										
										
										
											2011-03-25 17:16:22 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2011-03-25 17:11:32 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | /* catch esc */ | 
					
						
							| 
									
										
										
										
											2012-08-01 19:22:04 +00:00
										 |  |  | static int screen_render_modal(bContext *C, wmOperator *op, wmEvent *event) | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-08-01 19:22:04 +00:00
										 |  |  | 	Scene *scene = (Scene *) op->customdata; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 	/* no running blender, remove handler and pass through */ | 
					
						
							| 
									
										
										
										
											2012-08-01 19:22:04 +00:00
										 |  |  | 	if (0 == WM_jobs_test(CTX_wm_manager(C), scene)) { | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 		return OPERATOR_FINISHED | OPERATOR_PASS_THROUGH; | 
					
						
							| 
									
										
										
										
											2010-04-15 10:28:32 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* 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 */ | 
					
						
							| 
									
										
										
										
											2010-08-13 14:29:56 +00:00
										 |  |  | 	Main *mainp; | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	Scene *scene = CTX_data_scene(C); | 
					
						
							|  |  |  | 	SceneRenderLayer *srl = NULL; | 
					
						
							|  |  |  | 	View3D *v3d = CTX_wm_view3d(C); | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 	Render *re; | 
					
						
							|  |  |  | 	wmJob *steve; | 
					
						
							|  |  |  | 	RenderJob *rj; | 
					
						
							|  |  |  | 	Image *ima; | 
					
						
							| 
									
										
										
										
											2011-02-07 16:41:57 +00:00
										 |  |  | 	int jobflag; | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	const short is_animation = RNA_boolean_get(op->ptr, "animation"); | 
					
						
							|  |  |  | 	const short is_write_still = RNA_boolean_get(op->ptr, "write_still"); | 
					
						
							|  |  |  | 	struct Object *camera_override = v3d ? V3D_CAMERA_LOCAL(v3d) : NULL; | 
					
						
							| 
									
										
										
										
											2011-11-03 17:06:12 +00:00
										 |  |  | 	const char *name; | 
					
						
							| 
									
										
										
										
											2010-11-16 14:40:46 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 	/* only one render job at a time */ | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (WM_jobs_test(CTX_wm_manager(C), scene)) | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (!RE_is_rendering_allowed(scene, camera_override, op->reports)) { | 
					
						
							| 
									
										
										
										
											2010-11-03 13:10:09 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (!is_animation && is_write_still && BKE_imtype_is_movie(scene->r.im_format.imtype)) { | 
					
						
							| 
									
										
										
										
											2011-09-19 12:26:20 +00:00
										 |  |  | 		BKE_report(op->reports, RPT_ERROR, "Can't write a single file with an animation format selected"); | 
					
						
							| 
									
										
										
										
											2010-11-16 14:40:46 +00:00
										 |  |  | 		return OPERATOR_CANCELLED; | 
					
						
							|  |  |  | 	}	 | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 	/* stop all running jobs, currently previews frustrate Render */ | 
					
						
							|  |  |  | 	WM_jobs_stop_all(CTX_wm_manager(C)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-13 14:29:56 +00:00
										 |  |  | 	/* get main */ | 
					
						
							| 
									
										
										
										
											2012-08-08 18:21:54 +00:00
										 |  |  | 	if (G.debug_value == 101) { | 
					
						
							| 
									
										
										
										
											2010-08-13 14:29:56 +00:00
										 |  |  | 		/* thread-safety experiment, copy main from the undo buffer */ | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 		mainp = BKE_undo_get_main(&scene); | 
					
						
							| 
									
										
										
										
											2010-08-13 14:29:56 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 		mainp = CTX_data_main(C); | 
					
						
							| 
									
										
										
										
											2010-08-13 14:29:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-05 07:57:05 +00:00
										 |  |  | 	/* cancel animation playback */ | 
					
						
							| 
									
										
										
										
											2012-05-25 12:56:29 +00:00
										 |  |  | 	if (ED_screen_animation_playing(CTX_wm_manager(C))) | 
					
						
							| 
									
										
										
										
											2010-07-19 11:25:23 +00:00
										 |  |  | 		ED_screen_animation_play(C, 0, 0); | 
					
						
							| 
									
										
										
										
											2010-04-05 07:57:05 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 	/* handle UI stuff */ | 
					
						
							|  |  |  | 	WM_cursor_wait(1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* flush multires changes (for sculpt) */ | 
					
						
							|  |  |  | 	multires_force_render_update(CTX_data_active_object(C)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-08 16:47:58 +00:00
										 |  |  | 	/* cleanup sequencer caches before starting user triggered render.
 | 
					
						
							| 
									
										
										
										
											2012-04-22 11:54:53 +00:00
										 |  |  | 	 * otherwise, invalidated cache entries can make their way into | 
					
						
							|  |  |  | 	 * the output rendering. We can't put that into RE_BlenderFrame, | 
					
						
							|  |  |  | 	 * since sequence rendering can call that recursively... (peter) */ | 
					
						
							| 
									
										
										
										
											2012-08-08 11:56:58 +00:00
										 |  |  | 	BKE_sequencer_cache_cleanup(); | 
					
						
							| 
									
										
										
										
											2010-08-08 16:47:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 	/* get editmode results */ | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	ED_object_exit_editmode(C, 0);  /* 0 = does not exit editmode */ | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// store spare
 | 
					
						
							|  |  |  | 	// get view3d layer, local layer, make this nice api call to render
 | 
					
						
							|  |  |  | 	// store spare
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* ensure at least 1 area shows result */ | 
					
						
							| 
									
										
										
										
											2011-05-19 11:34:11 +00:00
										 |  |  | 	render_view_open(C, event->x, event->y); | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	jobflag = WM_JOB_EXCL_RENDER | WM_JOB_PRIORITY | WM_JOB_PROGRESS; | 
					
						
							| 
									
										
										
										
											2011-02-07 16:41:57 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2011-10-23 17:52:20 +00:00
										 |  |  | 	/* custom scene and single layer re-render */ | 
					
						
							|  |  |  | 	screen_render_scene_layer_set(op, mainp, &scene, &srl); | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (RNA_struct_property_is_set(op->ptr, "layer")) | 
					
						
							| 
									
										
										
										
											2011-02-07 16:41:57 +00:00
										 |  |  | 		jobflag |= WM_JOB_SUSPEND; | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* job custom data */ | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	rj = MEM_callocN(sizeof(RenderJob), "render job"); | 
					
						
							|  |  |  | 	rj->main = mainp; | 
					
						
							|  |  |  | 	rj->scene = scene; | 
					
						
							|  |  |  | 	rj->win = CTX_wm_window(C); | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 	rj->srl = srl; | 
					
						
							| 
									
										
										
										
											2011-04-30 04:29:36 +00:00
										 |  |  | 	rj->camera_override = camera_override; | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	rj->lay = (v3d) ? v3d->lay : scene->lay; | 
					
						
							|  |  |  | 	rj->anim = is_animation; | 
					
						
							|  |  |  | 	rj->write_still = is_write_still && !is_animation; | 
					
						
							|  |  |  | 	rj->iuser.scene = scene; | 
					
						
							|  |  |  | 	rj->iuser.ok = 1; | 
					
						
							|  |  |  | 	rj->reports = op->reports; | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* setup job */ | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	if (RE_seq_render_active(scene, &scene->r)) name = "Sequence Render"; | 
					
						
							|  |  |  | 	else name = "Render"; | 
					
						
							| 
									
										
										
										
											2011-11-03 17:06:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	steve = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), scene, name, jobflag); | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 	WM_jobs_customdata(steve, rj, render_freejob); | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	WM_jobs_timer(steve, 0.2, NC_SCENE | ND_RENDER_RESULT, 0); | 
					
						
							| 
									
										
										
										
											2010-04-15 10:28:32 +00:00
										 |  |  | 	WM_jobs_callbacks(steve, render_startjob, NULL, NULL, render_endjob); | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* get a render result image, and make sure it is empty */ | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	ima = BKE_image_verify_viewer(IMA_TYPE_R_RESULT, "Render Result"); | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 	BKE_image_signal(ima, NULL, IMA_SIGNAL_FREE); | 
					
						
							| 
									
										
										
										
											2010-03-27 15:35:34 +00:00
										 |  |  | 	BKE_image_backup_render(rj->scene, ima); | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	rj->image = ima; | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* setup new render */ | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	re = RE_NewRender(scene->id.name); | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 	RE_test_break_cb(re, rj, render_breakjob); | 
					
						
							| 
									
										
										
										
											2011-03-25 17:11:32 +00:00
										 |  |  | 	RE_draw_lock_cb(re, rj, render_drawlock); | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 	RE_display_draw_cb(re, rj, image_rect_update); | 
					
						
							|  |  |  | 	RE_stats_draw_cb(re, rj, image_renderinfo_cb); | 
					
						
							| 
									
										
										
										
											2010-05-27 08:22:16 +00:00
										 |  |  | 	RE_progress_cb(re, rj, render_progress_update); | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	rj->re = re; | 
					
						
							| 
									
										
										
										
											2012-08-08 18:37:06 +00:00
										 |  |  | 	G.is_break = FALSE; | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-01 19:22:04 +00:00
										 |  |  | 	/* store actual owner of job, so modal operator could check for it,
 | 
					
						
							|  |  |  | 	 * the reason of this is that active scene could change when rendering | 
					
						
							|  |  |  | 	 * several layers from composistor [#31800] | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	op->customdata = scene; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 	WM_jobs_start(CTX_wm_manager(C), steve); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	WM_cursor_wait(0); | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	WM_event_add_notifier(C, NC_SCENE | ND_RENDER_RESULT, scene); | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-08 18:37:06 +00:00
										 |  |  | 	/* we set G.is_rendering here already instead of only in the job, this ensure
 | 
					
						
							| 
									
										
										
										
											2012-03-03 16:31:46 +00:00
										 |  |  | 	 * main loop or other scene updates are disabled in time, since they may | 
					
						
							|  |  |  | 	 * have started before the job thread */ | 
					
						
							| 
									
										
										
										
											2012-08-08 18:37:06 +00:00
										 |  |  | 	G.is_rendering = TRUE; | 
					
						
							| 
									
										
										
										
											2010-04-15 10:28:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 	/* 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 */ | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->name = "Render"; | 
					
						
							|  |  |  | 	ot->description = "Render active scene"; | 
					
						
							|  |  |  | 	ot->idname = "RENDER_OT_render"; | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->invoke = screen_render_invoke; | 
					
						
							|  |  |  | 	ot->modal = screen_render_modal; | 
					
						
							|  |  |  | 	ot->exec = screen_render_exec; | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	/*ot->poll = ED_operator_screenactive;*/ /* this isn't needed, causes failer in background mode */ | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-16 14:40:46 +00:00
										 |  |  | 	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)"); | 
					
						
							| 
									
										
										
										
											2011-10-23 17:52:20 +00:00
										 |  |  | 	RNA_def_string(ot->srna, "layer", "", RE_MAXNAME, "Render Layer", "Single render layer to re-render (used only when animation is disabled)"); | 
					
						
							| 
									
										
										
										
											2012-03-29 22:42:32 +00:00
										 |  |  | 	RNA_def_string(ot->srna, "scene", "", MAX_ID_NAME - 2, "Scene", "Scene to render, current scene if not specified"); | 
					
						
							| 
									
										
										
										
											2010-03-08 16:36:53 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 |