Curve Batch Cache: Rework Implementation to use new batch request

Shaded triangles are not yet implemented (request from gpumaterials).

This also changes the mechanism to draw curve normals to make it not
dependant on normal size display. This way different viewport can
reuse the same batch.
This commit is contained in:
Clément Foucault 2018-12-13 01:26:07 +01:00
parent 77164e30c7
commit 2afed99da3
Notes: blender-bot 2023-02-14 06:25:25 +01:00
Referenced by issue #59410, Changing Handle Type on Bezier Curve Points breaks them
10 changed files with 528 additions and 629 deletions

View File

@ -281,6 +281,7 @@ data_to_c_simple(modes/shaders/edit_mesh_overlay_facefill_frag.glsl SRC)
data_to_c_simple(modes/shaders/edit_curve_overlay_handle_vert.glsl SRC)
data_to_c_simple(modes/shaders/edit_curve_overlay_handle_geom.glsl SRC)
data_to_c_simple(modes/shaders/edit_curve_overlay_loosevert_vert.glsl SRC)
data_to_c_simple(modes/shaders/edit_curve_overlay_normals_vert.glsl SRC)
data_to_c_simple(modes/shaders/edit_lattice_overlay_frag.glsl SRC)
data_to_c_simple(modes/shaders/edit_lattice_overlay_loosevert_vert.glsl SRC)
data_to_c_simple(modes/shaders/edit_normals_vert.glsl SRC)

View File

@ -3195,15 +3195,15 @@ GPUBatch *DRW_cache_curve_edge_wire_get(Object *ob)
BLI_assert(ob->type == OB_CURVE);
struct Curve *cu = ob->data;
return DRW_curve_batch_cache_get_wire_edge(cu, ob->runtime.curve_cache);
return DRW_curve_batch_cache_get_wire_edge(cu);
}
GPUBatch *DRW_cache_curve_edge_normal_get(Object *ob, float normal_size)
GPUBatch *DRW_cache_curve_edge_normal_get(Object *ob)
{
BLI_assert(ob->type == OB_CURVE);
struct Curve *cu = ob->data;
return DRW_curve_batch_cache_get_normal_edge(cu, ob->runtime.curve_cache, normal_size);
return DRW_curve_batch_cache_get_normal_edge(cu);
}
GPUBatch *DRW_cache_curve_edge_overlay_get(Object *ob)
@ -3227,7 +3227,7 @@ GPUBatch *DRW_cache_curve_surface_get(Object *ob)
BLI_assert(ob->type == OB_CURVE);
struct Curve *cu = ob->data;
return DRW_curve_batch_cache_get_triangles_with_normals(cu, ob->runtime.curve_cache);
return DRW_curve_batch_cache_get_triangles_with_normals(cu);
}
GPUBatch *DRW_cache_curve_face_wireframe_get(Object *ob)
@ -3235,7 +3235,7 @@ GPUBatch *DRW_cache_curve_face_wireframe_get(Object *ob)
BLI_assert(ob->type == OB_CURVE);
struct Curve *cu = ob->data;
return DRW_curve_batch_cache_get_wireframes_face(cu, ob->runtime.curve_cache);
return DRW_curve_batch_cache_get_wireframes_face(cu);
}
/* Return list of batches */
@ -3245,7 +3245,7 @@ GPUBatch **DRW_cache_curve_surface_shaded_get(
BLI_assert(ob->type == OB_CURVE);
struct Curve *cu = ob->data;
return DRW_curve_batch_cache_get_surface_shaded(cu, ob->runtime.curve_cache, gpumat_array, gpumat_array_len);
return DRW_curve_batch_cache_get_surface_shaded(cu, gpumat_array, gpumat_array_len);
}
/** \} */
@ -3287,7 +3287,7 @@ GPUBatch *DRW_cache_text_edge_wire_get(Object *ob)
BLI_assert(ob->type == OB_FONT);
struct Curve *cu = ob->data;
return DRW_curve_batch_cache_get_wire_edge(cu, ob->runtime.curve_cache);
return DRW_curve_batch_cache_get_wire_edge(cu);
}
GPUBatch *DRW_cache_text_surface_get(Object *ob)
@ -3297,7 +3297,7 @@ GPUBatch *DRW_cache_text_surface_get(Object *ob)
if (cu->editfont && (cu->flag & CU_FAST)) {
return NULL;
}
return DRW_curve_batch_cache_get_triangles_with_normals(cu, ob->runtime.curve_cache);
return DRW_curve_batch_cache_get_triangles_with_normals(cu);
}
GPUBatch *DRW_cache_text_face_wireframe_get(Object *ob)
@ -3307,7 +3307,7 @@ GPUBatch *DRW_cache_text_face_wireframe_get(Object *ob)
if (cu->editfont && (cu->flag & CU_FAST)) {
return NULL;
}
return DRW_curve_batch_cache_get_wireframes_face(cu, ob->runtime.curve_cache);
return DRW_curve_batch_cache_get_wireframes_face(cu);
}
GPUBatch **DRW_cache_text_surface_shaded_get(
@ -3318,21 +3318,7 @@ GPUBatch **DRW_cache_text_surface_shaded_get(
if (cu->editfont && (cu->flag & CU_FAST)) {
return NULL;
}
return DRW_curve_batch_cache_get_surface_shaded(cu, ob->runtime.curve_cache, gpumat_array, gpumat_array_len);
}
GPUBatch *DRW_cache_text_cursor_overlay_get(Object *ob)
{
BLI_assert(ob->type == OB_FONT);
struct Curve *cu = ob->data;
return DRW_curve_batch_cache_get_edit_cursor(cu);
}
GPUBatch *DRW_cache_text_select_overlay_get(Object *ob)
{
BLI_assert(ob->type == OB_FONT);
struct Curve *cu = ob->data;
return DRW_curve_batch_cache_get_edit_select(cu);
return DRW_curve_batch_cache_get_surface_shaded(cu, gpumat_array, gpumat_array_len);
}
/** \} */
@ -3347,7 +3333,7 @@ GPUBatch *DRW_cache_surf_surface_get(Object *ob)
BLI_assert(ob->type == OB_SURF);
struct Curve *cu = ob->data;
return DRW_curve_batch_cache_get_triangles_with_normals(cu, ob->runtime.curve_cache);
return DRW_curve_batch_cache_get_triangles_with_normals(cu);
}
GPUBatch *DRW_cache_surf_face_wireframe_get(Object *ob)
@ -3355,7 +3341,7 @@ GPUBatch *DRW_cache_surf_face_wireframe_get(Object *ob)
BLI_assert(ob->type == OB_SURF);
struct Curve *cu = ob->data;
return DRW_curve_batch_cache_get_wireframes_face(cu, ob->runtime.curve_cache);
return DRW_curve_batch_cache_get_wireframes_face(cu);
}
/* Return list of batches */
@ -3365,7 +3351,7 @@ GPUBatch **DRW_cache_surf_surface_shaded_get(
BLI_assert(ob->type == OB_SURF);
struct Curve *cu = ob->data;
return DRW_curve_batch_cache_get_surface_shaded(cu, ob->runtime.curve_cache, gpumat_array, gpumat_array_len);
return DRW_curve_batch_cache_get_surface_shaded(cu, gpumat_array, gpumat_array_len);
}
/** \} */
@ -3748,6 +3734,11 @@ void drw_batch_cache_generate_requested(Object *ob)
case OB_MESH:
DRW_mesh_batch_cache_create_requested(ob);
break;
case OB_CURVE:
case OB_FONT:
case OB_SURF:
DRW_curve_batch_cache_create_requested(ob);
break;
/* TODO all cases */
default:
break;

View File

@ -156,7 +156,7 @@ struct GPUBatch *DRW_cache_curve_surface_verts_get(struct Object *ob);
struct GPUBatch *DRW_cache_curve_edge_wire_get(struct Object *ob);
struct GPUBatch *DRW_cache_curve_face_wireframe_get(Object *ob);
/* edit-mode */
struct GPUBatch *DRW_cache_curve_edge_normal_get(struct Object *ob, float normal_size);
struct GPUBatch *DRW_cache_curve_edge_normal_get(struct Object *ob);
struct GPUBatch *DRW_cache_curve_edge_overlay_get(struct Object *ob);
struct GPUBatch *DRW_cache_curve_vert_overlay_get(struct Object *ob, bool handles);

View File

@ -64,36 +64,31 @@ void DRW_gpencil_batch_cache_dirty_tag(struct bGPdata *gpd);
void DRW_gpencil_batch_cache_free(struct bGPdata *gpd);
/* Curve */
struct GPUBatch *DRW_curve_batch_cache_get_wire_edge(struct Curve *cu, struct CurveCache *ob_curve_cache);
struct GPUBatch *DRW_curve_batch_cache_get_normal_edge(
struct Curve *cu, struct CurveCache *ob_curve_cache, float normal_size);
void DRW_curve_batch_cache_create_requested(struct Object *ob);
struct GPUBatch *DRW_curve_batch_cache_get_wire_edge(struct Curve *cu);
struct GPUBatch *DRW_curve_batch_cache_get_normal_edge(struct Curve *cu);
struct GPUBatch *DRW_curve_batch_cache_get_edit_edges(struct Curve *cu);
struct GPUBatch *DRW_curve_batch_cache_get_edit_verts(struct Curve *cu, bool handles);
struct GPUBatch *DRW_curve_batch_cache_get_triangles_with_normals(
struct Curve *cu, struct CurveCache *ob_curve_cache);
struct GPUBatch *DRW_curve_batch_cache_get_triangles_with_normals(struct Curve *cu);
struct GPUBatch **DRW_curve_batch_cache_get_surface_shaded(
struct Curve *cu, struct CurveCache *ob_curve_cache,
struct GPUMaterial **gpumat_array, uint gpumat_array_len);
struct GPUBatch *DRW_curve_batch_cache_get_wireframes_face(struct Curve *cu, struct CurveCache *ob_curve_cache);
struct Curve *cu, struct GPUMaterial **gpumat_array, uint gpumat_array_len);
struct GPUBatch *DRW_curve_batch_cache_get_wireframes_face(struct Curve *cu);
/* Metaball */
struct GPUBatch *DRW_metaball_batch_cache_get_triangles_with_normals(struct Object *ob);
struct GPUBatch **DRW_metaball_batch_cache_get_surface_shaded(struct Object *ob, struct MetaBall *mb, struct GPUMaterial **gpumat_array, uint gpumat_array_len);
struct GPUBatch *DRW_metaball_batch_cache_get_wireframes_face(struct Object *ob);
/* Curve (Font) */
struct GPUBatch *DRW_curve_batch_cache_get_edit_cursor(struct Curve *cu);
struct GPUBatch *DRW_curve_batch_cache_get_edit_select(struct Curve *cu);
/* DispList */
struct GPUVertBuf *DRW_displist_vertbuf_calc_pos_with_normals(struct ListBase *lb);
struct GPUIndexBuf *DRW_displist_indexbuf_calc_triangles_in_order(struct ListBase *lb);
struct GPUVertBuf *DRW_displist_vertbuf_calc_pos_with_normals(struct ListBase *lb, struct GPUVertBuf *vbo);
struct GPUIndexBuf *DRW_displist_indexbuf_calc_triangles_in_order(struct ListBase *lb, struct GPUIndexBuf *vbo);
struct GPUIndexBuf **DRW_displist_indexbuf_calc_triangles_in_order_split_by_material(
struct ListBase *lb, uint gpumat_array_len);
struct GPUBatch **DRW_displist_batch_calc_tri_pos_normals_and_uv_split_by_material(
struct ListBase *lb, uint gpumat_array_len);
struct GPUBatch *DRW_displist_create_edges_overlay_batch(ListBase *lb);
struct GPUBatch *DRW_displist_create_edges_overlay_batch(ListBase *lb, struct GPUVertBuf *vbo);
/* Lattice */
struct GPUBatch *DRW_lattice_batch_cache_get_all_edges(struct Lattice *lt, bool use_weight, const int actdef);
@ -219,6 +214,10 @@ struct GPUBatch *DRW_particles_batch_cache_get_edit_tip_points(
#define DRW_ADD_FLAG_FROM_VBO_REQUEST(flag, vbo, value) (flag |= DRW_vbo_requested(vbo) ? value : 0)
#define DRW_ADD_FLAG_FROM_IBO_REQUEST(flag, ibo, value) (flag |= DRW_ibo_requested(ibo) ? value : 0)
/* Test and assign NULL if test fails */
#define DRW_TEST_ASSIGN_VBO(v) (v = (DRW_vbo_requested(v) ? v : NULL))
#define DRW_TEST_ASSIGN_IBO(v) (v = (DRW_ibo_requested(v) ? v : NULL))
struct GPUBatch *DRW_batch_request(struct GPUBatch **batch);
bool DRW_batch_requested(struct GPUBatch *batch, int prim_type);
void DRW_ibo_request(struct GPUBatch *batch, struct GPUIndexBuf **ibo);

File diff suppressed because it is too large Load Diff

View File

@ -125,7 +125,7 @@ static void displist_indexbufbuilder_set(
}
}
GPUVertBuf *DRW_displist_vertbuf_calc_pos_with_normals(ListBase *lb)
GPUVertBuf *DRW_displist_vertbuf_calc_pos_with_normals(ListBase *lb, GPUVertBuf *vbo)
{
static GPUVertFormat format = { 0 };
static struct { uint pos, nor; } attr_id;
@ -135,7 +135,12 @@ GPUVertBuf *DRW_displist_vertbuf_calc_pos_with_normals(ListBase *lb)
attr_id.nor = GPU_vertformat_attr_add(&format, "nor", GPU_COMP_I16, 4, GPU_FETCH_INT_TO_FLOAT_UNIT);
}
GPUVertBuf *vbo = GPU_vertbuf_create_with_format(&format);
if (vbo == NULL) {
vbo = GPU_vertbuf_create_with_format(&format);
}
else {
GPU_vertbuf_init_with_format(vbo, &format);
}
GPU_vertbuf_data_alloc(vbo, curve_render_surface_vert_len_get(lb));
BKE_displist_normals_add(lb);
@ -166,7 +171,7 @@ GPUVertBuf *DRW_displist_vertbuf_calc_pos_with_normals(ListBase *lb)
return vbo;
}
GPUIndexBuf *DRW_displist_indexbuf_calc_triangles_in_order(ListBase *lb)
GPUIndexBuf *DRW_displist_indexbuf_calc_triangles_in_order(ListBase *lb, GPUIndexBuf *ibo)
{
const int tri_len = curve_render_surface_tri_len_get(lb);
const int vert_len = curve_render_surface_vert_len_get(lb);
@ -182,7 +187,13 @@ GPUIndexBuf *DRW_displist_indexbuf_calc_triangles_in_order(ListBase *lb)
ofs += dl_vert_len(dl);
}
return GPU_indexbuf_build(&elb);
if (ibo != NULL) {
GPU_indexbuf_build_in_place(&elb, ibo);
}
else {
ibo = GPU_indexbuf_build(&elb);
}
return ibo;
}
GPUIndexBuf **DRW_displist_indexbuf_calc_triangles_in_order_split_by_material(ListBase *lb, uint gpumat_array_len)
@ -267,7 +278,7 @@ static void set_overlay_wires_quad_tri_indices(void *thunk, uint v1, uint v2, ui
}
}
GPUBatch *DRW_displist_create_edges_overlay_batch(ListBase *lb)
GPUBatch *DRW_displist_create_edges_overlay_batch(ListBase *lb, GPUVertBuf *vbo)
{
static DRWDisplistWireThunk thunk;
static GPUVertFormat format = {0};
@ -278,7 +289,13 @@ GPUBatch *DRW_displist_create_edges_overlay_batch(ListBase *lb)
GPU_vertformat_triple_load(&format);
}
thunk.vbo = GPU_vertbuf_create_with_format(&format);
if (vbo == NULL) {
thunk.vbo = GPU_vertbuf_create_with_format(&format);
}
else {
GPU_vertbuf_init_with_format(vbo, &format);
thunk.vbo = vbo;
}
int vert_len = curve_render_surface_tri_len_get(lb) * 3;
GPU_vertbuf_data_alloc(thunk.vbo, vert_len);
@ -300,7 +317,12 @@ GPUBatch *DRW_displist_create_edges_overlay_batch(ListBase *lb)
GPU_vertbuf_data_resize(thunk.vbo, thunk.vidx);
}
return GPU_batch_create_ex(GPU_PRIM_TRIS, thunk.vbo, NULL, GPU_BATCH_OWNS_VBO);
if (vbo == NULL) {
return GPU_batch_create_ex(GPU_PRIM_TRIS, thunk.vbo, NULL, GPU_BATCH_OWNS_VBO);
}
else {
return NULL;
}
}

View File

@ -2070,7 +2070,7 @@ typedef struct MeshBatchCache {
struct {
/* Contains indices to unique edit vertices to not
* draw the same vert multiple times (because of tesselation). */
GPUIndexBuf *edit_verts;
GPUIndexBuf *edit_verts_points;
} ibo;
struct {
@ -3747,10 +3747,6 @@ static GPUVertFormat *edit_mesh_facedot_format(uint *r_pos_id, uint *r_nor_flag_
return &format_facedots;
}
/* Test and assign NULL if test fails */
#define TEST_ASSIGN_VBO(v) (v = (DRW_vbo_requested(v) ? v : NULL))
#define TEST_ASSIGN_IBO(v) (v = (DRW_ibo_requested(v) ? v : NULL))
static void mesh_create_edit_tris_and_verts(
MeshRenderData *rdata,
GPUVertBuf *vbo_data, GPUVertBuf *vbo_pos_nor, GPUVertBuf *vbo_lnor, GPUIndexBuf *ibo_verts)
@ -3768,23 +3764,23 @@ static void mesh_create_edit_tris_and_verts(
GPUVertFormat *lnor_format = edit_mesh_lnor_format(&attr_id.lnor);
/* Positions & Vert Normals */
if (TEST_ASSIGN_VBO(vbo_pos_nor)) {
if (DRW_TEST_ASSIGN_VBO(vbo_pos_nor)) {
GPU_vertbuf_init_with_format(vbo_pos_nor, pos_nor_format);
GPU_vertbuf_data_alloc(vbo_pos_nor, verts_tri_len);
}
/* Overlay data */
if (TEST_ASSIGN_VBO(vbo_data)) {
if (DRW_TEST_ASSIGN_VBO(vbo_data)) {
GPU_vertbuf_init_with_format(vbo_data, data_format);
GPU_vertbuf_data_alloc(vbo_data, verts_tri_len);
}
/* Loop Normals */
if (TEST_ASSIGN_VBO(vbo_lnor)) {
if (DRW_TEST_ASSIGN_VBO(vbo_lnor)) {
GPU_vertbuf_init_with_format(vbo_lnor, lnor_format);
GPU_vertbuf_data_alloc(vbo_lnor, verts_tri_len);
}
/* Verts IBO */
GPUIndexBufBuilder elb, *elbp = NULL;
if (TEST_ASSIGN_IBO(ibo_verts)) {
if (DRW_TEST_ASSIGN_IBO(ibo_verts)) {
elbp = &elb;
GPU_indexbuf_init(elbp, GPU_PRIM_POINTS, points_len, verts_tri_len);
/* Clear tag */
@ -3861,12 +3857,12 @@ static void mesh_create_edit_loose_edges(
GPUVertFormat *data_format = edit_mesh_data_format(&attr_id.data);
/* Positions & Vert Normals */
if (TEST_ASSIGN_VBO(vbo_pos_nor_ledges)) {
if (DRW_TEST_ASSIGN_VBO(vbo_pos_nor_ledges)) {
GPU_vertbuf_init_with_format(vbo_pos_nor_ledges, pos_nor_format);
GPU_vertbuf_data_alloc(vbo_pos_nor_ledges, verts_ledges_len);
}
/* Overlay data */
if (TEST_ASSIGN_VBO(vbo_data_ledges)) {
if (DRW_TEST_ASSIGN_VBO(vbo_data_ledges)) {
GPU_vertbuf_init_with_format(vbo_data_ledges, data_format);
GPU_vertbuf_data_alloc(vbo_data_ledges, verts_ledges_len);
}
@ -3913,12 +3909,12 @@ static void mesh_create_edit_loose_verts(
GPUVertFormat *data_format = edit_mesh_data_format(&attr_id.data);
/* Positions & Vert Normals */
if (TEST_ASSIGN_VBO(vbo_pos_nor_lverts)) {
if (DRW_TEST_ASSIGN_VBO(vbo_pos_nor_lverts)) {
GPU_vertbuf_init_with_format(vbo_pos_nor_lverts, pos_nor_format);
GPU_vertbuf_data_alloc(vbo_pos_nor_lverts, verts_lverts_len);
}
/* Overlay data */
if (TEST_ASSIGN_VBO(vbo_data_lverts)) {
if (DRW_TEST_ASSIGN_VBO(vbo_data_lverts)) {
GPU_vertbuf_init_with_format(vbo_data_lverts, data_format);
GPU_vertbuf_data_alloc(vbo_data_lverts, verts_lverts_len);
}
@ -3961,7 +3957,7 @@ static void mesh_create_edit_facedots(
struct { uint fdot_pos, fdot_nor_flag; } attr_id;
GPUVertFormat *facedot_format = edit_mesh_facedot_format(&attr_id.fdot_pos, &attr_id.fdot_nor_flag);
if (TEST_ASSIGN_VBO(vbo_pos_nor_data_facedots)) {
if (DRW_TEST_ASSIGN_VBO(vbo_pos_nor_data_facedots)) {
GPU_vertbuf_init_with_format(vbo_pos_nor_data_facedots, facedot_format);
GPU_vertbuf_data_alloc(vbo_pos_nor_data_facedots, verts_facedot_len);
/* TODO(fclem): Maybe move data generation to mesh_render_data_create() */
@ -5788,7 +5784,7 @@ void DRW_mesh_batch_cache_create_requested(Object *ob)
DRW_vbo_request(cache->batch.edit_triangles, &cache->edit.data);
}
if (DRW_batch_requested(cache->batch.edit_vertices, GPU_PRIM_POINTS)) {
DRW_ibo_request(cache->batch.edit_vertices, &cache->ibo.edit_verts);
DRW_ibo_request(cache->batch.edit_vertices, &cache->ibo.edit_verts_points);
DRW_vbo_request(cache->batch.edit_vertices, &cache->edit.pos_nor);
DRW_vbo_request(cache->batch.edit_vertices, &cache->edit.data);
}
@ -5801,7 +5797,7 @@ void DRW_mesh_batch_cache_create_requested(Object *ob)
DRW_vbo_request(cache->batch.edit_loose_verts, &cache->edit.data_lverts);
}
if (DRW_batch_requested(cache->batch.edit_triangles_nor, GPU_PRIM_POINTS)) {
DRW_ibo_request(cache->batch.edit_triangles_nor, &cache->ibo.edit_verts);
DRW_ibo_request(cache->batch.edit_triangles_nor, &cache->ibo.edit_verts_points);
DRW_vbo_request(cache->batch.edit_triangles_nor, &cache->edit.pos_nor);
}
if (DRW_batch_requested(cache->batch.edit_triangles_lnor, GPU_PRIM_POINTS)) {
@ -5829,7 +5825,7 @@ void DRW_mesh_batch_cache_create_requested(Object *ob)
DRW_ADD_FLAG_FROM_VBO_REQUEST(mr_edit_flag, cache->edit.pos_nor_lverts, MR_DATATYPE_VERT | MR_DATATYPE_LOOSE_VERT | MR_DATATYPE_OVERLAY);
DRW_ADD_FLAG_FROM_VBO_REQUEST(mr_edit_flag, cache->edit.pos_nor_data_facedots, MR_DATATYPE_VERT | MR_DATATYPE_LOOP | MR_DATATYPE_POLY | MR_DATATYPE_OVERLAY);
DRW_ADD_FLAG_FROM_VBO_REQUEST(mr_edit_flag, cache->edit.lnor, MR_DATATYPE_VERT | MR_DATATYPE_LOOP | MR_DATATYPE_LOOPTRI | MR_DATATYPE_OVERLAY);
DRW_ADD_FLAG_FROM_IBO_REQUEST(mr_edit_flag, cache->ibo.edit_verts, MR_DATATYPE_VERT | MR_DATATYPE_POLY | MR_DATATYPE_LOOPTRI);
DRW_ADD_FLAG_FROM_IBO_REQUEST(mr_edit_flag, cache->ibo.edit_verts_points, MR_DATATYPE_VERT | MR_DATATYPE_POLY | MR_DATATYPE_LOOPTRI);
Mesh *me_original = me;
MBC_GET_FINAL_MESH(me);
@ -5864,10 +5860,10 @@ void DRW_mesh_batch_cache_create_requested(Object *ob)
if (DRW_vbo_requested(cache->edit.data) ||
DRW_vbo_requested(cache->edit.pos_nor) ||
DRW_vbo_requested(cache->edit.lnor) ||
DRW_ibo_requested(cache->ibo.edit_verts))
DRW_ibo_requested(cache->ibo.edit_verts_points))
{
mesh_create_edit_tris_and_verts(rdata, cache->edit.data, cache->edit.pos_nor,
cache->edit.lnor, cache->ibo.edit_verts);
cache->edit.lnor, cache->ibo.edit_verts_points);
}
if (DRW_vbo_requested(cache->edit.data_ledges) || DRW_vbo_requested(cache->edit.pos_nor_ledges)) {
mesh_create_edit_loose_edges(rdata, cache->edit.data_ledges, cache->edit.pos_nor_ledges);

View File

@ -143,7 +143,7 @@ static GPUVertBuf *mball_batch_cache_get_pos_and_normals(Object *ob, MetaBallBat
{
if (cache->pos_nor_in_order == NULL) {
ListBase *lb = &ob->runtime.curve_cache->disp;
cache->pos_nor_in_order = DRW_displist_vertbuf_calc_pos_with_normals(lb);
cache->pos_nor_in_order = DRW_displist_vertbuf_calc_pos_with_normals(lb, NULL);
}
return cache->pos_nor_in_order;
}
@ -167,7 +167,7 @@ GPUBatch *DRW_metaball_batch_cache_get_triangles_with_normals(Object *ob)
cache->batch = GPU_batch_create_ex(
GPU_PRIM_TRIS,
mball_batch_cache_get_pos_and_normals(ob, cache),
DRW_displist_indexbuf_calc_triangles_in_order(lb),
DRW_displist_indexbuf_calc_triangles_in_order(lb, NULL),
GPU_BATCH_OWNS_INDEX);
}
@ -204,7 +204,7 @@ GPUBatch *DRW_metaball_batch_cache_get_wireframes_face(Object *ob)
if (cache->face_wire.batch == NULL) {
ListBase *lb = &ob->runtime.curve_cache->disp;
cache->face_wire.batch = DRW_displist_create_edges_overlay_batch(lb);
cache->face_wire.batch = DRW_displist_create_edges_overlay_batch(lb, NULL);
}
return cache->face_wire.batch;

View File

@ -47,11 +47,13 @@ extern struct GlobalsUboStorage ts; /* draw_common.c */
extern char datatoc_common_globals_lib_glsl[];
extern char datatoc_edit_curve_overlay_loosevert_vert_glsl[];
extern char datatoc_edit_curve_overlay_normals_vert_glsl[];
extern char datatoc_edit_curve_overlay_handle_vert_glsl[];
extern char datatoc_edit_curve_overlay_handle_geom_glsl[];
extern char datatoc_gpu_shader_point_varying_color_frag_glsl[];
extern char datatoc_gpu_shader_3D_smooth_color_frag_glsl[];
extern char datatoc_gpu_shader_uniform_color_frag_glsl[];
/* *********** LISTS *********** */
/* All lists are per viewport specific datas.
@ -83,6 +85,7 @@ typedef struct EDIT_CURVE_Data {
static struct {
GPUShader *wire_sh;
GPUShader *wire_normals_sh;
GPUShader *overlay_edge_sh; /* handles and nurbs control cage */
GPUShader *overlay_vert_sh;
} e_data = {NULL}; /* Engine data */
@ -90,6 +93,7 @@ static struct {
typedef struct EDIT_CURVE_PrivateData {
/* resulting curve as 'wire' for curves (and optionally normals) */
DRWShadingGroup *wire_shgrp;
DRWShadingGroup *wire_normals_shgrp;
DRWShadingGroup *overlay_edge_shgrp;
DRWShadingGroup *overlay_vert_shgrp;
@ -108,6 +112,12 @@ static void EDIT_CURVE_engine_init(void *UNUSED(vedata))
e_data.wire_sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR);
}
if (!e_data.wire_normals_sh) {
e_data.wire_normals_sh = DRW_shader_create(
datatoc_edit_curve_overlay_normals_vert_glsl, NULL,
datatoc_gpu_shader_uniform_color_frag_glsl, NULL);
}
if (!e_data.overlay_edge_sh) {
e_data.overlay_edge_sh = DRW_shader_create_with_lib(
datatoc_edit_curve_overlay_handle_vert_glsl,
@ -152,6 +162,12 @@ static void EDIT_CURVE_cache_init(void *vedata)
DRW_shgroup_uniform_vec4(grp, "color", ts.colorWireEdit, 1);
stl->g_data->wire_shgrp = grp;
grp = DRW_shgroup_create(e_data.wire_normals_sh, psl->wire_pass);
DRW_shgroup_uniform_vec4(grp, "color", ts.colorWireEdit, 1);
DRW_shgroup_uniform_float_copy(grp, "normalSize", v3d->overlay.normals_length);
stl->g_data->wire_normals_shgrp = grp;
psl->overlay_edge_pass = DRW_pass_create(
"Curve Handle Overlay",
DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND);
@ -190,8 +206,9 @@ static void EDIT_CURVE_cache_populate(void *vedata, Object *ob)
DRW_shgroup_call_add(stl->g_data->wire_shgrp, geom, ob->obmat);
if ((cu->flag & CU_3D) && (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_CU_NORMALS) != 0) {
geom = DRW_cache_curve_edge_normal_get(ob, v3d->overlay.normals_length);
DRW_shgroup_call_add(stl->g_data->wire_shgrp, geom, ob->obmat);
static uint instance_len = 2;
geom = DRW_cache_curve_edge_normal_get(ob);
DRW_shgroup_call_instances_add(stl->g_data->wire_normals_shgrp, geom, ob->obmat, &instance_len);
}
geom = DRW_cache_curve_edge_overlay_get(ob);
@ -242,6 +259,7 @@ static void EDIT_CURVE_draw_scene(void *vedata)
* Mostly used for freeing shaders */
static void EDIT_CURVE_engine_free(void)
{
DRW_SHADER_FREE_SAFE(e_data.wire_normals_sh);
DRW_SHADER_FREE_SAFE(e_data.overlay_edge_sh);
DRW_SHADER_FREE_SAFE(e_data.overlay_vert_sh);
}

View File

@ -0,0 +1,23 @@
/* Draw Curve Normals */
uniform mat4 ModelViewProjectionMatrix;
uniform float normalSize;
in vec3 pos;
in vec3 nor;
in vec3 tan;
in float rad;
void main()
{
vec3 final_pos = pos;
float flip = (gl_InstanceID != 0) ? -1.0 : 1.0;
if (gl_VertexID % 2 == 0) {
final_pos += normalSize * rad * (flip * nor - tan);
}
gl_Position = ModelViewProjectionMatrix * vec4(final_pos, 1.0);
}