[Bf-blender-cvs] [1f1e90a0133] master: Fix T59890: regression of the precision when projecting the cursor.

mano-wii noreply at git.blender.org
Thu Mar 21 21:32:19 CET 2019


Commit: 1f1e90a013301b4283fdf9300e7e68b7fc55d894
Author: mano-wii
Date:   Thu Mar 21 17:02:41 2019 -0300
Branches: master
https://developer.blender.org/rB1f1e90a013301b4283fdf9300e7e68b7fc55d894

Fix T59890: regression of the precision when projecting the cursor.

Basically the framebuffer size was different from the glViewport size.
This made the depth read in glReadPixel not corresponding to the center of the pixel.

Another thing that reduced precision compared to blender 2.79 is the `GPU_matrix_unproject` that now computes using `float`s instead of `double`s.
But this may be for another commit.

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

M	source/blender/draw/intern/draw_manager.c

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

diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index db565b96dab..bfc48f839da 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -2023,12 +2023,8 @@ static struct DRWSelectBuffer {
 	struct GPUTexture *texture_u32;
 } g_select_buffer = {NULL};
 
-static void draw_select_framebuffer_depth_only_setup(const rcti *rect)
+static void draw_select_framebuffer_depth_only_setup(const int size[2])
 {
-	float size[2];
-	size[0] = BLI_rcti_size_x(rect);
-	size[1] = BLI_rcti_size_y(rect);
-
 	if (g_select_buffer.framebuffer_depth_only == NULL) {
 		g_select_buffer.framebuffer_depth_only = GPU_framebuffer_create();
 		g_select_buffer.framebuffer_select_id = GPU_framebuffer_create();
@@ -2061,13 +2057,9 @@ static void draw_select_framebuffer_depth_only_setup(const rcti *rect)
 	}
 }
 
-static void draw_select_framebuffer_select_id_setup(const rcti *rect)
+static void draw_select_framebuffer_select_id_setup(const int size[2])
 {
-	float size[2];
-	size[0] = BLI_rcti_size_x(rect);
-	size[1] = BLI_rcti_size_y(rect);
-
-	draw_select_framebuffer_depth_only_setup(rect);
+	draw_select_framebuffer_depth_only_setup(size);
 
 	if ((g_select_buffer.texture_u32 != NULL) &&
 	    ((GPU_texture_width(g_select_buffer.texture_u32) != size[0]) ||
@@ -2144,8 +2136,9 @@ void DRW_draw_select_loop(
 		}
 	}
 
+	int viewport_size[2] = {BLI_rcti_size_x(rect), BLI_rcti_size_y(rect)};
 	struct GPUViewport *viewport = GPU_viewport_create();
-	GPU_viewport_size_set(viewport, (const int[2]){BLI_rcti_size_x(rect), BLI_rcti_size_y(rect)});
+	GPU_viewport_size_set(viewport, viewport_size);
 
 	DST.viewport = viewport;
 	DST.options.is_select = true;
@@ -2253,7 +2246,7 @@ void DRW_draw_select_loop(
 	}
 
 	/* Setup framebuffer */
-	draw_select_framebuffer_depth_only_setup(rect);
+	draw_select_framebuffer_depth_only_setup(viewport_size);
 	GPU_framebuffer_bind(g_select_buffer.framebuffer_depth_only);
 	GPU_framebuffer_clear_depth(g_select_buffer.framebuffer_depth_only, 1.0f);
 
@@ -2355,11 +2348,12 @@ void DRW_draw_depth_loop(
 	/* Reset before using it. */
 	drw_state_prepare_clean_for_draw(&DST);
 
+	int viewport_size[2] = {ar->winx, ar->winy};
 	struct GPUViewport *viewport = GPU_viewport_create();
-	GPU_viewport_size_set(viewport, (const int[2]){ar->winx, ar->winy});
+	GPU_viewport_size_set(viewport, viewport_size);
 
 	/* Setup framebuffer */
-	draw_select_framebuffer_depth_only_setup(&ar->winrct);
+	draw_select_framebuffer_depth_only_setup(viewport_size);
 	GPU_framebuffer_bind(g_select_buffer.framebuffer_depth_only);
 	GPU_framebuffer_clear_depth(g_select_buffer.framebuffer_depth_only, 1.0f);
 
@@ -2474,7 +2468,8 @@ void DRW_framebuffer_select_id_setup(ARegion *ar, const bool clear)
 	DRW_opengl_context_enable();
 
 	/* Setup framebuffer */
-	draw_select_framebuffer_select_id_setup(&ar->winrct);
+	int viewport_size[2] = {ar->winx, ar->winy};
+	draw_select_framebuffer_select_id_setup(viewport_size);
 	GPU_framebuffer_bind(g_select_buffer.framebuffer_select_id);
 
 	/* dithering and AA break color coding, so disable */



More information about the Bf-blender-cvs mailing list