[Bf-blender-cvs] [e3e2f24] cycles-ptex-06: More cleanup

Nicholas Bishop noreply at git.blender.org
Thu Jan 15 20:13:33 CET 2015


Commit: e3e2f242a3605f34d351f8c92c420e6791f7853d
Author: Nicholas Bishop
Date:   Thu Jan 15 17:53:56 2015 +0100
Branches: cycles-ptex-06
https://developer.blender.org/rBe3e2f242a3605f34d351f8c92c420e6791f7853d

More cleanup

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

M	intern/cycles/render/image.cpp

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

diff --git a/intern/cycles/render/image.cpp b/intern/cycles/render/image.cpp
index bfeaa15..913059c 100644
--- a/intern/cycles/render/image.cpp
+++ b/intern/cycles/render/image.cpp
@@ -110,57 +110,75 @@ struct PtexEdgeIter {
 
 		float u_res = res.u() - 1.0f;
 		float v_res = res.v() - 1.0f;
-		const float u_step = (u_res + 1.0f) / (float)from_res;
-		const float v_step = (v_res + 1.0f) / (float)from_res;
+		const float u_incr = (u_res + 1.0f) / (float)from_res;
+		const float v_incr = (v_res + 1.0f) / (float)from_res;
 
 		switch (edge_id) {
 			case Ptex::e_bottom:
 				if (reverse) {
 					pos = make_float2(u_res, 0);
-					step = make_float2(-u_step, 0);
+					incr = make_float2(-u_incr, 0);
 				}
 				else {
 					pos = make_float2(0, 0);
-					step = make_float2(u_step, 0);
+					incr = make_float2(u_incr, 0);
 				}
 				break;
 
 			case Ptex::e_right:
 				if (reverse) {
 					pos = make_float2(u_res, v_res);
-					step = make_float2(0, -v_step);
+					incr = make_float2(0, -v_incr);
 				}
 				else {
 					pos = make_float2(u_res, 0);
-					step = make_float2(0, v_step);
+					incr = make_float2(0, v_incr);
 				}
 				break;
 
 			case Ptex::e_top:
 				if (reverse) {
 					pos = make_float2(0, v_res);
-					step = make_float2(u_step, 0);
+					incr = make_float2(u_incr, 0);
 				}
 				else {
 					pos = make_float2(u_res, v_res);
-					step = make_float2(-u_step, 0);
+					incr = make_float2(-u_incr, 0);
 				}
 				break;
 
 			case Ptex::e_left:
 				if (reverse) {
 					pos = make_float2(0, 0);
-					step = make_float2(0, v_step);
+					incr = make_float2(0, v_incr);
 				}
 				else {
 					pos = make_float2(0, v_res);
-					step = make_float2(0, -v_step);
+					incr = make_float2(0, -v_incr);
 				}
 		}
 	}
 
-	void next() {
-		pos += step;
+	void step() {
+		pos += incr;
+	}
+
+	void step(int n) {
+		pos += incr * n;
+	}
+
+	void read_num_texels(PtexPackedTexture &output, const int num,
+						 int *dst_offset, const int dst_incr)
+	{
+		for (int i = 0; i < num; i++) {
+			const int offset = *dst_offset;
+
+			assert(output.valid_pixel_index(offset));
+			read_texel(output.texels.data() + offset);
+
+			(*dst_offset) += dst_incr;
+			step();
+		}
 	}
 
 	/* TODO(nicholasbishop): not doing any special filtering for
@@ -177,7 +195,7 @@ struct PtexEdgeIter {
 
 	PtexFaceData &face;
 	float2 pos;
-	float2 step;
+	float2 incr;
 };
 
 #if 0
@@ -244,8 +262,7 @@ static void ptex_copy_face_pixels(PtexPackedTexture &output,
 	/* Add borders by copying data from adjacent faces */
 	const Ptex::FaceInfo &info = r->getFaceInfo(face_id);
 	const bool is_subface = info.isSubface();
-	const int x_inc[4] = {bpt, 0,          -bpt, 0};
-	const int y_inc[4] = {0,   dst_stride,  0,   -dst_stride};
+	const int dst_incr_array[4] = {bpt, dst_stride, -bpt, -dst_stride};
 	dst_offset = ((elem.co[1] - 1) * output.width +
 				  (elem.co[0] - 1)) * bpt;
 
@@ -254,9 +271,10 @@ static void ptex_copy_face_pixels(PtexPackedTexture &output,
 		 * is adjacent to a non-quad there are two adjacent subfaces */
 		int adj_face_id[2] = {info.adjface(i), -1};
 		Ptex::EdgeId adj_edge[2] = {info.adjedge(i)};
+		bool no_adj = false;
 
+		// TODO
 		const int side_res = elem.res[(i == 0 || i == 2) ? 0 : 1];
-		bool no_adj = false;
 
 		if (adj_face_id[0] == -1) {
 			/* If there's no adjacent face, pretend the face is
@@ -276,69 +294,39 @@ static void ptex_copy_face_pixels(PtexPackedTexture &output,
 		}
 
 		// TODO: handle corners correctly
-
-		dst_offset += x_inc[i] + y_inc[i];
+		const int dst_incr = dst_incr_array[i];
+		dst_offset += dst_incr;
 
 		PtexFaceData *face_data[2] = {
 			r->getData(adj_face_id[0]),
 			adj_face_id[1] == -1 ? NULL : r->getData(adj_face_id[1])
 		};
 
-		// TODO, all kinds of uglyness here
-
-		
-
 		if (no_adj) {
 			PtexEdgeIter iter(*face_data[0], adj_edge[0], side_res, false);
-			for (int j = 0; j < side_res; j++) {
-				assert(output.valid_pixel_index(dst_offset));
-				iter.read_texel(output.texels.data() + dst_offset);
-
-				dst_offset += x_inc[i] + y_inc[i];
-				iter.next();
-			}
+			iter.read_num_texels(output, side_res, &dst_offset, dst_incr);
 		}
 		else if (is_subface && !adj_info.isSubface()) {
 			PtexEdgeIter iter(*face_data[0], adj_edge[0], side_res * 2, true);
 			const bool is_primary = adj_info.adjface(adj_edge[0]) == face_id;
 			if (is_primary) {
-				for (int j = 0; j < side_res; j++) {
-					iter.next();
-				}
+				iter.step(side_res);
 			}
 
-			for (int j = 0; j < side_res; j++) {
-				assert(output.valid_pixel_index(dst_offset));
-				iter.read_texel(output.texels.data() + dst_offset);
-
-				dst_offset += x_inc[i] + y_inc[i];
-				iter.next();
-			}
+			iter.read_num_texels(output, side_res, &dst_offset, dst_incr);
 		}
 		else if (!is_subface && adj_info.isSubface()) {
 			const int half_side_res = side_res / 2;
 			for (int sf = 0; sf <= 1; sf++) {
 				PtexEdgeIter iter(*face_data[sf], adj_edge[sf],
 								  half_side_res, true);
-				for (int j = 0; j < half_side_res; j++) {
-					assert(output.valid_pixel_index(dst_offset));
-					iter.read_texel(output.texels.data() + dst_offset);
-
-					dst_offset += x_inc[i] + y_inc[i];
-					iter.next();
-				}
+				iter.read_num_texels(output, half_side_res, &dst_offset,
+									 dst_incr);
 			}
 		}
 		else {
 			PtexEdgeIter iter(*face_data[0], adj_edge[0], side_res, true);
-
-			for (int j = 0; j < side_res; j++) {
-				assert(output.valid_pixel_index(dst_offset));
-				iter.read_texel(output.texels.data() + dst_offset);
-
-				dst_offset += x_inc[i] + y_inc[i];
-				iter.next();
-			}
+			iter.read_num_texels(output, side_res, &dst_offset, dst_incr);
 		}
 	}
 }




More information about the Bf-blender-cvs mailing list