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:
authorHans Goudey <h.goudey@me.com>2022-06-23 00:57:57 +0300
committerHans Goudey <h.goudey@me.com>2022-06-23 00:58:22 +0300
commitd2a3b99ff7abb3d7deb30da4554b1cda6ff32766 (patch)
treef08204c8296144b284a5173e711ba18965b8d129
parent532b33973bb71f91a5962c9f9c63ff26bf51bd67 (diff)
Cleanup: Use const arguments
Also use Curves as an argument instead of Object, since it's more specific to this situation.
-rw-r--r--source/blender/draw/intern/draw_cache_impl_curves.cc28
-rw-r--r--source/blender/draw/intern/draw_curves.cc24
-rw-r--r--source/blender/draw/intern/draw_curves_private.h13
3 files changed, 35 insertions, 30 deletions
diff --git a/source/blender/draw/intern/draw_cache_impl_curves.cc b/source/blender/draw/intern/draw_cache_impl_curves.cc
index ee81f74ca26..6e098e0310d 100644
--- a/source/blender/draw/intern/draw_cache_impl_curves.cc
+++ b/source/blender/draw/intern/draw_cache_impl_curves.cc
@@ -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;
diff --git a/source/blender/draw/intern/draw_curves.cc b/source/blender/draw/intern/draw_curves.cc
index c40f2275968..d040b4eade3 100644
--- a/source/blender/draw/intern/draw_curves.cc
+++ b/source/blender/draw/intern/draw_curves.cc
@@ -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) {
diff --git a/source/blender/draw/intern/draw_curves_private.h b/source/blender/draw/intern/draw_curves_private.h
index 7d54e1089d6..31122ed5248 100644
--- a/source/blender/draw/intern/draw_curves_private.h
+++ b/source/blender/draw/intern/draw_curves_private.h
@@ -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,