[Bf-blender-cvs] [145298e] master: Cleanup: GL Render (simplify internal logic)

Campbell Barton noreply at git.blender.org
Wed Nov 11 14:31:15 CET 2015


Commit: 145298e2d3b2edfc3ddb6d8ccfb3f393232dafb9
Author: Campbell Barton
Date:   Wed Nov 11 21:56:25 2015 +1100
Branches: master
https://developer.blender.org/rB145298e2d3b2edfc3ddb6d8ccfb3f393232dafb9

Cleanup: GL Render (simplify internal logic)

Reduce code-paths so improvements to 3D view render apply to sequencer too.

===================================================================

M	source/blender/blenkernel/BKE_sequencer.h
M	source/blender/blenkernel/intern/sequencer.c
M	source/blender/editors/include/ED_view3d.h
M	source/blender/editors/render/render_opengl.c
M	source/blender/editors/sculpt_paint/paint_image_proj.c
M	source/blender/editors/space_view3d/view3d_draw.c
M	source/blender/windowmanager/intern/wm_files.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_sequencer.h b/source/blender/blenkernel/BKE_sequencer.h
index 418179c..350edde 100644
--- a/source/blender/blenkernel/BKE_sequencer.h
+++ b/source/blender/blenkernel/BKE_sequencer.h
@@ -36,6 +36,7 @@ struct StripColorBalance;
 struct Editing;
 struct GSet;
 struct GPUOffScreen;
+struct GPUFX;
 struct ImBuf;
 struct Main;
 struct Mask;
@@ -105,6 +106,7 @@ typedef struct SeqRenderData {
 
 	/* special case for OpenGL render */
 	struct GPUOffScreen *gpu_offscreen;
+	struct GPUFX *gpu_fx;
 	int gpu_samples;
 } SeqRenderData;
 
@@ -417,7 +419,7 @@ typedef struct ImBuf *(*SequencerDrawView)(
         struct Scene *, struct Object *, int, int,
         unsigned int, int, bool, bool, bool,
         int, int, const char *,
-        struct GPUOffScreen *, char[256]);
+        struct GPUFX *, struct GPUOffScreen *, char[256]);
 extern SequencerDrawView sequencer_view3d_cb;
 
 /* copy/paste */
diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c
index 45d33e5..6d58365 100644
--- a/source/blender/blenkernel/intern/sequencer.c
+++ b/source/blender/blenkernel/intern/sequencer.c
@@ -3222,7 +3222,7 @@ static ImBuf *seq_render_scene_strip(const SeqRenderData *context, Sequence *seq
 		        (context->scene->r.seq_flag & R_SEQ_SOLID_TEX) != 0,
 		        use_gpencil, true, scene->r.alphamode,
 		        context->gpu_samples, viewname,
-		        context->gpu_offscreen, err_out);
+		        context->gpu_fx, context->gpu_offscreen, err_out);
 		if (ibuf == NULL) {
 			fprintf(stderr, "seq_render_scene_strip failed to get opengl buffer: %s\n", err_out);
 		}
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h
index 9da1221..e5fe163 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/source/blender/editors/include/ED_view3d.h
@@ -334,12 +334,12 @@ struct ImBuf *ED_view3d_draw_offscreen_imbuf(
         struct Scene *scene, struct View3D *v3d, struct ARegion *ar, int sizex, int sizey,
         unsigned int flag, bool draw_background,
         int alpha_mode, int samples, const char *viewname,
-        struct GPUOffScreen *ofs, char err_out[256]);
+        struct GPUFX *fx, struct GPUOffScreen *ofs, char err_out[256]);
 struct ImBuf *ED_view3d_draw_offscreen_imbuf_simple(
         struct Scene *scene, struct Object *camera, int width, int height,
         unsigned int flag, int drawtype, bool use_solid_tex, bool use_gpencil, bool draw_background,
         int alpha_mode, int samples, const char *viewname,
-        struct GPUOffScreen *ofs, char err_out[256]);
+        struct GPUFX *fx, struct GPUOffScreen *ofs, char err_out[256]);
 
 struct Base *ED_view3d_give_base_under_cursor(struct bContext *C, const int mval[2]);
 void ED_view3d_quadview_update(struct ScrArea *sa, struct ARegion *ar, bool do_clip);
diff --git a/source/blender/editors/render/render_opengl.c b/source/blender/editors/render/render_opengl.c
index 263abe7..2a48d30 100644
--- a/source/blender/editors/render/render_opengl.c
+++ b/source/blender/editors/render/render_opengl.c
@@ -253,7 +253,6 @@ static void screen_opengl_render_doit(OGLRender *oglrender, RenderResult *rr)
 	RegionView3D *rv3d = oglrender->rv3d;
 	Object *camera = NULL;
 	ImBuf *ibuf;
-	float winmat[4][4];
 	float *rectf = RE_RenderViewGetById(rr, oglrender->view_id)->rectf;
 	int sizex = oglrender->sizex;
 	int sizey = oglrender->sizey;
@@ -276,6 +275,7 @@ static void screen_opengl_render_doit(OGLRender *oglrender, RenderResult *rr)
 
 		context.view_id = BKE_scene_multiview_view_id_get(&scene->r, viewname);
 		context.gpu_offscreen = oglrender->ofs;
+		context.gpu_fx = oglrender->fx;
 		context.gpu_samples = oglrender->ofs_samples;
 
 		ibuf = BKE_sequencer_give_ibuf(&context, CFRA, chanshown);
@@ -337,62 +337,32 @@ static void screen_opengl_render_doit(OGLRender *oglrender, RenderResult *rr)
 			MEM_freeN(gp_rect);
 		}
 	}
-	else if (view_context) {
-		bool is_persp;
-		/* full copy */
-		GPUFXSettings fx_settings = v3d->fx_settings;
-
-		ED_view3d_draw_offscreen_init(scene, v3d);
-
-		GPU_offscreen_bind(oglrender->ofs, true); /* bind */
-
-		/* render 3d view */
-		if (rv3d->persp == RV3D_CAMOB && v3d->camera) {
-#if 0
-			const bool is_ortho = (scene->r.mode & R_ORTHO) != 0;
-#endif
-			camera = BKE_camera_multiview_render(oglrender->scene, v3d->camera, viewname);
-			RE_GetCameraWindow(oglrender->re, camera, scene->r.cfra, winmat);
-			if (camera->type == OB_CAMERA) {
-				Camera *cam = camera->data;
-				is_persp = cam->type == CAM_PERSP;
+	else {
+		/* shouldnt suddenly give errors mid-render but possible */
+		char err_out[256] = "unknown";
+		ImBuf *ibuf_view;
+
+		if (view_context) {
+			ibuf_view = ED_view3d_draw_offscreen_imbuf(
+			       scene, v3d, ar, sizex, sizey,
+			       IB_rect, draw_bgpic,
+			       (draw_sky) ? R_ADDSKY : R_ALPHAPREMUL, oglrender->ofs_samples, viewname,
+			       oglrender->fx, oglrender->ofs, err_out);
+
+			/* for stamp only */
+			if (rv3d->persp == RV3D_CAMOB && v3d->camera) {
+				camera = BKE_camera_multiview_render(oglrender->scene, v3d->camera, viewname);
 			}
-			else
-				is_persp = true;
-			BKE_camera_to_gpu_dof(camera, &fx_settings);
 		}
 		else {
-			rctf viewplane;
-			float clipsta, clipend;
-
-			bool is_ortho = ED_view3d_viewplane_get(v3d, rv3d, sizex, sizey, &viewplane, &clipsta, &clipend, NULL);
-			if (is_ortho) orthographic_m4(winmat, viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, -clipend, clipend);
-			else perspective_m4(winmat, viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, clipsta, clipend);
-
-			is_persp = !is_ortho;
+			ibuf_view = ED_view3d_draw_offscreen_imbuf_simple(
+			        scene, scene->camera, oglrender->sizex, oglrender->sizey,
+			        IB_rect, OB_SOLID, false, true, true,
+			        (draw_sky) ? R_ADDSKY : R_ALPHAPREMUL, oglrender->ofs_samples, viewname,
+			        oglrender->fx, oglrender->ofs, err_out);
+			camera = scene->camera;
 		}
 
-		rect = MEM_mallocN(sizex * sizey * sizeof(unsigned char) * 4, "offscreen rect");
-
-		ED_view3d_draw_offscreen(
-		        scene, v3d, ar, sizex, sizey, NULL, winmat,
-		        draw_bgpic, draw_sky, is_persp, viewname,
-		        oglrender->fx, &fx_settings,
-		        oglrender->ofs);
-		GPU_offscreen_read_pixels(oglrender->ofs, GL_UNSIGNED_BYTE, rect);
-
-		GPU_offscreen_unbind(oglrender->ofs, true); /* unbind */
-	}
-	else {
-		/* shouldnt suddenly give errors mid-render but possible */
-		char err_out[256] = "unknown";
-		ImBuf *ibuf_view = ED_view3d_draw_offscreen_imbuf_simple(
-		        scene, scene->camera, oglrender->sizex, oglrender->sizey,
-		        IB_rect, OB_SOLID, false, true, true,
-		        (draw_sky) ? R_ADDSKY : R_ALPHAPREMUL, oglrender->ofs_samples, viewname,
-		        oglrender->ofs, err_out);
-		camera = scene->camera;
-
 		if (ibuf_view) {
 			/* steal rect reference from ibuf */
 			rect = (unsigned char *)ibuf_view->rect;
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index 565f8a5..3b6f88f 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -5402,7 +5402,7 @@ static int texture_paint_image_from_view_exec(bContext *C, wmOperator *op)
 	ibuf = ED_view3d_draw_offscreen_imbuf(
 	        scene, CTX_wm_view3d(C), CTX_wm_region(C),
 	        w, h, IB_rect, false, R_ALPHAPREMUL, 0, NULL,
-	        NULL, err_out);
+	        NULL, NULL, err_out);
 	if (!ibuf) {
 		/* Mostly happens when OpenGL offscreen buffer was failed to create, */
 		/* but could be other reasons. Should be handled in the future. nazgul */
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index 40cd91a..1486173 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -3296,13 +3296,18 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(
         unsigned int flag, bool draw_background,
         int alpha_mode, int samples, const char *viewname,
         /* output vars */
-        GPUOffScreen *ofs, char err_out[256])
+        GPUFX *fx, GPUOffScreen *ofs, char err_out[256])
 {
 	RegionView3D *rv3d = ar->regiondata;
 	ImBuf *ibuf;
 	const bool draw_sky = (alpha_mode == R_ADDSKY) && v3d && (v3d->flag3 & V3D_SHOW_WORLD);
 	const bool own_ofs = (ofs == NULL);
 
+	/* view state */
+	GPUFXSettings fx_settings = {NULL};
+	float winmat[4][4];
+	bool is_ortho;
+
 	if (UNLIKELY(v3d == NULL))
 		return NULL;
 
@@ -3325,7 +3330,6 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(
 	/* render 3d view */
 	if (rv3d->persp == RV3D_CAMOB && v3d->camera) {
 		CameraParams params;
-		GPUFXSettings fx_settings = {NULL};
 		Object *camera = BKE_camera_multiview_render(scene, v3d->camera, viewname);
 
 		BKE_camera_params_init(&params);
@@ -3339,19 +3343,29 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(
 
 		BKE_camera_to_gpu_dof(camera, &fx_settings);
 
-		ED_view3d_draw_offscreen(
-		        scene, v3d, ar, sizex, sizey, NULL, params.winmat,
-		        draw_background, draw_sky, !params.is_ortho, viewname,
-		        NULL, &fx_settings,
-		        ofs);
+		is_ortho = params.is_ortho;
+		copy_m4_m4(winmat, params.winmat);
 	}
 	else {
-		ED_view3d_draw_offscreen(
-		        scene, v3d, ar, sizex, sizey, NULL, NULL,
-		        draw_background, draw_sky, true, viewname,
-		        NULL, NULL, ofs);
+		rctf viewplane;
+		float clipsta, clipend;
+
+		fx_settings = v3d->fx_settings;
+
+		is_ortho = ED_view3d_viewplane_get(v3d, rv3d, sizex, sizey, &viewplane, &clipsta, &clipend, NULL);
+		if (is_ortho) {
+			orthographic_m4(winmat, viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, -clipend, clipend);
+		}
+		else {
+			perspective_m4(winmat, viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, clipsta, clipend);
+		}
 	}
 
+	ED_view3d_draw_offscreen(
+	        scene, v3d, ar, sizex, sizey, NULL, winmat,
+	        draw_background, draw_sky, !is_ortho, viewname,
+	        fx, &fx_settings, ofs);
+
 	/* read in pixels & stamp */
 	ibuf = IMB_allocImBuf(sizex, sizey, 32, flag);


@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list