diff options
-rw-r--r-- | source/blender/draw/intern/draw_manager.h | 2 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager_data.c | 9 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager_exec.c | 11 |
3 files changed, 14 insertions, 8 deletions
diff --git a/source/blender/draw/intern/draw_manager.h b/source/blender/draw/intern/draw_manager.h index f040afc794c..6d415ee95b3 100644 --- a/source/blender/draw/intern/draw_manager.h +++ b/source/blender/draw/intern/draw_manager.h @@ -362,6 +362,8 @@ struct DRWView { int clip_planes_len; /** Does culling result needs to be updated. */ bool is_dirty; + /** Does facing needs to be reversed? */ + bool is_inverted; /** Culling */ uint32_t culling_mask; BoundBox frustum_corners; diff --git a/source/blender/draw/intern/draw_manager_data.c b/source/blender/draw/intern/draw_manager_data.c index 0af68181478..fbdabb44b15 100644 --- a/source/blender/draw/intern/draw_manager_data.c +++ b/source/blender/draw/intern/draw_manager_data.c @@ -1551,13 +1551,6 @@ static void draw_view_matrix_state_update(DRWViewUboStorage *storage, const float viewmat[4][4], const float winmat[4][4]) { - /* If only one the matrices is negative, then the - * polygon winding changes and we don't want that. - * By convention, the winmat is negative because - * looking through the -Z axis. So this inverse the - * changes the test for the winmat. */ - BLI_assert(is_negative_m4(viewmat) == !is_negative_m4(winmat)); - copy_m4_m4(storage->viewmat, viewmat); invert_m4_m4(storage->viewinv, storage->viewmat); @@ -1629,6 +1622,7 @@ void DRW_view_update_sub(DRWView *view, const float viewmat[4][4], const float w BLI_assert(view->parent != NULL); view->is_dirty = true; + view->is_inverted = (is_negative_m4(viewmat) == is_negative_m4(winmat)); draw_view_matrix_state_update(&view->storage, viewmat, winmat); } @@ -1646,6 +1640,7 @@ void DRW_view_update(DRWView *view, BLI_assert(view->parent == NULL); view->is_dirty = true; + view->is_inverted = (is_negative_m4(viewmat) == is_negative_m4(winmat)); draw_view_matrix_state_update(&view->storage, viewmat, winmat); diff --git a/source/blender/draw/intern/draw_manager_exec.c b/source/blender/draw/intern/draw_manager_exec.c index 23a3e0b05d4..0ff3e2b1853 100644 --- a/source/blender/draw/intern/draw_manager_exec.c +++ b/source/blender/draw/intern/draw_manager_exec.c @@ -1072,7 +1072,7 @@ static void draw_call_resource_bind(DRWCommandsState *state, const DRWResourceHa /* Front face is not a resource but it is inside the resource handle. */ bool neg_scale = DRW_handle_negative_scale_get(handle); if (neg_scale != state->neg_scale) { - glFrontFace((neg_scale) ? GL_CW : GL_CCW); + glFrontFace((neg_scale != DST.view_active->is_inverted) ? GL_CW : GL_CCW); state->neg_scale = neg_scale; } @@ -1395,6 +1395,10 @@ static void drw_draw_pass_ex(DRWPass *pass, drw_state_set(pass->state); drw_state_validate(); + if (DST.view_active->is_inverted) { + glFrontFace(GL_CW); + } + DRW_stats_query_start(pass->name); for (DRWShadingGroup *shgroup = start_group; shgroup; shgroup = shgroup->next) { @@ -1444,6 +1448,11 @@ static void drw_draw_pass_ex(DRWPass *pass, drw_state_set((DST.state & ~DRW_STATE_RASTERIZER_ENABLED) | DRW_STATE_DEFAULT); } + /* Reset default. */ + if (DST.view_active->is_inverted) { + glFrontFace(GL_CCW); + } + DRW_stats_query_end(); } |