diff options
Diffstat (limited to 'source/blender/editors/space_clip/clip_draw.c')
-rw-r--r-- | source/blender/editors/space_clip/clip_draw.c | 113 |
1 files changed, 65 insertions, 48 deletions
diff --git a/source/blender/editors/space_clip/clip_draw.c b/source/blender/editors/space_clip/clip_draw.c index 2d3dc9127c3..cbca2f0c46e 100644 --- a/source/blender/editors/space_clip/clip_draw.c +++ b/source/blender/editors/space_clip/clip_draw.c @@ -248,6 +248,53 @@ static void draw_movieclip_notes(SpaceClip *sc, ARegion *ar) ED_region_info_draw(ar, str, block, 0.6f); } +static void draw_movieclip_buffer_glsl(SpaceClip *sc, ImBuf *ibuf, int x, int y, + float zoomx, float zoomy) +{ + MovieClip *clip = ED_space_clip_get_clip(sc); + int filter = GL_LINEAR; + + glPushMatrix(); + glTranslatef(x, y, 0.0f); + glScalef(zoomx, zoomy, 1.0f); + + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + + glColor4f(1.0, 1.0, 1.0, 1.0); + + /* non-scaled proxy shouldn;t use diltering */ + if ((clip->flag & MCLIP_USE_PROXY) == 0 || + ELEM(sc->user.render_size, MCLIP_PROXY_RENDER_SIZE_FULL, MCLIP_PROXY_RENDER_SIZE_100)) + { + filter = GL_NEAREST; + } + + glaDrawPixelsTex(0, 0, ibuf->x, ibuf->y, GL_FLOAT, filter, ibuf->rect_float); + + glPopMatrix(); +} + +static void draw_movieclip_buffer_fallback(const bContext *C, ImBuf *ibuf, int x, int y, + int width, int height, float zoomx, float zoomy) +{ + unsigned char *display_buffer; + void *cache_handle; + + display_buffer = IMB_display_buffer_acquire_ctx(C, ibuf, &cache_handle); + + if (display_buffer) { + /* set zoom */ + glPixelZoom(zoomx * width / ibuf->x, zoomy * height / ibuf->y); + + glaDrawPixelsAuto(x, y, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, GL_NEAREST, display_buffer); + + /* reset zoom */ + glPixelZoom(1.0f, 1.0f); + } + + IMB_display_buffer_release(cache_handle); +} + static void draw_movieclip_buffer(const bContext *C, SpaceClip *sc, ARegion *ar, ImBuf *ibuf, int width, int height, float zoomx, float zoomy) { @@ -261,62 +308,32 @@ static void draw_movieclip_buffer(const bContext *C, SpaceClip *sc, ARegion *ar, glRectf(x, y, x + zoomx * width, y + zoomy * height); } else { - unsigned char *display_buffer; - void *cache_handle; - - display_buffer = IMB_display_buffer_acquire_ctx(C, ibuf, &cache_handle); - - if (display_buffer) { - int need_fallback = 1; - - /* checkerboard for case alpha */ - if (ibuf->planes == 32) { - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - fdrawcheckerboard(x, y, x + zoomx * ibuf->x, y + zoomy * ibuf->y); - } + bool need_fallback = true; - if (ED_space_clip_texture_buffer_supported(sc)) { - if (ED_space_clip_load_movieclip_buffer(sc, ibuf, display_buffer)) { - glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + /* checkerboard for case alpha */ + if (ibuf->planes == 32) { + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glPushMatrix(); - glTranslatef(x, y, 0.0f); - glScalef(zoomx, zoomy, 1.0f); - - glBegin(GL_QUADS); - glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 0.0f); - glTexCoord2f(1.0f, 0.0f); glVertex2f(width, 0.0f); - glTexCoord2f(1.0f, 1.0f); glVertex2f(width, height); - glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, height); - glEnd(); - - glPopMatrix(); - - ED_space_clip_unload_movieclip_buffer(sc); - - need_fallback = 0; - } - } + fdrawcheckerboard(x, y, x + zoomx * ibuf->x, y + zoomy * ibuf->y); + } - /* if texture buffers aren't efficiently supported or texture is too large to - * be binder fallback to simple draw pixels solution */ - if (need_fallback) { - /* set zoom */ - glPixelZoom(zoomx * width / ibuf->x, zoomy * height / ibuf->y); + /* GLSL display transform for byte buffers is not supported yet */ + if (ibuf->rect_float && IMB_coloemanagement_setup_glsl_draw_from_ctx(C)) { + draw_movieclip_buffer_glsl(sc, ibuf, x, y, zoomx, zoomy); - glaDrawPixelsAuto(x, y, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, GL_NEAREST, display_buffer); + IMB_coloemanagement_finish_glsl_draw(); - /* reset zoom */ - glPixelZoom(1.0f, 1.0f); - } + need_fallback = false; + } - if (ibuf->planes == 32) - glDisable(GL_BLEND); + /* if GLSL display failed, fallback to regular glaDrawPixelsAuto method */ + if (need_fallback) { + draw_movieclip_buffer_fallback(C, ibuf, x, y, width, height, zoomx, zoomy); } - IMB_display_buffer_release(cache_handle); + if (ibuf->planes == 32) + glDisable(GL_BLEND); } } |