Changeset View
Standalone View
source/blender/editors/include/ED_uvedit.h
| /* SPDX-License-Identifier: GPL-2.0-or-later | /* SPDX-License-Identifier: GPL-2.0-or-later | ||||
| * Copyright 2008 Blender Foundation. All rights reserved. */ | * Copyright 2008 Blender Foundation. All rights reserved. */ | ||||
| /** \file | /** \file | ||||
| * \ingroup editors | * \ingroup editors | ||||
| */ | */ | ||||
| #pragma once | #pragma once | ||||
| #include "BKE_customdata.h" | |||||
| #ifdef __cplusplus | #ifdef __cplusplus | ||||
| extern "C" { | extern "C" { | ||||
| #endif | #endif | ||||
| struct ARegion; | struct ARegion; | ||||
| struct ARegionType; | struct ARegionType; | ||||
| struct BMEditMesh; | struct BMEditMesh; | ||||
| struct BMFace; | struct BMFace; | ||||
| ▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | |||||
| bool ED_uvedit_test(struct Object *obedit); | bool ED_uvedit_test(struct Object *obedit); | ||||
| /* Visibility and selection tests. */ | /* Visibility and selection tests. */ | ||||
| bool uvedit_face_visible_test_ex(const struct ToolSettings *ts, struct BMFace *efa); | bool uvedit_face_visible_test_ex(const struct ToolSettings *ts, struct BMFace *efa); | ||||
| bool uvedit_face_select_test_ex(const struct ToolSettings *ts, | bool uvedit_face_select_test_ex(const struct ToolSettings *ts, | ||||
| struct BMFace *efa, | struct BMFace *efa, | ||||
| int cd_loop_uv_offset); | BMUVOffsets offsets); | ||||
campbellbarton: Pass by `const` pointer instead of by value, same for other functions here. | |||||
Done Inline ActionsI strongly disagree. We'd need nullptr checks in every function taking such a pointer. const reference I can live with. In fact I had them all as const reference before changing them to pass by value at the request of @Hans Goudey (HooglyBoogly) . Baardaap: I strongly disagree. We'd need nullptr checks in every function taking such a pointer.
const… | |||||
Done Inline ActionsOh. hm. it's C, so no pass by const reference. Still... isn't this something better left to the compiler these days? Baardaap: Oh. hm. it's C, so no pass by const reference.
Still... isn't this something better left to… | |||||
Done Inline ActionsThis struct is very small, it's just four integers-- the same size as Span and other structs we typically pass by value. It makes the code much simpler to pass by value, especially C code without the concept of references. So I'm in favor of passing by value here. HooglyBoogly: This struct is very small, it's just four integers-- the same size as `Span` and other structs… | |||||
Done Inline ActionsI was/am concerned with this adding overhead to draw code. for e.g. this passing 16 byte argument to drawing functions that run on every face & loop (updating edit-mesh draw data), even when the mesh doesn't have UV's (just to check the value is -1 and returning in some cases). However I couldn't measure a performance difference so I suppose it's OK, it would be good to have a rule of thumb for whats reasonable to pass by value (noticed larger structs being passed by value creeping into our code recently), although some seem like mistakes too. campbellbarton: I was/am concerned with this adding overhead to draw code. for e.g. this passing 16 byte… | |||||
Done Inline ActionsAs an aside, some studying of generated code in godbolt made me think passing by reference is not a certified win either. For small(ish) functions gcc -O3 was inlined when passed by value (struct with 4 integers), but not when passed by reference. Also when passing by reference extra instructions were generated to move the referenced value into registers to work on them, while in the pass-by-value they already were in registers. I guess it depends on register-pressure which is faster, but imo without profiling it's not really possible to tell which is actually better. So to me passing this by reference/pointer feels like 'premature optimisation' . Though I must admit I need to suppress an urge to do it anyway, since for me having learned C in the early 90s passing 128 bytes *on the stack* feels like heresy :-D Baardaap: As an aside, some studying of generated code in godbolt made me think passing by reference is… | |||||
| bool uvedit_edge_select_test_ex(const struct ToolSettings *ts, | bool uvedit_edge_select_test_ex(const struct ToolSettings *ts, | ||||
| struct BMLoop *l, | struct BMLoop *l, | ||||
| int cd_loop_uv_offset); | BMUVOffsets offsets); | ||||
| bool uvedit_uv_select_test_ex(const struct ToolSettings *ts, | bool uvedit_uv_select_test_ex(const struct ToolSettings *ts, | ||||
| struct BMLoop *l, | struct BMLoop *l, | ||||
| int cd_loop_uv_offset); | BMUVOffsets offsets); | ||||
| bool uvedit_face_visible_test(const struct Scene *scene, struct BMFace *efa); | bool uvedit_face_visible_test(const struct Scene *scene, struct BMFace *efa); | ||||
| bool uvedit_face_select_test(const struct Scene *scene, struct BMFace *efa, int cd_loop_uv_offset); | bool uvedit_face_select_test(const struct Scene *scene, struct BMFace *efa, BMUVOffsets offsets); | ||||
| bool uvedit_edge_select_test(const struct Scene *scene, struct BMLoop *l, int cd_loop_uv_offset); | bool uvedit_edge_select_test(const struct Scene *scene, struct BMLoop *l, BMUVOffsets offsets); | ||||
| bool uvedit_uv_select_test(const struct Scene *scene, struct BMLoop *l, int cd_loop_uv_offset); | bool uvedit_uv_select_test(const struct Scene *scene, struct BMLoop *l, BMUVOffsets offsets); | ||||
| /* Individual UV element selection functions. */ | /* Individual UV element selection functions. */ | ||||
| /** | /** | ||||
| * \brief Select UV Face | * \brief Select UV Face | ||||
| * | * | ||||
| * Changes selection state of a single UV Face. | * Changes selection state of a single UV Face. | ||||
| */ | */ | ||||
| void uvedit_face_select_set(const struct Scene *scene, | void uvedit_face_select_set(const struct Scene *scene, | ||||
| struct BMesh *bm, | struct BMesh *bm, | ||||
| struct BMFace *efa, | struct BMFace *efa, | ||||
| bool select, | bool select, | ||||
| bool do_history, | bool do_history, | ||||
| int cd_loop_uv_offset); | BMUVOffsets offsets); | ||||
| /** | /** | ||||
| * \brief Select UV Edge | * \brief Select UV Edge | ||||
| * | * | ||||
| * Changes selection state of a single UV Edge. | * Changes selection state of a single UV Edge. | ||||
| */ | */ | ||||
| void uvedit_edge_select_set(const struct Scene *scene, | void uvedit_edge_select_set(const struct Scene *scene, | ||||
| struct BMesh *bm, | struct BMesh *bm, | ||||
| struct BMLoop *l, | struct BMLoop *l, | ||||
| bool select, | bool select, | ||||
| bool do_history, | bool do_history, | ||||
| int cd_loop_uv_offset); | BMUVOffsets offsets); | ||||
| /** | /** | ||||
| * \brief Select UV Vertex | * \brief Select UV Vertex | ||||
| * | * | ||||
| * Changes selection state of a single UV vertex. | * Changes selection state of a single UV vertex. | ||||
| */ | */ | ||||
| void uvedit_uv_select_set(const struct Scene *scene, | void uvedit_uv_select_set(const struct Scene *scene, | ||||
| struct BMesh *bm, | struct BMesh *bm, | ||||
| struct BMLoop *l, | struct BMLoop *l, | ||||
| bool select, | bool select, | ||||
| bool do_history, | bool do_history, | ||||
| int cd_loop_uv_offset); | BMUVOffsets offsets); | ||||
| /* Low level functions for (de)selecting individual UV elements. Ensure UV face visibility before | /* Low level functions for (de)selecting individual UV elements. Ensure UV face visibility before | ||||
| * use. */ | * use. */ | ||||
| void uvedit_face_select_enable(const struct Scene *scene, | void uvedit_face_select_enable(const struct Scene *scene, | ||||
| struct BMesh *bm, | struct BMesh *bm, | ||||
| struct BMFace *efa, | struct BMFace *efa, | ||||
| bool do_history, | bool do_history, | ||||
| int cd_loop_uv_offset); | BMUVOffsets offsets); | ||||
| void uvedit_face_select_disable(const struct Scene *scene, | void uvedit_face_select_disable(const struct Scene *scene, | ||||
| struct BMesh *bm, | struct BMesh *bm, | ||||
| struct BMFace *efa, | struct BMFace *efa, | ||||
| int cd_loop_uv_offset); | BMUVOffsets offsets); | ||||
| void uvedit_edge_select_enable(const struct Scene *scene, | void uvedit_edge_select_enable(const struct Scene *scene, | ||||
| struct BMesh *bm, | struct BMesh *bm, | ||||
| struct BMLoop *l, | struct BMLoop *l, | ||||
| bool do_history, | bool do_history, | ||||
| int cd_loop_uv_offset); | BMUVOffsets offsets); | ||||
| void uvedit_edge_select_disable(const struct Scene *scene, | void uvedit_edge_select_disable(const struct Scene *scene, | ||||
| struct BMesh *bm, | struct BMesh *bm, | ||||
| struct BMLoop *l, | struct BMLoop *l, | ||||
| int cd_loop_uv_offset); | BMUVOffsets offsets); | ||||
| void uvedit_uv_select_enable(const struct Scene *scene, | void uvedit_uv_select_enable(const struct Scene *scene, | ||||
| struct BMesh *bm, | struct BMesh *bm, | ||||
| struct BMLoop *l, | struct BMLoop *l, | ||||
| bool do_history, | bool do_history, | ||||
| int cd_loop_uv_offset); | BMUVOffsets offsets); | ||||
| void uvedit_uv_select_disable(const struct Scene *scene, | void uvedit_uv_select_disable(const struct Scene *scene, | ||||
| struct BMesh *bm, | struct BMesh *bm, | ||||
| struct BMLoop *l, | struct BMLoop *l, | ||||
| int cd_loop_uv_offset); | BMUVOffsets offsets); | ||||
| /* Sticky mode UV element selection functions. */ | /* Sticky mode UV element selection functions. */ | ||||
| void uvedit_face_select_set_with_sticky(const struct Scene *scene, | void uvedit_face_select_set_with_sticky(const struct Scene *scene, | ||||
| struct BMEditMesh *em, | struct BMEditMesh *em, | ||||
| struct BMFace *efa, | struct BMFace *efa, | ||||
| bool select, | bool select, | ||||
| bool do_history, | bool do_history, | ||||
| int cd_loop_uv_offset); | BMUVOffsets offsets); | ||||
| void uvedit_edge_select_set_with_sticky(const struct Scene *scene, | void uvedit_edge_select_set_with_sticky(const struct Scene *scene, | ||||
| struct BMEditMesh *em, | struct BMEditMesh *em, | ||||
| struct BMLoop *l, | struct BMLoop *l, | ||||
| bool select, | bool select, | ||||
| bool do_history, | bool do_history, | ||||
| int cd_loop_uv_offset); | BMUVOffsets offsets); | ||||
| void uvedit_uv_select_set_with_sticky(const struct Scene *scene, | void uvedit_uv_select_set_with_sticky(const struct Scene *scene, | ||||
| struct BMEditMesh *em, | struct BMEditMesh *em, | ||||
| struct BMLoop *l, | struct BMLoop *l, | ||||
| bool select, | bool select, | ||||
| bool do_history, | bool do_history, | ||||
| int cd_loop_uv_offset); | BMUVOffsets offsets); | ||||
| /* Low level functions for sticky element selection (sticky mode independent). Type of sticky | /* Low level functions for sticky element selection (sticky mode independent). Type of sticky | ||||
| * selection is specified explicitly (using sticky_flag, except for face selection). */ | * selection is specified explicitly (using sticky_flag, except for face selection). */ | ||||
| void uvedit_face_select_shared_vert(const struct Scene *scene, | void uvedit_face_select_shared_vert(const struct Scene *scene, | ||||
| struct BMEditMesh *em, | struct BMEditMesh *em, | ||||
| struct BMFace *efa, | struct BMFace *efa, | ||||
| const bool select, | const bool select, | ||||
| const bool do_history, | const bool do_history, | ||||
| const int cd_loop_uv_offset); | BMUVOffsets offsets); | ||||
| void uvedit_edge_select_shared_vert(const struct Scene *scene, | void uvedit_edge_select_shared_vert(const struct Scene *scene, | ||||
| struct BMEditMesh *em, | struct BMEditMesh *em, | ||||
| struct BMLoop *l, | struct BMLoop *l, | ||||
| const bool select, | const bool select, | ||||
| const int sticky_flag, | const int sticky_flag, | ||||
| const bool do_history, | const bool do_history, | ||||
| const int cd_loop_uv_offset); | BMUVOffsets offsets); | ||||
| void uvedit_uv_select_shared_vert(const struct Scene *scene, | void uvedit_uv_select_shared_vert(const struct Scene *scene, | ||||
| struct BMEditMesh *em, | struct BMEditMesh *em, | ||||
| struct BMLoop *l, | struct BMLoop *l, | ||||
| const bool select, | const bool select, | ||||
| const int sticky_flag, | const int sticky_flag, | ||||
| const bool do_history, | const bool do_history, | ||||
| const int cd_loop_uv_offset); | BMUVOffsets offsets); | ||||
| /* Sets required UV edge flags as specified by the sticky_flag. */ | /* Sets required UV edge flags as specified by the sticky_flag. */ | ||||
| void uvedit_edge_select_set_noflush(const struct Scene *scene, | void uvedit_edge_select_set_noflush(const struct Scene *scene, | ||||
| struct BMLoop *l, | struct BMLoop *l, | ||||
| const bool select, | const bool select, | ||||
| const int sticky_flag, | const int sticky_flag, | ||||
| const int cd_loop_uv_offset); | BMUVOffsets offsets); | ||||
| /** | /** | ||||
| * \brief UV Select Mode set | * \brief UV Select Mode set | ||||
| * | * | ||||
| * Updates selection state for UVs based on the select mode and sticky mode. Similar to | * Updates selection state for UVs based on the select mode and sticky mode. Similar to | ||||
| * #EDBM_selectmode_set. | * #EDBM_selectmode_set. | ||||
| */ | */ | ||||
| void ED_uvedit_selectmode_clean(const struct Scene *scene, struct Object *obedit); | void ED_uvedit_selectmode_clean(const struct Scene *scene, struct Object *obedit); | ||||
| ▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | struct FaceIsland { | ||||
| struct FaceIsland *prev; | struct FaceIsland *prev; | ||||
| struct BMFace **faces; | struct BMFace **faces; | ||||
| int faces_len; | int faces_len; | ||||
| rctf bounds_rect; | rctf bounds_rect; | ||||
| /** | /** | ||||
| * \note While this is duplicate information, | * \note While this is duplicate information, | ||||
| * it allows islands from multiple meshes to be stored in the same list. | * it allows islands from multiple meshes to be stored in the same list. | ||||
| */ | */ | ||||
| int cd_loop_uv_offset; | BMUVOffsets offsets; | ||||
| float aspect_y; | float aspect_y; | ||||
| }; | }; | ||||
| int bm_mesh_calc_uv_islands(const Scene *scene, | int bm_mesh_calc_uv_islands(const Scene *scene, | ||||
| struct BMesh *bm, | struct BMesh *bm, | ||||
| ListBase *island_list, | ListBase *island_list, | ||||
| const bool only_selected_faces, | const bool only_selected_faces, | ||||
| const bool only_selected_uvs, | const bool only_selected_uvs, | ||||
| const bool use_seams, | const bool use_seams, | ||||
| const float aspect_y, | const float aspect_y, | ||||
| const int cd_loop_uv_offset); | BMUVOffsets offsets); | ||||
| struct UVMapUDIM_Params { | struct UVMapUDIM_Params { | ||||
| const struct Image *image; | const struct Image *image; | ||||
| /** Copied from #SpaceImage.tile_grid_shape */ | /** Copied from #SpaceImage.tile_grid_shape */ | ||||
| int grid_shape[2]; | int grid_shape[2]; | ||||
| }; | }; | ||||
| typedef enum { | typedef enum { | ||||
| ▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines | |||||
Pass by const pointer instead of by value, same for other functions here.