Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen Bakker <jeroen@blender.org>2020-12-18 18:06:26 +0300
committerJeroen Bakker <jeroen@blender.org>2021-01-04 13:09:56 +0300
commitd11a87b88c4d76aff77912313752d23fffc8e65d (patch)
treebd770e25985ccb82b2557790d654ea6c8fc36642 /source/blender/draw/intern/draw_cache_impl_volume.c
parent17be2149a805a3f43a10ff6f800ada429889aa6b (diff)
DrawManager: High quality normals for non meshes
This adds high quality normals for non meshes. These include * Volumetric Object Wireframe * Metaballs * Extracted Curves * Curves in edit mode This is in preparation to fix a regression in recent AMD drivers where the `GL_INT_2_10_10_10_REV` data type isn't working in Polaris cards.
Diffstat (limited to 'source/blender/draw/intern/draw_cache_impl_volume.c')
-rw-r--r--source/blender/draw/intern/draw_cache_impl_volume.c38
1 files changed, 31 insertions, 7 deletions
diff --git a/source/blender/draw/intern/draw_cache_impl_volume.c b/source/blender/draw/intern/draw_cache_impl_volume.c
index 1a9e40fb03b..e90282a269a 100644
--- a/source/blender/draw/intern/draw_cache_impl_volume.c
+++ b/source/blender/draw/intern/draw_cache_impl_volume.c
@@ -145,25 +145,45 @@ void DRW_volume_batch_cache_free(Volume *volume)
volume_batch_cache_clear(volume);
MEM_SAFE_FREE(volume->batch_cache);
}
+typedef struct VolumeWireframeUserData {
+ Volume *volume;
+ Scene *scene;
+} VolumeWireframeUserData;
static void drw_volume_wireframe_cb(
void *userdata, float (*verts)[3], int (*edges)[2], int totvert, int totedge)
{
- Volume *volume = userdata;
+ VolumeWireframeUserData *data = userdata;
+ Scene *scene = data->scene;
+ Volume *volume = data->volume;
VolumeBatchCache *cache = volume->batch_cache;
+ const bool do_hq_normals = (scene->r.perf_flag & SCE_PERF_HQ_NORMALS) != 0;
/* Create vertex buffer. */
static GPUVertFormat format = {0};
- static uint pos_id, nor_id;
+ static GPUVertFormat format_hq = {0};
+ static struct {
+ uint pos_id, nor_id;
+ uint pos_hq_id, nor_hq_id;
+ } attr_id;
+
if (format.attr_len == 0) {
- pos_id = GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
- nor_id = GPU_vertformat_attr_add(&format, "nor", GPU_COMP_I10, 4, GPU_FETCH_INT_TO_FLOAT_UNIT);
+ attr_id.pos_id = GPU_vertformat_attr_add(&format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
+ attr_id.nor_id = GPU_vertformat_attr_add(
+ &format, "nor", GPU_COMP_I10, 4, GPU_FETCH_INT_TO_FLOAT_UNIT);
+ attr_id.pos_id = GPU_vertformat_attr_add(&format_hq, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
+ attr_id.nor_id = GPU_vertformat_attr_add(
+ &format_hq, "nor", GPU_COMP_I16, 3, GPU_FETCH_INT_TO_FLOAT_UNIT);
}
static float normal[3] = {1.0f, 0.0f, 0.0f};
- GPUPackedNormal packed_normal = GPU_normal_convert_i10_v3(normal);
+ GPUNormal packed_normal;
+ GPU_normal_convert_v3(&packed_normal, normal, do_hq_normals);
+ uint pos_id = do_hq_normals ? attr_id.pos_hq_id : attr_id.pos_id;
+ uint nor_id = do_hq_normals ? attr_id.nor_hq_id : attr_id.nor_id;
- cache->face_wire.pos_nor_in_order = GPU_vertbuf_create_with_format(&format);
+ cache->face_wire.pos_nor_in_order = GPU_vertbuf_create_with_format(do_hq_normals ? &format_hq :
+ &format);
GPU_vertbuf_data_alloc(cache->face_wire.pos_nor_in_order, totvert);
GPU_vertbuf_attr_fill(cache->face_wire.pos_nor_in_order, pos_id, verts);
GPU_vertbuf_attr_fill_stride(cache->face_wire.pos_nor_in_order, nor_id, 0, &packed_normal);
@@ -209,7 +229,11 @@ GPUBatch *DRW_volume_batch_cache_get_wireframes_face(Volume *volume)
}
/* Create wireframe from OpenVDB tree. */
- BKE_volume_grid_wireframe(volume, volume_grid, drw_volume_wireframe_cb, volume);
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ VolumeWireframeUserData userdata;
+ userdata.volume = volume;
+ userdata.scene = draw_ctx->scene;
+ BKE_volume_grid_wireframe(volume, volume_grid, drw_volume_wireframe_cb, &userdata);
}
return cache->face_wire.batch;