Fix T59890: regression of the precision when projecting the cursor.
authormano-wii <germano.costa@ig.com.br>
Thu, 21 Mar 2019 20:02:41 +0000 (17:02 -0300)
committermano-wii <germano.costa@ig.com.br>
Thu, 21 Mar 2019 20:04:35 +0000 (17:04 -0300)
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.

source/blender/draw/intern/draw_manager.c

index db565b9..bfc48f8 100644 (file)
@@ -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 */