From 6e040b045ab1d94a877ab6f72f431c9b64e1121c Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Tue, 13 Feb 2018 18:18:04 +0100 Subject: GPU: add offscreen buffer drawing utility functions. --- source/blender/gpu/intern/gpu_viewport.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'source/blender/gpu/intern/gpu_viewport.c') diff --git a/source/blender/gpu/intern/gpu_viewport.c b/source/blender/gpu/intern/gpu_viewport.c index 3ef53b3a6c3..fc045805874 100644 --- a/source/blender/gpu/intern/gpu_viewport.c +++ b/source/blender/gpu/intern/gpu_viewport.c @@ -474,7 +474,7 @@ cleanup: GPU_framebuffer_slots_bind(dfbl->default_fb, 0); } -static void draw_ofs_to_screen(GPUViewport *viewport) +static void draw_ofs_to_screen(GPUViewport *viewport, const rcti *rect) { DefaultTextureList *dtxl = viewport->txl; @@ -483,6 +483,9 @@ static void draw_ofs_to_screen(GPUViewport *viewport) 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); + Gwn_VertFormat *format = immVertexFormat(); unsigned int texcoord = GWN_vertformat_attr_add(format, "texCoord", GWN_COMP_F32, 2, GWN_FETCH_FLOAT); unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT); @@ -495,16 +498,16 @@ static void draw_ofs_to_screen(GPUViewport *viewport) immBegin(GWN_PRIM_TRI_STRIP, 4); immAttrib2f(texcoord, 0.0f, 0.0f); - immVertex2f(pos, 0.0f, 0.0f); + immVertex2f(pos, rect->xmin, rect->ymin); immAttrib2f(texcoord, 1.0f, 0.0f); - immVertex2f(pos, w, 0.0f); + immVertex2f(pos, rect->xmin + w, rect->ymin); immAttrib2f(texcoord, 0.0f, 1.0f); - immVertex2f(pos, 0.0f, h); + immVertex2f(pos, rect->xmin, rect->ymin + h); immAttrib2f(texcoord, 1.0f, 1.0f); - immVertex2f(pos, w, h); + immVertex2f(pos, rect->xmin + w, rect->ymin + h); immEnd(); @@ -523,9 +526,16 @@ void GPU_viewport_unbind(GPUViewport *viewport) glEnable(GL_SCISSOR_TEST); glDisable(GL_DEPTH_TEST); + } +} +void GPU_viewport_draw_to_screen(GPUViewport *viewport, const rcti *rect) +{ + DefaultFramebufferList *dfbl = viewport->fbl; + + if (dfbl->default_fb) { /* This might be bandwidth limiting */ - draw_ofs_to_screen(viewport); + draw_ofs_to_screen(viewport, rect); } } -- cgit v1.2.3