[Bf-blender-cvs] [3bed8a73384] soc-2019-openxr: Refactor GPU viewport onscreen drawing for "upside down" drawing
Julian Eisel
noreply at git.blender.org
Tue Oct 15 22:36:08 CEST 2019
Commit: 3bed8a73384d110213466515d0d7abdeb2c82bf2
Author: Julian Eisel
Date: Tue Oct 15 22:32:35 2019 +0200
Branches: soc-2019-openxr
https://developer.blender.org/rB3bed8a73384d110213466515d0d7abdeb2c82bf2
Refactor GPU viewport onscreen drawing for "upside down" drawing
Reduces code duplication for the DirectX specific upside down drawing.
Didn't actually test the upside down drawing, since I need to do that on
Windows.
===================================================================
M source/blender/gpu/GPU_viewport.h
M source/blender/gpu/intern/gpu_viewport.c
M source/blender/windowmanager/intern/wm_draw.c
M source/blender/windowmanager/intern/wm_xr.c
M source/blender/windowmanager/wm.h
===================================================================
diff --git a/source/blender/gpu/GPU_viewport.h b/source/blender/gpu/GPU_viewport.h
index d7695a41f86..17cbad21ec4 100644
--- a/source/blender/gpu/GPU_viewport.h
+++ b/source/blender/gpu/GPU_viewport.h
@@ -99,7 +99,8 @@ GPUViewport *GPU_viewport_create(void);
void GPU_viewport_bind(GPUViewport *viewport, const rcti *rect);
void GPU_viewport_unbind(GPUViewport *viewport);
void GPU_viewport_draw_to_screen(GPUViewport *viewport, const rcti *rect);
-void GPU_viewport_draw_to_screen_ex(GPUViewport *viewport, const rcti *rect, bool to_srgb);
+void GPU_viewport_draw_to_screen_ex(
+ GPUViewport *viewport, float x1, float x2, float y1, float y2, bool to_srgb);
void GPU_viewport_free(GPUViewport *viewport);
GPUViewport *GPU_viewport_create_from_offscreen(struct GPUOffScreen *ofs);
diff --git a/source/blender/gpu/intern/gpu_viewport.c b/source/blender/gpu/intern/gpu_viewport.c
index 59cb78b3fe1..73f588ba3d1 100644
--- a/source/blender/gpu/intern/gpu_viewport.c
+++ b/source/blender/gpu/intern/gpu_viewport.c
@@ -505,32 +505,18 @@ void GPU_viewport_bind(GPUViewport *viewport, const rcti *rect)
}
}
-void GPU_viewport_draw_to_screen_ex(GPUViewport *viewport, const rcti *rect, bool to_srgb)
+void GPU_viewport_draw_to_screen_ex(
+ GPUViewport *viewport, float x1, float x2, float y1, float y2, bool to_srgb)
{
- DefaultFramebufferList *dfbl = viewport->fbl;
+ GPUTexture *color = GPU_viewport_color_texture(viewport);
- if (dfbl->default_fb == NULL) {
+ if (!color) {
return;
}
- DefaultTextureList *dtxl = viewport->txl;
-
- GPUTexture *color = dtxl->color;
-
- 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);
-
/* wmOrtho for the screen has this same offset */
- const float halfx = GLA_PIXEL_OFS / w;
- const float halfy = GLA_PIXEL_OFS / h;
-
- float x1 = rect->xmin;
- float x2 = rect->xmin + w;
- float y1 = rect->ymin;
- float y2 = rect->ymin + h;
+ const float halfx = GLA_PIXEL_OFS / ABS(x2 - x1);
+ const float halfy = GLA_PIXEL_OFS / ABS(y2 - y1);
GPUShader *shader = GPU_shader_get_builtin_shader(
to_srgb ? GPU_SHADER_2D_IMAGE_RECT_LINEAR_TO_SRGB : GPU_SHADER_2D_IMAGE_RECT_COLOR);
@@ -553,7 +539,18 @@ void GPU_viewport_draw_to_screen_ex(GPUViewport *viewport, const rcti *rect, boo
void GPU_viewport_draw_to_screen(GPUViewport *viewport, const rcti *rect)
{
- GPU_viewport_draw_to_screen_ex(viewport, rect, false);
+ GPUTexture *color = GPU_viewport_color_texture(viewport);
+
+ if (color) {
+ 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);
+
+ GPU_viewport_draw_to_screen_ex(
+ viewport, rect->xmin, rect->xmin + w, rect->ymin, rect->ymin + h, false);
+ }
}
void GPU_viewport_unbind(GPUViewport *UNUSED(viewport))
diff --git a/source/blender/windowmanager/intern/wm_draw.c b/source/blender/windowmanager/intern/wm_draw.c
index cce16afb883..37e519fd0e7 100644
--- a/source/blender/windowmanager/intern/wm_draw.c
+++ b/source/blender/windowmanager/intern/wm_draw.c
@@ -756,39 +756,6 @@ static void wm_draw_window_onscreen(bContext *C, wmWindow *win, int view)
}
}
-void wm_draw_upside_down(int sizex, int sizey, bool to_srgb)
-{
- GPUVertFormat *format = immVertexFormat();
- uint texcoord = GPU_vertformat_attr_add(format, "texCoord", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
- uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
-
- immBindBuiltinProgram(to_srgb ? GPU_SHADER_2D_IMAGE_LINEAR_TO_SRGB : GPU_SHADER_2D_IMAGE);
-
- /* wmOrtho for the screen has this same offset */
- const float halfx = GLA_PIXEL_OFS / sizex;
- const float halfy = GLA_PIXEL_OFS / sizex;
-
- immUniform1i("image", 0); /* texture is already bound to GL_TEXTURE0 unit */
-
- immBegin(GPU_PRIM_TRI_FAN, 4);
-
- immAttr2f(texcoord, halfx, 1.0f + halfy);
- immVertex2f(pos, 0.0f, 0.0f);
-
- immAttr2f(texcoord, 1.0f + halfx, 1.0f + halfy);
- immVertex2f(pos, sizex, 0.0f);
-
- immAttr2f(texcoord, 1.0f + halfx, halfy);
- immVertex2f(pos, sizex, sizey);
-
- immAttr2f(texcoord, halfx, halfy);
- immVertex2f(pos, 0.0f, sizey);
-
- immEnd();
-
- immUnbindProgram();
-}
-
static void wm_draw_window(bContext *C, wmWindow *win)
{
bScreen *screen = WM_window_get_active_screen(win);
diff --git a/source/blender/windowmanager/intern/wm_xr.c b/source/blender/windowmanager/intern/wm_xr.c
index 40276e8664f..e88082b14e9 100644
--- a/source/blender/windowmanager/intern/wm_xr.c
+++ b/source/blender/windowmanager/intern/wm_xr.c
@@ -496,20 +496,16 @@ void wm_xr_draw_view(const GHOST_XrDrawViewInfo *draw_view, void *customdata)
GPU_framebuffer_bind(surface_data->fbo);
- GPUTexture *texture = GPU_offscreen_color_texture(offscreen);
-
wm_draw_offscreen_texture_parameters(offscreen);
wmViewport(&rect);
- if (surface_data->secondary_ghost_ctx &&
- GHOST_isUpsideDownContext(surface_data->secondary_ghost_ctx)) {
- GPU_texture_bind(texture, 0);
- wm_draw_upside_down(draw_view->width, draw_view->height, draw_view->expects_srgb_buffer);
- GPU_texture_unbind(texture);
- }
- else {
- GPU_viewport_draw_to_screen_ex(viewport, &rect, draw_view->expects_srgb_buffer);
- }
+ const bool is_upside_down = surface_data->secondary_ghost_ctx &&
+ GHOST_isUpsideDownContext(surface_data->secondary_ghost_ctx);
+ const int ymin = is_upside_down ? draw_view->height : 0;
+ const int ymax = is_upside_down ? 0 : draw_view->height;
+ GPU_viewport_draw_to_screen_ex(
+ viewport, 0, draw_view->width, ymin, ymax, draw_view->expects_srgb_buffer);
+
/* Leave viewport bound so GHOST_Xr can use its context/framebuffer, its unbound in
* wm_xr_session_surface_draw(). */
// GPU_viewport_unbind(viewport);
diff --git a/source/blender/windowmanager/wm.h b/source/blender/windowmanager/wm.h
index 618b9e3ca88..931ac58d50e 100644
--- a/source/blender/windowmanager/wm.h
+++ b/source/blender/windowmanager/wm.h
@@ -101,7 +101,6 @@ void wm_open_init_use_scripts(wmOperator *op, bool use_prefs);
/* wm_draw.c */
struct GPUOffScreen;
void wm_draw_offscreen_texture_parameters(struct GPUOffScreen *offscreen);
-void wm_draw_upside_down(int sizex, int sizey, bool to_srgb);
#ifdef WITH_OPENXR
/* wm_xr.c */
More information about the Bf-blender-cvs
mailing list