Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/transform/transform_constraints.c
| Context not available. | |||||
| #include "GPU_matrix.h" | #include "GPU_matrix.h" | ||||
| #include "GPU_state.h" | #include "GPU_state.h" | ||||
| #include "DRW_render.h" | |||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "BLI_string.h" | #include "BLI_string.h" | ||||
| Context not available. | |||||
| } | } | ||||
| } | } | ||||
| void drawPropVerts(const struct bContext *C, TransInfo *t) | |||||
| { | |||||
| if (!(t->flag & T_PROP_EDIT)) { | |||||
| return; | |||||
| } | |||||
| ToolSettings *ts = CTX_data_tool_settings(C); | |||||
| if (!ts->proportional_draw_gradient) { | |||||
| return; | |||||
| } | |||||
| if (t->mode == TFM_EDGE_SLIDE || t->mode == TFM_VERT_SLIDE) { | |||||
| return; | |||||
| } | |||||
| if (t->spacetype == SPACE_VIEW3D || t->spacetype == SPACE_IMAGE) { | |||||
campbellbarton: Prefer early return, as is done above.
Could also use note on other spaces that might be… | |||||
| bool is_view3d = t->spacetype == SPACE_VIEW3D; | |||||
| float color_start[4], color_center[4], color_end[4]; | |||||
| UI_GetThemeColor4fv(TH_PROP_GRADIENT_START, color_start); | |||||
| UI_GetThemeColor4fv(TH_PROP_GRADIENT_CENTER, color_center); | |||||
| UI_GetThemeColor4fv(TH_PROP_GRADIENT_END, color_end); | |||||
| float color[4]; | |||||
| copy_v4_v4(color, color_end); | |||||
| color[3] = 1.0; | |||||
| const float vertex_size = UI_GetThemeValuef(TH_VERTEX_SIZE) * 1.666f; | |||||
| int depth_test_enabled; | |||||
| depth_test_enabled = GPU_depth_test_enabled(); | |||||
| GPUVertFormat *format = immVertexFormat(); | |||||
| uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); | |||||
| uint col = GPU_vertformat_attr_add(format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT); | |||||
| if (is_view3d) { | |||||
| /*for object mode just draw over everything*/ | |||||
campbellbartonUnsubmitted Not Done Inline ActionsUse spaces around comments & full sentences, same for other comments here. /* For object mode just draw over everything. */ campbellbarton: Use spaces around comments & full sentences, same for other comments here.
`/* For object mode… | |||||
| if (!(t->flag & T_EDIT) && depth_test_enabled) | |||||
| GPU_depth_test(false); | |||||
| else if (!depth_test_enabled) | |||||
| GPU_depth_test(true); | |||||
campbellbartonUnsubmitted Not Done Inline ActionsUse braces. campbellbarton: Use braces. | |||||
| immBindBuiltinProgram(GPU_SHADER_3D_POINT_FIXED_SIZE_VARYING_COLOR_OFFSET); | |||||
| /*borrowed from edit_mesh_mode.c*/ | |||||
fclemUnsubmitted Not Done Inline Actions/* Use this format for comments. */ With Capital on first char and fullstop at the end. fclem: `/* Use this format for comments. */` With Capital on first char and fullstop at the end. | |||||
| { | |||||
| RegionView3D *rv3d = CTX_wm_region_view3d(C); | |||||
| float winmat[4][4]; | |||||
| float viewdist = rv3d->dist; | |||||
| DRW_viewport_matrix_get(winmat, DRW_MAT_WIN); | |||||
fclemUnsubmitted Not Done Inline ActionsUse GPU_matrix API here. fclem: Use GPU_matrix API here. | |||||
| /* special exception for ortho camera (viewdist isnt used for perspective cameras) */ | |||||
| if (rv3d->persp == RV3D_CAMOB && rv3d->is_persp == false) { | |||||
| viewdist = 1.0f / max_ff(fabsf(rv3d->winmat[0][0]), fabsf(rv3d->winmat[1][1])); | |||||
| } | |||||
| const float depth_ofs = bglPolygonOffsetCalc((float *)winmat, viewdist, 1.0f); | |||||
| immUniform1f("ofs", depth_ofs); | |||||
fclemUnsubmitted Not Done Inline ActionsInstead of modifying the shader modify the projection matrix instead. Push it and restore after drawing. fclem: Instead of modifying the shader modify the projection matrix instead. Push it and restore after… | |||||
| } | |||||
| } | |||||
| else { | |||||
| if (depth_test_enabled) | |||||
| GPU_depth_test(false); | |||||
| GPU_matrix_push(); | |||||
| GPU_matrix_scale_2f(1.0f / t->aspect[0], 1.0f / t->aspect[1]); | |||||
| immBindBuiltinProgram(GPU_SHADER_3D_POINT_FIXED_SIZE_VARYING_COLOR); | |||||
| } | |||||
| GPU_point_size(vertex_size); | |||||
| FOREACH_TRANS_DATA_CONTAINER (t, tc) { | |||||
| if (is_view3d) { | |||||
| GPU_matrix_push(); | |||||
| if(t->flag & T_EDIT) | |||||
| GPU_matrix_mul(tc->mat); | |||||
| } | |||||
| immBeginAtMost(GPU_PRIM_POINTS, tc->data_len); | |||||
fclemUnsubmitted Not Done Inline ActionsReplace by immBeginBatchAtMost. Immediate mode can overflow and is slow. fclem: Replace by `immBeginBatchAtMost`. Immediate mode can overflow and is slow. | |||||
| for (int i = 0; i < tc->data_len; i++) { | |||||
| TransData td = tc->data[i]; | |||||
| if (td.factor == 0.0) { | |||||
| break; | |||||
| } | |||||
| float factor = td.factor * 2.0f; | |||||
| if (factor < 1.0) { | |||||
| interp_v3_v3v3(color, color_start, color_center, factor); | |||||
| } | |||||
| else { | |||||
| interp_v3_v3v3(color, color_center, color_end, factor - 1.0f); | |||||
| } | |||||
| immAttr4fv(col, color); | |||||
| immVertex3fv(pos, td.loc); | |||||
| } | |||||
| immEnd(); | |||||
| if (is_view3d) | |||||
fclemUnsubmitted Not Done Inline ActionsStyle : Always use brackets with conditional statements. fclem: Style : Always use brackets with conditional statements. | |||||
| GPU_matrix_pop(); | |||||
| } | |||||
| if (!is_view3d) | |||||
| GPU_matrix_pop(); | |||||
| immUnbindProgram(); | |||||
| if (!GPU_depth_test_enabled() && depth_test_enabled) | |||||
| GPU_depth_test(true); | |||||
| } | |||||
| } | |||||
| static void drawObjectConstraint(TransInfo *t) | static void drawObjectConstraint(TransInfo *t) | ||||
| { | { | ||||
| /* Draw the first one lighter because that's the one who controls the others. | /* Draw the first one lighter because that's the one who controls the others. | ||||
| Context not available. | |||||
Prefer early return, as is done above.
Could also use note on other spaces that might be supported, movie-clip for eg, did you try this?