diff options
Diffstat (limited to 'source/blender/gpu/intern/gpu_viewport.c')
-rw-r--r-- | source/blender/gpu/intern/gpu_viewport.c | 46 |
1 files changed, 38 insertions, 8 deletions
diff --git a/source/blender/gpu/intern/gpu_viewport.c b/source/blender/gpu/intern/gpu_viewport.c index 8ccfa3d9898..e4fd5d3f122 100644 --- a/source/blender/gpu/intern/gpu_viewport.c +++ b/source/blender/gpu/intern/gpu_viewport.c @@ -532,7 +532,13 @@ static void gpu_viewport_draw_colormanaged(GPUViewport *viewport, } } -void GPU_viewport_draw_to_screen(GPUViewport *viewport, const rcti *rect) +/** + * Version of #GPU_viewport_draw_to_screen() that lets caller decide if display colorspace + * transform should be performed. + */ +void GPU_viewport_draw_to_screen_ex(GPUViewport *viewport, + const rcti *rect, + bool display_colorspace) { DefaultFramebufferList *dfbl = viewport->fbl; DefaultTextureList *dtxl = viewport->txl; @@ -545,18 +551,22 @@ void GPU_viewport_draw_to_screen(GPUViewport *viewport, const rcti *rect) const float w = (float)GPU_texture_width(color); const float h = (float)GPU_texture_height(color); - BLI_assert(w == BLI_rcti_size_x(rect) + 1); - BLI_assert(h == BLI_rcti_size_y(rect) + 1); + /* We allow rects with min/max swapped, but we also need coorectly assigned coordinates. */ + rcti sanitized_rect = *rect; + BLI_rcti_sanitize(&sanitized_rect); + + BLI_assert(w == BLI_rcti_size_x(&sanitized_rect) + 1); + BLI_assert(h == BLI_rcti_size_y(&sanitized_rect) + 1); /* wmOrtho for the screen has this same offset */ const float halfx = GLA_PIXEL_OFS / w; const float halfy = GLA_PIXEL_OFS / h; rctf pos_rect = { - .xmin = rect->xmin, - .ymin = rect->ymin, - .xmax = rect->xmin + w, - .ymax = rect->ymin + h, + .xmin = sanitized_rect.xmin, + .ymin = sanitized_rect.ymin, + .xmax = sanitized_rect.xmin + w, + .ymax = sanitized_rect.ymin + h, }; rctf uv_rect = { @@ -565,8 +575,28 @@ void GPU_viewport_draw_to_screen(GPUViewport *viewport, const rcti *rect) .xmax = halfx + 1.0f, .ymax = halfy + 1.0f, }; + /* Mirror the UV rect in case axis-swapped drawing is requested (by passing a rect with min and + * max values swapped). */ + if (BLI_rcti_size_x(rect) < 0) { + SWAP(float, uv_rect.xmin, uv_rect.xmax); + } + if (BLI_rcti_size_y(rect) < 0) { + SWAP(float, uv_rect.ymin, uv_rect.ymax); + } + + gpu_viewport_draw_colormanaged(viewport, &pos_rect, &uv_rect, display_colorspace); +} - gpu_viewport_draw_colormanaged(viewport, &pos_rect, &uv_rect, true); +/** + * Merge and draw the buffers of \a viewport into the currently active framebuffer, performing + * color transform to display space. + * + * \param rect: Coordinates to draw into. By swapping min and max values, drawing can be done with + * inversed axis coordinates (upside down or sideways). + */ +void GPU_viewport_draw_to_screen(GPUViewport *viewport, const rcti *rect) +{ + GPU_viewport_draw_to_screen_ex(viewport, rect, true); } /** |