Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/uvedit/uvedit_draw.c
| Show First 20 Lines • Show All 179 Lines • ▼ Show 20 Lines | static void uvedit_get_batches(Object *ob, | ||||
| if (drawfaces) { | if (drawfaces) { | ||||
| *facedots = DRW_mesh_batch_cache_get_edituv_facedots(ob->data); | *facedots = DRW_mesh_batch_cache_get_edituv_facedots(ob->data); | ||||
| } | } | ||||
| else { | else { | ||||
| *facedots = NULL; | *facedots = NULL; | ||||
| } | } | ||||
| if (draw_stretch && (sima->dt_uvstretch == SI_UVDT_STRETCH_AREA)) { | if (draw_stretch && (sima->dt_uvstretch == SI_UVDT_STRETCH_AREA)) { | ||||
| *faces = DRW_mesh_batch_cache_get_edituv_faces_strech_area(ob->data); | *faces = DRW_mesh_batch_cache_get_edituv_faces_stretch_area(ob->data, NULL, NULL); | ||||
| } | } | ||||
| else if (draw_stretch) { | else if (draw_stretch) { | ||||
| *faces = DRW_mesh_batch_cache_get_edituv_faces_strech_angle(ob->data); | *faces = DRW_mesh_batch_cache_get_edituv_faces_stretch_angle(ob->data); | ||||
| } | } | ||||
| else if (draw_faces) { | else if (draw_faces) { | ||||
| *faces = DRW_mesh_batch_cache_get_edituv_faces(ob->data); | *faces = DRW_mesh_batch_cache_get_edituv_faces(ob->data); | ||||
| } | } | ||||
| else { | else { | ||||
| *faces = NULL; | *faces = NULL; | ||||
| } | } | ||||
| DRW_mesh_batch_cache_create_requested(ob, ob->data, scene, false, false); | DRW_mesh_batch_cache_create_requested(ob, ob->data, scene, false, false); | ||||
| } | } | ||||
| static void draw_uvs_shadow(SpaceImage *UNUSED(sima), | static void draw_uvs_shadow(SpaceImage *UNUSED(sima), | ||||
fclem: This function looks weird. I preferred the way it was before with additional parameters to… | |||||
| Scene *scene, | Scene *scene, | ||||
| Object *obedit, | Object *obedit, | ||||
| Depsgraph *depsgraph) | Depsgraph *depsgraph) | ||||
| { | { | ||||
| Object *ob_eval = DEG_get_evaluated_object(depsgraph, obedit); | Object *ob_eval = DEG_get_evaluated_object(depsgraph, obedit); | ||||
| Mesh *me = ob_eval->data; | Mesh *me = ob_eval->data; | ||||
| float col[4]; | float col[4]; | ||||
| UI_GetThemeColor4fv(TH_UV_SHADOW, col); | UI_GetThemeColor4fv(TH_UV_SHADOW, col); | ||||
| ▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | if (do_material_masking && me->mloopuv) { | ||||
| GPU_batch_program_use_end(geom); | GPU_batch_program_use_end(geom); | ||||
| } | } | ||||
| else { | else { | ||||
| GPU_batch_draw(geom); | GPU_batch_draw(geom); | ||||
| } | } | ||||
| } | } | ||||
| /* draws uv's in the image space */ | /* draws uv's in the image space */ | ||||
| static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit, Depsgraph *depsgraph) | /** | ||||
| * Sum the areas in mesh and uv space of all given objects and return the ratios | |||||
| * needed for drawing. | |||||
| */ | |||||
| static void get_draw_stretch_area_ratios(SpaceImage *sima, | |||||
| Scene *scene, | |||||
| uint num_objects, | |||||
| Object *objects[], | |||||
| Depsgraph *depsgraph, | |||||
| float *tot_area_ratio, | |||||
| float *tot_area_ratio_inv) | |||||
| { | |||||
| const bool draw_stretch = (sima->flag & SI_DRAW_STRETCH) != 0; | |||||
| const bool stretch_area = sima->dt_uvstretch == SI_UVDT_STRETCH_AREA; | |||||
| if (draw_stretch && stretch_area) { | |||||
| float sum_tot_area = 0.0f; | |||||
| float sum_tot_uv_area = 0.0f; | |||||
| for (int iter_index = 0; iter_index < num_objects; iter_index++) { | |||||
| Object *ob = objects[iter_index]; | |||||
| Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); | |||||
| float ob_tot_area = 0.0f; | |||||
| float ob_tot_uv_area = 0.0f; | |||||
| Mesh *mesh_eval = ob_eval->data; | |||||
| /* XXX: Jikes! Let's say this does not fit in the current design at all! | |||||
| * | |||||
| * The plan is that we are moving the drawing of the uv editor to the draw | |||||
| * manager. When doing that we will be able to optimize it. */ | |||||
| DRW_mesh_batch_cache_validate(mesh_eval); | |||||
| DRW_mesh_batch_cache_get_edituv_faces_stretch_area(mesh_eval, NULL, NULL); | |||||
| DRW_mesh_batch_cache_create_requested(ob_eval, mesh_eval, scene, false, false); | |||||
| DRW_mesh_batch_cache_get_edituv_faces_stretch_area(mesh_eval, &ob_tot_area, &ob_tot_uv_area); | |||||
| sum_tot_area += ob_tot_area; | |||||
| sum_tot_uv_area += ob_tot_uv_area; | |||||
| } | |||||
| if (sum_tot_area > FLT_EPSILON && sum_tot_uv_area > FLT_EPSILON) { | |||||
| *tot_area_ratio = sum_tot_area / sum_tot_uv_area; | |||||
| *tot_area_ratio_inv = sum_tot_uv_area / sum_tot_area; | |||||
| } | |||||
| else { | |||||
| *tot_area_ratio = 0.0f; | |||||
| *tot_area_ratio_inv = 0.0f; | |||||
| } | |||||
| } | |||||
| } | |||||
| static void draw_uvs(SpaceImage *sima, | |||||
| Scene *scene, | |||||
| Object *obedit, | |||||
| Depsgraph *depsgraph, | |||||
| float tot_area_ratio, | |||||
| float tot_area_ratio_inv) | |||||
| { | { | ||||
| GPUBatch *faces, *edges, *verts, *facedots; | GPUBatch *faces, *edges, *verts, *facedots; | ||||
| Object *ob_eval = DEG_get_evaluated_object(depsgraph, obedit); | Object *ob_eval = DEG_get_evaluated_object(depsgraph, obedit); | ||||
| const ToolSettings *ts = scene->toolsettings; | const ToolSettings *ts = scene->toolsettings; | ||||
| float col1[4], col2[4], col3[4], transparent[4] = {0.0f, 0.0f, 0.0f, 0.0f}; | float col1[4], col2[4], col3[4], transparent[4] = {0.0f, 0.0f, 0.0f, 0.0f}; | ||||
| if (sima->flag & SI_DRAWSHADOW) { | if (sima->flag & SI_DRAWSHADOW) { | ||||
| bool is_cage_like_final_meshes = false; | bool is_cage_like_final_meshes = false; | ||||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | if (!draw_stretch) { | ||||
| GPU_batch_uniform_4fv(faces, "selectColor", col2); | GPU_batch_uniform_4fv(faces, "selectColor", col2); | ||||
| GPU_batch_uniform_4fv(faces, "activeColor", col3); | GPU_batch_uniform_4fv(faces, "activeColor", col3); | ||||
| } | } | ||||
| else if (sima->dt_uvstretch == SI_UVDT_STRETCH_ANGLE) { | else if (sima->dt_uvstretch == SI_UVDT_STRETCH_ANGLE) { | ||||
| float asp[2]; | float asp[2]; | ||||
| ED_space_image_get_uv_aspect(sima, &asp[0], &asp[1]); | ED_space_image_get_uv_aspect(sima, &asp[0], &asp[1]); | ||||
| GPU_batch_uniform_2fv(faces, "aspect", asp); | GPU_batch_uniform_2fv(faces, "aspect", asp); | ||||
| } | } | ||||
| else if (sima->dt_uvstretch == SI_UVDT_STRETCH_AREA) { | |||||
| GPU_batch_uniform_1f(faces, "totalAreaRatio", tot_area_ratio); | |||||
| GPU_batch_uniform_1f(faces, "totalAreaRatioInv", tot_area_ratio_inv); | |||||
| } | |||||
| GPU_batch_draw(faces); | GPU_batch_draw(faces); | ||||
| if (!draw_stretch) { | if (!draw_stretch) { | ||||
| GPU_blend(false); | GPU_blend(false); | ||||
| } | } | ||||
| } | } | ||||
| if (edges) { | if (edges) { | ||||
| ▲ Show 20 Lines • Show All 142 Lines • ▼ Show 20 Lines | if (show_uvedit || show_uvshadow || show_texpaint_uvshadow) { | ||||
| else if (show_uvedit) { | else if (show_uvedit) { | ||||
| uint objects_len = 0; | uint objects_len = 0; | ||||
| Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs( | Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs( | ||||
| view_layer, ((View3D *)NULL), &objects_len); | view_layer, ((View3D *)NULL), &objects_len); | ||||
| if (objects_len > 0) { | if (objects_len > 0) { | ||||
| GPU_clear_depth(1.0f); | GPU_clear_depth(1.0f); | ||||
| GPU_clear(GPU_DEPTH_BIT); | GPU_clear(GPU_DEPTH_BIT); | ||||
| } | } | ||||
| float tot_area_ratio = 0.0f; | |||||
| float tot_area_ratio_inv = 0.0f; | |||||
| get_draw_stretch_area_ratios( | |||||
| sima, scene, objects_len, objects, depsgraph, &tot_area_ratio, &tot_area_ratio_inv); | |||||
| for (uint ob_index = 0; ob_index < objects_len; ob_index++) { | for (uint ob_index = 0; ob_index < objects_len; ob_index++) { | ||||
| Object *ob_iter = objects[ob_index]; | Object *ob_iter = objects[ob_index]; | ||||
| draw_uvs(sima, scene, ob_iter, depsgraph); | draw_uvs(sima, scene, ob_iter, depsgraph, tot_area_ratio, tot_area_ratio_inv); | ||||
| } | } | ||||
| MEM_freeN(objects); | MEM_freeN(objects); | ||||
| } | } | ||||
| else { | else { | ||||
| draw_uvs_texpaint(scene, obact, depsgraph); | draw_uvs_texpaint(scene, obact, depsgraph); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
This function looks weird. I preferred the way it was before with additional parameters to DRW_mesh_batch_cache_get_edituv_faces_stretch_angle.
Here this function seems really hacky but I agree the other way is not optimal either as you have to know when to dereference the pointer.