Cleanup: Use const arguments
Also use Curves as an argument instead of Object, since it's more specific to this situation.
This commit is contained in:
parent
532b33973b
commit
d2a3b99ff7
Notes:
blender-bot
2023-02-14 03:03:03 +01:00
Referenced by issue #99171, Regression: crash in BKE_mesh_tag_coords_changed when modifying vertex coods of appended item via script
|
@ -258,7 +258,7 @@ static void curves_batch_cache_fill_segments_proc_pos(
|
|||
}
|
||||
}
|
||||
|
||||
static void curves_batch_cache_ensure_procedural_pos(Curves &curves,
|
||||
static void curves_batch_cache_ensure_procedural_pos(const Curves &curves,
|
||||
CurvesEvalCache &cache,
|
||||
GPUMaterial *gpu_material)
|
||||
{
|
||||
|
@ -311,8 +311,11 @@ void drw_curves_get_attribute_sampler_name(const char *layer_name, char r_sample
|
|||
BLI_snprintf(r_sampler_name, 32, "a%s", attr_safe_name);
|
||||
}
|
||||
|
||||
static void curves_batch_cache_ensure_procedural_final_attr(
|
||||
CurvesEvalCache &cache, GPUVertFormat *format, int subdiv, int index, const char *name)
|
||||
static void curves_batch_cache_ensure_procedural_final_attr(CurvesEvalCache &cache,
|
||||
const GPUVertFormat *format,
|
||||
const int subdiv,
|
||||
const int index,
|
||||
const char *name)
|
||||
{
|
||||
CurvesEvalFinalCache &final_cache = cache.final[subdiv];
|
||||
final_cache.attributes_buf[index] = GPU_vertbuf_create_with_format_ex(format,
|
||||
|
@ -333,8 +336,8 @@ static void curves_batch_cache_ensure_procedural_final_attr(
|
|||
static void curves_batch_ensure_attribute(const Curves &curves,
|
||||
CurvesEvalCache &cache,
|
||||
const DRW_AttributeRequest &request,
|
||||
int subdiv,
|
||||
int index)
|
||||
const int subdiv,
|
||||
const int index)
|
||||
{
|
||||
GPU_VERTBUF_DISCARD_SAFE(cache.proc_attributes_buf[index]);
|
||||
DRW_TEXTURE_FREE_SAFE(cache.proc_attributes_tex[index]);
|
||||
|
@ -563,16 +566,15 @@ static bool curves_ensure_attributes(const Curves &curves,
|
|||
return need_tf_update;
|
||||
}
|
||||
|
||||
bool curves_ensure_procedural_data(Object *object,
|
||||
bool curves_ensure_procedural_data(Curves *curves,
|
||||
CurvesEvalCache **r_hair_cache,
|
||||
GPUMaterial *gpu_material,
|
||||
const int subdiv,
|
||||
const int thickness_res)
|
||||
{
|
||||
bool need_ft_update = false;
|
||||
Curves &curves = *static_cast<Curves *>(object->data);
|
||||
|
||||
CurvesBatchCache &cache = curves_batch_cache_get(curves);
|
||||
CurvesBatchCache &cache = curves_batch_cache_get(*curves);
|
||||
*r_hair_cache = &cache.curves_cache;
|
||||
|
||||
const int steps = 3; /* TODO: don't hard-code? */
|
||||
|
@ -580,14 +582,14 @@ bool curves_ensure_procedural_data(Object *object,
|
|||
|
||||
/* Refreshed on combing and simulation. */
|
||||
if ((*r_hair_cache)->proc_point_buf == nullptr) {
|
||||
ensure_seg_pt_count(curves, cache.curves_cache);
|
||||
curves_batch_cache_ensure_procedural_pos(curves, cache.curves_cache, gpu_material);
|
||||
ensure_seg_pt_count(*curves, cache.curves_cache);
|
||||
curves_batch_cache_ensure_procedural_pos(*curves, cache.curves_cache, gpu_material);
|
||||
need_ft_update = true;
|
||||
}
|
||||
|
||||
/* Refreshed if active layer or custom data changes. */
|
||||
if ((*r_hair_cache)->strand_tex == nullptr) {
|
||||
curves_batch_cache_ensure_procedural_strand_data(curves, cache.curves_cache);
|
||||
curves_batch_cache_ensure_procedural_strand_data(*curves, cache.curves_cache);
|
||||
}
|
||||
|
||||
/* Refreshed only on subdiv count change. */
|
||||
|
@ -597,11 +599,11 @@ bool curves_ensure_procedural_data(Object *object,
|
|||
}
|
||||
if ((*r_hair_cache)->final[subdiv].proc_hairs[thickness_res - 1] == nullptr) {
|
||||
curves_batch_cache_ensure_procedural_indices(
|
||||
curves, cache.curves_cache, thickness_res, subdiv);
|
||||
*curves, cache.curves_cache, thickness_res, subdiv);
|
||||
}
|
||||
|
||||
if (gpu_material) {
|
||||
need_ft_update |= curves_ensure_attributes(curves, cache, gpu_material, subdiv);
|
||||
need_ft_update |= curves_ensure_attributes(*curves, cache, gpu_material, subdiv);
|
||||
}
|
||||
|
||||
return need_ft_update;
|
||||
|
|
|
@ -246,13 +246,14 @@ static void drw_curves_cache_update_transform_feedback(CurvesEvalCache *cache, c
|
|||
}
|
||||
}
|
||||
|
||||
static CurvesEvalCache *drw_curves_cache_get(Object *object,
|
||||
static CurvesEvalCache *drw_curves_cache_get(Curves &curves,
|
||||
GPUMaterial *gpu_material,
|
||||
int subdiv,
|
||||
int thickness_res)
|
||||
{
|
||||
CurvesEvalCache *cache;
|
||||
bool update = curves_ensure_procedural_data(object, &cache, gpu_material, subdiv, thickness_res);
|
||||
const bool update = curves_ensure_procedural_data(
|
||||
&curves, &cache, gpu_material, subdiv, thickness_res);
|
||||
|
||||
if (update) {
|
||||
if (drw_curves_shader_type_get() == PART_REFINE_SHADER_COMPUTE) {
|
||||
|
@ -268,12 +269,13 @@ static CurvesEvalCache *drw_curves_cache_get(Object *object,
|
|||
GPUVertBuf *DRW_curves_pos_buffer_get(Object *object)
|
||||
{
|
||||
const DRWContextState *draw_ctx = DRW_context_state_get();
|
||||
Scene *scene = draw_ctx->scene;
|
||||
const Scene *scene = draw_ctx->scene;
|
||||
|
||||
int subdiv = scene->r.hair_subdiv;
|
||||
int thickness_res = (scene->r.hair_type == SCE_HAIR_SHAPE_STRAND) ? 1 : 2;
|
||||
const int subdiv = scene->r.hair_subdiv;
|
||||
const int thickness_res = (scene->r.hair_type == SCE_HAIR_SHAPE_STRAND) ? 1 : 2;
|
||||
|
||||
CurvesEvalCache *cache = drw_curves_cache_get(object, nullptr, subdiv, thickness_res);
|
||||
Curves &curves = *static_cast<Curves *>(object->data);
|
||||
CurvesEvalCache *cache = drw_curves_cache_get(curves, nullptr, subdiv, thickness_res);
|
||||
|
||||
return cache->final[subdiv].proc_buf;
|
||||
}
|
||||
|
@ -303,15 +305,16 @@ DRWShadingGroup *DRW_shgroup_curves_create_sub(Object *object,
|
|||
GPUMaterial *gpu_material)
|
||||
{
|
||||
const DRWContextState *draw_ctx = DRW_context_state_get();
|
||||
Scene *scene = draw_ctx->scene;
|
||||
const Scene *scene = draw_ctx->scene;
|
||||
CurvesUniformBufPool *pool = DST.vmempool->curves_ubos;
|
||||
CurvesInfosBuf &curves_infos = pool->alloc();
|
||||
Curves &curves_id = *static_cast<Curves *>(object->data);
|
||||
|
||||
int subdiv = scene->r.hair_subdiv;
|
||||
int thickness_res = (scene->r.hair_type == SCE_HAIR_SHAPE_STRAND) ? 1 : 2;
|
||||
const int subdiv = scene->r.hair_subdiv;
|
||||
const int thickness_res = (scene->r.hair_type == SCE_HAIR_SHAPE_STRAND) ? 1 : 2;
|
||||
|
||||
CurvesEvalCache *curves_cache = drw_curves_cache_get(
|
||||
object, gpu_material, subdiv, thickness_res);
|
||||
curves_id, gpu_material, subdiv, thickness_res);
|
||||
|
||||
DRWShadingGroup *shgrp = DRW_shgroup_create_sub(shgrp_parent);
|
||||
|
||||
|
@ -330,7 +333,6 @@ DRWShadingGroup *DRW_shgroup_curves_create_sub(Object *object,
|
|||
|
||||
/* Use the radius of the root and tip of the first curve for now. This is a workaround that we
|
||||
* use for now because we can't use a per-point radius yet. */
|
||||
Curves &curves_id = *static_cast<Curves *>(object->data);
|
||||
const blender::bke::CurvesGeometry &curves = blender::bke::CurvesGeometry::wrap(
|
||||
curves_id.geometry);
|
||||
if (curves.curves_num() >= 1) {
|
||||
|
|
|
@ -16,6 +16,12 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct Curves;
|
||||
struct GPUVertBuf;
|
||||
struct GPUIndexBuf;
|
||||
struct GPUBatch;
|
||||
struct GPUTexture;
|
||||
|
||||
#define MAX_THICKRES 2 /* see eHairType */
|
||||
#define MAX_HAIR_SUBDIV 4 /* see hair_subdiv rna */
|
||||
|
||||
|
@ -25,11 +31,6 @@ typedef enum CurvesEvalShader {
|
|||
} CurvesEvalShader;
|
||||
#define CURVES_EVAL_SHADER_NUM 3
|
||||
|
||||
struct GPUVertBuf;
|
||||
struct GPUIndexBuf;
|
||||
struct GPUBatch;
|
||||
struct GPUTexture;
|
||||
|
||||
typedef struct CurvesEvalFinalCache {
|
||||
/* Output of the subdivision stage: vertex buffer sized to subdiv level. */
|
||||
GPUVertBuf *proc_buf;
|
||||
|
@ -95,7 +96,7 @@ typedef struct CurvesEvalCache {
|
|||
/**
|
||||
* Ensure all necessary textures and buffers exist for GPU accelerated drawing.
|
||||
*/
|
||||
bool curves_ensure_procedural_data(struct Object *object,
|
||||
bool curves_ensure_procedural_data(struct Curves *curves,
|
||||
struct CurvesEvalCache **r_hair_cache,
|
||||
struct GPUMaterial *gpu_material,
|
||||
int subdiv,
|
||||
|
|
Loading…
Reference in New Issue