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
This commit is contained in:
Sergey Sharybin 2013-04-12 10:52:47 +00:00
parent 677a96e189
commit 0d86c3f84c
5 changed files with 35 additions and 27 deletions

@ -482,8 +482,8 @@ class USERPREF_PT_system(Panel):
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()

@ -7764,14 +7764,8 @@ static void do_versions_userdef(FileData *fd, BlendFileData *bfd)
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 */

@ -708,17 +708,13 @@ void glaDrawPixelsSafe(float x, float y, int img_w, int img_h, int row_w, int fo
/* 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);
}
else {
glaDrawPixelsSafe(x, y, img_w, img_h, img_w, format, type, rect);
}
glaDrawPixelsSafe(x, y, img_w, img_h, img_w, format, type, rect);
}
/* 2D Drawing Assistance */
@ -1052,6 +1048,11 @@ void glaDrawImBuf_glsl(ImBuf *ibuf, float x, float y, int zoomfilter,
/* 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.

@ -452,7 +452,7 @@ typedef struct UserDef {
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 @@ typedef enum eMultiSample_Type {
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
}

@ -3374,6 +3374,14 @@ static void rna_def_userdef_system(BlenderRNA *brna)
};
#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 @@ static void rna_def_userdef_system(BlenderRNA *brna)
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",