Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@gmail.com>2019-04-20 13:47:06 +0300
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2019-04-20 14:32:36 +0300
commit7cbb8f20a4b479380dac1d2a2f7c7f85ede408be (patch)
tree3c5b5a91f2cdc2eb285cfa41886053366337ff11 /source/blender/editors
parented0c9654ddfdcbe19d8094d4b4a43f0f06d9ee5c (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')
-rw-r--r--source/blender/editors/include/BIF_glutil.h2
-rw-r--r--source/blender/editors/render/render_internal.c4
-rw-r--r--source/blender/editors/screen/glutil.c18
-rw-r--r--source/blender/editors/space_sequencer/sequencer_draw.c4
4 files changed, 25 insertions, 3 deletions
diff --git a/source/blender/editors/include/BIF_glutil.h b/source/blender/editors/include/BIF_glutil.h
index c30674907da..c88277c2ea5 100644
--- a/source/blender/editors/include/BIF_glutil.h
+++ b/source/blender/editors/include/BIF_glutil.h
@@ -167,6 +167,8 @@ void ED_draw_imbuf_ctx_clipping(const struct bContext *C,
float zoom_x,
float zoom_y);
+int ED_draw_imbuf_method(struct ImBuf *ibuf);
+
/* OpenGL drawing utility functions. Do not use these in new code, these
* are intended to be moved or removed in the future. */
diff --git a/source/blender/editors/render/render_internal.c b/source/blender/editors/render/render_internal.c
index 6df1ba5e0aa..d9a68a060f8 100644
--- a/source/blender/editors/render/render_internal.c
+++ b/source/blender/editors/render/render_internal.c
@@ -72,6 +72,8 @@
#include "ED_undo.h"
#include "ED_view3d.h"
+#include "BIF_glutil.h"
+
#include "RE_pipeline.h"
#include "RE_engine.h"
@@ -607,7 +609,7 @@ static void image_rect_update(void *rjv, RenderResult *rr, volatile rcti *renrec
* operate with.
*/
if (rr->do_exr_tile || !rj->supports_glsl_draw || ibuf->channels == 1 ||
- U.image_draw_method != IMAGE_DRAW_METHOD_GLSL) {
+ ED_draw_imbuf_method(ibuf) != IMAGE_DRAW_METHOD_GLSL) {
image_buffer_rect_update(rj, rr, ibuf, &rj->iuser, renrect, viewname);
}
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)
diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c
index 5842d3b9c0d..69fc9ef3e17 100644
--- a/source/blender/editors/space_sequencer/sequencer_draw.c
+++ b/source/blender/editors/space_sequencer/sequencer_draw.c
@@ -62,6 +62,8 @@
#include "ED_screen.h"
#include "ED_space_api.h"
+#include "BIF_glutil.h"
+
#include "UI_interface.h"
#include "UI_resources.h"
#include "UI_view2d.h"
@@ -1226,7 +1228,7 @@ static void *sequencer_OCIO_transform_ibuf(
void *cache_handle = NULL;
bool force_fallback = false;
*glsl_used = false;
- force_fallback |= (U.image_draw_method != IMAGE_DRAW_METHOD_GLSL);
+ force_fallback |= (ED_draw_imbuf_method(ibuf) != IMAGE_DRAW_METHOD_GLSL);
force_fallback |= (ibuf->dither != 0.0f);
if (force_fallback) {