[Bf-blender-cvs] [238e238] object_nodes: Add support for texture node trees in new dependency graph.

Lukas Tönne noreply at git.blender.org
Tue Nov 24 09:44:10 CET 2015


Commit: 238e2389c0b868a070780b1906dd9be0a2619b27
Author: Lukas Tönne
Date:   Sat Nov 7 17:15:28 2015 +0100
Branches: object_nodes
https://developer.blender.org/rB238e2389c0b868a070780b1906dd9be0a2619b27

Add support for texture node trees in new dependency graph.

===================================================================

M	source/blender/blenkernel/BKE_texture.h
M	source/blender/blenkernel/intern/texture.c
M	source/blender/depsgraph/DEG_depsgraph_build.h
M	source/blender/depsgraph/intern/depsgraph_build.cc
M	source/blender/depsgraph/intern/depsgraph_build_nodes.cc
M	source/blender/depsgraph/intern/depsgraph_build_relations.cc
M	source/blender/depsgraph/intern/depsnode_opcodes.h
M	source/blender/modifiers/intern/MOD_displace.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_texture.h b/source/blender/blenkernel/BKE_texture.h
index 95918b9..6c1b87b 100644
--- a/source/blender/blenkernel/BKE_texture.h
+++ b/source/blender/blenkernel/BKE_texture.h
@@ -41,6 +41,7 @@ struct bNode;
 struct Brush;
 struct ColorBand;
 struct EnvMap;
+struct EvaluationContext;
 struct FreestyleLineStyle;
 struct Lamp;
 struct Main;
@@ -137,6 +138,8 @@ void BKE_texture_get_value(
         const struct Scene *scene, struct Tex *texture,
         float *tex_co, struct TexResult *texres, bool use_color_management);
 
+void BKE_texture_invalidate(struct EvaluationContext *eval_ctx, struct Tex *tex);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c
index 463ca25..7cef00b 100644
--- a/source/blender/blenkernel/intern/texture.c
+++ b/source/blender/blenkernel/intern/texture.c
@@ -68,6 +68,9 @@
 #include "BKE_animsys.h"
 #include "BKE_colortools.h"
 #include "BKE_scene.h"
+#include "BKE_depsgraph.h"
+
+#include "BVM_api.h"
 
 #include "RE_shader_ext.h"
 
@@ -1680,3 +1683,12 @@ void BKE_texture_get_value(
 		copy_v3_fl(&texres->tr, texres->tin);
 	}
 }
+
+/* -------------------- */
+/* Depsgraph evaluation */
+
+void BKE_texture_invalidate(EvaluationContext *UNUSED(eval_ctx), Tex *tex)
+{
+	BVM_texture_cache_invalidate(tex);
+}
+
diff --git a/source/blender/depsgraph/DEG_depsgraph_build.h b/source/blender/depsgraph/DEG_depsgraph_build.h
index f680c47..3acae9c 100644
--- a/source/blender/depsgraph/DEG_depsgraph_build.h
+++ b/source/blender/depsgraph/DEG_depsgraph_build.h
@@ -105,9 +105,14 @@ typedef enum eDepsObjectComponentType {
 	DEG_OB_COMP_SHADING,           /* Material Shading Component */
 } eDepsObjectComponentType;
 
+typedef enum eDepsTextureComponentType {
+	DEG_OB_TEX_PARAMETERS,        /* Parameters Component - Default when nothing else fits (i.e. just SDNA property setting) */
+} eDepsTextureComponentType;
+
 void DEG_add_scene_relation(struct DepsNodeHandle *node, struct Scene *scene, eDepsSceneComponentType component, const char *description);
 void DEG_add_object_relation(struct DepsNodeHandle *node, struct Object *ob, eDepsObjectComponentType component, const char *description);
 void DEG_add_bone_relation(struct DepsNodeHandle *handle, struct Object *ob, const char *bone_name, eDepsObjectComponentType component, const char *description);
+void DEG_add_texture_relation(struct DepsNodeHandle *handle, struct Tex *tex, eDepsTextureComponentType component, const char *description);
 
 /* TODO(sergey): Remove once all geometry update is granular. */
 void DEG_add_special_eval_flag(struct Depsgraph *graph, struct ID *id, short flag);
diff --git a/source/blender/depsgraph/intern/depsgraph_build.cc b/source/blender/depsgraph/intern/depsgraph_build.cc
index 7a2ee2c..efbb50c 100644
--- a/source/blender/depsgraph/intern/depsgraph_build.cc
+++ b/source/blender/depsgraph/intern/depsgraph_build.cc
@@ -131,6 +131,14 @@ static eDepsNode_Type deg_build_object_component_type(eDepsObjectComponentType c
 	return DEPSNODE_TYPE_UNDEFINED;
 }
 
+static eDepsNode_Type deg_build_texture_component_type(eDepsTextureComponentType component)
+{
+	switch (component) {
+		case DEG_OB_TEX_PARAMETERS:         return DEPSNODE_TYPE_PARAMETERS;
+	}
+	return DEPSNODE_TYPE_UNDEFINED;
+}
+
 void DEG_add_scene_relation(DepsNodeHandle *handle, struct Scene *scene, eDepsSceneComponentType component, const char *description)
 {
 	eDepsNode_Type type = deg_build_scene_component_type(component);
@@ -154,6 +162,13 @@ void DEG_add_bone_relation(DepsNodeHandle *handle, struct Object *ob, const char
 	handle->builder->add_node_handle_relation(comp_key, handle, DEPSREL_TYPE_GEOMETRY_EVAL, description);
 }
 
+void DEG_add_texture_relation(DepsNodeHandle *handle, struct Tex *tex, eDepsTextureComponentType component, const char *description)
+{
+	eDepsNode_Type type = deg_build_texture_component_type(component);
+	ComponentKey comp_key(&tex->id, type);
+	handle->builder->add_node_handle_relation(comp_key, handle, DEPSREL_TYPE_STANDARD, description);
+}
+
 void DEG_add_special_eval_flag(Depsgraph *graph, ID *id, short flag)
 {
 	if (graph == NULL) {
diff --git a/source/blender/depsgraph/intern/depsgraph_build_nodes.cc b/source/blender/depsgraph/intern/depsgraph_build_nodes.cc
index 5d72cfc..b1e05c7 100644
--- a/source/blender/depsgraph/intern/depsgraph_build_nodes.cc
+++ b/source/blender/depsgraph/intern/depsgraph_build_nodes.cc
@@ -1174,6 +1174,19 @@ void DepsgraphNodeBuilder::build_texture(DepsNode *owner_node, Tex *tex)
 		return;
 	}
 	tex_id->flag |= LIB_DOIT;
+	
+	/* texture itself */
+	add_id_node(tex_id);
+	
+	/* Parameters for drivers. */
+	add_operation_node(tex_id, DEPSNODE_TYPE_PARAMETERS, DEPSOP_TYPE_INIT,
+	                   NULL,
+	                   DEG_OPCODE_TEXTURE_INIT);
+	
+	add_operation_node(tex_id, DEPSNODE_TYPE_PARAMETERS, DEPSOP_TYPE_POST,
+	                   function_bind(BKE_texture_invalidate, _1, tex),
+	                   DEG_OPCODE_TEXTURE_INVALIDATE);
+	
 	/* texture itself */
 	build_animdata(tex_id);
 	/* texture's nodetree */
diff --git a/source/blender/depsgraph/intern/depsgraph_build_relations.cc b/source/blender/depsgraph/intern/depsgraph_build_relations.cc
index 7848195..101e905 100644
--- a/source/blender/depsgraph/intern/depsgraph_build_relations.cc
+++ b/source/blender/depsgraph/intern/depsgraph_build_relations.cc
@@ -1834,12 +1834,29 @@ void DepsgraphRelationBuilder::build_texture(ID *owner, Tex *tex)
 		return;
 	}
 	tex_id->flag |= LIB_DOIT;
-
+	
+	ComponentKey parameters_key(tex_id, DEPSNODE_TYPE_PARAMETERS);
+	
+	OperationKey eval_key(tex_id, DEPSNODE_TYPE_PARAMETERS, DEG_OPCODE_TEXTURE_INIT);
+	OperationKey invalidate_key(tex_id, DEPSNODE_TYPE_PARAMETERS, DEG_OPCODE_TEXTURE_INVALIDATE);
+	add_relation(eval_key, invalidate_key,
+	             DEPSREL_TYPE_OPERATION, "Texture Eval");
+	
 	/* texture itself */
-	build_animdata(tex_id);
-
-	/* texture's nodetree */
-	build_nodetree(owner, tex->nodetree);
+	build_animdata(owner);
+	
+	if (needs_animdata_node(tex_id)) {
+		ComponentKey animation_key(tex_id, DEPSNODE_TYPE_ANIMATION);
+		add_relation(animation_key, parameters_key,
+		             DEPSREL_TYPE_COMPONENT_ORDER, "Texture Parameters");
+	}
+	
+	if (tex->nodetree) {
+		build_nodetree(owner, tex->nodetree);
+		ComponentKey nodetree_key(&tex->nodetree->id, DEPSNODE_TYPE_PARAMETERS);
+		add_relation(nodetree_key, parameters_key,
+		             DEPSREL_TYPE_COMPONENT_ORDER, "NTree->Texture Parameters");
+	}
 }
 
 /* Texture-stack attached to some shading datablock */
diff --git a/source/blender/depsgraph/intern/depsnode_opcodes.h b/source/blender/depsgraph/intern/depsnode_opcodes.h
index b81822c..c62e96c 100644
--- a/source/blender/depsgraph/intern/depsnode_opcodes.h
+++ b/source/blender/depsgraph/intern/depsnode_opcodes.h
@@ -139,6 +139,14 @@ DEF_DEG_OPCODE(BONE_CONSTRAINTS)
 DEF_DEG_OPCODE(BONE_READY)
 DEF_DEG_OPCODE(BONE_DONE)
 
+/* Textures ---------------------------------------- */
+
+/* placeholder */
+DEF_DEG_OPCODE(TEXTURE_INIT)
+
+/* invalidate caches, recalculate texture effects */
+DEF_DEG_OPCODE(TEXTURE_INVALIDATE)
+
 /* Particles --------------------------------------- */
 
 /* XXX: placeholder - Particle System eval */
diff --git a/source/blender/modifiers/intern/MOD_displace.c b/source/blender/modifiers/intern/MOD_displace.c
index 9ba2d21..d48bd97 100644
--- a/source/blender/modifiers/intern/MOD_displace.c
+++ b/source/blender/modifiers/intern/MOD_displace.c
@@ -190,6 +190,9 @@ static void updateDepsgraph(ModifierData *md,
 	if (dmd->texmapping == MOD_DISP_MAP_GLOBAL) {
 		DEG_add_object_relation(node, ob, DEG_OB_COMP_TRANSFORM, "Displace Modifier");
 	}
+	if (dmd->texture) {
+		DEG_add_texture_relation(node, dmd->texture, DEG_OB_TEX_PARAMETERS, "Displace Modifier");
+	}
 }
 
 /* dm must be a CDDerivedMesh */




More information about the Bf-blender-cvs mailing list