GPencil: Move Object Depth Order to Object

There was a conflict between Object "In Front" and how the strokes were managed in Stroke panel for grease pencil datablock.

In order to keep consistency, the order of the object has been moved to Object level and now it's using the standard "In Front" flag. As all it is 3D, the option "Back" has been removed.

This also fixes the problem with task T62137.

Also related to commit 54ffc4e19d and D4405
This commit is contained in:
Antonio Vazquez 2019-03-04 17:05:44 +01:00
parent b27ada979c
commit f6bafef1e1
Notes: blender-bot 2023-02-14 09:21:21 +01:00
Referenced by issue #62137, Grease Pencil InFront display not working
12 changed files with 22 additions and 49 deletions

View File

@ -347,9 +347,9 @@ class DATA_PT_gpencil_strokes(DataButtonsPanel, Panel):
gpd = context.gpencil_data
layout.prop(gpd, "object_depth_order")
if gpd.object_depth_order == '3DSPACE':
layout.prop(gpd, "stroke_depth_order")
col = layout.column(align=True)
col.prop(gpd, "stroke_depth_order")
col.enabled = not ob.show_in_front
col = layout.column(align=True)
col.prop(gpd, "stroke_thickness_space")

View File

@ -411,7 +411,6 @@ bGPdata *BKE_gpencil_data_addnew(Main *bmain, const char name[])
/* GP object specific settings */
ARRAY_SET_ITEMS(gpd->line_color, 0.6f, 0.6f, 0.6f, 0.5f);
gpd->xray_mode = GP_XRAY_3DSPACE;
gpd->pixfactor = GP_DEFAULT_PIX_FACTOR;
/* grid settings */

View File

@ -416,7 +416,8 @@ static DRWShadingGroup *DRW_gpencil_shgroup_fill_create(
stl->shgroups[id].texture_flip = gp_style->flag & GP_STYLE_COLOR_FLIP_FILL ? 1 : 0;
DRW_shgroup_uniform_int(grp, "texture_flip", &stl->shgroups[id].texture_flip, 1);
DRW_shgroup_uniform_int(grp, "xraymode", (const int *) &gpd->xray_mode, 1);
stl->shgroups[id].xray_mode = (ob->dtx & OB_DRAWXRAY) ? GP_XRAY_FRONT : GP_XRAY_3DSPACE;
DRW_shgroup_uniform_int(grp, "xraymode", &stl->shgroups[id].xray_mode, 1);
DRW_shgroup_uniform_int(grp, "drawmode", (const int *) &gpd->draw_mode, 1);
/* viewport x-ray */
@ -570,7 +571,8 @@ DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(
}
if ((gpd) && (id > -1)) {
DRW_shgroup_uniform_int(grp, "xraymode", (const int *) &gpd->xray_mode, 1);
stl->shgroups[id].xray_mode = (ob->dtx & OB_DRAWXRAY) ? GP_XRAY_FRONT : GP_XRAY_3DSPACE;
DRW_shgroup_uniform_int(grp, "xraymode", &stl->shgroups[id].xray_mode, 1);
}
else {
/* for drawing always on predefined z-depth */
@ -689,7 +691,8 @@ static DRWShadingGroup *DRW_gpencil_shgroup_point_create(
}
if (gpd) {
DRW_shgroup_uniform_int(grp, "xraymode", (const int *)&gpd->xray_mode, 1);
stl->shgroups[id].xray_mode = (ob->dtx & OB_DRAWXRAY) ? GP_XRAY_FRONT : GP_XRAY_3DSPACE;
DRW_shgroup_uniform_int(grp, "xraymode", (const int *)&stl->shgroups[id].xray_mode, 1);
}
else {
/* for drawing always on on predefined z-depth */
@ -1495,7 +1498,7 @@ static void DRW_gpencil_shgroups_create(
GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
GPENCIL_PassList *psl = ((GPENCIL_Data *)vedata)->psl;
bGPdata *gpd = (bGPdata *)ob->data;
DRWPass *stroke_pass = GPENCIL_3D_DRAWMODE(gpd) ? psl->stroke_pass_3d : psl->stroke_pass_2d;
DRWPass *stroke_pass = GPENCIL_3D_DRAWMODE(ob, gpd) ? psl->stroke_pass_3d : psl->stroke_pass_2d;
GpencilBatchGroup *elm = NULL;
DRWShadingGroup *shgrp = NULL;

View File

@ -740,7 +740,7 @@ static void gpencil_free_obj_runtime(GPENCIL_StorageList *stl)
static void gpencil_draw_pass_range(
GPENCIL_FramebufferList *fbl, GPENCIL_StorageList *stl,
GPENCIL_PassList *psl, GPENCIL_TextureList *txl,
GPUFrameBuffer *fb, bGPdata *gpd,
GPUFrameBuffer *fb, Object *ob, bGPdata *gpd,
DRWShadingGroup *init_shgrp, DRWShadingGroup *end_shgrp, bool multi)
{
if (init_shgrp == NULL) {
@ -753,7 +753,7 @@ static void gpencil_draw_pass_range(
}
DRW_draw_pass_subset(
GPENCIL_3D_DRAWMODE(gpd) ? psl->stroke_pass_3d : psl->stroke_pass_2d,
GPENCIL_3D_DRAWMODE(ob, gpd) ? psl->stroke_pass_3d : psl->stroke_pass_2d,
init_shgrp, end_shgrp);
if ((!stl->storage->is_mat_preview) && (multi)) {
@ -780,6 +780,7 @@ static void drw_gpencil_select_render(GPENCIL_StorageList *stl, GPENCIL_PassList
for (int i = 0; i < stl->g_data->gp_cache_used; i++) {
cache_ob = &stl->g_data->gp_object_cache[i];
if (cache_ob) {
Object *ob = cache_ob->ob;
bGPdata *gpd = cache_ob->gpd;
init_shgrp = NULL;
if (cache_ob->tot_layers > 0) {
@ -792,7 +793,7 @@ static void drw_gpencil_select_render(GPENCIL_StorageList *stl, GPENCIL_PassList
}
/* draw group */
DRW_draw_pass_subset(
GPENCIL_3D_DRAWMODE(gpd) ? psl->stroke_pass_3d : psl->stroke_pass_2d,
GPENCIL_3D_DRAWMODE(ob, gpd) ? psl->stroke_pass_3d : psl->stroke_pass_2d,
init_shgrp, end_shgrp);
}
/* the cache must be dirty for next loop */
@ -911,7 +912,7 @@ void GPENCIL_draw_scene(void *ved)
/* draw pending groups */
gpencil_draw_pass_range(
fbl, stl, psl, txl, fbl->temp_fb_a,
gpd, init_shgrp, end_shgrp, is_last);
ob, gpd, init_shgrp, end_shgrp, is_last);
/* draw current group in separated texture */
init_shgrp = array_elm->init_shgrp;
@ -921,7 +922,7 @@ void GPENCIL_draw_scene(void *ved)
GPU_framebuffer_clear_color_depth(fbl->temp_fb_fx, clearcol, 1.0f);
gpencil_draw_pass_range(
fbl, stl, psl, txl, fbl->temp_fb_fx,
gpd, init_shgrp, end_shgrp,
ob, gpd, init_shgrp, end_shgrp,
is_last);
/* Blend A texture and FX texture */
@ -949,7 +950,7 @@ void GPENCIL_draw_scene(void *ved)
/* last group */
gpencil_draw_pass_range(
fbl, stl, psl, txl, fbl->temp_fb_a,
gpd, init_shgrp, end_shgrp,
ob, gpd, init_shgrp, end_shgrp,
true);
}

View File

@ -118,6 +118,7 @@ typedef struct GPENCIL_shgroup {
int keep_size;
int caps_mode[2];
float obj_scale;
int xray_mode;
/* color of the wireframe */
float wire_color[4];
@ -467,8 +468,8 @@ void GPENCIL_render_to_image(void *vedata, struct RenderEngine *engine, struct R
} \
}
#define GPENCIL_3D_DRAWMODE(gpd) \
((gpd) && (gpd->draw_mode == GP_DRAWMODE_3D) && (gpd->xray_mode == GP_XRAY_3DSPACE))
#define GPENCIL_3D_DRAWMODE(ob, gpd) \
((gpd) && (gpd->draw_mode == GP_DRAWMODE_3D) && (ob->dtx & OB_DRAWXRAY))
#define GPENCIL_USE_SOLID(stl) \
((stl) && ((stl->storage->is_render) || (stl->storage->is_mat_preview)))

View File

@ -35,7 +35,6 @@ uniform vec4 wire_color;
#define GP_XRAY_FRONT 0
#define GP_XRAY_3DSPACE 1
#define GP_XRAY_BACK 2
#define GP_DRAWMODE_2D 0
#define GP_DRAWMODE_3D 1
@ -163,9 +162,6 @@ void main()
gl_FragDepth = gl_FragCoord.z;
}
}
else if (xraymode == GP_XRAY_BACK) {
gl_FragDepth = 0.999999;
}
else {
gl_FragDepth = 0.000001;
}

View File

@ -14,7 +14,6 @@ out vec2 mTexCoord;
#define GP_XRAY_FRONT 0
#define GP_XRAY_3DSPACE 1
#define GP_XRAY_BACK 2
/* project 3d point to 2d on screen space */
vec2 toScreenSpace(vec4 vertex)
@ -31,9 +30,6 @@ float getZdepth(vec4 point)
if (xraymode == GP_XRAY_3DSPACE) {
return (point.z / point.w);
}
if (xraymode == GP_XRAY_BACK) {
return 0.999999;
}
/* in front by default */
return 0.000001;

View File

@ -17,7 +17,6 @@ out vec2 uvfac;
#define GP_XRAY_FRONT 0
#define GP_XRAY_3DSPACE 1
#define GP_XRAY_BACK 2
/* keep this list synchronized with list in gpencil_engine.h */
#define GPENCIL_COLOR_SOLID 0
@ -41,9 +40,6 @@ float getZdepth(vec4 point)
if (xraymode == GP_XRAY_3DSPACE) {
return (point.z / point.w);
}
if (xraymode == GP_XRAY_BACK) {
return 0.999999;
}
/* in front by default */
return 0.000001;

View File

@ -1188,9 +1188,6 @@ static bool gp_session_initdata(bContext *C, tGPsdata *p)
/* mark datablock as being used for annotations */
gpd->flag |= GP_DATA_ANNOTATIONS;
/* annotations always in front of all objects */
gpd->xray_mode = GP_XRAY_FRONT;
}
p->gpd = *gpd_ptr;
}

View File

@ -721,7 +721,7 @@ static void gp_draw_stroke_3d(tGPDdraw *tgpw, short thickness, const float ink[4
immUniform1i("keep_size", keep_size);
immUniform1i("pixfactor", tgpw->gpd->pixfactor);
/* xray mode always to 3D space to avoid wrong zdepth calculation (T60051) */
immUniform1i("xraymode", GP_XRAY_3DSPACE);
immUniform1i("xraymode", 1);
/* draw stroke curve */
GPU_line_width(max_ff(curpressure * thickness, 1.0f));

View File

@ -460,9 +460,7 @@ typedef struct bGPdata {
/** Settings for this datablock. */
int flag;
/** Xray mode for strokes (eGP_DepthOrdering). */
short xray_mode;
char _pad1[2];
char _pad1[4];
/* Palettes */
/** List of bGPDpalette's - Deprecated (2.78 - 2.79 only). */
@ -616,7 +614,6 @@ typedef enum eGP_OnionModes {
typedef enum eGP_DepthOrdering {
GP_XRAY_FRONT = 0,
GP_XRAY_3DSPACE = 1,
GP_XRAY_BACK = 2,
} eGP_DepthOrdering;
/* draw modes (Use 2D or 3D position) */

View File

@ -57,13 +57,6 @@ static EnumPropertyItem rna_enum_gpencil_stroke_depth_order_items[] = {
{0, NULL, 0, NULL, NULL},
};
static EnumPropertyItem rna_enum_gpencil_object_depth_order_items[] = {
{GP_XRAY_FRONT, "FRONT", 0, "Front", "Display all strokes in front"},
{GP_XRAY_3DSPACE, "3DSPACE", 0, "3D Space", "Display strokes relative to other objects in 3D space"},
{GP_XRAY_BACK, "BACK", 0, "Back", "Display all strokes last"},
{0, NULL, 0, NULL, NULL},
};
static EnumPropertyItem rna_enum_gpencil_onion_modes_items[] = {
{GP_ONION_MODE_ABSOLUTE, "ABSOLUTE", 0, "Frames", "Frames in absolute range of the scene frame"},
{GP_ONION_MODE_RELATIVE, "RELATIVE", 0, "Keyframes", "Frames in relative range of the Grease Pencil keyframes"},
@ -1510,12 +1503,6 @@ static void rna_def_gpencil_data(BlenderRNA *brna)
"Defines how the strokes are ordered in 3D space");
RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update");
prop = RNA_def_property(srna, "object_depth_order", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "xray_mode");
RNA_def_property_enum_items(prop, rna_enum_gpencil_object_depth_order_items);
RNA_def_property_ui_text(prop, "Object Depth Order", "");
RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update");
/* Flags */
prop = RNA_def_property(srna, "use_stroke_edit_mode", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_DATA_STROKE_EDITMODE);