[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [36774] trunk/blender/source/blender/ editors/render: Code refactor: split code for render updates and opening render view into

Brecht Van Lommel brechtvanlommel at pandora.be
Thu May 19 13:34:11 CEST 2011


Revision: 36774
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36774
Author:   blendix
Date:     2011-05-19 11:34:11 +0000 (Thu, 19 May 2011)
Log Message:
-----------
Code refactor: split code for render updates and opening render view into
separate files, no functional changes.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/render/CMakeLists.txt
    trunk/blender/source/blender/editors/render/render_intern.h
    trunk/blender/source/blender/editors/render/render_internal.c
    trunk/blender/source/blender/editors/render/render_opengl.c
    trunk/blender/source/blender/editors/render/render_preview.c
    trunk/blender/source/blender/editors/render/render_shading.c

Added Paths:
-----------
    trunk/blender/source/blender/editors/render/render_update.c
    trunk/blender/source/blender/editors/render/render_view.c

Modified: trunk/blender/source/blender/editors/render/CMakeLists.txt
===================================================================
--- trunk/blender/source/blender/editors/render/CMakeLists.txt	2011-05-19 11:24:56 UTC (rev 36773)
+++ trunk/blender/source/blender/editors/render/CMakeLists.txt	2011-05-19 11:34:11 UTC (rev 36774)
@@ -41,6 +41,8 @@
 	render_ops.c
 	render_preview.c
 	render_shading.c
+	render_update.c
+	render_view.c
 
 	render_intern.h
 )

Modified: trunk/blender/source/blender/editors/render/render_intern.h
===================================================================
--- trunk/blender/source/blender/editors/render/render_intern.h	2011-05-19 11:24:56 UTC (rev 36773)
+++ trunk/blender/source/blender/editors/render/render_intern.h	2011-05-19 11:34:11 UTC (rev 36774)
@@ -65,14 +65,17 @@
 void TEXTURE_OT_envmap_clear_all(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 */
+/* render_opengl.c uses this */
 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_view.c */
+void render_view_open(struct bContext *C, int mx, int my);
+
+void RENDER_OT_view_show(struct wmOperatorType *ot);
+void RENDER_OT_view_cancel(struct wmOperatorType *ot);
+
 /* render_opengl.c */
 void RENDER_OT_opengl(struct wmOperatorType *ot);
 

Modified: trunk/blender/source/blender/editors/render/render_internal.c
===================================================================
--- trunk/blender/source/blender/editors/render/render_internal.c	2011-05-19 11:24:56 UTC (rev 36773)
+++ trunk/blender/source/blender/editors/render/render_internal.c	2011-05-19 11:34:11 UTC (rev 36774)
@@ -73,17 +73,14 @@
 
 #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, wmWindow **win);
-static ScrArea *find_area_image_empty(bContext *C);
+/* Render Callbacks */
 
 /* 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;
+	int rymin, rxmin, do_color_management;
 	char *rectc;
 
 	/* if renrect argument, we only refresh scanlines */
@@ -95,7 +92,8 @@
 		/* 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;
+		if(xmax<2)
+			return;
 
 		ymin= renrect->ymin + rr->crop;
 		ymax= renrect->ymax - ymin + rr->crop;
@@ -141,270 +139,56 @@
 	
 	rectf+= 4*(rr->rectx*ymin + xmin);
 	rectc= (char *)(ibuf->rect + ibuf->x*rymin + rxmin);
+
+	do_color_management = (scene && (scene->r.color_mgt_flag & R_COLOR_MANAGEMENT));
 	
 	/* 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;
-			const float dither = ibuf->dither / 255.0f;
+	for(y1= 0; y1<ymax; y1++) {
+		float *rf= rectf;
+		float srgb[3];
+		char *rc= rectc;
+		const float dither = ibuf->dither / 255.0f;
 
-			/* XXX temp. because crop offset */
-			if( rectc >= (char *)(ibuf->rect)) {
-				for(x1= 0; x1<xmax; x1++, rf += 4, rc+=4) {
-					const float d = (BLI_frand()-0.5f)*dither;
-					srgb[0]= d + linearrgb_to_srgb(rf[0]);
-					srgb[1]= d + linearrgb_to_srgb(rf[1]);
-					srgb[2]= d + 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]);
+		/* XXX temp. because crop offset */
+		if(rectc >= (char *)(ibuf->rect)) {
+			for(x1= 0; x1<xmax; x1++, rf += 4, rc+=4) {
+				/* color management */
+				if(do_color_management) {
+					srgb[0]= linearrgb_to_srgb(rf[0]);
+					srgb[1]= linearrgb_to_srgb(rf[1]);
+					srgb[2]= linearrgb_to_srgb(rf[2]);
 				}
-			}
-			rectf += 4*rr->rectx;
-			rectc += 4*ibuf->x;
-		}
-	} else {
-		for(y1= 0; y1<ymax; y1++) {
-			float *rf= rectf;
-			char *rc= rectc;
-			float rgb[3];
-			const float dither = ibuf->dither / 255.0f;
+				else {
+					copy_v3_v3(srgb, rf);
+				}
 
-			/* XXX temp. because crop offset */
-			if( rectc >= (char *)(ibuf->rect)) {
-				for(x1= 0; x1<xmax; x1++, rf += 4, rc+=4) {
+				/* dither */
+				if(dither != 0.0f) {
 					const float d = (BLI_frand()-0.5f)*dither;
-					
-					rgb[0] = d + rf[0];
-					rgb[1] = d + rf[1];
-					rgb[2] = d + rf[2];
-					
-					rc[0]= FTOCHAR(rgb[0]);
-					rc[1]= FTOCHAR(rgb[1]);
-					rc[2]= FTOCHAR(rgb[2]);
-					rc[3]= FTOCHAR(rf[3]);
+
+					srgb[0] += d;
+					srgb[1] += d;
+					srgb[2] += d;
 				}
-			}
-			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_NONE)
-		return;
-	
-	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) && 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, &win); 
-		if(sa==NULL)
-			sa= find_area_image_empty(C);
-		
-		/* if area found in other window, we make that one show in front */
-		if(win && win!=CTX_wm_window(C))
-			wm_window_raise(win);
-
-		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;
+				/* write */
+				rc[0]= FTOCHAR(srgb[0]);
+				rc[1]= FTOCHAR(srgb[1]);
+				rc[2]= FTOCHAR(srgb[2]);
+				rc[3]= FTOCHAR(rf[3]);
 			}
-			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 */
-			;
-		}
-
+		rectf += 4*rr->rectx;
+		rectc += 4*ibuf->x;
 	}
-
 }
 
-
 /* ****************************** 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, wmWindow **win)
-{
-	wmWindowManager *wm= CTX_wm_manager(C);
-	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;
-			}
-		}
-		if(sa)
-			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
-
 static void render_error_reports(void *reports, const char *str)
 {
 	BKE_report(reports, RPT_ERROR, str);
@@ -428,10 +212,6 @@
 		return OPERATOR_CANCELLED;
 	}
 
-	if(re==NULL) {

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list