diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2019-04-20 13:47:06 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2019-04-20 14:32:36 +0300 |
commit | 7cbb8f20a4b479380dac1d2a2f7c7f85ede408be (patch) | |
tree | 3c5b5a91f2cdc2eb285cfa41886053366337ff11 /source/blender/editors/screen | |
parent | ed0c9654ddfdcbe19d8094d4b4a43f0f06d9ee5c (diff) |
GPU: automatically draw images with GLSL shader depending on resolution
This adds a new "Automatic" image display method which uses GLSL shaders for
most images. It only does CPU side color management for higher res images
where sending big float buffers to the GPU is likely to be a bottleneck or
cause memory usage problem.
Automatic is the default now, previously it was 2D Texture.
Diffstat (limited to 'source/blender/editors/screen')
-rw-r--r-- | source/blender/editors/screen/glutil.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/source/blender/editors/screen/glutil.c b/source/blender/editors/screen/glutil.c index 868bc982c51..c22d9d66251 100644 --- a/source/blender/editors/screen/glutil.c +++ b/source/blender/editors/screen/glutil.c @@ -557,7 +557,7 @@ void ED_draw_imbuf_clipping(ImBuf *ibuf, force_fallback |= ibuf->channels == 1; /* If user decided not to use GLSL, fallback to glaDrawPixelsAuto */ - force_fallback |= (U.image_draw_method != IMAGE_DRAW_METHOD_GLSL); + force_fallback |= (ED_draw_imbuf_method(ibuf) != IMAGE_DRAW_METHOD_GLSL); /* Try to draw buffer using GLSL display transform */ if (force_fallback == false) { @@ -731,6 +731,22 @@ void ED_draw_imbuf_ctx( ED_draw_imbuf_ctx_clipping(C, ibuf, x, y, zoomfilter, 0.0f, 0.0f, 0.0f, 0.0f, zoom_x, zoom_y); } +int ED_draw_imbuf_method(ImBuf *ibuf) +{ + if (U.image_draw_method == IMAGE_DRAW_METHOD_AUTO) { + /* Use faster GLSL when CPU to GPU transfer is unlikely to be a bottleneck, + * otherwise do color management on CPU side. */ + const size_t threshold = 2048 * 2048 * 4 * sizeof(float); + const size_t data_size = (ibuf->rect_float) ? sizeof(float) : sizeof(uchar); + const size_t size = ibuf->x * ibuf->y * ibuf->channels * data_size; + + return (size > threshold) ? IMAGE_DRAW_METHOD_2DTEXTURE : IMAGE_DRAW_METHOD_GLSL; + } + else { + return U.image_draw_method; + } +} + /* don't move to GPU_immediate_util.h because this uses user-prefs * and isn't very low level */ void immDrawBorderCorners(unsigned int pos, const rcti *border, float zoomx, float zoomy) |