diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-04-04 16:20:13 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2013-04-04 16:20:13 +0400 |
commit | c1b704a11aac13190054f42f2cd21a51c9132758 (patch) | |
tree | e306190d5ee56a621a2f20606b1b864000ad57b6 /source/blender/editors | |
parent | f6add59e912f0496d9cf7a41af8ce6917e7b62d8 (diff) |
Use GLSL display for compositor backdrop and sequencer preview
Now only background images remained to be ported. Plus implement
GLSL for dithering and RGB curves.
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/include/BIF_glutil.h | 7 | ||||
-rw-r--r-- | source/blender/editors/screen/glutil.c | 33 | ||||
-rw-r--r-- | source/blender/editors/space_node/drawnode.c | 21 | ||||
-rw-r--r-- | source/blender/editors/space_sequencer/sequencer_draw.c | 48 |
4 files changed, 91 insertions, 18 deletions
diff --git a/source/blender/editors/include/BIF_glutil.h b/source/blender/editors/include/BIF_glutil.h index af2dc884508..dfb02fa9c1b 100644 --- a/source/blender/editors/include/BIF_glutil.h +++ b/source/blender/editors/include/BIF_glutil.h @@ -35,6 +35,8 @@ struct rctf; struct ImBuf; struct bContext; +struct ColorManagedViewSettings; +struct ColorManagedDisplaySettings; void fdrawbezier(float vec[4][3]); void fdrawline(float x1, float y1, float x2, float y2); @@ -213,6 +215,11 @@ void bgl_get_mats(bglMats *mats); /* **** Color management helper functions for GLSL display/transform ***** */ /* Draw imbuf on a screen, preferably using GLSL display transform */ +void glaDrawImBuf_glsl(struct ImBuf *ibuf, float x, float y, int zoomfilter, + struct ColorManagedViewSettings *view_settings, + struct ColorManagedDisplaySettings *display_settings); + +/* Draw imbuf on a screen, preferably using GLSL display transform */ void glaDrawImBuf_glsl_ctx(const struct bContext *C, struct ImBuf *ibuf, float x, float y, int zoomfilter); /* Transform buffer from role to scene linear space using GLSL OCIO conversion */ diff --git a/source/blender/editors/screen/glutil.c b/source/blender/editors/screen/glutil.c index 3469604b3dd..ac8f44a3ab1 100644 --- a/source/blender/editors/screen/glutil.c +++ b/source/blender/editors/screen/glutil.c @@ -1028,7 +1028,9 @@ void bglFlush(void) /* **** Color management helper functions for GLSL display/transform ***** */ /* Draw given image buffer on a screen using GLSL for display transform */ -void glaDrawImBuf_glsl_ctx(const bContext *C, ImBuf *ibuf, float x, float y, int zoomfilter) +void glaDrawImBuf_glsl(ImBuf *ibuf, float x, float y, int zoomfilter, + ColorManagedViewSettings *view_settings, + ColorManagedDisplaySettings *display_settings) { bool force_fallback = false; bool need_fallback = true; @@ -1080,10 +1082,19 @@ void glaDrawImBuf_glsl_ctx(const bContext *C, ImBuf *ibuf, float x, float y, int if (force_fallback == false) { int ok; - if (ibuf->rect_float) - ok = IMB_colormanagement_setup_glsl_draw_ctx(C, TRUE); - else - ok = IMB_colormanagement_setup_glsl_draw_from_space_ctx(C, ibuf->rect_colorspace, FALSE); + if (ibuf->rect_float) { + if (ibuf->float_colorspace) { + ok = IMB_colormanagement_setup_glsl_draw_from_space(view_settings, display_settings, + ibuf->float_colorspace, TRUE); + } + else { + ok = IMB_colormanagement_setup_glsl_draw(view_settings, display_settings, TRUE); + } + } + else { + ok = IMB_colormanagement_setup_glsl_draw_from_space(view_settings, display_settings, + ibuf->rect_colorspace, FALSE); + } if (ok) { glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); @@ -1121,7 +1132,7 @@ void glaDrawImBuf_glsl_ctx(const bContext *C, ImBuf *ibuf, float x, float y, int unsigned char *display_buffer; void *cache_handle; - display_buffer = IMB_display_buffer_acquire_ctx(C, ibuf, &cache_handle); + display_buffer = IMB_display_buffer_acquire(ibuf, view_settings, display_settings, &cache_handle); if (display_buffer) glaDrawPixelsAuto(x, y, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, @@ -1131,6 +1142,16 @@ void glaDrawImBuf_glsl_ctx(const bContext *C, ImBuf *ibuf, float x, float y, int } } +void glaDrawImBuf_glsl_ctx(const bContext *C, ImBuf *ibuf, float x, float y, int zoomfilter) +{ + ColorManagedViewSettings *view_settings; + ColorManagedDisplaySettings *display_settings; + + IMB_colormanagement_display_settings_from_ctx(C, &view_settings, &display_settings); + + glaDrawImBuf_glsl(ibuf, x, y, zoomfilter, view_settings, display_settings); +} + /* Transform buffer from role to scene linear space using GLSL OCIO conversion * * See IMB_colormanagement_setup_transform_from_role_glsl description for diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c index d7206c9b111..cd3de834e78 100644 --- a/source/blender/editors/space_node/drawnode.c +++ b/source/blender/editors/space_node/drawnode.c @@ -2948,8 +2948,6 @@ void draw_nodespace_back_pix(const bContext *C, ARegion *ar, SpaceNode *snode) ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock); if (ibuf) { float x, y; - unsigned char *display_buffer; - void *cache_handle; glMatrixMode(GL_PROJECTION); glPushMatrix(); @@ -2967,14 +2965,16 @@ void draw_nodespace_back_pix(const bContext *C, ARegion *ar, SpaceNode *snode) x = (ar->winx - snode->zoom * ibuf->x) / 2 + snode->xof; y = (ar->winy - snode->zoom * ibuf->y) / 2 + snode->yof; - - display_buffer = IMB_display_buffer_acquire_ctx(C, ibuf, &cache_handle); + if (ibuf->rect || ibuf->rect_float) { + unsigned char *display_buffer = NULL; + void *cache_handle = NULL; - if (display_buffer) { if (snode->flag & (SNODE_SHOW_R | SNODE_SHOW_G | SNODE_SHOW_B)) { int ofs; + display_buffer = IMB_display_buffer_acquire_ctx(C, ibuf, &cache_handle); + #ifdef __BIG_ENDIAN__ if (snode->flag & SNODE_SHOW_R) ofs = 2; else if (snode->flag & SNODE_SHOW_G) ofs = 1; @@ -2994,6 +2994,8 @@ void draw_nodespace_back_pix(const bContext *C, ARegion *ar, SpaceNode *snode) glPixelZoom(1.0f, 1.0f); } else if (snode->flag & SNODE_SHOW_ALPHA) { + display_buffer = IMB_display_buffer_acquire_ctx(C, ibuf, &cache_handle); + glPixelZoom(snode->zoom, snode->zoom); /* swap bytes, so alpha is most significant one, then just draw it as luminance int */ #ifdef __BIG_ENDIAN__ @@ -3011,7 +3013,7 @@ void draw_nodespace_back_pix(const bContext *C, ARegion *ar, SpaceNode *snode) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glPixelZoom(snode->zoom, snode->zoom); - glaDrawPixelsAuto(x, y, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, display_buffer); + glaDrawImBuf_glsl_ctx(C, ibuf, x, y, GL_NEAREST); glPixelZoom(1.0f, 1.0f); glDisable(GL_BLEND); @@ -3019,13 +3021,14 @@ void draw_nodespace_back_pix(const bContext *C, ARegion *ar, SpaceNode *snode) else { glPixelZoom(snode->zoom, snode->zoom); - glaDrawPixelsAuto(x, y, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, display_buffer); + glaDrawImBuf_glsl_ctx(C, ibuf, x, y, GL_NEAREST); glPixelZoom(1.0f, 1.0f); } - } - IMB_display_buffer_release(cache_handle); + if (cache_handle) + IMB_display_buffer_release(cache_handle); + } /** @note draw selected info on backdrop */ if (snode->edittree) { diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c index 141af5d5ba4..3a7610cbf2a 100644 --- a/source/blender/editors/space_sequencer/sequencer_draw.c +++ b/source/blender/editors/space_sequencer/sequencer_draw.c @@ -920,9 +920,11 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq float col[3]; GLuint texid; GLuint last_texid; - unsigned char *display_buffer; + void *display_buffer; void *cache_handle = NULL; const int is_imbuf = ED_space_sequencer_check_show_imbuf(sseq); + int format, type; + bool glsl_used = false; if (G.is_rendering == FALSE && (scene->r.seq_flag & R_SEQ_GL_PREV) == 0) { /* stop all running jobs, except screen one. currently previews frustrate Render @@ -1040,9 +1042,46 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq } display_buffer = (unsigned char *)ibuf->rect; + format = GL_RGBA; + type = GL_UNSIGNED_BYTE; } else { - display_buffer = IMB_display_buffer_acquire_ctx(C, ibuf, &cache_handle); + if (ibuf->rect_float) { + display_buffer = ibuf->rect_float; + + if (ibuf->channels == 4) { + format = GL_RGBA; + } + else if (ibuf->channels == 3) { + format = GL_RGB; + } + else { + BLI_assert(!"Incompatible number of channels for float buffer in sequencer"); + format = GL_RGBA; + display_buffer = NULL; + } + + type = GL_FLOAT; + + if (ibuf->float_colorspace) { + glsl_used = IMB_colormanagement_setup_glsl_draw_from_space_ctx(C, ibuf->float_colorspace, TRUE); + } + else { + glsl_used = IMB_colormanagement_setup_glsl_draw_ctx(C, TRUE); + } + } + else if (ibuf->rect) { + display_buffer = ibuf->rect; + format = GL_RGBA; + type = GL_UNSIGNED_BYTE; + + glsl_used = IMB_colormanagement_setup_glsl_draw_from_space_ctx(C, ibuf->rect_colorspace, FALSE); + } + else { + format = GL_RGBA; + type = GL_UNSIGNED_BYTE; + display_buffer = NULL; + } } /* setting up the view - actual drawing starts here */ @@ -1068,7 +1107,7 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, ibuf->x, ibuf->y, 0, GL_RGBA, GL_UNSIGNED_BYTE, display_buffer); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, ibuf->x, ibuf->y, 0, format, type, display_buffer); glBegin(GL_QUADS); @@ -1105,6 +1144,9 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq glDisable(GL_BLEND); glDeleteTextures(1, &texid); + if (glsl_used) + IMB_colormanagement_finish_glsl_draw(); + if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) { float x1 = v2d->tot.xmin; |