[Bf-blender-cvs] [4c0bcc3d136] temp_bmesh_multires: PBVH drawing now properly names attributes.
Joseph Eagar
noreply at git.blender.org
Mon Oct 26 08:20:09 CET 2020
Commit: 4c0bcc3d1364204406323e42e37c54ae61c2b0af
Author: Joseph Eagar
Date: Mon Oct 26 00:19:14 2020 -0700
Branches: temp_bmesh_multires
https://developer.blender.org/rB4c0bcc3d1364204406323e42e37c54ae61c2b0af
PBVH drawing now properly names attributes.
NOTE: I've added a new function, DRW_make_cdlayer_attr_aliases, for
this. It's patterned after extract_uvs. The appropriate devs from the
draw engine team should take a look.
===================================================================
M source/blender/blenkernel/intern/pbvh.c
M source/blender/draw/DRW_engine.h
M source/blender/draw/intern/draw_cache.c
M source/blender/gpu/GPU_buffers.h
M source/blender/gpu/GPU_vertex_format.h
M source/blender/gpu/intern/gpu_buffers.c
===================================================================
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index b643564f6b4..31f945262bd 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -1296,6 +1296,7 @@ static void pbvh_update_draw_buffer_cb(void *__restrict userdata,
}
if (node->flag & PBVH_UpdateDrawBuffers) {
+
const int update_flags = pbvh_get_buffers_update_flags(pbvh);
switch (pbvh->type) {
case PBVH_GRIDS:
@@ -1357,6 +1358,19 @@ static void pbvh_update_draw_buffers(PBVH *pbvh, PBVHNode **nodes, int totnode,
}
}
+ CustomData *vdata;
+ CustomData *ldata;
+
+ if (pbvh->type == PBVH_BMESH) {
+ vdata = &pbvh->bm->vdata;
+ ldata = &pbvh->bm->ldata;
+ } else {
+ vdata = &pbvh->vdata;
+ ldata = &pbvh->ldata;
+ }
+
+ GPU_pbvh_update_attribute_names(vdata, ldata);
+
/* Parallel creation and update of draw buffers. */
PBVHUpdateData data = {
.pbvh = pbvh,
diff --git a/source/blender/draw/DRW_engine.h b/source/blender/draw/DRW_engine.h
index ca5c2c94b40..e9c783ccae5 100644
--- a/source/blender/draw/DRW_engine.h
+++ b/source/blender/draw/DRW_engine.h
@@ -39,6 +39,9 @@ struct DrawEngineType;
struct GPUMaterial;
struct GPUOffScreen;
struct GPUViewport;
+struct GPUVertFormat;
+struct CustomData;
+struct CustomDataLayer;
struct ID;
struct Main;
struct Object;
@@ -79,6 +82,10 @@ typedef bool (*DRW_ObjectFilterFn)(struct Object *ob, void *user_data);
void DRW_draw_view(const struct bContext *C);
void DRW_draw_region_engine_info(int xoffset, int *yoffset, int line_height);
+void DRW_make_cdlayer_attr_aliases(struct GPUVertFormat *format,
+ char *base_name,
+ struct CustomData *data,
+ struct CustomDataLayer *cl);
void DRW_draw_render_loop_ex(struct Depsgraph *depsgraph,
struct RenderEngineType *engine_type,
diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c
index 52e7e91a995..b8d06d9eb62 100644
--- a/source/blender/draw/intern/draw_cache.c
+++ b/source/blender/draw/intern/draw_cache.c
@@ -37,6 +37,7 @@
#include "BKE_object.h"
#include "BKE_paint.h"
+#include "BKE_customdata.h"
#include "GPU_batch.h"
#include "GPU_batch_utils.h"
@@ -473,6 +474,40 @@ static void sphere_lat_lon_vert(GPUVertBuf *vbo, int *v_ofs, float lat, float lo
(*v_ofs)++;
}
+void DRW_make_cdlayer_attr_aliases(GPUVertFormat *format, char *base_name, CustomData *data, CustomDataLayer *cl)
+{
+ char attr_name[32], attr_safe_name[GPU_MAX_SAFE_ATTR_NAME];
+ const char *layer_name = cl->name;
+
+ int i = (int) (cl - data->typemap[cl->type]);
+
+ GPU_vertformat_safe_attr_name(layer_name, attr_safe_name, GPU_MAX_SAFE_ATTR_NAME);
+
+ /* UV layer name. */
+ BLI_snprintf(attr_name, sizeof(attr_name), "%s%s", base_name, attr_safe_name);
+ GPU_vertformat_alias_add(format, attr_name);
+
+ /* Auto layer name. */
+ BLI_snprintf(attr_name, sizeof(attr_name), "a%s", attr_safe_name);
+ GPU_vertformat_alias_add(format, attr_name);
+
+ /* Active render layer name. */
+ if (i == CustomData_get_render_layer(data, cl->type)) {
+ GPU_vertformat_alias_add(format, base_name);
+ }
+ /* Active display layer name. */
+ if (i == CustomData_get_active_layer(data, cl->type)) {
+ BLI_snprintf(attr_name, sizeof(attr_name), "a%s", base_name);
+ GPU_vertformat_alias_add(format, attr_name);
+ }
+
+ /* Stencil mask uv layer name. */
+ if (i == CustomData_get_stencil_layer(data, cl->type)) {
+ BLI_snprintf(attr_name, sizeof(attr_name), "m%s", base_name);
+ GPU_vertformat_alias_add(format, attr_name);
+ }
+}
+
GPUBatch *DRW_cache_sphere_get(void)
{
if (!SHC.drw_sphere) {
diff --git a/source/blender/gpu/GPU_buffers.h b/source/blender/gpu/GPU_buffers.h
index 0610a7ca991..c2fee960353 100644
--- a/source/blender/gpu/GPU_buffers.h
+++ b/source/blender/gpu/GPU_buffers.h
@@ -44,8 +44,9 @@ struct MVert;
struct Mesh;
struct PBVH;
struct SubdivCCG;
+struct CustomData;
-/* Buffers for drawing from PBVH grids. */
+ /* Buffers for drawing from PBVH grids. */
typedef struct GPU_PBVH_Buffers GPU_PBVH_Buffers;
/* Build must be called once before using the other functions, used every time
@@ -86,6 +87,7 @@ void GPU_pbvh_mesh_buffers_update(GPU_PBVH_Buffers *buffers,
const struct MPropCol *vtcol,
const int update_flags);
+void GPU_pbvh_update_attribute_names(struct CustomData *vdata, struct CustomData *ldata);
void GPU_pbvh_bmesh_buffers_update(GPU_PBVH_Buffers *buffers,
struct BMesh *bm,
struct TableGSet *bm_faces,
diff --git a/source/blender/gpu/GPU_vertex_format.h b/source/blender/gpu/GPU_vertex_format.h
index 59af912ed3d..3bd4f985832 100644
--- a/source/blender/gpu/GPU_vertex_format.h
+++ b/source/blender/gpu/GPU_vertex_format.h
@@ -111,6 +111,8 @@ void GPU_vertformat_from_shader(GPUVertFormat *format, const struct GPUShader *s
uint GPU_vertformat_attr_add(
GPUVertFormat *, const char *name, GPUVertCompType, uint comp_len, GPUVertFetchMode);
void GPU_vertformat_alias_add(GPUVertFormat *, const char *alias);
+void GPU_vertformat_alias_clear(GPUVertFormat *format, int attr_id);
+void GPU_vertformat_alias_add_n(GPUVertFormat *format, int attr_id, const char *alias);
void GPU_vertformat_multiload_enable(GPUVertFormat *format, int load_count);
diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c
index 9588656338f..1fa1acbe88b 100644
--- a/source/blender/gpu/intern/gpu_buffers.c
+++ b/source/blender/gpu/intern/gpu_buffers.c
@@ -51,6 +51,8 @@
#include "GPU_batch.h"
#include "GPU_buffers.h"
+#include "DRW_engine.h"
+
#include "gpu_private.h"
#include "bmesh.h"
@@ -112,26 +114,7 @@ static struct {
void gpu_pbvh_init()
{
- /* Initialize vertex buffer (match 'VertexBufferFormat'). */
- if (g_vbo_id.format.attr_len == 0) {
- g_vbo_id.pos = GPU_vertformat_attr_add(
- &g_vbo_id.format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
- g_vbo_id.nor = GPU_vertformat_attr_add(
- &g_vbo_id.format, "nor", GPU_COMP_I16, 3, GPU_FETCH_INT_TO_FLOAT_UNIT);
- /* TODO: Do not allocate these `.msk` and `.col` when they are not used. */
- g_vbo_id.msk = GPU_vertformat_attr_add(
- &g_vbo_id.format, "msk", GPU_COMP_U8, 1, GPU_FETCH_INT_TO_FLOAT_UNIT);
- g_vbo_id.col = GPU_vertformat_attr_add(
- &g_vbo_id.format, "c", GPU_COMP_U16, 4, GPU_FETCH_INT_TO_FLOAT_UNIT);
- g_vbo_id.fset = GPU_vertformat_attr_add(
- &g_vbo_id.format, "fset", GPU_COMP_U8, 3, GPU_FETCH_INT_TO_FLOAT_UNIT);
-
- g_vbo_id.uv = GPU_vertformat_attr_add(
- &g_vbo_id.format, "uvs", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
- GPU_vertformat_alias_add(&g_vbo_id.format, "texCoord");
- GPU_vertformat_alias_add(&g_vbo_id.format, "u");
- GPU_vertformat_alias_add(&g_vbo_id.format, "au");
- }
+ GPU_pbvh_update_attribute_names(NULL, NULL);
}
void gpu_pbvh_exit()
@@ -927,6 +910,48 @@ void GPU_pbvh_bmesh_buffers_update_free(GPU_PBVH_Buffers *buffers)
}
}
+void GPU_pbvh_update_attribute_names(CustomData *vdata, CustomData *ldata)
+{
+ GPU_vertformat_clear(&g_vbo_id);
+
+ /* Initialize vertex buffer (match 'VertexBufferFormat'). */
+ if (g_vbo_id.format.attr_len == 0) {
+ g_vbo_id.pos = GPU_vertformat_attr_add(
+ &g_vbo_id.format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
+ g_vbo_id.nor = GPU_vertformat_attr_add(
+ &g_vbo_id.format, "nor", GPU_COMP_I16, 3, GPU_FETCH_INT_TO_FLOAT_UNIT);
+ /* TODO: Do not allocate these `.msk` and `.col` when they are not used. */
+ g_vbo_id.msk = GPU_vertformat_attr_add(
+ &g_vbo_id.format, "msk", GPU_COMP_U8, 1, GPU_FETCH_INT_TO_FLOAT_UNIT);
+ g_vbo_id.col = GPU_vertformat_attr_add(
+ &g_vbo_id.format, "c", GPU_COMP_U16, 4, GPU_FETCH_INT_TO_FLOAT_UNIT);
+
+ if (vdata && CustomData_has_layer(vdata, CD_PROP_COLOR)) {
+ const int cd_vcol_index = CustomData_get_layer_index(vdata, CD_PROP_COLOR);
+ CustomDataLayer *cl = vdata->layers + cd_vcol_index;
+ cl += cl->active;
+
+ DRW_make_cdlayer_attr_aliases(&g_vbo_id.format, "c", vdata, cl);
+ }
+
+ g_vbo_id.fset = GPU_vertformat_attr_add(
+ &g_vbo_id.format, "fset", GPU_COMP_U8, 3, GPU_FETCH_INT_TO_FLOAT_UNIT);
+
+ g_vbo_id.uv = GPU_vertformat_attr_add(
+ &g_vbo_id.format, "uvs", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
+ GPU_vertformat_alias_add(&g_vbo_id.format, "u");
+
+ if (ldata && CustomData_has_layer(ldata, CD_MLOOPUV)) {
+ const int cd_uv_index = CustomData_get_layer_index(ldata, CD_MLOOPUV);
+ CustomDataLayer *cl = ldata->layers + cd_uv_index;
+ cl += cl->active;
+
+ DRW_make_cdlayer_attr_aliases(&g_vbo_id.format, "u", ldata, cl);
+ }
+
+ }
+}
+
/* Creates a vertex buffer (coordinate, normal, color) and, if smooth
* shading, an element index buffer.
* Threaded - do not call any functions that use OpenGL calls! */
@@ -944,11 +969,7 @@ void GPU_pbvh_bmesh_buffers_update(GPU_PBVH_Buffers *buffers,
int tottri, totvert;
bool empty_mask = true;
BMFace *f = NULL;
- int cd_vcol_offset = -1;
-
- if (CustomData_has_layer(&bm->vdata, CD_PROP_COLOR)) {
- cd_vcol_offset = CustomData_get_offset(&bm->vdata, CD_PROP_COLOR);
- }
+ int cd_vcol_offset = CustomData_get_offset(&bm->vdata, CD_PROP_COLOR);
/* Count visible triangles */
tottri = gpu_bmesh_face_visible_count(bm_faces);
@@ -1094,7 +1115,7 @@ void GPU_pbvh_bmesh_buffers_update(GPU_PBVH_Buffers *buffers,
MPropCol *mp = BM_ELEM_CD_GET_VOID_P(l[i]->v, cd_vcol_offset);
ushort vcol[4];
- //printf(
+ // printf(
// "%.2f %.2f %.2f %.2f\n", mp->color[0], mp->color[1], mp->color[2], mp->color[3]);
vcol[0] = unit_float_to_ushort_clamp(mp->color[0]);
vcol[1] = unit_float_to_ushort_clamp(mp->color[1]);
More information about the Bf-blender-cvs
mailing list