Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/intern/draw_manager_data.c
| Show First 20 Lines • Show All 660 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| BLI_assert(ob); | BLI_assert(ob); | ||||
| /* Index. */ | /* Index. */ | ||||
| ob_infos->ob_index = ob->index; | ob_infos->ob_index = ob->index; | ||||
| /* Orco factors. */ | /* Orco factors. */ | ||||
| drw_call_calc_orco(ob, ob_infos->orcotexfac); | drw_call_calc_orco(ob, ob_infos->orcotexfac); | ||||
| /* Random float value. */ | /* Random float value. */ | ||||
| uint random = (DST.dupli_source) ? | uint random = (DST.dupli_source) ? | ||||
| DST.dupli_source->random_id : | DST.dupli_source->random_id : | ||||
| /* TODO(fclem): this is rather costly to do at runtime. Maybe we can | /* TODO(fclem): this is rather costly to do at runtime. Maybe we can | ||||
| * put it in ob->runtime and make depsgraph ensure it is up to date. */ | * put it in ob->runtime and make depsgraph ensure it is up to date. */ | ||||
| BLI_hash_int_2d(BLI_hash_string(ob->id.name + 2), 0); | BLI_hash_int_2d(BLI_hash_string(ob->id.name + 2), 0); | ||||
| ob_infos->ob_random = random * (1.0f / (float)0xFFFFFFFF); | ob_infos->ob_random = random * (1.0f / (float)0xFFFFFFFF); | ||||
| /* Object State. */ | /* Object State. */ | ||||
| ob_infos->ob_flag = 1.0f; /* Required to have a correct sign */ | ob_infos->ob_flag = 1.0f; /* Required to have a correct sign */ | ||||
| ob_infos->ob_flag += (ob->base_flag & BASE_SELECTED) ? (1 << 1) : 0; | ob_infos->ob_flag += (ob->base_flag & BASE_SELECTED) ? (1 << 1) : 0; | ||||
| ob_infos->ob_flag += (ob->base_flag & BASE_FROM_DUPLI) ? (1 << 2) : 0; | ob_infos->ob_flag += (ob->base_flag & BASE_FROM_DUPLI) ? (1 << 2) : 0; | ||||
| ▲ Show 20 Lines • Show All 1,390 Lines • ▼ Show 20 Lines | else { | ||||
| /* For XR, the view matrix may contain a scale factor. Then, transforming only the center | /* For XR, the view matrix may contain a scale factor. Then, transforming only the center | ||||
| * into world space after calculating the radius will result in incorrect behavior. */ | * into world space after calculating the radius will result in incorrect behavior. */ | ||||
| mul_m4_v3(viewinv, bsphere->center); /* Transform to world space. */ | mul_m4_v3(viewinv, bsphere->center); /* Transform to world space. */ | ||||
| mul_m4_v3(viewinv, farpoint); | mul_m4_v3(viewinv, farpoint); | ||||
| bsphere->radius = len_v3v3(bsphere->center, farpoint); | bsphere->radius = len_v3v3(bsphere->center, farpoint); | ||||
| } | } | ||||
| } | } | ||||
| static void draw_view_matrix_state_update(ViewInfos *storage, | static void draw_view_matrix_state_update(DRWView *view, | ||||
| const float viewmat[4][4], | const float viewmat[4][4], | ||||
| const float winmat[4][4]) | const float winmat[4][4]) | ||||
| { | { | ||||
| ViewInfos *storage = &view->storage; | |||||
| copy_m4_m4(storage->viewmat, viewmat); | copy_m4_m4(storage->viewmat, viewmat); | ||||
| invert_m4_m4(storage->viewinv, storage->viewmat); | invert_m4_m4(storage->viewinv, storage->viewmat); | ||||
| copy_m4_m4(storage->winmat, winmat); | copy_m4_m4(storage->winmat, winmat); | ||||
| invert_m4_m4(storage->wininv, storage->winmat); | invert_m4_m4(storage->wininv, storage->winmat); | ||||
| mul_m4_m4m4(storage->persmat, winmat, viewmat); | mul_m4_m4m4(view->persmat, winmat, viewmat); | ||||
| invert_m4_m4(storage->persinv, storage->persmat); | invert_m4_m4(view->persinv, view->persmat); | ||||
| const bool is_persp = (winmat[3][3] == 0.0f); | const bool is_persp = (winmat[3][3] == 0.0f); | ||||
| /* Near clip distance. */ | /* Near clip distance. */ | ||||
| storage->viewvecs[0][3] = (is_persp) ? -winmat[3][2] / (winmat[2][2] - 1.0f) : | storage->viewvecs[0][3] = (is_persp) ? -winmat[3][2] / (winmat[2][2] - 1.0f) : | ||||
| -(winmat[3][2] + 1.0f) / winmat[2][2]; | -(winmat[3][2] + 1.0f) / winmat[2][2]; | ||||
| /* Far clip distance. */ | /* Far clip distance. */ | ||||
| ▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Lines | |||||
| void DRW_view_update_sub(DRWView *view, const float viewmat[4][4], const float winmat[4][4]) | void DRW_view_update_sub(DRWView *view, const float viewmat[4][4], const float winmat[4][4]) | ||||
| { | { | ||||
| BLI_assert(view->parent != NULL); | BLI_assert(view->parent != NULL); | ||||
| view->is_dirty = true; | view->is_dirty = true; | ||||
| view->is_inverted = (is_negative_m4(viewmat) == is_negative_m4(winmat)); | view->is_inverted = (is_negative_m4(viewmat) == is_negative_m4(winmat)); | ||||
| draw_view_matrix_state_update(&view->storage, viewmat, winmat); | draw_view_matrix_state_update(view, viewmat, winmat); | ||||
| } | } | ||||
| void DRW_view_update(DRWView *view, | void DRW_view_update(DRWView *view, | ||||
| const float viewmat[4][4], | const float viewmat[4][4], | ||||
| const float winmat[4][4], | const float winmat[4][4], | ||||
| const float (*culling_viewmat)[4], | const float (*culling_viewmat)[4], | ||||
| const float (*culling_winmat)[4]) | const float (*culling_winmat)[4]) | ||||
| { | { | ||||
| /* DO NOT UPDATE THE DEFAULT VIEW. | /* DO NOT UPDATE THE DEFAULT VIEW. | ||||
| * Create sub-views instead, or a copy. */ | * Create sub-views instead, or a copy. */ | ||||
| BLI_assert(view != DST.view_default); | BLI_assert(view != DST.view_default); | ||||
| BLI_assert(view->parent == NULL); | BLI_assert(view->parent == NULL); | ||||
| view->is_dirty = true; | view->is_dirty = true; | ||||
| view->is_inverted = (is_negative_m4(viewmat) == is_negative_m4(winmat)); | view->is_inverted = (is_negative_m4(viewmat) == is_negative_m4(winmat)); | ||||
| draw_view_matrix_state_update(&view->storage, viewmat, winmat); | draw_view_matrix_state_update(view, viewmat, winmat); | ||||
| /* Prepare frustum culling. */ | /* Prepare frustum culling. */ | ||||
| #ifdef DRW_DEBUG_CULLING | #ifdef DRW_DEBUG_CULLING | ||||
| static float mv[MAX_CULLED_VIEWS][4][4], mw[MAX_CULLED_VIEWS][4][4]; | static float mv[MAX_CULLED_VIEWS][4][4], mw[MAX_CULLED_VIEWS][4][4]; | ||||
| /* Select view here. */ | /* Select view here. */ | ||||
| if (view->culling_mask != 0) { | if (view->culling_mask != 0) { | ||||
| Show All 24 Lines | if (culling_viewmat) { | ||||
| viewmat = culling_viewmat; | viewmat = culling_viewmat; | ||||
| invert_m4_m4(viewinv, viewmat); | invert_m4_m4(viewinv, viewmat); | ||||
| } | } | ||||
| else { | else { | ||||
| copy_m4_m4(viewinv, view->storage.viewinv); | copy_m4_m4(viewinv, view->storage.viewinv); | ||||
| } | } | ||||
| draw_frustum_boundbox_calc(viewinv, winmat, &view->frustum_corners); | draw_frustum_boundbox_calc(viewinv, winmat, &view->frustum_corners); | ||||
| draw_frustum_culling_planes_calc(view->storage.persmat, view->frustum_planes); | draw_frustum_culling_planes_calc(view->persmat, view->frustum_planes); | ||||
| draw_frustum_bound_sphere_calc( | draw_frustum_bound_sphere_calc( | ||||
| &view->frustum_corners, viewinv, winmat, wininv, &view->frustum_bsphere); | &view->frustum_corners, viewinv, winmat, wininv, &view->frustum_bsphere); | ||||
| /* TODO(fclem): Deduplicate. */ | /* TODO(fclem): Deduplicate. */ | ||||
| for (int i = 0; i < 8; i++) { | for (int i = 0; i < 8; i++) { | ||||
| copy_v3_v3(view->storage.frustum_corners[i], view->frustum_corners.vec[i]); | copy_v3_v3(view->storage.frustum_corners[i], view->frustum_corners.vec[i]); | ||||
| } | } | ||||
| for (int i = 0; i < 6; i++) { | for (int i = 0; i < 6; i++) { | ||||
| ▲ Show 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | void DRW_view_winmat_get(const DRWView *view, float mat[4][4], bool inverse) | ||||
| view = (view) ? view : DST.view_default; | view = (view) ? view : DST.view_default; | ||||
| const ViewInfos *storage = &view->storage; | const ViewInfos *storage = &view->storage; | ||||
| copy_m4_m4(mat, (inverse) ? storage->wininv : storage->winmat); | copy_m4_m4(mat, (inverse) ? storage->wininv : storage->winmat); | ||||
| } | } | ||||
| void DRW_view_persmat_get(const DRWView *view, float mat[4][4], bool inverse) | void DRW_view_persmat_get(const DRWView *view, float mat[4][4], bool inverse) | ||||
| { | { | ||||
| view = (view) ? view : DST.view_default; | view = (view) ? view : DST.view_default; | ||||
| const ViewInfos *storage = &view->storage; | copy_m4_m4(mat, (inverse) ? view->persinv : view->persmat); | ||||
| copy_m4_m4(mat, (inverse) ? storage->persinv : storage->persmat); | |||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Passes (DRW_pass) | /** \name Passes (DRW_pass) | ||||
| * \{ */ | * \{ */ | ||||
| ▲ Show 20 Lines • Show All 145 Lines • Show Last 20 Lines | |||||