[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16461] trunk/blender/source/blender:

Brecht Van Lommel brechtvanlommel at pandora.be
Wed Sep 10 15:03:00 CEST 2008


Revision: 16461
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16461
Author:   blendix
Date:     2008-09-10 15:02:58 +0200 (Wed, 10 Sep 2008)

Log Message:
-----------

Fix for bug #8132: on Mac OS X 10.5 with Nvidia cards drawing
background images and node previews goes wrong. The exact cause
of that is not sure, may be a driver bug, workaround is to fall
back to another slower function.

Modified Paths:
--------------
    trunk/blender/source/blender/include/BIF_glutil.h
    trunk/blender/source/blender/src/glutil.c
    trunk/blender/source/blender/src/mywindow.c

Modified: trunk/blender/source/blender/include/BIF_glutil.h
===================================================================
--- trunk/blender/source/blender/include/BIF_glutil.h	2008-09-10 12:04:20 UTC (rev 16460)
+++ trunk/blender/source/blender/include/BIF_glutil.h	2008-09-10 13:02:58 UTC (rev 16461)
@@ -204,6 +204,7 @@
 /* intel gfx cards frontbuffer problem */
 void bglFlush(void);
 int is_a_really_crappy_intel_card(void);
+int is_a_really_crappy_nvidia_card(void);
 void set_inverted_drawing(int enable);
 
 

Modified: trunk/blender/source/blender/src/glutil.c
===================================================================
--- trunk/blender/source/blender/src/glutil.c	2008-09-10 12:04:20 UTC (rev 16460)
+++ trunk/blender/source/blender/src/glutil.c	2008-09-10 13:02:58 UTC (rev 16461)
@@ -290,18 +290,67 @@
 	return texid;
 }
 
+#define FTOCHAR(val) val<=0.0f?0: (val>=1.0f?255: (char)(255.0f*val))
 void glaDrawPixelsTex(float x, float y, int img_w, int img_h, int format, void *rect)
 {
-	unsigned char *uc_rect= (unsigned char*) rect;
-	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 texid= get_cached_work_texture(&tex_w, &tex_h);
-	int nsubparts_x= (img_w+(tex_w-1))/tex_w;
-	int nsubparts_y= (img_h+(tex_h-1))/tex_h;
+	float *f_rect;
+	float xzoom, yzoom;
+	unsigned char *uc_rect;
+	int ltexid, lrowlength, texid, tex_w, tex_h;
+	int subpart_x, subpart_y, nsubparts_x, nsubparts_y;
 
+	uc_rect= (unsigned char*) rect;
+	f_rect= (float *)rect;
+
+#ifdef __APPLE__
+	/* On Nvidia, Mac OS X 10.5 this function doesn't work correct and
+	 * can crash even, use glDrawPixels instead of textures then */
+	if(is_a_really_crappy_nvidia_card()) {
+		float col[4], modcol[4];
+		unsigned char *srect = rect;
+		int a;
+
+		/* modulate with current color */
+		glGetFloatv(GL_CURRENT_COLOR, col);
+		if(col[0]!=1.0f || col[1]!=1.0f ||col[2]!=1.0f ||col[3]!=1.0f) {
+			srect = MEM_callocN(4*img_w*img_h, "glDrawPixelsTexSafe");
+			for(a=0; a<img_w*img_h*4; a+=4) {
+				if(format == GL_FLOAT) {
+					modcol[0]= col[0]*f_rect[a];
+					modcol[1]= col[1]*f_rect[a+1];
+					modcol[2]= col[2]*f_rect[a+2];
+					modcol[3]= col[3]*f_rect[a+3];
+				}
+				else {
+					modcol[0]= col[0]*uc_rect[a]*(1.0f/255.0f);
+					modcol[1]= col[1]*uc_rect[a+1]*(1.0f/255.0f);
+					modcol[2]= col[2]*uc_rect[a+2]*(1.0f/255.0f);
+					modcol[3]= col[3]*uc_rect[a+3]*(1.0f/255.0f);
+				}
+
+				srect[a]= FTOCHAR(modcol[0]);
+				srect[a+1]= FTOCHAR(modcol[1]);
+				srect[a+2]= FTOCHAR(modcol[2]);
+				srect[a+3]= FTOCHAR(modcol[3]);
+			}
+		}
+
+		glaDrawPixelsSafe(x, y, img_w, img_h, img_w, GL_RGBA, format, srect);
+
+		if(srect != rect)
+			MEM_freeN(srect);
+
+		return;
+	}
+#endif
+
+	xzoom= glaGetOneFloat(GL_ZOOM_X), yzoom= glaGetOneFloat(GL_ZOOM_Y);
+	ltexid= glaGetOneInteger(GL_TEXTURE_2D);
+	lrowlength= glaGetOneInteger(GL_UNPACK_ROW_LENGTH);
+	texid= get_cached_work_texture(&tex_w, &tex_h);
+	nsubparts_x= (img_w+(tex_w-1))/tex_w;
+	nsubparts_y= (img_h+(tex_h-1))/tex_h;
+
 	/* Specify the color outside this function, and tex will modulate it.
 	 * This is useful for changing alpha without using glPixelTransferf()
 	 */
@@ -348,7 +397,6 @@
 	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
 }
 
-#define FTOCHAR(val) val<=0.0f?0: (val>=1.0f?255: (char)(255.0f*val))
 void glaDrawPixelsSafe_to32(float fx, float fy, int img_w, int img_h, int row_w, float *rectf)
 {
 	float *rf;
@@ -717,6 +765,17 @@
 	return well_is_it;
 }
 
+int is_a_really_crappy_nvidia_card(void)
+{
+	static int well_is_it= -1;
+
+	/* Do you understand the implication? Do you? */
+	if (well_is_it==-1)
+		well_is_it= (strcmp((char*) glGetString(GL_VENDOR), "NVIDIA Corporation") == 0);
+
+	return well_is_it;
+}
+
 void bglFlush(void) 
 {
 	glFlush();

Modified: trunk/blender/source/blender/src/mywindow.c
===================================================================
--- trunk/blender/source/blender/src/mywindow.c	2008-09-10 12:04:20 UTC (rev 16460)
+++ trunk/blender/source/blender/src/mywindow.c	2008-09-10 13:02:58 UTC (rev 16461)
@@ -604,18 +604,6 @@
 
 /* ********** END MY WINDOW ************** */
 
-#ifdef WIN32
-static int is_a_really_crappy_nvidia_card(void) {
-	static int well_is_it= -1;
-
-		/* Do you understand the implication? Do you? */
-	if (well_is_it==-1)
-		well_is_it= (strcmp((char*) glGetString(GL_VENDOR), "NVIDIA Corporation") == 0);
-
-	return well_is_it;
-}
-#endif
-
 void myswapbuffers(void)
 {
 	ScrArea *sa;





More information about the Bf-blender-cvs mailing list