[Bf-blender-cvs] [1be189f] master: Cycles: Get rid of hardcoded enum values in the code

Sergey Sharybin noreply at git.blender.org
Wed Oct 22 16:17:45 CEST 2014


Commit: 1be189f000242db37c074599e75761669b1afc58
Author: Sergey Sharybin
Date:   Wed Oct 22 16:17:03 2014 +0200
Branches: master
https://developer.blender.org/rB1be189f000242db37c074599e75761669b1afc58

Cycles: Get rid of hardcoded enum values in the code

Still need to keep enum definition in sync with the python code,
but the code itself is a bit more clear to understand now.

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

M	intern/cycles/blender/blender_shader.cpp
M	intern/cycles/render/shader.cpp
M	intern/cycles/render/shader.h

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

diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp
index 97f2ecc..27c2e9e 100644
--- a/intern/cycles/blender/blender_shader.cpp
+++ b/intern/cycles/blender/blender_shader.cpp
@@ -1014,8 +1014,8 @@ void BlenderSync::sync_materials(bool update_all)
 			shader->use_mis = get_boolean(cmat, "sample_as_light");
 			shader->use_transparent_shadow = get_boolean(cmat, "use_transparent_shadow");
 			shader->heterogeneous_volume = !get_boolean(cmat, "homogeneous_volume");
-			shader->volume_sampling_method = RNA_enum_get(&cmat, "volume_sampling");
-			shader->volume_interpolation_method = RNA_enum_get(&cmat, "volume_interpolation");
+			shader->volume_sampling_method = (VolumeSampling)RNA_enum_get(&cmat, "volume_sampling");
+			shader->volume_interpolation_method = (VolumeInterpolation)RNA_enum_get(&cmat, "volume_interpolation");
 
 			shader->set_graph(graph);
 			shader->tag_update(scene);
@@ -1045,8 +1045,8 @@ void BlenderSync::sync_world(bool update_all)
 			/* volume */
 			PointerRNA cworld = RNA_pointer_get(&b_world.ptr, "cycles");
 			shader->heterogeneous_volume = !get_boolean(cworld, "homogeneous_volume");
-			shader->volume_sampling_method = RNA_enum_get(&cworld, "volume_sampling");
-			shader->volume_interpolation_method = RNA_enum_get(&cworld, "volume_interpolation");
+			shader->volume_sampling_method = (VolumeSampling)RNA_enum_get(&cworld, "volume_sampling");
+			shader->volume_interpolation_method = (VolumeInterpolation)RNA_enum_get(&cworld, "volume_interpolation");
 		}
 		else if(b_world) {
 			ShaderNode *closure, *out;
diff --git a/intern/cycles/render/shader.cpp b/intern/cycles/render/shader.cpp
index b960dfa..2a3969b 100644
--- a/intern/cycles/render/shader.cpp
+++ b/intern/cycles/render/shader.cpp
@@ -138,8 +138,8 @@ Shader::Shader()
 	use_mis = true;
 	use_transparent_shadow = true;
 	heterogeneous_volume = true;
-	volume_sampling_method = 0;
-	volume_interpolation_method = 0;
+	volume_sampling_method = VOLUME_SAMPLING_DISTANCE;
+	volume_interpolation_method = VOLUME_INTERPOLATION_LINEAR;
 
 	has_surface = false;
 	has_surface_transparent = false;
@@ -353,11 +353,11 @@ void ShaderManager::device_update_common(Device *device, DeviceScene *dscene, Sc
 			flag |= SD_HAS_BSSRDF_BUMP;
 		if(shader->has_converter_blackbody)
 			has_converter_blackbody = true;
-		if(shader->volume_sampling_method == 1)
+		if(shader->volume_sampling_method == VOLUME_SAMPLING_EQUIANGULAR)
 			flag |= SD_VOLUME_EQUIANGULAR;
-		if(shader->volume_sampling_method == 2)
+		if(shader->volume_sampling_method == VOLUME_SAMPLING_MULTIPLE_IMPORTANCE)
 			flag |= SD_VOLUME_MIS;
-		if(shader->volume_interpolation_method == 1)
+		if(shader->volume_interpolation_method == VOLUME_INTERPOLATION_CUBIC)
 			flag |= SD_VOLUME_CUBIC;
 
 		/* regular shader */
diff --git a/intern/cycles/render/shader.h b/intern/cycles/render/shader.h
index 0eef62a..b267731 100644
--- a/intern/cycles/render/shader.h
+++ b/intern/cycles/render/shader.h
@@ -44,6 +44,18 @@ enum ShadingSystem {
 	SHADINGSYSTEM_SVM
 };
 
+/* Keep those in sync with the python-defined enum. */
+enum VolumeSampling {
+	VOLUME_SAMPLING_DISTANCE = 0,
+	VOLUME_SAMPLING_EQUIANGULAR = 1,
+	VOLUME_SAMPLING_MULTIPLE_IMPORTANCE = 2,
+};
+
+enum VolumeInterpolation {
+	VOLUME_INTERPOLATION_LINEAR = 0,
+	VOLUME_INTERPOLATION_CUBIC = 1,
+};
+
 /* Shader describing the appearance of a Mesh, Light or Background.
  *
  * While there is only a single shader graph, it has three outputs: surface,
@@ -68,7 +80,7 @@ public:
 	bool use_mis;
 	bool use_transparent_shadow;
 	bool heterogeneous_volume;
-	int volume_sampling_method;
+	VolumeSampling volume_sampling_method;
 	int volume_interpolation_method;
 
 	/* synchronization */




More information about the Bf-blender-cvs mailing list