[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [46955] branches/soc-2012-swiss_cheese/ source/blender: PixelStore Policy

Jason Wilkins Jason.A.Wilkins at gmail.com
Thu May 24 00:13:19 CEST 2012


Revision: 46955
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=46955
Author:   jwilkins
Date:     2012-05-23 22:13:18 +0000 (Wed, 23 May 2012)
Log Message:
-----------
PixelStore Policy

The way Blender uses PixelStore the best policy seems to be to assume that the values are set to their defaults (Do not call PixelStore if you do not have to) and restore the default value for anything that was changed after completing the store operation.

Modified Paths:
--------------
    branches/soc-2012-swiss_cheese/source/blender/editors/screen/glutil.c
    branches/soc-2012-swiss_cheese/source/blender/editors/space_image/image_draw.c
    branches/soc-2012-swiss_cheese/source/blender/editors/space_node/drawnode.c
    branches/soc-2012-swiss_cheese/source/blender/editors/space_view3d/drawarmature.c
    branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_draw.c

Modified: branches/soc-2012-swiss_cheese/source/blender/editors/screen/glutil.c
===================================================================
--- branches/soc-2012-swiss_cheese/source/blender/editors/screen/glutil.c	2012-05-23 21:39:39 UTC (rev 46954)
+++ branches/soc-2012-swiss_cheese/source/blender/editors/screen/glutil.c	2012-05-23 22:13:18 UTC (rev 46955)
@@ -483,7 +483,6 @@
 	float *f_rect = (float *)rect;
 	float xzoom = glaGetOneFloat(GL_ZOOM_X), yzoom = glaGetOneFloat(GL_ZOOM_Y);
 	int ltexid = glaGetOneInteger(GL_TEXTURE_2D);
-	int lrowlength = glaGetOneInteger(GL_UNPACK_ROW_LENGTH);
 	int subpart_x, subpart_y, tex_w, tex_h;
 	int seamless, offset_x, offset_y, nsubparts_x, nsubparts_y;
 	int texid = get_cached_work_texture(&tex_w, &tex_h);
@@ -492,6 +491,7 @@
 	 * This is useful for changing alpha without using glPixelTransferf()
 	 */
 	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+
 	glPixelStorei(GL_UNPACK_ROW_LENGTH, img_w);
 	glBindTexture(GL_TEXTURE_2D, texid);
 
@@ -571,7 +571,7 @@
 	}
 
 	glBindTexture(GL_TEXTURE_2D, ltexid);
-	glPixelStorei(GL_UNPACK_ROW_LENGTH, lrowlength);
+	glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); /* restore default value */
 	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 	
 #ifdef __APPLE__
@@ -628,8 +628,6 @@
 	draw_h = MIN2(img_h - off_y, ceil((scissor[3] - rast_y) / yzoom));
 
 	if (draw_w > 0 && draw_h > 0) {
-		int old_row_length = glaGetOneInteger(GL_UNPACK_ROW_LENGTH);
-
 		/* Don't use safe RasterPos (slower) if we can avoid it. */
 		if (rast_x >= 0 && rast_y >= 0) {
 			glRasterPos2f(rast_x, rast_y);
@@ -638,7 +636,10 @@
 			glaRasterPosSafe2f(rast_x, rast_y, 0, 0);
 		}
 
-		glPixelStorei(GL_UNPACK_ROW_LENGTH, row_w);
+		if (img_w != row_w) {
+			glPixelStorei(GL_UNPACK_ROW_LENGTH, row_w);
+		}
+
 		if (format == GL_LUMINANCE || format == GL_RED) {
 			if (type == GL_FLOAT) {
 				float *f_rect = (float *)rect;
@@ -659,8 +660,10 @@
 				glDrawPixels(draw_w, draw_h, format, type, uc_rect + (off_y * row_w + off_x) * 4);
 			}
 		}
-		
-		glPixelStorei(GL_UNPACK_ROW_LENGTH,  old_row_length);
+
+		if (img_w != row_w) {
+			glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); /* restore default value */
+		}
 	}
 }
 

Modified: branches/soc-2012-swiss_cheese/source/blender/editors/space_image/image_draw.c
===================================================================
--- branches/soc-2012-swiss_cheese/source/blender/editors/space_image/image_draw.c	2012-05-23 21:39:39 UTC (rev 46954)
+++ branches/soc-2012-swiss_cheese/source/blender/editors/space_image/image_draw.c	2012-05-23 22:13:18 UTC (rev 46955)
@@ -336,13 +336,17 @@
 
 static void sima_draw_alpha_pixels(float x1, float y1, int rectx, int recty, unsigned int *recti)
 {
-	
 	/* swap bytes, so alpha is most significant one, then just draw it as luminance int */
-	if (ENDIAN_ORDER == B_ENDIAN)
-		glPixelStorei(GL_UNPACK_SWAP_BYTES, 1);
 
+#if ENDIAN_ORDER == B_ENDIAN
+	glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_TRUE);
+#endif
+
 	glaDrawPixelsSafe(x1, y1, rectx, recty, rectx, GL_LUMINANCE, GL_UNSIGNED_INT, recti);
-	glPixelStorei(GL_UNPACK_SWAP_BYTES, 0);
+
+#if ENDIAN_ORDER == B_ENDIAN
+	glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); /* restore default value */
+#endif
 }
 
 static void sima_draw_alpha_pixelsf(float x1, float y1, int rectx, int recty, float *rectf)

Modified: branches/soc-2012-swiss_cheese/source/blender/editors/space_node/drawnode.c
===================================================================
--- branches/soc-2012-swiss_cheese/source/blender/editors/space_node/drawnode.c	2012-05-23 21:39:39 UTC (rev 46954)
+++ branches/soc-2012-swiss_cheese/source/blender/editors/space_node/drawnode.c	2012-05-23 22:13:18 UTC (rev 46955)
@@ -2682,13 +2682,17 @@
 			if (ibuf->rect) {
 				if (snode->flag & SNODE_SHOW_ALPHA) {
 					glPixelZoom(snode->zoom, snode->zoom);
+
 					/* swap bytes, so alpha is most significant one, then just draw it as luminance int */
-					if (ENDIAN_ORDER == B_ENDIAN)
-						glPixelStorei(GL_UNPACK_SWAP_BYTES, 1);
-					
+
+#if ENDIAN_ORDER == B_ENDIAN
+					glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_TRUE);
+#endif
 					glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_LUMINANCE, GL_UNSIGNED_INT, ibuf->rect);
-					
-					glPixelStorei(GL_UNPACK_SWAP_BYTES, 0);
+
+#if ENDIAN_ORDER == B_ENDIAN
+					glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); /* restore default value */
+#endif
 					glPixelZoom(1.0f, 1.0f);
 				}
 				else if (snode->flag & SNODE_USE_ALPHA) {

Modified: branches/soc-2012-swiss_cheese/source/blender/editors/space_view3d/drawarmature.c
===================================================================
--- branches/soc-2012-swiss_cheese/source/blender/editors/space_view3d/drawarmature.c	2012-05-23 21:39:39 UTC (rev 46954)
+++ branches/soc-2012-swiss_cheese/source/blender/editors/space_view3d/drawarmature.c	2012-05-23 22:13:18 UTC (rev 46955)
@@ -1098,6 +1098,8 @@
 	glLineWidth(1.0);
 	
 	glPopMatrix();
+
+	glPixelStorei(GL_UNPACK_ALIGNMENT, 4); /* restore default value */
 }
 
 static void draw_b_bone_boxes(int dt, bPoseChannel *pchan, float xwidth, float length, float zwidth)

Modified: branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_draw.c
===================================================================
--- branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_draw.c	2012-05-23 21:39:39 UTC (rev 46954)
+++ branches/soc-2012-swiss_cheese/source/blender/gpu/intern/gpu_draw.c	2012-05-23 22:13:18 UTC (rev 46955)
@@ -774,12 +774,7 @@
 	else {
 		/* for the special case, we can do a partial update
 		 * which is much quicker for painting */
-		GLint row_length, skip_pixels, skip_rows;
 
-		glGetIntegerv(GL_UNPACK_ROW_LENGTH, &row_length);
-		glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &skip_pixels);
-		glGetIntegerv(GL_UNPACK_SKIP_ROWS, &skip_rows);
-
 		/* if color correction is needed, we must update the part that needs updating. */
 		if (ibuf->rect_float && (!U.use_16bit_textures || (ibuf->profile == IB_PROFILE_LINEAR_RGB))) {
 			float *buffer = MEM_mallocN(w*h*sizeof(float)*4, "temp_texpaint_float_buf");
@@ -799,10 +794,15 @@
 		
 		glBindTexture(GL_TEXTURE_2D, ima->bindcode);
 
-		glPixelStorei(GL_UNPACK_ROW_LENGTH, ibuf->x);
-		glPixelStorei(GL_UNPACK_SKIP_PIXELS, x);
-		glPixelStorei(GL_UNPACK_SKIP_ROWS, y);
+		if (ibuf->x != 0)
+			glPixelStorei(GL_UNPACK_ROW_LENGTH,  ibuf->x);
 
+		if (x != 0)
+			glPixelStorei(GL_UNPACK_SKIP_PIXELS, x);
+
+		if (y != 0)
+			glPixelStorei(GL_UNPACK_SKIP_ROWS,   y);
+
 		if (ibuf->rect_float)
 			glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, GL_RGBA,
 				GL_FLOAT, ibuf->rect_float);
@@ -810,10 +810,15 @@
 			glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, GL_RGBA,
 				GL_UNSIGNED_BYTE, ibuf->rect);
 
-		glPixelStorei(GL_UNPACK_ROW_LENGTH, row_length);
-		glPixelStorei(GL_UNPACK_SKIP_PIXELS, skip_pixels);
-		glPixelStorei(GL_UNPACK_SKIP_ROWS, skip_rows);
+		if (ibuf->x != 0)
+			glPixelStorei(GL_UNPACK_ROW_LENGTH,  0); /* restore default value */
 
+		if (x != 0)
+			glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); /* restore default value */
+
+		if (y != 0)
+			glPixelStorei(GL_UNPACK_SKIP_ROWS,   0); /* restore default value */
+
 		if (ima->tpageflag & IMA_MIPMAP_COMPLETE)
 			ima->tpageflag &= ~IMA_MIPMAP_COMPLETE;
 	}




More information about the Bf-blender-cvs mailing list