[Bf-blender-cvs] [827b7de9d69] greasepencil-object: Add a new User Prefs parameter to control GP multisample AA

Antonio Vazquez noreply at git.blender.org
Sat Jun 9 13:30:56 CEST 2018


Commit: 827b7de9d699bd2163c00e215d5b61710714e5bd
Author: Antonio Vazquez
Date:   Sat Jun 9 13:29:40 2018 +0200
Branches: greasepencil-object
https://developer.blender.org/rB827b7de9d699bd2163c00e215d5b61710714e5bd

Add a new User Prefs parameter to control GP multisample AA

For general use of Viewport the multisample AA is not required and can produce errors in selection, but for grease pencil the AA is required all the time to get smooth lines, so a new parameter has been added to User Prefs screen to define this value.

If we use the same value for both AA (grease pencil and Viewport), the viewport would be intefered by grease pencil settings.

The new value is below Viewport Samples.

By default the value was set to 4 samples.

This changes was done as result of requirement of grease pencil development team artists.

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

M	source/blender/blenloader/intern/readfile.c
M	source/blender/draw/engines/gpencil/gpencil_engine.c
M	source/blender/draw/engines/gpencil/gpencil_engine.h
M	source/blender/draw/engines/gpencil/gpencil_render.c
M	source/blender/draw/intern/DRW_render.h

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

diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index b52ead30f3b..25f1894d2fb 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -8630,6 +8630,11 @@ static void do_versions_userdef(FileData *fd, BlendFileData *bfd)
 		user->walk_navigation.jump_height = 0.4f;      /* m */
 		user->walk_navigation.teleport_time = 0.2f; /* s */
 	}
+
+	/* grease pencil multisamples */
+	if (!DNA_struct_elem_find(fd->filesdna, "UserDef", "short", "gpencil_multisamples")) {
+		user->gpencil_multisamples = 4;
+	}
 }
 
 static void do_versions(FileData *fd, Library *lib, Main *main)
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 7b84917a710..f78196e6c61 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -70,6 +70,34 @@ extern char datatoc_gpencil_edit_point_frag_glsl[];
 static GPENCIL_e_data e_data = {NULL}; /* Engine data */
 
 /* *********** FUNCTIONS *********** */
+
+/* create a multisample buffer if not present */
+void DRW_gpencil_multisample_ensure(GPENCIL_Data *vedata, int rect_w, int rect_h)
+{
+	GPENCIL_FramebufferList *fbl = vedata->fbl;
+
+	if (U.gpencil_multisamples > 0) {
+		if (!fbl->multisample_fb) {
+			fbl->multisample_fb = GPU_framebuffer_create();
+			if (fbl->multisample_fb) {
+				if (e_data.multisample_color == NULL) {
+					e_data.multisample_color = GPU_texture_create_2D_multisample(rect_w, rect_h, GPU_RGBA8, NULL, U.gpencil_multisamples, NULL);
+				}
+				if (e_data.multisample_depth == NULL) {
+					e_data.multisample_depth = GPU_texture_create_2D_multisample(rect_w, rect_h, GPU_DEPTH24_STENCIL8, NULL, U.gpencil_multisamples, NULL);
+				}
+				GPU_framebuffer_ensure_config(&fbl->multisample_fb, {
+					GPU_ATTACHMENT_TEXTURE(e_data.multisample_depth),
+					GPU_ATTACHMENT_TEXTURE(e_data.multisample_color)
+					});
+				if (!GPU_framebuffer_check_valid(fbl->multisample_fb, NULL)) {
+					GPU_framebuffer_free(fbl->multisample_fb);
+				}
+			}
+		}
+	}
+}
+
 static void GPENCIL_create_framebuffers(void *vedata)
 {
 	GPENCIL_FramebufferList *fbl = ((GPENCIL_Data *)vedata)->fbl;
@@ -81,6 +109,11 @@ static void GPENCIL_create_framebuffers(void *vedata)
 		const float *viewport_size = DRW_viewport_size_get();
 		const int size[2] = { (int)viewport_size[0], (int)viewport_size[1] };
 
+		/* create multiframe framebuffer for AA */
+		if (U.gpencil_multisamples > 0) {
+			DRW_gpencil_multisample_ensure(vedata, size[0], size[1]);
+		}
+
 		/* temp textures */
 		e_data.temp_depth_tx_a = DRW_texture_pool_query_2D(size[0], size[1], GPU_DEPTH24_STENCIL8,
 			&draw_engine_object_type);
@@ -202,6 +235,8 @@ static void GPENCIL_engine_free(void)
 	DRW_SHADER_FREE_SAFE(e_data.gpencil_paper_sh);
 
 	DRW_TEXTURE_FREE_SAFE(e_data.gpencil_blank_texture);
+	DRW_TEXTURE_FREE_SAFE(e_data.multisample_color);
+	DRW_TEXTURE_FREE_SAFE(e_data.multisample_depth);
 }
 
 void GPENCIL_cache_init(void *vedata)
@@ -513,8 +548,9 @@ static void gpencil_free_obj_list(GPENCIL_StorageList *stl)
 }
 
 /* draw scene */
-void GPENCIL_draw_scene(void *vedata)
+void GPENCIL_draw_scene(void *ved)
 {
+	GPENCIL_Data *vedata = (GPENCIL_Data *)ved;
 	GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
 
 	GPENCIL_PassList *psl = ((GPENCIL_Data *)vedata)->psl;
@@ -539,19 +575,33 @@ void GPENCIL_draw_scene(void *vedata)
 		}
 	}
 
+
 	/* if we have a painting session, we use fast viewport drawing method */
 	if ((!is_render) && (stl->g_data->session_flag & GP_DRW_PAINT_PAINTING)) {
 		GPU_framebuffer_bind(dfbl->default_fb);
 
-		MULTISAMPLE_SYNC_ENABLE(dfbl, dtxl);
+		/* attach multisample textures */
+		if (U.gpencil_multisamples > 0) {
+			GPU_framebuffer_texture_attach(fbl->multisample_fb, e_data.multisample_depth, 0, 0);
+			GPU_framebuffer_texture_attach(fbl->multisample_fb, e_data.multisample_color, 0, 0);
+		}
+
+		MULTISAMPLE_GP_SYNC_ENABLE(U.gpencil_multisamples, fbl);
 
 		DRW_draw_pass(psl->painting_pass);
 		DRW_draw_pass(psl->drawing_pass);
 
-		MULTISAMPLE_SYNC_DISABLE(dfbl, dtxl);
+		MULTISAMPLE_GP_SYNC_DISABLE(U.gpencil_multisamples, fbl, dfbl->default_fb, e_data);
 
 		/* free memory */
 		gpencil_free_obj_list(stl);
+
+		/* detach multisample */
+		if (U.gpencil_multisamples > 0) {
+			GPU_framebuffer_texture_detach(fbl->multisample_fb, e_data.multisample_depth);
+			GPU_framebuffer_texture_detach(fbl->multisample_fb, e_data.multisample_color);
+		}
+
 		return;
 	}
 
@@ -563,6 +613,11 @@ void GPENCIL_draw_scene(void *vedata)
 		GPU_framebuffer_texture_attach(fbl->painting_fb, e_data.painting_depth_tx, 0, 0);
 		GPU_framebuffer_texture_attach(fbl->painting_fb, e_data.painting_color_tx, 0, 0);
 
+		if (U.gpencil_multisamples > 0) {
+			GPU_framebuffer_texture_attach(fbl->multisample_fb, e_data.multisample_depth, 0, 0);
+			GPU_framebuffer_texture_attach(fbl->multisample_fb, e_data.multisample_color, 0, 0);
+		}
+
 		/* Draw all pending objects */
 		if (stl->g_data->gp_cache_used > 0) {
 
@@ -584,13 +639,13 @@ void GPENCIL_draw_scene(void *vedata)
 				 * draw only a subset that usually start with a fill and end with stroke because the
 				 * shading groups are created by pairs */
 				if (end_grp >= init_grp) {
-					 MULTISAMPLE_SYNC_ENABLE(dfbl, dtxl);
+					MULTISAMPLE_GP_SYNC_ENABLE(U.gpencil_multisamples, fbl);
 
 					DRW_draw_pass_subset(psl->stroke_pass,
 						stl->shgroups[init_grp].shgrps_fill != NULL ? stl->shgroups[init_grp].shgrps_fill : stl->shgroups[init_grp].shgrps_stroke,
 						stl->shgroups[end_grp].shgrps_stroke);
 
-					MULTISAMPLE_GP_SYNC_DISABLE(dfbl, dtxl, fbl->temp_fb_a);
+					MULTISAMPLE_GP_SYNC_DISABLE(U.gpencil_multisamples, fbl, fbl->temp_fb_a, e_data);
 				}
 				/* Current buffer drawing */
 				if ((!is_render) && (gpd->sbuffer_size > 0)) {
@@ -631,6 +686,11 @@ void GPENCIL_draw_scene(void *vedata)
 		GPU_framebuffer_texture_detach(fbl->painting_fb, e_data.painting_depth_tx);
 		GPU_framebuffer_texture_detach(fbl->painting_fb, e_data.painting_color_tx);
 
+		if (U.gpencil_multisamples > 0) {
+			GPU_framebuffer_texture_detach(fbl->multisample_fb, e_data.multisample_depth);
+			GPU_framebuffer_texture_detach(fbl->multisample_fb, e_data.multisample_color);
+		}
+
 		/* attach again default framebuffer after detach textures */
 		if (!is_render) {
 			GPU_framebuffer_bind(dfbl->default_fb);
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index c11fdd8cc8d..e4fb870bba7 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -27,6 +27,7 @@
 #define __GPENCIL_ENGINE_H__
 
 #include "GPU_batch.h"
+#include "GPU_framebuffer.h"
 
 struct tGPspoint;
 struct bGPDstroke;
@@ -136,6 +137,8 @@ typedef struct GPENCIL_FramebufferList {
 	struct GPUFrameBuffer *main;
 	struct GPUFrameBuffer *temp_fb_a;
 	struct GPUFrameBuffer *painting_fb;
+
+	struct GPUFrameBuffer *multisample_fb;
 } GPENCIL_FramebufferList;
 
 typedef struct GPENCIL_TextureList {
@@ -199,8 +202,12 @@ typedef struct GPENCIL_e_data {
 	struct GPUTexture *painting_depth_tx;
 	struct GPUTexture *painting_color_tx;
 
-	struct GPUTexture *gpencil_blank_texture;
+	/* multisample textures */
+	struct GPUTexture *multisample_color;
+	struct GPUTexture *multisample_depth;
 
+	struct GPUTexture *gpencil_blank_texture;
+	
 	/* runtime pointers texture */
 	struct GPUTexture *input_depth_tx;
 	struct GPUTexture *input_color_tx;
@@ -240,6 +247,8 @@ void DRW_gpencil_populate_buffer_strokes(struct GPENCIL_e_data *e_data, void *ve
 void DRW_gpencil_populate_multiedit(struct GPENCIL_e_data *e_data, void *vedata, struct Scene *scene, struct Object *ob, struct bGPdata *gpd);
 void DRW_gpencil_triangulate_stroke_fill(struct bGPDstroke *gps);
 
+void DRW_gpencil_multisample_ensure(struct GPENCIL_Data *vedata, int rect_w, int rect_h);
+
 /* create geometry functions */
 struct Gwn_Batch *DRW_gpencil_get_point_geom(struct bGPDstroke *gps, short thickness, const float ink[4]);
 struct Gwn_Batch *DRW_gpencil_get_stroke_geom(struct bGPDframe *gpf, struct bGPDstroke *gps, short thickness, const float ink[4]);
@@ -272,4 +281,24 @@ void GPENCIL_draw_scene(void *vedata);
 void GPENCIL_render_init(struct GPENCIL_Data *ved, struct RenderEngine *engine, struct Depsgraph *depsgraph);
 void GPENCIL_render_to_image(void *vedata, struct RenderEngine *engine, struct RenderLayer *render_layer, const rcti *rect);
 
+/* Use of multisample framebuffers. */
+#define MULTISAMPLE_GP_SYNC_ENABLE(lvl, fbl) { \
+	if ((lvl > 0) && (fbl->multisample_fb != NULL)) { \
+		DRW_stats_query_start("GP Multisample Blit"); \
+		GPU_framebuffer_bind(fbl->multisample_fb); \
+		/* TODO clear only depth but need to do alpha to coverage for transparencies. */ \
+		GPU_framebuffer_clear_color_depth(fbl->multisample_fb, (const float[4]){0.0f}, 1.0f); \
+		DRW_stats_query_end(); \
+	} \
+}
+
+#define MULTISAMPLE_GP_SYNC_DISABLE(lvl, fbl, fb, e_data) { \
+	if ((lvl > 0) && (fbl->multisample_fb != NULL)) { \
+		DRW_stats_query_start("GP Multisample Resolve"); \
+		GPU_framebuffer_bind(fb); \
+		DRW_multisamples_resolve(e_data.multisample_depth, e_data.multisample_color); \
+		DRW_stats_query_end(); \
+	} \
+}
+
 #endif /* __GPENCIL_ENGINE_H__ */
diff --git a/source/blender/draw/engines/gpencil/gpencil_render.c b/source/blender/draw/engines/gpencil/gpencil_render.c
index 6acffb822ca..0afb4e9af63 100644
--- a/source/blender/draw/engines/gpencil/gpencil_render.c
+++ b/source/blender/draw/engines/gpencil/gpencil_render.c
@@ -39,28 +39,6 @@
 
 #include "gpencil_engine.h"
 
- /* create a multisample buffer if not present */
-static void DRW_framebuffer_multisample_ensure(DefaultFramebufferList *dfbl, DefaultTextureList *dtxl, int rect_w, int rect_h)
-{
-	if (U.ogl_multisamples > 0) {
-		if (!dfbl->multisample_fb) {
-			dfbl->multisample_fb = GPU_framebuffer_create();
-			if (dfbl->multisample_fb) {
-				dtxl->multisample_color = GPU_texture_create_2D_multisample(rect_w, rect_h, GPU_RGBA8, NULL, U.ogl_multisamples, NULL);
-				dtxl->multisample_

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list