diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2018-03-02 20:05:42 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2018-03-02 20:35:59 +0300 |
commit | 5e730974fe39ab67e0e56cb683b13bb8148e0415 (patch) | |
tree | 9343743f9abd89f277ff241a55d8644b07b88300 | |
parent | d63829117c21c0d926cf0a9df645c3ed5cd8057a (diff) |
DRW: Add DRWMatrixState to manage all matrices together.
-rw-r--r-- | source/blender/draw/intern/DRW_render.h | 10 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager.c | 44 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager.h | 4 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager_data.c | 14 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_manager_exec.c | 18 |
5 files changed, 60 insertions, 30 deletions
diff --git a/source/blender/draw/intern/DRW_render.h b/source/blender/draw/intern/DRW_render.h index 1713960597e..d8885bd77c5 100644 --- a/source/blender/draw/intern/DRW_render.h +++ b/source/blender/draw/intern/DRW_render.h @@ -398,12 +398,22 @@ typedef enum { DRW_MAT_VIEWINV, DRW_MAT_WIN, DRW_MAT_WININV, + + DRW_MAT_COUNT, // Don't use this. } DRWViewportMatrixType; +typedef struct DRWMatrixState{ + float mat[DRW_MAT_COUNT][4][4]; +} DRWMatrixState; + void DRW_viewport_init(const bContext *C); void DRW_viewport_matrix_get(float mat[4][4], DRWViewportMatrixType type); +void DRW_viewport_matrix_get_all(DRWMatrixState *state); void DRW_viewport_matrix_override_set(float mat[4][4], DRWViewportMatrixType type); +void DRW_viewport_matrix_override_set_all(DRWMatrixState *state); void DRW_viewport_matrix_override_unset(DRWViewportMatrixType type); +void DRW_viewport_matrix_override_unset_all(void); + const float *DRW_viewport_size_get(void); const float *DRW_viewport_screenvecs_get(void); const float *DRW_viewport_pixelsize_get(void); diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c index aa0ddd0d31b..8feffa246ef 100644 --- a/source/blender/draw/intern/draw_manager.c +++ b/source/blender/draw/intern/draw_manager.c @@ -405,14 +405,14 @@ static void drw_viewport_var_init(void) /* Refresh DST.pixelsize */ DST.pixsize = rv3d->pixsize; - copy_m4_m4(DST.original_mat[DRW_MAT_PERS], rv3d->persmat); - copy_m4_m4(DST.original_mat[DRW_MAT_PERSINV], rv3d->persinv); - copy_m4_m4(DST.original_mat[DRW_MAT_VIEW], rv3d->viewmat); - copy_m4_m4(DST.original_mat[DRW_MAT_VIEWINV], rv3d->viewinv); - copy_m4_m4(DST.original_mat[DRW_MAT_WIN], rv3d->winmat); - invert_m4_m4(DST.original_mat[DRW_MAT_WININV], rv3d->winmat); + copy_m4_m4(DST.original_mat.mat[DRW_MAT_PERS], rv3d->persmat); + copy_m4_m4(DST.original_mat.mat[DRW_MAT_PERSINV], rv3d->persinv); + copy_m4_m4(DST.original_mat.mat[DRW_MAT_VIEW], rv3d->viewmat); + copy_m4_m4(DST.original_mat.mat[DRW_MAT_VIEWINV], rv3d->viewinv); + copy_m4_m4(DST.original_mat.mat[DRW_MAT_WIN], rv3d->winmat); + invert_m4_m4(DST.original_mat.mat[DRW_MAT_WININV], rv3d->winmat); - memcpy(DST.view_data.mat, DST.original_mat, sizeof(DST.original_mat)); + memcpy(DST.view_data.matstate.mat, DST.original_mat.mat, sizeof(DST.original_mat.mat)); copy_v4_v4(DST.view_data.viewcamtexcofac, rv3d->viewcamtexcofac); } @@ -448,26 +448,46 @@ static void drw_viewport_var_init(void) void DRW_viewport_matrix_get(float mat[4][4], DRWViewportMatrixType type) { - BLI_assert(type >= DRW_MAT_PERS && type <= DRW_MAT_WININV); + BLI_assert(type >= 0 && type < DRW_MAT_COUNT); BLI_assert(((DST.override_mat & (1 << type)) != 0)|| DST.draw_ctx.rv3d != NULL); /* Can't use this in render mode. */ - copy_m4_m4(mat, DST.view_data.mat[type]); + copy_m4_m4(mat, DST.view_data.matstate.mat[type]); +} + +void DRW_viewport_matrix_get_all(DRWMatrixState *state) +{ + memcpy(state, DST.view_data.matstate.mat, sizeof(DRWMatrixState)); } void DRW_viewport_matrix_override_set(float mat[4][4], DRWViewportMatrixType type) { - copy_m4_m4(DST.view_data.mat[type], mat); + BLI_assert(type < DRW_MAT_COUNT); + copy_m4_m4(DST.view_data.matstate.mat[type], mat); DST.override_mat |= (1 << type); DST.dirty_mat = true; } void DRW_viewport_matrix_override_unset(DRWViewportMatrixType type) { - copy_m4_m4(DST.view_data.mat[type], DST.original_mat[type]); + BLI_assert(type < DRW_MAT_COUNT); + copy_m4_m4(DST.view_data.matstate.mat[type], DST.original_mat.mat[type]); DST.override_mat &= ~(1 << type); DST.dirty_mat = true; } +void DRW_viewport_matrix_override_set_all(DRWMatrixState *state) +{ + memcpy(DST.view_data.matstate.mat, state, sizeof(DRWMatrixState)); + DST.dirty_mat = true; +} + +void DRW_viewport_matrix_override_unset_all(void) +{ + memcpy(DST.view_data.matstate.mat, DST.original_mat.mat, sizeof(DRWMatrixState)); + DST.override_mat = 0; + DST.dirty_mat = true; +} + bool DRW_viewport_is_persp_get(void) { RegionView3D *rv3d = DST.draw_ctx.rv3d; @@ -475,7 +495,7 @@ bool DRW_viewport_is_persp_get(void) return rv3d->is_persp; } else { - return DST.view_data.mat[DRW_MAT_WIN][3][3] == 0.0f; + return DST.view_data.matstate.mat[DRW_MAT_WIN][3][3] == 0.0f; } BLI_assert(0); return false; diff --git a/source/blender/draw/intern/draw_manager.h b/source/blender/draw/intern/draw_manager.h index 58973471c4e..f8989a0703a 100644 --- a/source/blender/draw/intern/draw_manager.h +++ b/source/blender/draw/intern/draw_manager.h @@ -305,13 +305,13 @@ typedef struct DRWManager { double cache_time; /* View dependant uniforms. */ - float original_mat[6][4][4]; /* Original rv3d matrices. */ + DRWMatrixState original_mat; /* Original rv3d matrices. */ int override_mat; /* Bitflag of which matrices are overriden. */ int num_clip_planes; /* Number of active clipplanes. */ bool dirty_mat; struct { - float mat[6][4][4]; + DRWMatrixState matstate; float viewcamtexcofac[4]; float clip_planes_eq[MAX_CLIP_PLANES][4]; } view_data; diff --git a/source/blender/draw/intern/draw_manager_data.c b/source/blender/draw/intern/draw_manager_data.c index fd4652a0305..8a644005484 100644 --- a/source/blender/draw/intern/draw_manager_data.c +++ b/source/blender/draw/intern/draw_manager_data.c @@ -458,12 +458,12 @@ static void drw_interface_init(DRWShadingGroup *shgroup, GPUShader *shader) #endif /* TODO : They should be grouped inside a UBO updated once per redraw. */ - drw_interface_builtin_uniform(shgroup, GWN_UNIFORM_VIEW, DST.view_data.mat[DRW_MAT_VIEW], 16, 1); - drw_interface_builtin_uniform(shgroup, GWN_UNIFORM_VIEW_INV, DST.view_data.mat[DRW_MAT_VIEWINV], 16, 1); - drw_interface_builtin_uniform(shgroup, GWN_UNIFORM_VIEWPROJECTION, DST.view_data.mat[DRW_MAT_PERS], 16, 1); - drw_interface_builtin_uniform(shgroup, GWN_UNIFORM_VIEWPROJECTION_INV, DST.view_data.mat[DRW_MAT_PERSINV], 16, 1); - drw_interface_builtin_uniform(shgroup, GWN_UNIFORM_PROJECTION, DST.view_data.mat[DRW_MAT_WIN], 16, 1); - drw_interface_builtin_uniform(shgroup, GWN_UNIFORM_PROJECTION_INV, DST.view_data.mat[DRW_MAT_WININV], 16, 1); + drw_interface_builtin_uniform(shgroup, GWN_UNIFORM_VIEW, DST.view_data.matstate.mat[DRW_MAT_VIEW], 16, 1); + drw_interface_builtin_uniform(shgroup, GWN_UNIFORM_VIEW_INV, DST.view_data.matstate.mat[DRW_MAT_VIEWINV], 16, 1); + drw_interface_builtin_uniform(shgroup, GWN_UNIFORM_VIEWPROJECTION, DST.view_data.matstate.mat[DRW_MAT_PERS], 16, 1); + drw_interface_builtin_uniform(shgroup, GWN_UNIFORM_VIEWPROJECTION_INV, DST.view_data.matstate.mat[DRW_MAT_PERSINV], 16, 1); + drw_interface_builtin_uniform(shgroup, GWN_UNIFORM_PROJECTION, DST.view_data.matstate.mat[DRW_MAT_WIN], 16, 1); + drw_interface_builtin_uniform(shgroup, GWN_UNIFORM_PROJECTION_INV, DST.view_data.matstate.mat[DRW_MAT_WININV], 16, 1); drw_interface_builtin_uniform(shgroup, GWN_UNIFORM_CAMERATEXCO, DST.view_data.viewcamtexcofac, 3, 2); drw_interface_builtin_uniform(shgroup, GWN_UNIFORM_CLIPPLANES, DST.view_data.clip_planes_eq, 4, DST.num_clip_planes); /* TO REMOVE */ @@ -895,7 +895,7 @@ static int pass_shgroup_dist_sort(void *thunk, const void *a, const void *b) void DRW_pass_sort_shgroup_z(DRWPass *pass) { float (*viewinv)[4]; - viewinv = DST.view_data.mat[DRW_MAT_VIEWINV]; + viewinv = DST.view_data.matstate.mat[DRW_MAT_VIEWINV]; ZSortData zsortdata = {viewinv[2], viewinv[3]}; diff --git a/source/blender/draw/intern/draw_manager_exec.c b/source/blender/draw/intern/draw_manager_exec.c index 055baff6a96..6cf8dfc7904 100644 --- a/source/blender/draw/intern/draw_manager_exec.c +++ b/source/blender/draw/intern/draw_manager_exec.c @@ -388,10 +388,10 @@ static void draw_clipping_setup_from_view(void) if (DST.clipping.updated) return; - float (*viewprojinv)[4] = DST.view_data.mat[DRW_MAT_PERSINV]; - float (*viewinv)[4] = DST.view_data.mat[DRW_MAT_VIEWINV]; - float (*projmat)[4] = DST.view_data.mat[DRW_MAT_WIN]; - float (*projinv)[4] = DST.view_data.mat[DRW_MAT_WININV]; + float (*viewprojinv)[4] = DST.view_data.matstate.mat[DRW_MAT_PERSINV]; + float (*viewinv)[4] = DST.view_data.matstate.mat[DRW_MAT_VIEWINV]; + float (*projmat)[4] = DST.view_data.matstate.mat[DRW_MAT_WIN]; + float (*projinv)[4] = DST.view_data.matstate.mat[DRW_MAT_WININV]; BoundSphere *bsphere = &DST.clipping.frustum_bsphere; /* Extract Clipping Planes */ @@ -555,13 +555,13 @@ static void draw_matrices_model_prepare(DRWCallState *st) if (st->matflag & (DRW_CALL_MODELVIEW | DRW_CALL_MODELVIEWINVERSE | DRW_CALL_NORMALVIEW | DRW_CALL_EYEVEC)) { - mul_m4_m4m4(st->modelview, DST.view_data.mat[DRW_MAT_VIEW], st->model); + mul_m4_m4m4(st->modelview, DST.view_data.matstate.mat[DRW_MAT_VIEW], st->model); } if (st->matflag & DRW_CALL_MODELVIEWINVERSE) { invert_m4_m4(st->modelviewinverse, st->modelview); } if (st->matflag & DRW_CALL_MODELVIEWPROJECTION) { - mul_m4_m4m4(st->modelviewprojection, DST.view_data.mat[DRW_MAT_PERS], st->model); + mul_m4_m4m4(st->modelviewprojection, DST.view_data.matstate.mat[DRW_MAT_PERS], st->model); } if (st->matflag & DRW_CALL_NORMALVIEW) { copy_m3_m4(st->normalview, st->modelview); @@ -610,9 +610,9 @@ static void draw_geometry_prepare(DRWShadingGroup *shgroup, DRWCallState *state) unit_m4(unitmat); GPU_shader_uniform_vector(shgroup->shader, shgroup->model, 16, 1, (float *)unitmat); GPU_shader_uniform_vector(shgroup->shader, shgroup->modelinverse, 16, 1, (float *)unitmat); - GPU_shader_uniform_vector(shgroup->shader, shgroup->modelview, 16, 1, (float *)DST.view_data.mat[DRW_MAT_VIEW]); - GPU_shader_uniform_vector(shgroup->shader, shgroup->modelviewinverse, 16, 1, (float *)DST.view_data.mat[DRW_MAT_VIEWINV]); - GPU_shader_uniform_vector(shgroup->shader, shgroup->modelviewprojection, 16, 1, (float *)DST.view_data.mat[DRW_MAT_PERS]); + GPU_shader_uniform_vector(shgroup->shader, shgroup->modelview, 16, 1, (float *)DST.view_data.matstate.mat[DRW_MAT_VIEW]); + GPU_shader_uniform_vector(shgroup->shader, shgroup->modelviewinverse, 16, 1, (float *)DST.view_data.matstate.mat[DRW_MAT_VIEWINV]); + GPU_shader_uniform_vector(shgroup->shader, shgroup->modelviewprojection, 16, 1, (float *)DST.view_data.matstate.mat[DRW_MAT_PERS]); GPU_shader_uniform_vector(shgroup->shader, shgroup->orcotexfac, 3, 2, (float *)shgroup->instance_orcofac); } } |