[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55983] trunk/blender: Image draw method option

Sergey Sharybin sergey.vfx at gmail.com
Fri Apr 12 12:52:48 CEST 2013


Revision: 55983
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55983
Author:   nazgul
Date:     2013-04-12 10:52:47 +0000 (Fri, 12 Apr 2013)
Log Message:
-----------
Image draw method option

This option replaces previously added GPU limit
option, which became tricky to follow after GLSL
display space conversion.

There're 4 modes available:
- AUTO which will try to guess which mode is
  best to use.
  Currently It'll try using GLSL and if it fails,
  will fallback to 2D textures.
  Probably it'll make sense checking on whether
  2D textures works well but currently such behavior
  shall be sufficient.
  Later we could make this method smarter (for example
  don't try to use GLSL on certain GPU or so).
- GLSL will currently behave the same way as AUTO,
  but it is intended to always try using GLSL
  (unless it can not be used because of existing
  limitation of dither and RGB curves).
- 2D Textures will use CPU-based color space conversion
  and use OGL 2D Texture to display the image.
  Image will be displayed in tiles, so there shall be
  no big GPU memory consumption.
- DrawPixels will straightly fallback to glDrawPixels
  without trying to use any fancy GPU stuff.

Hopefully this will also fix
#34943: Blender crashes when resizing the Compositing Screen Window

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_ui/space_userpref.py
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/editors/screen/glutil.c
    trunk/blender/source/blender/makesdna/DNA_userdef_types.h
    trunk/blender/source/blender/makesrna/intern/rna_userdef.c

Modified: trunk/blender/release/scripts/startup/bl_ui/space_userpref.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/space_userpref.py	2013-04-12 10:19:31 UTC (rev 55982)
+++ trunk/blender/release/scripts/startup/bl_ui/space_userpref.py	2013-04-12 10:52:47 UTC (rev 55983)
@@ -482,8 +482,8 @@
 
         col.separator()
 
-        col.label(text="Images:")
-        col.prop(system, "image_gpubuffer_limit")
+        col.label(text="Images Draw Method:")
+        col.prop(system, "image_draw_method", text="")
 
         col.separator()
         col.separator()

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c	2013-04-12 10:19:31 UTC (rev 55982)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c	2013-04-12 10:52:47 UTC (rev 55983)
@@ -7764,14 +7764,8 @@
 			copy_v4_v4_char(btheme->tseq.grid, btheme->tseq.back);
 		}
 	}
-	
-	if (bmain->versionfile < 267) {
-	
-		if (!DNA_struct_elem_find(fd->filesdna, "UserDef", "short", "image_gpubuffer_limit"))
-			user->image_gpubuffer_limit = 20;
-		
-	}
 }
+
 static void do_versions(FileData *fd, Library *lib, Main *main)
 {
 	/* WATCH IT!!!: pointers from libdata have not been converted */

Modified: trunk/blender/source/blender/editors/screen/glutil.c
===================================================================
--- trunk/blender/source/blender/editors/screen/glutil.c	2013-04-12 10:19:31 UTC (rev 55982)
+++ trunk/blender/source/blender/editors/screen/glutil.c	2013-04-12 10:52:47 UTC (rev 55983)
@@ -708,17 +708,13 @@
 /* uses either DrawPixelsSafe or DrawPixelsTex, based on user defined maximum */
 void glaDrawPixelsAuto(float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect)
 {
-	if (U.image_gpubuffer_limit) {
-		/* Megapixels, use float math to prevent overflow */
-		float img_size = ((float)img_w * (float)img_h) / (1024.0f * 1024.0f);
-		
-		if (U.image_gpubuffer_limit > (int)img_size) {
-			glColor4f(1.0, 1.0, 1.0, 1.0);
-			glaDrawPixelsTex(x, y, img_w, img_h, format, type, zoomfilter, rect);
-			return;
-		}
+	if (U.image_draw_method != IMAGE_DRAW_METHOD_DRAWPIXELS) {
+		glColor4f(1.0, 1.0, 1.0, 1.0);
+		glaDrawPixelsTex(x, y, img_w, img_h, format, type, zoomfilter, rect);
 	}
-	glaDrawPixelsSafe(x, y, img_w, img_h, img_w, format, type, rect);
+	else {
+		glaDrawPixelsSafe(x, y, img_w, img_h, img_w, format, type, rect);
+	}
 }
 
 /* 2D Drawing Assistance */
@@ -1052,6 +1048,11 @@
 	/* Single channel images could not be transformed using GLSL yet */
 	force_fallback = ibuf->channels == 1;
 
+	/* If user decided not to use GLSL, fallback to glaDrawPixelsAuto */
+	force_fallback = !ELEM(U.image_draw_method,
+	                       IMAGE_DRAW_METHOD_AUTO,
+	                       IMAGE_DRAW_METHOD_GLSL);
+
 	/* This is actually lots of crap, but currently not sure about
 	 * more clear way to bypass partial buffer update crappyness
 	 * while rendering.

Modified: trunk/blender/source/blender/makesdna/DNA_userdef_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_userdef_types.h	2013-04-12 10:19:31 UTC (rev 55982)
+++ trunk/blender/source/blender/makesdna/DNA_userdef_types.h	2013-04-12 10:52:47 UTC (rev 55983)
@@ -452,7 +452,7 @@
 
 	short ogl_multisamples;	/* amount of samples for OpenGL FSA, if zero no FSA */
 
-	short image_gpubuffer_limit; /* If set, amount of mega-pixels to use for texture drawing of images */
+	short image_draw_method; /* Method to be used to draw the images (AUTO, GLSL, Textures or DrawPixels) */
 	
 	float glalphaclip;
 	
@@ -753,7 +753,12 @@
 	USER_MULTISAMPLE_16	= 16,
 } eMultiSample_Type;
 	
-	
+typedef enum eImageDrawMethod {
+	IMAGE_DRAW_METHOD_AUTO = 0,
+	IMAGE_DRAW_METHOD_GLSL = 1,
+	IMAGE_DRAW_METHOD_2DTEXTURE = 2,
+	IMAGE_DRAW_METHOD_DRAWPIXELS = 3,
+} eImageDrawMethod;
 
 #ifdef __cplusplus
 }

Modified: trunk/blender/source/blender/makesrna/intern/rna_userdef.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_userdef.c	2013-04-12 10:19:31 UTC (rev 55982)
+++ trunk/blender/source/blender/makesrna/intern/rna_userdef.c	2013-04-12 10:52:47 UTC (rev 55983)
@@ -3374,6 +3374,14 @@
 	};
 #endif
 
+	static EnumPropertyItem image_draw_methods[] = {
+		{IMAGE_DRAW_METHOD_AUTO, "AUTO", 0, "Auto", "Try to detect best drawing method automatically"},
+		{IMAGE_DRAW_METHOD_GLSL, "GLSL", 0, "GLSL", "Use GLSL shaders for display transform and draw image with 2D texture"},
+		{IMAGE_DRAW_METHOD_2DTEXTURE, "2DTEXTURE", 0, "2D Texture", "Use CPU for display transform and draw image with 2D texture"},
+		{IMAGE_DRAW_METHOD_DRAWPIXELS, "DRAWPIXELS", 0, "DrawPixels", "Use CPU for display transform and draw image using DrawPixels"},
+		{0, NULL, 0, NULL, NULL}
+	};
+
 	srna = RNA_def_struct(brna, "UserPreferencesSystem", NULL);
 	RNA_def_struct_sdna(srna, "UserDef");
 	RNA_def_struct_nested(brna, srna, "UserPreferences");
@@ -3518,12 +3526,12 @@
 	RNA_def_property_ui_text(prop, "GPU Mipmap Generation", "Generate Image Mipmaps on the GPU");
 	RNA_def_property_update(prop, 0, "rna_userdef_gl_gpu_mipmaps");
 
-	prop = RNA_def_property(srna, "image_gpubuffer_limit", PROP_INT, PROP_NONE);
-	RNA_def_property_int_sdna(prop, NULL, "image_gpubuffer_limit");
-	RNA_def_property_range(prop, 0, 128);
-	RNA_def_property_ui_text(prop, "Image GPU draw limit", "If set, amount of Mega Pixels to use for drawing Images as GPU textures");
-	
-	
+	prop = RNA_def_property(srna, "image_draw_method", PROP_ENUM, PROP_NONE);
+	RNA_def_property_enum_items(prop, image_draw_methods);
+	RNA_def_property_enum_sdna(prop, NULL, "image_draw_method");
+	RNA_def_property_ui_text(prop, "Image Draw Method", "Method used for displaying images on the screen");
+	RNA_def_property_update(prop, 0, "rna_userdef_update");
+
 	prop = RNA_def_property(srna, "use_vertex_buffer_objects", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_negative_sdna(prop, NULL, "gameflags", USER_DISABLE_VBO);
 	RNA_def_property_ui_text(prop, "VBOs",




More information about the Bf-blender-cvs mailing list