[Bf-blender-cvs] [7b96f02] master: OpenGL Render: Support full-sample Anti-Aliasing

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


Commit: 7b96f02f5b7e08712874eadaad7275140d0f6ef5
Author: Campbell Barton
Date:   Thu Nov 12 00:06:26 2015 +1100
Branches: master
https://developer.blender.org/rB7b96f02f5b7e08712874eadaad7275140d0f6ef5

OpenGL Render: Support full-sample Anti-Aliasing

This brings back old (slower), higher quality method.
Useful since graphics cards often use a faster MSAA which only oversamples edges.

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

M	release/scripts/startup/bl_ui/space_info.py
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/release/scripts/startup/bl_ui/space_info.py b/release/scripts/startup/bl_ui/space_info.py
index d295cc1..369656f 100644
--- a/release/scripts/startup/bl_ui/space_info.py
+++ b/release/scripts/startup/bl_ui/space_info.py
@@ -262,8 +262,9 @@ class INFO_MT_opengl_render(Menu):
         layout = self.layout
 
         rd = context.scene.render
-
         layout.prop(rd, "use_antialiasing")
+        layout.prop(rd, "use_full_sample")
+
         layout.prop_menu_enum(rd, "antialiasing_samples")
         layout.prop_menu_enum(rd, "alpha_mode")
 
diff --git a/source/blender/blenkernel/BKE_sequencer.h b/source/blender/blenkernel/BKE_sequencer.h
index 350edde..0a2a2c7 100644
--- a/source/blender/blenkernel/BKE_sequencer.h
+++ b/source/blender/blenkernel/BKE_sequencer.h
@@ -108,6 +108,7 @@ typedef struct SeqRenderData {
 	struct GPUOffScreen *gpu_offscreen;
 	struct GPUFX *gpu_fx;
 	int gpu_samples;
+	bool gpu_full_samples;
 } SeqRenderData;
 
 void BKE_sequencer_new_render_data(
@@ -418,7 +419,7 @@ struct Sequence *BKE_sequencer_add_movie_strip(struct bContext *C, ListBase *seq
 typedef struct ImBuf *(*SequencerDrawView)(
         struct Scene *, struct Object *, int, int,
         unsigned int, int, bool, bool, bool,
-        int, int, const char *,
+        int, int, bool, const char *,
         struct GPUFX *, struct GPUOffScreen *, char[256]);
 extern SequencerDrawView sequencer_view3d_cb;
 
diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c
index 6d58365..08975fe 100644
--- a/source/blender/blenkernel/intern/sequencer.c
+++ b/source/blender/blenkernel/intern/sequencer.c
@@ -565,6 +565,7 @@ void BKE_sequencer_new_render_data(
 	r_context->view_id = 0;
 	r_context->gpu_offscreen = NULL;
 	r_context->gpu_samples = (scene->r.mode & R_OSA) ? scene->r.osa : 0;
+	r_context->gpu_full_samples = (r_context->gpu_samples) && (scene->r.scemode & R_FULL_SAMPLE);
 }
 
 /* ************************* iterator ************************** */
@@ -3221,7 +3222,7 @@ static ImBuf *seq_render_scene_strip(const SeqRenderData *context, Sequence *seq
 		        context->scene->r.seq_prev_type,
 		        (context->scene->r.seq_flag & R_SEQ_SOLID_TEX) != 0,
 		        use_gpencil, true, scene->r.alphamode,
-		        context->gpu_samples, viewname,
+		        context->gpu_samples, context->gpu_full_samples, viewname,
 		        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 e5fe163..83a71c6 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/source/blender/editors/include/ED_view3d.h
@@ -333,12 +333,12 @@ void ED_view3d_draw_offscreen(
 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,
+        int alpha_mode, int samples, bool full_samples, const char *viewname,
         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,
+        int alpha_mode, int samples, bool full_samples, const char *viewname,
         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]);
diff --git a/source/blender/editors/render/render_opengl.c b/source/blender/editors/render/render_opengl.c
index 2a48d30..738ee1f 100644
--- a/source/blender/editors/render/render_opengl.c
+++ b/source/blender/editors/render/render_opengl.c
@@ -97,6 +97,7 @@ typedef struct OGLRender {
 
 	GPUOffScreen *ofs;
 	int ofs_samples;
+	bool ofs_full_samples;
 	GPUFX *fx;
 	int sizex, sizey;
 	int write_still;
@@ -276,7 +277,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;
+		context.gpu_full_samples = oglrender->ofs_full_samples;
 
 		ibuf = BKE_sequencer_give_ibuf(&context, CFRA, chanshown);
 
@@ -341,12 +342,13 @@ static void screen_opengl_render_doit(OGLRender *oglrender, RenderResult *rr)
 		/* shouldnt suddenly give errors mid-render but possible */
 		char err_out[256] = "unknown";
 		ImBuf *ibuf_view;
+		const int alpha_mode = (draw_sky) ? R_ADDSKY : R_ALPHAPREMUL;
 
 		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,
+			       alpha_mode, oglrender->ofs_samples, oglrender->ofs_full_samples, viewname,
 			       oglrender->fx, oglrender->ofs, err_out);
 
 			/* for stamp only */
@@ -358,7 +360,7 @@ static void screen_opengl_render_doit(OGLRender *oglrender, RenderResult *rr)
 			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,
+			        alpha_mode, oglrender->ofs_samples, oglrender->ofs_full_samples, viewname,
 			        oglrender->fx, oglrender->ofs, err_out);
 			camera = scene->camera;
 		}
@@ -471,6 +473,7 @@ static bool screen_opengl_render_init(bContext *C, wmOperator *op)
 	OGLRender *oglrender;
 	int sizex, sizey;
 	const int samples = (scene->r.mode & R_OSA) ? scene->r.osa : 0;
+	const bool full_samples = (samples != 0) && (scene->r.scemode & R_FULL_SAMPLE);
 	bool is_view_context = RNA_boolean_get(op->ptr, "view_context");
 	const bool is_animation = RNA_boolean_get(op->ptr, "animation");
 	const bool is_sequencer = RNA_boolean_get(op->ptr, "sequencer");
@@ -515,7 +518,7 @@ static bool screen_opengl_render_init(bContext *C, wmOperator *op)
 	sizey = (scene->r.size * scene->r.ysch) / 100;
 
 	/* corrects render size with actual size, not every card supports non-power-of-two dimensions */
-	ofs = GPU_offscreen_create(sizex, sizey, samples, err_out);
+	ofs = GPU_offscreen_create(sizex, sizey, full_samples ? 0 : samples, err_out);
 
 	if (!ofs) {
 		BKE_reportf(op->reports, RPT_ERROR, "Failed to create OpenGL off-screen buffer, %s", err_out);
@@ -528,6 +531,7 @@ static bool screen_opengl_render_init(bContext *C, wmOperator *op)
 
 	oglrender->ofs = ofs;
 	oglrender->ofs_samples = samples;
+	oglrender->ofs_full_samples = full_samples;
 	oglrender->sizex = sizex;
 	oglrender->sizey = sizey;
 	oglrender->bmain = CTX_data_main(C);
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index 3b6f88f..6ebf965 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -5401,7 +5401,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,
+	        w, h, IB_rect, false, R_ALPHAPREMUL, 0, false, NULL,
 	        NULL, NULL, err_out);
 	if (!ibuf) {
 		/* Mostly happens when OpenGL offscreen buffer was failed to create, */
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index 1486173..ab0d02a 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -48,6 +48,7 @@
 
 #include "BLI_blenlib.h"
 #include "BLI_math.h"
+#include "BLI_jitter.h"
 #include "BLI_utildefines.h"
 #include "BLI_endian_switch.h"
 #include "BLI_threads.h"
@@ -3294,7 +3295,7 @@ void ED_view3d_draw_offscreen(
 ImBuf *ED_view3d_draw_offscreen_imbuf(
         Scene *scene, View3D *v3d, ARegion *ar, int sizex, int sizey,
         unsigned int flag, bool draw_background,
-        int alpha_mode, int samples, const char *viewname,
+        int alpha_mode, int samples, bool full_samples, const char *viewname,
         /* output vars */
         GPUFX *fx, GPUOffScreen *ofs, char err_out[256])
 {
@@ -3305,8 +3306,8 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(
 
 	/* view state */
 	GPUFXSettings fx_settings = {NULL};
+	bool is_ortho = false;
 	float winmat[4][4];
-	bool is_ortho;
 
 	if (UNLIKELY(v3d == NULL))
 		return NULL;
@@ -3316,7 +3317,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(
 		glPushAttrib(GL_LIGHTING_BIT);
 
 		/* bind */
-		ofs = GPU_offscreen_create(sizex, sizey, samples, err_out);
+		ofs = GPU_offscreen_create(sizex, sizey, full_samples ? 0 : samples, err_out);
 		if (ofs == NULL) {
 			glPopAttrib();
 			return NULL;
@@ -3327,6 +3328,9 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(
 
 	GPU_offscreen_bind(ofs, true);
 
+	/* read in pixels & stamp */
+	ibuf = IMB_allocImBuf(sizex, sizey, 32, flag);
+
 	/* render 3d view */
 	if (rv3d->persp == RV3D_CAMOB && v3d->camera) {
 		CameraParams params;
@@ -3361,18 +3365,82 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(
 		}
 	}
 
-	ED_view3d_draw_offscreen(
-	        scene, v3d, ar, sizex, sizey, NULL, winmat,
-	        draw_background, draw_sky, !is_ortho, viewname,
-	        fx, &fx_settings, ofs);
+	if ((samples && full_samples) == 0) {
+		/* Single-pass render, common case */
+		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);
+		if (ibuf->rect_float) {
+			GPU_offscreen_read_pixels(ofs, GL_FLOAT, ibuf->rect_float);
+		}
+		else if (ibuf->rect) {
+			GPU_offscreen_read_pixels(o

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list