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:
authorAlexander Gavrilov <angavrilov@gmail.com>2022-09-30 18:54:26 +0300
committerAlexander Gavrilov <angavrilov@gmail.com>2022-09-30 20:01:57 +0300
commit554afabf7580d60cc1990bb9df9d9940cb1fb1c3 (patch)
treefdd40672265c948b600482d3b17d9667dbf17844 /source/blender/draw
parent42eda155df3b77a49c4c1aa3ddcc681e43771111 (diff)
Attribute Node: refactor lookup to remove duplication between engines.
Currently lookup of Object and Instancer attributes is completely duplicated between Cycles, Eevee and Eevee Next. This is bad design, so this patch aims to deduplicate it by introducing a common API in blenkernel. In case of Cycles this requires certain hacks, but according to Brecht it is planned to be rewritten later for more direct access to internal Blender data anyway. Differential Revision: https://developer.blender.org/D16117
Diffstat (limited to 'source/blender/draw')
-rw-r--r--source/blender/draw/intern/draw_instance_data.c75
-rw-r--r--source/blender/draw/intern/draw_resource.cc77
-rw-r--r--source/blender/draw/intern/draw_shader_shared.h1
3 files changed, 7 insertions, 146 deletions
diff --git a/source/blender/draw/intern/draw_instance_data.c b/source/blender/draw/intern/draw_instance_data.c
index 7ed5ca7c983..a56883ce304 100644
--- a/source/blender/draw/intern/draw_instance_data.c
+++ b/source/blender/draw/intern/draw_instance_data.c
@@ -585,87 +585,18 @@ static DRWUniformAttrBuf *drw_uniform_attrs_pool_ensure(GHash *table,
return (DRWUniformAttrBuf *)*pval;
}
-/* This function mirrors lookup_property in cycles/blender/blender_object.cpp */
-static bool drw_uniform_property_lookup(ID *id, const char *name, float r_data[4])
-{
- PointerRNA ptr, id_ptr;
- PropertyRNA *prop;
-
- if (!id) {
- return false;
- }
-
- RNA_id_pointer_create(id, &id_ptr);
-
- if (!RNA_path_resolve(&id_ptr, name, &ptr, &prop)) {
- return false;
- }
-
- if (prop == NULL) {
- return false;
- }
-
- PropertyType type = RNA_property_type(prop);
- int arraylen = RNA_property_array_length(&ptr, prop);
-
- if (arraylen == 0) {
- float value;
-
- if (type == PROP_FLOAT) {
- value = RNA_property_float_get(&ptr, prop);
- }
- else if (type == PROP_INT) {
- value = RNA_property_int_get(&ptr, prop);
- }
- else {
- return false;
- }
-
- copy_v4_fl4(r_data, value, value, value, 1);
- return true;
- }
-
- if (type == PROP_FLOAT && arraylen <= 4) {
- copy_v4_fl4(r_data, 0, 0, 0, 1);
- RNA_property_float_get_array(&ptr, prop, r_data);
- return true;
- }
-
- return false;
-}
-
-/* This function mirrors lookup_instance_property in cycles/blender/blender_object.cpp */
static void drw_uniform_attribute_lookup(GPUUniformAttr *attr,
Object *ob,
Object *dupli_parent,
DupliObject *dupli_source,
float r_data[4])
{
- copy_v4_fl(r_data, 0);
-
/* If requesting instance data, check the parent particle system and object. */
if (attr->use_dupli) {
- if (dupli_source && dupli_source->particle_system) {
- ParticleSettings *settings = dupli_source->particle_system->part;
- if (drw_uniform_property_lookup((ID *)settings, attr->name_id_prop, r_data) ||
- drw_uniform_property_lookup((ID *)settings, attr->name, r_data)) {
- return;
- }
- }
- if (drw_uniform_property_lookup((ID *)dupli_parent, attr->name_id_prop, r_data) ||
- drw_uniform_property_lookup((ID *)dupli_parent, attr->name, r_data)) {
- return;
- }
+ BKE_object_dupli_find_rgba_attribute(ob, dupli_source, dupli_parent, attr->name, r_data);
}
-
- /* Check the object and mesh. */
- if (ob) {
- if (drw_uniform_property_lookup((ID *)ob, attr->name_id_prop, r_data) ||
- drw_uniform_property_lookup((ID *)ob, attr->name, r_data) ||
- drw_uniform_property_lookup((ID *)ob->data, attr->name_id_prop, r_data) ||
- drw_uniform_property_lookup((ID *)ob->data, attr->name, r_data)) {
- return;
- }
+ else {
+ BKE_object_dupli_find_rgba_attribute(ob, NULL, NULL, attr->name, r_data);
}
}
diff --git a/source/blender/draw/intern/draw_resource.cc b/source/blender/draw/intern/draw_resource.cc
index 689df4edb31..f57058190fb 100644
--- a/source/blender/draw/intern/draw_resource.cc
+++ b/source/blender/draw/intern/draw_resource.cc
@@ -19,58 +19,6 @@
* \{ */
/**
- * Extract object attribute from RNA property.
- * Returns true if the attribute was correctly extracted.
- * This function mirrors lookup_property in cycles/blender/blender_object.cpp
- */
-bool ObjectAttribute::id_property_lookup(ID *id, const char *name)
-{
- PointerRNA ptr, id_ptr;
- PropertyRNA *prop;
-
- if (id == nullptr) {
- return false;
- }
-
- RNA_id_pointer_create(id, &id_ptr);
-
- if (!RNA_path_resolve(&id_ptr, name, &ptr, &prop)) {
- return false;
- }
-
- if (prop == nullptr) {
- return false;
- }
-
- PropertyType type = RNA_property_type(prop);
- int array_len = RNA_property_array_length(&ptr, prop);
-
- if (array_len == 0) {
- float value;
-
- if (type == PROP_FLOAT) {
- value = RNA_property_float_get(&ptr, prop);
- }
- else if (type == PROP_INT) {
- value = RNA_property_int_get(&ptr, prop);
- }
- else {
- return false;
- }
-
- *reinterpret_cast<float4 *>(&data_x) = float4(value, value, value, 1.0f);
- return true;
- }
-
- if (type == PROP_FLOAT && array_len <= 4) {
- *reinterpret_cast<float4 *>(&data_x) = float4(0.0f, 0.0f, 0.0f, 1.0f);
- RNA_property_float_get_array(&ptr, prop, &data_x);
- return true;
- }
- return false;
-}
-
-/**
* Go through all possible source of the given object uniform attribute.
* Returns true if the attribute was correctly filled.
* This function mirrors lookup_instance_property in cycles/blender/blender_object.cpp
@@ -81,29 +29,12 @@ bool ObjectAttribute::sync(const blender::draw::ObjectRef &ref, const GPUUniform
/* If requesting instance data, check the parent particle system and object. */
if (attr.use_dupli) {
- if ((ref.dupli_object != nullptr) && (ref.dupli_object->particle_system != nullptr)) {
- ParticleSettings *settings = ref.dupli_object->particle_system->part;
- if (this->id_property_lookup((ID *)settings, attr.name_id_prop) ||
- this->id_property_lookup((ID *)settings, attr.name)) {
- return true;
- }
- }
- if (this->id_property_lookup((ID *)ref.dupli_parent, attr.name_id_prop) ||
- this->id_property_lookup((ID *)ref.dupli_parent, attr.name)) {
- return true;
- }
+ return BKE_object_dupli_find_rgba_attribute(
+ ref.object, ref.dupli_object, ref.dupli_parent, attr.name, &data_x);
}
-
- /* Check the object and mesh. */
- if (ref.object != nullptr) {
- if (this->id_property_lookup((ID *)ref.object, attr.name_id_prop) ||
- this->id_property_lookup((ID *)ref.object, attr.name) ||
- this->id_property_lookup((ID *)ref.object->data, attr.name_id_prop) ||
- this->id_property_lookup((ID *)ref.object->data, attr.name)) {
- return true;
- }
+ else {
+ return BKE_object_dupli_find_rgba_attribute(ref.object, nullptr, nullptr, attr.name, &data_x);
}
- return false;
}
/** \} */
diff --git a/source/blender/draw/intern/draw_shader_shared.h b/source/blender/draw/intern/draw_shader_shared.h
index bedbedcf438..a572b9ee865 100644
--- a/source/blender/draw/intern/draw_shader_shared.h
+++ b/source/blender/draw/intern/draw_shader_shared.h
@@ -205,7 +205,6 @@ struct ObjectAttribute {
#if !defined(GPU_SHADER) && defined(__cplusplus)
bool sync(const blender::draw::ObjectRef &ref, const GPUUniformAttr &attr);
- bool id_property_lookup(ID *id, const char *name);
#endif
};
#pragma pack(pop)