[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [40861] branches/soc-2011-onion-uv-tools/ source/blender/gpu/intern/gpu_draw.c: Long standing todo: Support tiled high resolution images.

Antony Riakiotakis kalast at gmail.com
Sun Oct 9 02:17:47 CEST 2011


Revision: 40861
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=40861
Author:   psy-fi
Date:     2011-10-09 00:17:47 +0000 (Sun, 09 Oct 2011)
Log Message:
-----------
Long standing todo: Support tiled high resolution images. Also added check for color correction so as to avoid converting the image if already in sRGB space.

Modified Paths:
--------------
    branches/soc-2011-onion-uv-tools/source/blender/gpu/intern/gpu_draw.c

Modified: branches/soc-2011-onion-uv-tools/source/blender/gpu/intern/gpu_draw.c
===================================================================
--- branches/soc-2011-onion-uv-tools/source/blender/gpu/intern/gpu_draw.c	2011-10-08 22:24:28 UTC (rev 40860)
+++ branches/soc-2011-onion-uv-tools/source/blender/gpu/intern/gpu_draw.c	2011-10-09 00:17:47 UTC (rev 40861)
@@ -429,7 +429,9 @@
 	int rectw, recth, tpx=0, tpy=0, y;
 	unsigned int *rectrow, *tilerectrow;
 	unsigned int *tilerect= NULL, *scalerect= NULL, *rect= NULL;
+	float *frectrow, *ftilerectrow, *ftilerect= NULL;
 	float *frect = NULL, *fscalerect = NULL;
+	float *color_corrected_frect = NULL;
 	short texwindx, texwindy, texwinsx, texwinsy;
 	/*flag to determine whether high resolution format is used*/
 	int useHighPrecisionTex = FALSE;
@@ -483,15 +485,14 @@
 		return 0;
 
 	if (ibuf->rect_float){
-		/*replace with user preference when ready :)*/
 		if(U.high_bit_depth_tex)
 		{
 			/*Use high precision textures. This is relatively harmless because OpenGL gives us
 			a high precision format only if it is available*/
 			useHighPrecisionTex = TRUE;
 		}
-		else if(ibuf->rect==NULL){
-		IMB_rect_from_float(ibuf);
+		if(ibuf->rect==NULL){
+			IMB_rect_from_float(ibuf);
 		}
 
 	}
@@ -528,29 +529,42 @@
 			tpx= texwindx;
 			tpy= texwindy;
 
-			rect= ibuf->rect + texwinsy*ibuf->x + texwinsx;
+			if(useHighPrecisionTex){
+				/* We may also need a color corrected float image. Dithering will not apply since it's high precision */
+				if(ibuf->profile == IB_PROFILE_LINEAR_RGB){
+					color_corrected_frect = MEM_mallocN(ibuf->x*ibuf->y*sizeof(float)*4, "floar_buf_col_cor");
+					IMB_float_color_corrected_from_float_rect(ibuf, color_corrected_frect);
+					frect= color_corrected_frect + texwinsy*ibuf->x + texwinsx;
+				}else{
+					frect= ibuf->rect_float + texwinsy*ibuf->x + texwinsx;
+				}
+			}else{
+				rect= ibuf->rect + texwinsy*ibuf->x + texwinsx;
+			}
 		}
 	}
 	else {
 		/* regular image mode */
 		bind= &ima->bindcode;
-		
+
 		if(*bind==0) {
 			tpx= ibuf->x;
 			tpy= ibuf->y;
 			rect= ibuf->rect;
 			if(useHighPrecisionTex){
-				/*We also need a color corrected float image*/
-				frect = MEM_mallocN(ibuf->x*ibuf->y*sizeof(float)*4, "floar_buf_col_cor");
-				IMB_float_color_corrected_from_float_rect(ibuf, frect);
+				/* We may also need a color corrected float image. Dithering will not apply since it's high precision */
+				if(ibuf->profile == IB_PROFILE_LINEAR_RGB){
+					frect = color_corrected_frect = MEM_mallocN(ibuf->x*ibuf->y*sizeof(float)*4, "floar_buf_col_cor");
+					IMB_float_color_corrected_from_float_rect(ibuf, color_corrected_frect);
+					frect= color_corrected_frect + texwinsy*ibuf->x + texwinsx;
+				}else{
+					frect= ibuf->rect_float;
+				}
+			}
 		}
 	}
-	}
 
 	if(*bind != 0) {
-		if(frect)
-			MEM_freeN(frect);
-
 		/* enable opengl drawing with textures */
 		glBindTexture(GL_TEXTURE_2D, *bind);
 		return *bind;
@@ -561,16 +575,29 @@
 
 	/* for tiles, copy only part of image into buffer */
 	if (GTS.tilemode) {
-		tilerect= MEM_mallocN(rectw*recth*sizeof(*tilerect), "tilerect");
+		if(useHighPrecisionTex){
+			ftilerect= MEM_mallocN(rectw*recth*sizeof(*ftilerect), "tilerect");
 
-		for (y=0; y<recth; y++) {
-			rectrow= &rect[y*ibuf->x];
-			tilerectrow= &tilerect[y*rectw];
-				
-			memcpy(tilerectrow, rectrow, tpx*sizeof(*rectrow));
+			for (y=0; y<recth; y++) {
+				frectrow= &frect[y*ibuf->x];
+				ftilerectrow= &ftilerect[y*rectw];
+
+				memcpy(ftilerectrow, frectrow, tpx*sizeof(*frectrow));
+			}
+
+			frect= ftilerect;
+		}else{
+			tilerect= MEM_mallocN(rectw*recth*sizeof(*tilerect), "tilerect");
+
+			for (y=0; y<recth; y++) {
+				rectrow= &rect[y*ibuf->x];
+				tilerectrow= &tilerect[y*rectw];
+
+				memcpy(tilerectrow, rectrow, tpx*sizeof(*rectrow));
+			}
+			
+			rect= tilerect;
 		}
-			
-		rect= tilerect;
 	}
 
 	/* scale if not a power of two. This is not strictly necessary for newer 
@@ -589,11 +616,11 @@
 		}
 		else
 		{
-		scalerect= MEM_mallocN(rectw*recth*sizeof(*scalerect), "scalerect");
-		gluScaleImage(GL_RGBA, tpx, tpy, GL_UNSIGNED_BYTE, rect, rectw, recth, GL_UNSIGNED_BYTE, scalerect);
-		rect= scalerect;
+			scalerect= MEM_mallocN(rectw*recth*sizeof(*scalerect), "scalerect");
+			gluScaleImage(GL_RGBA, tpx, tpy, GL_UNSIGNED_BYTE, rect, rectw, recth, GL_UNSIGNED_BYTE, scalerect);
+			rect= scalerect;
+		}
 	}
-	}
 
 	/* create image */
 	glGenTextures(1, (GLuint *)bind);
@@ -626,12 +653,14 @@
 	/* clean up */
 	if (tilerect)
 		MEM_freeN(tilerect);
+	if (ftilerect)
+			MEM_freeN(ftilerect);
 	if (scalerect)
 		MEM_freeN(scalerect);
 	if (fscalerect)
 		MEM_freeN(fscalerect);
-	if(frect)
-		MEM_freeN(frect);
+	if(color_corrected_frect)
+		MEM_freeN(color_corrected_frect);
 	return *bind;
 }
 




More information about the Bf-blender-cvs mailing list